Upload folder using huggingface_hub
Browse files- 6.17.1/workflowcanvas/Index.svelte +57 -0
- 6.17.1/workflowcanvas/package.json +34 -0
- 6.17.1/workflowcanvas/workflow/NodeModelPicker.svelte +1338 -0
- 6.17.1/workflowcanvas/workflow/NodeWidget.svelte +690 -0
- 6.17.1/workflowcanvas/workflow/WorkflowBottomBar.svelte +444 -0
- 6.17.1/workflowcanvas/workflow/WorkflowCanvas.svelte +2154 -0
- 6.17.1/workflowcanvas/workflow/WorkflowEdges.svelte +207 -0
- 6.17.1/workflowcanvas/workflow/WorkflowEmptyState.svelte +36 -0
- 6.17.1/workflowcanvas/workflow/WorkflowNodeSF.svelte +1088 -0
- 6.17.1/workflowcanvas/workflow/WorkflowSidebar.svelte +1727 -0
- 6.17.1/workflowcanvas/workflow/featured.ts +99 -0
- 6.17.1/workflowcanvas/workflow/hf-auth.svelte.ts +117 -0
- 6.17.1/workflowcanvas/workflow/icons/AudioIcon.svelte +16 -0
- 6.17.1/workflowcanvas/workflow/icons/CheckIcon.svelte +9 -0
- 6.17.1/workflowcanvas/workflow/icons/ChevronDownIcon.svelte +13 -0
- 6.17.1/workflowcanvas/workflow/icons/ChevronLeftIcon.svelte +13 -0
- 6.17.1/workflowcanvas/workflow/icons/CloseIcon.svelte +8 -0
- 6.17.1/workflowcanvas/workflow/icons/DatasetIcon.svelte +20 -0
- 6.17.1/workflowcanvas/workflow/icons/DownloadIcon.svelte +15 -0
- 6.17.1/workflowcanvas/workflow/icons/FunctionIcon.svelte +14 -0
- 6.17.1/workflowcanvas/workflow/icons/ImageIcon.svelte +19 -0
- 6.17.1/workflowcanvas/workflow/icons/Model3DIcon.svelte +15 -0
- 6.17.1/workflowcanvas/workflow/icons/OpenLinkIcon.svelte +21 -0
- 6.17.1/workflowcanvas/workflow/icons/PlayIcon.svelte +9 -0
- 6.17.1/workflowcanvas/workflow/icons/PlusIcon.svelte +8 -0
- 6.17.1/workflowcanvas/workflow/icons/SearchIcon.svelte +9 -0
- 6.17.1/workflowcanvas/workflow/icons/StopIcon.svelte +9 -0
- 6.17.1/workflowcanvas/workflow/icons/TextIcon.svelte +14 -0
- 6.17.1/workflowcanvas/workflow/icons/VideoIcon.svelte +18 -0
- 6.17.1/workflowcanvas/workflow/inference-stream.ts +126 -0
- 6.17.1/workflowcanvas/workflow/node-library.ts +316 -0
- 6.17.1/workflowcanvas/workflow/space-api.ts +325 -0
- 6.17.1/workflowcanvas/workflow/viewport-persistence.ts +46 -0
- 6.17.1/workflowcanvas/workflow/workflow-executor.ts +526 -0
- 6.17.1/workflowcanvas/workflow/workflow-graph.ts +146 -0
- 6.17.1/workflowcanvas/workflow/workflow-migration.ts +224 -0
- 6.17.1/workflowcanvas/workflow/workflow-modalities.ts +282 -0
- 6.17.1/workflowcanvas/workflow/workflow-store.ts +421 -0
- 6.17.1/workflowcanvas/workflow/workflow-types.ts +203 -0
6.17.1/workflowcanvas/Index.svelte
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Gradio } from "@gradio/utils";
|
| 3 |
+
import { get } from "svelte/store";
|
| 4 |
+
import WorkflowCanvas from "./workflow/WorkflowCanvas.svelte";
|
| 5 |
+
import { workflow, sanitize_for_save } from "./workflow/workflow-store";
|
| 6 |
+
|
| 7 |
+
let _props = $props();
|
| 8 |
+
const gradio = new Gradio<Record<string, never>, { value: string | null }>(
|
| 9 |
+
_props
|
| 10 |
+
);
|
| 11 |
+
|
| 12 |
+
let serverObj = $derived(gradio.shared?.server ?? {});
|
| 13 |
+
let initialValue = $derived(gradio.props.value ?? null);
|
| 14 |
+
|
| 15 |
+
$effect(() => {
|
| 16 |
+
if (!serverObj?.save_workflow) return;
|
| 17 |
+
|
| 18 |
+
function handlePageHide() {
|
| 19 |
+
const gradioConfig = (window as any).gradio_config;
|
| 20 |
+
const componentId = gradioConfig?.components?.find(
|
| 21 |
+
(c: any) => c.type === "workflowcanvas"
|
| 22 |
+
)?.id;
|
| 23 |
+
if (!componentId) return;
|
| 24 |
+
const client = gradio.shared?.client;
|
| 25 |
+
if (!client) return;
|
| 26 |
+
const root = gradioConfig?.root ?? "";
|
| 27 |
+
const apiPrefix = gradioConfig?.api_prefix ?? "/gradio_api";
|
| 28 |
+
fetch(`${root}${apiPrefix}/component_server/`, {
|
| 29 |
+
method: "POST",
|
| 30 |
+
headers: { "Content-Type": "application/json" },
|
| 31 |
+
body: JSON.stringify({
|
| 32 |
+
data: [JSON.stringify(sanitize_for_save(get(workflow)))],
|
| 33 |
+
component_id: componentId,
|
| 34 |
+
fn_name: "save_workflow",
|
| 35 |
+
session_hash: client.session_hash
|
| 36 |
+
}),
|
| 37 |
+
keepalive: true
|
| 38 |
+
}).catch(() => {});
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
window.addEventListener("pagehide", handlePageHide);
|
| 42 |
+
return () => window.removeEventListener("pagehide", handlePageHide);
|
| 43 |
+
});
|
| 44 |
+
</script>
|
| 45 |
+
|
| 46 |
+
<div class="workflow-fullscreen">
|
| 47 |
+
<WorkflowCanvas server={serverObj} {initialValue} />
|
| 48 |
+
</div>
|
| 49 |
+
|
| 50 |
+
<style>
|
| 51 |
+
.workflow-fullscreen {
|
| 52 |
+
position: fixed;
|
| 53 |
+
inset: 0;
|
| 54 |
+
z-index: 100;
|
| 55 |
+
background: #0c0d10;
|
| 56 |
+
}
|
| 57 |
+
</style>
|
6.17.1/workflowcanvas/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@gradio/workflowcanvas",
|
| 3 |
+
"version": "0.2.0",
|
| 4 |
+
"description": "Gradio Workflow Canvas component",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"author": "",
|
| 7 |
+
"license": "Apache-2.0",
|
| 8 |
+
"private": false,
|
| 9 |
+
"main_changeset": true,
|
| 10 |
+
"main": "Index.svelte",
|
| 11 |
+
"exports": {
|
| 12 |
+
".": {
|
| 13 |
+
"gradio": "./Index.svelte",
|
| 14 |
+
"svelte": "./dist/Index.svelte",
|
| 15 |
+
"types": "./dist/Index.svelte.d.ts",
|
| 16 |
+
"default": "./dist/Index.svelte"
|
| 17 |
+
},
|
| 18 |
+
"./package.json": "./package.json"
|
| 19 |
+
},
|
| 20 |
+
"dependencies": {
|
| 21 |
+
"@gradio/atoms": "workspace:^",
|
| 22 |
+
"@gradio/client": "workspace:^",
|
| 23 |
+
"@gradio/statustracker": "workspace:^",
|
| 24 |
+
"@gradio/utils": "workspace:^",
|
| 25 |
+
"@huggingface/hub": "^1.0.0",
|
| 26 |
+
"svelte": "^5.48.0"
|
| 27 |
+
},
|
| 28 |
+
"devDependencies": {
|
| 29 |
+
"@gradio/preview": "workspace:^"
|
| 30 |
+
},
|
| 31 |
+
"peerDependencies": {
|
| 32 |
+
"svelte": "^5.48.0"
|
| 33 |
+
}
|
| 34 |
+
}
|
6.17.1/workflowcanvas/workflow/NodeModelPicker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_MODELS } from "./featured";
|
| 5 |
+
import type { ModalityConfig, SubTab } from "./workflow-modalities";
|
| 6 |
+
import SearchIcon from "./icons/SearchIcon.svelte";
|
| 7 |
+
import CloseIcon from "./icons/CloseIcon.svelte";
|
| 8 |
+
import OpenLinkIcon from "./icons/OpenLinkIcon.svelte";
|
| 9 |
+
|
| 10 |
+
interface SpaceResult {
|
| 11 |
+
id: string;
|
| 12 |
+
title: string;
|
| 13 |
+
description: string;
|
| 14 |
+
likes: number;
|
| 15 |
+
running: boolean;
|
| 16 |
+
category: string | null;
|
| 17 |
+
pipeline_tag?: string;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
type Source = "spaces" | "models" | "datasets";
|
| 21 |
+
|
| 22 |
+
interface Props {
|
| 23 |
+
mode: "create" | "update";
|
| 24 |
+
modality: ModalityConfig;
|
| 25 |
+
nodeId?: string;
|
| 26 |
+
server?: Record<string, any>;
|
| 27 |
+
hfToken?: string;
|
| 28 |
+
anchorX?: number;
|
| 29 |
+
anchorY?: number;
|
| 30 |
+
initialSource?: Source;
|
| 31 |
+
initialSubtab?: string;
|
| 32 |
+
oncreate: (template: any) => void;
|
| 33 |
+
onupdate: (nodeId: string, template: any) => void;
|
| 34 |
+
onclose: () => void;
|
| 35 |
+
onerror?: (message: string) => void;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
let {
|
| 39 |
+
mode,
|
| 40 |
+
modality,
|
| 41 |
+
nodeId,
|
| 42 |
+
server = {},
|
| 43 |
+
hfToken = "",
|
| 44 |
+
anchorX = undefined,
|
| 45 |
+
anchorY = undefined,
|
| 46 |
+
initialSource = undefined,
|
| 47 |
+
initialSubtab = undefined,
|
| 48 |
+
oncreate,
|
| 49 |
+
onupdate,
|
| 50 |
+
onclose,
|
| 51 |
+
onerror
|
| 52 |
+
}: Props = $props();
|
| 53 |
+
|
| 54 |
+
let source = $state<Source>(
|
| 55 |
+
initialSource ?? (modality.key === "data" ? "datasets" : "spaces")
|
| 56 |
+
);
|
| 57 |
+
const is_dataset = $derived(source === "datasets");
|
| 58 |
+
const is_model = $derived(source === "models");
|
| 59 |
+
const is_spaces = $derived(source === "spaces");
|
| 60 |
+
const show_source_toggle = $derived(modality.key !== "data");
|
| 61 |
+
|
| 62 |
+
const search_placeholder = $derived.by(() => {
|
| 63 |
+
const kind = is_dataset ? "datasets" : is_model ? "models" : "spaces";
|
| 64 |
+
// Data modality is its own thing β no per-modality qualifier needed.
|
| 65 |
+
if (modality.key === "data") return `Search ${kind}...`;
|
| 66 |
+
return `Search ${modality.label.toLowerCase()} ${kind}...`;
|
| 67 |
+
});
|
| 68 |
+
|
| 69 |
+
// In "models" mode the HF API can only filter by pipeline_tag, so subtabs
|
| 70 |
+
// whose only constraint is a free-text query (e.g. Enhance, Remove BG) are
|
| 71 |
+
// hidden β they wouldn't return anything meaningful from the models API.
|
| 72 |
+
const visible_subtabs = $derived(
|
| 73 |
+
is_model
|
| 74 |
+
? modality.subtabs.filter((st) => {
|
| 75 |
+
if (st.key === "all") return true;
|
| 76 |
+
const model_tag_list = st.modelTags ?? st.pipelineTags;
|
| 77 |
+
return model_tag_list.length > 0;
|
| 78 |
+
})
|
| 79 |
+
: modality.subtabs
|
| 80 |
+
);
|
| 81 |
+
|
| 82 |
+
function set_source(next: Source): void {
|
| 83 |
+
if (next === source) return;
|
| 84 |
+
// Reset emptiness flags up front so the auto-switch effect can't
|
| 85 |
+
// fire on a stale value mid-source-change (same race as the
|
| 86 |
+
// subtab onclick).
|
| 87 |
+
trending_empty = null;
|
| 88 |
+
new_empty = null;
|
| 89 |
+
source = next;
|
| 90 |
+
// If the active subtab disappears in the new source, fall back to "all"
|
| 91 |
+
if (!visible_subtabs.some((st) => st.key === active_subtab.key)) {
|
| 92 |
+
active_subtab = visible_subtabs[0] ?? modality.subtabs[0];
|
| 93 |
+
}
|
| 94 |
+
if (active_content_tab === "search") {
|
| 95 |
+
search_query = "";
|
| 96 |
+
active_content_tab = "trending";
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
const AVATAR_COLORS = [
|
| 101 |
+
"#f97316",
|
| 102 |
+
"#8b5cf6",
|
| 103 |
+
"#3b82f6",
|
| 104 |
+
"#10b981",
|
| 105 |
+
"#ec4899",
|
| 106 |
+
"#f59e0b",
|
| 107 |
+
"#06b6d4",
|
| 108 |
+
"#84cc16"
|
| 109 |
+
];
|
| 110 |
+
function avatar_color(id: string): string {
|
| 111 |
+
let h = 5381;
|
| 112 |
+
for (let i = 0; i < id.length; i++) h = ((h << 5) + h) ^ id.charCodeAt(i);
|
| 113 |
+
return AVATAR_COLORS[Math.abs(h) % AVATAR_COLORS.length];
|
| 114 |
+
}
|
| 115 |
+
function avatar_initial(id: string): string {
|
| 116 |
+
return (id.split("/").pop() || id)[0].toUpperCase();
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
type ContentTab = "featured" | "trending" | "new" | "search";
|
| 120 |
+
|
| 121 |
+
let active_subtab = $state<SubTab>(
|
| 122 |
+
(initialSubtab && modality.subtabs.find((s) => s.key === initialSubtab)) ||
|
| 123 |
+
modality.subtabs[0]
|
| 124 |
+
);
|
| 125 |
+
let active_content_tab = $state<ContentTab>(
|
| 126 |
+
// Datasets API doesn't have a featured list, jump straight to search/trending.
|
| 127 |
+
// When entering with a specific subtab, Featured ignores subtab filters, so
|
| 128 |
+
// go to trending so the subtab actually narrows results.
|
| 129 |
+
modality.key === "data" || initialSubtab ? "trending" : "featured"
|
| 130 |
+
);
|
| 131 |
+
let zero_gpu_only = $state(false);
|
| 132 |
+
|
| 133 |
+
const featured_results = $derived.by(() => {
|
| 134 |
+
if (source === "datasets") return [];
|
| 135 |
+
const list = source === "models" ? FEATURED_MODELS : FEATURED_SPACES;
|
| 136 |
+
const cats = modality.acceptedCategories ?? [modality.category];
|
| 137 |
+
return list
|
| 138 |
+
.filter((item) => cats.includes(item.modality))
|
| 139 |
+
.map((item) => ({
|
| 140 |
+
id: item.id,
|
| 141 |
+
title: item.title,
|
| 142 |
+
description: item.description,
|
| 143 |
+
likes: item.likes ?? 0,
|
| 144 |
+
running: true,
|
| 145 |
+
category: item.modality,
|
| 146 |
+
pipeline_tag: item.pipeline_tag
|
| 147 |
+
}));
|
| 148 |
+
});
|
| 149 |
+
|
| 150 |
+
// If the active tab is known-empty, fall through to the next available
|
| 151 |
+
// one so the panel never sits on a blank tab. Cascade: featured β
|
| 152 |
+
// trending β new β search.
|
| 153 |
+
$effect(() => {
|
| 154 |
+
if (active_content_tab === "featured" && featured_results.length === 0) {
|
| 155 |
+
active_content_tab = "trending";
|
| 156 |
+
} else if (active_content_tab === "trending" && trending_empty === true) {
|
| 157 |
+
active_content_tab = new_empty === true ? "search" : "new";
|
| 158 |
+
} else if (active_content_tab === "new" && new_empty === true) {
|
| 159 |
+
active_content_tab = trending_empty === true ? "search" : "trending";
|
| 160 |
+
}
|
| 161 |
+
});
|
| 162 |
+
let search_query = $state("");
|
| 163 |
+
let results = $state<SpaceResult[]>([]);
|
| 164 |
+
let loading = $state(false);
|
| 165 |
+
let loading_space_id = $state<string | null>(null);
|
| 166 |
+
|
| 167 |
+
// Track per-tab emptiness so we can hide Trending / New when a fetch
|
| 168 |
+
// confirms there are no matching results. Reset to null (unknown) when
|
| 169 |
+
// any filter changes that affects the fetch, so the next fetch can
|
| 170 |
+
// re-evaluate. Featured tabs are handled separately via featured_results.
|
| 171 |
+
let trending_empty = $state<boolean | null>(null);
|
| 172 |
+
let new_empty = $state<boolean | null>(null);
|
| 173 |
+
|
| 174 |
+
const display_results = $derived(
|
| 175 |
+
active_content_tab === "featured" ? featured_results : results
|
| 176 |
+
);
|
| 177 |
+
let search_timeout: ReturnType<typeof setTimeout> | null = null;
|
| 178 |
+
let fetch_token = 0;
|
| 179 |
+
|
| 180 |
+
function parse_results(raw: any): SpaceResult[] {
|
| 181 |
+
if (!Array.isArray(raw)) return [];
|
| 182 |
+
return raw.map((s: any) => {
|
| 183 |
+
const desc =
|
| 184 |
+
s.cardData?.short_description || s.ai_short_description || "";
|
| 185 |
+
return {
|
| 186 |
+
id: s.id,
|
| 187 |
+
title: s.cardData?.title || s.title || s.id.split("/").pop() || s.id,
|
| 188 |
+
description: desc,
|
| 189 |
+
likes: s.likes ?? 0,
|
| 190 |
+
running: s.runtime?.stage === "RUNNING",
|
| 191 |
+
category: categorizeSpace(
|
| 192 |
+
s.cardData?.pipeline_tag || s.pipeline_tag,
|
| 193 |
+
s.cardData?.tags,
|
| 194 |
+
desc,
|
| 195 |
+
s.id
|
| 196 |
+
),
|
| 197 |
+
pipeline_tag: s.cardData?.pipeline_tag || s.pipeline_tag || undefined
|
| 198 |
+
};
|
| 199 |
+
});
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
async function fetch_results() {
|
| 203 |
+
if (is_dataset) {
|
| 204 |
+
await fetch_datasets(search_query);
|
| 205 |
+
return;
|
| 206 |
+
}
|
| 207 |
+
if (is_model) {
|
| 208 |
+
await fetch_models(search_query);
|
| 209 |
+
return;
|
| 210 |
+
}
|
| 211 |
+
if (!server?.search_spaces) {
|
| 212 |
+
results = [];
|
| 213 |
+
return;
|
| 214 |
+
}
|
| 215 |
+
const token = ++fetch_token;
|
| 216 |
+
loading = true;
|
| 217 |
+
try {
|
| 218 |
+
// Spaces use the per-subtab `spaceTags` override when present
|
| 219 |
+
// (category names like "image-editing") and fall back to
|
| 220 |
+
// `pipelineTags` for subtabs where the model pipeline tag
|
| 221 |
+
// works as a Space category too (e.g. text-to-image).
|
| 222 |
+
const space_tag_list =
|
| 223 |
+
active_subtab.spaceTags ?? active_subtab.pipelineTags;
|
| 224 |
+
const space_tag = space_tag_list.length > 0 ? space_tag_list[0] : "";
|
| 225 |
+
|
| 226 |
+
let kind: string;
|
| 227 |
+
let query: string;
|
| 228 |
+
|
| 229 |
+
if (active_content_tab === "search") {
|
| 230 |
+
kind = "search";
|
| 231 |
+
query = search_query;
|
| 232 |
+
} else if (active_subtab.query) {
|
| 233 |
+
// Always forward the subtab's freeform query alongside the
|
| 234 |
+
// category. The server prefers `category=` when valid and
|
| 235 |
+
// falls back to `q=` when the category isn't a real HF
|
| 236 |
+
// Space category (e.g. `automatic-speech-recognition`).
|
| 237 |
+
kind = active_content_tab === "new" ? "new" : "trending";
|
| 238 |
+
query = active_subtab.query;
|
| 239 |
+
} else {
|
| 240 |
+
kind = active_content_tab === "new" ? "new" : "trending";
|
| 241 |
+
query = "";
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
const raw = await server.search_spaces([
|
| 245 |
+
kind,
|
| 246 |
+
query,
|
| 247 |
+
space_tag,
|
| 248 |
+
"",
|
| 249 |
+
zero_gpu_only
|
| 250 |
+
]);
|
| 251 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 252 |
+
let parsed = parse_results(data);
|
| 253 |
+
|
| 254 |
+
// Keep results that match the modality OR are uncategorised
|
| 255 |
+
// (most Gradio Spaces lack a pipeline_tag on their card).
|
| 256 |
+
if (active_content_tab !== "search" && !space_tag) {
|
| 257 |
+
const cats = modality.acceptedCategories ?? [modality.category];
|
| 258 |
+
parsed = parsed.filter((s) => !s.category || cats.includes(s.category));
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
if (token !== fetch_token) return;
|
| 262 |
+
results = parsed.slice(0, 20);
|
| 263 |
+
} catch {
|
| 264 |
+
if (token === fetch_token) results = [];
|
| 265 |
+
} finally {
|
| 266 |
+
if (token === fetch_token) loading = false;
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
async function fetch_datasets(query: string) {
|
| 271 |
+
if (!server?.search_datasets) {
|
| 272 |
+
results = [];
|
| 273 |
+
loading = false;
|
| 274 |
+
return;
|
| 275 |
+
}
|
| 276 |
+
const token = ++fetch_token;
|
| 277 |
+
loading = true;
|
| 278 |
+
try {
|
| 279 |
+
const raw = await server.search_datasets([query]);
|
| 280 |
+
if (token !== fetch_token) return;
|
| 281 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 282 |
+
if (!Array.isArray(data)) {
|
| 283 |
+
results = [];
|
| 284 |
+
return;
|
| 285 |
+
}
|
| 286 |
+
results = data.slice(0, 20).map((d: any) => ({
|
| 287 |
+
id: d.id,
|
| 288 |
+
title: d.id.split("/").pop() || d.id,
|
| 289 |
+
description: d.description || d.cardData?.summary || "",
|
| 290 |
+
likes: d.likes ?? 0,
|
| 291 |
+
running: true,
|
| 292 |
+
category: "data",
|
| 293 |
+
pipeline_tag: undefined
|
| 294 |
+
}));
|
| 295 |
+
} catch {
|
| 296 |
+
if (token === fetch_token) results = [];
|
| 297 |
+
} finally {
|
| 298 |
+
if (token === fetch_token) loading = false;
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
async function fetch_models(q: string) {
|
| 303 |
+
if (!server?.search_models) {
|
| 304 |
+
results = [];
|
| 305 |
+
loading = false;
|
| 306 |
+
return;
|
| 307 |
+
}
|
| 308 |
+
const token = ++fetch_token;
|
| 309 |
+
loading = true;
|
| 310 |
+
try {
|
| 311 |
+
// Models use the per-subtab `modelTags` override when present
|
| 312 |
+
// and fall back to `pipelineTags`. `spaceTags` is ignored here
|
| 313 |
+
// because Space category names (e.g. "image-editing") aren't
|
| 314 |
+
// valid model pipeline tags.
|
| 315 |
+
const model_tag_list =
|
| 316 |
+
active_subtab.modelTags ?? active_subtab.pipelineTags;
|
| 317 |
+
const pipeline_tag = model_tag_list[0] ?? "";
|
| 318 |
+
let kind: string;
|
| 319 |
+
if (active_content_tab === "search") {
|
| 320 |
+
kind = "search";
|
| 321 |
+
} else {
|
| 322 |
+
kind = active_content_tab === "new" ? "new" : "trending";
|
| 323 |
+
q = "";
|
| 324 |
+
}
|
| 325 |
+
const raw = await server.search_models([kind, q, pipeline_tag, ""]);
|
| 326 |
+
if (token !== fetch_token) return;
|
| 327 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 328 |
+
if (!Array.isArray(data)) {
|
| 329 |
+
results = [];
|
| 330 |
+
return;
|
| 331 |
+
}
|
| 332 |
+
results = data
|
| 333 |
+
.filter((m: any) => m.pipeline_tag && TASK_SCHEMAS[m.pipeline_tag])
|
| 334 |
+
.slice(0, 24)
|
| 335 |
+
.map((m: any) => ({
|
| 336 |
+
id: m.id,
|
| 337 |
+
title: m.id.split("/").pop() || m.id,
|
| 338 |
+
description: m.pipeline_tag || "",
|
| 339 |
+
likes: m.likes ?? 0,
|
| 340 |
+
running: true,
|
| 341 |
+
category: "model",
|
| 342 |
+
pipeline_tag: m.pipeline_tag
|
| 343 |
+
}));
|
| 344 |
+
} catch {
|
| 345 |
+
if (token === fetch_token) results = [];
|
| 346 |
+
} finally {
|
| 347 |
+
if (token === fetch_token) loading = false;
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
// Fetch when tab/subtab/mode changes (Featured is static, no API call).
|
| 352 |
+
// After each fetch, record whether the active tab came back empty so we
|
| 353 |
+
// can hide it from the tab strip.
|
| 354 |
+
$effect(() => {
|
| 355 |
+
active_subtab;
|
| 356 |
+
active_content_tab;
|
| 357 |
+
is_dataset;
|
| 358 |
+
is_model;
|
| 359 |
+
zero_gpu_only;
|
| 360 |
+
if (active_content_tab !== "search" && active_content_tab !== "featured") {
|
| 361 |
+
const captured = active_content_tab;
|
| 362 |
+
void fetch_results().then(() => {
|
| 363 |
+
if (captured === "trending") trending_empty = results.length === 0;
|
| 364 |
+
else if (captured === "new") new_empty = results.length === 0;
|
| 365 |
+
});
|
| 366 |
+
} else if (active_content_tab === "search" && search_query.length >= 2) {
|
| 367 |
+
void fetch_results();
|
| 368 |
+
}
|
| 369 |
+
});
|
| 370 |
+
|
| 371 |
+
function handle_search_input(e: Event) {
|
| 372 |
+
search_query = (e.currentTarget as HTMLInputElement).value;
|
| 373 |
+
if (search_timeout) clearTimeout(search_timeout);
|
| 374 |
+
if (is_dataset) {
|
| 375 |
+
loading = true;
|
| 376 |
+
search_timeout = setTimeout(() => void fetch_datasets(search_query), 150);
|
| 377 |
+
return;
|
| 378 |
+
}
|
| 379 |
+
if (is_model) {
|
| 380 |
+
if (search_query.length < 2) {
|
| 381 |
+
if (active_content_tab === "search") results = [];
|
| 382 |
+
return;
|
| 383 |
+
}
|
| 384 |
+
active_content_tab = "search";
|
| 385 |
+
loading = true;
|
| 386 |
+
search_timeout = setTimeout(() => void fetch_models(search_query), 150);
|
| 387 |
+
return;
|
| 388 |
+
}
|
| 389 |
+
if (search_query.length < 2) {
|
| 390 |
+
if (active_content_tab === "search") results = [];
|
| 391 |
+
return;
|
| 392 |
+
}
|
| 393 |
+
active_content_tab = "search";
|
| 394 |
+
loading = true;
|
| 395 |
+
search_timeout = setTimeout(() => void fetch_results(), 150);
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
function select_model(item: SpaceResult) {
|
| 399 |
+
if (!item.pipeline_tag) return;
|
| 400 |
+
const schema = TASK_SCHEMAS[item.pipeline_tag];
|
| 401 |
+
const template = {
|
| 402 |
+
label: item.id.split("/").pop() || item.id,
|
| 403 |
+
kind: "transform" as const,
|
| 404 |
+
source: "model" as const,
|
| 405 |
+
model_id: item.id,
|
| 406 |
+
pipeline_tag: item.pipeline_tag,
|
| 407 |
+
inputs: normalizeOperatorPorts(modality, schema?.inputs ?? []),
|
| 408 |
+
outputs: normalizeOperatorPorts(modality, schema?.outputs ?? []),
|
| 409 |
+
width: 280,
|
| 410 |
+
height: 90
|
| 411 |
+
};
|
| 412 |
+
if (mode === "update" && nodeId) {
|
| 413 |
+
onupdate(nodeId, template);
|
| 414 |
+
} else {
|
| 415 |
+
oncreate(template);
|
| 416 |
+
}
|
| 417 |
+
onclose();
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
async function select_space(space: SpaceResult) {
|
| 421 |
+
if (loading_space_id) return;
|
| 422 |
+
loading_space_id = space.id;
|
| 423 |
+
try {
|
| 424 |
+
const api_info = await fetchSpaceApi(space.id);
|
| 425 |
+
const template = {
|
| 426 |
+
label: space.title || space.id.split("/").pop() || space.id,
|
| 427 |
+
kind: "transform" as const,
|
| 428 |
+
source: "space" as const,
|
| 429 |
+
space_id: space.id,
|
| 430 |
+
pipeline_tag: space.pipeline_tag,
|
| 431 |
+
endpoint: api_info.endpoint,
|
| 432 |
+
endpoints: api_info.endpoints,
|
| 433 |
+
inputs: normalizeOperatorPorts(modality, api_info.inputs),
|
| 434 |
+
outputs: normalizeOperatorPorts(modality, api_info.outputs),
|
| 435 |
+
width: api_info.width,
|
| 436 |
+
height: 90
|
| 437 |
+
};
|
| 438 |
+
if (mode === "update" && nodeId) {
|
| 439 |
+
onupdate(nodeId, template);
|
| 440 |
+
} else {
|
| 441 |
+
oncreate(template);
|
| 442 |
+
}
|
| 443 |
+
onclose();
|
| 444 |
+
} catch (err) {
|
| 445 |
+
loading_space_id = null;
|
| 446 |
+
const msg = err instanceof Error ? err.message : "Couldn't load space";
|
| 447 |
+
const label = space.title || space.id;
|
| 448 |
+
onerror?.(`${label}: ${msg}`);
|
| 449 |
+
}
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
function feature_to_port_type(feature: any): string {
|
| 453 |
+
const t = feature?.type;
|
| 454 |
+
if (!t) return "json";
|
| 455 |
+
if (t._type === "Image" || t.dtype === "image") return "image";
|
| 456 |
+
if (t._type === "Audio" || t.dtype === "audio") return "audio";
|
| 457 |
+
if (t._type === "Video" || t.dtype === "video") return "video";
|
| 458 |
+
if (t._type === "ClassLabel") return "text";
|
| 459 |
+
if (t._type === "Translation" || t._type === "TranslationVariableLanguages")
|
| 460 |
+
return "text";
|
| 461 |
+
if (t._type === "Value") {
|
| 462 |
+
if (t.dtype === "string") return "text";
|
| 463 |
+
if (t.dtype?.includes("int") || t.dtype?.includes("float"))
|
| 464 |
+
return "number";
|
| 465 |
+
if (t.dtype === "bool") return "boolean";
|
| 466 |
+
}
|
| 467 |
+
return "json";
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
async function select_dataset(dataset: SpaceResult) {
|
| 471 |
+
loading_space_id = dataset.id;
|
| 472 |
+
let outputs: Array<{ id: string; label: string; type: string }> = [
|
| 473 |
+
{ id: "out_0", label: "Data", type: "json" }
|
| 474 |
+
];
|
| 475 |
+
let config = "default";
|
| 476 |
+
let split = "train";
|
| 477 |
+
try {
|
| 478 |
+
if (server?.get_dataset_schema) {
|
| 479 |
+
const raw = await server.get_dataset_schema([dataset.id]);
|
| 480 |
+
const schema = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 481 |
+
if (
|
| 482 |
+
!schema.error &&
|
| 483 |
+
Array.isArray(schema.features) &&
|
| 484 |
+
schema.features.length > 0
|
| 485 |
+
) {
|
| 486 |
+
config = schema.config ?? "default";
|
| 487 |
+
split = schema.split ?? "train";
|
| 488 |
+
const ports = schema.features.map((f: any, i: number) => ({
|
| 489 |
+
id: `out_${i}`,
|
| 490 |
+
label: f.name,
|
| 491 |
+
type: feature_to_port_type(f)
|
| 492 |
+
}));
|
| 493 |
+
if (ports.length > 0) outputs = ports;
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
} catch {
|
| 497 |
+
} finally {
|
| 498 |
+
loading_space_id = null;
|
| 499 |
+
}
|
| 500 |
+
oncreate({
|
| 501 |
+
label: dataset.title || dataset.id.split("/").pop() || dataset.id,
|
| 502 |
+
kind: "transform" as const,
|
| 503 |
+
source: "dataset" as const,
|
| 504 |
+
dataset_id: dataset.id,
|
| 505 |
+
dataset_config: config,
|
| 506 |
+
dataset_split: split,
|
| 507 |
+
// Single scalar input: row index. Inline-editable when not wired
|
| 508 |
+
// (the standard `.port-inline-config` block handles the widget);
|
| 509 |
+
// accepts upstream numbers/fns when wired.
|
| 510 |
+
inputs: [
|
| 511 |
+
{
|
| 512 |
+
id: "row_index",
|
| 513 |
+
label: "Row",
|
| 514 |
+
type: "number" as const,
|
| 515 |
+
default_value: 0
|
| 516 |
+
}
|
| 517 |
+
],
|
| 518 |
+
outputs,
|
| 519 |
+
width: 240,
|
| 520 |
+
height: 90
|
| 521 |
+
});
|
| 522 |
+
onclose();
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
function hub_url(id: string): string {
|
| 526 |
+
if (is_dataset) return `https://huggingface.co/datasets/${id}`;
|
| 527 |
+
if (is_model) return `https://huggingface.co/${id}`;
|
| 528 |
+
return `https://huggingface.co/spaces/${id}`;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
function handle_row_click(item: SpaceResult) {
|
| 532 |
+
if (is_dataset) {
|
| 533 |
+
void select_dataset(item);
|
| 534 |
+
} else if (is_model) {
|
| 535 |
+
select_model(item);
|
| 536 |
+
} else {
|
| 537 |
+
select_space(item);
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
function format_likes(n: number): string {
|
| 542 |
+
if (n >= 1000) return `${(n / 1000).toFixed(1)}k`;
|
| 543 |
+
return String(n);
|
| 544 |
+
}
|
| 545 |
+
</script>
|
| 546 |
+
|
| 547 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 548 |
+
<div class="picker-overlay" onclick={onclose}>
|
| 549 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 550 |
+
<div
|
| 551 |
+
class="picker-panel"
|
| 552 |
+
class:picker-panel-anchored={anchorX !== undefined}
|
| 553 |
+
style={anchorX !== undefined
|
| 554 |
+
? `left:${anchorX}px; top:${anchorY ?? 0}px;`
|
| 555 |
+
: ""}
|
| 556 |
+
onclick={(e) => e.stopPropagation()}
|
| 557 |
+
onwheel={(e) => e.stopPropagation()}
|
| 558 |
+
>
|
| 559 |
+
<!-- Search row β input only. Mode tabs (Featured / Trending / New)
|
| 560 |
+
live in the subtab strip below so they share visual weight
|
| 561 |
+
with the modality categories (Generate / Edit / β¦). -->
|
| 562 |
+
<div class="picker-search-row">
|
| 563 |
+
<div class="picker-search-wrap">
|
| 564 |
+
<span class="search-icon">
|
| 565 |
+
<SearchIcon />
|
| 566 |
+
</span>
|
| 567 |
+
<input
|
| 568 |
+
class="picker-search"
|
| 569 |
+
type="text"
|
| 570 |
+
placeholder={search_placeholder}
|
| 571 |
+
value={search_query}
|
| 572 |
+
oninput={handle_search_input}
|
| 573 |
+
autofocus
|
| 574 |
+
/>
|
| 575 |
+
<button
|
| 576 |
+
class="picker-close-inline"
|
| 577 |
+
onclick={onclose}
|
| 578 |
+
aria-label="Close"
|
| 579 |
+
>
|
| 580 |
+
<CloseIcon />
|
| 581 |
+
</button>
|
| 582 |
+
</div>
|
| 583 |
+
</div>
|
| 584 |
+
|
| 585 |
+
<!-- Source toggle (Spaces / Models) β hidden for datasets -->
|
| 586 |
+
{#if show_source_toggle}
|
| 587 |
+
<div class="picker-source-row">
|
| 588 |
+
<button
|
| 589 |
+
class="picker-source-btn"
|
| 590 |
+
class:active={source === "spaces"}
|
| 591 |
+
onclick={() => set_source("spaces")}>Spaces</button
|
| 592 |
+
>
|
| 593 |
+
<button
|
| 594 |
+
class="picker-source-btn"
|
| 595 |
+
class:active={source === "models"}
|
| 596 |
+
onclick={() => set_source("models")}>Models</button
|
| 597 |
+
>
|
| 598 |
+
</div>
|
| 599 |
+
{/if}
|
| 600 |
+
|
| 601 |
+
<!-- Modality subtabs: which kind of Space (Generate / Edit / β¦). -->
|
| 602 |
+
{#if !is_dataset && visible_subtabs.length > 1}
|
| 603 |
+
<div class="picker-subtabs">
|
| 604 |
+
{#each visible_subtabs as st}
|
| 605 |
+
<button
|
| 606 |
+
class="picker-subtab"
|
| 607 |
+
class:active={active_subtab.key === st.key}
|
| 608 |
+
onclick={() => {
|
| 609 |
+
// Reset emptiness flags BEFORE writing active_subtab /
|
| 610 |
+
// active_content_tab. Otherwise the auto-switch effect
|
| 611 |
+
// can fire first and read a stale `trending_empty=true`
|
| 612 |
+
// from the previous subtab, bumping active_content_tab
|
| 613 |
+
// to "search" β which then fetches the wrong list.
|
| 614 |
+
trending_empty = null;
|
| 615 |
+
new_empty = null;
|
| 616 |
+
active_subtab = st;
|
| 617 |
+
if (active_content_tab !== "search")
|
| 618 |
+
active_content_tab = "trending";
|
| 619 |
+
}}
|
| 620 |
+
>
|
| 621 |
+
{st.label}
|
| 622 |
+
</button>
|
| 623 |
+
{/each}
|
| 624 |
+
</div>
|
| 625 |
+
{/if}
|
| 626 |
+
|
| 627 |
+
<!-- Content modes: how the list is sorted (Featured / Trending / New).
|
| 628 |
+
Smaller and lighter than the category subtabs so they read as
|
| 629 |
+
a secondary sort control, not a competing category. -->
|
| 630 |
+
{#if !is_dataset}
|
| 631 |
+
<div class="picker-mode-row">
|
| 632 |
+
<span class="picker-mode-label">Sort:</span>
|
| 633 |
+
{#if featured_results.length > 0}
|
| 634 |
+
<button
|
| 635 |
+
class="picker-mode-btn"
|
| 636 |
+
class:active={active_content_tab === "featured"}
|
| 637 |
+
onclick={() => {
|
| 638 |
+
active_content_tab = "featured";
|
| 639 |
+
search_query = "";
|
| 640 |
+
}}>Featured</button
|
| 641 |
+
>
|
| 642 |
+
{/if}
|
| 643 |
+
{#if trending_empty !== true}
|
| 644 |
+
<button
|
| 645 |
+
class="picker-mode-btn"
|
| 646 |
+
class:active={active_content_tab === "trending"}
|
| 647 |
+
onclick={() => {
|
| 648 |
+
active_content_tab = "trending";
|
| 649 |
+
search_query = "";
|
| 650 |
+
}}>Trending</button
|
| 651 |
+
>
|
| 652 |
+
{/if}
|
| 653 |
+
{#if new_empty !== true}
|
| 654 |
+
<button
|
| 655 |
+
class="picker-mode-btn"
|
| 656 |
+
class:active={active_content_tab === "new"}
|
| 657 |
+
onclick={() => {
|
| 658 |
+
active_content_tab = "new";
|
| 659 |
+
search_query = "";
|
| 660 |
+
}}>New β¦</button
|
| 661 |
+
>
|
| 662 |
+
{/if}
|
| 663 |
+
{#if is_spaces}
|
| 664 |
+
<label
|
| 665 |
+
class="picker-zerogpu-toggle"
|
| 666 |
+
title="Show only ZeroGPU Spaces β these scale with your HF credits and rarely hit quota"
|
| 667 |
+
>
|
| 668 |
+
<input type="checkbox" bind:checked={zero_gpu_only} />
|
| 669 |
+
<span>ZeroGPU only</span>
|
| 670 |
+
</label>
|
| 671 |
+
{/if}
|
| 672 |
+
</div>
|
| 673 |
+
{/if}
|
| 674 |
+
|
| 675 |
+
<!-- Results -->
|
| 676 |
+
<div class="picker-results" class:picker-results-stale={loading}>
|
| 677 |
+
{#if loading && display_results.length === 0 && active_content_tab !== "featured"}
|
| 678 |
+
<div class="picker-loading">
|
| 679 |
+
<span class="spinner"></span>
|
| 680 |
+
</div>
|
| 681 |
+
{:else if display_results.length === 0}
|
| 682 |
+
<div class="picker-empty">
|
| 683 |
+
{active_content_tab === "search"
|
| 684 |
+
? "Nothing found"
|
| 685 |
+
: active_content_tab === "featured"
|
| 686 |
+
? `No featured ${source} for ${modality.label.toLowerCase()} yet`
|
| 687 |
+
: `No ${modality.label.toLowerCase()} ${source} found`}
|
| 688 |
+
</div>
|
| 689 |
+
{:else}
|
| 690 |
+
{#each display_results as space (space.id)}
|
| 691 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 692 |
+
<div
|
| 693 |
+
class="space-row"
|
| 694 |
+
class:loading={loading_space_id === space.id}
|
| 695 |
+
onclick={() => handle_row_click(space)}
|
| 696 |
+
role="button"
|
| 697 |
+
tabindex="0"
|
| 698 |
+
>
|
| 699 |
+
<div
|
| 700 |
+
class="space-avatar"
|
| 701 |
+
style="background:linear-gradient(135deg, {avatar_color(
|
| 702 |
+
space.id
|
| 703 |
+
)}, {avatar_color(space.id + '_2')})"
|
| 704 |
+
>
|
| 705 |
+
{avatar_initial(space.id)}
|
| 706 |
+
</div>
|
| 707 |
+
<div class="space-row-left">
|
| 708 |
+
<div class="space-name-row">
|
| 709 |
+
<span class="space-name"
|
| 710 |
+
>{space.title ||
|
| 711 |
+
(space.id.split("/").pop() ?? space.id)}</span
|
| 712 |
+
>
|
| 713 |
+
{#if active_content_tab === "featured"}
|
| 714 |
+
<span class="space-badge space-badge-featured">Featured</span>
|
| 715 |
+
{/if}
|
| 716 |
+
{#if space.pipeline_tag}
|
| 717 |
+
<span class="space-badge">{space.pipeline_tag}</span>
|
| 718 |
+
{/if}
|
| 719 |
+
</div>
|
| 720 |
+
{#if space.description}
|
| 721 |
+
<div class="space-desc">{space.description}</div>
|
| 722 |
+
{/if}
|
| 723 |
+
</div>
|
| 724 |
+
<div class="space-row-right">
|
| 725 |
+
{#if loading_space_id === space.id}
|
| 726 |
+
<span class="spinner small"></span>
|
| 727 |
+
{:else if space.likes > 0}
|
| 728 |
+
<span class="space-likes">β₯ {format_likes(space.likes)}</span>
|
| 729 |
+
{/if}
|
| 730 |
+
<a
|
| 731 |
+
class="space-row-link"
|
| 732 |
+
href={hub_url(space.id)}
|
| 733 |
+
target="_blank"
|
| 734 |
+
rel="noopener noreferrer"
|
| 735 |
+
title="Open on HuggingFace"
|
| 736 |
+
aria-label="Open on HuggingFace"
|
| 737 |
+
onclick={(e) => e.stopPropagation()}
|
| 738 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 739 |
+
>
|
| 740 |
+
<OpenLinkIcon />
|
| 741 |
+
</a>
|
| 742 |
+
</div>
|
| 743 |
+
</div>
|
| 744 |
+
{/each}
|
| 745 |
+
{/if}
|
| 746 |
+
</div>
|
| 747 |
+
</div>
|
| 748 |
+
</div>
|
| 749 |
+
|
| 750 |
+
<style>
|
| 751 |
+
/* Reuse toast-in animation from WorkflowCanvas.css */
|
| 752 |
+
@keyframes wf-toast-in {
|
| 753 |
+
from {
|
| 754 |
+
opacity: 0;
|
| 755 |
+
transform: translateY(6px);
|
| 756 |
+
}
|
| 757 |
+
to {
|
| 758 |
+
opacity: 1;
|
| 759 |
+
transform: translateY(0);
|
| 760 |
+
}
|
| 761 |
+
}
|
| 762 |
+
.picker-overlay {
|
| 763 |
+
position: absolute;
|
| 764 |
+
inset: 0;
|
| 765 |
+
z-index: 50;
|
| 766 |
+
pointer-events: none;
|
| 767 |
+
display: flex;
|
| 768 |
+
align-items: center;
|
| 769 |
+
justify-content: center;
|
| 770 |
+
/* Compensate for the bottom bar (~60px) so the panel is centered in
|
| 771 |
+
* the visible canvas area, not the raw viewport. Extra few px of
|
| 772 |
+
* bottom padding keeps the optical center balanced against the top
|
| 773 |
+
* toolbar. */
|
| 774 |
+
padding-bottom: 72px;
|
| 775 |
+
padding-top: 8px;
|
| 776 |
+
box-sizing: border-box;
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
.picker-panel {
|
| 780 |
+
pointer-events: auto;
|
| 781 |
+
width: 520px;
|
| 782 |
+
/* Lock the panel to a fixed height so switching tabs (Featured /
|
| 783 |
+
* Trending / New) doesn't make the modal jump up and down. The
|
| 784 |
+
* results list scrolls inside; on short viewports we cap to leave
|
| 785 |
+
* room for the toolbar and bottom bar. */
|
| 786 |
+
height: min(620px, calc(100vh - 160px));
|
| 787 |
+
background: #13141c;
|
| 788 |
+
border: 1px solid #2a2b36;
|
| 789 |
+
border-radius: 16px;
|
| 790 |
+
box-shadow:
|
| 791 |
+
0 20px 60px rgba(0, 0, 0, 0.6),
|
| 792 |
+
0 0 0 1px rgba(255, 255, 255, 0.04);
|
| 793 |
+
display: flex;
|
| 794 |
+
flex-direction: column;
|
| 795 |
+
overflow: hidden;
|
| 796 |
+
animation: wf-toast-in 0.12s ease-out;
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
.picker-panel-anchored {
|
| 800 |
+
position: absolute;
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
.picker-close-inline {
|
| 804 |
+
position: absolute;
|
| 805 |
+
right: 8px;
|
| 806 |
+
top: 50%;
|
| 807 |
+
transform: translateY(-50%);
|
| 808 |
+
width: 22px;
|
| 809 |
+
height: 22px;
|
| 810 |
+
border: none;
|
| 811 |
+
border-radius: 50%;
|
| 812 |
+
background: transparent;
|
| 813 |
+
color: #5c5e6a;
|
| 814 |
+
font-size: 16px;
|
| 815 |
+
line-height: 1;
|
| 816 |
+
cursor: pointer;
|
| 817 |
+
display: flex;
|
| 818 |
+
align-items: center;
|
| 819 |
+
justify-content: center;
|
| 820 |
+
flex-shrink: 0;
|
| 821 |
+
padding: 0;
|
| 822 |
+
transition:
|
| 823 |
+
background 0.15s,
|
| 824 |
+
color 0.15s;
|
| 825 |
+
}
|
| 826 |
+
|
| 827 |
+
.picker-close-inline:hover {
|
| 828 |
+
background: #1e1f2a;
|
| 829 |
+
color: #a0a2ae;
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
+
:global(body:not(.dark)) .picker-close-inline {
|
| 833 |
+
color: #8b8d98;
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
:global(body:not(.dark)) .picker-close-inline:hover {
|
| 837 |
+
background: rgba(0, 0, 0, 0.06);
|
| 838 |
+
color: #3e4050;
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
.picker-search-row {
|
| 842 |
+
padding: 14px 16px 0;
|
| 843 |
+
flex-shrink: 0;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
.picker-search-wrap {
|
| 847 |
+
position: relative;
|
| 848 |
+
display: flex;
|
| 849 |
+
align-items: center;
|
| 850 |
+
}
|
| 851 |
+
|
| 852 |
+
.picker-mode-row {
|
| 853 |
+
display: flex;
|
| 854 |
+
align-items: center;
|
| 855 |
+
gap: 4px;
|
| 856 |
+
padding: 6px 16px 0;
|
| 857 |
+
flex-shrink: 0;
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
.picker-mode-label {
|
| 861 |
+
font-family: "Manrope", sans-serif;
|
| 862 |
+
font-size: 10px;
|
| 863 |
+
font-weight: 700;
|
| 864 |
+
text-transform: uppercase;
|
| 865 |
+
letter-spacing: 0.06em;
|
| 866 |
+
color: #4a4d57;
|
| 867 |
+
margin-right: 4px;
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
.picker-mode-btn {
|
| 871 |
+
padding: 3px 8px;
|
| 872 |
+
border: none;
|
| 873 |
+
border-radius: 14px;
|
| 874 |
+
background: transparent;
|
| 875 |
+
color: #6b6e78;
|
| 876 |
+
font-family: "Manrope", sans-serif;
|
| 877 |
+
font-size: 11px;
|
| 878 |
+
font-weight: 500;
|
| 879 |
+
cursor: pointer;
|
| 880 |
+
transition:
|
| 881 |
+
background 0.1s,
|
| 882 |
+
color 0.1s;
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
.picker-mode-btn:hover {
|
| 886 |
+
color: #c8c9d2;
|
| 887 |
+
background: rgba(255, 255, 255, 0.04);
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
.picker-mode-btn.active {
|
| 891 |
+
color: #f97316;
|
| 892 |
+
background: rgba(249, 115, 22, 0.08);
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
.picker-zerogpu-toggle {
|
| 896 |
+
margin-left: auto;
|
| 897 |
+
display: inline-flex;
|
| 898 |
+
align-items: center;
|
| 899 |
+
gap: 5px;
|
| 900 |
+
font-size: 10.5px;
|
| 901 |
+
color: #6b6e78;
|
| 902 |
+
cursor: pointer;
|
| 903 |
+
user-select: none;
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
.picker-zerogpu-toggle input {
|
| 907 |
+
accent-color: #f97316;
|
| 908 |
+
cursor: pointer;
|
| 909 |
+
margin: 0;
|
| 910 |
+
}
|
| 911 |
+
|
| 912 |
+
.picker-zerogpu-toggle:hover {
|
| 913 |
+
color: #a0a2ae;
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
:global(body:not(.dark)) .picker-zerogpu-toggle {
|
| 917 |
+
color: #6b6e78;
|
| 918 |
+
}
|
| 919 |
+
|
| 920 |
+
:global(body:not(.dark)) .picker-zerogpu-toggle:hover {
|
| 921 |
+
color: #3e4050;
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
:global(body:not(.dark)) .picker-mode-label {
|
| 925 |
+
color: #8b8d98;
|
| 926 |
+
}
|
| 927 |
+
|
| 928 |
+
:global(body:not(.dark)) .picker-mode-btn {
|
| 929 |
+
color: #8b8d98;
|
| 930 |
+
}
|
| 931 |
+
|
| 932 |
+
:global(body:not(.dark)) .picker-mode-btn:hover {
|
| 933 |
+
color: #3e4050;
|
| 934 |
+
background: rgba(0, 0, 0, 0.04);
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
:global(body:not(.dark)) .picker-mode-btn.active {
|
| 938 |
+
color: #ea580c;
|
| 939 |
+
background: rgba(249, 115, 22, 0.1);
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
.search-icon {
|
| 943 |
+
position: absolute;
|
| 944 |
+
left: 13px;
|
| 945 |
+
display: inline-flex;
|
| 946 |
+
color: #4a4d57;
|
| 947 |
+
pointer-events: none;
|
| 948 |
+
flex-shrink: 0;
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
.picker-search {
|
| 952 |
+
flex: 1;
|
| 953 |
+
min-width: 0;
|
| 954 |
+
padding: 11px 40px 11px 36px;
|
| 955 |
+
background: #0c0d10;
|
| 956 |
+
border: 1px solid #2a2b36;
|
| 957 |
+
border-radius: 10px;
|
| 958 |
+
font-family: "Manrope", sans-serif;
|
| 959 |
+
font-size: 14px;
|
| 960 |
+
color: #d5d6de;
|
| 961 |
+
outline: none;
|
| 962 |
+
transition:
|
| 963 |
+
border-color 0.15s,
|
| 964 |
+
box-shadow 0.15s;
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
.picker-search::placeholder {
|
| 968 |
+
color: #3e4050;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
.picker-search:focus {
|
| 972 |
+
border-color: #f97316;
|
| 973 |
+
box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
|
| 974 |
+
}
|
| 975 |
+
|
| 976 |
+
.picker-source-row {
|
| 977 |
+
display: flex;
|
| 978 |
+
gap: 4px;
|
| 979 |
+
padding: 8px 10px 0;
|
| 980 |
+
flex-shrink: 0;
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
.picker-source-btn {
|
| 984 |
+
flex: 1;
|
| 985 |
+
padding: 6px 10px;
|
| 986 |
+
border: 1px solid #1e1f2a;
|
| 987 |
+
border-radius: 6px;
|
| 988 |
+
background: transparent;
|
| 989 |
+
color: #6b6e78;
|
| 990 |
+
font-family: "Manrope", sans-serif;
|
| 991 |
+
font-size: 11.5px;
|
| 992 |
+
font-weight: 600;
|
| 993 |
+
cursor: pointer;
|
| 994 |
+
transition:
|
| 995 |
+
background 0.15s,
|
| 996 |
+
color 0.15s,
|
| 997 |
+
border-color 0.15s;
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
.picker-source-btn:hover {
|
| 1001 |
+
background: rgba(255, 255, 255, 0.04);
|
| 1002 |
+
color: #c8c9d2;
|
| 1003 |
+
}
|
| 1004 |
+
|
| 1005 |
+
.picker-source-btn.active {
|
| 1006 |
+
background: rgba(249, 115, 22, 0.12);
|
| 1007 |
+
border-color: rgba(249, 115, 22, 0.35);
|
| 1008 |
+
color: #f97316;
|
| 1009 |
+
}
|
| 1010 |
+
|
| 1011 |
+
:global(body:not(.dark)) .picker-source-btn {
|
| 1012 |
+
border-color: #e2e4ea;
|
| 1013 |
+
color: #6b6e78;
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
:global(body:not(.dark)) .picker-source-btn:hover {
|
| 1017 |
+
background: #f0f1f5;
|
| 1018 |
+
color: #1a1b25;
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
:global(body:not(.dark)) .picker-source-btn.active {
|
| 1022 |
+
background: rgba(249, 115, 22, 0.1);
|
| 1023 |
+
border-color: rgba(249, 115, 22, 0.35);
|
| 1024 |
+
color: #d65500;
|
| 1025 |
+
}
|
| 1026 |
+
|
| 1027 |
+
.picker-subtabs {
|
| 1028 |
+
display: flex;
|
| 1029 |
+
gap: 2px;
|
| 1030 |
+
padding: 8px 10px 0;
|
| 1031 |
+
flex-shrink: 0;
|
| 1032 |
+
flex-wrap: wrap;
|
| 1033 |
+
}
|
| 1034 |
+
|
| 1035 |
+
.picker-subtab {
|
| 1036 |
+
padding: 4px 10px;
|
| 1037 |
+
border: 1px solid transparent;
|
| 1038 |
+
border-radius: 20px;
|
| 1039 |
+
background: transparent;
|
| 1040 |
+
color: #5c5e6a;
|
| 1041 |
+
font-family: "Manrope", sans-serif;
|
| 1042 |
+
font-size: 11px;
|
| 1043 |
+
font-weight: 600;
|
| 1044 |
+
cursor: pointer;
|
| 1045 |
+
transition:
|
| 1046 |
+
background 0.15s,
|
| 1047 |
+
color 0.15s,
|
| 1048 |
+
border-color 0.15s;
|
| 1049 |
+
}
|
| 1050 |
+
|
| 1051 |
+
.picker-subtab:hover {
|
| 1052 |
+
background: rgba(255, 255, 255, 0.05);
|
| 1053 |
+
color: #a0a2ae;
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
.picker-subtab.active {
|
| 1057 |
+
background: rgba(249, 115, 22, 0.12);
|
| 1058 |
+
border-color: rgba(249, 115, 22, 0.3);
|
| 1059 |
+
color: #f97316;
|
| 1060 |
+
}
|
| 1061 |
+
|
| 1062 |
+
.picker-tabs {
|
| 1063 |
+
display: flex;
|
| 1064 |
+
gap: 0;
|
| 1065 |
+
padding: 8px 10px 0;
|
| 1066 |
+
border-bottom: 1px solid #1e1f2a;
|
| 1067 |
+
flex-shrink: 0;
|
| 1068 |
+
}
|
| 1069 |
+
|
| 1070 |
+
.picker-tab {
|
| 1071 |
+
padding: 6px 14px;
|
| 1072 |
+
border: none;
|
| 1073 |
+
border-bottom: 2px solid transparent;
|
| 1074 |
+
background: transparent;
|
| 1075 |
+
color: #5c5e6a;
|
| 1076 |
+
font-family: "Manrope", sans-serif;
|
| 1077 |
+
font-size: 12px;
|
| 1078 |
+
font-weight: 600;
|
| 1079 |
+
cursor: pointer;
|
| 1080 |
+
margin-bottom: -1px;
|
| 1081 |
+
transition:
|
| 1082 |
+
color 0.15s,
|
| 1083 |
+
border-color 0.15s;
|
| 1084 |
+
}
|
| 1085 |
+
|
| 1086 |
+
.picker-tab:hover {
|
| 1087 |
+
color: #a0a2ae;
|
| 1088 |
+
}
|
| 1089 |
+
|
| 1090 |
+
.picker-tab.active {
|
| 1091 |
+
color: #d5d6de;
|
| 1092 |
+
border-bottom-color: #f97316;
|
| 1093 |
+
}
|
| 1094 |
+
|
| 1095 |
+
.picker-results {
|
| 1096 |
+
flex: 1;
|
| 1097 |
+
overflow-y: auto;
|
| 1098 |
+
padding: 6px 8px 10px;
|
| 1099 |
+
scrollbar-width: thin;
|
| 1100 |
+
scrollbar-color: #2a2b36 transparent;
|
| 1101 |
+
transition: opacity 0.12s ease;
|
| 1102 |
+
}
|
| 1103 |
+
|
| 1104 |
+
.picker-results-stale {
|
| 1105 |
+
opacity: 0.55;
|
| 1106 |
+
}
|
| 1107 |
+
|
| 1108 |
+
.picker-loading {
|
| 1109 |
+
display: flex;
|
| 1110 |
+
justify-content: center;
|
| 1111 |
+
padding: 60px;
|
| 1112 |
+
}
|
| 1113 |
+
|
| 1114 |
+
.picker-empty {
|
| 1115 |
+
text-align: center;
|
| 1116 |
+
padding: 60px 24px;
|
| 1117 |
+
font-family: "Manrope", sans-serif;
|
| 1118 |
+
font-size: 13px;
|
| 1119 |
+
color: #4a4d57;
|
| 1120 |
+
}
|
| 1121 |
+
|
| 1122 |
+
.space-avatar {
|
| 1123 |
+
width: 52px;
|
| 1124 |
+
height: 52px;
|
| 1125 |
+
border-radius: 12px;
|
| 1126 |
+
font-size: 22px;
|
| 1127 |
+
font-weight: 700;
|
| 1128 |
+
color: rgba(0, 0, 0, 0.55);
|
| 1129 |
+
display: flex;
|
| 1130 |
+
align-items: center;
|
| 1131 |
+
justify-content: center;
|
| 1132 |
+
flex-shrink: 0;
|
| 1133 |
+
text-shadow: 0 1px 2px rgba(255, 255, 255, 0.15);
|
| 1134 |
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
|
| 1135 |
+
}
|
| 1136 |
+
|
| 1137 |
+
.space-row {
|
| 1138 |
+
display: flex;
|
| 1139 |
+
align-items: center;
|
| 1140 |
+
gap: 14px;
|
| 1141 |
+
padding: 10px 12px;
|
| 1142 |
+
border-radius: 10px;
|
| 1143 |
+
cursor: pointer;
|
| 1144 |
+
transition: background 0.12s;
|
| 1145 |
+
}
|
| 1146 |
+
|
| 1147 |
+
.space-row:hover {
|
| 1148 |
+
background: rgba(255, 255, 255, 0.04);
|
| 1149 |
+
}
|
| 1150 |
+
|
| 1151 |
+
.space-row.loading {
|
| 1152 |
+
opacity: 0.6;
|
| 1153 |
+
pointer-events: none;
|
| 1154 |
+
}
|
| 1155 |
+
|
| 1156 |
+
.space-row-left {
|
| 1157 |
+
flex: 1;
|
| 1158 |
+
min-width: 0;
|
| 1159 |
+
}
|
| 1160 |
+
|
| 1161 |
+
.space-name-row {
|
| 1162 |
+
display: flex;
|
| 1163 |
+
align-items: center;
|
| 1164 |
+
gap: 8px;
|
| 1165 |
+
min-width: 0;
|
| 1166 |
+
}
|
| 1167 |
+
|
| 1168 |
+
.space-name {
|
| 1169 |
+
font-family: "Manrope", sans-serif;
|
| 1170 |
+
font-size: 14px;
|
| 1171 |
+
font-weight: 700;
|
| 1172 |
+
color: #e8e9f0;
|
| 1173 |
+
white-space: nowrap;
|
| 1174 |
+
overflow: hidden;
|
| 1175 |
+
text-overflow: ellipsis;
|
| 1176 |
+
}
|
| 1177 |
+
|
| 1178 |
+
.space-badge {
|
| 1179 |
+
display: inline-flex;
|
| 1180 |
+
align-items: center;
|
| 1181 |
+
padding: 2px 7px;
|
| 1182 |
+
border-radius: 10px;
|
| 1183 |
+
background: rgba(255, 255, 255, 0.06);
|
| 1184 |
+
color: #8b8d98;
|
| 1185 |
+
font-family: "Manrope", sans-serif;
|
| 1186 |
+
font-size: 10px;
|
| 1187 |
+
font-weight: 600;
|
| 1188 |
+
white-space: nowrap;
|
| 1189 |
+
flex-shrink: 0;
|
| 1190 |
+
}
|
| 1191 |
+
|
| 1192 |
+
.space-badge-featured {
|
| 1193 |
+
background: rgba(249, 115, 22, 0.14);
|
| 1194 |
+
color: #f97316;
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
.space-desc {
|
| 1198 |
+
font-family: "Manrope", sans-serif;
|
| 1199 |
+
font-size: 12.5px;
|
| 1200 |
+
color: #7a7d88;
|
| 1201 |
+
margin-top: 3px;
|
| 1202 |
+
white-space: nowrap;
|
| 1203 |
+
overflow: hidden;
|
| 1204 |
+
text-overflow: ellipsis;
|
| 1205 |
+
line-height: 1.35;
|
| 1206 |
+
}
|
| 1207 |
+
|
| 1208 |
+
.space-row-right {
|
| 1209 |
+
display: flex;
|
| 1210 |
+
align-items: center;
|
| 1211 |
+
gap: 10px;
|
| 1212 |
+
flex-shrink: 0;
|
| 1213 |
+
}
|
| 1214 |
+
|
| 1215 |
+
.space-likes {
|
| 1216 |
+
font-family: "Manrope", sans-serif;
|
| 1217 |
+
font-size: 11px;
|
| 1218 |
+
font-weight: 600;
|
| 1219 |
+
color: #4a4d57;
|
| 1220 |
+
}
|
| 1221 |
+
|
| 1222 |
+
.space-row-link {
|
| 1223 |
+
display: inline-flex;
|
| 1224 |
+
align-items: center;
|
| 1225 |
+
justify-content: center;
|
| 1226 |
+
width: 22px;
|
| 1227 |
+
height: 22px;
|
| 1228 |
+
border-radius: 6px;
|
| 1229 |
+
color: #4a4d57;
|
| 1230 |
+
text-decoration: none;
|
| 1231 |
+
opacity: 0;
|
| 1232 |
+
transition:
|
| 1233 |
+
opacity 0.15s,
|
| 1234 |
+
color 0.15s,
|
| 1235 |
+
background 0.15s;
|
| 1236 |
+
}
|
| 1237 |
+
|
| 1238 |
+
.space-row:hover .space-row-link,
|
| 1239 |
+
.space-row:focus-within .space-row-link {
|
| 1240 |
+
opacity: 1;
|
| 1241 |
+
}
|
| 1242 |
+
|
| 1243 |
+
.space-row-link:hover {
|
| 1244 |
+
color: #f97316;
|
| 1245 |
+
background: rgba(249, 115, 22, 0.08);
|
| 1246 |
+
}
|
| 1247 |
+
|
| 1248 |
+
.spinner {
|
| 1249 |
+
display: inline-block;
|
| 1250 |
+
width: 18px;
|
| 1251 |
+
height: 18px;
|
| 1252 |
+
border: 2px solid #2a2b36;
|
| 1253 |
+
border-top-color: #f97316;
|
| 1254 |
+
border-radius: 50%;
|
| 1255 |
+
animation: spin 0.7s linear infinite;
|
| 1256 |
+
}
|
| 1257 |
+
|
| 1258 |
+
.spinner.small {
|
| 1259 |
+
width: 14px;
|
| 1260 |
+
height: 14px;
|
| 1261 |
+
border-width: 1.5px;
|
| 1262 |
+
}
|
| 1263 |
+
|
| 1264 |
+
@keyframes spin {
|
| 1265 |
+
to {
|
| 1266 |
+
transform: rotate(360deg);
|
| 1267 |
+
}
|
| 1268 |
+
}
|
| 1269 |
+
|
| 1270 |
+
/* Light mode */
|
| 1271 |
+
:global(body:not(.dark)) .picker-panel {
|
| 1272 |
+
background: #ffffff;
|
| 1273 |
+
border-color: #e2e4ea;
|
| 1274 |
+
box-shadow:
|
| 1275 |
+
0 12px 40px rgba(0, 0, 0, 0.12),
|
| 1276 |
+
0 0 0 1px rgba(0, 0, 0, 0.04);
|
| 1277 |
+
}
|
| 1278 |
+
|
| 1279 |
+
:global(body:not(.dark)) .picker-search {
|
| 1280 |
+
background: #f8f9fb;
|
| 1281 |
+
border-color: #e2e4ea;
|
| 1282 |
+
color: #1a1b25;
|
| 1283 |
+
}
|
| 1284 |
+
|
| 1285 |
+
:global(body:not(.dark)) .picker-search::placeholder {
|
| 1286 |
+
color: #b0b2bc;
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
:global(body:not(.dark)) .picker-search:focus {
|
| 1290 |
+
background: #ffffff;
|
| 1291 |
+
}
|
| 1292 |
+
|
| 1293 |
+
:global(body:not(.dark)) .picker-tabs {
|
| 1294 |
+
border-bottom-color: #e2e4ea;
|
| 1295 |
+
}
|
| 1296 |
+
|
| 1297 |
+
:global(body:not(.dark)) .picker-tab {
|
| 1298 |
+
color: #8b8d98;
|
| 1299 |
+
}
|
| 1300 |
+
|
| 1301 |
+
:global(body:not(.dark)) .picker-tab.active {
|
| 1302 |
+
color: #1a1b25;
|
| 1303 |
+
}
|
| 1304 |
+
|
| 1305 |
+
:global(body:not(.dark)) .space-row:hover {
|
| 1306 |
+
background: #f4f5f8;
|
| 1307 |
+
}
|
| 1308 |
+
|
| 1309 |
+
:global(body:not(.dark)) .space-name {
|
| 1310 |
+
color: #1a1b25;
|
| 1311 |
+
}
|
| 1312 |
+
|
| 1313 |
+
:global(body:not(.dark)) .space-desc {
|
| 1314 |
+
color: #6b6e78;
|
| 1315 |
+
}
|
| 1316 |
+
|
| 1317 |
+
:global(body:not(.dark)) .space-badge {
|
| 1318 |
+
background: #eef0f4;
|
| 1319 |
+
color: #6b6e78;
|
| 1320 |
+
}
|
| 1321 |
+
|
| 1322 |
+
:global(body:not(.dark)) .space-badge-featured {
|
| 1323 |
+
background: rgba(249, 115, 22, 0.12);
|
| 1324 |
+
color: #c84a00;
|
| 1325 |
+
}
|
| 1326 |
+
|
| 1327 |
+
:global(body:not(.dark)) .space-likes {
|
| 1328 |
+
color: #b0b2bc;
|
| 1329 |
+
}
|
| 1330 |
+
|
| 1331 |
+
:global(body:not(.dark)) .picker-empty {
|
| 1332 |
+
color: #b0b2bc;
|
| 1333 |
+
}
|
| 1334 |
+
|
| 1335 |
+
:global(body:not(.dark)) .space-avatar {
|
| 1336 |
+
color: rgba(0, 0, 0, 0.55);
|
| 1337 |
+
}
|
| 1338 |
+
</style>
|
6.17.1/workflowcanvas/workflow/NodeWidget.svelte
ADDED
|
@@ -0,0 +1,690 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type {
|
| 3 |
+
WFNode,
|
| 4 |
+
PortType,
|
| 5 |
+
NodeDataValue,
|
| 6 |
+
FileValue
|
| 7 |
+
} from "./workflow-types";
|
| 8 |
+
import { BaseTextbox } from "@gradio/textbox";
|
| 9 |
+
import { BaseStaticImage } from "@gradio/image";
|
| 10 |
+
import DownloadIcon from "./icons/DownloadIcon.svelte";
|
| 11 |
+
|
| 12 |
+
interface Props {
|
| 13 |
+
node: WFNode;
|
| 14 |
+
widgetPortId: string;
|
| 15 |
+
widgetType: PortType;
|
| 16 |
+
isReadonly: boolean;
|
| 17 |
+
ondatachange: (
|
| 18 |
+
nodeId: string,
|
| 19 |
+
portId: string,
|
| 20 |
+
value: NodeDataValue
|
| 21 |
+
) => void;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
let { node, widgetPortId, widgetType, isReadonly, ondatachange }: Props =
|
| 25 |
+
$props();
|
| 26 |
+
|
| 27 |
+
let fileInputEl: HTMLInputElement | undefined = $state();
|
| 28 |
+
|
| 29 |
+
function getTextValue(): string {
|
| 30 |
+
const v = node.data?.[widgetPortId];
|
| 31 |
+
return typeof v === "string" ? v : "";
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function getFileValue(): FileValue | null {
|
| 35 |
+
const v = node.data?.[widgetPortId];
|
| 36 |
+
return v && typeof v === "object" ? v : null;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
function getNumberValue(): number {
|
| 40 |
+
const v = node.data?.[widgetPortId];
|
| 41 |
+
return typeof v === "number" ? v : 0;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function getBooleanValue(): boolean {
|
| 45 |
+
const v = node.data?.[widgetPortId];
|
| 46 |
+
return typeof v === "boolean" ? v : false;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function handleNumberInput(e: Event) {
|
| 50 |
+
const target = e.currentTarget as HTMLInputElement;
|
| 51 |
+
ondatachange(node.id, widgetPortId, parseFloat(target.value) || 0);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function handleBooleanInput(e: Event) {
|
| 55 |
+
const target = e.currentTarget as HTMLInputElement;
|
| 56 |
+
ondatachange(node.id, widgetPortId, target.checked);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function revoke_old_blob(): void {
|
| 60 |
+
const old = getFileValue();
|
| 61 |
+
if (old?.url?.startsWith("blob:")) URL.revokeObjectURL(old.url);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function adopt_file(file: File): void {
|
| 65 |
+
revoke_old_blob();
|
| 66 |
+
ondatachange(node.id, widgetPortId, {
|
| 67 |
+
name: file.name,
|
| 68 |
+
url: URL.createObjectURL(file),
|
| 69 |
+
mime: file.type
|
| 70 |
+
});
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function handleFileSelect(e: Event) {
|
| 74 |
+
const file = (e.currentTarget as HTMLInputElement).files?.[0];
|
| 75 |
+
if (file) adopt_file(file);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function handleFileDrop(e: DragEvent) {
|
| 79 |
+
e.preventDefault();
|
| 80 |
+
e.stopPropagation();
|
| 81 |
+
const file = e.dataTransfer?.files?.[0];
|
| 82 |
+
if (file) adopt_file(file);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function clearFile() {
|
| 86 |
+
revoke_old_blob();
|
| 87 |
+
ondatachange(node.id, widgetPortId, null);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Download the current file value. Same-origin and blob/data URLs work
|
| 92 |
+
* via a direct `<a download>`. Cross-origin URLs (e.g. HF Inference
|
| 93 |
+
* results) often ignore the download attribute and navigate instead,
|
| 94 |
+
* so we fetch into a blob first and then trigger the link on the
|
| 95 |
+
* resulting object URL β that forces a save instead of a tab swap.
|
| 96 |
+
*/
|
| 97 |
+
async function downloadFile() {
|
| 98 |
+
const v = getFileValue();
|
| 99 |
+
if (!v?.url) return;
|
| 100 |
+
const name = v.name || "download";
|
| 101 |
+
const sameOrigin =
|
| 102 |
+
v.url.startsWith("blob:") ||
|
| 103 |
+
v.url.startsWith("data:") ||
|
| 104 |
+
(v.url.startsWith("http") &&
|
| 105 |
+
new URL(v.url, window.location.origin).origin ===
|
| 106 |
+
window.location.origin) ||
|
| 107 |
+
!v.url.startsWith("http");
|
| 108 |
+
try {
|
| 109 |
+
const url = sameOrigin
|
| 110 |
+
? v.url
|
| 111 |
+
: await fetch(v.url)
|
| 112 |
+
.then((r) => r.blob())
|
| 113 |
+
.then((b) => URL.createObjectURL(b));
|
| 114 |
+
const a = document.createElement("a");
|
| 115 |
+
a.href = url;
|
| 116 |
+
a.download = name;
|
| 117 |
+
document.body.appendChild(a);
|
| 118 |
+
a.click();
|
| 119 |
+
document.body.removeChild(a);
|
| 120 |
+
if (!sameOrigin) setTimeout(() => URL.revokeObjectURL(url), 1000);
|
| 121 |
+
} catch {
|
| 122 |
+
// Fall back to navigating; user can right-click β save.
|
| 123 |
+
window.open(v.url, "_blank", "noopener");
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
const i18n = (key: string) => key;
|
| 128 |
+
async function stubUpload(files: File[]): Promise<any[]> {
|
| 129 |
+
return files.map((f) => ({
|
| 130 |
+
url: URL.createObjectURL(f),
|
| 131 |
+
orig_name: f.name,
|
| 132 |
+
path: f.name,
|
| 133 |
+
mime_type: f.type,
|
| 134 |
+
size: f.size
|
| 135 |
+
}));
|
| 136 |
+
}
|
| 137 |
+
async function stubStream(): Promise<any> {
|
| 138 |
+
return;
|
| 139 |
+
}
|
| 140 |
+
</script>
|
| 141 |
+
|
| 142 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 143 |
+
<div
|
| 144 |
+
class="widget-zone nodrag nopan"
|
| 145 |
+
class:text-full={widgetType === "text" || widgetType === "json"}
|
| 146 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 147 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 148 |
+
>
|
| 149 |
+
{#if widgetType === "text" || widgetType === "json"}
|
| 150 |
+
<div class="widget-text-wrap">
|
| 151 |
+
<div class="widget-gradio-wrap">
|
| 152 |
+
<BaseTextbox
|
| 153 |
+
value={getTextValue()}
|
| 154 |
+
label="text"
|
| 155 |
+
show_label={false}
|
| 156 |
+
lines={widgetType === "json" ? 4 : 3}
|
| 157 |
+
max_lines={8}
|
| 158 |
+
placeholder={isReadonly
|
| 159 |
+
? "Waiting for output..."
|
| 160 |
+
: widgetType === "json"
|
| 161 |
+
? '{"key": "value"}'
|
| 162 |
+
: "Enter text..."}
|
| 163 |
+
disabled={isReadonly}
|
| 164 |
+
oninput={(val) => ondatachange(node.id, widgetPortId, val)}
|
| 165 |
+
/>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
{:else if widgetType === "number"}
|
| 169 |
+
<div class="widget-number-wrap">
|
| 170 |
+
{#if isReadonly}
|
| 171 |
+
<div class="widget-text-display">
|
| 172 |
+
{getNumberValue()}
|
| 173 |
+
</div>
|
| 174 |
+
{:else}
|
| 175 |
+
<input
|
| 176 |
+
class="widget-number"
|
| 177 |
+
type="number"
|
| 178 |
+
value={getNumberValue()}
|
| 179 |
+
oninput={handleNumberInput}
|
| 180 |
+
step="any"
|
| 181 |
+
/>
|
| 182 |
+
{/if}
|
| 183 |
+
</div>
|
| 184 |
+
{:else if widgetType === "boolean"}
|
| 185 |
+
<div class="widget-bool-wrap">
|
| 186 |
+
<label class="widget-checkbox-row">
|
| 187 |
+
<input
|
| 188 |
+
class="widget-checkbox"
|
| 189 |
+
type="checkbox"
|
| 190 |
+
checked={getBooleanValue()}
|
| 191 |
+
disabled={isReadonly}
|
| 192 |
+
onchange={handleBooleanInput}
|
| 193 |
+
/>
|
| 194 |
+
<span class="widget-checkbox-label"
|
| 195 |
+
>{getBooleanValue() ? "On" : "Off"}</span
|
| 196 |
+
>
|
| 197 |
+
</label>
|
| 198 |
+
</div>
|
| 199 |
+
{:else if widgetType === "image" || widgetType === "audio" || widgetType === "video" || widgetType === "file" || widgetType === "gallery" || widgetType === "model3d"}
|
| 200 |
+
{@const fileVal = getFileValue()}
|
| 201 |
+
{#if fileVal}
|
| 202 |
+
<div class="widget-preview">
|
| 203 |
+
{#if (widgetType === "image" || widgetType === "gallery") && isReadonly}
|
| 204 |
+
<div class="widget-gradio-wrap widget-gradio-image">
|
| 205 |
+
<BaseStaticImage
|
| 206 |
+
value={{
|
| 207 |
+
url: fileVal.url,
|
| 208 |
+
orig_name: fileVal.name,
|
| 209 |
+
path: fileVal.url,
|
| 210 |
+
mime_type: fileVal.mime
|
| 211 |
+
}}
|
| 212 |
+
show_label={false}
|
| 213 |
+
{i18n}
|
| 214 |
+
buttons={[]}
|
| 215 |
+
/>
|
| 216 |
+
</div>
|
| 217 |
+
{:else if widgetType === "image" || widgetType === "gallery"}
|
| 218 |
+
<img class="widget-img" src={fileVal.url} alt={fileVal.name} />
|
| 219 |
+
{:else if widgetType === "audio"}
|
| 220 |
+
<audio class="widget-audio" controls src={fileVal.url}></audio>
|
| 221 |
+
{:else if widgetType === "video"}
|
| 222 |
+
<video class="widget-video" controls src={fileVal.url}></video>
|
| 223 |
+
{:else}
|
| 224 |
+
<div class="widget-file-info">
|
| 225 |
+
<span class="widget-file-name">{fileVal.name}</span>
|
| 226 |
+
</div>
|
| 227 |
+
{/if}
|
| 228 |
+
<div class="widget-preview-actions">
|
| 229 |
+
<button
|
| 230 |
+
class="widget-action"
|
| 231 |
+
onclick={downloadFile}
|
| 232 |
+
title="Download {fileVal.name}"
|
| 233 |
+
aria-label="Download"
|
| 234 |
+
>
|
| 235 |
+
<DownloadIcon />
|
| 236 |
+
</button>
|
| 237 |
+
{#if !isReadonly}
|
| 238 |
+
<button
|
| 239 |
+
class="widget-action widget-clear"
|
| 240 |
+
onclick={clearFile}
|
| 241 |
+
title="Clear"
|
| 242 |
+
aria-label="Clear">×</button
|
| 243 |
+
>
|
| 244 |
+
{/if}
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
{:else if isReadonly}
|
| 248 |
+
<div class="widget-placeholder">Waiting for output...</div>
|
| 249 |
+
{:else}
|
| 250 |
+
<!-- svelte-ignore a11y_interactive_supports_focus -->
|
| 251 |
+
<div
|
| 252 |
+
class="widget-file-drop nodrag nopan"
|
| 253 |
+
role="button"
|
| 254 |
+
tabindex="0"
|
| 255 |
+
onclick={() => fileInputEl?.click()}
|
| 256 |
+
onkeydown={(e) => {
|
| 257 |
+
if (e.key === "Enter" || e.key === " ") fileInputEl?.click();
|
| 258 |
+
}}
|
| 259 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 260 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 261 |
+
ondragover={(e) => {
|
| 262 |
+
e.preventDefault();
|
| 263 |
+
e.stopPropagation();
|
| 264 |
+
}}
|
| 265 |
+
ondrop={handleFileDrop}
|
| 266 |
+
>
|
| 267 |
+
<input
|
| 268 |
+
bind:this={fileInputEl}
|
| 269 |
+
type="file"
|
| 270 |
+
accept={widgetType === "image"
|
| 271 |
+
? "image/*"
|
| 272 |
+
: widgetType === "audio"
|
| 273 |
+
? "audio/*"
|
| 274 |
+
: widgetType === "video"
|
| 275 |
+
? "video/*"
|
| 276 |
+
: widgetType === "model3d"
|
| 277 |
+
? ".glb,.gltf,.obj,.stl"
|
| 278 |
+
: "*"}
|
| 279 |
+
onchange={handleFileSelect}
|
| 280 |
+
style="display: none"
|
| 281 |
+
/>
|
| 282 |
+
<span class="widget-drop-text">
|
| 283 |
+
Drop {widgetType} or click
|
| 284 |
+
</span>
|
| 285 |
+
</div>
|
| 286 |
+
{/if}
|
| 287 |
+
{/if}
|
| 288 |
+
</div>
|
| 289 |
+
|
| 290 |
+
<style>
|
| 291 |
+
/* βββ Gradio Component Wrapper βββ */
|
| 292 |
+
.widget-text-wrap,
|
| 293 |
+
.widget-number-wrap,
|
| 294 |
+
.widget-bool-wrap {
|
| 295 |
+
padding: 6px 12px 8px;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
.widget-gradio-wrap {
|
| 299 |
+
font-size: 12px;
|
| 300 |
+
--input-text-size: 11px;
|
| 301 |
+
--input-text-weight: 400;
|
| 302 |
+
--input-padding: 8px 10px;
|
| 303 |
+
--input-background-fill: #101118;
|
| 304 |
+
--input-background-fill-focus: #101118;
|
| 305 |
+
--input-border-color: #1e1f2a;
|
| 306 |
+
--input-border-color-focus: var(--accent);
|
| 307 |
+
--input-border-width: 1px;
|
| 308 |
+
--input-radius: 6px;
|
| 309 |
+
--input-shadow: none;
|
| 310 |
+
--input-shadow-focus: 0 0 0 2px var(--accent-dim);
|
| 311 |
+
--input-placeholder-color: #4a4b58;
|
| 312 |
+
--body-text-color: #c8c9d2;
|
| 313 |
+
--font-sans: "JetBrains Mono", monospace;
|
| 314 |
+
--line-sm: 1.4;
|
| 315 |
+
--spacing-sm: 4px;
|
| 316 |
+
--weight-semibold: 600;
|
| 317 |
+
--layer-1: #101118;
|
| 318 |
+
--shadow-inset: none;
|
| 319 |
+
--button-secondary-background-fill: #1e1f2a;
|
| 320 |
+
--button-secondary-background-fill-hover: #2a2b36;
|
| 321 |
+
--button-secondary-text-color: #8b8d98;
|
| 322 |
+
--button-shadow-active: none;
|
| 323 |
+
--error-icon-color: #ef4444;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
.widget-gradio-wrap :global(textarea),
|
| 327 |
+
.widget-gradio-wrap :global(input) {
|
| 328 |
+
font-family: "JetBrains Mono", monospace !important;
|
| 329 |
+
font-size: 11px !important;
|
| 330 |
+
line-height: 1.4 !important;
|
| 331 |
+
background: #101118 !important;
|
| 332 |
+
color: #c8c9d2 !important;
|
| 333 |
+
border: 1px solid #1e1f2a !important;
|
| 334 |
+
border-radius: 6px !important;
|
| 335 |
+
padding: 8px 10px !important;
|
| 336 |
+
outline: none !important;
|
| 337 |
+
box-shadow: none !important;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
.widget-gradio-wrap :global(textarea:focus),
|
| 341 |
+
.widget-gradio-wrap :global(input:focus) {
|
| 342 |
+
border-color: var(--accent) !important;
|
| 343 |
+
box-shadow: 0 0 0 2px var(--accent-dim) !important;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
.widget-gradio-wrap :global(textarea::placeholder),
|
| 347 |
+
.widget-gradio-wrap :global(input::placeholder) {
|
| 348 |
+
color: #4a4b58 !important;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
.widget-gradio-wrap :global(.block),
|
| 352 |
+
.widget-gradio-wrap :global(.wrap),
|
| 353 |
+
.widget-gradio-wrap :global(.container) {
|
| 354 |
+
background: transparent !important;
|
| 355 |
+
border: none !important;
|
| 356 |
+
box-shadow: none !important;
|
| 357 |
+
padding: 0 !important;
|
| 358 |
+
margin: 0 !important;
|
| 359 |
+
gap: 0 !important;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
.widget-gradio-wrap :global(.block.padded) {
|
| 363 |
+
padding: 0 !important;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
.widget-gradio-wrap :global(.label-wrap),
|
| 367 |
+
.widget-gradio-wrap :global(.info-text),
|
| 368 |
+
.widget-gradio-wrap :global(.icon-button-wrapper),
|
| 369 |
+
.widget-gradio-wrap :global(.icon-buttons) {
|
| 370 |
+
display: none !important;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
.widget-gradio-image {
|
| 374 |
+
overflow: hidden;
|
| 375 |
+
border-radius: 6px;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
.widget-gradio-image :global(img) {
|
| 379 |
+
max-height: 140px !important;
|
| 380 |
+
width: 100% !important;
|
| 381 |
+
object-fit: contain !important;
|
| 382 |
+
display: block !important;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
.widget-gradio-image :global(.image-container) {
|
| 386 |
+
max-height: 140px !important;
|
| 387 |
+
overflow: hidden !important;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
.widget-gradio-image :global(.empty-wrapper) {
|
| 391 |
+
display: none !important;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
.widget-gradio-wrap :global(textarea) {
|
| 395 |
+
min-height: 60px !important;
|
| 396 |
+
height: auto !important;
|
| 397 |
+
resize: vertical !important;
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
.widget-gradio-wrap :global(label) {
|
| 401 |
+
display: block !important;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
.widget-gradio-wrap :global(.input-container) {
|
| 405 |
+
display: flex !important;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
/* βββ Widget Zone βββ */
|
| 409 |
+
.widget-zone {
|
| 410 |
+
padding: 0;
|
| 411 |
+
border-top: 1px solid #1e1f2a;
|
| 412 |
+
/* Canvas blocks user-select to stop dbl-click selecting random
|
| 413 |
+
* UI text; opt the widget back in so users can highlight + copy
|
| 414 |
+
* text inside textboxes / display zones. */
|
| 415 |
+
user-select: text;
|
| 416 |
+
-webkit-user-select: text;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
.widget-zone.text-full {
|
| 420 |
+
border-top: none;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
.widget-zone.text-full .widget-text-wrap {
|
| 424 |
+
padding: 0;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
.widget-zone.text-full :global(textarea) {
|
| 428 |
+
border-radius: 0 0 9px 9px !important;
|
| 429 |
+
border-top: 1px solid #1e1f2a !important;
|
| 430 |
+
border-left: none !important;
|
| 431 |
+
border-right: none !important;
|
| 432 |
+
border-bottom: none !important;
|
| 433 |
+
min-height: 120px !important;
|
| 434 |
+
width: 100% !important;
|
| 435 |
+
box-sizing: border-box !important;
|
| 436 |
+
resize: vertical !important;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
.widget-zone.text-full :global(textarea:focus) {
|
| 440 |
+
border-top-color: var(--accent) !important;
|
| 441 |
+
box-shadow: none !important;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
.widget-text-display {
|
| 445 |
+
font-family: "JetBrains Mono", monospace;
|
| 446 |
+
font-size: 11px;
|
| 447 |
+
line-height: 1.4;
|
| 448 |
+
padding: 8px 10px;
|
| 449 |
+
border: 1px solid #1e1f2a;
|
| 450 |
+
border-radius: 6px;
|
| 451 |
+
background: #101118;
|
| 452 |
+
color: #5c5e6a;
|
| 453 |
+
min-height: 42px;
|
| 454 |
+
max-height: 300px;
|
| 455 |
+
overflow-y: auto;
|
| 456 |
+
white-space: pre-wrap;
|
| 457 |
+
word-break: break-word;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
.widget-number {
|
| 461 |
+
width: 100%;
|
| 462 |
+
font-family: "JetBrains Mono", monospace;
|
| 463 |
+
font-size: 12px;
|
| 464 |
+
border: 1px solid #1e1f2a;
|
| 465 |
+
border-radius: 6px;
|
| 466 |
+
padding: 8px 10px;
|
| 467 |
+
background: #101118;
|
| 468 |
+
color: #c8c9d2;
|
| 469 |
+
outline: none;
|
| 470 |
+
box-sizing: border-box;
|
| 471 |
+
transition: border-color 0.15s;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
.widget-number:focus {
|
| 475 |
+
border-color: var(--accent);
|
| 476 |
+
box-shadow: 0 0 0 2px var(--accent-dim);
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
.widget-checkbox-row {
|
| 480 |
+
display: flex;
|
| 481 |
+
align-items: center;
|
| 482 |
+
gap: 8px;
|
| 483 |
+
padding: 6px 0;
|
| 484 |
+
cursor: pointer;
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
.widget-checkbox {
|
| 488 |
+
width: 16px;
|
| 489 |
+
height: 16px;
|
| 490 |
+
accent-color: var(--accent);
|
| 491 |
+
cursor: pointer;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
.widget-checkbox-label {
|
| 495 |
+
font-family: "JetBrains Mono", monospace;
|
| 496 |
+
font-size: 11px;
|
| 497 |
+
color: #8b8d98;
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
.widget-file-info {
|
| 501 |
+
padding: 10px 12px;
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
.widget-file-name {
|
| 505 |
+
font-family: "JetBrains Mono", monospace;
|
| 506 |
+
font-size: 10.5px;
|
| 507 |
+
color: #8b8d98;
|
| 508 |
+
word-break: break-all;
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
.widget-file-drop {
|
| 512 |
+
display: flex;
|
| 513 |
+
align-items: center;
|
| 514 |
+
justify-content: center;
|
| 515 |
+
height: 80px;
|
| 516 |
+
border: none;
|
| 517 |
+
border-radius: 0 0 10px 10px;
|
| 518 |
+
background: #101118;
|
| 519 |
+
cursor: pointer;
|
| 520 |
+
transition: background 0.15s;
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
.widget-file-drop:hover {
|
| 524 |
+
background: #14151a;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
.widget-file-drop input {
|
| 528 |
+
display: none;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
.widget-drop-text {
|
| 532 |
+
font-size: 10.5px;
|
| 533 |
+
color: #4a4b58;
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
.widget-placeholder {
|
| 537 |
+
font-family: "JetBrains Mono", monospace;
|
| 538 |
+
font-size: 10px;
|
| 539 |
+
color: #2e2f3d;
|
| 540 |
+
text-align: center;
|
| 541 |
+
padding: 24px 0;
|
| 542 |
+
background: #101118;
|
| 543 |
+
border-radius: 0 0 10px 10px;
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
.widget-preview {
|
| 547 |
+
position: relative;
|
| 548 |
+
overflow: hidden;
|
| 549 |
+
border-radius: 0 0 10px 10px;
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
.widget-img {
|
| 553 |
+
display: block;
|
| 554 |
+
width: 100%;
|
| 555 |
+
max-height: 320px;
|
| 556 |
+
object-fit: contain;
|
| 557 |
+
background: #101118;
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
.widget-audio {
|
| 561 |
+
display: block;
|
| 562 |
+
width: 100%;
|
| 563 |
+
height: 36px;
|
| 564 |
+
border-radius: 5px;
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
.widget-video {
|
| 568 |
+
display: block;
|
| 569 |
+
width: 100%;
|
| 570 |
+
max-height: 100px;
|
| 571 |
+
object-fit: contain;
|
| 572 |
+
border-radius: 5px;
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
.widget-preview-actions {
|
| 576 |
+
position: absolute;
|
| 577 |
+
top: 4px;
|
| 578 |
+
right: 4px;
|
| 579 |
+
display: flex;
|
| 580 |
+
gap: 4px;
|
| 581 |
+
opacity: 0;
|
| 582 |
+
transition: opacity 0.15s;
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
.widget-preview:hover .widget-preview-actions {
|
| 586 |
+
opacity: 1;
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
.widget-action {
|
| 590 |
+
width: 22px;
|
| 591 |
+
height: 22px;
|
| 592 |
+
border-radius: 50%;
|
| 593 |
+
border: none;
|
| 594 |
+
background: rgba(0, 0, 0, 0.6);
|
| 595 |
+
color: #d5d6de;
|
| 596 |
+
font-size: 13px;
|
| 597 |
+
line-height: 1;
|
| 598 |
+
cursor: pointer;
|
| 599 |
+
display: flex;
|
| 600 |
+
align-items: center;
|
| 601 |
+
justify-content: center;
|
| 602 |
+
padding: 0;
|
| 603 |
+
transition:
|
| 604 |
+
background 0.15s,
|
| 605 |
+
color 0.15s;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
.widget-action:hover {
|
| 609 |
+
background: rgba(0, 0, 0, 0.85);
|
| 610 |
+
color: #fff;
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
.widget-clear:hover {
|
| 614 |
+
background: rgba(239, 68, 68, 0.85);
|
| 615 |
+
color: #fff;
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
/* βββ Light mode βββ */
|
| 619 |
+
:global(body:not(.dark)) .widget-zone {
|
| 620 |
+
border-top-color: #e2e4ea;
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
:global(body:not(.dark)) .widget-gradio-wrap {
|
| 624 |
+
--input-background-fill: #f8f9fb;
|
| 625 |
+
--input-background-fill-focus: #ffffff;
|
| 626 |
+
--input-border-color: #e2e4ea;
|
| 627 |
+
--input-placeholder-color: #c0c2cc;
|
| 628 |
+
--body-text-color: #1a1b25;
|
| 629 |
+
--layer-1: #f8f9fb;
|
| 630 |
+
--button-secondary-background-fill: #f0f1f5;
|
| 631 |
+
--button-secondary-background-fill-hover: #e2e4ea;
|
| 632 |
+
--button-secondary-text-color: #6b6e78;
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
:global(body:not(.dark)) .widget-gradio-wrap :global(textarea),
|
| 636 |
+
:global(body:not(.dark)) .widget-gradio-wrap :global(input) {
|
| 637 |
+
background: #f8f9fb !important;
|
| 638 |
+
color: #1a1b25 !important;
|
| 639 |
+
border-color: #e2e4ea !important;
|
| 640 |
+
}
|
| 641 |
+
|
| 642 |
+
:global(body:not(.dark)) .widget-gradio-wrap :global(textarea::placeholder),
|
| 643 |
+
:global(body:not(.dark)) .widget-gradio-wrap :global(input::placeholder) {
|
| 644 |
+
color: #c0c2cc !important;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
:global(body:not(.dark)) .widget-text-display {
|
| 648 |
+
background: #f8f9fb;
|
| 649 |
+
border-color: #e2e4ea;
|
| 650 |
+
color: #6b6e78;
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
:global(body:not(.dark)) .widget-number {
|
| 654 |
+
background: #f8f9fb;
|
| 655 |
+
border-color: #e2e4ea;
|
| 656 |
+
color: #1a1b25;
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
:global(body:not(.dark)) .widget-checkbox-label {
|
| 660 |
+
color: #6b6e78;
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
:global(body:not(.dark)) .widget-file-name {
|
| 664 |
+
color: #6b6e78;
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
:global(body:not(.dark)) .widget-file-drop {
|
| 668 |
+
background: #f8f9fb;
|
| 669 |
+
border-color: #d0d2dc;
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
+
:global(body:not(.dark)) .widget-file-drop:hover {
|
| 673 |
+
background: #f0f1f5;
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
:global(body:not(.dark)) .widget-drop-text {
|
| 677 |
+
color: #b0b2bc;
|
| 678 |
+
}
|
| 679 |
+
|
| 680 |
+
:global(body:not(.dark)) .widget-placeholder {
|
| 681 |
+
background: #f8f9fb;
|
| 682 |
+
border-color: #e2e4ea;
|
| 683 |
+
color: #b0b2bc;
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
:global(body:not(.dark)) .widget-preview {
|
| 687 |
+
background: #f8f9fb;
|
| 688 |
+
border-color: #e2e4ea;
|
| 689 |
+
}
|
| 690 |
+
</style>
|
6.17.1/workflowcanvas/workflow/WorkflowBottomBar.svelte
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ig } from "./workflow-modalities";
|
| 4 |
+
import ImageIcon from "./icons/ImageIcon.svelte";
|
| 5 |
+
import AudioIcon from "./icons/AudioIcon.svelte";
|
| 6 |
+
import VideoIcon from "./icons/VideoIcon.svelte";
|
| 7 |
+
import Model3DIcon from "./icons/Model3DIcon.svelte";
|
| 8 |
+
import TextIcon from "./icons/TextIcon.svelte";
|
| 9 |
+
import DatasetIcon from "./icons/DatasetIcon.svelte";
|
| 10 |
+
import PlusIcon from "./icons/PlusIcon.svelte";
|
| 11 |
+
import FunctionIcon from "./icons/FunctionIcon.svelte";
|
| 12 |
+
import StopIcon from "./icons/StopIcon.svelte";
|
| 13 |
+
import PlayIcon from "./icons/PlayIcon.svelte";
|
| 14 |
+
|
| 15 |
+
export interface BoundFnTemplate {
|
| 16 |
+
fn: string;
|
| 17 |
+
label: string;
|
| 18 |
+
inputs: { id: string; label: string; type: string }[];
|
| 19 |
+
outputs: { id: string; label: string; type: string }[];
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
interface Props {
|
| 23 |
+
running: boolean;
|
| 24 |
+
hasTransforms: boolean;
|
| 25 |
+
boundFns: BoundFnTemplate[];
|
| 26 |
+
onopenpicker: (modality: ModalityConfig) => void;
|
| 27 |
+
onaddinput: (portType: string) => void;
|
| 28 |
+
onaddfn: (template: BoundFnTemplate) => void;
|
| 29 |
+
onrun: () => void;
|
| 30 |
+
onstop: () => void;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
let {
|
| 34 |
+
running,
|
| 35 |
+
hasTransforms,
|
| 36 |
+
boundFns,
|
| 37 |
+
onopenpicker,
|
| 38 |
+
onaddinput,
|
| 39 |
+
onaddfn,
|
| 40 |
+
onrun,
|
| 41 |
+
onstop
|
| 42 |
+
}: Props = $props();
|
| 43 |
+
|
| 44 |
+
const INPUT_TYPES = [
|
| 45 |
+
{ key: "image", label: "Image" },
|
| 46 |
+
{ key: "text", label: "Text" },
|
| 47 |
+
{ key: "audio", label: "Audio" },
|
| 48 |
+
{ key: "video", label: "Video" },
|
| 49 |
+
{ key: "number", label: "Number" },
|
| 50 |
+
{ key: "file", label: "File" }
|
| 51 |
+
];
|
| 52 |
+
|
| 53 |
+
let showInputMenu = $state(false);
|
| 54 |
+
let showFnMenu = $state(false);
|
| 55 |
+
|
| 56 |
+
function closeMenus(): void {
|
| 57 |
+
showInputMenu = false;
|
| 58 |
+
showFnMenu = false;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function toggleInputMenu(e: MouseEvent) {
|
| 62 |
+
e.stopPropagation();
|
| 63 |
+
showFnMenu = false;
|
| 64 |
+
showInputMenu = !showInputMenu;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
function toggleFnMenu(e: MouseEvent) {
|
| 68 |
+
e.stopPropagation();
|
| 69 |
+
showInputMenu = false;
|
| 70 |
+
showFnMenu = !showFnMenu;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function handleInputType(type: string, e: MouseEvent) {
|
| 74 |
+
e.stopPropagation();
|
| 75 |
+
showInputMenu = false;
|
| 76 |
+
onaddinput(type);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function handleFnClick(tmpl: BoundFnTemplate, e: MouseEvent) {
|
| 80 |
+
e.stopPropagation();
|
| 81 |
+
showFnMenu = false;
|
| 82 |
+
onaddfn(tmpl);
|
| 83 |
+
}
|
| 84 |
+
</script>
|
| 85 |
+
|
| 86 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 87 |
+
<div
|
| 88 |
+
class="bottom-bar"
|
| 89 |
+
onclick={(e) => {
|
| 90 |
+
e.stopPropagation();
|
| 91 |
+
closeMenus();
|
| 92 |
+
}}
|
| 93 |
+
>
|
| 94 |
+
<div class="bb-group">
|
| 95 |
+
{#each MODALITIES as m}
|
| 96 |
+
<div class="bb-modality-wrap">
|
| 97 |
+
<button
|
| 98 |
+
class="bb-btn"
|
| 99 |
+
onclick={(e) => {
|
| 100 |
+
e.stopPropagation();
|
| 101 |
+
closeMenus();
|
| 102 |
+
onopenpicker(m);
|
| 103 |
+
}}
|
| 104 |
+
title="Add {m.label} node"
|
| 105 |
+
>
|
| 106 |
+
<span class="bb-icon">
|
| 107 |
+
{#if m.key === "image"}
|
| 108 |
+
<ImageIcon />
|
| 109 |
+
{:else if m.key === "audio"}
|
| 110 |
+
<AudioIcon />
|
| 111 |
+
{:else if m.key === "video"}
|
| 112 |
+
<VideoIcon />
|
| 113 |
+
{:else if m.key === "3d"}
|
| 114 |
+
<Model3DIcon />
|
| 115 |
+
{:else if m.key === "text"}
|
| 116 |
+
<TextIcon />
|
| 117 |
+
{/if}
|
| 118 |
+
</span>
|
| 119 |
+
<span class="bb-label">{m.label}</span>
|
| 120 |
+
</button>
|
| 121 |
+
</div>
|
| 122 |
+
{/each}
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<button
|
| 126 |
+
class="bb-btn"
|
| 127 |
+
onclick={(e) => {
|
| 128 |
+
e.stopPropagation();
|
| 129 |
+
onopenpicker(DATASET_MODALITY);
|
| 130 |
+
}}
|
| 131 |
+
title="Add dataset node"
|
| 132 |
+
>
|
| 133 |
+
<span class="bb-icon">
|
| 134 |
+
<DatasetIcon />
|
| 135 |
+
</span>
|
| 136 |
+
<span class="bb-label">Data</span>
|
| 137 |
+
</button>
|
| 138 |
+
|
| 139 |
+
<div class="bb-divider"></div>
|
| 140 |
+
|
| 141 |
+
<div class="bb-input-wrap">
|
| 142 |
+
<button
|
| 143 |
+
class="bb-input-btn"
|
| 144 |
+
onclick={toggleInputMenu}
|
| 145 |
+
title="Add input node"
|
| 146 |
+
>
|
| 147 |
+
<PlusIcon />
|
| 148 |
+
Input
|
| 149 |
+
</button>
|
| 150 |
+
{#if showInputMenu}
|
| 151 |
+
<div class="input-type-menu">
|
| 152 |
+
{#each INPUT_TYPES as t}
|
| 153 |
+
<button
|
| 154 |
+
class="input-type-opt"
|
| 155 |
+
onclick={(e) => handleInputType(t.key, e)}>{t.label}</button
|
| 156 |
+
>
|
| 157 |
+
{/each}
|
| 158 |
+
</div>
|
| 159 |
+
{/if}
|
| 160 |
+
</div>
|
| 161 |
+
|
| 162 |
+
{#if boundFns.length > 0}
|
| 163 |
+
<div class="bb-input-wrap">
|
| 164 |
+
<button
|
| 165 |
+
class="bb-input-btn"
|
| 166 |
+
onclick={toggleFnMenu}
|
| 167 |
+
title="Add Python function node"
|
| 168 |
+
>
|
| 169 |
+
<FunctionIcon />
|
| 170 |
+
Function
|
| 171 |
+
</button>
|
| 172 |
+
{#if showFnMenu}
|
| 173 |
+
<div class="input-type-menu fn-menu">
|
| 174 |
+
{#each boundFns as t}
|
| 175 |
+
<button
|
| 176 |
+
class="input-type-opt"
|
| 177 |
+
onclick={(e) => handleFnClick(t, e)}
|
| 178 |
+
title={t.fn}
|
| 179 |
+
>
|
| 180 |
+
{t.label}
|
| 181 |
+
</button>
|
| 182 |
+
{/each}
|
| 183 |
+
</div>
|
| 184 |
+
{/if}
|
| 185 |
+
</div>
|
| 186 |
+
{/if}
|
| 187 |
+
|
| 188 |
+
<div class="bb-divider"></div>
|
| 189 |
+
|
| 190 |
+
{#if running}
|
| 191 |
+
<button class="bb-run-btn stop" onclick={onstop}>
|
| 192 |
+
<StopIcon />
|
| 193 |
+
Stop
|
| 194 |
+
</button>
|
| 195 |
+
{:else}
|
| 196 |
+
<button class="bb-run-btn" onclick={onrun} disabled={!hasTransforms}>
|
| 197 |
+
<PlayIcon />
|
| 198 |
+
Run
|
| 199 |
+
</button>
|
| 200 |
+
{/if}
|
| 201 |
+
</div>
|
| 202 |
+
|
| 203 |
+
<style>
|
| 204 |
+
.bottom-bar {
|
| 205 |
+
position: absolute;
|
| 206 |
+
bottom: 20px;
|
| 207 |
+
left: 50%;
|
| 208 |
+
transform: translateX(-50%);
|
| 209 |
+
display: flex;
|
| 210 |
+
align-items: center;
|
| 211 |
+
gap: 6px;
|
| 212 |
+
padding: 5px 8px;
|
| 213 |
+
background: rgba(16, 17, 24, 0.92);
|
| 214 |
+
border: 1px solid rgba(255, 255, 255, 0.07);
|
| 215 |
+
border-radius: 40px;
|
| 216 |
+
backdrop-filter: blur(16px);
|
| 217 |
+
-webkit-backdrop-filter: blur(16px);
|
| 218 |
+
box-shadow:
|
| 219 |
+
0 4px 24px rgba(0, 0, 0, 0.5),
|
| 220 |
+
0 0 0 1px rgba(255, 255, 255, 0.03);
|
| 221 |
+
z-index: 20;
|
| 222 |
+
white-space: nowrap;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
.bb-group {
|
| 226 |
+
display: flex;
|
| 227 |
+
align-items: center;
|
| 228 |
+
gap: 2px;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.bb-btn {
|
| 232 |
+
display: flex;
|
| 233 |
+
align-items: center;
|
| 234 |
+
gap: 6px;
|
| 235 |
+
padding: 6px 12px;
|
| 236 |
+
border: none;
|
| 237 |
+
border-radius: 28px;
|
| 238 |
+
background: transparent;
|
| 239 |
+
color: #8b8d98;
|
| 240 |
+
font-family: "Manrope", sans-serif;
|
| 241 |
+
font-size: 12px;
|
| 242 |
+
font-weight: 600;
|
| 243 |
+
cursor: pointer;
|
| 244 |
+
transition:
|
| 245 |
+
background 0.15s,
|
| 246 |
+
color 0.15s;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
.bb-btn:hover,
|
| 250 |
+
.bb-btn-active {
|
| 251 |
+
background: rgba(255, 255, 255, 0.06);
|
| 252 |
+
color: #d5d6de;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
.bb-modality-wrap {
|
| 256 |
+
position: relative;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
.bb-icon {
|
| 260 |
+
display: flex;
|
| 261 |
+
align-items: center;
|
| 262 |
+
justify-content: center;
|
| 263 |
+
flex-shrink: 0;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
.bb-label {
|
| 267 |
+
letter-spacing: -0.01em;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
.bb-divider {
|
| 271 |
+
width: 1px;
|
| 272 |
+
height: 20px;
|
| 273 |
+
background: rgba(255, 255, 255, 0.07);
|
| 274 |
+
flex-shrink: 0;
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
.bb-input-wrap {
|
| 278 |
+
position: relative;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
.bb-input-btn {
|
| 282 |
+
display: flex;
|
| 283 |
+
align-items: center;
|
| 284 |
+
gap: 5px;
|
| 285 |
+
padding: 6px 12px;
|
| 286 |
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
| 287 |
+
border-radius: 28px;
|
| 288 |
+
background: transparent;
|
| 289 |
+
color: #6b6e78;
|
| 290 |
+
font-family: "Manrope", sans-serif;
|
| 291 |
+
font-size: 12px;
|
| 292 |
+
font-weight: 600;
|
| 293 |
+
cursor: pointer;
|
| 294 |
+
transition:
|
| 295 |
+
background 0.15s,
|
| 296 |
+
color 0.15s,
|
| 297 |
+
border-color 0.15s;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
.bb-input-btn:hover {
|
| 301 |
+
background: rgba(255, 255, 255, 0.06);
|
| 302 |
+
color: #a0a2ae;
|
| 303 |
+
border-color: rgba(255, 255, 255, 0.14);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
.input-type-menu {
|
| 307 |
+
position: absolute;
|
| 308 |
+
bottom: calc(100% + 16px);
|
| 309 |
+
left: 50%;
|
| 310 |
+
transform: translateX(-50%);
|
| 311 |
+
background: #16171f;
|
| 312 |
+
border: 1px solid #2a2b36;
|
| 313 |
+
border-radius: 10px;
|
| 314 |
+
padding: 4px;
|
| 315 |
+
display: flex;
|
| 316 |
+
flex-direction: column;
|
| 317 |
+
gap: 1px;
|
| 318 |
+
/* Negative Y offset casts the shadow UPWARD, since the menu opens
|
| 319 |
+
* above the bottom bar. The previous downward shadow smudged onto
|
| 320 |
+
* the button below. Pair with a subtle inset ring for crisper
|
| 321 |
+
* edge definition on dark bg. */
|
| 322 |
+
box-shadow:
|
| 323 |
+
0 -6px 20px rgba(0, 0, 0, 0.35),
|
| 324 |
+
0 0 0 1px rgba(255, 255, 255, 0.03);
|
| 325 |
+
z-index: 30;
|
| 326 |
+
min-width: 90px;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
.input-type-opt {
|
| 330 |
+
padding: 7px 12px;
|
| 331 |
+
border: none;
|
| 332 |
+
border-radius: 6px;
|
| 333 |
+
background: transparent;
|
| 334 |
+
color: #8b8d98;
|
| 335 |
+
font-family: "Manrope", sans-serif;
|
| 336 |
+
font-size: 12px;
|
| 337 |
+
font-weight: 500;
|
| 338 |
+
cursor: pointer;
|
| 339 |
+
text-align: left;
|
| 340 |
+
transition:
|
| 341 |
+
background 0.1s,
|
| 342 |
+
color 0.1s;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
.input-type-opt:hover {
|
| 346 |
+
background: rgba(255, 255, 255, 0.06);
|
| 347 |
+
color: #d5d6de;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
.bb-run-btn {
|
| 351 |
+
display: flex;
|
| 352 |
+
align-items: center;
|
| 353 |
+
gap: 6px;
|
| 354 |
+
padding: 7px 16px;
|
| 355 |
+
border: none;
|
| 356 |
+
border-radius: 28px;
|
| 357 |
+
background: linear-gradient(135deg, #f97316, #ea580c);
|
| 358 |
+
color: #fff;
|
| 359 |
+
font-family: "Manrope", sans-serif;
|
| 360 |
+
font-size: 12.5px;
|
| 361 |
+
font-weight: 700;
|
| 362 |
+
cursor: pointer;
|
| 363 |
+
transition:
|
| 364 |
+
transform 0.1s,
|
| 365 |
+
box-shadow 0.15s;
|
| 366 |
+
box-shadow: 0 2px 10px rgba(249, 115, 22, 0.3);
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
.bb-run-btn:hover {
|
| 370 |
+
transform: translateY(-1px);
|
| 371 |
+
box-shadow: 0 4px 18px rgba(249, 115, 22, 0.4);
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
.bb-run-btn:active {
|
| 375 |
+
transform: translateY(0);
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
.bb-run-btn:disabled {
|
| 379 |
+
opacity: 0.35;
|
| 380 |
+
cursor: default;
|
| 381 |
+
transform: none;
|
| 382 |
+
box-shadow: none;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
.bb-run-btn.stop {
|
| 386 |
+
background: linear-gradient(135deg, #ef4444, #dc2626);
|
| 387 |
+
box-shadow: 0 2px 10px rgba(239, 68, 68, 0.3);
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
.bb-run-btn.stop:hover {
|
| 391 |
+
box-shadow: 0 4px 18px rgba(239, 68, 68, 0.4);
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
/* Light mode */
|
| 395 |
+
:global(body:not(.dark)) .bottom-bar {
|
| 396 |
+
background: rgba(255, 255, 255, 0.92);
|
| 397 |
+
border-color: rgba(0, 0, 0, 0.08);
|
| 398 |
+
box-shadow:
|
| 399 |
+
0 4px 24px rgba(0, 0, 0, 0.12),
|
| 400 |
+
0 0 0 1px rgba(0, 0, 0, 0.04);
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
:global(body:not(.dark)) .bb-btn {
|
| 404 |
+
color: #6b6e78;
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
:global(body:not(.dark)) .bb-btn:hover {
|
| 408 |
+
background: rgba(0, 0, 0, 0.04);
|
| 409 |
+
color: #1a1b25;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
:global(body:not(.dark)) .bb-divider {
|
| 413 |
+
background: rgba(0, 0, 0, 0.1);
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
:global(body:not(.dark)) .bb-input-btn {
|
| 417 |
+
border-color: rgba(0, 0, 0, 0.1);
|
| 418 |
+
color: #8b8d98;
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
:global(body:not(.dark)) .bb-input-btn:hover {
|
| 422 |
+
background: rgba(0, 0, 0, 0.04);
|
| 423 |
+
color: #3e4050;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
:global(body:not(.dark)) .input-type-menu {
|
| 427 |
+
background: #ffffff;
|
| 428 |
+
border-color: #e2e4ea;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
:global(body:not(.dark)) .input-type-opt {
|
| 432 |
+
color: #6b6e78;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
:global(body:not(.dark)) .input-type-opt:hover {
|
| 436 |
+
background: #f0f1f5;
|
| 437 |
+
color: #1a1b25;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
:global(body:not(.dark)) .bb-models-btn-active {
|
| 441 |
+
color: #ea580c;
|
| 442 |
+
background: rgba(234, 88, 12, 0.08);
|
| 443 |
+
}
|
| 444 |
+
</style>
|
6.17.1/workflowcanvas/workflow/WorkflowCanvas.svelte
ADDED
|
@@ -0,0 +1,2154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { setContext } from "svelte";
|
| 3 |
+
|
| 4 |
+
import WorkflowNodeSF from "./WorkflowNodeSF.svelte";
|
| 5 |
+
import WorkflowBottomBar from "./WorkflowBottomBar.svelte";
|
| 6 |
+
import type { BoundFnTemplate } from "./WorkflowBottomBar.svelte";
|
| 7 |
+
import NodeModelPicker from "./NodeModelPicker.svelte";
|
| 8 |
+
import WorkflowEmptyState from "./WorkflowEmptyState.svelte";
|
| 9 |
+
|
| 10 |
+
import {
|
| 11 |
+
MODALITIES,
|
| 12 |
+
DATASET_MODALITY,
|
| 13 |
+
portMeta,
|
| 14 |
+
modalityForPort
|
| 15 |
+
} from "./workflow-modalities";
|
| 16 |
+
import type { ModalityConfig } from "./workflow-modalities";
|
| 17 |
+
import { fetchSpaceApi } from "./space-api";
|
| 18 |
+
import {
|
| 19 |
+
workflow,
|
| 20 |
+
addNode,
|
| 21 |
+
moveNode,
|
| 22 |
+
addEdge,
|
| 23 |
+
removeEdge,
|
| 24 |
+
updateNodeData,
|
| 25 |
+
removeNode,
|
| 26 |
+
replaceNodeSource,
|
| 27 |
+
switch_endpoint,
|
| 28 |
+
hydrate_endpoints,
|
| 29 |
+
sanitize_for_save,
|
| 30 |
+
revoke_blob_urls
|
| 31 |
+
} from "./workflow-store";
|
| 32 |
+
import { migrateToV2, toLegacyShape } from "./workflow-migration";
|
| 33 |
+
import { PORT_COLOR, ports_compatible } from "./workflow-types";
|
| 34 |
+
import type {
|
| 35 |
+
PortType,
|
| 36 |
+
WFNode,
|
| 37 |
+
WFEdge,
|
| 38 |
+
NodeStatus,
|
| 39 |
+
NodeRole
|
| 40 |
+
} from "./workflow-types";
|
| 41 |
+
import { executeWorkflow } from "./workflow-executor";
|
| 42 |
+
import { stream_text_generation } from "./inference-stream";
|
| 43 |
+
import {
|
| 44 |
+
findFreeSpot as findFreeSpotImpl,
|
| 45 |
+
topoSort,
|
| 46 |
+
resolveCurrentInputs as resolveCurrentInputsImpl,
|
| 47 |
+
computeStaleNodes,
|
| 48 |
+
buildUpstreamSubgraph as buildUpstreamSubgraphImpl
|
| 49 |
+
} from "./workflow-graph";
|
| 50 |
+
import { LIBRARY, getComponentForPortType } from "./node-library";
|
| 51 |
+
import { createHFAuth } from "./hf-auth.svelte";
|
| 52 |
+
import { load_viewport, save_viewport } from "./viewport-persistence";
|
| 53 |
+
import CheckIcon from "./icons/CheckIcon.svelte";
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* A node template's role for the v2 store. v1-style templates from LIBRARY/
|
| 57 |
+
* picker use `kind: "component" | "transform"` β map them to v2 roles here.
|
| 58 |
+
* Subjects aren't auto-created by templates today; they're created when an
|
| 59 |
+
* edge wires into a reference (future enhancement). For now, components default
|
| 60 |
+
* to reference.
|
| 61 |
+
*/
|
| 62 |
+
function templateRole(template: any): NodeRole {
|
| 63 |
+
if (template?.role) return template.role;
|
| 64 |
+
if (template?.kind === "transform") return "operator";
|
| 65 |
+
return "reference";
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
let {
|
| 69 |
+
server = {},
|
| 70 |
+
initialValue = null
|
| 71 |
+
}: { server?: Record<string, any>; initialValue?: string | null } = $props();
|
| 72 |
+
|
| 73 |
+
const auth = createHFAuth(() => server);
|
| 74 |
+
|
| 75 |
+
$effect(() => {
|
| 76 |
+
if (server?.get_token) {
|
| 77 |
+
void auth.checkLoginStatus();
|
| 78 |
+
}
|
| 79 |
+
});
|
| 80 |
+
|
| 81 |
+
$effect(() => {
|
| 82 |
+
if (!initialValue) return;
|
| 83 |
+
try {
|
| 84 |
+
const parsed = JSON.parse(initialValue);
|
| 85 |
+
// Migration handles both v1 (legacy workflow.json files) and v2.
|
| 86 |
+
const v2 = migrateToV2(parsed);
|
| 87 |
+
workflow.set(v2);
|
| 88 |
+
} catch {}
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
$effect(() => {
|
| 92 |
+
const wf = $workflow;
|
| 93 |
+
if (!server?.save_workflow) return;
|
| 94 |
+
const timer = setTimeout(() => {
|
| 95 |
+
server
|
| 96 |
+
.save_workflow([JSON.stringify(sanitize_for_save(wf))])
|
| 97 |
+
.catch(() => {});
|
| 98 |
+
}, 500);
|
| 99 |
+
return () => clearTimeout(timer);
|
| 100 |
+
});
|
| 101 |
+
|
| 102 |
+
// Pull the bind=[β¦] list from the server once on mount so the
|
| 103 |
+
// Functions button in the bottom bar can offer them as add-able
|
| 104 |
+
// nodes. Silently no-op if the server doesn't expose it (older
|
| 105 |
+
// gradio backends).
|
| 106 |
+
$effect(() => {
|
| 107 |
+
if (!server?.list_bound_fns) return;
|
| 108 |
+
void server
|
| 109 |
+
.list_bound_fns()
|
| 110 |
+
.then((raw: string) => {
|
| 111 |
+
try {
|
| 112 |
+
const parsed = JSON.parse(raw);
|
| 113 |
+
if (Array.isArray(parsed)) boundFns = parsed as BoundFnTemplate[];
|
| 114 |
+
} catch {
|
| 115 |
+
/* ignore malformed */
|
| 116 |
+
}
|
| 117 |
+
})
|
| 118 |
+
.catch(() => {});
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
$effect(() => {
|
| 122 |
+
window.addEventListener("keydown", handleKeydown);
|
| 123 |
+
return () => window.removeEventListener("keydown", handleKeydown);
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
// βββ Canvas state βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 127 |
+
let viewport = $state(load_viewport($workflow.name));
|
| 128 |
+
|
| 129 |
+
let lastViewportName = $state($workflow.name);
|
| 130 |
+
$effect(() => {
|
| 131 |
+
if ($workflow.name !== lastViewportName) {
|
| 132 |
+
lastViewportName = $workflow.name;
|
| 133 |
+
viewport = load_viewport($workflow.name);
|
| 134 |
+
}
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
$effect(() => {
|
| 138 |
+
const name = $workflow.name;
|
| 139 |
+
const v = viewport;
|
| 140 |
+
const timer = setTimeout(() => save_viewport(name, v), 250);
|
| 141 |
+
return () => clearTimeout(timer);
|
| 142 |
+
});
|
| 143 |
+
|
| 144 |
+
// Pointer interaction state: track which kind of drag is happening so
|
| 145 |
+
// pointermove/up know what to do. Mutually exclusive β at most one mode.
|
| 146 |
+
type DragMode =
|
| 147 |
+
| { kind: "pan"; startX: number; startY: number; vx: number; vy: number }
|
| 148 |
+
| {
|
| 149 |
+
kind: "node";
|
| 150 |
+
nodeId: string;
|
| 151 |
+
startClientX: number;
|
| 152 |
+
startClientY: number;
|
| 153 |
+
startNodeX: number;
|
| 154 |
+
startNodeY: number;
|
| 155 |
+
}
|
| 156 |
+
| {
|
| 157 |
+
kind: "connection";
|
| 158 |
+
fromNodeId: string;
|
| 159 |
+
fromPortId: string;
|
| 160 |
+
type: PortType;
|
| 161 |
+
reversed: boolean;
|
| 162 |
+
cursorCanvasX: number;
|
| 163 |
+
cursorCanvasY: number;
|
| 164 |
+
};
|
| 165 |
+
let dragMode = $state<DragMode | null>(null);
|
| 166 |
+
|
| 167 |
+
// βββ App state ββββββββββββββββββββββββοΏ½οΏ½βββββββββββββββββββββββββββββββββββββ
|
| 168 |
+
let canvasEl: HTMLDivElement;
|
| 169 |
+
let running = $state(false);
|
| 170 |
+
let abortController: AbortController | null = null;
|
| 171 |
+
let nodeStatus: Record<string, NodeStatus> = $state({});
|
| 172 |
+
let nodeErrors: Record<string, string> = $state({});
|
| 173 |
+
/**
|
| 174 |
+
* Bound Python functions advertised by the server (`list_bound_fns`).
|
| 175 |
+
* Populates the bottom-bar Functions button so users can re-add an
|
| 176 |
+
* fn node after deleting it without re-launching the app.
|
| 177 |
+
*/
|
| 178 |
+
let boundFns = $state<BoundFnTemplate[]>([]);
|
| 179 |
+
/**
|
| 180 |
+
* Snapshot of resolved inputs at the moment a node last completed. Used
|
| 181 |
+
* to flag nodes as stale when their current inputs differ from the
|
| 182 |
+
* snapshot β i.e. an upstream value changed but this node hasn't been
|
| 183 |
+
* re-run yet. Pattern lifted from gradio-app/daggr.
|
| 184 |
+
*/
|
| 185 |
+
let nodeInputSnapshots: Record<string, string> = $state({});
|
| 186 |
+
let editingName = $state(false);
|
| 187 |
+
let selectedNodeId: string | null = $state(null);
|
| 188 |
+
let showShortcuts = $state(false);
|
| 189 |
+
let nameInput: HTMLInputElement = $state()!;
|
| 190 |
+
|
| 191 |
+
type Pending = {
|
| 192 |
+
from_node_id: string;
|
| 193 |
+
from_port_id: string;
|
| 194 |
+
type: PortType;
|
| 195 |
+
reversed?: boolean;
|
| 196 |
+
};
|
| 197 |
+
let activeConnection: Pending | null = $state(null);
|
| 198 |
+
|
| 199 |
+
interface WfToast {
|
| 200 |
+
id: number;
|
| 201 |
+
message: string;
|
| 202 |
+
type: "info" | "warning" | "error" | "success";
|
| 203 |
+
}
|
| 204 |
+
let toasts: WfToast[] = $state([]);
|
| 205 |
+
let toastCounter = 0;
|
| 206 |
+
|
| 207 |
+
function showToast(
|
| 208 |
+
msg: string,
|
| 209 |
+
ms = 3000,
|
| 210 |
+
type: "info" | "warning" | "error" | "success" = "info"
|
| 211 |
+
): void {
|
| 212 |
+
const id = ++toastCounter;
|
| 213 |
+
toasts = [...toasts, { id, message: msg, type }].slice(-3);
|
| 214 |
+
if (ms > 0)
|
| 215 |
+
setTimeout(() => {
|
| 216 |
+
toasts = toasts.filter((t) => t.id !== id);
|
| 217 |
+
}, ms);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
// v1 shape for read paths; writes go through v2 store actions.
|
| 221 |
+
const legacyView = $derived(toLegacyShape($workflow));
|
| 222 |
+
|
| 223 |
+
const gridTile = $derived.by(() => {
|
| 224 |
+
let tile = 22 * viewport.zoom;
|
| 225 |
+
while (tile < 16) tile *= 2;
|
| 226 |
+
return tile;
|
| 227 |
+
});
|
| 228 |
+
|
| 229 |
+
const nodeCount = $derived(legacyView.nodes.length);
|
| 230 |
+
const hasTransforms = $derived($workflow.operators.length > 0);
|
| 231 |
+
const edgeCount = $derived($workflow.edges.length);
|
| 232 |
+
|
| 233 |
+
const connectedPortsSet = $derived(() => {
|
| 234 |
+
const set = new Set<string>();
|
| 235 |
+
for (const e of $workflow.edges) {
|
| 236 |
+
set.add(`${e.from_node_id}:${e.from_port_id}:output`);
|
| 237 |
+
set.add(`${e.to_node_id}:${e.to_port_id}:input`);
|
| 238 |
+
}
|
| 239 |
+
return set;
|
| 240 |
+
});
|
| 241 |
+
|
| 242 |
+
interface ActivePicker {
|
| 243 |
+
mode: "create" | "update";
|
| 244 |
+
modality: ModalityConfig;
|
| 245 |
+
nodeId?: string;
|
| 246 |
+
anchorX?: number;
|
| 247 |
+
anchorY?: number;
|
| 248 |
+
initialSource?: "spaces" | "models" | "datasets";
|
| 249 |
+
initialSubtab?: string;
|
| 250 |
+
}
|
| 251 |
+
let activePicker: ActivePicker | null = $state(null);
|
| 252 |
+
|
| 253 |
+
interface PendingDrop {
|
| 254 |
+
from_node_id: string;
|
| 255 |
+
from_port_id: string;
|
| 256 |
+
type: PortType;
|
| 257 |
+
x: number;
|
| 258 |
+
y: number;
|
| 259 |
+
reversed?: boolean;
|
| 260 |
+
positionOnly?: boolean;
|
| 261 |
+
}
|
| 262 |
+
let pendingDrop: PendingDrop | null = $state(null);
|
| 263 |
+
|
| 264 |
+
interface DropOption {
|
| 265 |
+
kind: "model" | "component";
|
| 266 |
+
label: string;
|
| 267 |
+
subtab?: string;
|
| 268 |
+
}
|
| 269 |
+
interface DropChoice {
|
| 270 |
+
clientX: number;
|
| 271 |
+
clientY: number;
|
| 272 |
+
modelOptions: DropOption[];
|
| 273 |
+
componentOptions: DropOption[];
|
| 274 |
+
/** true β user dragged from an input port (needs a Source);
|
| 275 |
+
* false β user dragged from an output port (needs an Output sink). */
|
| 276 |
+
reversed: boolean;
|
| 277 |
+
}
|
| 278 |
+
let dropChoice: DropChoice | null = $state(null);
|
| 279 |
+
|
| 280 |
+
interface DoubleClickMenu {
|
| 281 |
+
clientX: number;
|
| 282 |
+
clientY: number;
|
| 283 |
+
canvasX: number;
|
| 284 |
+
canvasY: number;
|
| 285 |
+
}
|
| 286 |
+
let doubleClickMenu: DoubleClickMenu | null = $state(null);
|
| 287 |
+
|
| 288 |
+
function inputOutputLabel(type: PortType, reversed: boolean): string {
|
| 289 |
+
const base = portMeta(type)?.label ?? "File";
|
| 290 |
+
// When dragging from an input (reversed), media types want an "Upload"
|
| 291 |
+
// affordance; scalar types reuse their own label as the source widget.
|
| 292 |
+
if (reversed) {
|
| 293 |
+
const scalar =
|
| 294 |
+
type === "text" ||
|
| 295 |
+
type === "number" ||
|
| 296 |
+
type === "json" ||
|
| 297 |
+
type === "boolean";
|
| 298 |
+
return scalar ? base : "Upload";
|
| 299 |
+
}
|
| 300 |
+
return base;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// βββ Context for node components ββββββββββββββββββββββββββββββββββββββββββββ
|
| 304 |
+
const wfCtx = $state({
|
| 305 |
+
pending: null as Pending | null,
|
| 306 |
+
nodeStatus: {} as Record<string, NodeStatus>,
|
| 307 |
+
nodeErrors: {} as Record<string, string>,
|
| 308 |
+
staleNodes: new Set<string>(),
|
| 309 |
+
connectedPorts: new Set<string>(),
|
| 310 |
+
ondatachange: updateNodeData,
|
| 311 |
+
onremove: (id: string) => removeNode(id),
|
| 312 |
+
onopenpicker: (id: string) => openPickerForNode(id),
|
| 313 |
+
onswitchendpoint: (id: string, endpointName: string) =>
|
| 314 |
+
switch_endpoint(id, endpointName),
|
| 315 |
+
onhydratendpoints: async (id: string, spaceId: string) => {
|
| 316 |
+
try {
|
| 317 |
+
const info = await fetchSpaceApi(spaceId);
|
| 318 |
+
if (!info.endpoints || info.endpoints.length === 0) {
|
| 319 |
+
showToast(`${spaceId} has no usable endpoints`, 4000, "warning");
|
| 320 |
+
return;
|
| 321 |
+
}
|
| 322 |
+
hydrate_endpoints(id, info.endpoints);
|
| 323 |
+
if (info.endpoints.length === 1) {
|
| 324 |
+
showToast(`${spaceId} only exposes one endpoint`, 3000);
|
| 325 |
+
}
|
| 326 |
+
} catch (err) {
|
| 327 |
+
showToast(
|
| 328 |
+
err instanceof Error ? err.message : "Failed to load endpoints",
|
| 329 |
+
4000,
|
| 330 |
+
"error"
|
| 331 |
+
);
|
| 332 |
+
}
|
| 333 |
+
},
|
| 334 |
+
onrunnode: (id: string) => void runNode(id),
|
| 335 |
+
onselect: (id: string) => selectNode(id),
|
| 336 |
+
onnodepointerdown: (e: PointerEvent, id: string) => startNodeDrag(e, id),
|
| 337 |
+
onportpointerdown: (
|
| 338 |
+
e: PointerEvent,
|
| 339 |
+
nodeId: string,
|
| 340 |
+
portId: string,
|
| 341 |
+
type: PortType,
|
| 342 |
+
isInput: boolean
|
| 343 |
+
) => startConnection(e, nodeId, portId, type, isInput)
|
| 344 |
+
});
|
| 345 |
+
setContext("wf", wfCtx);
|
| 346 |
+
|
| 347 |
+
$effect(() => {
|
| 348 |
+
wfCtx.pending = activeConnection;
|
| 349 |
+
});
|
| 350 |
+
$effect(() => {
|
| 351 |
+
wfCtx.nodeStatus = nodeStatus;
|
| 352 |
+
});
|
| 353 |
+
$effect(() => {
|
| 354 |
+
wfCtx.nodeErrors = nodeErrors;
|
| 355 |
+
});
|
| 356 |
+
$effect(() => {
|
| 357 |
+
wfCtx.staleNodes = staleNodes;
|
| 358 |
+
});
|
| 359 |
+
$effect(() => {
|
| 360 |
+
wfCtx.connectedPorts = connectedPortsSet();
|
| 361 |
+
});
|
| 362 |
+
|
| 363 |
+
// βββ Custom canvas event handlers βββββββββββββββββββββββββββββββββββββββββββ
|
| 364 |
+
|
| 365 |
+
function clientToCanvas(
|
| 366 |
+
clientX: number,
|
| 367 |
+
clientY: number
|
| 368 |
+
): { x: number; y: number } {
|
| 369 |
+
const r = canvasEl?.getBoundingClientRect();
|
| 370 |
+
if (!r) return { x: 0, y: 0 };
|
| 371 |
+
return {
|
| 372 |
+
x: (clientX - r.left - viewport.x) / viewport.zoom,
|
| 373 |
+
y: (clientY - r.top - viewport.y) / viewport.zoom
|
| 374 |
+
};
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
function onCanvasPointerDown(e: PointerEvent): void {
|
| 378 |
+
if (e.button !== 0) return;
|
| 379 |
+
const target = e.target as HTMLElement;
|
| 380 |
+
// Only start pan when clicking truly empty canvas β not nodes, edges, ports, UI
|
| 381 |
+
if (
|
| 382 |
+
target.closest(
|
| 383 |
+
".node-pos-wrap, .edge-path, .picker-panel, .drop-menu, .add-node-menu, .bottom-bar, .zoom-controls, .toolbar"
|
| 384 |
+
)
|
| 385 |
+
) {
|
| 386 |
+
return;
|
| 387 |
+
}
|
| 388 |
+
dragMode = {
|
| 389 |
+
kind: "pan",
|
| 390 |
+
startX: e.clientX,
|
| 391 |
+
startY: e.clientY,
|
| 392 |
+
vx: viewport.x,
|
| 393 |
+
vy: viewport.y
|
| 394 |
+
};
|
| 395 |
+
canvasEl.setPointerCapture(e.pointerId);
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
function onWheel(e: WheelEvent): void {
|
| 399 |
+
if (!canvasEl) return;
|
| 400 |
+
e.preventDefault();
|
| 401 |
+
const r = canvasEl.getBoundingClientRect();
|
| 402 |
+
const cx = e.clientX - r.left;
|
| 403 |
+
const cy = e.clientY - r.top;
|
| 404 |
+
const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
| 405 |
+
const oldZoom = viewport.zoom;
|
| 406 |
+
const newZoom = Math.max(0.15, Math.min(4, oldZoom * factor));
|
| 407 |
+
viewport = {
|
| 408 |
+
x: cx - (cx - viewport.x) * (newZoom / oldZoom),
|
| 409 |
+
y: cy - (cy - viewport.y) * (newZoom / oldZoom),
|
| 410 |
+
zoom: newZoom
|
| 411 |
+
};
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
function startNodeDrag(e: PointerEvent, nodeId: string): void {
|
| 415 |
+
if (e.button !== 0) return;
|
| 416 |
+
const node = legacyView.nodes.find((n) => n.id === nodeId);
|
| 417 |
+
if (!node) return;
|
| 418 |
+
e.stopPropagation();
|
| 419 |
+
dragMode = {
|
| 420 |
+
kind: "node",
|
| 421 |
+
nodeId,
|
| 422 |
+
startClientX: e.clientX,
|
| 423 |
+
startClientY: e.clientY,
|
| 424 |
+
startNodeX: node.x,
|
| 425 |
+
startNodeY: node.y
|
| 426 |
+
};
|
| 427 |
+
canvasEl?.setPointerCapture(e.pointerId);
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
function startConnection(
|
| 431 |
+
e: PointerEvent,
|
| 432 |
+
nodeId: string,
|
| 433 |
+
portId: string,
|
| 434 |
+
type: PortType,
|
| 435 |
+
isInput: boolean
|
| 436 |
+
): void {
|
| 437 |
+
if (e.button !== 0) return;
|
| 438 |
+
e.stopPropagation();
|
| 439 |
+
const { x, y } = clientToCanvas(e.clientX, e.clientY);
|
| 440 |
+
dragMode = {
|
| 441 |
+
kind: "connection",
|
| 442 |
+
fromNodeId: nodeId,
|
| 443 |
+
fromPortId: portId,
|
| 444 |
+
type,
|
| 445 |
+
reversed: isInput,
|
| 446 |
+
cursorCanvasX: x,
|
| 447 |
+
cursorCanvasY: y
|
| 448 |
+
};
|
| 449 |
+
activeConnection = {
|
| 450 |
+
from_node_id: nodeId,
|
| 451 |
+
from_port_id: portId,
|
| 452 |
+
type,
|
| 453 |
+
reversed: isInput
|
| 454 |
+
};
|
| 455 |
+
canvasEl?.setPointerCapture(e.pointerId);
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
function onCanvasPointerMove(e: PointerEvent): void {
|
| 459 |
+
if (!dragMode) return;
|
| 460 |
+
if (dragMode.kind === "pan") {
|
| 461 |
+
viewport = {
|
| 462 |
+
...viewport,
|
| 463 |
+
x: dragMode.vx + (e.clientX - dragMode.startX),
|
| 464 |
+
y: dragMode.vy + (e.clientY - dragMode.startY)
|
| 465 |
+
};
|
| 466 |
+
} else if (dragMode.kind === "node") {
|
| 467 |
+
const dx = (e.clientX - dragMode.startClientX) / viewport.zoom;
|
| 468 |
+
const dy = (e.clientY - dragMode.startClientY) / viewport.zoom;
|
| 469 |
+
moveNode(
|
| 470 |
+
dragMode.nodeId,
|
| 471 |
+
dragMode.startNodeX + dx,
|
| 472 |
+
dragMode.startNodeY + dy
|
| 473 |
+
);
|
| 474 |
+
} else if (dragMode.kind === "connection") {
|
| 475 |
+
const { x, y } = clientToCanvas(e.clientX, e.clientY);
|
| 476 |
+
dragMode = { ...dragMode, cursorCanvasX: x, cursorCanvasY: y };
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
function onCanvasPointerUp(e: PointerEvent): void {
|
| 481 |
+
if (!dragMode) return;
|
| 482 |
+
const mode = dragMode;
|
| 483 |
+
if (mode.kind === "connection") {
|
| 484 |
+
activeConnection = null;
|
| 485 |
+
const targetEl = document.elementFromPoint(
|
| 486 |
+
e.clientX,
|
| 487 |
+
e.clientY
|
| 488 |
+
) as HTMLElement | null;
|
| 489 |
+
|
| 490 |
+
// 1. Precise hit on a port handle β use it directly.
|
| 491 |
+
const portEl = targetEl?.closest("[data-port-id]") as HTMLElement | null;
|
| 492 |
+
if (portEl) {
|
| 493 |
+
const toNodeId = portEl.getAttribute("data-node-id");
|
| 494 |
+
const toPortId = portEl.getAttribute("data-port-id");
|
| 495 |
+
const toIsInput =
|
| 496 |
+
portEl.getAttribute("data-port-direction") === "input";
|
| 497 |
+
if (toNodeId && toPortId && toNodeId !== mode.fromNodeId) {
|
| 498 |
+
tryCreateEdge(
|
| 499 |
+
mode.fromNodeId,
|
| 500 |
+
mode.fromPortId,
|
| 501 |
+
mode.reversed,
|
| 502 |
+
toNodeId,
|
| 503 |
+
toPortId,
|
| 504 |
+
toIsInput
|
| 505 |
+
);
|
| 506 |
+
}
|
| 507 |
+
dragMode = null;
|
| 508 |
+
try {
|
| 509 |
+
canvasEl?.releasePointerCapture(e.pointerId);
|
| 510 |
+
} catch {}
|
| 511 |
+
return;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
// 2. Fuzzy hit β dropped on a node body, not its port. Find the first
|
| 515 |
+
// compatible free port on that node and use it. This is what users
|
| 516 |
+
// usually mean: "connect to that node", not "to that 12px circle."
|
| 517 |
+
const nodeWrap = targetEl?.closest(
|
| 518 |
+
"[data-node-id]"
|
| 519 |
+
) as HTMLElement | null;
|
| 520 |
+
const droppedNodeId = nodeWrap?.getAttribute("data-node-id");
|
| 521 |
+
if (droppedNodeId && droppedNodeId !== mode.fromNodeId) {
|
| 522 |
+
const autoPort = pickCompatiblePort(
|
| 523 |
+
droppedNodeId,
|
| 524 |
+
mode.type,
|
| 525 |
+
mode.reversed
|
| 526 |
+
);
|
| 527 |
+
if (autoPort) {
|
| 528 |
+
tryCreateEdge(
|
| 529 |
+
mode.fromNodeId,
|
| 530 |
+
mode.fromPortId,
|
| 531 |
+
mode.reversed,
|
| 532 |
+
droppedNodeId,
|
| 533 |
+
autoPort.id,
|
| 534 |
+
autoPort.direction === "input"
|
| 535 |
+
);
|
| 536 |
+
dragMode = null;
|
| 537 |
+
try {
|
| 538 |
+
canvasEl?.releasePointerCapture(e.pointerId);
|
| 539 |
+
} catch {}
|
| 540 |
+
return;
|
| 541 |
+
}
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
// 3. Empty drop β open the drop-choice menu so the user can spawn a new node.
|
| 545 |
+
const r = canvasEl?.getBoundingClientRect();
|
| 546 |
+
if (r) {
|
| 547 |
+
const drop: PendingDrop = {
|
| 548 |
+
from_node_id: mode.fromNodeId,
|
| 549 |
+
from_port_id: mode.fromPortId,
|
| 550 |
+
type: mode.type,
|
| 551 |
+
x: mode.cursorCanvasX,
|
| 552 |
+
y: mode.cursorCanvasY,
|
| 553 |
+
reversed: mode.reversed
|
| 554 |
+
};
|
| 555 |
+
const choice: DropChoice = {
|
| 556 |
+
clientX: e.clientX - r.left,
|
| 557 |
+
clientY: e.clientY - r.top,
|
| 558 |
+
modelOptions: buildModelOptions(mode.type),
|
| 559 |
+
componentOptions: buildComponentOptions(mode.type, mode.reversed),
|
| 560 |
+
reversed: mode.reversed
|
| 561 |
+
};
|
| 562 |
+
setTimeout(() => {
|
| 563 |
+
pendingDrop = drop;
|
| 564 |
+
dropChoice = choice;
|
| 565 |
+
}, 0);
|
| 566 |
+
}
|
| 567 |
+
}
|
| 568 |
+
dragMode = null;
|
| 569 |
+
try {
|
| 570 |
+
canvasEl?.releasePointerCapture(e.pointerId);
|
| 571 |
+
} catch {}
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
/**
|
| 575 |
+
* Choose the best port on `nodeId` for a connection of `type` whose source
|
| 576 |
+
* is reversed/forward. Forward = we're dragging an output, so we want an
|
| 577 |
+
* unconnected input on the target; reversed = we're dragging an input, so
|
| 578 |
+
* we want any output on the target. Returns null if nothing fits.
|
| 579 |
+
*/
|
| 580 |
+
function pickCompatiblePort(
|
| 581 |
+
nodeId: string,
|
| 582 |
+
type: PortType,
|
| 583 |
+
reversed: boolean
|
| 584 |
+
): { id: string; direction: "input" | "output" } | null {
|
| 585 |
+
const target = legacyView.nodes.find((n) => n.id === nodeId);
|
| 586 |
+
if (!target) return null;
|
| 587 |
+
if (reversed) {
|
| 588 |
+
const out = target.outputs.find((p) => ports_compatible(p.type, type));
|
| 589 |
+
return out ? { id: out.id, direction: "output" } : null;
|
| 590 |
+
}
|
| 591 |
+
const inPort = target.inputs.find(
|
| 592 |
+
(p) =>
|
| 593 |
+
ports_compatible(type, p.type) &&
|
| 594 |
+
!$workflow.edges.some(
|
| 595 |
+
(e) => e.to_node_id === nodeId && e.to_port_id === p.id
|
| 596 |
+
)
|
| 597 |
+
);
|
| 598 |
+
return inPort ? { id: inPort.id, direction: "input" } : null;
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
/**
|
| 602 |
+
* Cache of measured port-handle centers in canvas-space. Re-populated after
|
| 603 |
+
* any node change via the effect below; canvas coords are invariant to
|
| 604 |
+
* pan/zoom so we don't need to re-measure on viewport changes.
|
| 605 |
+
*/
|
| 606 |
+
let portPositions = $state(new Map<string, { x: number; y: number }>());
|
| 607 |
+
|
| 608 |
+
function portKey(
|
| 609 |
+
nodeId: string,
|
| 610 |
+
portId: string,
|
| 611 |
+
direction: "input" | "output"
|
| 612 |
+
): string {
|
| 613 |
+
return `${nodeId}:${portId}:${direction}`;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
$effect(() => {
|
| 617 |
+
legacyView.nodes;
|
| 618 |
+
// Defer until after Svelte commits this render so the handle elements
|
| 619 |
+
// have their final positions in the DOM.
|
| 620 |
+
const raf = requestAnimationFrame(() => {
|
| 621 |
+
if (!canvasEl) return;
|
| 622 |
+
const cr = canvasEl.getBoundingClientRect();
|
| 623 |
+
const next = new Map<string, { x: number; y: number }>();
|
| 624 |
+
canvasEl.querySelectorAll<HTMLElement>("[data-port-id]").forEach((el) => {
|
| 625 |
+
const nodeId = el.getAttribute("data-node-id");
|
| 626 |
+
const portId = el.getAttribute("data-port-id");
|
| 627 |
+
const dir = el.getAttribute("data-port-direction") as
|
| 628 |
+
| "input"
|
| 629 |
+
| "output"
|
| 630 |
+
| null;
|
| 631 |
+
if (!nodeId || !portId || !dir) return;
|
| 632 |
+
const r = el.getBoundingClientRect();
|
| 633 |
+
const cx = r.left + r.width / 2 - cr.left;
|
| 634 |
+
const cy = r.top + r.height / 2 - cr.top;
|
| 635 |
+
next.set(portKey(nodeId, portId, dir), {
|
| 636 |
+
x: (cx - viewport.x) / viewport.zoom,
|
| 637 |
+
y: (cy - viewport.y) / viewport.zoom
|
| 638 |
+
});
|
| 639 |
+
});
|
| 640 |
+
portPositions = next;
|
| 641 |
+
});
|
| 642 |
+
return () => cancelAnimationFrame(raf);
|
| 643 |
+
});
|
| 644 |
+
|
| 645 |
+
/**
|
| 646 |
+
* Canvas-space position of a port handle. Uses the measured DOM position
|
| 647 |
+
* when available; falls back to a coarse estimate for the first paint
|
| 648 |
+
* before the measurement effect has run (handles are ~24px outside the
|
| 649 |
+
* node edge, so the heuristic offsets X by Β±18 to hit the handle center).
|
| 650 |
+
*/
|
| 651 |
+
function portPos(
|
| 652 |
+
nodeId: string,
|
| 653 |
+
portId: string,
|
| 654 |
+
direction: "input" | "output"
|
| 655 |
+
): { x: number; y: number } | null {
|
| 656 |
+
const measured = portPositions.get(portKey(nodeId, portId, direction));
|
| 657 |
+
if (measured) return measured;
|
| 658 |
+
const node = legacyView.nodes.find((n) => n.id === nodeId);
|
| 659 |
+
if (!node) return null;
|
| 660 |
+
const ports = direction === "input" ? node.inputs : node.outputs;
|
| 661 |
+
const i = ports.findIndex((p) => p.id === portId);
|
| 662 |
+
if (i < 0) return null;
|
| 663 |
+
const headerHeight = 36;
|
| 664 |
+
const rowHeight = 30;
|
| 665 |
+
const y = node.y + headerHeight + i * rowHeight + rowHeight / 2;
|
| 666 |
+
const x = direction === "input" ? node.x - 18 : node.x + node.width + 18;
|
| 667 |
+
return { x, y };
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
function bezier(
|
| 671 |
+
a: { x: number; y: number },
|
| 672 |
+
b: { x: number; y: number }
|
| 673 |
+
): string {
|
| 674 |
+
const dx = Math.max(40, Math.abs(b.x - a.x) * 0.5);
|
| 675 |
+
return `M ${a.x} ${a.y} C ${a.x + dx} ${a.y}, ${b.x - dx} ${b.y}, ${b.x} ${b.y}`;
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
function edgePath(edge: WFEdge): string | null {
|
| 679 |
+
const a = portPos(edge.from_node_id, edge.from_port_id, "output");
|
| 680 |
+
const b = portPos(edge.to_node_id, edge.to_port_id, "input");
|
| 681 |
+
if (!a || !b) return null;
|
| 682 |
+
return bezier(a, b);
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
function connectionPreviewPath(
|
| 686 |
+
mode: Extract<DragMode, { kind: "connection" }>
|
| 687 |
+
): string | null {
|
| 688 |
+
const port = portPos(
|
| 689 |
+
mode.fromNodeId,
|
| 690 |
+
mode.fromPortId,
|
| 691 |
+
mode.reversed ? "input" : "output"
|
| 692 |
+
);
|
| 693 |
+
if (!port) return null;
|
| 694 |
+
const cursor = { x: mode.cursorCanvasX, y: mode.cursorCanvasY };
|
| 695 |
+
return mode.reversed ? bezier(cursor, port) : bezier(port, cursor);
|
| 696 |
+
}
|
| 697 |
+
|
| 698 |
+
function tryCreateEdge(
|
| 699 |
+
fromId: string,
|
| 700 |
+
fromPort: string,
|
| 701 |
+
fromIsInput: boolean,
|
| 702 |
+
toId: string,
|
| 703 |
+
toPort: string,
|
| 704 |
+
toIsInput: boolean
|
| 705 |
+
): void {
|
| 706 |
+
if (fromIsInput === toIsInput) return; // both ends same direction β invalid
|
| 707 |
+
// Normalize: edges always flow output β input
|
| 708 |
+
const [sourceId, sourcePort, targetId, targetPort] = fromIsInput
|
| 709 |
+
? [toId, toPort, fromId, fromPort]
|
| 710 |
+
: [fromId, fromPort, toId, toPort];
|
| 711 |
+
const sourceNode = legacyView.nodes.find((n) => n.id === sourceId);
|
| 712 |
+
const targetNode = legacyView.nodes.find((n) => n.id === targetId);
|
| 713 |
+
if (!sourceNode || !targetNode) return;
|
| 714 |
+
const outPort = sourceNode.outputs.find((p) => p.id === sourcePort);
|
| 715 |
+
const inPort = targetNode.inputs.find((p) => p.id === targetPort);
|
| 716 |
+
if (!outPort || !inPort || !ports_compatible(outPort.type, inPort.type))
|
| 717 |
+
return;
|
| 718 |
+
addEdge({
|
| 719 |
+
from_node_id: sourceId,
|
| 720 |
+
from_port_id: sourcePort,
|
| 721 |
+
to_node_id: targetId,
|
| 722 |
+
to_port_id: targetPort,
|
| 723 |
+
type: outPort.type
|
| 724 |
+
});
|
| 725 |
+
}
|
| 726 |
+
|
| 727 |
+
function buildModelOptions(type: PortType): DropOption[] {
|
| 728 |
+
const modality = modalityForPort(type);
|
| 729 |
+
if (!modality) return [];
|
| 730 |
+
return modality.subtabs
|
| 731 |
+
.filter((st) => st.key !== "all")
|
| 732 |
+
.map((st) => ({
|
| 733 |
+
kind: "model" as const,
|
| 734 |
+
label: st.label,
|
| 735 |
+
subtab: st.key
|
| 736 |
+
}));
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
function buildComponentOptions(
|
| 740 |
+
type: PortType,
|
| 741 |
+
reversed: boolean
|
| 742 |
+
): DropOption[] {
|
| 743 |
+
return [
|
| 744 |
+
{ kind: "component" as const, label: inputOutputLabel(type, reversed) }
|
| 745 |
+
];
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
function handleDropChoiceModel(subtab?: string): void {
|
| 749 |
+
dropChoice = null;
|
| 750 |
+
if (!pendingDrop) return;
|
| 751 |
+
const modality = modalityForPort(pendingDrop.type);
|
| 752 |
+
if (!modality) return;
|
| 753 |
+
activePicker = { mode: "create", modality, initialSubtab: subtab };
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
function handleDropChoiceUpload(): void {
|
| 757 |
+
dropChoice = null;
|
| 758 |
+
const drop = pendingDrop;
|
| 759 |
+
pendingDrop = null;
|
| 760 |
+
if (!drop) return;
|
| 761 |
+
const typedComponents: Record<string, any> = {};
|
| 762 |
+
for (const c of LIBRARY.components) {
|
| 763 |
+
typedComponents[c.outputs[0]?.type ?? "any"] = c;
|
| 764 |
+
}
|
| 765 |
+
const template = typedComponents[drop.type] ?? LIBRARY.components[0];
|
| 766 |
+
const rawX = drop.reversed
|
| 767 |
+
? drop.x - (template.width ?? 200) - 80
|
| 768 |
+
: drop.x - (template.width ?? 200) / 2;
|
| 769 |
+
const { x, y } = findFreeSpot(rawX, drop.y - 45);
|
| 770 |
+
// reversed=true β user dragged from an input port; they need a Source
|
| 771 |
+
// (reference) supplying that value. reversed=false β user dragged from
|
| 772 |
+
// an output port; they need a Sink (subject) displaying that value.
|
| 773 |
+
const role: "reference" | "subject" = drop.reversed
|
| 774 |
+
? "reference"
|
| 775 |
+
: "subject";
|
| 776 |
+
const newId = addNode(role, template, x, y);
|
| 777 |
+
const newNode = legacyView.nodes.find((n) => n.id === newId);
|
| 778 |
+
if (drop.reversed) {
|
| 779 |
+
const outputPort = newNode?.outputs.find((p: any) =>
|
| 780 |
+
ports_compatible(p.type, drop.type)
|
| 781 |
+
);
|
| 782 |
+
if (outputPort) {
|
| 783 |
+
addEdge({
|
| 784 |
+
from_node_id: newId,
|
| 785 |
+
from_port_id: outputPort.id,
|
| 786 |
+
to_node_id: drop.from_node_id,
|
| 787 |
+
to_port_id: drop.from_port_id,
|
| 788 |
+
type: drop.type
|
| 789 |
+
});
|
| 790 |
+
}
|
| 791 |
+
} else {
|
| 792 |
+
const inputPort = newNode?.inputs.find((p: any) =>
|
| 793 |
+
ports_compatible(drop.type, p.type)
|
| 794 |
+
);
|
| 795 |
+
if (inputPort) {
|
| 796 |
+
addEdge({
|
| 797 |
+
from_node_id: drop.from_node_id,
|
| 798 |
+
from_port_id: drop.from_port_id,
|
| 799 |
+
to_node_id: newId,
|
| 800 |
+
to_port_id: inputPort.id,
|
| 801 |
+
type: drop.type
|
| 802 |
+
});
|
| 803 |
+
}
|
| 804 |
+
}
|
| 805 |
+
}
|
| 806 |
+
|
| 807 |
+
function handleCanvasDoubleClick(e: MouseEvent): void {
|
| 808 |
+
const target = e.target as HTMLElement;
|
| 809 |
+
if (
|
| 810 |
+
target.closest(".node-pos-wrap") ||
|
| 811 |
+
target.closest(".drop-menu") ||
|
| 812 |
+
target.closest(".picker-panel")
|
| 813 |
+
)
|
| 814 |
+
return;
|
| 815 |
+
const r = canvasEl?.getBoundingClientRect();
|
| 816 |
+
if (!r) return;
|
| 817 |
+
setTimeout(() => {
|
| 818 |
+
doubleClickMenu = {
|
| 819 |
+
clientX: e.clientX - r.left,
|
| 820 |
+
clientY: e.clientY - r.top,
|
| 821 |
+
canvasX: (e.clientX - r.left - viewport.x) / viewport.zoom,
|
| 822 |
+
canvasY: (e.clientY - r.top - viewport.y) / viewport.zoom
|
| 823 |
+
};
|
| 824 |
+
}, 0);
|
| 825 |
+
}
|
| 826 |
+
|
| 827 |
+
function handleDoubleClickInputNode(portType: PortType): void {
|
| 828 |
+
if (!doubleClickMenu) return;
|
| 829 |
+
const { canvasX, canvasY } = doubleClickMenu;
|
| 830 |
+
doubleClickMenu = null;
|
| 831 |
+
const typedComponents: Record<string, any> = {};
|
| 832 |
+
for (const c of LIBRARY.components) {
|
| 833 |
+
typedComponents[c.outputs[0]?.type ?? "any"] = c;
|
| 834 |
+
}
|
| 835 |
+
const template = typedComponents[portType] ?? LIBRARY.components[0];
|
| 836 |
+
addNode(
|
| 837 |
+
"reference",
|
| 838 |
+
template,
|
| 839 |
+
canvasX - (template.width ?? 200) / 2,
|
| 840 |
+
canvasY - 45
|
| 841 |
+
);
|
| 842 |
+
}
|
| 843 |
+
|
| 844 |
+
function handleDoubleClickUpload(): void {
|
| 845 |
+
if (!doubleClickMenu) return;
|
| 846 |
+
const { canvasX, canvasY } = doubleClickMenu;
|
| 847 |
+
doubleClickMenu = null;
|
| 848 |
+
|
| 849 |
+
// Attach the input to body briefly. Safari (and some popup
|
| 850 |
+
// blockers) refuse to open the OS file-picker dialog when
|
| 851 |
+
// `input.click()` is called on a detached element, even from
|
| 852 |
+
// a real user gesture.
|
| 853 |
+
const input = document.createElement("input");
|
| 854 |
+
input.type = "file";
|
| 855 |
+
input.accept = "image/*,audio/*,video/*";
|
| 856 |
+
input.style.display = "none";
|
| 857 |
+
document.body.appendChild(input);
|
| 858 |
+
const cleanup = (): void => {
|
| 859 |
+
try {
|
| 860 |
+
document.body.removeChild(input);
|
| 861 |
+
} catch {
|
| 862 |
+
/* noop */
|
| 863 |
+
}
|
| 864 |
+
};
|
| 865 |
+
input.onchange = () => {
|
| 866 |
+
const file = input.files?.[0];
|
| 867 |
+
if (!file) {
|
| 868 |
+
cleanup();
|
| 869 |
+
return;
|
| 870 |
+
}
|
| 871 |
+
let portType: PortType = "file";
|
| 872 |
+
if (file.type.startsWith("image/")) portType = "image";
|
| 873 |
+
else if (file.type.startsWith("audio/")) portType = "audio";
|
| 874 |
+
else if (file.type.startsWith("video/")) portType = "video";
|
| 875 |
+
const typedComponents: Record<string, any> = {};
|
| 876 |
+
for (const c of LIBRARY.components) {
|
| 877 |
+
typedComponents[c.outputs[0]?.type ?? "any"] = c;
|
| 878 |
+
}
|
| 879 |
+
const template = typedComponents[portType] ?? LIBRARY.components[0];
|
| 880 |
+
const { x: fx, y: fy } = findFreeSpot(
|
| 881 |
+
canvasX - (template.width ?? 200) / 2,
|
| 882 |
+
canvasY - 45
|
| 883 |
+
);
|
| 884 |
+
const newId = addNode("reference", template, fx, fy);
|
| 885 |
+
const url = URL.createObjectURL(file);
|
| 886 |
+
const portId = template.outputs[0]?.id;
|
| 887 |
+
if (portId && newId) {
|
| 888 |
+
updateNodeData(newId, portId, {
|
| 889 |
+
url,
|
| 890 |
+
path: file.name,
|
| 891 |
+
name: file.name
|
| 892 |
+
} as any);
|
| 893 |
+
}
|
| 894 |
+
cleanup();
|
| 895 |
+
};
|
| 896 |
+
// `cancel` fires when the user dismisses the dialog without picking.
|
| 897 |
+
input.oncancel = cleanup;
|
| 898 |
+
input.click();
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
function handleDoubleClickSpaceModel(modality: ModalityConfig): void {
|
| 902 |
+
if (!doubleClickMenu) return;
|
| 903 |
+
const { canvasX, canvasY } = doubleClickMenu;
|
| 904 |
+
doubleClickMenu = null;
|
| 905 |
+
pendingDrop = {
|
| 906 |
+
from_node_id: "",
|
| 907 |
+
from_port_id: "",
|
| 908 |
+
type: "any" as PortType,
|
| 909 |
+
x: canvasX,
|
| 910 |
+
y: canvasY,
|
| 911 |
+
positionOnly: true
|
| 912 |
+
};
|
| 913 |
+
activePicker = { mode: "create", modality };
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
// βββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 917 |
+
|
| 918 |
+
function resolveCurrentInputs(node: WFNode): Record<string, unknown> {
|
| 919 |
+
return resolveCurrentInputsImpl(node, legacyView.nodes, $workflow.edges);
|
| 920 |
+
}
|
| 921 |
+
|
| 922 |
+
const staleNodes = $derived(
|
| 923 |
+
computeStaleNodes(
|
| 924 |
+
legacyView.nodes,
|
| 925 |
+
$workflow.edges,
|
| 926 |
+
nodeStatus,
|
| 927 |
+
nodeInputSnapshots
|
| 928 |
+
)
|
| 929 |
+
);
|
| 930 |
+
|
| 931 |
+
function canvasCenter(): { x: number; y: number } {
|
| 932 |
+
if (!canvasEl) return { x: 200, y: 200 };
|
| 933 |
+
const r = canvasEl.getBoundingClientRect();
|
| 934 |
+
return {
|
| 935 |
+
x: (r.width / 2 - viewport.x) / viewport.zoom - 150,
|
| 936 |
+
y: (r.height / 2 - viewport.y) / viewport.zoom - 60
|
| 937 |
+
};
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
/**
|
| 941 |
+
* Walk diagonally from (x, y) in 28px steps until an open spot is found
|
| 942 |
+
* that doesn't visually overlap an existing node. Used by any code path
|
| 943 |
+
* that drops a fresh node at a fixed fallback position (canvas center,
|
| 944 |
+
* picker create, etc.) β without this, successive adds stack identically.
|
| 945 |
+
*/
|
| 946 |
+
function findFreeSpot(x: number, y: number): { x: number; y: number } {
|
| 947 |
+
return findFreeSpotImpl(legacyView.nodes, x, y);
|
| 948 |
+
}
|
| 949 |
+
|
| 950 |
+
async function addTemplateToCanvas(
|
| 951 |
+
template: any,
|
| 952 |
+
x?: number,
|
| 953 |
+
y?: number
|
| 954 |
+
): Promise<string | null> {
|
| 955 |
+
if (
|
| 956 |
+
template.source === "space" &&
|
| 957 |
+
template.space_id &&
|
| 958 |
+
template.inputs.length === 0
|
| 959 |
+
) {
|
| 960 |
+
showToast(`Connecting to ${template.space_id}...`);
|
| 961 |
+
try {
|
| 962 |
+
const apiInfo = await fetchSpaceApi(template.space_id);
|
| 963 |
+
template.inputs = apiInfo.inputs;
|
| 964 |
+
template.outputs = apiInfo.outputs;
|
| 965 |
+
template.endpoint = apiInfo.endpoint;
|
| 966 |
+
template.width = apiInfo.width;
|
| 967 |
+
} catch (err) {
|
| 968 |
+
showToast(
|
| 969 |
+
err instanceof Error ? err.message : "Failed to connect to Space",
|
| 970 |
+
5000,
|
| 971 |
+
"error"
|
| 972 |
+
);
|
| 973 |
+
return null;
|
| 974 |
+
}
|
| 975 |
+
}
|
| 976 |
+
if (x === undefined || y === undefined) {
|
| 977 |
+
const nodes = legacyView.nodes;
|
| 978 |
+
x =
|
| 979 |
+
nodes.length > 0
|
| 980 |
+
? Math.max(...nodes.map((n) => n.x + n.width)) + 80
|
| 981 |
+
: 200;
|
| 982 |
+
y = nodes.length > 0 ? nodes[nodes.length - 1].y : 150;
|
| 983 |
+
}
|
| 984 |
+
return addNode(templateRole(template), template, x, y);
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
async function handleDrop(e: DragEvent): Promise<void> {
|
| 988 |
+
e.preventDefault();
|
| 989 |
+
const raw = e.dataTransfer?.getData("node-template");
|
| 990 |
+
if (!raw) return;
|
| 991 |
+
const template = JSON.parse(raw);
|
| 992 |
+
const r = canvasEl.getBoundingClientRect();
|
| 993 |
+
const x = (e.clientX - r.left - viewport.x) / viewport.zoom - 100;
|
| 994 |
+
const y = (e.clientY - r.top - viewport.y) / viewport.zoom - 45;
|
| 995 |
+
await addTemplateToCanvas(template, x, y);
|
| 996 |
+
}
|
| 997 |
+
|
| 998 |
+
function revokeAllBlobUrls(nodes: WFNode[]): void {
|
| 999 |
+
for (const node of nodes) revoke_blob_urls(node.data);
|
| 1000 |
+
}
|
| 1001 |
+
|
| 1002 |
+
let clearConfirm = $state(false);
|
| 1003 |
+
|
| 1004 |
+
function clearWorkflow(): void {
|
| 1005 |
+
if (legacyView.nodes.length === 0) return;
|
| 1006 |
+
clearConfirm = true;
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
function confirmClearWorkflow(): void {
|
| 1010 |
+
clearConfirm = false;
|
| 1011 |
+
revokeAllBlobUrls(legacyView.nodes);
|
| 1012 |
+
workflow.set({
|
| 1013 |
+
schema_version: "2",
|
| 1014 |
+
name: $workflow.name,
|
| 1015 |
+
runtime: { default: "client" },
|
| 1016 |
+
references: [],
|
| 1017 |
+
operators: [],
|
| 1018 |
+
subjects: [],
|
| 1019 |
+
edges: [],
|
| 1020 |
+
view: { default: "canvas" }
|
| 1021 |
+
});
|
| 1022 |
+
}
|
| 1023 |
+
|
| 1024 |
+
function autoLayout(): void {
|
| 1025 |
+
const sorted = topoSort(legacyView.nodes, $workflow.edges);
|
| 1026 |
+
const edges = $workflow.edges;
|
| 1027 |
+
const depth = new Map<string, number>();
|
| 1028 |
+
for (const node of sorted) {
|
| 1029 |
+
const maxParent = edges
|
| 1030 |
+
.filter((e) => e.to_node_id === node.id)
|
| 1031 |
+
.map((e) => depth.get(e.from_node_id) ?? 0)
|
| 1032 |
+
.reduce((max, d) => Math.max(max, d + 1), 0);
|
| 1033 |
+
depth.set(node.id, maxParent);
|
| 1034 |
+
}
|
| 1035 |
+
const columns = new Map<number, WFNode[]>();
|
| 1036 |
+
for (const node of sorted) {
|
| 1037 |
+
const d = depth.get(node.id) ?? 0;
|
| 1038 |
+
if (!columns.has(d)) columns.set(d, []);
|
| 1039 |
+
columns.get(d)!.push(node);
|
| 1040 |
+
}
|
| 1041 |
+
const gap = 30;
|
| 1042 |
+
const colGap = 80;
|
| 1043 |
+
// Auto-layout produces { id -> {x, y} }; apply to v2 arrays without
|
| 1044 |
+
// changing role membership.
|
| 1045 |
+
const positions = new Map<string, { x: number; y: number }>();
|
| 1046 |
+
let xOffset = 80;
|
| 1047 |
+
for (const [_, col] of [...columns.entries()].sort((a, b) => a[0] - b[0])) {
|
| 1048 |
+
let yOffset = 80;
|
| 1049 |
+
let maxWidth = 0;
|
| 1050 |
+
for (const node of col) {
|
| 1051 |
+
positions.set(node.id, { x: xOffset, y: yOffset });
|
| 1052 |
+
yOffset += node.height + gap;
|
| 1053 |
+
maxWidth = Math.max(maxWidth, node.width);
|
| 1054 |
+
}
|
| 1055 |
+
xOffset += maxWidth + colGap;
|
| 1056 |
+
}
|
| 1057 |
+
workflow.update((wf) => {
|
| 1058 |
+
const reposition = <T extends { id: string; x: number; y: number }>(
|
| 1059 |
+
n: T
|
| 1060 |
+
): T => {
|
| 1061 |
+
const p = positions.get(n.id);
|
| 1062 |
+
return p ? { ...n, x: p.x, y: p.y } : n;
|
| 1063 |
+
};
|
| 1064 |
+
return {
|
| 1065 |
+
...wf,
|
| 1066 |
+
references: wf.references.map(reposition),
|
| 1067 |
+
operators: wf.operators.map(reposition),
|
| 1068 |
+
subjects: wf.subjects.map(reposition)
|
| 1069 |
+
};
|
| 1070 |
+
});
|
| 1071 |
+
}
|
| 1072 |
+
|
| 1073 |
+
async function runNode(targetId: string): Promise<void> {
|
| 1074 |
+
if (running) return;
|
| 1075 |
+
await runWorkflow(buildUpstreamSubgraphImpl($workflow, targetId));
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
async function runWorkflow(target?: Workflow): Promise<void> {
|
| 1079 |
+
if (running) return;
|
| 1080 |
+
running = true;
|
| 1081 |
+
const wfToRun = target ?? $workflow;
|
| 1082 |
+
// Clear status only for nodes we're about to run, so already-finished
|
| 1083 |
+
// nodes outside the target subgraph keep their snapshots + state.
|
| 1084 |
+
const runningIds = new Set([
|
| 1085 |
+
...wfToRun.references.map((n) => n.id),
|
| 1086 |
+
...wfToRun.operators.map((n) => n.id),
|
| 1087 |
+
...wfToRun.subjects.map((n) => n.id)
|
| 1088 |
+
]);
|
| 1089 |
+
nodeStatus = Object.fromEntries(
|
| 1090 |
+
Object.entries(nodeStatus).filter(([id]) => !runningIds.has(id))
|
| 1091 |
+
);
|
| 1092 |
+
nodeErrors = Object.fromEntries(
|
| 1093 |
+
Object.entries(nodeErrors).filter(([id]) => !runningIds.has(id))
|
| 1094 |
+
);
|
| 1095 |
+
abortController = new AbortController();
|
| 1096 |
+
|
| 1097 |
+
const oauthToken = await auth.getOAuthToken();
|
| 1098 |
+
const hasAuth = !!oauthToken || !!auth.hfToken;
|
| 1099 |
+
if (
|
| 1100 |
+
legacyView.nodes.some((n) => n.source === "space" && n.space_id) &&
|
| 1101 |
+
!hasAuth
|
| 1102 |
+
) {
|
| 1103 |
+
showToast(
|
| 1104 |
+
"Running as guest β GPU Spaces may hit quota limits. Sign in with HuggingFace for your own compute.",
|
| 1105 |
+
5000,
|
| 1106 |
+
"warning"
|
| 1107 |
+
);
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
const callSpaceWithToken = server?.call_space
|
| 1111 |
+
? async (spaceId: string, endpoint: string, argsJson: string) =>
|
| 1112 |
+
server.call_space([spaceId, endpoint, argsJson, auth.hfToken || ""])
|
| 1113 |
+
: undefined;
|
| 1114 |
+
|
| 1115 |
+
const callModelWithToken = server?.call_model
|
| 1116 |
+
? async (
|
| 1117 |
+
modelId: string,
|
| 1118 |
+
pipelineTag: string,
|
| 1119 |
+
argsJson: string,
|
| 1120 |
+
provider?: string
|
| 1121 |
+
) =>
|
| 1122 |
+
server.call_model([
|
| 1123 |
+
modelId,
|
| 1124 |
+
pipelineTag,
|
| 1125 |
+
argsJson,
|
| 1126 |
+
auth.hfToken || "",
|
| 1127 |
+
provider ?? ""
|
| 1128 |
+
])
|
| 1129 |
+
: undefined;
|
| 1130 |
+
|
| 1131 |
+
const fetchDatasetWithToken = server?.fetch_dataset
|
| 1132 |
+
? async (
|
| 1133 |
+
datasetId: string,
|
| 1134 |
+
config: string,
|
| 1135 |
+
split: string,
|
| 1136 |
+
offset: string,
|
| 1137 |
+
length: string
|
| 1138 |
+
) =>
|
| 1139 |
+
server.fetch_dataset([
|
| 1140 |
+
datasetId,
|
| 1141 |
+
config,
|
| 1142 |
+
split,
|
| 1143 |
+
offset,
|
| 1144 |
+
length,
|
| 1145 |
+
auth.hfToken || ""
|
| 1146 |
+
])
|
| 1147 |
+
: undefined;
|
| 1148 |
+
|
| 1149 |
+
const callFnWithToken = server?.call_fn
|
| 1150 |
+
? async (fnName: string, argsJson: string) =>
|
| 1151 |
+
server.call_fn([fnName, argsJson])
|
| 1152 |
+
: undefined;
|
| 1153 |
+
|
| 1154 |
+
await executeWorkflow(
|
| 1155 |
+
wfToRun,
|
| 1156 |
+
(nodeId, status, error, errorType) => {
|
| 1157 |
+
nodeStatus = { ...nodeStatus, [nodeId]: status };
|
| 1158 |
+
if (status === "done") {
|
| 1159 |
+
const node = legacyView.nodes.find((n) => n.id === nodeId);
|
| 1160 |
+
if (node) {
|
| 1161 |
+
nodeInputSnapshots = {
|
| 1162 |
+
...nodeInputSnapshots,
|
| 1163 |
+
[nodeId]: JSON.stringify(resolveCurrentInputs(node))
|
| 1164 |
+
};
|
| 1165 |
+
}
|
| 1166 |
+
}
|
| 1167 |
+
if (error) {
|
| 1168 |
+
nodeErrors = { ...nodeErrors, [nodeId]: error };
|
| 1169 |
+
const node = legacyView.nodes.find((n) => n.id === nodeId);
|
| 1170 |
+
const label =
|
| 1171 |
+
node?.label ?? node?.space_id ?? node?.model_id ?? "Node";
|
| 1172 |
+
showToast(
|
| 1173 |
+
`${label}: ${error}`,
|
| 1174 |
+
errorType === "quota" || errorType === "gpu" ? 0 : 5000,
|
| 1175 |
+
"error"
|
| 1176 |
+
);
|
| 1177 |
+
}
|
| 1178 |
+
},
|
| 1179 |
+
(nodeId, portId, value) => {
|
| 1180 |
+
updateNodeData(nodeId, portId, value);
|
| 1181 |
+
},
|
| 1182 |
+
abortController.signal,
|
| 1183 |
+
callSpaceWithToken,
|
| 1184 |
+
callModelWithToken,
|
| 1185 |
+
fetchDatasetWithToken,
|
| 1186 |
+
callFnWithToken,
|
| 1187 |
+
(modelId, prompt, provider, signal, onChunk) =>
|
| 1188 |
+
stream_text_generation({
|
| 1189 |
+
modelId,
|
| 1190 |
+
prompt,
|
| 1191 |
+
provider,
|
| 1192 |
+
hfToken: auth.hfToken || undefined,
|
| 1193 |
+
signal: signal ?? undefined,
|
| 1194 |
+
onChunk
|
| 1195 |
+
})
|
| 1196 |
+
);
|
| 1197 |
+
|
| 1198 |
+
running = false;
|
| 1199 |
+
abortController = null;
|
| 1200 |
+
|
| 1201 |
+
const hasErrors = Object.values(nodeStatus).some((s) => s === "error");
|
| 1202 |
+
showToast(
|
| 1203 |
+
hasErrors ? "Workflow finished with errors" : "Workflow complete",
|
| 1204 |
+
hasErrors ? 5000 : 3000,
|
| 1205 |
+
hasErrors ? "error" : "success"
|
| 1206 |
+
);
|
| 1207 |
+
|
| 1208 |
+
setTimeout(() => {
|
| 1209 |
+
nodeStatus = Object.fromEntries(
|
| 1210 |
+
Object.entries(nodeStatus).filter(([_, s]) => s === "error")
|
| 1211 |
+
);
|
| 1212 |
+
}, 3000);
|
| 1213 |
+
}
|
| 1214 |
+
|
| 1215 |
+
function stopWorkflow(): void {
|
| 1216 |
+
abortController?.abort();
|
| 1217 |
+
running = false;
|
| 1218 |
+
abortController = null;
|
| 1219 |
+
nodeStatus = Object.fromEntries(
|
| 1220 |
+
Object.entries(nodeStatus).map(([id, s]) => [
|
| 1221 |
+
id,
|
| 1222 |
+
s === "running" ? "idle" : s
|
| 1223 |
+
])
|
| 1224 |
+
);
|
| 1225 |
+
showToast("Stopped", 3000, "warning");
|
| 1226 |
+
}
|
| 1227 |
+
|
| 1228 |
+
function handleGlobalClick(e: MouseEvent): void {
|
| 1229 |
+
const target = e.target as HTMLElement;
|
| 1230 |
+
if (dropChoice && !target?.closest(".drop-menu")) {
|
| 1231 |
+
dropChoice = null;
|
| 1232 |
+
pendingDrop = null;
|
| 1233 |
+
}
|
| 1234 |
+
if (doubleClickMenu && !target?.closest(".add-node-menu")) {
|
| 1235 |
+
doubleClickMenu = null;
|
| 1236 |
+
}
|
| 1237 |
+
if (
|
| 1238 |
+
showShortcuts &&
|
| 1239 |
+
!target?.closest(".shortcuts-panel") &&
|
| 1240 |
+
!target?.closest(".zoom-controls")
|
| 1241 |
+
) {
|
| 1242 |
+
showShortcuts = false;
|
| 1243 |
+
}
|
| 1244 |
+
if (activePicker && !target?.closest(".picker-panel")) {
|
| 1245 |
+
activePicker = null;
|
| 1246 |
+
}
|
| 1247 |
+
}
|
| 1248 |
+
|
| 1249 |
+
function zoomToFit(): void {
|
| 1250 |
+
const nodes = legacyView.nodes;
|
| 1251 |
+
if (nodes.length === 0) {
|
| 1252 |
+
viewport = { x: 0, y: 0, zoom: 1 };
|
| 1253 |
+
return;
|
| 1254 |
+
}
|
| 1255 |
+
const padding = 60;
|
| 1256 |
+
const minX = Math.min(...nodes.map((n) => n.x));
|
| 1257 |
+
const minY = Math.min(...nodes.map((n) => n.y));
|
| 1258 |
+
const maxX = Math.max(...nodes.map((n) => n.x + n.width));
|
| 1259 |
+
const maxY = Math.max(...nodes.map((n) => n.y + n.height));
|
| 1260 |
+
const contentW = maxX - minX + padding * 2;
|
| 1261 |
+
const contentH = maxY - minY + padding * 2;
|
| 1262 |
+
if (!canvasEl) {
|
| 1263 |
+
viewport = { x: 0, y: 0, zoom: 1 };
|
| 1264 |
+
return;
|
| 1265 |
+
}
|
| 1266 |
+
const r = canvasEl.getBoundingClientRect();
|
| 1267 |
+
const newZoom = Math.min(
|
| 1268 |
+
Math.max(Math.min(r.width / contentW, r.height / contentH), 0.15),
|
| 1269 |
+
2
|
| 1270 |
+
);
|
| 1271 |
+
viewport = {
|
| 1272 |
+
x: (r.width - contentW * newZoom) / 2 - (minX - padding) * newZoom,
|
| 1273 |
+
y: (r.height - contentH * newZoom) / 2 - (minY - padding) * newZoom,
|
| 1274 |
+
zoom: newZoom
|
| 1275 |
+
};
|
| 1276 |
+
}
|
| 1277 |
+
|
| 1278 |
+
function selectNode(id: string): void {
|
| 1279 |
+
selectedNodeId = id;
|
| 1280 |
+
}
|
| 1281 |
+
|
| 1282 |
+
function duplicateNode(id: string): void {
|
| 1283 |
+
const node = legacyView.nodes.find((n) => n.id === id);
|
| 1284 |
+
if (!node) return;
|
| 1285 |
+
const { id: _, data: __, ...template } = node;
|
| 1286 |
+
selectedNodeId = addNode(
|
| 1287 |
+
templateRole(template),
|
| 1288 |
+
template,
|
| 1289 |
+
node.x + 40,
|
| 1290 |
+
node.y + 40
|
| 1291 |
+
);
|
| 1292 |
+
}
|
| 1293 |
+
|
| 1294 |
+
function handleKeydown(e: KeyboardEvent): void {
|
| 1295 |
+
if (
|
| 1296 |
+
e.key === "Enter" &&
|
| 1297 |
+
(e.metaKey || e.ctrlKey) &&
|
| 1298 |
+
!running &&
|
| 1299 |
+
hasTransforms
|
| 1300 |
+
) {
|
| 1301 |
+
e.preventDefault();
|
| 1302 |
+
runWorkflow();
|
| 1303 |
+
return;
|
| 1304 |
+
}
|
| 1305 |
+
const tag = (e.target as HTMLElement)?.tagName;
|
| 1306 |
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return;
|
| 1307 |
+
if ((e.key === "Delete" || e.key === "Backspace") && selectedNodeId) {
|
| 1308 |
+
e.preventDefault();
|
| 1309 |
+
const id = selectedNodeId;
|
| 1310 |
+
selectedNodeId = null;
|
| 1311 |
+
requestAnimationFrame(() => removeNode(id));
|
| 1312 |
+
}
|
| 1313 |
+
if (e.key === "d" && (e.metaKey || e.ctrlKey) && selectedNodeId) {
|
| 1314 |
+
e.preventDefault();
|
| 1315 |
+
duplicateNode(selectedNodeId);
|
| 1316 |
+
}
|
| 1317 |
+
if (e.key === "f" && !e.metaKey && !e.ctrlKey) {
|
| 1318 |
+
e.preventDefault();
|
| 1319 |
+
zoomToFit();
|
| 1320 |
+
}
|
| 1321 |
+
if (e.key === "0" && (e.metaKey || e.ctrlKey)) {
|
| 1322 |
+
e.preventDefault();
|
| 1323 |
+
viewport = { x: 0, y: 0, zoom: 1 };
|
| 1324 |
+
}
|
| 1325 |
+
if (e.key === "Escape") {
|
| 1326 |
+
selectedNodeId = null;
|
| 1327 |
+
activeConnection = null;
|
| 1328 |
+
activePicker = null;
|
| 1329 |
+
pendingDrop = null;
|
| 1330 |
+
dropChoice = null;
|
| 1331 |
+
doubleClickMenu = null;
|
| 1332 |
+
clearConfirm = false;
|
| 1333 |
+
}
|
| 1334 |
+
if (e.key === "Enter" && clearConfirm) {
|
| 1335 |
+
e.preventDefault();
|
| 1336 |
+
confirmClearWorkflow();
|
| 1337 |
+
}
|
| 1338 |
+
}
|
| 1339 |
+
|
| 1340 |
+
function openPicker(modality: ModalityConfig): void {
|
| 1341 |
+
activePicker = { mode: "create", modality };
|
| 1342 |
+
}
|
| 1343 |
+
|
| 1344 |
+
function openPickerForNode(nodeId: string): void {
|
| 1345 |
+
const node = legacyView.nodes.find((n) => n.id === nodeId);
|
| 1346 |
+
if (!node) return;
|
| 1347 |
+
|
| 1348 |
+
// Components no longer open the picker β only transform nodes can have
|
| 1349 |
+
// their model/space swapped. Guard so any stale callers no-op cleanly.
|
| 1350 |
+
if (node.kind !== "transform") return;
|
| 1351 |
+
|
| 1352 |
+
let modality: ModalityConfig;
|
| 1353 |
+
let initialSource: "spaces" | "models" | "datasets" = "spaces";
|
| 1354 |
+
if (node.dataset_id) {
|
| 1355 |
+
modality = DATASET_MODALITY;
|
| 1356 |
+
initialSource = "datasets";
|
| 1357 |
+
} else {
|
| 1358 |
+
const cat = node.pipeline_tag
|
| 1359 |
+
? getModalityForPipelineTag(node.pipeline_tag)
|
| 1360 |
+
: "image";
|
| 1361 |
+
modality = MODALITIES.find((m) => m.category === cat) ?? MODALITIES[0];
|
| 1362 |
+
initialSource = node.model_id ? "models" : "spaces";
|
| 1363 |
+
}
|
| 1364 |
+
|
| 1365 |
+
let anchorX: number | undefined;
|
| 1366 |
+
let anchorY: number | undefined;
|
| 1367 |
+
if (canvasEl) {
|
| 1368 |
+
const r = canvasEl.getBoundingClientRect();
|
| 1369 |
+
const panelWidth = 536;
|
| 1370 |
+
const panelHeight = 620;
|
| 1371 |
+
const nodeScreenRight =
|
| 1372 |
+
node.x * viewport.zoom + viewport.x + node.width * viewport.zoom;
|
| 1373 |
+
anchorX = nodeScreenRight + 12;
|
| 1374 |
+
if (anchorX + panelWidth > r.width) {
|
| 1375 |
+
anchorX = Math.max(
|
| 1376 |
+
4,
|
| 1377 |
+
node.x * viewport.zoom + viewport.x - panelWidth - 12
|
| 1378 |
+
);
|
| 1379 |
+
}
|
| 1380 |
+
anchorX = Math.max(4, anchorX);
|
| 1381 |
+
anchorY = Math.max(
|
| 1382 |
+
4,
|
| 1383 |
+
Math.min(
|
| 1384 |
+
node.y * viewport.zoom + viewport.y,
|
| 1385 |
+
r.height - panelHeight - 8
|
| 1386 |
+
)
|
| 1387 |
+
);
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
activePicker = {
|
| 1391 |
+
mode: "update",
|
| 1392 |
+
modality,
|
| 1393 |
+
nodeId,
|
| 1394 |
+
anchorX,
|
| 1395 |
+
anchorY,
|
| 1396 |
+
initialSource
|
| 1397 |
+
};
|
| 1398 |
+
}
|
| 1399 |
+
|
| 1400 |
+
function getModalityForPipelineTag(tag: string): string {
|
| 1401 |
+
const map: Record<string, string> = {
|
| 1402 |
+
"text-to-image": "image",
|
| 1403 |
+
"image-to-image": "image",
|
| 1404 |
+
"text-to-audio": "audio",
|
| 1405 |
+
"text-to-speech": "audio",
|
| 1406 |
+
"automatic-speech-recognition": "audio",
|
| 1407 |
+
"text-to-video": "video",
|
| 1408 |
+
"image-to-video": "video",
|
| 1409 |
+
"text-to-3d": "3d",
|
| 1410 |
+
"image-to-3d": "3d",
|
| 1411 |
+
"text-generation": "text",
|
| 1412 |
+
summarization: "text",
|
| 1413 |
+
translation: "text"
|
| 1414 |
+
};
|
| 1415 |
+
return map[tag] ?? "image";
|
| 1416 |
+
}
|
| 1417 |
+
|
| 1418 |
+
const SUBGRAPH_PORT_TYPES = new Set([
|
| 1419 |
+
"image",
|
| 1420 |
+
"audio",
|
| 1421 |
+
"video",
|
| 1422 |
+
"text",
|
| 1423 |
+
"file",
|
| 1424 |
+
"gallery",
|
| 1425 |
+
"boolean",
|
| 1426 |
+
"number"
|
| 1427 |
+
]);
|
| 1428 |
+
|
| 1429 |
+
async function handlePickerCreate(template: any): Promise<void> {
|
| 1430 |
+
activePicker = null;
|
| 1431 |
+
const drop = pendingDrop;
|
| 1432 |
+
pendingDrop = null;
|
| 1433 |
+
let x: number, y: number;
|
| 1434 |
+
if (drop) {
|
| 1435 |
+
x = drop.reversed
|
| 1436 |
+
? drop.x - (template.width ?? 200) - 80
|
| 1437 |
+
: drop.x - (template.width ?? 200) / 2;
|
| 1438 |
+
y = drop.y - 60;
|
| 1439 |
+
} else {
|
| 1440 |
+
({ x, y } = findFreeSpot(canvasCenter().x, canvasCenter().y));
|
| 1441 |
+
}
|
| 1442 |
+
const newId = await addTemplateToCanvas({ ...template }, x, y);
|
| 1443 |
+
if (!newId) return;
|
| 1444 |
+
|
| 1445 |
+
// For spaces added fresh to the canvas (not wired from an existing port),
|
| 1446 |
+
// auto-create input + output components to form a ready-to-run subgraph
|
| 1447 |
+
const isSpaceFresh =
|
| 1448 |
+
template.source === "space" && (!drop || drop.positionOnly);
|
| 1449 |
+
if (isSpaceFresh) {
|
| 1450 |
+
const spaceNode = legacyView.nodes.find((n) => n.id === newId);
|
| 1451 |
+
if (spaceNode) {
|
| 1452 |
+
const compGap = 24;
|
| 1453 |
+
const compH = 180;
|
| 1454 |
+
const inputPorts = spaceNode.inputs.filter((p) =>
|
| 1455 |
+
SUBGRAPH_PORT_TYPES.has(p.type)
|
| 1456 |
+
);
|
| 1457 |
+
const outputPorts = spaceNode.outputs.filter((p) =>
|
| 1458 |
+
SUBGRAPH_PORT_TYPES.has(p.type)
|
| 1459 |
+
);
|
| 1460 |
+
|
| 1461 |
+
const inTotal = inputPorts.length * (compH + compGap) - compGap;
|
| 1462 |
+
const inStartY = y + (spaceNode.height ?? 90) / 2 - inTotal / 2;
|
| 1463 |
+
inputPorts.forEach((port, i) => {
|
| 1464 |
+
const comp = getComponentForPortType(port.type);
|
| 1465 |
+
if (!comp) return;
|
| 1466 |
+
const { x: cx, y: cy } = findFreeSpot(
|
| 1467 |
+
x - 220 - 80,
|
| 1468 |
+
inStartY + i * (compH + compGap)
|
| 1469 |
+
);
|
| 1470 |
+
const cId = addNode("reference", comp, cx, cy);
|
| 1471 |
+
addEdge({
|
| 1472 |
+
from_node_id: cId,
|
| 1473 |
+
from_port_id: "out",
|
| 1474 |
+
to_node_id: newId,
|
| 1475 |
+
to_port_id: port.id,
|
| 1476 |
+
type: port.type
|
| 1477 |
+
});
|
| 1478 |
+
});
|
| 1479 |
+
|
| 1480 |
+
const outTotal = outputPorts.length * (compH + compGap) - compGap;
|
| 1481 |
+
const outStartY = y + (spaceNode.height ?? 90) / 2 - outTotal / 2;
|
| 1482 |
+
outputPorts.forEach((port, i) => {
|
| 1483 |
+
const comp = getComponentForPortType(port.type);
|
| 1484 |
+
if (!comp) return;
|
| 1485 |
+
const { x: cx, y: cy } = findFreeSpot(
|
| 1486 |
+
x + (spaceNode.width ?? 280) + 80,
|
| 1487 |
+
outStartY + i * (compH + compGap)
|
| 1488 |
+
);
|
| 1489 |
+
const cId = addNode("subject", comp, cx, cy);
|
| 1490 |
+
addEdge({
|
| 1491 |
+
from_node_id: newId,
|
| 1492 |
+
from_port_id: port.id,
|
| 1493 |
+
to_node_id: cId,
|
| 1494 |
+
to_port_id: "in",
|
| 1495 |
+
type: port.type
|
| 1496 |
+
});
|
| 1497 |
+
});
|
| 1498 |
+
}
|
| 1499 |
+
return;
|
| 1500 |
+
}
|
| 1501 |
+
|
| 1502 |
+
// Wiring from an existing port drag
|
| 1503 |
+
if (drop && !drop.positionOnly) {
|
| 1504 |
+
const newNode = legacyView.nodes.find((n) => n.id === newId);
|
| 1505 |
+
if (drop.reversed) {
|
| 1506 |
+
const outputPort = newNode?.outputs.find((p: any) =>
|
| 1507 |
+
ports_compatible(p.type, drop.type)
|
| 1508 |
+
);
|
| 1509 |
+
if (outputPort) {
|
| 1510 |
+
addEdge({
|
| 1511 |
+
from_node_id: newId,
|
| 1512 |
+
from_port_id: outputPort.id,
|
| 1513 |
+
to_node_id: drop.from_node_id,
|
| 1514 |
+
to_port_id: drop.from_port_id,
|
| 1515 |
+
type: drop.type
|
| 1516 |
+
});
|
| 1517 |
+
}
|
| 1518 |
+
} else {
|
| 1519 |
+
const inputPort = newNode?.inputs.find((p: any) =>
|
| 1520 |
+
ports_compatible(drop.type, p.type)
|
| 1521 |
+
);
|
| 1522 |
+
if (inputPort) {
|
| 1523 |
+
addEdge({
|
| 1524 |
+
from_node_id: drop.from_node_id,
|
| 1525 |
+
from_port_id: drop.from_port_id,
|
| 1526 |
+
to_node_id: newId,
|
| 1527 |
+
to_port_id: inputPort.id,
|
| 1528 |
+
type: drop.type
|
| 1529 |
+
});
|
| 1530 |
+
}
|
| 1531 |
+
}
|
| 1532 |
+
}
|
| 1533 |
+
}
|
| 1534 |
+
|
| 1535 |
+
function handlePickerUpdate(nodeId: string, template: any): void {
|
| 1536 |
+
replaceNodeSource(nodeId, template);
|
| 1537 |
+
activePicker = null;
|
| 1538 |
+
}
|
| 1539 |
+
|
| 1540 |
+
function addInputNode(portType: string, cx?: number, cy?: number): void {
|
| 1541 |
+
let pos: { x: number; y: number };
|
| 1542 |
+
if (cx !== undefined && cy !== undefined) {
|
| 1543 |
+
const r = canvasEl?.getBoundingClientRect();
|
| 1544 |
+
pos = r
|
| 1545 |
+
? {
|
| 1546 |
+
x: (cx - r.left - viewport.x) / viewport.zoom,
|
| 1547 |
+
y: (cy - r.top - viewport.y) / viewport.zoom
|
| 1548 |
+
}
|
| 1549 |
+
: canvasCenter();
|
| 1550 |
+
} else {
|
| 1551 |
+
pos = canvasCenter();
|
| 1552 |
+
}
|
| 1553 |
+
const typedComponents: Record<string, any> = {};
|
| 1554 |
+
for (const c of LIBRARY.components) {
|
| 1555 |
+
typedComponents[c.outputs[0]?.type ?? "any"] = c;
|
| 1556 |
+
}
|
| 1557 |
+
const template = typedComponents[portType] ?? LIBRARY.components[0];
|
| 1558 |
+
const half = (template.width ?? 200) / 2;
|
| 1559 |
+
const { x, y } = findFreeSpot(pos.x - half, pos.y - 45);
|
| 1560 |
+
addNode("reference", template, x, y);
|
| 1561 |
+
}
|
| 1562 |
+
|
| 1563 |
+
/**
|
| 1564 |
+
* Spawn a Python fn node from a server-advertised bound function.
|
| 1565 |
+
* Wire-compatible with `_workflow_from_bind`: same id prefix, same
|
| 1566 |
+
* port shape, so it merges cleanly with any auto-generated fn nodes
|
| 1567 |
+
* already on the canvas.
|
| 1568 |
+
*/
|
| 1569 |
+
function addFnNode(tmpl: BoundFnTemplate): void {
|
| 1570 |
+
const half = 110;
|
| 1571 |
+
const { x, y } = findFreeSpot(
|
| 1572 |
+
canvasCenter().x - half,
|
| 1573 |
+
canvasCenter().y - 45
|
| 1574 |
+
);
|
| 1575 |
+
const height =
|
| 1576 |
+
80 + Math.max(tmpl.inputs.length, tmpl.outputs.length, 1) * 36;
|
| 1577 |
+
addNode(
|
| 1578 |
+
"operator",
|
| 1579 |
+
{
|
| 1580 |
+
label: tmpl.label,
|
| 1581 |
+
kind: "fn",
|
| 1582 |
+
source: "fn",
|
| 1583 |
+
fn: tmpl.fn,
|
| 1584 |
+
inputs: tmpl.inputs,
|
| 1585 |
+
outputs: tmpl.outputs,
|
| 1586 |
+
width: 220,
|
| 1587 |
+
height
|
| 1588 |
+
},
|
| 1589 |
+
x,
|
| 1590 |
+
y
|
| 1591 |
+
);
|
| 1592 |
+
}
|
| 1593 |
+
|
| 1594 |
+
function setName(value: string): void {
|
| 1595 |
+
workflow.update((wf) => ({ ...wf, name: value }));
|
| 1596 |
+
editingName = false;
|
| 1597 |
+
}
|
| 1598 |
+
</script>
|
| 1599 |
+
|
| 1600 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 1601 |
+
<div class="workflow-root" onclick={handleGlobalClick}>
|
| 1602 |
+
<div class="toolbar">
|
| 1603 |
+
<div class="toolbar-left">
|
| 1604 |
+
{#if editingName}
|
| 1605 |
+
<input
|
| 1606 |
+
bind:this={nameInput}
|
| 1607 |
+
class="name-input"
|
| 1608 |
+
value={$workflow.name}
|
| 1609 |
+
onblur={(e) => setName(e.currentTarget.value)}
|
| 1610 |
+
onkeydown={(e) => {
|
| 1611 |
+
if (e.key === "Enter") setName(e.currentTarget.value);
|
| 1612 |
+
if (e.key === "Escape") editingName = false;
|
| 1613 |
+
}}
|
| 1614 |
+
/>
|
| 1615 |
+
{:else}
|
| 1616 |
+
<button
|
| 1617 |
+
class="name-btn"
|
| 1618 |
+
onclick={() => {
|
| 1619 |
+
editingName = true;
|
| 1620 |
+
requestAnimationFrame(() => nameInput?.focus());
|
| 1621 |
+
}}
|
| 1622 |
+
>
|
| 1623 |
+
<span class="name-text">{$workflow.name}</span>
|
| 1624 |
+
<span class="name-edit-icon">✎</span>
|
| 1625 |
+
</button>
|
| 1626 |
+
{/if}
|
| 1627 |
+
<span class="toolbar-stat"
|
| 1628 |
+
>{nodeCount} nodes · {edgeCount} edges</span
|
| 1629 |
+
>
|
| 1630 |
+
</div>
|
| 1631 |
+
<div class="toolbar-right">
|
| 1632 |
+
{#if !auth.isCheckingLogin}
|
| 1633 |
+
{#if auth.loggedInUser}
|
| 1634 |
+
<span class="toolbar-user-info"
|
| 1635 |
+
>Logged in as <strong>{auth.loggedInUser}</strong></span
|
| 1636 |
+
>
|
| 1637 |
+
{#if auth.isHFSpace}
|
| 1638 |
+
<button
|
| 1639 |
+
class="toolbar-login-btn logged-in"
|
| 1640 |
+
onclick={auth.handleLogout}>Log out</button
|
| 1641 |
+
>
|
| 1642 |
+
{/if}
|
| 1643 |
+
{:else if auth.isHFSpace}
|
| 1644 |
+
<button class="toolbar-login-btn" onclick={auth.handleLogin}
|
| 1645 |
+
>Sign in with π€</button
|
| 1646 |
+
>
|
| 1647 |
+
{:else}
|
| 1648 |
+
<form class="toolbar-token-form" onsubmit={(e) => e.preventDefault()}>
|
| 1649 |
+
<input
|
| 1650 |
+
class="toolbar-token-input"
|
| 1651 |
+
class:has-user={!!auth.tokenUser}
|
| 1652 |
+
class:invalid={auth.tokenStatus === "invalid"}
|
| 1653 |
+
type="password"
|
| 1654 |
+
placeholder="Paste HF token (hf_...)"
|
| 1655 |
+
value={auth.hfToken}
|
| 1656 |
+
onchange={(e) => auth.saveToken(e.currentTarget.value)}
|
| 1657 |
+
title="HuggingFace token for GPU access"
|
| 1658 |
+
/>
|
| 1659 |
+
{#if auth.tokenUser}
|
| 1660 |
+
<span
|
| 1661 |
+
class="toolbar-token-status valid"
|
| 1662 |
+
title={`Signed in as ${auth.tokenUser}`}
|
| 1663 |
+
>
|
| 1664 |
+
<CheckIcon />
|
| 1665 |
+
{auth.tokenUser}
|
| 1666 |
+
</span>
|
| 1667 |
+
{:else if auth.tokenStatus === "validating"}
|
| 1668 |
+
<span class="toolbar-token-status validating">checkingβ¦</span>
|
| 1669 |
+
{:else if auth.tokenStatus === "invalid"}
|
| 1670 |
+
<span class="toolbar-token-status invalid">invalid</span>
|
| 1671 |
+
{/if}
|
| 1672 |
+
</form>
|
| 1673 |
+
{/if}
|
| 1674 |
+
{/if}
|
| 1675 |
+
<button class="tool-btn" onclick={autoLayout} title="Auto-arrange nodes"
|
| 1676 |
+
>Layout</button
|
| 1677 |
+
>
|
| 1678 |
+
<button class="tool-btn" onclick={clearWorkflow}>Clear</button>
|
| 1679 |
+
</div>
|
| 1680 |
+
</div>
|
| 1681 |
+
|
| 1682 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 1683 |
+
<div
|
| 1684 |
+
class="editor"
|
| 1685 |
+
class:editor-panning={dragMode?.kind === "pan"}
|
| 1686 |
+
bind:this={canvasEl}
|
| 1687 |
+
ondragover={(e) => e.preventDefault()}
|
| 1688 |
+
ondrop={handleDrop}
|
| 1689 |
+
ondblclick={handleCanvasDoubleClick}
|
| 1690 |
+
onpointerdown={onCanvasPointerDown}
|
| 1691 |
+
onpointermove={onCanvasPointerMove}
|
| 1692 |
+
onpointerup={onCanvasPointerUp}
|
| 1693 |
+
onwheel={onWheel}
|
| 1694 |
+
>
|
| 1695 |
+
<!-- Dot grid background β fixed in screen space, parallax-free -->
|
| 1696 |
+
<div
|
| 1697 |
+
class="canvas-bg"
|
| 1698 |
+
style="background-position: {viewport.x}px {viewport.y}px; background-size: {gridTile}px {gridTile}px;"
|
| 1699 |
+
></div>
|
| 1700 |
+
|
| 1701 |
+
<!-- Viewport: all nodes + edges live in here, sharing one transform -->
|
| 1702 |
+
<div
|
| 1703 |
+
class="canvas-viewport"
|
| 1704 |
+
style="transform: translate({viewport.x}px, {viewport.y}px) scale({viewport.zoom});"
|
| 1705 |
+
>
|
| 1706 |
+
<!-- Edges layer (SVG). overflow:visible so edges aren't clipped. -->
|
| 1707 |
+
<svg class="edges-layer" width="1" height="1" style="overflow: visible;">
|
| 1708 |
+
{#each legacyView.edges as edge (edge.id)}
|
| 1709 |
+
{@const path = edgePath(edge)}
|
| 1710 |
+
{#if path}
|
| 1711 |
+
<path
|
| 1712 |
+
class="edge-path"
|
| 1713 |
+
d={path}
|
| 1714 |
+
stroke={PORT_COLOR[edge.type] ?? "#6b6e78"}
|
| 1715 |
+
stroke-width={2 / viewport.zoom}
|
| 1716 |
+
fill="none"
|
| 1717 |
+
onclick={() => removeEdge(edge.id)}
|
| 1718 |
+
/>
|
| 1719 |
+
{/if}
|
| 1720 |
+
{/each}
|
| 1721 |
+
{#if dragMode?.kind === "connection"}
|
| 1722 |
+
{@const preview = connectionPreviewPath(dragMode)}
|
| 1723 |
+
{#if preview}
|
| 1724 |
+
<path
|
| 1725 |
+
class="edge-preview"
|
| 1726 |
+
d={preview}
|
| 1727 |
+
stroke={PORT_COLOR[dragMode.type] ?? "#6b6e78"}
|
| 1728 |
+
stroke-width={2 / viewport.zoom}
|
| 1729 |
+
stroke-dasharray="6 4"
|
| 1730 |
+
fill="none"
|
| 1731 |
+
/>
|
| 1732 |
+
{/if}
|
| 1733 |
+
{/if}
|
| 1734 |
+
</svg>
|
| 1735 |
+
|
| 1736 |
+
<!-- Nodes layer -->
|
| 1737 |
+
{#each legacyView.nodes as n (n.id)}
|
| 1738 |
+
<div
|
| 1739 |
+
class="node-pos-wrap"
|
| 1740 |
+
class:node-pos-selected={selectedNodeId === n.id}
|
| 1741 |
+
data-node-id={n.id}
|
| 1742 |
+
style="left: {n.x}px; top: {n.y}px; width: {n.width}px;"
|
| 1743 |
+
onpointerdown={(e) => startNodeDrag(e, n.id)}
|
| 1744 |
+
>
|
| 1745 |
+
<WorkflowNodeSF
|
| 1746 |
+
id={n.id}
|
| 1747 |
+
data={n}
|
| 1748 |
+
selected={selectedNodeId === n.id}
|
| 1749 |
+
/>
|
| 1750 |
+
</div>
|
| 1751 |
+
{/each}
|
| 1752 |
+
</div>
|
| 1753 |
+
|
| 1754 |
+
{#if nodeCount === 0}
|
| 1755 |
+
<WorkflowEmptyState />
|
| 1756 |
+
{/if}
|
| 1757 |
+
|
| 1758 |
+
{#if running}
|
| 1759 |
+
<div class="run-overlay"></div>
|
| 1760 |
+
{/if}
|
| 1761 |
+
|
| 1762 |
+
{#if dropChoice}
|
| 1763 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 1764 |
+
<!-- Stop click + mousedown propagation: handleGlobalClick on
|
| 1765 |
+
workflow-root closes activePicker when the click target is
|
| 1766 |
+
outside .picker-panel. Without onclick stopPropagation, a
|
| 1767 |
+
"Generate" click here would set activePicker and then have
|
| 1768 |
+
the very same click bubble out and close it. -->
|
| 1769 |
+
<div
|
| 1770 |
+
class="drop-menu"
|
| 1771 |
+
style="left: {dropChoice.clientX}px; top: {dropChoice.clientY}px;"
|
| 1772 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 1773 |
+
onclick={(e) => e.stopPropagation()}
|
| 1774 |
+
>
|
| 1775 |
+
{#if dropChoice.modelOptions.length > 0}
|
| 1776 |
+
<div class="drop-section-label">Models</div>
|
| 1777 |
+
{#each dropChoice.modelOptions as opt}
|
| 1778 |
+
<button
|
| 1779 |
+
class="drop-opt"
|
| 1780 |
+
onclick={() => handleDropChoiceModel(opt.subtab)}
|
| 1781 |
+
>{opt.label}</button
|
| 1782 |
+
>
|
| 1783 |
+
{/each}
|
| 1784 |
+
{/if}
|
| 1785 |
+
{#if dropChoice.componentOptions.length > 0}
|
| 1786 |
+
<div class="drop-section-label">
|
| 1787 |
+
{dropChoice.reversed ? "Sources" : "Outputs"}
|
| 1788 |
+
</div>
|
| 1789 |
+
{#each dropChoice.componentOptions as opt}
|
| 1790 |
+
<button class="drop-opt" onclick={handleDropChoiceUpload}
|
| 1791 |
+
>{opt.label}</button
|
| 1792 |
+
>
|
| 1793 |
+
{/each}
|
| 1794 |
+
{/if}
|
| 1795 |
+
</div>
|
| 1796 |
+
{/if}
|
| 1797 |
+
|
| 1798 |
+
{#if doubleClickMenu}
|
| 1799 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 1800 |
+
<!-- Stop click+mousedown so handleGlobalClick (on .workflow-root)
|
| 1801 |
+
doesn't close the menu before the inner button fires.
|
| 1802 |
+
Same bug we fixed on .drop-menu earlier. -->
|
| 1803 |
+
<div
|
| 1804 |
+
class="add-node-menu"
|
| 1805 |
+
style="left: {doubleClickMenu.clientX}px; top: {doubleClickMenu.clientY}px;"
|
| 1806 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 1807 |
+
onclick={(e) => e.stopPropagation()}
|
| 1808 |
+
>
|
| 1809 |
+
<div class="add-node-section-label">Add</div>
|
| 1810 |
+
<div class="add-node-grid">
|
| 1811 |
+
<button class="add-node-type-btn" onclick={handleDoubleClickUpload}
|
| 1812 |
+
>Upload Media</button
|
| 1813 |
+
>
|
| 1814 |
+
<button
|
| 1815 |
+
class="add-node-type-btn"
|
| 1816 |
+
onclick={() => handleDoubleClickInputNode("text" as PortType)}
|
| 1817 |
+
>Text</button
|
| 1818 |
+
>
|
| 1819 |
+
</div>
|
| 1820 |
+
<div class="add-node-divider"></div>
|
| 1821 |
+
<div class="add-node-section-label">Space / Model</div>
|
| 1822 |
+
<div class="add-node-grid">
|
| 1823 |
+
{#each MODALITIES.filter( (m) => ["image", "audio", "video", "text", "3d"].includes(m.key) ) as m}
|
| 1824 |
+
<button
|
| 1825 |
+
class="add-node-type-btn"
|
| 1826 |
+
onclick={() => handleDoubleClickSpaceModel(m)}>{m.label}</button
|
| 1827 |
+
>
|
| 1828 |
+
{/each}
|
| 1829 |
+
</div>
|
| 1830 |
+
</div>
|
| 1831 |
+
{/if}
|
| 1832 |
+
|
| 1833 |
+
<div class="zoom-controls">
|
| 1834 |
+
<button
|
| 1835 |
+
class="zoom-ctrl-btn"
|
| 1836 |
+
onclick={() => (showShortcuts = !showShortcuts)}
|
| 1837 |
+
title="Keyboard shortcuts">?</button
|
| 1838 |
+
>
|
| 1839 |
+
<button class="zoom-ctrl-btn" onclick={zoomToFit} title="Fit all (F)"
|
| 1840 |
+
>⤢</button
|
| 1841 |
+
>
|
| 1842 |
+
<button
|
| 1843 |
+
class="zoom-ctrl-btn"
|
| 1844 |
+
onclick={() => {
|
| 1845 |
+
viewport = { ...viewport, zoom: Math.max(0.15, viewport.zoom / 1.2) };
|
| 1846 |
+
}}>β</button
|
| 1847 |
+
>
|
| 1848 |
+
<button
|
| 1849 |
+
class="zoom-btn"
|
| 1850 |
+
onclick={() => {
|
| 1851 |
+
viewport = { x: 0, y: 0, zoom: 1 };
|
| 1852 |
+
}}>{Math.round(viewport.zoom * 100)}%</button
|
| 1853 |
+
>
|
| 1854 |
+
<button
|
| 1855 |
+
class="zoom-ctrl-btn"
|
| 1856 |
+
onclick={() => {
|
| 1857 |
+
viewport = { ...viewport, zoom: Math.min(4, viewport.zoom * 1.2) };
|
| 1858 |
+
}}>+</button
|
| 1859 |
+
>
|
| 1860 |
+
</div>
|
| 1861 |
+
|
| 1862 |
+
{#if showShortcuts}
|
| 1863 |
+
<div class="shortcuts-panel">
|
| 1864 |
+
<div class="shortcuts-title">Keyboard shortcuts</div>
|
| 1865 |
+
<div class="shortcut-row">
|
| 1866 |
+
<kbd>Cmd+Enter</kbd> <span>Run workflow</span>
|
| 1867 |
+
</div>
|
| 1868 |
+
<div class="shortcut-row">
|
| 1869 |
+
<kbd>Cmd+D</kbd> <span>Duplicate node</span>
|
| 1870 |
+
</div>
|
| 1871 |
+
<div class="shortcut-row"><kbd>F</kbd> <span>Zoom to fit</span></div>
|
| 1872 |
+
<div class="shortcut-row"><kbd>Cmd+0</kbd> <span>Reset zoom</span></div>
|
| 1873 |
+
<div class="shortcut-row">
|
| 1874 |
+
<kbd>Delete</kbd> <span>Remove node</span>
|
| 1875 |
+
</div>
|
| 1876 |
+
<div class="shortcut-row"><kbd>Escape</kbd> <span>Deselect</span></div>
|
| 1877 |
+
<div class="shortcut-row"><kbd>Scroll</kbd> <span>Zoom</span></div>
|
| 1878 |
+
<div class="shortcut-row"><kbd>Drag canvas</kbd> <span>Pan</span></div>
|
| 1879 |
+
<div class="shortcut-row">
|
| 1880 |
+
<kbd>Double-click</kbd> <span>Rename node</span>
|
| 1881 |
+
</div>
|
| 1882 |
+
</div>
|
| 1883 |
+
{/if}
|
| 1884 |
+
|
| 1885 |
+
<WorkflowBottomBar
|
| 1886 |
+
{running}
|
| 1887 |
+
{hasTransforms}
|
| 1888 |
+
{boundFns}
|
| 1889 |
+
onopenpicker={openPicker}
|
| 1890 |
+
onaddinput={addInputNode}
|
| 1891 |
+
onaddfn={addFnNode}
|
| 1892 |
+
onrun={() => void runWorkflow()}
|
| 1893 |
+
onstop={stopWorkflow}
|
| 1894 |
+
/>
|
| 1895 |
+
|
| 1896 |
+
{#if activePicker}
|
| 1897 |
+
<!-- Key on modality so swapping the bottom-bar modality button
|
| 1898 |
+
while the picker is open re-mounts the component and
|
| 1899 |
+
re-fetches Trending / New for the new modality. Without
|
| 1900 |
+
this, NodeModelPicker just sees its `modality` prop change
|
| 1901 |
+
and keeps stale activeSubtab + results. -->
|
| 1902 |
+
{#key activePicker.modality.key}
|
| 1903 |
+
<NodeModelPicker
|
| 1904 |
+
mode={activePicker.mode}
|
| 1905 |
+
modality={activePicker.modality}
|
| 1906 |
+
nodeId={activePicker.nodeId}
|
| 1907 |
+
initialSource={activePicker.initialSource}
|
| 1908 |
+
initialSubtab={activePicker.initialSubtab}
|
| 1909 |
+
{server}
|
| 1910 |
+
hfToken={auth.hfToken}
|
| 1911 |
+
anchorX={activePicker.anchorX}
|
| 1912 |
+
anchorY={activePicker.anchorY}
|
| 1913 |
+
oncreate={handlePickerCreate}
|
| 1914 |
+
onupdate={handlePickerUpdate}
|
| 1915 |
+
onclose={() => {
|
| 1916 |
+
activePicker = null;
|
| 1917 |
+
}}
|
| 1918 |
+
onerror={(msg) => showToast(msg, 5000, "error")}
|
| 1919 |
+
/>
|
| 1920 |
+
{/key}
|
| 1921 |
+
{/if}
|
| 1922 |
+
</div>
|
| 1923 |
+
|
| 1924 |
+
{#if toasts.length > 0}
|
| 1925 |
+
<div class="wf-toast-stack">
|
| 1926 |
+
{#each toasts as t (t.id)}
|
| 1927 |
+
<div class="wf-toast wf-toast-{t.type}">
|
| 1928 |
+
<span class="wf-toast-msg">{t.message}</span>
|
| 1929 |
+
<button
|
| 1930 |
+
class="wf-toast-close"
|
| 1931 |
+
aria-label="Dismiss"
|
| 1932 |
+
title="Dismiss"
|
| 1933 |
+
onclick={() => (toasts = toasts.filter((x) => x.id !== t.id))}
|
| 1934 |
+
>
|
| 1935 |
+
Γ
|
| 1936 |
+
</button>
|
| 1937 |
+
</div>
|
| 1938 |
+
{/each}
|
| 1939 |
+
</div>
|
| 1940 |
+
{/if}
|
| 1941 |
+
|
| 1942 |
+
{#if clearConfirm}
|
| 1943 |
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
| 1944 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 1945 |
+
<div class="wf-modal-backdrop" onclick={() => (clearConfirm = false)}>
|
| 1946 |
+
<div
|
| 1947 |
+
class="wf-modal"
|
| 1948 |
+
role="dialog"
|
| 1949 |
+
aria-modal="true"
|
| 1950 |
+
aria-labelledby="wf-modal-title"
|
| 1951 |
+
onclick={(e) => e.stopPropagation()}
|
| 1952 |
+
>
|
| 1953 |
+
<div class="wf-modal-title" id="wf-modal-title">Clear workflow?</div>
|
| 1954 |
+
<div class="wf-modal-body">
|
| 1955 |
+
This will remove <strong>{nodeCount}</strong>
|
| 1956 |
+
{nodeCount === 1 ? "node" : "nodes"} and
|
| 1957 |
+
<strong>{edgeCount}</strong>
|
| 1958 |
+
{edgeCount === 1 ? "edge" : "edges"}. This can't be undone.
|
| 1959 |
+
</div>
|
| 1960 |
+
<div class="wf-modal-actions">
|
| 1961 |
+
<button class="wf-modal-btn" onclick={() => (clearConfirm = false)}
|
| 1962 |
+
>Cancel</button
|
| 1963 |
+
>
|
| 1964 |
+
<button
|
| 1965 |
+
class="wf-modal-btn wf-modal-btn-danger"
|
| 1966 |
+
onclick={confirmClearWorkflow}>Clear</button
|
| 1967 |
+
>
|
| 1968 |
+
</div>
|
| 1969 |
+
</div>
|
| 1970 |
+
</div>
|
| 1971 |
+
{/if}
|
| 1972 |
+
</div>
|
| 1973 |
+
|
| 1974 |
+
<style>
|
| 1975 |
+
@import "./WorkflowCanvas.css";
|
| 1976 |
+
|
| 1977 |
+
/* βββ Custom canvas βββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 1978 |
+
.editor {
|
| 1979 |
+
cursor: grab;
|
| 1980 |
+
}
|
| 1981 |
+
|
| 1982 |
+
.editor.editor-panning {
|
| 1983 |
+
cursor: grabbing;
|
| 1984 |
+
}
|
| 1985 |
+
|
| 1986 |
+
.canvas-bg {
|
| 1987 |
+
position: absolute;
|
| 1988 |
+
inset: 0;
|
| 1989 |
+
background-image: radial-gradient(#2a2b36 1px, transparent 1px);
|
| 1990 |
+
background-repeat: repeat;
|
| 1991 |
+
pointer-events: none;
|
| 1992 |
+
}
|
| 1993 |
+
|
| 1994 |
+
.canvas-viewport {
|
| 1995 |
+
position: absolute;
|
| 1996 |
+
top: 0;
|
| 1997 |
+
left: 0;
|
| 1998 |
+
transform-origin: 0 0;
|
| 1999 |
+
width: 0;
|
| 2000 |
+
height: 0;
|
| 2001 |
+
}
|
| 2002 |
+
|
| 2003 |
+
.edges-layer {
|
| 2004 |
+
position: absolute;
|
| 2005 |
+
top: 0;
|
| 2006 |
+
left: 0;
|
| 2007 |
+
overflow: visible;
|
| 2008 |
+
pointer-events: none;
|
| 2009 |
+
}
|
| 2010 |
+
|
| 2011 |
+
.edges-layer .edge-path {
|
| 2012 |
+
cursor: pointer;
|
| 2013 |
+
pointer-events: stroke;
|
| 2014 |
+
transition: stroke-width 0.1s;
|
| 2015 |
+
}
|
| 2016 |
+
|
| 2017 |
+
.edges-layer .edge-path:hover {
|
| 2018 |
+
stroke-width: 3 !important;
|
| 2019 |
+
}
|
| 2020 |
+
|
| 2021 |
+
.edges-layer .edge-preview {
|
| 2022 |
+
pointer-events: none;
|
| 2023 |
+
}
|
| 2024 |
+
|
| 2025 |
+
.node-pos-wrap {
|
| 2026 |
+
position: absolute;
|
| 2027 |
+
touch-action: none;
|
| 2028 |
+
z-index: 1;
|
| 2029 |
+
}
|
| 2030 |
+
|
| 2031 |
+
.node-pos-wrap.node-pos-selected {
|
| 2032 |
+
z-index: 2;
|
| 2033 |
+
}
|
| 2034 |
+
|
| 2035 |
+
:global(body:not(.dark)) .canvas-bg {
|
| 2036 |
+
background-image: radial-gradient(#d0d2dc 1px, transparent 1px);
|
| 2037 |
+
}
|
| 2038 |
+
|
| 2039 |
+
/* βββ Light mode βββ */
|
| 2040 |
+
:global(body:not(.dark) .workflow-root) {
|
| 2041 |
+
background: #f8f9fb;
|
| 2042 |
+
border-color: #e2e4ea;
|
| 2043 |
+
color-scheme: light;
|
| 2044 |
+
box-shadow:
|
| 2045 |
+
0 0 0 1px rgba(0, 0, 0, 0.04),
|
| 2046 |
+
0 20px 60px rgba(0, 0, 0, 0.08);
|
| 2047 |
+
}
|
| 2048 |
+
|
| 2049 |
+
:global(body:not(.dark) .toolbar) {
|
| 2050 |
+
background: #ffffff;
|
| 2051 |
+
border-bottom-color: #e2e4ea;
|
| 2052 |
+
}
|
| 2053 |
+
|
| 2054 |
+
:global(body:not(.dark) .name-btn:hover) {
|
| 2055 |
+
background: #f0f1f5;
|
| 2056 |
+
}
|
| 2057 |
+
:global(body:not(.dark) .name-text) {
|
| 2058 |
+
color: #1a1b25;
|
| 2059 |
+
}
|
| 2060 |
+
:global(body:not(.dark) .name-edit-icon) {
|
| 2061 |
+
color: #b0b2bc;
|
| 2062 |
+
}
|
| 2063 |
+
:global(body:not(.dark) .name-input) {
|
| 2064 |
+
background: #ffffff;
|
| 2065 |
+
color: #1a1b25;
|
| 2066 |
+
}
|
| 2067 |
+
:global(body:not(.dark) .toolbar-stat) {
|
| 2068 |
+
color: #b0b2bc;
|
| 2069 |
+
}
|
| 2070 |
+
:global(body:not(.dark) .tool-btn) {
|
| 2071 |
+
border-color: #e2e4ea;
|
| 2072 |
+
color: #8b8d98;
|
| 2073 |
+
}
|
| 2074 |
+
:global(body:not(.dark) .tool-btn:hover) {
|
| 2075 |
+
background: #f0f1f5;
|
| 2076 |
+
color: #3e4050;
|
| 2077 |
+
border-color: #d0d2dc;
|
| 2078 |
+
}
|
| 2079 |
+
:global(body:not(.dark) .toolbar-login-btn) {
|
| 2080 |
+
border-color: #e2e4ea;
|
| 2081 |
+
color: #6b6e78;
|
| 2082 |
+
}
|
| 2083 |
+
:global(body:not(.dark) .toolbar-login-btn:hover) {
|
| 2084 |
+
background: #f0f1f5;
|
| 2085 |
+
color: #1a1b25;
|
| 2086 |
+
border-color: #d0d2dc;
|
| 2087 |
+
}
|
| 2088 |
+
:global(body:not(.dark) .toolbar-login-btn.logged-in) {
|
| 2089 |
+
color: #8b8d98;
|
| 2090 |
+
}
|
| 2091 |
+
:global(body:not(.dark) .toolbar-user-info) {
|
| 2092 |
+
color: #8b8d98;
|
| 2093 |
+
}
|
| 2094 |
+
:global(body:not(.dark) .toolbar-user-info strong) {
|
| 2095 |
+
color: #3e4050;
|
| 2096 |
+
}
|
| 2097 |
+
:global(body:not(.dark) .toolbar-token-input) {
|
| 2098 |
+
background: #ffffff;
|
| 2099 |
+
color: #6b6e78;
|
| 2100 |
+
border-color: #e2e4ea;
|
| 2101 |
+
}
|
| 2102 |
+
:global(body:not(.dark) .toolbar-token-input::placeholder) {
|
| 2103 |
+
color: #c0c2cc;
|
| 2104 |
+
}
|
| 2105 |
+
:global(body:not(.dark) .toolbar-token-input:focus) {
|
| 2106 |
+
background: #ffffff;
|
| 2107 |
+
color: #3e4050;
|
| 2108 |
+
}
|
| 2109 |
+
:global(body:not(.dark) .toolbar-divider) {
|
| 2110 |
+
background: #e2e4ea;
|
| 2111 |
+
}
|
| 2112 |
+
:global(body:not(.dark) .zoom-controls) {
|
| 2113 |
+
background: #ffffff;
|
| 2114 |
+
border-color: #e2e4ea;
|
| 2115 |
+
}
|
| 2116 |
+
:global(body:not(.dark) .zoom-ctrl-btn) {
|
| 2117 |
+
color: #9a9caa;
|
| 2118 |
+
}
|
| 2119 |
+
:global(body:not(.dark) .zoom-ctrl-btn:hover) {
|
| 2120 |
+
background: #f0f1f5;
|
| 2121 |
+
color: #3e4050;
|
| 2122 |
+
}
|
| 2123 |
+
:global(body:not(.dark) .zoom-btn) {
|
| 2124 |
+
background: #ffffff;
|
| 2125 |
+
border-color: #e2e4ea;
|
| 2126 |
+
color: #9a9caa;
|
| 2127 |
+
}
|
| 2128 |
+
:global(body:not(.dark) .zoom-btn:hover) {
|
| 2129 |
+
color: #3e4050;
|
| 2130 |
+
border-color: #d0d2dc;
|
| 2131 |
+
}
|
| 2132 |
+
:global(body:not(.dark) .shortcuts-panel) {
|
| 2133 |
+
background: #ffffff;
|
| 2134 |
+
border-color: #e2e4ea;
|
| 2135 |
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
|
| 2136 |
+
}
|
| 2137 |
+
:global(body:not(.dark) .shortcuts-title) {
|
| 2138 |
+
color: #6b6e78;
|
| 2139 |
+
}
|
| 2140 |
+
:global(body:not(.dark) .shortcut-row) {
|
| 2141 |
+
color: #9a9caa;
|
| 2142 |
+
}
|
| 2143 |
+
:global(body:not(.dark) .shortcut-row kbd) {
|
| 2144 |
+
background: #f0f1f5;
|
| 2145 |
+
color: #3e4050;
|
| 2146 |
+
border-color: #d0d2dc;
|
| 2147 |
+
}
|
| 2148 |
+
:global(body:not(.dark) .wf-toast) {
|
| 2149 |
+
background: #ffffff;
|
| 2150 |
+
color: #2a2b36;
|
| 2151 |
+
border-color: #e2e4ea;
|
| 2152 |
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
| 2153 |
+
}
|
| 2154 |
+
</style>
|
6.17.1/workflowcanvas/workflow/WorkflowEdges.svelte
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { workflow } from "./workflow-store";
|
| 3 |
+
import { PORT_COLOR } from "./workflow-types";
|
| 4 |
+
import type { PortType, WFNode } from "./workflow-types";
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
pending: {
|
| 8 |
+
from_node_id: string;
|
| 9 |
+
from_port_id: string;
|
| 10 |
+
type: PortType;
|
| 11 |
+
x: number;
|
| 12 |
+
y: number;
|
| 13 |
+
reversed?: boolean;
|
| 14 |
+
} | null;
|
| 15 |
+
onremove: (id: string) => void;
|
| 16 |
+
zoom: number;
|
| 17 |
+
panX: number;
|
| 18 |
+
panY: number;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
let { pending, onremove, zoom, panX, panY }: Props = $props();
|
| 22 |
+
|
| 23 |
+
function bez(x1: number, y1: number, x2: number, y2: number): string {
|
| 24 |
+
const cx = Math.max(Math.abs(x2 - x1) * 0.5, 60);
|
| 25 |
+
return `M ${x1} ${y1} C ${x1 + cx} ${y1}, ${x2 - cx} ${y2}, ${x2} ${y2}`;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function getPortPos(
|
| 29 |
+
nodes: WFNode[],
|
| 30 |
+
nodeId: string,
|
| 31 |
+
portId: string,
|
| 32 |
+
side: "output" | "input"
|
| 33 |
+
): { x: number; y: number } {
|
| 34 |
+
// DOM measurement β always accurate regardless of layout
|
| 35 |
+
const dotEl = document.querySelector(
|
| 36 |
+
`[data-port-id="${nodeId}:${portId}:${side}"]`
|
| 37 |
+
);
|
| 38 |
+
const transformEl = document.querySelector(".canvas-transform");
|
| 39 |
+
if (dotEl && transformEl) {
|
| 40 |
+
const dotRect = dotEl.getBoundingClientRect();
|
| 41 |
+
const transformRect = transformEl.getBoundingClientRect();
|
| 42 |
+
const edgeX =
|
| 43 |
+
side === "output"
|
| 44 |
+
? dotRect.right - transformRect.left
|
| 45 |
+
: dotRect.left - transformRect.left;
|
| 46 |
+
return {
|
| 47 |
+
x: edgeX / zoom,
|
| 48 |
+
y: (dotRect.top + dotRect.height / 2 - transformRect.top) / zoom
|
| 49 |
+
};
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// Fallback
|
| 53 |
+
const node = nodes.find((n) => n.id === nodeId);
|
| 54 |
+
if (!node) return { x: 0, y: 0 };
|
| 55 |
+
const ports = side === "output" ? node.outputs : node.inputs;
|
| 56 |
+
const idx = ports.findIndex((p) => p.id === portId);
|
| 57 |
+
const portIndex = idx >= 0 ? idx : 0;
|
| 58 |
+
const DOT_OUTSET = 24;
|
| 59 |
+
const x =
|
| 60 |
+
side === "output"
|
| 61 |
+
? node.x + node.width + DOT_OUTSET
|
| 62 |
+
: node.x - DOT_OUTSET;
|
| 63 |
+
const headerH = node.source === "space" && node.space_id ? 60 : 44;
|
| 64 |
+
if (side === "input") {
|
| 65 |
+
return { x, y: node.y + headerH + portIndex * 26 };
|
| 66 |
+
} else {
|
| 67 |
+
const portsBlockH = ports.length * 26;
|
| 68 |
+
return { x, y: node.y + node.height - portsBlockH + portIndex * 26 - 2 };
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
</script>
|
| 72 |
+
|
| 73 |
+
<svg class="edge-layer">
|
| 74 |
+
<defs>
|
| 75 |
+
{#each $workflow.edges as edge (edge.id)}
|
| 76 |
+
<linearGradient id="grad-{edge.id}" x1="0%" y1="0%" x2="100%" y2="0%">
|
| 77 |
+
<stop
|
| 78 |
+
offset="0%"
|
| 79 |
+
stop-color={PORT_COLOR[edge.type]}
|
| 80 |
+
stop-opacity="0.9"
|
| 81 |
+
/>
|
| 82 |
+
<stop
|
| 83 |
+
offset="100%"
|
| 84 |
+
stop-color={PORT_COLOR[edge.type]}
|
| 85 |
+
stop-opacity="0.4"
|
| 86 |
+
/>
|
| 87 |
+
</linearGradient>
|
| 88 |
+
{/each}
|
| 89 |
+
</defs>
|
| 90 |
+
|
| 91 |
+
{#each $workflow.edges as edge (edge.id)}
|
| 92 |
+
{@const from = getPortPos(
|
| 93 |
+
$workflow.nodes,
|
| 94 |
+
edge.from_node_id,
|
| 95 |
+
edge.from_port_id,
|
| 96 |
+
"output"
|
| 97 |
+
)}
|
| 98 |
+
{@const to = getPortPos(
|
| 99 |
+
$workflow.nodes,
|
| 100 |
+
edge.to_node_id,
|
| 101 |
+
edge.to_port_id,
|
| 102 |
+
"input"
|
| 103 |
+
)}
|
| 104 |
+
<!-- glow -->
|
| 105 |
+
<path
|
| 106 |
+
d={bez(from.x, from.y, to.x, to.y)}
|
| 107 |
+
fill="none"
|
| 108 |
+
stroke={PORT_COLOR[edge.type]}
|
| 109 |
+
stroke-width={6 / zoom}
|
| 110 |
+
stroke-opacity="0.08"
|
| 111 |
+
style="pointer-events: none"
|
| 112 |
+
/>
|
| 113 |
+
<!-- hitbox -->
|
| 114 |
+
<path
|
| 115 |
+
class="wire-hitbox"
|
| 116 |
+
d={bez(from.x, from.y, to.x, to.y)}
|
| 117 |
+
fill="none"
|
| 118 |
+
stroke="transparent"
|
| 119 |
+
stroke-width={16 / zoom}
|
| 120 |
+
onclick={() => onremove(edge.id)}
|
| 121 |
+
role="button"
|
| 122 |
+
tabindex="-1"
|
| 123 |
+
/>
|
| 124 |
+
<!-- wire -->
|
| 125 |
+
<path
|
| 126 |
+
class="wire"
|
| 127 |
+
d={bez(from.x, from.y, to.x, to.y)}
|
| 128 |
+
fill="none"
|
| 129 |
+
stroke="url(#grad-{edge.id})"
|
| 130 |
+
stroke-width={2 / zoom}
|
| 131 |
+
style="pointer-events: none"
|
| 132 |
+
/>
|
| 133 |
+
<!-- flow particles -->
|
| 134 |
+
<path
|
| 135 |
+
class="wire-flow"
|
| 136 |
+
d={bez(from.x, from.y, to.x, to.y)}
|
| 137 |
+
fill="none"
|
| 138 |
+
stroke={PORT_COLOR[edge.type]}
|
| 139 |
+
stroke-width={2 / zoom}
|
| 140 |
+
stroke-dasharray="{4 / zoom} {12 / zoom}"
|
| 141 |
+
stroke-opacity="0.5"
|
| 142 |
+
style="pointer-events: none"
|
| 143 |
+
/>
|
| 144 |
+
{/each}
|
| 145 |
+
|
| 146 |
+
{#if pending}
|
| 147 |
+
{@const anchor = getPortPos(
|
| 148 |
+
$workflow.nodes,
|
| 149 |
+
pending.from_node_id,
|
| 150 |
+
pending.from_port_id,
|
| 151 |
+
pending.reversed ? "input" : "output"
|
| 152 |
+
)}
|
| 153 |
+
<path
|
| 154 |
+
d={pending.reversed
|
| 155 |
+
? bez(pending.x, pending.y, anchor.x, anchor.y)
|
| 156 |
+
: bez(anchor.x, anchor.y, pending.x, pending.y)}
|
| 157 |
+
fill="none"
|
| 158 |
+
stroke={PORT_COLOR[pending.type] ?? "#5c5e6a"}
|
| 159 |
+
stroke-width={2 / zoom}
|
| 160 |
+
stroke-dasharray="{6 / zoom} {4 / zoom}"
|
| 161 |
+
stroke-opacity="0.6"
|
| 162 |
+
style="pointer-events: none"
|
| 163 |
+
/>
|
| 164 |
+
<circle
|
| 165 |
+
cx={pending.x}
|
| 166 |
+
cy={pending.y}
|
| 167 |
+
r={4 / zoom}
|
| 168 |
+
fill="none"
|
| 169 |
+
stroke={PORT_COLOR[pending.type] ?? "#5c5e6a"}
|
| 170 |
+
stroke-width={1.5 / zoom}
|
| 171 |
+
stroke-opacity="0.5"
|
| 172 |
+
style="pointer-events: none"
|
| 173 |
+
/>
|
| 174 |
+
{/if}
|
| 175 |
+
</svg>
|
| 176 |
+
|
| 177 |
+
<style>
|
| 178 |
+
.edge-layer {
|
| 179 |
+
position: absolute;
|
| 180 |
+
top: 0;
|
| 181 |
+
left: 0;
|
| 182 |
+
width: 1px;
|
| 183 |
+
height: 1px;
|
| 184 |
+
overflow: visible;
|
| 185 |
+
pointer-events: none;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
.wire-hitbox {
|
| 189 |
+
pointer-events: stroke;
|
| 190 |
+
cursor: pointer;
|
| 191 |
+
transition: stroke 0.15s;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.wire-hitbox:hover {
|
| 195 |
+
stroke: rgba(239, 68, 68, 0.25);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
.wire-flow {
|
| 199 |
+
animation: flow 1.2s linear infinite;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
@keyframes flow {
|
| 203 |
+
to {
|
| 204 |
+
stroke-dashoffset: -16;
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
</style>
|
6.17.1/workflowcanvas/workflow/WorkflowEmptyState.svelte
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div class="empty-state">
|
| 2 |
+
<div class="empty-icon">β¦</div>
|
| 3 |
+
<div class="empty-title">Start building</div>
|
| 4 |
+
<div class="empty-hint">Add a model or space from the toolbar below</div>
|
| 5 |
+
</div>
|
| 6 |
+
|
| 7 |
+
<style>
|
| 8 |
+
.empty-state {
|
| 9 |
+
position: absolute;
|
| 10 |
+
inset: 0;
|
| 11 |
+
display: flex;
|
| 12 |
+
flex-direction: column;
|
| 13 |
+
align-items: center;
|
| 14 |
+
justify-content: center;
|
| 15 |
+
gap: 8px;
|
| 16 |
+
pointer-events: none;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.empty-icon {
|
| 20 |
+
font-size: 22px;
|
| 21 |
+
color: #2a2b36;
|
| 22 |
+
margin-bottom: 4px;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.empty-title {
|
| 26 |
+
font-size: 15px;
|
| 27 |
+
font-weight: 700;
|
| 28 |
+
color: #3e3f4d;
|
| 29 |
+
letter-spacing: -0.01em;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.empty-hint {
|
| 33 |
+
font-size: 11.5px;
|
| 34 |
+
color: #2a2b36;
|
| 35 |
+
}
|
| 36 |
+
</style>
|
6.17.1/workflowcanvas/workflow/WorkflowNodeSF.svelte
ADDED
|
@@ -0,0 +1,1088 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { getContext } from "svelte";
|
| 3 |
+
import { resizeNode, workflow } from "./workflow-store";
|
| 4 |
+
import NodeWidget from "./NodeWidget.svelte";
|
| 5 |
+
import PlayIcon from "./icons/PlayIcon.svelte";
|
| 6 |
+
import OpenLinkIcon from "./icons/OpenLinkIcon.svelte";
|
| 7 |
+
import {
|
| 8 |
+
PORT_COLOR,
|
| 9 |
+
PORT_COLOR_DIM,
|
| 10 |
+
ports_compatible
|
| 11 |
+
} from "./workflow-types";
|
| 12 |
+
import type {
|
| 13 |
+
WFNode,
|
| 14 |
+
PortType,
|
| 15 |
+
NodeDataValue,
|
| 16 |
+
NodeStatus
|
| 17 |
+
} from "./workflow-types";
|
| 18 |
+
|
| 19 |
+
interface Props {
|
| 20 |
+
id: string;
|
| 21 |
+
data: WFNode;
|
| 22 |
+
selected?: boolean;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
let { id, data: node, selected = false }: Props = $props();
|
| 26 |
+
|
| 27 |
+
interface WfCtx {
|
| 28 |
+
pending: {
|
| 29 |
+
from_node_id: string;
|
| 30 |
+
from_port_id: string;
|
| 31 |
+
type: PortType;
|
| 32 |
+
reversed?: boolean;
|
| 33 |
+
} | null;
|
| 34 |
+
nodeStatus: Record<string, NodeStatus>;
|
| 35 |
+
nodeErrors: Record<string, string>;
|
| 36 |
+
staleNodes: Set<string>;
|
| 37 |
+
connectedPorts: Set<string>;
|
| 38 |
+
ondatachange: (
|
| 39 |
+
nodeId: string,
|
| 40 |
+
portId: string,
|
| 41 |
+
value: NodeDataValue
|
| 42 |
+
) => void;
|
| 43 |
+
onremove: (id: string) => void;
|
| 44 |
+
onopenpicker: (id: string) => void;
|
| 45 |
+
onswitchendpoint: (id: string, endpointName: string) => void;
|
| 46 |
+
onhydratendpoints: (id: string, spaceId: string) => void;
|
| 47 |
+
onrunnode: (id: string) => void;
|
| 48 |
+
onselect: (id: string) => void;
|
| 49 |
+
onnodepointerdown: (e: PointerEvent, id: string) => void;
|
| 50 |
+
onportpointerdown: (
|
| 51 |
+
e: PointerEvent,
|
| 52 |
+
nodeId: string,
|
| 53 |
+
portId: string,
|
| 54 |
+
type: PortType,
|
| 55 |
+
isInput: boolean
|
| 56 |
+
) => void;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
const ctx = getContext<WfCtx>("wf");
|
| 60 |
+
|
| 61 |
+
const pending = $derived(ctx.pending);
|
| 62 |
+
const status = $derived((ctx.nodeStatus[id] ?? "idle") as NodeStatus);
|
| 63 |
+
const error = $derived(ctx.nodeErrors[id] ?? "");
|
| 64 |
+
const isStale = $derived(ctx.staleNodes.has(id));
|
| 65 |
+
const connectedPorts = $derived(ctx.connectedPorts);
|
| 66 |
+
// Only operator nodes have meaningful per-node execution. References just
|
| 67 |
+
// hold values; subjects just display passthrough.
|
| 68 |
+
const canRunSolo = $derived(node.kind === "transform");
|
| 69 |
+
|
| 70 |
+
let nodeEl: HTMLDivElement;
|
| 71 |
+
let editingLabel = $state(false);
|
| 72 |
+
let labelInput: HTMLInputElement;
|
| 73 |
+
let showAllInputs = $state(false);
|
| 74 |
+
|
| 75 |
+
const INPUT_COLLAPSE_THRESHOLD = 3;
|
| 76 |
+
|
| 77 |
+
function renameNode(newLabel: string): void {
|
| 78 |
+
const trimmed = newLabel.trim();
|
| 79 |
+
if (trimmed && trimmed !== node.label) {
|
| 80 |
+
workflow.update((wf) => ({
|
| 81 |
+
...wf,
|
| 82 |
+
nodes: wf.nodes.map((n) =>
|
| 83 |
+
n.id === node.id ? { ...n, label: trimmed } : n
|
| 84 |
+
)
|
| 85 |
+
}));
|
| 86 |
+
}
|
| 87 |
+
editingLabel = false;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
const primaryType = $derived<PortType>(
|
| 91 |
+
node.outputs[0]?.type ?? node.inputs[0]?.type ?? "any"
|
| 92 |
+
);
|
| 93 |
+
const accentColor = $derived(PORT_COLOR[primaryType]);
|
| 94 |
+
const accentDim = $derived(PORT_COLOR_DIM[primaryType]);
|
| 95 |
+
|
| 96 |
+
const isComponent = $derived(node.kind === "component");
|
| 97 |
+
const componentIsOutput = $derived(
|
| 98 |
+
isComponent && node.inputs[0]
|
| 99 |
+
? connectedPorts.has(`${node.id}:${node.inputs[0].id}:input`)
|
| 100 |
+
: false
|
| 101 |
+
);
|
| 102 |
+
const mode = $derived(
|
| 103 |
+
isComponent ? (componentIsOutput ? "output" : "input") : node.kind
|
| 104 |
+
);
|
| 105 |
+
|
| 106 |
+
const hasWidget = $derived(mode === "input" || mode === "output");
|
| 107 |
+
const widgetPortId = $derived(
|
| 108 |
+
mode === "input"
|
| 109 |
+
? (node.outputs[0]?.id ?? null)
|
| 110 |
+
: mode === "output"
|
| 111 |
+
? (node.inputs[0]?.id ?? null)
|
| 112 |
+
: null
|
| 113 |
+
);
|
| 114 |
+
const widgetType = $derived<PortType | null>(
|
| 115 |
+
mode === "input"
|
| 116 |
+
? (node.outputs[0]?.type ?? null)
|
| 117 |
+
: mode === "output"
|
| 118 |
+
? (node.inputs[0]?.type ?? null)
|
| 119 |
+
: null
|
| 120 |
+
);
|
| 121 |
+
const isReadonly = $derived(mode === "output");
|
| 122 |
+
|
| 123 |
+
function sourceHFUrl(n: WFNode): string {
|
| 124 |
+
if (n.space_id) return `https://huggingface.co/spaces/${n.space_id}`;
|
| 125 |
+
if (n.model_id) return `https://huggingface.co/${n.model_id}`;
|
| 126 |
+
if (n.dataset_id) return `https://huggingface.co/datasets/${n.dataset_id}`;
|
| 127 |
+
return "";
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
const isDropTarget = $derived(
|
| 131 |
+
pending !== null &&
|
| 132 |
+
pending.from_node_id !== node.id &&
|
| 133 |
+
node.inputs.some(
|
| 134 |
+
(p) =>
|
| 135 |
+
ports_compatible(pending.type, p.type) &&
|
| 136 |
+
!connectedPorts.has(`${node.id}:${p.id}:input`)
|
| 137 |
+
)
|
| 138 |
+
);
|
| 139 |
+
|
| 140 |
+
$effect(() => {
|
| 141 |
+
if (!nodeEl) return;
|
| 142 |
+
const ro = new ResizeObserver(([entry]) => {
|
| 143 |
+
const h = Math.ceil(entry.borderBoxSize[0].blockSize);
|
| 144 |
+
if (Math.abs(h - node.height) > 1) {
|
| 145 |
+
resizeNode(node.id, node.width, h);
|
| 146 |
+
}
|
| 147 |
+
});
|
| 148 |
+
ro.observe(nodeEl);
|
| 149 |
+
return () => ro.disconnect();
|
| 150 |
+
});
|
| 151 |
+
</script>
|
| 152 |
+
|
| 153 |
+
<div
|
| 154 |
+
class="wf-node"
|
| 155 |
+
class:node-transform={node.kind === "transform"}
|
| 156 |
+
class:node-running={status === "running"}
|
| 157 |
+
class:node-done={status === "done"}
|
| 158 |
+
class:node-error={status === "error"}
|
| 159 |
+
class:node-stale={isStale}
|
| 160 |
+
class:node-selected={selected}
|
| 161 |
+
class:node-droptarget={isDropTarget}
|
| 162 |
+
class:has-pending={pending !== null}
|
| 163 |
+
bind:this={nodeEl}
|
| 164 |
+
onclick={() => ctx.onselect(node.id)}
|
| 165 |
+
style="
|
| 166 |
+
width: {node.width}px;
|
| 167 |
+
--accent: {accentColor};
|
| 168 |
+
--accent-dim: {accentDim};
|
| 169 |
+
"
|
| 170 |
+
>
|
| 171 |
+
<div class="node-header" role="button" tabindex="-1">
|
| 172 |
+
<div class="node-header-top">
|
| 173 |
+
{#if status === "running"}
|
| 174 |
+
<span class="node-status-spinner"></span>
|
| 175 |
+
{/if}
|
| 176 |
+
{#if editingLabel}
|
| 177 |
+
<input
|
| 178 |
+
bind:this={labelInput}
|
| 179 |
+
class="node-label-input"
|
| 180 |
+
value={node.label}
|
| 181 |
+
onblur={(e) => renameNode(e.currentTarget.value)}
|
| 182 |
+
onkeydown={(e) => {
|
| 183 |
+
if (e.key === "Enter") renameNode(e.currentTarget.value);
|
| 184 |
+
if (e.key === "Escape") editingLabel = false;
|
| 185 |
+
e.stopPropagation();
|
| 186 |
+
}}
|
| 187 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 188 |
+
/>
|
| 189 |
+
{:else}
|
| 190 |
+
<span
|
| 191 |
+
class="node-label"
|
| 192 |
+
ondblclick={(e) => {
|
| 193 |
+
e.stopPropagation();
|
| 194 |
+
editingLabel = true;
|
| 195 |
+
requestAnimationFrame(() => labelInput?.select());
|
| 196 |
+
}}>{node.label}</span
|
| 197 |
+
>
|
| 198 |
+
{/if}
|
| 199 |
+
{#if canRunSolo}
|
| 200 |
+
<button
|
| 201 |
+
class="node-run"
|
| 202 |
+
class:node-run-stale={isStale}
|
| 203 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 204 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 205 |
+
onclick={(e) => {
|
| 206 |
+
e.stopPropagation();
|
| 207 |
+
ctx.onrunnode(node.id);
|
| 208 |
+
}}
|
| 209 |
+
title={isStale ? "Run this node (inputs changed)" : "Run this node"}
|
| 210 |
+
aria-label="Run this node"
|
| 211 |
+
>
|
| 212 |
+
<PlayIcon />
|
| 213 |
+
</button>
|
| 214 |
+
{/if}
|
| 215 |
+
<button
|
| 216 |
+
class="node-delete"
|
| 217 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 218 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 219 |
+
onclick={(e) => {
|
| 220 |
+
e.stopPropagation();
|
| 221 |
+
ctx.onremove(node.id);
|
| 222 |
+
}}
|
| 223 |
+
title="Delete node">×</button
|
| 224 |
+
>
|
| 225 |
+
</div>
|
| 226 |
+
</div>
|
| 227 |
+
|
| 228 |
+
<!-- Source label for transform nodes β floats above the card.
|
| 229 |
+
Components are pure data containers and have no source label. -->
|
| 230 |
+
{#if node.kind === "transform"}
|
| 231 |
+
{#if node.space_id || node.model_id || node.dataset_id}
|
| 232 |
+
{@const itemId = node.space_id ?? node.model_id ?? node.dataset_id ?? ""}
|
| 233 |
+
<div class="node-outside-label-wrap">
|
| 234 |
+
<button
|
| 235 |
+
class="node-outside-label"
|
| 236 |
+
title="Click to change source"
|
| 237 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 238 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 239 |
+
onclick={(e) => {
|
| 240 |
+
e.stopPropagation();
|
| 241 |
+
ctx.onopenpicker(node.id);
|
| 242 |
+
}}>{itemId.split("/").pop() ?? itemId}</button
|
| 243 |
+
>
|
| 244 |
+
<a
|
| 245 |
+
class="node-outside-link"
|
| 246 |
+
href={sourceHFUrl(node)}
|
| 247 |
+
target="_blank"
|
| 248 |
+
rel="noopener noreferrer"
|
| 249 |
+
title="Open on HuggingFace"
|
| 250 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 251 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 252 |
+
onclick={(e) => e.stopPropagation()}
|
| 253 |
+
aria-label="Open on HuggingFace"
|
| 254 |
+
>
|
| 255 |
+
<OpenLinkIcon />
|
| 256 |
+
</a>
|
| 257 |
+
</div>
|
| 258 |
+
{:else if node.fn}
|
| 259 |
+
<!-- Python fn nodes already have a "source" β their function
|
| 260 |
+
name. Show that above the card; no picker swap because
|
| 261 |
+
fn nodes can't be replaced by a Space/Model in place. -->
|
| 262 |
+
<div class="node-outside-label-wrap">
|
| 263 |
+
<span class="node-outside-label node-outside-label-fn">{node.fn}()</span
|
| 264 |
+
>
|
| 265 |
+
</div>
|
| 266 |
+
{:else}
|
| 267 |
+
<button
|
| 268 |
+
class="node-outside-label node-outside-label-empty"
|
| 269 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 270 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 271 |
+
onclick={(e) => {
|
| 272 |
+
e.stopPropagation();
|
| 273 |
+
ctx.onopenpicker(node.id);
|
| 274 |
+
}}>+ source</button
|
| 275 |
+
>
|
| 276 |
+
{/if}
|
| 277 |
+
{/if}
|
| 278 |
+
|
| 279 |
+
{#if node.space_id}
|
| 280 |
+
<div
|
| 281 |
+
class="node-endpoint-row"
|
| 282 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 283 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 284 |
+
>
|
| 285 |
+
{#if node.endpoints && node.endpoints.length > 1}
|
| 286 |
+
<select
|
| 287 |
+
class="node-endpoint-select"
|
| 288 |
+
value={node.endpoint ?? ""}
|
| 289 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 290 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 291 |
+
onclick={(e) => e.stopPropagation()}
|
| 292 |
+
onchange={(e) => {
|
| 293 |
+
e.stopPropagation();
|
| 294 |
+
ctx.onswitchendpoint(
|
| 295 |
+
node.id,
|
| 296 |
+
(e.currentTarget as HTMLSelectElement).value
|
| 297 |
+
);
|
| 298 |
+
}}
|
| 299 |
+
>
|
| 300 |
+
{#each node.endpoints as ep}
|
| 301 |
+
<option value={ep.name}>{ep.name}</option>
|
| 302 |
+
{/each}
|
| 303 |
+
</select>
|
| 304 |
+
{:else if !node.endpoints}
|
| 305 |
+
<button
|
| 306 |
+
class="node-endpoint-load"
|
| 307 |
+
onpointerdown={(e) => e.stopPropagation()}
|
| 308 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 309 |
+
onclick={(e) => {
|
| 310 |
+
e.stopPropagation();
|
| 311 |
+
ctx.onhydratendpoints(node.id, node.space_id ?? "");
|
| 312 |
+
}}
|
| 313 |
+
title="Discover this Space's other endpoints"
|
| 314 |
+
>
|
| 315 |
+
{node.endpoint ?? "/predict"} βΎ
|
| 316 |
+
</button>
|
| 317 |
+
{/if}
|
| 318 |
+
</div>
|
| 319 |
+
{/if}
|
| 320 |
+
|
| 321 |
+
<!-- Input ports -->
|
| 322 |
+
{#if node.inputs.length > 0}
|
| 323 |
+
{@const collapsible = node.inputs.length > INPUT_COLLAPSE_THRESHOLD}
|
| 324 |
+
<div class="ports" class:widget-ports={hasWidget}>
|
| 325 |
+
{#each node.inputs as port, i}
|
| 326 |
+
{@const portConnected = connectedPorts.has(
|
| 327 |
+
`${node.id}:${port.id}:input`
|
| 328 |
+
)}
|
| 329 |
+
{@const visible =
|
| 330 |
+
showAllInputs || i < INPUT_COLLAPSE_THRESHOLD || portConnected}
|
| 331 |
+
{#if visible}
|
| 332 |
+
<div class="port-row input-row" class:widget-port={hasWidget}>
|
| 333 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 334 |
+
<div
|
| 335 |
+
class="port-handle-sf input-handle-sf"
|
| 336 |
+
class:connected={portConnected}
|
| 337 |
+
class:incompatible={pending !== null &&
|
| 338 |
+
!ports_compatible(pending.type, port.type)}
|
| 339 |
+
class:pulse={pending !== null &&
|
| 340 |
+
ports_compatible(pending.type, port.type)}
|
| 341 |
+
data-node-id={node.id}
|
| 342 |
+
data-port-id={port.id}
|
| 343 |
+
data-port-type={port.type}
|
| 344 |
+
data-port-direction="input"
|
| 345 |
+
style="--port-color: {PORT_COLOR[port.type]}"
|
| 346 |
+
onpointerdown={(e) =>
|
| 347 |
+
ctx.onportpointerdown(e, node.id, port.id, port.type, true)}
|
| 348 |
+
></div>
|
| 349 |
+
{#if !hasWidget}
|
| 350 |
+
<span
|
| 351 |
+
class="port-label"
|
| 352 |
+
class:port-label-optional={port.required === false}
|
| 353 |
+
>{port.label}</span
|
| 354 |
+
>
|
| 355 |
+
<span class="port-type-tag" style="color: {PORT_COLOR[port.type]}"
|
| 356 |
+
>{port.type}</span
|
| 357 |
+
>
|
| 358 |
+
{/if}
|
| 359 |
+
</div>
|
| 360 |
+
{#if !portConnected && node.kind === "transform" && (port.type === "text" || port.type === "number" || port.type === "boolean" || port.type === "any" || port.type === "json")}
|
| 361 |
+
<div
|
| 362 |
+
class="port-inline-config"
|
| 363 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 364 |
+
>
|
| 365 |
+
{#if port.type === "number"}
|
| 366 |
+
<input
|
| 367 |
+
class="inline-input inline-number"
|
| 368 |
+
type="number"
|
| 369 |
+
step="any"
|
| 370 |
+
placeholder={port.default_value != null
|
| 371 |
+
? String(port.default_value)
|
| 372 |
+
: "0"}
|
| 373 |
+
value={node.data?.[port.id] ?? ""}
|
| 374 |
+
oninput={(e) =>
|
| 375 |
+
ctx.ondatachange(
|
| 376 |
+
node.id,
|
| 377 |
+
port.id,
|
| 378 |
+
parseFloat(e.currentTarget.value) || 0
|
| 379 |
+
)}
|
| 380 |
+
/>
|
| 381 |
+
{:else if port.type === "boolean"}
|
| 382 |
+
<label class="inline-checkbox">
|
| 383 |
+
<input
|
| 384 |
+
type="checkbox"
|
| 385 |
+
checked={!!node.data?.[port.id]}
|
| 386 |
+
onchange={(e) =>
|
| 387 |
+
ctx.ondatachange(
|
| 388 |
+
node.id,
|
| 389 |
+
port.id,
|
| 390 |
+
e.currentTarget.checked
|
| 391 |
+
)}
|
| 392 |
+
/>
|
| 393 |
+
<span>{node.data?.[port.id] ? "On" : "Off"}</span>
|
| 394 |
+
</label>
|
| 395 |
+
{:else}
|
| 396 |
+
<input
|
| 397 |
+
class="inline-input"
|
| 398 |
+
type="text"
|
| 399 |
+
placeholder={port.default_value != null
|
| 400 |
+
? String(port.default_value)
|
| 401 |
+
: port.label}
|
| 402 |
+
value={typeof node.data?.[port.id] === "string"
|
| 403 |
+
? (node.data[port.id] as string)
|
| 404 |
+
: ""}
|
| 405 |
+
oninput={(e) =>
|
| 406 |
+
ctx.ondatachange(node.id, port.id, e.currentTarget.value)}
|
| 407 |
+
/>
|
| 408 |
+
{/if}
|
| 409 |
+
</div>
|
| 410 |
+
{/if}
|
| 411 |
+
{/if}
|
| 412 |
+
{/each}
|
| 413 |
+
{#if collapsible}
|
| 414 |
+
<button
|
| 415 |
+
class="ports-toggle"
|
| 416 |
+
onmousedown={(e) => e.stopPropagation()}
|
| 417 |
+
onclick={() => (showAllInputs = !showAllInputs)}
|
| 418 |
+
>
|
| 419 |
+
{#if showAllInputs}β΄ show less{:else}βΎ {node.inputs.length -
|
| 420 |
+
INPUT_COLLAPSE_THRESHOLD} more params{/if}
|
| 421 |
+
</button>
|
| 422 |
+
{/if}
|
| 423 |
+
</div>
|
| 424 |
+
{/if}
|
| 425 |
+
|
| 426 |
+
<!-- Widget zone -->
|
| 427 |
+
{#if hasWidget && widgetPortId && widgetType}
|
| 428 |
+
<NodeWidget
|
| 429 |
+
{node}
|
| 430 |
+
{widgetPortId}
|
| 431 |
+
{widgetType}
|
| 432 |
+
{isReadonly}
|
| 433 |
+
ondatachange={ctx.ondatachange}
|
| 434 |
+
/>
|
| 435 |
+
{/if}
|
| 436 |
+
|
| 437 |
+
<!-- Output ports -->
|
| 438 |
+
{#if node.outputs.length > 0}
|
| 439 |
+
<div class="ports" class:widget-ports={hasWidget}>
|
| 440 |
+
{#each node.outputs as port}
|
| 441 |
+
{@const portConnected = connectedPorts.has(
|
| 442 |
+
`${node.id}:${port.id}:output`
|
| 443 |
+
)}
|
| 444 |
+
<div class="port-row output-row" class:widget-port={hasWidget}>
|
| 445 |
+
{#if !hasWidget}
|
| 446 |
+
<span class="port-type-tag" style="color: {PORT_COLOR[port.type]}"
|
| 447 |
+
>{port.type}</span
|
| 448 |
+
>
|
| 449 |
+
<span class="port-label">{port.label}</span>
|
| 450 |
+
{/if}
|
| 451 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 452 |
+
<div
|
| 453 |
+
class="port-handle-sf output-handle-sf"
|
| 454 |
+
class:connected={portConnected}
|
| 455 |
+
data-node-id={node.id}
|
| 456 |
+
data-port-id={port.id}
|
| 457 |
+
data-port-type={port.type}
|
| 458 |
+
data-port-direction="output"
|
| 459 |
+
style="--port-color: {PORT_COLOR[port.type]}"
|
| 460 |
+
onpointerdown={(e) =>
|
| 461 |
+
ctx.onportpointerdown(e, node.id, port.id, port.type, false)}
|
| 462 |
+
></div>
|
| 463 |
+
</div>
|
| 464 |
+
{/each}
|
| 465 |
+
</div>
|
| 466 |
+
{/if}
|
| 467 |
+
|
| 468 |
+
{#if status === "error" && error}
|
| 469 |
+
<div class="node-error-banner">{error}</div>
|
| 470 |
+
{/if}
|
| 471 |
+
</div>
|
| 472 |
+
|
| 473 |
+
<style>
|
| 474 |
+
/* Prevent SvelteFlow from adding its own drag cursor while we use the node header */
|
| 475 |
+
.wf-node {
|
| 476 |
+
position: relative;
|
| 477 |
+
background: #16171f;
|
| 478 |
+
border: 1px solid #24252e;
|
| 479 |
+
border-radius: 10px;
|
| 480 |
+
min-height: 90px;
|
| 481 |
+
user-select: none;
|
| 482 |
+
font-family: "Manrope", sans-serif;
|
| 483 |
+
overflow: visible;
|
| 484 |
+
transition:
|
| 485 |
+
box-shadow 0.2s,
|
| 486 |
+
border-color 0.3s;
|
| 487 |
+
box-sizing: border-box;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
/* Space/transform nodes get a subtle top accent to distinguish from component nodes */
|
| 491 |
+
.wf-node.node-transform {
|
| 492 |
+
background: #13141c;
|
| 493 |
+
border-color: #2a2b38;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
.wf-node.node-transform .node-header {
|
| 497 |
+
border-bottom-color: #22233a;
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
.wf-node:hover {
|
| 501 |
+
box-shadow:
|
| 502 |
+
0 0 0 1px var(--accent-dim),
|
| 503 |
+
0 4px 20px rgba(0, 0, 0, 0.4);
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
.wf-node.node-selected {
|
| 507 |
+
border-color: #f97316;
|
| 508 |
+
box-shadow:
|
| 509 |
+
0 0 0 1px #f97316,
|
| 510 |
+
0 0 16px rgba(249, 115, 22, 0.15);
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
.wf-node.node-droptarget {
|
| 514 |
+
border-color: var(--accent);
|
| 515 |
+
box-shadow:
|
| 516 |
+
0 0 0 1px var(--accent),
|
| 517 |
+
0 0 20px var(--accent-dim);
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
.wf-node.node-running {
|
| 521 |
+
border-color: #f5a623;
|
| 522 |
+
box-shadow: 0 0 12px rgba(245, 166, 35, 0.2);
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
.wf-node.node-done {
|
| 526 |
+
border-color: #4fd1a5;
|
| 527 |
+
box-shadow: 0 0 12px rgba(79, 209, 165, 0.15);
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
.wf-node.node-error {
|
| 531 |
+
border-color: #ef4444;
|
| 532 |
+
box-shadow: 0 0 12px rgba(239, 68, 68, 0.15);
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
/* Stale: ran successfully, but inputs have since changed. Subtle dashed
|
| 536 |
+
* outline so the user knows the displayed output no longer reflects
|
| 537 |
+
* current upstream state. Overridden by running/error which are stronger
|
| 538 |
+
* signals. */
|
| 539 |
+
.wf-node.node-stale:not(.node-running):not(.node-error) {
|
| 540 |
+
border-color: #f97316;
|
| 541 |
+
border-style: dashed;
|
| 542 |
+
box-shadow: 0 0 10px rgba(249, 115, 22, 0.12);
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
.node-status-spinner {
|
| 546 |
+
width: 12px;
|
| 547 |
+
height: 12px;
|
| 548 |
+
border: 2px solid transparent;
|
| 549 |
+
border-top-color: #f5a623;
|
| 550 |
+
border-radius: 50%;
|
| 551 |
+
animation: node-spin 0.7s linear infinite;
|
| 552 |
+
flex-shrink: 0;
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
@keyframes node-spin {
|
| 556 |
+
to {
|
| 557 |
+
transform: rotate(360deg);
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
.node-header {
|
| 562 |
+
display: flex;
|
| 563 |
+
flex-direction: column;
|
| 564 |
+
gap: 4px;
|
| 565 |
+
padding: 9px 12px 8px;
|
| 566 |
+
cursor: grab;
|
| 567 |
+
border-bottom: 1px solid #1e1f2a;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
.node-header:active {
|
| 571 |
+
cursor: grabbing;
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
.node-header-top {
|
| 575 |
+
display: flex;
|
| 576 |
+
align-items: center;
|
| 577 |
+
gap: 7px;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
.node-label {
|
| 581 |
+
font-size: 12.5px;
|
| 582 |
+
font-weight: 600;
|
| 583 |
+
color: #d5d6de;
|
| 584 |
+
white-space: nowrap;
|
| 585 |
+
cursor: text;
|
| 586 |
+
flex: 1;
|
| 587 |
+
min-width: 0;
|
| 588 |
+
overflow: hidden;
|
| 589 |
+
padding: 1px 4px;
|
| 590 |
+
border: 1px solid transparent;
|
| 591 |
+
border-radius: 4px;
|
| 592 |
+
box-sizing: border-box;
|
| 593 |
+
mask-image: linear-gradient(
|
| 594 |
+
to right,
|
| 595 |
+
black calc(100% - 24px),
|
| 596 |
+
transparent 100%
|
| 597 |
+
);
|
| 598 |
+
-webkit-mask-image: linear-gradient(
|
| 599 |
+
to right,
|
| 600 |
+
black calc(100% - 24px),
|
| 601 |
+
transparent 100%
|
| 602 |
+
);
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
.node-label-input {
|
| 606 |
+
font-family: "Manrope", sans-serif;
|
| 607 |
+
font-size: 12.5px;
|
| 608 |
+
font-weight: 600;
|
| 609 |
+
color: #d5d6de;
|
| 610 |
+
background: #101118;
|
| 611 |
+
border: 1px solid #f97316;
|
| 612 |
+
border-radius: 4px;
|
| 613 |
+
padding: 1px 4px;
|
| 614 |
+
outline: none;
|
| 615 |
+
width: 100%;
|
| 616 |
+
min-width: 0;
|
| 617 |
+
box-sizing: border-box;
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
.node-outside-label-wrap {
|
| 621 |
+
position: absolute;
|
| 622 |
+
bottom: calc(100% + 6px);
|
| 623 |
+
/* Anchor to the card's right edge; label sits to the LEFT of the
|
| 624 |
+
* open-link icon with a small gap. */
|
| 625 |
+
right: 0;
|
| 626 |
+
display: flex;
|
| 627 |
+
align-items: center;
|
| 628 |
+
gap: 6px;
|
| 629 |
+
pointer-events: auto;
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
.node-outside-label {
|
| 633 |
+
position: absolute;
|
| 634 |
+
bottom: calc(100% + 6px);
|
| 635 |
+
right: 12px;
|
| 636 |
+
white-space: nowrap;
|
| 637 |
+
font-family: "Manrope", sans-serif;
|
| 638 |
+
font-size: 11.5px;
|
| 639 |
+
font-weight: 500;
|
| 640 |
+
color: #6b6e78;
|
| 641 |
+
background: transparent;
|
| 642 |
+
border: none;
|
| 643 |
+
padding: 0;
|
| 644 |
+
cursor: pointer;
|
| 645 |
+
transition: color 0.15s;
|
| 646 |
+
pointer-events: auto;
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
.node-outside-label-wrap .node-outside-label {
|
| 650 |
+
position: static;
|
| 651 |
+
bottom: auto;
|
| 652 |
+
right: auto;
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
.node-outside-label:hover {
|
| 656 |
+
color: #c8c9d2;
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
.node-outside-link {
|
| 660 |
+
display: inline-flex;
|
| 661 |
+
align-items: center;
|
| 662 |
+
justify-content: center;
|
| 663 |
+
width: 16px;
|
| 664 |
+
height: 16px;
|
| 665 |
+
color: #4a4d57;
|
| 666 |
+
opacity: 0;
|
| 667 |
+
text-decoration: none;
|
| 668 |
+
border-radius: 3px;
|
| 669 |
+
transition:
|
| 670 |
+
opacity 0.15s,
|
| 671 |
+
color 0.15s,
|
| 672 |
+
background 0.15s;
|
| 673 |
+
flex-shrink: 0;
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
.wf-node:hover .node-outside-link,
|
| 677 |
+
.node-outside-label-wrap:focus-within .node-outside-link {
|
| 678 |
+
opacity: 1;
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
.node-outside-link:hover {
|
| 682 |
+
color: #f97316;
|
| 683 |
+
background: rgba(249, 115, 22, 0.08);
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
.node-outside-label-empty {
|
| 687 |
+
color: #3a3b47;
|
| 688 |
+
font-size: 10.5px;
|
| 689 |
+
}
|
| 690 |
+
|
| 691 |
+
.node-outside-label-empty:hover {
|
| 692 |
+
color: #f97316;
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
.node-outside-label-fn {
|
| 696 |
+
font-family: "JetBrains Mono", monospace;
|
| 697 |
+
font-size: 10.5px;
|
| 698 |
+
color: #8b8d98;
|
| 699 |
+
cursor: default;
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
.node-delete {
|
| 703 |
+
display: none;
|
| 704 |
+
width: 20px;
|
| 705 |
+
height: 20px;
|
| 706 |
+
border: none;
|
| 707 |
+
border-radius: 4px;
|
| 708 |
+
background: transparent;
|
| 709 |
+
color: #5c5e6a;
|
| 710 |
+
font-size: 12px;
|
| 711 |
+
cursor: pointer;
|
| 712 |
+
flex-shrink: 0;
|
| 713 |
+
margin-left: auto;
|
| 714 |
+
align-items: center;
|
| 715 |
+
justify-content: center;
|
| 716 |
+
padding: 0;
|
| 717 |
+
text-align: center;
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
.wf-node:hover .node-delete {
|
| 721 |
+
display: flex;
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
.node-delete:hover {
|
| 725 |
+
background: rgba(239, 68, 68, 0.15);
|
| 726 |
+
color: #ef4444;
|
| 727 |
+
}
|
| 728 |
+
|
| 729 |
+
/* Per-node run button β hidden by default, revealed on hover, mirrors
|
| 730 |
+
* the node-delete affordance pattern. Stale state pulses faintly to
|
| 731 |
+
* signal "this needs re-running". */
|
| 732 |
+
.node-run {
|
| 733 |
+
display: none;
|
| 734 |
+
width: 20px;
|
| 735 |
+
height: 20px;
|
| 736 |
+
margin-left: auto;
|
| 737 |
+
border: none;
|
| 738 |
+
border-radius: 4px;
|
| 739 |
+
background: transparent;
|
| 740 |
+
color: #5c5e6a;
|
| 741 |
+
cursor: pointer;
|
| 742 |
+
flex-shrink: 0;
|
| 743 |
+
align-items: center;
|
| 744 |
+
justify-content: center;
|
| 745 |
+
padding: 0;
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
.wf-node:hover .node-run {
|
| 749 |
+
display: flex;
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
.node-run + .node-delete {
|
| 753 |
+
margin-left: 2px;
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
.node-run:hover {
|
| 757 |
+
background: rgba(249, 115, 22, 0.18);
|
| 758 |
+
color: #f97316;
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
.node-run.node-run-stale {
|
| 762 |
+
display: flex;
|
| 763 |
+
color: #f97316;
|
| 764 |
+
animation: node-run-pulse 1.8s ease-in-out infinite;
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
@keyframes node-run-pulse {
|
| 768 |
+
0%,
|
| 769 |
+
100% {
|
| 770 |
+
opacity: 1;
|
| 771 |
+
}
|
| 772 |
+
50% {
|
| 773 |
+
opacity: 0.55;
|
| 774 |
+
}
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
.ports {
|
| 778 |
+
padding: 6px 0 8px;
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
.ports.widget-ports {
|
| 782 |
+
padding: 0;
|
| 783 |
+
}
|
| 784 |
+
|
| 785 |
+
.port-row.widget-port {
|
| 786 |
+
padding: 0;
|
| 787 |
+
min-height: 0;
|
| 788 |
+
position: static;
|
| 789 |
+
}
|
| 790 |
+
|
| 791 |
+
.port-row {
|
| 792 |
+
display: flex;
|
| 793 |
+
align-items: center;
|
| 794 |
+
gap: 7px;
|
| 795 |
+
padding: 4px 12px;
|
| 796 |
+
position: relative;
|
| 797 |
+
min-height: 22px;
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
.input-row {
|
| 801 |
+
padding-left: 20px;
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
.output-row {
|
| 805 |
+
justify-content: flex-end;
|
| 806 |
+
padding-right: 20px;
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
.port-label {
|
| 810 |
+
font-size: 11.5px;
|
| 811 |
+
font-weight: 500;
|
| 812 |
+
color: #8b8d98;
|
| 813 |
+
white-space: nowrap;
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
.port-label-optional {
|
| 817 |
+
opacity: 0.5;
|
| 818 |
+
}
|
| 819 |
+
|
| 820 |
+
.port-type-tag {
|
| 821 |
+
font-family: "JetBrains Mono", monospace;
|
| 822 |
+
font-size: 9px;
|
| 823 |
+
font-weight: 500;
|
| 824 |
+
opacity: 0.5;
|
| 825 |
+
}
|
| 826 |
+
|
| 827 |
+
/* Port handles (plain divs, positioned on each port-row) */
|
| 828 |
+
.port-handle-sf {
|
| 829 |
+
width: 12px;
|
| 830 |
+
height: 12px;
|
| 831 |
+
border-radius: 50%;
|
| 832 |
+
border: 2px solid var(--port-color);
|
| 833 |
+
background: #0c0d10;
|
| 834 |
+
cursor: crosshair;
|
| 835 |
+
opacity: 0.5;
|
| 836 |
+
transition:
|
| 837 |
+
opacity 0.15s,
|
| 838 |
+
transform 0.15s,
|
| 839 |
+
background 0.15s,
|
| 840 |
+
box-shadow 0.15s;
|
| 841 |
+
position: absolute;
|
| 842 |
+
top: 50%;
|
| 843 |
+
transform: translateY(-50%);
|
| 844 |
+
touch-action: none;
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
.wf-node:hover .port-handle-sf,
|
| 848 |
+
.wf-node.node-selected .port-handle-sf,
|
| 849 |
+
.wf-node.has-pending .port-handle-sf {
|
| 850 |
+
opacity: 1;
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
.port-handle-sf.incompatible {
|
| 854 |
+
border-color: #ef4444;
|
| 855 |
+
opacity: 0.4;
|
| 856 |
+
animation: none;
|
| 857 |
+
}
|
| 858 |
+
|
| 859 |
+
.port-handle-sf.connected {
|
| 860 |
+
background: var(--port-color);
|
| 861 |
+
opacity: 1;
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
.input-handle-sf {
|
| 865 |
+
left: -24px;
|
| 866 |
+
right: auto;
|
| 867 |
+
}
|
| 868 |
+
|
| 869 |
+
.output-handle-sf {
|
| 870 |
+
right: -24px;
|
| 871 |
+
left: auto;
|
| 872 |
+
border-radius: 2px;
|
| 873 |
+
transform: translateY(-50%) rotate(45deg);
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
.port-handle-sf:hover {
|
| 877 |
+
opacity: 1;
|
| 878 |
+
background: var(--port-color);
|
| 879 |
+
box-shadow: 0 0 6px var(--port-color);
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
+
.output-handle-sf:hover {
|
| 883 |
+
transform: translateY(-50%) rotate(45deg) scale(1.4);
|
| 884 |
+
}
|
| 885 |
+
|
| 886 |
+
.port-handle-sf.pulse {
|
| 887 |
+
animation: port-pulse 1s ease-in-out infinite;
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
@keyframes port-pulse {
|
| 891 |
+
0%,
|
| 892 |
+
100% {
|
| 893 |
+
box-shadow: 0 0 0 0 transparent;
|
| 894 |
+
}
|
| 895 |
+
50% {
|
| 896 |
+
box-shadow: 0 0 0 4px var(--port-color);
|
| 897 |
+
opacity: 0.3;
|
| 898 |
+
}
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
.node-error-banner {
|
| 902 |
+
font-family: "JetBrains Mono", monospace;
|
| 903 |
+
font-size: 9px;
|
| 904 |
+
color: #fca5a5;
|
| 905 |
+
background: rgba(239, 68, 68, 0.1);
|
| 906 |
+
border-top: 1px solid rgba(239, 68, 68, 0.2);
|
| 907 |
+
border-radius: 0 0 10px 10px;
|
| 908 |
+
padding: 6px 12px;
|
| 909 |
+
line-height: 1.4;
|
| 910 |
+
word-break: break-word;
|
| 911 |
+
overflow: hidden;
|
| 912 |
+
max-height: 4.5em;
|
| 913 |
+
overflow-y: auto;
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
.ports-toggle {
|
| 917 |
+
display: block;
|
| 918 |
+
width: 100%;
|
| 919 |
+
padding: 4px 12px;
|
| 920 |
+
border: none;
|
| 921 |
+
background: transparent;
|
| 922 |
+
font-family: "JetBrains Mono", monospace;
|
| 923 |
+
font-size: 9px;
|
| 924 |
+
font-weight: 600;
|
| 925 |
+
color: #3e3f4d;
|
| 926 |
+
cursor: pointer;
|
| 927 |
+
text-align: left;
|
| 928 |
+
letter-spacing: 0.03em;
|
| 929 |
+
transition: color 0.15s;
|
| 930 |
+
}
|
| 931 |
+
|
| 932 |
+
.ports-toggle:hover {
|
| 933 |
+
color: #8b8d98;
|
| 934 |
+
}
|
| 935 |
+
|
| 936 |
+
.port-inline-config {
|
| 937 |
+
padding: 2px 12px 4px 20px;
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
.inline-input {
|
| 941 |
+
width: 100%;
|
| 942 |
+
font-family: "JetBrains Mono", monospace;
|
| 943 |
+
font-size: 10px;
|
| 944 |
+
padding: 4px 8px;
|
| 945 |
+
border: 1px solid #1e1f2a;
|
| 946 |
+
border-radius: 4px;
|
| 947 |
+
background: #101118;
|
| 948 |
+
color: #c8c9d2;
|
| 949 |
+
outline: none;
|
| 950 |
+
box-sizing: border-box;
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
.inline-input:focus {
|
| 954 |
+
border-color: #3e3f4d;
|
| 955 |
+
}
|
| 956 |
+
|
| 957 |
+
.inline-input::placeholder {
|
| 958 |
+
color: #4a4b58;
|
| 959 |
+
}
|
| 960 |
+
|
| 961 |
+
.inline-number {
|
| 962 |
+
width: 80px;
|
| 963 |
+
}
|
| 964 |
+
|
| 965 |
+
.inline-checkbox {
|
| 966 |
+
display: flex;
|
| 967 |
+
align-items: center;
|
| 968 |
+
gap: 6px;
|
| 969 |
+
font-family: "JetBrains Mono", monospace;
|
| 970 |
+
font-size: 10px;
|
| 971 |
+
color: #8b8d98;
|
| 972 |
+
cursor: pointer;
|
| 973 |
+
}
|
| 974 |
+
|
| 975 |
+
/* Light mode */
|
| 976 |
+
:global(body:not(.dark)) .wf-node {
|
| 977 |
+
background: #ffffff;
|
| 978 |
+
border-color: #e2e4ea;
|
| 979 |
+
}
|
| 980 |
+
|
| 981 |
+
:global(body:not(.dark)) .wf-node:hover {
|
| 982 |
+
box-shadow:
|
| 983 |
+
0 0 0 1px var(--accent-dim),
|
| 984 |
+
0 4px 20px rgba(0, 0, 0, 0.08);
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
:global(body:not(.dark)) .node-header {
|
| 988 |
+
border-bottom-color: #e2e4ea;
|
| 989 |
+
}
|
| 990 |
+
|
| 991 |
+
:global(body:not(.dark)) .node-label {
|
| 992 |
+
color: #1a1b25;
|
| 993 |
+
}
|
| 994 |
+
|
| 995 |
+
:global(body:not(.dark)) .node-label-input {
|
| 996 |
+
color: #1a1b25;
|
| 997 |
+
background: #ffffff;
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
:global(body:not(.dark)) .port-label {
|
| 1001 |
+
color: #6b6e78;
|
| 1002 |
+
}
|
| 1003 |
+
|
| 1004 |
+
:global(body:not(.dark)) .node-outside-label {
|
| 1005 |
+
color: #9a9caa;
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
:global(body:not(.dark)) .node-outside-label:hover {
|
| 1009 |
+
color: #1a1b25;
|
| 1010 |
+
}
|
| 1011 |
+
|
| 1012 |
+
:global(body:not(.dark)) .node-outside-label-empty {
|
| 1013 |
+
color: #c0c2cc;
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
:global(body:not(.dark)) .ports-toggle {
|
| 1017 |
+
color: #b0b2bc;
|
| 1018 |
+
}
|
| 1019 |
+
|
| 1020 |
+
:global(body:not(.dark)) .node-delete {
|
| 1021 |
+
color: #9a9caa;
|
| 1022 |
+
}
|
| 1023 |
+
|
| 1024 |
+
:global(body:not(.dark)) .port-handle-sf {
|
| 1025 |
+
background: #ffffff;
|
| 1026 |
+
}
|
| 1027 |
+
|
| 1028 |
+
:global(body:not(.dark)) .inline-input {
|
| 1029 |
+
background: #f8f9fb;
|
| 1030 |
+
border-color: #e2e4ea;
|
| 1031 |
+
color: #1a1b25;
|
| 1032 |
+
}
|
| 1033 |
+
|
| 1034 |
+
:global(body:not(.dark)) .inline-input::placeholder {
|
| 1035 |
+
color: #c0c2cc;
|
| 1036 |
+
}
|
| 1037 |
+
|
| 1038 |
+
:global(body:not(.dark)) .inline-checkbox {
|
| 1039 |
+
color: #6b6e78;
|
| 1040 |
+
}
|
| 1041 |
+
|
| 1042 |
+
.node-endpoint-row {
|
| 1043 |
+
padding: 2px 12px 0 0;
|
| 1044 |
+
display: flex;
|
| 1045 |
+
justify-content: flex-end;
|
| 1046 |
+
}
|
| 1047 |
+
|
| 1048 |
+
.node-endpoint-select,
|
| 1049 |
+
.node-endpoint-load {
|
| 1050 |
+
font-family: "JetBrains Mono", monospace;
|
| 1051 |
+
font-size: 9.5px;
|
| 1052 |
+
padding: 1px 0 1px 4px;
|
| 1053 |
+
border: none;
|
| 1054 |
+
background: transparent;
|
| 1055 |
+
color: #5c5e6a;
|
| 1056 |
+
cursor: pointer;
|
| 1057 |
+
outline: none;
|
| 1058 |
+
opacity: 0.6;
|
| 1059 |
+
transition:
|
| 1060 |
+
opacity 0.15s,
|
| 1061 |
+
color 0.15s;
|
| 1062 |
+
-webkit-appearance: none;
|
| 1063 |
+
appearance: none;
|
| 1064 |
+
text-align: right;
|
| 1065 |
+
text-align-last: right;
|
| 1066 |
+
}
|
| 1067 |
+
|
| 1068 |
+
.node-endpoint-select:hover,
|
| 1069 |
+
.node-endpoint-load:hover {
|
| 1070 |
+
opacity: 1;
|
| 1071 |
+
color: #a0a2ae;
|
| 1072 |
+
}
|
| 1073 |
+
|
| 1074 |
+
.wf-node:hover .node-endpoint-select,
|
| 1075 |
+
.wf-node:hover .node-endpoint-load {
|
| 1076 |
+
opacity: 1;
|
| 1077 |
+
}
|
| 1078 |
+
|
| 1079 |
+
:global(body:not(.dark)) .node-endpoint-select,
|
| 1080 |
+
:global(body:not(.dark)) .node-endpoint-load {
|
| 1081 |
+
color: #8b8d98;
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
:global(body:not(.dark)) .node-endpoint-select:hover,
|
| 1085 |
+
:global(body:not(.dark)) .node-endpoint-load:hover {
|
| 1086 |
+
color: #3e4050;
|
| 1087 |
+
}
|
| 1088 |
+
</style>
|
6.17.1/workflowcanvas/workflow/WorkflowSidebar.svelte
ADDED
|
@@ -0,0 +1,1727 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import {
|
| 3 |
+
LIBRARY,
|
| 4 |
+
SPACE_CATEGORIES,
|
| 5 |
+
TASK_SCHEMAS,
|
| 6 |
+
categorizeSpace,
|
| 7 |
+
type NodeTemplate
|
| 8 |
+
} from "./node-library";
|
| 9 |
+
import { PORT_COLOR } from "./workflow-types";
|
| 10 |
+
import type { PortType } from "./workflow-types";
|
| 11 |
+
import { fetchSpaceApi, normalize_space_id } from "./space-api";
|
| 12 |
+
import ChevronLeftIcon from "./icons/ChevronLeftIcon.svelte";
|
| 13 |
+
import ChevronDownIcon from "./icons/ChevronDownIcon.svelte";
|
| 14 |
+
|
| 15 |
+
interface TrendingSpace {
|
| 16 |
+
id: string;
|
| 17 |
+
title: string;
|
| 18 |
+
description: string;
|
| 19 |
+
likes: number;
|
| 20 |
+
running: boolean;
|
| 21 |
+
category: string | null;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
let {
|
| 25 |
+
onadd = undefined,
|
| 26 |
+
server = {},
|
| 27 |
+
hfToken = "",
|
| 28 |
+
trendingSpaces: propTrendingSpaces = undefined,
|
| 29 |
+
trendingLoading: propTrendingLoading = undefined
|
| 30 |
+
}: {
|
| 31 |
+
onadd?: (template: NodeTemplate) => void;
|
| 32 |
+
server?: Record<string, any>;
|
| 33 |
+
hfToken?: string;
|
| 34 |
+
trendingSpaces?: TrendingSpace[];
|
| 35 |
+
trendingLoading?: boolean;
|
| 36 |
+
} = $props();
|
| 37 |
+
|
| 38 |
+
let expandedSection: string | null = $state("spaces");
|
| 39 |
+
let collapsed = $state(false);
|
| 40 |
+
let sidebarWidth = $state(240);
|
| 41 |
+
let isResizing = $state(false);
|
| 42 |
+
|
| 43 |
+
// Load custom spaces from localStorage
|
| 44 |
+
let customSpaces: NodeTemplate[] = $state(
|
| 45 |
+
typeof localStorage !== "undefined"
|
| 46 |
+
? JSON.parse(localStorage.getItem("gradio_custom_spaces") ?? "[]")
|
| 47 |
+
: []
|
| 48 |
+
);
|
| 49 |
+
|
| 50 |
+
// Auto-save custom spaces to localStorage
|
| 51 |
+
$effect(() => {
|
| 52 |
+
if (typeof localStorage !== "undefined") {
|
| 53 |
+
localStorage.setItem(
|
| 54 |
+
"gradio_custom_spaces",
|
| 55 |
+
JSON.stringify(customSpaces)
|
| 56 |
+
);
|
| 57 |
+
}
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
function startResize(e: MouseEvent) {
|
| 61 |
+
e.preventDefault();
|
| 62 |
+
isResizing = true;
|
| 63 |
+
const startX = e.clientX;
|
| 64 |
+
const startWidth = sidebarWidth;
|
| 65 |
+
|
| 66 |
+
function onMove(ev: MouseEvent) {
|
| 67 |
+
sidebarWidth = Math.max(
|
| 68 |
+
160,
|
| 69 |
+
Math.min(400, startWidth + (ev.clientX - startX))
|
| 70 |
+
);
|
| 71 |
+
}
|
| 72 |
+
function onUp() {
|
| 73 |
+
isResizing = false;
|
| 74 |
+
window.removeEventListener("mousemove", onMove);
|
| 75 |
+
window.removeEventListener("mouseup", onUp);
|
| 76 |
+
}
|
| 77 |
+
window.addEventListener("mousemove", onMove);
|
| 78 |
+
window.addEventListener("mouseup", onUp);
|
| 79 |
+
}
|
| 80 |
+
let customSpaceInput = $state("");
|
| 81 |
+
let loadingSpace = $state(false);
|
| 82 |
+
let loadingSpaceName = $state("");
|
| 83 |
+
let spaceError = $state("");
|
| 84 |
+
|
| 85 |
+
function handleWindowClick(e: MouseEvent): void {
|
| 86 |
+
const target = e.target as HTMLElement;
|
| 87 |
+
if (searchResults.length > 0 && !target.closest(".add-space-wrapper")) {
|
| 88 |
+
searchResults = [];
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// Trending spaces β use parent-provided data if available, otherwise fetch own
|
| 93 |
+
let ownTrendingSpaces: TrendingSpace[] = $state([]);
|
| 94 |
+
let ownTrendingLoading = $state(true);
|
| 95 |
+
let trendingSpaces = $derived(propTrendingSpaces ?? ownTrendingSpaces);
|
| 96 |
+
let trendingLoading = $derived(propTrendingLoading ?? ownTrendingLoading);
|
| 97 |
+
|
| 98 |
+
async function fetchTrendingSpaces() {
|
| 99 |
+
if (propTrendingSpaces !== undefined) return;
|
| 100 |
+
if (!server?.search_spaces) {
|
| 101 |
+
ownTrendingLoading = false;
|
| 102 |
+
return;
|
| 103 |
+
}
|
| 104 |
+
try {
|
| 105 |
+
const raw = await server.search_spaces(["trending", "", ""]);
|
| 106 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 107 |
+
if (!Array.isArray(data)) {
|
| 108 |
+
ownTrendingSpaces = [];
|
| 109 |
+
return;
|
| 110 |
+
}
|
| 111 |
+
ownTrendingSpaces = data
|
| 112 |
+
.map((s: any) => {
|
| 113 |
+
const desc = s.cardData?.short_description || "";
|
| 114 |
+
return {
|
| 115 |
+
id: s.id,
|
| 116 |
+
title: s.cardData?.title || s.id.split("/").pop() || s.id,
|
| 117 |
+
description: desc,
|
| 118 |
+
likes: s.likes ?? 0,
|
| 119 |
+
running: s.runtime?.stage === "RUNNING",
|
| 120 |
+
category: categorizeSpace(
|
| 121 |
+
s.cardData?.pipeline_tag || s.pipeline_tag,
|
| 122 |
+
s.cardData?.tags,
|
| 123 |
+
desc,
|
| 124 |
+
s.id
|
| 125 |
+
)
|
| 126 |
+
};
|
| 127 |
+
})
|
| 128 |
+
.filter((s: TrendingSpace) => s.category !== null && s.running);
|
| 129 |
+
} catch {
|
| 130 |
+
ownTrendingSpaces = [];
|
| 131 |
+
} finally {
|
| 132 |
+
ownTrendingLoading = false;
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
if (typeof window !== "undefined") {
|
| 137 |
+
fetchTrendingSpaces();
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function trendingToTemplate(space: TrendingSpace): NodeTemplate {
|
| 141 |
+
return {
|
| 142 |
+
label: space.id.split("/").pop() || space.id,
|
| 143 |
+
kind: "transform",
|
| 144 |
+
source: "space",
|
| 145 |
+
space_id: space.id,
|
| 146 |
+
category: space.category ?? undefined,
|
| 147 |
+
inputs: [],
|
| 148 |
+
outputs: [],
|
| 149 |
+
width: 280,
|
| 150 |
+
height: 90
|
| 151 |
+
};
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
function getTrendingByCategory(cat: string): TrendingSpace[] {
|
| 155 |
+
return trendingSpaces.filter((s) => s.category === cat);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
// Search state
|
| 159 |
+
let searchResults: {
|
| 160 |
+
id: string;
|
| 161 |
+
likes: number;
|
| 162 |
+
title?: string;
|
| 163 |
+
description?: string;
|
| 164 |
+
running: boolean;
|
| 165 |
+
}[] = $state([]);
|
| 166 |
+
let searching = $state(false);
|
| 167 |
+
let searchTimeout: ReturnType<typeof setTimeout> | null = null;
|
| 168 |
+
|
| 169 |
+
function handleSearchInput(e: Event) {
|
| 170 |
+
const query = (e.currentTarget as HTMLInputElement).value;
|
| 171 |
+
customSpaceInput = query;
|
| 172 |
+
spaceError = "";
|
| 173 |
+
|
| 174 |
+
if (searchTimeout) clearTimeout(searchTimeout);
|
| 175 |
+
|
| 176 |
+
if (query.length < 2) {
|
| 177 |
+
searchResults = [];
|
| 178 |
+
searching = false;
|
| 179 |
+
return;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
if (normalize_space_id(query)) {
|
| 183 |
+
searchResults = [];
|
| 184 |
+
return;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
searching = true;
|
| 188 |
+
searchTimeout = setTimeout(async () => {
|
| 189 |
+
try {
|
| 190 |
+
if (!server?.search_spaces) {
|
| 191 |
+
searchResults = [];
|
| 192 |
+
return;
|
| 193 |
+
}
|
| 194 |
+
const raw = await server.search_spaces(["search", query, ""]);
|
| 195 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 196 |
+
if (!Array.isArray(data)) {
|
| 197 |
+
searchResults = [];
|
| 198 |
+
return;
|
| 199 |
+
}
|
| 200 |
+
searchResults = data
|
| 201 |
+
.filter((s: any) => s.sdk === "gradio")
|
| 202 |
+
.slice(0, 6)
|
| 203 |
+
.map((s: any) => ({
|
| 204 |
+
id: s.id,
|
| 205 |
+
likes: s.likes ?? 0,
|
| 206 |
+
title: s.title || s.id.split("/").pop(),
|
| 207 |
+
description: s.ai_short_description || "",
|
| 208 |
+
running: s.runtime?.stage === "RUNNING"
|
| 209 |
+
}));
|
| 210 |
+
} catch {
|
| 211 |
+
searchResults = [];
|
| 212 |
+
} finally {
|
| 213 |
+
searching = false;
|
| 214 |
+
}
|
| 215 |
+
}, 300);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
function selectSearchResult(spaceId: string) {
|
| 219 |
+
customSpaceInput = spaceId;
|
| 220 |
+
searchResults = [];
|
| 221 |
+
addCustomSpace();
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
function primaryType(item: (typeof LIBRARY)["inputs"][number]): PortType {
|
| 225 |
+
return item.outputs[0]?.type ?? item.inputs[0]?.type ?? "any";
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
function toggle(section: string) {
|
| 229 |
+
expandedSection = expandedSection === section ? null : section;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
async function addCustomSpace() {
|
| 233 |
+
const spaceId = normalize_space_id(customSpaceInput);
|
| 234 |
+
if (!spaceId) {
|
| 235 |
+
spaceError = "Enter owner/repo or paste a Space URL";
|
| 236 |
+
return;
|
| 237 |
+
}
|
| 238 |
+
if (customSpaces.some((s) => s.space_id === spaceId)) {
|
| 239 |
+
customSpaceInput = "";
|
| 240 |
+
return;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
loadingSpace = true;
|
| 244 |
+
loadingSpaceName = spaceId;
|
| 245 |
+
spaceError = "";
|
| 246 |
+
customSpaceInput = "";
|
| 247 |
+
|
| 248 |
+
try {
|
| 249 |
+
const apiInfo = await fetchSpaceApi(spaceId);
|
| 250 |
+
const label = spaceId.split("/").pop() ?? spaceId;
|
| 251 |
+
|
| 252 |
+
customSpaces = [
|
| 253 |
+
...customSpaces,
|
| 254 |
+
{
|
| 255 |
+
label,
|
| 256 |
+
kind: "transform",
|
| 257 |
+
source: "space",
|
| 258 |
+
space_id: spaceId,
|
| 259 |
+
endpoint: apiInfo.endpoint,
|
| 260 |
+
inputs: apiInfo.inputs,
|
| 261 |
+
outputs: apiInfo.outputs,
|
| 262 |
+
width: apiInfo.width,
|
| 263 |
+
height: 90
|
| 264 |
+
}
|
| 265 |
+
];
|
| 266 |
+
customSpaceInput = "";
|
| 267 |
+
} catch (err) {
|
| 268 |
+
spaceError = err instanceof Error ? err.message : "Failed to connect";
|
| 269 |
+
} finally {
|
| 270 |
+
loadingSpace = false;
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// ββ Model search ββ
|
| 275 |
+
interface HFModel {
|
| 276 |
+
id: string;
|
| 277 |
+
pipeline_tag: string;
|
| 278 |
+
likes: number;
|
| 279 |
+
downloads: number;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
const MODEL_TASKS = [
|
| 283 |
+
{ key: "text-to-image", label: "Text β Image" },
|
| 284 |
+
{ key: "text-generation", label: "Text Generation" },
|
| 285 |
+
{ key: "image-to-text", label: "Image β Text" },
|
| 286 |
+
{ key: "image-classification", label: "Image Classification" },
|
| 287 |
+
{ key: "object-detection", label: "Object Detection" },
|
| 288 |
+
{ key: "automatic-speech-recognition", label: "Speech β Text" },
|
| 289 |
+
{ key: "text-to-speech", label: "Text β Speech" },
|
| 290 |
+
{ key: "translation", label: "Translation" },
|
| 291 |
+
{ key: "summarization", label: "Summarization" },
|
| 292 |
+
{ key: "text-classification", label: "Text Classification" },
|
| 293 |
+
{ key: "image-to-image", label: "Image β Image" },
|
| 294 |
+
{ key: "depth-estimation", label: "Depth Estimation" },
|
| 295 |
+
{ key: "image-segmentation", label: "Image Segmentation" },
|
| 296 |
+
{ key: "text-to-video", label: "Text β Video" },
|
| 297 |
+
{ key: "image-text-to-text", label: "Image+Text β Text" },
|
| 298 |
+
{ key: "feature-extraction", label: "Embeddings" }
|
| 299 |
+
];
|
| 300 |
+
|
| 301 |
+
let modelSearchQuery = $state("");
|
| 302 |
+
let modelSearchResults: HFModel[] = $state([]);
|
| 303 |
+
let modelSearching = $state(false);
|
| 304 |
+
let modelSearchTimeout: ReturnType<typeof setTimeout> | null = null;
|
| 305 |
+
let selectedModelTask = $state("");
|
| 306 |
+
let trendingModels: HFModel[] = $state([]);
|
| 307 |
+
let trendingModelsLoading = $state(true);
|
| 308 |
+
|
| 309 |
+
async function fetchTrendingModels() {
|
| 310 |
+
if (!server?.search_models) {
|
| 311 |
+
trendingModelsLoading = false;
|
| 312 |
+
return;
|
| 313 |
+
}
|
| 314 |
+
try {
|
| 315 |
+
const raw = await server.search_models(["trending", "", "", ""]);
|
| 316 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 317 |
+
if (!Array.isArray(data)) {
|
| 318 |
+
trendingModels = [];
|
| 319 |
+
return;
|
| 320 |
+
}
|
| 321 |
+
trendingModels = data
|
| 322 |
+
.filter((m: any) => m.pipeline_tag && TASK_SCHEMAS[m.pipeline_tag])
|
| 323 |
+
.map((m: any) => ({
|
| 324 |
+
id: m.id,
|
| 325 |
+
pipeline_tag: m.pipeline_tag,
|
| 326 |
+
likes: m.likes ?? 0,
|
| 327 |
+
downloads: m.downloads ?? 0
|
| 328 |
+
}));
|
| 329 |
+
} catch {
|
| 330 |
+
trendingModels = [];
|
| 331 |
+
} finally {
|
| 332 |
+
trendingModelsLoading = false;
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
if (typeof window !== "undefined") {
|
| 337 |
+
fetchTrendingModels();
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
function handleModelSearch(e: Event) {
|
| 341 |
+
const query = (e.currentTarget as HTMLInputElement).value;
|
| 342 |
+
modelSearchQuery = query;
|
| 343 |
+
|
| 344 |
+
if (modelSearchTimeout) clearTimeout(modelSearchTimeout);
|
| 345 |
+
|
| 346 |
+
if (query.length < 2 && !selectedModelTask) {
|
| 347 |
+
modelSearchResults = [];
|
| 348 |
+
modelSearching = false;
|
| 349 |
+
return;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
modelSearching = true;
|
| 353 |
+
modelSearchTimeout = setTimeout(async () => {
|
| 354 |
+
try {
|
| 355 |
+
if (!server?.search_models) {
|
| 356 |
+
modelSearchResults = [];
|
| 357 |
+
return;
|
| 358 |
+
}
|
| 359 |
+
const raw = await server.search_models([
|
| 360 |
+
"search",
|
| 361 |
+
query.length >= 2 ? query : "",
|
| 362 |
+
selectedModelTask,
|
| 363 |
+
""
|
| 364 |
+
]);
|
| 365 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 366 |
+
if (!Array.isArray(data)) {
|
| 367 |
+
modelSearchResults = [];
|
| 368 |
+
return;
|
| 369 |
+
}
|
| 370 |
+
modelSearchResults = data
|
| 371 |
+
.filter((m: any) => m.pipeline_tag && TASK_SCHEMAS[m.pipeline_tag])
|
| 372 |
+
.map((m: any) => ({
|
| 373 |
+
id: m.id,
|
| 374 |
+
pipeline_tag: m.pipeline_tag,
|
| 375 |
+
likes: m.likes ?? 0,
|
| 376 |
+
downloads: m.downloads ?? 0
|
| 377 |
+
}));
|
| 378 |
+
} catch {
|
| 379 |
+
modelSearchResults = [];
|
| 380 |
+
} finally {
|
| 381 |
+
modelSearching = false;
|
| 382 |
+
}
|
| 383 |
+
}, 300);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function handleTaskFilter(taskKey: string) {
|
| 387 |
+
selectedModelTask = selectedModelTask === taskKey ? "" : taskKey;
|
| 388 |
+
// Re-trigger search with new filter
|
| 389 |
+
handleModelSearch({ currentTarget: { value: modelSearchQuery } } as any);
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
function modelToTemplate(model: HFModel): NodeTemplate {
|
| 393 |
+
const schema = TASK_SCHEMAS[model.pipeline_tag];
|
| 394 |
+
return {
|
| 395 |
+
label: model.id.split("/").pop() || model.id,
|
| 396 |
+
kind: "transform",
|
| 397 |
+
source: "model",
|
| 398 |
+
model_id: model.id,
|
| 399 |
+
pipeline_tag: model.pipeline_tag,
|
| 400 |
+
inputs: schema?.inputs ?? [],
|
| 401 |
+
outputs: schema?.outputs ?? [],
|
| 402 |
+
width: 280,
|
| 403 |
+
height: 90
|
| 404 |
+
};
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
function getModelsForTask(task: string): HFModel[] {
|
| 408 |
+
return trendingModels.filter((m) => m.pipeline_tag === task);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
// ββ Dataset search ββ
|
| 412 |
+
interface HFDataset {
|
| 413 |
+
id: string;
|
| 414 |
+
likes: number;
|
| 415 |
+
downloads: number;
|
| 416 |
+
description: string;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
let datasetSearchQuery = $state("");
|
| 420 |
+
let datasetSearchResults: HFDataset[] = $state([]);
|
| 421 |
+
let datasetSearching = $state(false);
|
| 422 |
+
let datasetSearchTimeout: ReturnType<typeof setTimeout> | null = null;
|
| 423 |
+
let loadingDataset = $state(false);
|
| 424 |
+
let loadingDatasetName = $state("");
|
| 425 |
+
let datasetError = $state("");
|
| 426 |
+
let datasetsAdded = $state(0);
|
| 427 |
+
|
| 428 |
+
function handleDatasetSearch(e: Event) {
|
| 429 |
+
const query = (e.currentTarget as HTMLInputElement).value;
|
| 430 |
+
datasetSearchQuery = query;
|
| 431 |
+
datasetError = "";
|
| 432 |
+
|
| 433 |
+
if (datasetSearchTimeout) clearTimeout(datasetSearchTimeout);
|
| 434 |
+
|
| 435 |
+
if (query.length < 2) {
|
| 436 |
+
datasetSearchResults = [];
|
| 437 |
+
datasetSearching = false;
|
| 438 |
+
return;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
datasetSearching = true;
|
| 442 |
+
datasetSearchTimeout = setTimeout(async () => {
|
| 443 |
+
try {
|
| 444 |
+
if (!server?.search_datasets) {
|
| 445 |
+
datasetSearchResults = [];
|
| 446 |
+
return;
|
| 447 |
+
}
|
| 448 |
+
const raw = await server.search_datasets([query, ""]);
|
| 449 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 450 |
+
if (!Array.isArray(data)) {
|
| 451 |
+
datasetSearchResults = [];
|
| 452 |
+
return;
|
| 453 |
+
}
|
| 454 |
+
datasetSearchResults = data.map((d: any) => ({
|
| 455 |
+
id: d.id,
|
| 456 |
+
likes: d.likes ?? 0,
|
| 457 |
+
downloads: d.downloads ?? 0,
|
| 458 |
+
description: d.cardData?.description?.slice(0, 80) || ""
|
| 459 |
+
}));
|
| 460 |
+
} catch {
|
| 461 |
+
datasetSearchResults = [];
|
| 462 |
+
} finally {
|
| 463 |
+
datasetSearching = false;
|
| 464 |
+
}
|
| 465 |
+
}, 300);
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
async function addDataset(datasetId: string) {
|
| 469 |
+
loadingDataset = true;
|
| 470 |
+
loadingDatasetName = datasetId;
|
| 471 |
+
datasetError = "";
|
| 472 |
+
|
| 473 |
+
try {
|
| 474 |
+
if (!server?.get_dataset_schema)
|
| 475 |
+
throw new Error("Dataset schema function not available");
|
| 476 |
+
const raw = await server.get_dataset_schema([datasetId, hfToken || ""]);
|
| 477 |
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
| 478 |
+
if (data?.error) throw new Error(data.error);
|
| 479 |
+
|
| 480 |
+
const features: { name: string; type: any }[] = data.features ?? [];
|
| 481 |
+
const featureToPortType = (f: any): PortType => {
|
| 482 |
+
const dtype = f.type?.dtype || f.type?._type || "";
|
| 483 |
+
if (
|
| 484 |
+
dtype === "string" ||
|
| 485 |
+
(f.type?._type === "Value" && f.type?.dtype === "string")
|
| 486 |
+
)
|
| 487 |
+
return "text";
|
| 488 |
+
if (
|
| 489 |
+
dtype === "float32" ||
|
| 490 |
+
dtype === "float64" ||
|
| 491 |
+
dtype === "int32" ||
|
| 492 |
+
dtype === "int64"
|
| 493 |
+
)
|
| 494 |
+
return "number";
|
| 495 |
+
if (f.type?._type === "Image") return "image";
|
| 496 |
+
if (f.type?._type === "Audio") return "audio";
|
| 497 |
+
return "json";
|
| 498 |
+
};
|
| 499 |
+
|
| 500 |
+
const outputs = features.slice(0, 6).map((f, i) => ({
|
| 501 |
+
id: `out_${i}`,
|
| 502 |
+
label: f.name,
|
| 503 |
+
type: featureToPortType(f)
|
| 504 |
+
}));
|
| 505 |
+
|
| 506 |
+
const template: NodeTemplate = {
|
| 507 |
+
label: datasetId.split("/").pop() || datasetId,
|
| 508 |
+
kind: "input" as const,
|
| 509 |
+
source: "dataset",
|
| 510 |
+
dataset_id: datasetId,
|
| 511 |
+
dataset_config: data.config,
|
| 512 |
+
dataset_split: data.split,
|
| 513 |
+
inputs: [],
|
| 514 |
+
outputs,
|
| 515 |
+
width: 280,
|
| 516 |
+
height: Math.max(90, 50 + outputs.length * 22)
|
| 517 |
+
};
|
| 518 |
+
|
| 519 |
+
onadd?.(template);
|
| 520 |
+
datasetsAdded += 1;
|
| 521 |
+
} catch (err) {
|
| 522 |
+
datasetError =
|
| 523 |
+
err instanceof Error ? err.message : "Failed to load dataset";
|
| 524 |
+
} finally {
|
| 525 |
+
loadingDataset = false;
|
| 526 |
+
}
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
const sections = [
|
| 530 |
+
{ key: "spaces", label: "Spaces", icon: "hub", items: LIBRARY.spaces },
|
| 531 |
+
{
|
| 532 |
+
key: "models",
|
| 533 |
+
label: "Models",
|
| 534 |
+
icon: "model",
|
| 535 |
+
items: [] as NodeTemplate[]
|
| 536 |
+
},
|
| 537 |
+
{
|
| 538 |
+
key: "datasets",
|
| 539 |
+
label: "Datasets",
|
| 540 |
+
icon: "data",
|
| 541 |
+
items: [] as NodeTemplate[]
|
| 542 |
+
},
|
| 543 |
+
{
|
| 544 |
+
key: "components",
|
| 545 |
+
label: "Components",
|
| 546 |
+
icon: "layers",
|
| 547 |
+
items: LIBRARY.components
|
| 548 |
+
}
|
| 549 |
+
];
|
| 550 |
+
</script>
|
| 551 |
+
|
| 552 |
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
| 553 |
+
<svelte:window onclick={handleWindowClick} />
|
| 554 |
+
|
| 555 |
+
<aside
|
| 556 |
+
class="sidebar"
|
| 557 |
+
class:sidebar-collapsed={collapsed}
|
| 558 |
+
style="width: {collapsed ? 40 : sidebarWidth}px; min-width: {collapsed
|
| 559 |
+
? 40
|
| 560 |
+
: sidebarWidth}px;"
|
| 561 |
+
>
|
| 562 |
+
<div class="sidebar-header">
|
| 563 |
+
<button
|
| 564 |
+
class="sidebar-collapse-btn"
|
| 565 |
+
class:collapsed
|
| 566 |
+
onclick={() => (collapsed = !collapsed)}
|
| 567 |
+
>
|
| 568 |
+
<ChevronLeftIcon />
|
| 569 |
+
</button>
|
| 570 |
+
</div>
|
| 571 |
+
|
| 572 |
+
{#if !collapsed}
|
| 573 |
+
{#each sections as section}
|
| 574 |
+
<button
|
| 575 |
+
class="section-toggle"
|
| 576 |
+
class:expanded={expandedSection === section.key}
|
| 577 |
+
onclick={() => toggle(section.key)}
|
| 578 |
+
>
|
| 579 |
+
<span class="section-label">{section.label}</span>
|
| 580 |
+
<span class="section-count"
|
| 581 |
+
>{section.key === "spaces"
|
| 582 |
+
? customSpaces.length + trendingSpaces.length
|
| 583 |
+
: section.key === "models"
|
| 584 |
+
? trendingModels.length
|
| 585 |
+
: section.key === "datasets"
|
| 586 |
+
? datasetsAdded
|
| 587 |
+
: section.items.length}</span
|
| 588 |
+
>
|
| 589 |
+
<span
|
| 590 |
+
class="section-chevron"
|
| 591 |
+
class:expanded={expandedSection === section.key}
|
| 592 |
+
>
|
| 593 |
+
<ChevronDownIcon />
|
| 594 |
+
</span>
|
| 595 |
+
</button>
|
| 596 |
+
|
| 597 |
+
{#if expandedSection === section.key}
|
| 598 |
+
<div class="section-items">
|
| 599 |
+
{#if section.key === "spaces"}
|
| 600 |
+
{#if trendingLoading}
|
| 601 |
+
<div class="trending-status">
|
| 602 |
+
<span class="space-loading-spinner"></span>
|
| 603 |
+
<span class="trending-status-text"
|
| 604 |
+
>Loading trending spaces...</span
|
| 605 |
+
>
|
| 606 |
+
</div>
|
| 607 |
+
{/if}
|
| 608 |
+
|
| 609 |
+
{#each SPACE_CATEGORIES as cat}
|
| 610 |
+
{@const trending = getTrendingByCategory(cat.key)}
|
| 611 |
+
{#if trending.length > 0}
|
| 612 |
+
<div class="category-header">
|
| 613 |
+
<span class="category-label">{cat.label}</span>
|
| 614 |
+
<span class="category-count">{trending.length}</span>
|
| 615 |
+
</div>
|
| 616 |
+
|
| 617 |
+
{#each trending as space}
|
| 618 |
+
<div
|
| 619 |
+
draggable="true"
|
| 620 |
+
class="space-card"
|
| 621 |
+
onclick={() => onadd?.(trendingToTemplate(space))}
|
| 622 |
+
ondragstart={(e) => {
|
| 623 |
+
const template = trendingToTemplate(space);
|
| 624 |
+
e.dataTransfer!.setData(
|
| 625 |
+
"node-template",
|
| 626 |
+
JSON.stringify(template)
|
| 627 |
+
);
|
| 628 |
+
const ghost = document.createElement("div");
|
| 629 |
+
ghost.textContent = space.title;
|
| 630 |
+
ghost.style.cssText =
|
| 631 |
+
"background:#f97316;color:#0c0d10;padding:4px 10px;border-radius:5px;font-family:Manrope,sans-serif;font-size:11px;font-weight:600;position:fixed;top:-100px";
|
| 632 |
+
document.body.appendChild(ghost);
|
| 633 |
+
e.dataTransfer!.setDragImage(ghost, 0, 0);
|
| 634 |
+
setTimeout(() => document.body.removeChild(ghost), 0);
|
| 635 |
+
}}
|
| 636 |
+
>
|
| 637 |
+
<div class="space-card-header">
|
| 638 |
+
<span
|
| 639 |
+
class="space-card-status"
|
| 640 |
+
class:space-card-running={space.running}
|
| 641 |
+
title={space.running ? "Running" : "Sleeping"}
|
| 642 |
+
></span>
|
| 643 |
+
<span class="space-card-name">{space.title}</span>
|
| 644 |
+
<span class="space-card-likes"
|
| 645 |
+
>♥ {space.likes}</span
|
| 646 |
+
>
|
| 647 |
+
<a
|
| 648 |
+
class="space-card-link"
|
| 649 |
+
href="https://huggingface.co/spaces/{space.id}"
|
| 650 |
+
target="_blank"
|
| 651 |
+
rel="noopener"
|
| 652 |
+
onclick={(e) => e.stopPropagation()}
|
| 653 |
+
title="Open on HuggingFace">↗</a
|
| 654 |
+
>
|
| 655 |
+
</div>
|
| 656 |
+
<div class="space-card-id">{space.id}</div>
|
| 657 |
+
{#if space.description}
|
| 658 |
+
<div class="space-card-desc">{space.description}</div>
|
| 659 |
+
{/if}
|
| 660 |
+
</div>
|
| 661 |
+
{/each}
|
| 662 |
+
{/if}
|
| 663 |
+
{/each}
|
| 664 |
+
{:else if section.key === "models"}
|
| 665 |
+
<div class="add-space-wrapper">
|
| 666 |
+
<div class="add-space">
|
| 667 |
+
<input
|
| 668 |
+
class="space-input"
|
| 669 |
+
type="text"
|
| 670 |
+
placeholder="Search models..."
|
| 671 |
+
value={modelSearchQuery}
|
| 672 |
+
oninput={handleModelSearch}
|
| 673 |
+
/>
|
| 674 |
+
</div>
|
| 675 |
+
</div>
|
| 676 |
+
<div class="model-task-filters">
|
| 677 |
+
{#each MODEL_TASKS as task}
|
| 678 |
+
<button
|
| 679 |
+
class="model-task-tag"
|
| 680 |
+
class:model-task-tag-active={selectedModelTask === task.key}
|
| 681 |
+
onclick={() => handleTaskFilter(task.key)}
|
| 682 |
+
>{task.label}</button
|
| 683 |
+
>
|
| 684 |
+
{/each}
|
| 685 |
+
</div>
|
| 686 |
+
|
| 687 |
+
{#if modelSearching}
|
| 688 |
+
<div class="space-loading">
|
| 689 |
+
<span class="space-loading-spinner"></span>
|
| 690 |
+
<span class="space-loading-text">Searching...</span>
|
| 691 |
+
</div>
|
| 692 |
+
{:else if modelSearchQuery.length >= 2 || selectedModelTask}
|
| 693 |
+
{#each modelSearchResults as model}
|
| 694 |
+
{@const template = modelToTemplate(model)}
|
| 695 |
+
{@const pt =
|
| 696 |
+
template.outputs[0]?.type ??
|
| 697 |
+
template.inputs[0]?.type ??
|
| 698 |
+
"any"}
|
| 699 |
+
<div
|
| 700 |
+
draggable="true"
|
| 701 |
+
class="space-card"
|
| 702 |
+
onclick={() => onadd?.(template)}
|
| 703 |
+
ondragstart={(e) => {
|
| 704 |
+
e.dataTransfer!.setData(
|
| 705 |
+
"node-template",
|
| 706 |
+
JSON.stringify(template)
|
| 707 |
+
);
|
| 708 |
+
const ghost = document.createElement("div");
|
| 709 |
+
ghost.textContent = model.id;
|
| 710 |
+
ghost.style.cssText = `background:${PORT_COLOR[pt]};color:#0c0d10;padding:4px 10px;border-radius:5px;font-family:Manrope,sans-serif;font-size:11px;font-weight:600;position:fixed;top:-100px`;
|
| 711 |
+
document.body.appendChild(ghost);
|
| 712 |
+
e.dataTransfer!.setDragImage(ghost, 0, 0);
|
| 713 |
+
setTimeout(() => document.body.removeChild(ghost), 0);
|
| 714 |
+
}}
|
| 715 |
+
>
|
| 716 |
+
<div class="space-card-header">
|
| 717 |
+
<span
|
| 718 |
+
class="chip-dot"
|
| 719 |
+
style="background: {PORT_COLOR[
|
| 720 |
+
pt
|
| 721 |
+
]}; box-shadow: 0 0 6px {PORT_COLOR[pt]}40"
|
| 722 |
+
></span>
|
| 723 |
+
<span class="space-card-name"
|
| 724 |
+
>{model.id.split("/").pop()}</span
|
| 725 |
+
>
|
| 726 |
+
<span class="space-card-likes">♥ {model.likes}</span>
|
| 727 |
+
</div>
|
| 728 |
+
<div class="space-card-id">{model.id}</div>
|
| 729 |
+
<div class="space-card-desc">{model.pipeline_tag}</div>
|
| 730 |
+
</div>
|
| 731 |
+
{/each}
|
| 732 |
+
{#if modelSearchResults.length === 0}
|
| 733 |
+
<div class="trending-status">
|
| 734 |
+
<span class="trending-status-text">No models found</span>
|
| 735 |
+
</div>
|
| 736 |
+
{/if}
|
| 737 |
+
{:else if trendingModelsLoading}
|
| 738 |
+
<div class="trending-status">
|
| 739 |
+
<span class="space-loading-spinner"></span>
|
| 740 |
+
<span class="trending-status-text"
|
| 741 |
+
>Loading trending models...</span
|
| 742 |
+
>
|
| 743 |
+
</div>
|
| 744 |
+
{:else}
|
| 745 |
+
{#each MODEL_TASKS.slice(0, 6) as task}
|
| 746 |
+
{@const models = getModelsForTask(task.key)}
|
| 747 |
+
{#if models.length > 0}
|
| 748 |
+
<div class="category-header">
|
| 749 |
+
<span class="category-label">{task.label}</span>
|
| 750 |
+
<span class="category-count">{models.length}</span>
|
| 751 |
+
</div>
|
| 752 |
+
{#each models.slice(0, 3) as model}
|
| 753 |
+
{@const template = modelToTemplate(model)}
|
| 754 |
+
{@const pt =
|
| 755 |
+
template.outputs[0]?.type ??
|
| 756 |
+
template.inputs[0]?.type ??
|
| 757 |
+
"any"}
|
| 758 |
+
<div
|
| 759 |
+
draggable="true"
|
| 760 |
+
class="space-card"
|
| 761 |
+
onclick={() => onadd?.(template)}
|
| 762 |
+
ondragstart={(e) => {
|
| 763 |
+
e.dataTransfer!.setData(
|
| 764 |
+
"node-template",
|
| 765 |
+
JSON.stringify(template)
|
| 766 |
+
);
|
| 767 |
+
}}
|
| 768 |
+
>
|
| 769 |
+
<div class="space-card-header">
|
| 770 |
+
<span
|
| 771 |
+
class="chip-dot"
|
| 772 |
+
style="background: {PORT_COLOR[
|
| 773 |
+
pt
|
| 774 |
+
]}; box-shadow: 0 0 6px {PORT_COLOR[pt]}40"
|
| 775 |
+
></span>
|
| 776 |
+
<span class="space-card-name"
|
| 777 |
+
>{model.id.split("/").pop()}</span
|
| 778 |
+
>
|
| 779 |
+
<span class="space-card-likes"
|
| 780 |
+
>♥ {model.likes}</span
|
| 781 |
+
>
|
| 782 |
+
</div>
|
| 783 |
+
<div class="space-card-id">{model.id}</div>
|
| 784 |
+
</div>
|
| 785 |
+
{/each}
|
| 786 |
+
{/if}
|
| 787 |
+
{/each}
|
| 788 |
+
{/if}
|
| 789 |
+
{:else if section.key === "datasets"}
|
| 790 |
+
<div class="add-space-wrapper">
|
| 791 |
+
<div class="add-space">
|
| 792 |
+
<input
|
| 793 |
+
class="space-input"
|
| 794 |
+
type="text"
|
| 795 |
+
placeholder="Search datasets..."
|
| 796 |
+
value={datasetSearchQuery}
|
| 797 |
+
disabled={loadingDataset}
|
| 798 |
+
oninput={handleDatasetSearch}
|
| 799 |
+
onkeydown={(e) => {
|
| 800 |
+
if (e.key === "Enter" && datasetSearchQuery.includes("/")) {
|
| 801 |
+
datasetSearchResults = [];
|
| 802 |
+
addDataset(datasetSearchQuery.trim());
|
| 803 |
+
}
|
| 804 |
+
if (e.key === "Escape") datasetSearchResults = [];
|
| 805 |
+
}}
|
| 806 |
+
/>
|
| 807 |
+
</div>
|
| 808 |
+
{#if datasetSearchResults.length > 0}
|
| 809 |
+
<div class="search-dropdown">
|
| 810 |
+
{#each datasetSearchResults as result}
|
| 811 |
+
<button
|
| 812 |
+
class="search-result"
|
| 813 |
+
onclick={() => {
|
| 814 |
+
const id = result.id;
|
| 815 |
+
datasetSearchResults = [];
|
| 816 |
+
datasetSearchQuery = "";
|
| 817 |
+
addDataset(id);
|
| 818 |
+
}}
|
| 819 |
+
>
|
| 820 |
+
<div class="search-result-top">
|
| 821 |
+
<span class="search-result-name">{result.id}</span>
|
| 822 |
+
<span class="search-result-likes"
|
| 823 |
+
>♥ {result.likes}</span
|
| 824 |
+
>
|
| 825 |
+
</div>
|
| 826 |
+
{#if result.description}
|
| 827 |
+
<div class="search-result-desc">
|
| 828 |
+
{result.description}
|
| 829 |
+
</div>
|
| 830 |
+
{/if}
|
| 831 |
+
</button>
|
| 832 |
+
{/each}
|
| 833 |
+
</div>
|
| 834 |
+
{:else if datasetSearching}
|
| 835 |
+
<div class="search-dropdown">
|
| 836 |
+
<div class="search-searching">Searching...</div>
|
| 837 |
+
</div>
|
| 838 |
+
{/if}
|
| 839 |
+
</div>
|
| 840 |
+
{#if loadingDataset}
|
| 841 |
+
<div class="space-loading">
|
| 842 |
+
<span class="space-loading-spinner"></span>
|
| 843 |
+
<span class="space-loading-text"
|
| 844 |
+
>Loading {loadingDatasetName}...</span
|
| 845 |
+
>
|
| 846 |
+
</div>
|
| 847 |
+
{/if}
|
| 848 |
+
{#if datasetError}
|
| 849 |
+
<span class="space-error">{datasetError}</span>
|
| 850 |
+
{/if}
|
| 851 |
+
<div class="trending-status">
|
| 852 |
+
<span class="trending-status-text"
|
| 853 |
+
>Search for a dataset by name</span
|
| 854 |
+
>
|
| 855 |
+
</div>
|
| 856 |
+
{:else}
|
| 857 |
+
{#each section.items as item}
|
| 858 |
+
{@const pt = primaryType(item)}
|
| 859 |
+
<div
|
| 860 |
+
draggable="true"
|
| 861 |
+
class="chip"
|
| 862 |
+
onclick={() => onadd?.(item)}
|
| 863 |
+
ondragstart={(e) => {
|
| 864 |
+
e.dataTransfer!.setData(
|
| 865 |
+
"node-template",
|
| 866 |
+
JSON.stringify(item)
|
| 867 |
+
);
|
| 868 |
+
const ghost = document.createElement("div");
|
| 869 |
+
ghost.textContent = item.label;
|
| 870 |
+
ghost.style.cssText = `background:${PORT_COLOR[pt]};color:#0c0d10;padding:4px 10px;border-radius:5px;font-family:Manrope,sans-serif;font-size:11px;font-weight:600;position:fixed;top:-100px`;
|
| 871 |
+
document.body.appendChild(ghost);
|
| 872 |
+
e.dataTransfer!.setDragImage(ghost, 0, 0);
|
| 873 |
+
setTimeout(() => document.body.removeChild(ghost), 0);
|
| 874 |
+
}}
|
| 875 |
+
>
|
| 876 |
+
<span
|
| 877 |
+
class="chip-dot"
|
| 878 |
+
style="background: {PORT_COLOR[
|
| 879 |
+
pt
|
| 880 |
+
]}; box-shadow: 0 0 6px {PORT_COLOR[pt]}40"
|
| 881 |
+
></span>
|
| 882 |
+
<span class="chip-label">{item.label}</span>
|
| 883 |
+
</div>
|
| 884 |
+
{/each}
|
| 885 |
+
{/if}
|
| 886 |
+
|
| 887 |
+
{#if section.key === "spaces"}
|
| 888 |
+
{#each customSpaces as item, i}
|
| 889 |
+
{@const pt = primaryType(item)}
|
| 890 |
+
<div
|
| 891 |
+
draggable="true"
|
| 892 |
+
class="chip"
|
| 893 |
+
onclick={() => onadd?.(item)}
|
| 894 |
+
ondragstart={(e) =>
|
| 895 |
+
e.dataTransfer!.setData(
|
| 896 |
+
"node-template",
|
| 897 |
+
JSON.stringify(item)
|
| 898 |
+
)}
|
| 899 |
+
>
|
| 900 |
+
<span
|
| 901 |
+
class="chip-dot"
|
| 902 |
+
style="background: {PORT_COLOR[
|
| 903 |
+
pt
|
| 904 |
+
]}; box-shadow: 0 0 6px {PORT_COLOR[pt]}40"
|
| 905 |
+
></span>
|
| 906 |
+
<span class="chip-label">{item.label}</span>
|
| 907 |
+
{#if item.space_id}
|
| 908 |
+
<a
|
| 909 |
+
class="chip-link"
|
| 910 |
+
href="https://huggingface.co/spaces/{item.space_id}"
|
| 911 |
+
target="_blank"
|
| 912 |
+
rel="noopener"
|
| 913 |
+
onclick={(e) => e.stopPropagation()}
|
| 914 |
+
title="Open on HuggingFace">↗</a
|
| 915 |
+
>
|
| 916 |
+
{/if}
|
| 917 |
+
<button
|
| 918 |
+
class="chip-remove"
|
| 919 |
+
onclick={(e) => {
|
| 920 |
+
e.stopPropagation();
|
| 921 |
+
customSpaces = customSpaces.filter((_, j) => j !== i);
|
| 922 |
+
}}
|
| 923 |
+
title="Remove">×</button
|
| 924 |
+
>
|
| 925 |
+
</div>
|
| 926 |
+
{/each}
|
| 927 |
+
<div class="add-space-wrapper">
|
| 928 |
+
<div class="add-space">
|
| 929 |
+
<input
|
| 930 |
+
class="space-input"
|
| 931 |
+
type="text"
|
| 932 |
+
placeholder="Search Spaces..."
|
| 933 |
+
value={customSpaceInput}
|
| 934 |
+
disabled={loadingSpace}
|
| 935 |
+
oninput={handleSearchInput}
|
| 936 |
+
onkeydown={(e) => {
|
| 937 |
+
if (e.key === "Enter" && customSpaceInput.includes("/")) {
|
| 938 |
+
searchResults = [];
|
| 939 |
+
addCustomSpace();
|
| 940 |
+
}
|
| 941 |
+
if (e.key === "Escape") searchResults = [];
|
| 942 |
+
}}
|
| 943 |
+
/>
|
| 944 |
+
<button
|
| 945 |
+
class="space-add-btn"
|
| 946 |
+
onclick={() => {
|
| 947 |
+
searchResults = [];
|
| 948 |
+
addCustomSpace();
|
| 949 |
+
}}
|
| 950 |
+
disabled={loadingSpace ||
|
| 951 |
+
!customSpaceInput.trim().includes("/")}
|
| 952 |
+
>{loadingSpace ? "..." : "+"}</button
|
| 953 |
+
>
|
| 954 |
+
</div>
|
| 955 |
+
{#if searchResults.length > 0}
|
| 956 |
+
<div class="search-dropdown">
|
| 957 |
+
{#each searchResults as result}
|
| 958 |
+
<button
|
| 959 |
+
class="search-result"
|
| 960 |
+
onclick={() => selectSearchResult(result.id)}
|
| 961 |
+
>
|
| 962 |
+
<div class="search-result-top">
|
| 963 |
+
<span
|
| 964 |
+
class="search-result-status"
|
| 965 |
+
class:search-result-running={result.running}
|
| 966 |
+
title={result.running ? "Running" : "Not running"}
|
| 967 |
+
></span>
|
| 968 |
+
<span class="search-result-name">{result.id}</span>
|
| 969 |
+
<span class="search-result-likes"
|
| 970 |
+
>♥ {result.likes}</span
|
| 971 |
+
>
|
| 972 |
+
<a
|
| 973 |
+
class="search-result-link"
|
| 974 |
+
href="https://huggingface.co/spaces/{result.id}"
|
| 975 |
+
target="_blank"
|
| 976 |
+
rel="noopener"
|
| 977 |
+
onclick={(e) => e.stopPropagation()}
|
| 978 |
+
title="Open on HuggingFace">↗</a
|
| 979 |
+
>
|
| 980 |
+
</div>
|
| 981 |
+
{#if result.description}
|
| 982 |
+
<div class="search-result-desc">
|
| 983 |
+
{result.description}
|
| 984 |
+
</div>
|
| 985 |
+
{/if}
|
| 986 |
+
</button>
|
| 987 |
+
{/each}
|
| 988 |
+
</div>
|
| 989 |
+
{:else if searching}
|
| 990 |
+
<div class="search-dropdown">
|
| 991 |
+
<div class="search-searching">Searching...</div>
|
| 992 |
+
</div>
|
| 993 |
+
{/if}
|
| 994 |
+
</div>
|
| 995 |
+
{#if loadingSpace}
|
| 996 |
+
<div class="space-loading">
|
| 997 |
+
<span class="space-loading-spinner"></span>
|
| 998 |
+
<span class="space-loading-text"
|
| 999 |
+
>Connecting to {loadingSpaceName}...</span
|
| 1000 |
+
>
|
| 1001 |
+
</div>
|
| 1002 |
+
{/if}
|
| 1003 |
+
{#if spaceError}
|
| 1004 |
+
<span class="space-error">{spaceError}</span>
|
| 1005 |
+
{/if}
|
| 1006 |
+
{/if}
|
| 1007 |
+
</div>
|
| 1008 |
+
{/if}
|
| 1009 |
+
{/each}
|
| 1010 |
+
|
| 1011 |
+
<div class="sidebar-footer">
|
| 1012 |
+
<span class="hint">Drag to canvas</span>
|
| 1013 |
+
</div>
|
| 1014 |
+
{/if}
|
| 1015 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 1016 |
+
{#if !collapsed}
|
| 1017 |
+
<div class="resize-handle" onmousedown={startResize}></div>
|
| 1018 |
+
{/if}
|
| 1019 |
+
</aside>
|
| 1020 |
+
|
| 1021 |
+
<style>
|
| 1022 |
+
.sidebar {
|
| 1023 |
+
position: relative;
|
| 1024 |
+
display: flex;
|
| 1025 |
+
flex-direction: column;
|
| 1026 |
+
background: #101118;
|
| 1027 |
+
border-right: 1px solid #1e1f2a;
|
| 1028 |
+
overflow-y: auto;
|
| 1029 |
+
font-family: "Manrope", sans-serif;
|
| 1030 |
+
color-scheme: dark;
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
.sidebar-collapsed {
|
| 1034 |
+
width: 40px;
|
| 1035 |
+
min-width: 40px;
|
| 1036 |
+
}
|
| 1037 |
+
|
| 1038 |
+
.sidebar-collapse-btn {
|
| 1039 |
+
display: flex;
|
| 1040 |
+
align-items: center;
|
| 1041 |
+
justify-content: center;
|
| 1042 |
+
width: 24px;
|
| 1043 |
+
height: 24px;
|
| 1044 |
+
border: none;
|
| 1045 |
+
border-radius: 4px;
|
| 1046 |
+
background: transparent;
|
| 1047 |
+
color: #5c5e6a;
|
| 1048 |
+
cursor: pointer;
|
| 1049 |
+
flex-shrink: 0;
|
| 1050 |
+
padding: 0;
|
| 1051 |
+
line-height: 1;
|
| 1052 |
+
transition:
|
| 1053 |
+
color 0.15s,
|
| 1054 |
+
background 0.15s,
|
| 1055 |
+
transform 0.2s ease;
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
.sidebar-collapse-btn:hover {
|
| 1059 |
+
background: #1e1f2a;
|
| 1060 |
+
color: #a0a2ae;
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
.sidebar-collapse-btn.collapsed {
|
| 1064 |
+
transform: rotate(180deg);
|
| 1065 |
+
}
|
| 1066 |
+
|
| 1067 |
+
.sidebar-header {
|
| 1068 |
+
display: flex;
|
| 1069 |
+
align-items: center;
|
| 1070 |
+
gap: 6px;
|
| 1071 |
+
padding: 12px 12px 10px;
|
| 1072 |
+
border-bottom: 1px solid #1e1f2a;
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
.sidebar-collapsed .sidebar-header {
|
| 1076 |
+
justify-content: center;
|
| 1077 |
+
padding: 14px 8px 10px;
|
| 1078 |
+
}
|
| 1079 |
+
|
| 1080 |
+
.section-toggle {
|
| 1081 |
+
display: flex;
|
| 1082 |
+
align-items: center;
|
| 1083 |
+
width: 100%;
|
| 1084 |
+
padding: 10px 16px;
|
| 1085 |
+
border: none;
|
| 1086 |
+
background: transparent;
|
| 1087 |
+
cursor: pointer;
|
| 1088 |
+
transition: background 0.15s;
|
| 1089 |
+
}
|
| 1090 |
+
|
| 1091 |
+
.section-toggle:hover {
|
| 1092 |
+
background: #16171f;
|
| 1093 |
+
}
|
| 1094 |
+
|
| 1095 |
+
.section-label {
|
| 1096 |
+
font-size: 12px;
|
| 1097 |
+
font-weight: 600;
|
| 1098 |
+
color: #a0a2ae;
|
| 1099 |
+
flex: 1;
|
| 1100 |
+
text-align: left;
|
| 1101 |
+
}
|
| 1102 |
+
|
| 1103 |
+
.section-count {
|
| 1104 |
+
font-family: "JetBrains Mono", monospace;
|
| 1105 |
+
font-size: 10px;
|
| 1106 |
+
color: #3e3f4d;
|
| 1107 |
+
margin-right: 6px;
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
.section-chevron {
|
| 1111 |
+
display: inline-flex;
|
| 1112 |
+
color: #5c5e6a;
|
| 1113 |
+
flex-shrink: 0;
|
| 1114 |
+
transition: transform 0.2s ease;
|
| 1115 |
+
transform: rotate(-90deg);
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
.section-chevron.expanded {
|
| 1119 |
+
transform: rotate(0deg);
|
| 1120 |
+
}
|
| 1121 |
+
|
| 1122 |
+
.section-items {
|
| 1123 |
+
padding: 2px 8px 8px;
|
| 1124 |
+
}
|
| 1125 |
+
|
| 1126 |
+
.chip {
|
| 1127 |
+
display: flex;
|
| 1128 |
+
align-items: center;
|
| 1129 |
+
gap: 8px;
|
| 1130 |
+
padding: 7px 10px;
|
| 1131 |
+
margin-bottom: 2px;
|
| 1132 |
+
border-radius: 6px;
|
| 1133 |
+
cursor: pointer;
|
| 1134 |
+
transition:
|
| 1135 |
+
background 0.15s,
|
| 1136 |
+
transform 0.1s;
|
| 1137 |
+
background: transparent;
|
| 1138 |
+
}
|
| 1139 |
+
|
| 1140 |
+
.chip:hover {
|
| 1141 |
+
background: #1a1b25;
|
| 1142 |
+
}
|
| 1143 |
+
|
| 1144 |
+
.chip:active {
|
| 1145 |
+
cursor: grabbing;
|
| 1146 |
+
transform: scale(0.98);
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
+
.chip-dot {
|
| 1150 |
+
width: 7px;
|
| 1151 |
+
height: 7px;
|
| 1152 |
+
border-radius: 50%;
|
| 1153 |
+
flex-shrink: 0;
|
| 1154 |
+
}
|
| 1155 |
+
|
| 1156 |
+
.category-header {
|
| 1157 |
+
display: flex;
|
| 1158 |
+
align-items: center;
|
| 1159 |
+
gap: 6px;
|
| 1160 |
+
padding: 8px 10px 4px;
|
| 1161 |
+
margin-top: 4px;
|
| 1162 |
+
}
|
| 1163 |
+
|
| 1164 |
+
.category-header:first-child {
|
| 1165 |
+
margin-top: 0;
|
| 1166 |
+
}
|
| 1167 |
+
|
| 1168 |
+
.category-label {
|
| 1169 |
+
font-size: 10px;
|
| 1170 |
+
font-weight: 700;
|
| 1171 |
+
text-transform: uppercase;
|
| 1172 |
+
letter-spacing: 0.06em;
|
| 1173 |
+
color: #5c5e6a;
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
.category-count {
|
| 1177 |
+
font-family: "JetBrains Mono", monospace;
|
| 1178 |
+
font-size: 9px;
|
| 1179 |
+
color: #3e3f4d;
|
| 1180 |
+
}
|
| 1181 |
+
|
| 1182 |
+
/* Trending space cards */
|
| 1183 |
+
.space-card {
|
| 1184 |
+
display: flex;
|
| 1185 |
+
flex-direction: column;
|
| 1186 |
+
padding: 8px 10px;
|
| 1187 |
+
margin-bottom: 2px;
|
| 1188 |
+
border-radius: 6px;
|
| 1189 |
+
cursor: pointer;
|
| 1190 |
+
transition:
|
| 1191 |
+
background 0.15s,
|
| 1192 |
+
transform 0.1s;
|
| 1193 |
+
background: transparent;
|
| 1194 |
+
}
|
| 1195 |
+
|
| 1196 |
+
.space-card:hover {
|
| 1197 |
+
background: #1a1b25;
|
| 1198 |
+
}
|
| 1199 |
+
|
| 1200 |
+
.space-card:active {
|
| 1201 |
+
cursor: grabbing;
|
| 1202 |
+
transform: scale(0.98);
|
| 1203 |
+
}
|
| 1204 |
+
|
| 1205 |
+
.space-card-header {
|
| 1206 |
+
display: flex;
|
| 1207 |
+
align-items: center;
|
| 1208 |
+
gap: 6px;
|
| 1209 |
+
width: 100%;
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
+
.space-card-status {
|
| 1213 |
+
width: 6px;
|
| 1214 |
+
height: 6px;
|
| 1215 |
+
border-radius: 50%;
|
| 1216 |
+
background: #5c5e6a;
|
| 1217 |
+
flex-shrink: 0;
|
| 1218 |
+
}
|
| 1219 |
+
|
| 1220 |
+
.space-card-running {
|
| 1221 |
+
background: #34d399;
|
| 1222 |
+
box-shadow: 0 0 4px #34d39960;
|
| 1223 |
+
}
|
| 1224 |
+
|
| 1225 |
+
.space-card-name {
|
| 1226 |
+
font-size: 12px;
|
| 1227 |
+
font-weight: 600;
|
| 1228 |
+
color: #c8c9d2;
|
| 1229 |
+
flex: 1;
|
| 1230 |
+
overflow: hidden;
|
| 1231 |
+
text-overflow: ellipsis;
|
| 1232 |
+
white-space: nowrap;
|
| 1233 |
+
}
|
| 1234 |
+
|
| 1235 |
+
.space-card-likes {
|
| 1236 |
+
font-family: "JetBrains Mono", monospace;
|
| 1237 |
+
font-size: 9px;
|
| 1238 |
+
color: #5c5e6a;
|
| 1239 |
+
flex-shrink: 0;
|
| 1240 |
+
}
|
| 1241 |
+
|
| 1242 |
+
.space-card-link {
|
| 1243 |
+
visibility: hidden;
|
| 1244 |
+
font-size: 11px;
|
| 1245 |
+
color: #5c5e6a;
|
| 1246 |
+
text-decoration: none;
|
| 1247 |
+
flex-shrink: 0;
|
| 1248 |
+
padding: 2px;
|
| 1249 |
+
border-radius: 3px;
|
| 1250 |
+
transition: color 0.15s;
|
| 1251 |
+
}
|
| 1252 |
+
|
| 1253 |
+
.space-card:hover .space-card-link {
|
| 1254 |
+
visibility: visible;
|
| 1255 |
+
}
|
| 1256 |
+
|
| 1257 |
+
.space-card-link:hover {
|
| 1258 |
+
color: #c8c9d2;
|
| 1259 |
+
}
|
| 1260 |
+
|
| 1261 |
+
.space-card-id {
|
| 1262 |
+
font-family: "JetBrains Mono", monospace;
|
| 1263 |
+
font-size: 9px;
|
| 1264 |
+
color: #3e3f4d;
|
| 1265 |
+
padding-left: 12px;
|
| 1266 |
+
margin-top: 1px;
|
| 1267 |
+
overflow: hidden;
|
| 1268 |
+
text-overflow: ellipsis;
|
| 1269 |
+
white-space: nowrap;
|
| 1270 |
+
}
|
| 1271 |
+
|
| 1272 |
+
.space-card-desc {
|
| 1273 |
+
font-size: 10px;
|
| 1274 |
+
color: #5c5e6a;
|
| 1275 |
+
padding-left: 12px;
|
| 1276 |
+
margin-top: 2px;
|
| 1277 |
+
overflow: hidden;
|
| 1278 |
+
text-overflow: ellipsis;
|
| 1279 |
+
white-space: nowrap;
|
| 1280 |
+
line-height: 1.3;
|
| 1281 |
+
}
|
| 1282 |
+
|
| 1283 |
+
.trending-status {
|
| 1284 |
+
display: flex;
|
| 1285 |
+
align-items: center;
|
| 1286 |
+
gap: 8px;
|
| 1287 |
+
padding: 8px 12px;
|
| 1288 |
+
}
|
| 1289 |
+
|
| 1290 |
+
.trending-status-text {
|
| 1291 |
+
font-family: "JetBrains Mono", monospace;
|
| 1292 |
+
font-size: 9.5px;
|
| 1293 |
+
color: #5c5e6a;
|
| 1294 |
+
}
|
| 1295 |
+
|
| 1296 |
+
.chip-label {
|
| 1297 |
+
font-size: 12.5px;
|
| 1298 |
+
font-weight: 500;
|
| 1299 |
+
color: #c8c9d2;
|
| 1300 |
+
flex: 1;
|
| 1301 |
+
white-space: nowrap;
|
| 1302 |
+
overflow: hidden;
|
| 1303 |
+
text-overflow: ellipsis;
|
| 1304 |
+
}
|
| 1305 |
+
|
| 1306 |
+
.chip-link {
|
| 1307 |
+
visibility: hidden;
|
| 1308 |
+
font-size: 11px;
|
| 1309 |
+
color: #5c5e6a;
|
| 1310 |
+
text-decoration: none;
|
| 1311 |
+
flex-shrink: 0;
|
| 1312 |
+
line-height: 1;
|
| 1313 |
+
padding: 2px;
|
| 1314 |
+
border-radius: 3px;
|
| 1315 |
+
transition: color 0.15s;
|
| 1316 |
+
}
|
| 1317 |
+
|
| 1318 |
+
.chip:hover .chip-link {
|
| 1319 |
+
visibility: visible;
|
| 1320 |
+
}
|
| 1321 |
+
|
| 1322 |
+
.chip-link:hover {
|
| 1323 |
+
color: #c8c9d2;
|
| 1324 |
+
}
|
| 1325 |
+
|
| 1326 |
+
.chip-remove {
|
| 1327 |
+
visibility: hidden;
|
| 1328 |
+
display: flex;
|
| 1329 |
+
width: 16px;
|
| 1330 |
+
height: 16px;
|
| 1331 |
+
border: none;
|
| 1332 |
+
border-radius: 3px;
|
| 1333 |
+
background: transparent;
|
| 1334 |
+
color: #5c5e6a;
|
| 1335 |
+
font-size: 12px;
|
| 1336 |
+
line-height: 1;
|
| 1337 |
+
cursor: pointer;
|
| 1338 |
+
align-items: center;
|
| 1339 |
+
justify-content: center;
|
| 1340 |
+
padding: 0;
|
| 1341 |
+
flex-shrink: 0;
|
| 1342 |
+
}
|
| 1343 |
+
|
| 1344 |
+
.chip:hover .chip-remove {
|
| 1345 |
+
visibility: visible;
|
| 1346 |
+
}
|
| 1347 |
+
|
| 1348 |
+
.chip-remove:hover {
|
| 1349 |
+
color: #ef4444;
|
| 1350 |
+
background: rgba(239, 68, 68, 0.15);
|
| 1351 |
+
}
|
| 1352 |
+
|
| 1353 |
+
.chip-badge {
|
| 1354 |
+
font-family: "JetBrains Mono", monospace;
|
| 1355 |
+
font-size: 9px;
|
| 1356 |
+
font-weight: 700;
|
| 1357 |
+
letter-spacing: 0.04em;
|
| 1358 |
+
padding: 1px 5px;
|
| 1359 |
+
border-radius: 3px;
|
| 1360 |
+
background: #1e1f2a;
|
| 1361 |
+
color: #5c5e6a;
|
| 1362 |
+
}
|
| 1363 |
+
|
| 1364 |
+
.add-space {
|
| 1365 |
+
display: flex;
|
| 1366 |
+
gap: 4px;
|
| 1367 |
+
padding: 6px 4px 2px;
|
| 1368 |
+
}
|
| 1369 |
+
|
| 1370 |
+
.space-input {
|
| 1371 |
+
flex: 1;
|
| 1372 |
+
font-family: "JetBrains Mono", monospace;
|
| 1373 |
+
font-size: 10.5px;
|
| 1374 |
+
height: 28px;
|
| 1375 |
+
padding: 0 8px;
|
| 1376 |
+
border: 1px solid #1e1f2a;
|
| 1377 |
+
border-radius: 5px;
|
| 1378 |
+
background: #0c0d10;
|
| 1379 |
+
color: #c8c9d2;
|
| 1380 |
+
outline: none;
|
| 1381 |
+
min-width: 0;
|
| 1382 |
+
box-sizing: border-box;
|
| 1383 |
+
}
|
| 1384 |
+
|
| 1385 |
+
.space-input::placeholder {
|
| 1386 |
+
color: #5c5e6a;
|
| 1387 |
+
}
|
| 1388 |
+
|
| 1389 |
+
.space-input:focus {
|
| 1390 |
+
border-color: #3e3f4d;
|
| 1391 |
+
}
|
| 1392 |
+
|
| 1393 |
+
.space-add-btn {
|
| 1394 |
+
width: 28px;
|
| 1395 |
+
height: 28px;
|
| 1396 |
+
border: 1px solid #3e3f4d;
|
| 1397 |
+
border-radius: 5px;
|
| 1398 |
+
background: #1a1b25;
|
| 1399 |
+
color: #a0a2ae;
|
| 1400 |
+
font-size: 14px;
|
| 1401 |
+
font-weight: 600;
|
| 1402 |
+
cursor: pointer;
|
| 1403 |
+
display: flex;
|
| 1404 |
+
align-items: center;
|
| 1405 |
+
justify-content: center;
|
| 1406 |
+
transition:
|
| 1407 |
+
background 0.15s,
|
| 1408 |
+
color 0.15s,
|
| 1409 |
+
border-color 0.15s;
|
| 1410 |
+
flex-shrink: 0;
|
| 1411 |
+
}
|
| 1412 |
+
|
| 1413 |
+
.space-add-btn:hover:not(:disabled) {
|
| 1414 |
+
background: #2a2b36;
|
| 1415 |
+
color: #f97316;
|
| 1416 |
+
border-color: #f97316;
|
| 1417 |
+
}
|
| 1418 |
+
|
| 1419 |
+
.space-add-btn:disabled {
|
| 1420 |
+
opacity: 0.35;
|
| 1421 |
+
cursor: default;
|
| 1422 |
+
background: #101118;
|
| 1423 |
+
color: #3e3f4d;
|
| 1424 |
+
border-color: #1e1f2a;
|
| 1425 |
+
}
|
| 1426 |
+
|
| 1427 |
+
.add-space-wrapper {
|
| 1428 |
+
position: relative;
|
| 1429 |
+
}
|
| 1430 |
+
|
| 1431 |
+
.search-dropdown {
|
| 1432 |
+
position: absolute;
|
| 1433 |
+
top: 100%;
|
| 1434 |
+
left: 4px;
|
| 1435 |
+
right: 4px;
|
| 1436 |
+
background: #16171f;
|
| 1437 |
+
border: 1px solid #2a2b36;
|
| 1438 |
+
border-radius: 6px;
|
| 1439 |
+
margin-top: 2px;
|
| 1440 |
+
overflow: hidden;
|
| 1441 |
+
z-index: 10;
|
| 1442 |
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
|
| 1443 |
+
}
|
| 1444 |
+
|
| 1445 |
+
.search-result {
|
| 1446 |
+
display: flex;
|
| 1447 |
+
flex-direction: column;
|
| 1448 |
+
width: 100%;
|
| 1449 |
+
padding: 7px 10px;
|
| 1450 |
+
border: none;
|
| 1451 |
+
border-bottom: 1px solid #1e1f2a;
|
| 1452 |
+
background: transparent;
|
| 1453 |
+
color: #c8c9d2;
|
| 1454 |
+
cursor: pointer;
|
| 1455 |
+
text-align: left;
|
| 1456 |
+
transition: background 0.1s;
|
| 1457 |
+
}
|
| 1458 |
+
|
| 1459 |
+
.search-result:last-child {
|
| 1460 |
+
border-bottom: none;
|
| 1461 |
+
}
|
| 1462 |
+
|
| 1463 |
+
.search-result:hover {
|
| 1464 |
+
background: #1a1b25;
|
| 1465 |
+
}
|
| 1466 |
+
|
| 1467 |
+
.search-result-top {
|
| 1468 |
+
display: flex;
|
| 1469 |
+
align-items: center;
|
| 1470 |
+
gap: 6px;
|
| 1471 |
+
width: 100%;
|
| 1472 |
+
}
|
| 1473 |
+
|
| 1474 |
+
.search-result-status {
|
| 1475 |
+
width: 6px;
|
| 1476 |
+
height: 6px;
|
| 1477 |
+
border-radius: 50%;
|
| 1478 |
+
background: #5c5e6a;
|
| 1479 |
+
flex-shrink: 0;
|
| 1480 |
+
}
|
| 1481 |
+
|
| 1482 |
+
.search-result-running {
|
| 1483 |
+
background: #34d399;
|
| 1484 |
+
box-shadow: 0 0 4px #34d39960;
|
| 1485 |
+
}
|
| 1486 |
+
|
| 1487 |
+
.search-result-name {
|
| 1488 |
+
font-family: "JetBrains Mono", monospace;
|
| 1489 |
+
font-size: 10px;
|
| 1490 |
+
flex: 1;
|
| 1491 |
+
overflow: hidden;
|
| 1492 |
+
text-overflow: ellipsis;
|
| 1493 |
+
white-space: nowrap;
|
| 1494 |
+
}
|
| 1495 |
+
|
| 1496 |
+
.search-result-desc {
|
| 1497 |
+
font-size: 9.5px;
|
| 1498 |
+
color: #5c5e6a;
|
| 1499 |
+
margin-top: 2px;
|
| 1500 |
+
padding-left: 12px;
|
| 1501 |
+
overflow: hidden;
|
| 1502 |
+
text-overflow: ellipsis;
|
| 1503 |
+
white-space: nowrap;
|
| 1504 |
+
}
|
| 1505 |
+
|
| 1506 |
+
.search-result-likes {
|
| 1507 |
+
font-family: "JetBrains Mono", monospace;
|
| 1508 |
+
font-size: 9px;
|
| 1509 |
+
color: #5c5e6a;
|
| 1510 |
+
flex-shrink: 0;
|
| 1511 |
+
}
|
| 1512 |
+
|
| 1513 |
+
.search-result-link {
|
| 1514 |
+
font-size: 11px;
|
| 1515 |
+
color: #5c5e6a;
|
| 1516 |
+
text-decoration: none;
|
| 1517 |
+
flex-shrink: 0;
|
| 1518 |
+
padding: 2px;
|
| 1519 |
+
border-radius: 3px;
|
| 1520 |
+
transition: color 0.15s;
|
| 1521 |
+
}
|
| 1522 |
+
|
| 1523 |
+
.search-result-link:hover {
|
| 1524 |
+
color: #c8c9d2;
|
| 1525 |
+
}
|
| 1526 |
+
|
| 1527 |
+
.search-searching {
|
| 1528 |
+
font-family: "JetBrains Mono", monospace;
|
| 1529 |
+
font-size: 9.5px;
|
| 1530 |
+
color: #5c5e6a;
|
| 1531 |
+
padding: 8px 10px;
|
| 1532 |
+
text-align: center;
|
| 1533 |
+
}
|
| 1534 |
+
|
| 1535 |
+
.space-loading {
|
| 1536 |
+
display: flex;
|
| 1537 |
+
align-items: center;
|
| 1538 |
+
gap: 8px;
|
| 1539 |
+
padding: 6px 12px;
|
| 1540 |
+
}
|
| 1541 |
+
|
| 1542 |
+
.space-loading-spinner {
|
| 1543 |
+
width: 12px;
|
| 1544 |
+
height: 12px;
|
| 1545 |
+
border: 2px solid transparent;
|
| 1546 |
+
border-top-color: #f5a623;
|
| 1547 |
+
border-radius: 50%;
|
| 1548 |
+
animation: sidebar-spin 0.7s linear infinite;
|
| 1549 |
+
flex-shrink: 0;
|
| 1550 |
+
}
|
| 1551 |
+
|
| 1552 |
+
@keyframes sidebar-spin {
|
| 1553 |
+
to {
|
| 1554 |
+
transform: rotate(360deg);
|
| 1555 |
+
}
|
| 1556 |
+
}
|
| 1557 |
+
|
| 1558 |
+
.space-loading-text {
|
| 1559 |
+
font-family: "JetBrains Mono", monospace;
|
| 1560 |
+
font-size: 9.5px;
|
| 1561 |
+
color: #5c5e6a;
|
| 1562 |
+
white-space: nowrap;
|
| 1563 |
+
overflow: hidden;
|
| 1564 |
+
text-overflow: ellipsis;
|
| 1565 |
+
}
|
| 1566 |
+
|
| 1567 |
+
.space-error {
|
| 1568 |
+
display: block;
|
| 1569 |
+
font-family: "JetBrains Mono", monospace;
|
| 1570 |
+
font-size: 9px;
|
| 1571 |
+
color: #ef4444;
|
| 1572 |
+
padding: 2px 12px 4px;
|
| 1573 |
+
}
|
| 1574 |
+
|
| 1575 |
+
.sidebar-footer {
|
| 1576 |
+
margin-top: auto;
|
| 1577 |
+
padding: 12px 16px;
|
| 1578 |
+
border-top: 1px solid #1e1f2a;
|
| 1579 |
+
}
|
| 1580 |
+
|
| 1581 |
+
.resize-handle {
|
| 1582 |
+
position: absolute;
|
| 1583 |
+
top: 0;
|
| 1584 |
+
right: -3px;
|
| 1585 |
+
width: 6px;
|
| 1586 |
+
height: 100%;
|
| 1587 |
+
cursor: col-resize;
|
| 1588 |
+
z-index: 10;
|
| 1589 |
+
}
|
| 1590 |
+
|
| 1591 |
+
.resize-handle:hover {
|
| 1592 |
+
background: rgba(249, 115, 22, 0.3);
|
| 1593 |
+
}
|
| 1594 |
+
|
| 1595 |
+
.model-task-filters {
|
| 1596 |
+
display: flex;
|
| 1597 |
+
flex-wrap: wrap;
|
| 1598 |
+
gap: 4px;
|
| 1599 |
+
padding: 4px 4px 8px;
|
| 1600 |
+
}
|
| 1601 |
+
|
| 1602 |
+
.model-task-tag {
|
| 1603 |
+
font-family: "JetBrains Mono", monospace;
|
| 1604 |
+
font-size: 9px;
|
| 1605 |
+
padding: 3px 7px;
|
| 1606 |
+
border: 1px solid #1e1f2a;
|
| 1607 |
+
border-radius: 4px;
|
| 1608 |
+
background: transparent;
|
| 1609 |
+
color: #5c5e6a;
|
| 1610 |
+
cursor: pointer;
|
| 1611 |
+
transition: all 0.15s;
|
| 1612 |
+
}
|
| 1613 |
+
|
| 1614 |
+
.model-task-tag:hover {
|
| 1615 |
+
border-color: #3e3f4d;
|
| 1616 |
+
color: #a0a2ae;
|
| 1617 |
+
}
|
| 1618 |
+
|
| 1619 |
+
.model-task-tag-active {
|
| 1620 |
+
border-color: #f97316;
|
| 1621 |
+
color: #f97316;
|
| 1622 |
+
background: rgba(249, 115, 22, 0.1);
|
| 1623 |
+
}
|
| 1624 |
+
|
| 1625 |
+
.hint {
|
| 1626 |
+
font-family: "JetBrains Mono", monospace;
|
| 1627 |
+
font-size: 10px;
|
| 1628 |
+
color: #2e2f3d;
|
| 1629 |
+
letter-spacing: 0.02em;
|
| 1630 |
+
}
|
| 1631 |
+
|
| 1632 |
+
/* βββ Light mode βββ */
|
| 1633 |
+
:global(body:not(.dark)) .sidebar {
|
| 1634 |
+
background: #f8f9fb;
|
| 1635 |
+
border-right-color: #e2e4ea;
|
| 1636 |
+
color-scheme: light;
|
| 1637 |
+
}
|
| 1638 |
+
|
| 1639 |
+
:global(body:not(.dark)) .sidebar-header {
|
| 1640 |
+
border-bottom-color: #e2e4ea;
|
| 1641 |
+
}
|
| 1642 |
+
|
| 1643 |
+
:global(body:not(.dark)) .sidebar-collapse-btn {
|
| 1644 |
+
color: #9a9caa;
|
| 1645 |
+
}
|
| 1646 |
+
|
| 1647 |
+
:global(body:not(.dark)) .sidebar-collapse-btn:hover {
|
| 1648 |
+
background: #e8eaf0;
|
| 1649 |
+
color: #3e4050;
|
| 1650 |
+
}
|
| 1651 |
+
|
| 1652 |
+
:global(body:not(.dark)) .section-toggle:hover {
|
| 1653 |
+
background: #f0f1f5;
|
| 1654 |
+
}
|
| 1655 |
+
|
| 1656 |
+
:global(body:not(.dark)) .section-label {
|
| 1657 |
+
color: #6b6e78;
|
| 1658 |
+
}
|
| 1659 |
+
|
| 1660 |
+
:global(body:not(.dark)) .section-count {
|
| 1661 |
+
color: #b0b2bc;
|
| 1662 |
+
}
|
| 1663 |
+
|
| 1664 |
+
:global(body:not(.dark)) .section-chevron {
|
| 1665 |
+
color: #9a9caa;
|
| 1666 |
+
}
|
| 1667 |
+
|
| 1668 |
+
:global(body:not(.dark)) .chip:hover {
|
| 1669 |
+
background: #f0f1f5;
|
| 1670 |
+
}
|
| 1671 |
+
|
| 1672 |
+
:global(body:not(.dark)) .chip-label {
|
| 1673 |
+
color: #1a1b25;
|
| 1674 |
+
}
|
| 1675 |
+
|
| 1676 |
+
:global(body:not(.dark)) .chip-link {
|
| 1677 |
+
color: #9a9caa;
|
| 1678 |
+
}
|
| 1679 |
+
|
| 1680 |
+
:global(body:not(.dark)) .chip-link:hover {
|
| 1681 |
+
color: #1a1b25;
|
| 1682 |
+
}
|
| 1683 |
+
|
| 1684 |
+
:global(body:not(.dark)) .category-label {
|
| 1685 |
+
color: #9a9caa;
|
| 1686 |
+
}
|
| 1687 |
+
|
| 1688 |
+
:global(body:not(.dark)) .category-count {
|
| 1689 |
+
color: #b0b2bc;
|
| 1690 |
+
}
|
| 1691 |
+
|
| 1692 |
+
:global(body:not(.dark)) .space-card:hover {
|
| 1693 |
+
background: #f0f1f5;
|
| 1694 |
+
}
|
| 1695 |
+
|
| 1696 |
+
:global(body:not(.dark)) .space-card-name {
|
| 1697 |
+
color: #1a1b25;
|
| 1698 |
+
}
|
| 1699 |
+
|
| 1700 |
+
:global(body:not(.dark)) .space-card-likes {
|
| 1701 |
+
color: #9a9caa;
|
| 1702 |
+
}
|
| 1703 |
+
|
| 1704 |
+
:global(body:not(.dark)) .space-card-link {
|
| 1705 |
+
color: #9a9caa;
|
| 1706 |
+
}
|
| 1707 |
+
|
| 1708 |
+
:global(body:not(.dark)) .space-card-link:hover {
|
| 1709 |
+
color: #1a1b25;
|
| 1710 |
+
}
|
| 1711 |
+
|
| 1712 |
+
:global(body:not(.dark)) .space-card-id {
|
| 1713 |
+
color: #b0b2bc;
|
| 1714 |
+
}
|
| 1715 |
+
|
| 1716 |
+
:global(body:not(.dark)) .space-card-desc {
|
| 1717 |
+
color: #9a9caa;
|
| 1718 |
+
}
|
| 1719 |
+
|
| 1720 |
+
:global(body:not(.dark)) .space-card-status {
|
| 1721 |
+
background: #b0b2bc;
|
| 1722 |
+
}
|
| 1723 |
+
|
| 1724 |
+
:global(body:not(.dark)) .trending-status-text {
|
| 1725 |
+
color: #9a9caa;
|
| 1726 |
+
}
|
| 1727 |
+
</style>
|
6.17.1/workflowcanvas/workflow/featured.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Curated lists of featured spaces and models, surfaced as the default tab
|
| 3 |
+
* in the node picker. Edit these arrays to change what users see first when
|
| 4 |
+
* they open the picker for a given modality.
|
| 5 |
+
*
|
| 6 |
+
* `modality` must match a `MODALITIES[*].key` (image / audio / video / text / 3d)
|
| 7 |
+
* or `"data"` for datasets. `pipeline_tag` is required for models so we can
|
| 8 |
+
* resolve their input/output port schema from TASK_SCHEMAS.
|
| 9 |
+
*/
|
| 10 |
+
export interface FeaturedItem {
|
| 11 |
+
id: string;
|
| 12 |
+
title: string;
|
| 13 |
+
description: string;
|
| 14 |
+
modality: string;
|
| 15 |
+
pipeline_tag?: string;
|
| 16 |
+
likes?: number;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
export const FEATURED_SPACES: FeaturedItem[] = [
|
| 20 |
+
{
|
| 21 |
+
id: "black-forest-labs/FLUX.1-schnell",
|
| 22 |
+
title: "FLUX.1 schnell",
|
| 23 |
+
description: "Fast, high-quality text-to-image",
|
| 24 |
+
modality: "image",
|
| 25 |
+
pipeline_tag: "text-to-image"
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
id: "stabilityai/stable-diffusion-3.5-large",
|
| 29 |
+
title: "Stable Diffusion 3.5 Large",
|
| 30 |
+
description: "High-fidelity text-to-image",
|
| 31 |
+
modality: "image",
|
| 32 |
+
pipeline_tag: "text-to-image"
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
id: "briaai/BRIA-RMBG-2.0",
|
| 36 |
+
title: "BRIA Background Removal",
|
| 37 |
+
description: "Remove image backgrounds",
|
| 38 |
+
modality: "image"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
id: "hf-audio/whisper-large-v3-turbo",
|
| 42 |
+
title: "Whisper Large v3 Turbo",
|
| 43 |
+
description: "Fast speech-to-text",
|
| 44 |
+
modality: "audio",
|
| 45 |
+
pipeline_tag: "automatic-speech-recognition"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
id: "coqui/xtts",
|
| 49 |
+
title: "Coqui XTTS",
|
| 50 |
+
description: "Multilingual text-to-speech with voice cloning",
|
| 51 |
+
modality: "audio",
|
| 52 |
+
pipeline_tag: "text-to-speech"
|
| 53 |
+
}
|
| 54 |
+
];
|
| 55 |
+
|
| 56 |
+
export const FEATURED_MODELS: FeaturedItem[] = [
|
| 57 |
+
{
|
| 58 |
+
id: "black-forest-labs/FLUX.1-schnell",
|
| 59 |
+
title: "FLUX.1 schnell",
|
| 60 |
+
description: "Text-to-image",
|
| 61 |
+
modality: "image",
|
| 62 |
+
pipeline_tag: "text-to-image"
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
id: "stabilityai/stable-diffusion-3.5-large-turbo",
|
| 66 |
+
title: "SD 3.5 Large Turbo",
|
| 67 |
+
description: "Fast text-to-image",
|
| 68 |
+
modality: "image",
|
| 69 |
+
pipeline_tag: "text-to-image"
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
id: "Qwen/Qwen2.5-VL-7B-Instruct",
|
| 73 |
+
title: "Qwen2.5-VL 7B",
|
| 74 |
+
description: "Image understanding & captioning",
|
| 75 |
+
modality: "image",
|
| 76 |
+
pipeline_tag: "image-to-text"
|
| 77 |
+
},
|
| 78 |
+
{
|
| 79 |
+
id: "openai/whisper-large-v3-turbo",
|
| 80 |
+
title: "Whisper Large v3 Turbo",
|
| 81 |
+
description: "Speech-to-text",
|
| 82 |
+
modality: "audio",
|
| 83 |
+
pipeline_tag: "automatic-speech-recognition"
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
id: "meta-llama/Llama-3.2-3B-Instruct",
|
| 87 |
+
title: "Llama 3.2 3B Instruct",
|
| 88 |
+
description: "Open-weights text generation",
|
| 89 |
+
modality: "text",
|
| 90 |
+
pipeline_tag: "text-generation"
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
id: "Qwen/Qwen2.5-7B-Instruct",
|
| 94 |
+
title: "Qwen 2.5 7B",
|
| 95 |
+
description: "Multilingual text generation",
|
| 96 |
+
modality: "text",
|
| 97 |
+
pipeline_tag: "text-generation"
|
| 98 |
+
}
|
| 99 |
+
];
|
6.17.1/workflowcanvas/workflow/hf-auth.svelte.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
async function fetch_username(token: string): Promise<string | null> {
|
| 2 |
+
try {
|
| 3 |
+
const res = await fetch("https://huggingface.co/api/whoami-v2", {
|
| 4 |
+
headers: { Authorization: `Bearer ${token}` }
|
| 5 |
+
});
|
| 6 |
+
if (!res.ok) return null;
|
| 7 |
+
return (await res.json()).name || "User";
|
| 8 |
+
} catch {
|
| 9 |
+
return null;
|
| 10 |
+
}
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
function redirect_to(path: string): void {
|
| 14 |
+
const target = encodeURIComponent(
|
| 15 |
+
window.location.pathname + window.location.search
|
| 16 |
+
);
|
| 17 |
+
window.location.assign(`${path}?_target_url=${target}`);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
export function createHFAuth(getServer: () => Record<string, any>) {
|
| 21 |
+
let loggedInUser = $state("");
|
| 22 |
+
let isHFSpace = $state(false);
|
| 23 |
+
let isCheckingLogin = $state(true);
|
| 24 |
+
let hfToken = $state(
|
| 25 |
+
typeof localStorage !== "undefined"
|
| 26 |
+
? (localStorage.getItem("hf_token") ?? "")
|
| 27 |
+
: ""
|
| 28 |
+
);
|
| 29 |
+
let tokenUser = $state("");
|
| 30 |
+
let tokenStatus = $state<"idle" | "validating" | "invalid">("idle");
|
| 31 |
+
|
| 32 |
+
async function validateToken(token: string): Promise<void> {
|
| 33 |
+
if (!token) {
|
| 34 |
+
tokenUser = "";
|
| 35 |
+
tokenStatus = "idle";
|
| 36 |
+
return;
|
| 37 |
+
}
|
| 38 |
+
tokenStatus = "validating";
|
| 39 |
+
const name = await fetch_username(token);
|
| 40 |
+
if (name) {
|
| 41 |
+
tokenUser = name;
|
| 42 |
+
tokenStatus = "idle";
|
| 43 |
+
} else {
|
| 44 |
+
tokenUser = "";
|
| 45 |
+
tokenStatus = "invalid";
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function saveToken(token: string): void {
|
| 50 |
+
hfToken = token.trim();
|
| 51 |
+
if (typeof localStorage !== "undefined") {
|
| 52 |
+
if (hfToken) localStorage.setItem("hf_token", hfToken);
|
| 53 |
+
else localStorage.removeItem("hf_token");
|
| 54 |
+
}
|
| 55 |
+
void validateToken(hfToken);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// Validate any token loaded from localStorage on init so the user
|
| 59 |
+
// sees the "Signed in as β¦" badge without needing to re-paste.
|
| 60 |
+
if (hfToken) void validateToken(hfToken);
|
| 61 |
+
|
| 62 |
+
async function getOAuthToken(): Promise<string> {
|
| 63 |
+
const s = getServer();
|
| 64 |
+
if (!s?.get_token) return "";
|
| 65 |
+
try {
|
| 66 |
+
return (await s.get_token()) || "";
|
| 67 |
+
} catch {
|
| 68 |
+
return "";
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
async function checkLoginStatus(): Promise<void> {
|
| 73 |
+
isHFSpace = window.location.hostname.endsWith(".hf.space");
|
| 74 |
+
const token = await getOAuthToken();
|
| 75 |
+
if (!token) {
|
| 76 |
+
loggedInUser = "";
|
| 77 |
+
isCheckingLogin = false;
|
| 78 |
+
return;
|
| 79 |
+
}
|
| 80 |
+
loggedInUser = (await fetch_username(token)) ?? "";
|
| 81 |
+
isCheckingLogin = false;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
function handleLogin(): void {
|
| 85 |
+
redirect_to("/login/huggingface");
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
function handleLogout(): void {
|
| 89 |
+
redirect_to("/logout");
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
return {
|
| 93 |
+
get loggedInUser() {
|
| 94 |
+
return loggedInUser;
|
| 95 |
+
},
|
| 96 |
+
get isHFSpace() {
|
| 97 |
+
return isHFSpace;
|
| 98 |
+
},
|
| 99 |
+
get isCheckingLogin() {
|
| 100 |
+
return isCheckingLogin;
|
| 101 |
+
},
|
| 102 |
+
get hfToken() {
|
| 103 |
+
return hfToken;
|
| 104 |
+
},
|
| 105 |
+
get tokenUser() {
|
| 106 |
+
return tokenUser;
|
| 107 |
+
},
|
| 108 |
+
get tokenStatus() {
|
| 109 |
+
return tokenStatus;
|
| 110 |
+
},
|
| 111 |
+
saveToken,
|
| 112 |
+
handleLogin,
|
| 113 |
+
handleLogout,
|
| 114 |
+
getOAuthToken,
|
| 115 |
+
checkLoginStatus
|
| 116 |
+
};
|
| 117 |
+
}
|
6.17.1/workflowcanvas/workflow/icons/AudioIcon.svelte
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
width="14"
|
| 3 |
+
height="14"
|
| 4 |
+
viewBox="0 0 14 14"
|
| 5 |
+
fill="none"
|
| 6 |
+
stroke="currentColor"
|
| 7 |
+
stroke-width="1.4"
|
| 8 |
+
stroke-linecap="round"
|
| 9 |
+
aria-hidden="true"
|
| 10 |
+
>
|
| 11 |
+
<path d="M2.5 6v2" />
|
| 12 |
+
<path d="M5 4v6" />
|
| 13 |
+
<path d="M7.5 2.5v9" />
|
| 14 |
+
<path d="M10 4.5v5" />
|
| 15 |
+
<path d="M12.5 6v2" />
|
| 16 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/CheckIcon.svelte
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="11" height="11" viewBox="0 0 11 11" fill="none" aria-hidden="true">
|
| 2 |
+
<path
|
| 3 |
+
d="M2 5.5L4.5 8L9 3"
|
| 4 |
+
stroke="currentColor"
|
| 5 |
+
stroke-width="1.6"
|
| 6 |
+
stroke-linecap="round"
|
| 7 |
+
stroke-linejoin="round"
|
| 8 |
+
/>
|
| 9 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/ChevronDownIcon.svelte
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
viewBox="0 0 24 24"
|
| 3 |
+
width="16"
|
| 4 |
+
height="16"
|
| 5 |
+
fill="none"
|
| 6 |
+
stroke="currentColor"
|
| 7 |
+
stroke-width="2"
|
| 8 |
+
stroke-linecap="round"
|
| 9 |
+
stroke-linejoin="round"
|
| 10 |
+
aria-hidden="true"
|
| 11 |
+
>
|
| 12 |
+
<polyline points="6 9 12 15 18 9"></polyline>
|
| 13 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/ChevronLeftIcon.svelte
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
viewBox="0 0 24 24"
|
| 3 |
+
width="16"
|
| 4 |
+
height="16"
|
| 5 |
+
fill="none"
|
| 6 |
+
stroke="currentColor"
|
| 7 |
+
stroke-width="2"
|
| 8 |
+
stroke-linecap="round"
|
| 9 |
+
stroke-linejoin="round"
|
| 10 |
+
aria-hidden="true"
|
| 11 |
+
>
|
| 12 |
+
<polyline points="15 18 9 12 15 6"></polyline>
|
| 13 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/CloseIcon.svelte
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" aria-hidden="true">
|
| 2 |
+
<path
|
| 3 |
+
d="M2 2L8 8M8 2L2 8"
|
| 4 |
+
stroke="currentColor"
|
| 5 |
+
stroke-width="1.5"
|
| 6 |
+
stroke-linecap="round"
|
| 7 |
+
/>
|
| 8 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/DatasetIcon.svelte
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
| 2 |
+
<ellipse
|
| 3 |
+
cx="7"
|
| 4 |
+
cy="3.5"
|
| 5 |
+
rx="5"
|
| 6 |
+
ry="2"
|
| 7 |
+
stroke="currentColor"
|
| 8 |
+
stroke-width="1.5"
|
| 9 |
+
/>
|
| 10 |
+
<path
|
| 11 |
+
d="M2 3.5v3c0 1.1 2.24 2 5 2s5-.9 5-2v-3"
|
| 12 |
+
stroke="currentColor"
|
| 13 |
+
stroke-width="1.5"
|
| 14 |
+
/>
|
| 15 |
+
<path
|
| 16 |
+
d="M2 6.5v3c0 1.1 2.24 2 5 2s5-.9 5-2v-3"
|
| 17 |
+
stroke="currentColor"
|
| 18 |
+
stroke-width="1.5"
|
| 19 |
+
/>
|
| 20 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/DownloadIcon.svelte
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
| 2 |
+
<path
|
| 3 |
+
d="M6 1.5v6.5M6 8L3 5M6 8l3-3"
|
| 4 |
+
stroke="currentColor"
|
| 5 |
+
stroke-width="1.4"
|
| 6 |
+
stroke-linecap="round"
|
| 7 |
+
stroke-linejoin="round"
|
| 8 |
+
/>
|
| 9 |
+
<path
|
| 10 |
+
d="M2 9.5v.5a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-.5"
|
| 11 |
+
stroke="currentColor"
|
| 12 |
+
stroke-width="1.4"
|
| 13 |
+
stroke-linecap="round"
|
| 14 |
+
/>
|
| 15 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/FunctionIcon.svelte
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
| 2 |
+
<path
|
| 3 |
+
d="M2 3h2.5a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H2"
|
| 4 |
+
stroke="currentColor"
|
| 5 |
+
stroke-width="1.4"
|
| 6 |
+
stroke-linecap="round"
|
| 7 |
+
/>
|
| 8 |
+
<path
|
| 9 |
+
d="M10 3H7.5a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1H10"
|
| 10 |
+
stroke="currentColor"
|
| 11 |
+
stroke-width="1.4"
|
| 12 |
+
stroke-linecap="round"
|
| 13 |
+
/>
|
| 14 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/ImageIcon.svelte
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
| 2 |
+
<rect
|
| 3 |
+
x="1.5"
|
| 4 |
+
y="2"
|
| 5 |
+
width="11"
|
| 6 |
+
height="10"
|
| 7 |
+
rx="1.5"
|
| 8 |
+
stroke="currentColor"
|
| 9 |
+
stroke-width="1.4"
|
| 10 |
+
/>
|
| 11 |
+
<circle cx="5" cy="5.5" r="1.1" stroke="currentColor" stroke-width="1.2" />
|
| 12 |
+
<path
|
| 13 |
+
d="M2 10l3-3 3 3 2-2 2 2"
|
| 14 |
+
stroke="currentColor"
|
| 15 |
+
stroke-width="1.4"
|
| 16 |
+
stroke-linecap="round"
|
| 17 |
+
stroke-linejoin="round"
|
| 18 |
+
/>
|
| 19 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/Model3DIcon.svelte
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
| 2 |
+
<path
|
| 3 |
+
d="M7 1.6L12 4.3v5.4L7 12.4 2 9.7V4.3L7 1.6z"
|
| 4 |
+
stroke="currentColor"
|
| 5 |
+
stroke-width="1.4"
|
| 6 |
+
stroke-linejoin="round"
|
| 7 |
+
/>
|
| 8 |
+
<path
|
| 9 |
+
d="M2 4.3L7 7l5-2.7"
|
| 10 |
+
stroke="currentColor"
|
| 11 |
+
stroke-width="1.2"
|
| 12 |
+
stroke-linejoin="round"
|
| 13 |
+
/>
|
| 14 |
+
<path d="M7 7v5.4" stroke="currentColor" stroke-width="1.2" />
|
| 15 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/OpenLinkIcon.svelte
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
| 2 |
+
<path
|
| 3 |
+
d="M5 2H3.5A1.5 1.5 0 0 0 2 3.5v5A1.5 1.5 0 0 0 3.5 10h5A1.5 1.5 0 0 0 10 8.5V7"
|
| 4 |
+
stroke="currentColor"
|
| 5 |
+
stroke-width="1.3"
|
| 6 |
+
stroke-linecap="round"
|
| 7 |
+
/>
|
| 8 |
+
<path
|
| 9 |
+
d="M7 2h3v3"
|
| 10 |
+
stroke="currentColor"
|
| 11 |
+
stroke-width="1.3"
|
| 12 |
+
stroke-linecap="round"
|
| 13 |
+
stroke-linejoin="round"
|
| 14 |
+
/>
|
| 15 |
+
<path
|
| 16 |
+
d="M10 2L5.5 6.5"
|
| 17 |
+
stroke="currentColor"
|
| 18 |
+
stroke-width="1.3"
|
| 19 |
+
stroke-linecap="round"
|
| 20 |
+
/>
|
| 21 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/PlayIcon.svelte
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
width="9"
|
| 3 |
+
height="10"
|
| 4 |
+
viewBox="0 0 9 10"
|
| 5 |
+
fill="currentColor"
|
| 6 |
+
aria-hidden="true"
|
| 7 |
+
>
|
| 8 |
+
<path d="M0 0l9 5-9 5V0z" />
|
| 9 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/PlusIcon.svelte
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="11" height="11" viewBox="0 0 11 11" fill="none" aria-hidden="true">
|
| 2 |
+
<path
|
| 3 |
+
d="M5.5 1v9M1 5.5h9"
|
| 4 |
+
stroke="currentColor"
|
| 5 |
+
stroke-width="1.8"
|
| 6 |
+
stroke-linecap="round"
|
| 7 |
+
/>
|
| 8 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/SearchIcon.svelte
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
| 2 |
+
<circle cx="6" cy="6" r="4.5" stroke="currentColor" stroke-width="1.5" />
|
| 3 |
+
<path
|
| 4 |
+
d="M9.5 9.5L12.5 12.5"
|
| 5 |
+
stroke="currentColor"
|
| 6 |
+
stroke-width="1.5"
|
| 7 |
+
stroke-linecap="round"
|
| 8 |
+
/>
|
| 9 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/StopIcon.svelte
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
width="9"
|
| 3 |
+
height="9"
|
| 4 |
+
viewBox="0 0 9 9"
|
| 5 |
+
fill="currentColor"
|
| 6 |
+
aria-hidden="true"
|
| 7 |
+
>
|
| 8 |
+
<rect width="9" height="9" rx="1.5" />
|
| 9 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/TextIcon.svelte
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
| 2 |
+
<path
|
| 3 |
+
d="M3 3h8"
|
| 4 |
+
stroke="currentColor"
|
| 5 |
+
stroke-width="1.6"
|
| 6 |
+
stroke-linecap="round"
|
| 7 |
+
/>
|
| 8 |
+
<path
|
| 9 |
+
d="M7 3v8"
|
| 10 |
+
stroke="currentColor"
|
| 11 |
+
stroke-width="1.6"
|
| 12 |
+
stroke-linecap="round"
|
| 13 |
+
/>
|
| 14 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/icons/VideoIcon.svelte
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
| 2 |
+
<rect
|
| 3 |
+
x="1.5"
|
| 4 |
+
y="3.5"
|
| 5 |
+
width="8.5"
|
| 6 |
+
height="7"
|
| 7 |
+
rx="1.4"
|
| 8 |
+
stroke="currentColor"
|
| 9 |
+
stroke-width="1.4"
|
| 10 |
+
/>
|
| 11 |
+
<path
|
| 12 |
+
d="M10 6l2.5-1.5v5L10 8V6z"
|
| 13 |
+
stroke="currentColor"
|
| 14 |
+
stroke-width="1.4"
|
| 15 |
+
stroke-linejoin="round"
|
| 16 |
+
stroke-linecap="round"
|
| 17 |
+
/>
|
| 18 |
+
</svg>
|
6.17.1/workflowcanvas/workflow/inference-stream.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Browser-side streaming client for HF Inference text generation.
|
| 3 |
+
*
|
| 4 |
+
* Routes through `https://router.huggingface.co/v1/chat/completions`, HF's
|
| 5 |
+
* OpenAI-compatible unified endpoint. This bypasses our Python `call_model`
|
| 6 |
+
* server function for text-generation specifically so tokens stream into
|
| 7 |
+
* the canvas as they arrive instead of waiting for the full response.
|
| 8 |
+
*
|
| 9 |
+
* Other tasks (image, audio, classification, etc.) still go through the
|
| 10 |
+
* Python path β only text-generation gets the streaming treatment because
|
| 11 |
+
* it's the one task where partial output is meaningful.
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
const ROUTER_URL = "https://router.huggingface.co/v1/chat/completions";
|
| 15 |
+
|
| 16 |
+
export interface StreamTextOptions {
|
| 17 |
+
modelId: string;
|
| 18 |
+
prompt: string;
|
| 19 |
+
hfToken?: string;
|
| 20 |
+
provider?: string;
|
| 21 |
+
maxTokens?: number;
|
| 22 |
+
signal?: AbortSignal;
|
| 23 |
+
onChunk: (delta: string, accumulated: string) => void;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Stream a text-generation response token-by-token. Returns the final
|
| 28 |
+
* accumulated string when the stream ends. `onChunk` fires for each
|
| 29 |
+
* incremental delta with both the new delta and the running accumulator.
|
| 30 |
+
*
|
| 31 |
+
* Throws if the request fails or the stream cannot be opened β the caller
|
| 32 |
+
* is expected to surface the error (toast / node status).
|
| 33 |
+
*/
|
| 34 |
+
export async function stream_text_generation(
|
| 35 |
+
opts: StreamTextOptions
|
| 36 |
+
): Promise<string> {
|
| 37 |
+
const headers: Record<string, string> = {
|
| 38 |
+
"Content-Type": "application/json"
|
| 39 |
+
};
|
| 40 |
+
if (opts.hfToken) headers["Authorization"] = `Bearer ${opts.hfToken}`;
|
| 41 |
+
|
| 42 |
+
const model =
|
| 43 |
+
opts.provider && opts.provider !== "auto"
|
| 44 |
+
? `${opts.modelId}:${opts.provider}`
|
| 45 |
+
: opts.modelId;
|
| 46 |
+
|
| 47 |
+
const body = JSON.stringify({
|
| 48 |
+
model,
|
| 49 |
+
messages: [{ role: "user", content: opts.prompt }],
|
| 50 |
+
max_tokens: opts.maxTokens ?? 512,
|
| 51 |
+
stream: true
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
const res = await fetch(ROUTER_URL, {
|
| 55 |
+
method: "POST",
|
| 56 |
+
headers,
|
| 57 |
+
body,
|
| 58 |
+
signal: opts.signal
|
| 59 |
+
});
|
| 60 |
+
|
| 61 |
+
if (!res.ok || !res.body) {
|
| 62 |
+
const detail = await res.text().catch(() => "");
|
| 63 |
+
throw new Error(
|
| 64 |
+
`HF router ${res.status}${detail ? `: ${detail.slice(0, 200)}` : ""}`
|
| 65 |
+
);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
const reader = res.body.getReader();
|
| 69 |
+
const decoder = new TextDecoder("utf-8");
|
| 70 |
+
let buffer = "";
|
| 71 |
+
let accumulated = "";
|
| 72 |
+
|
| 73 |
+
try {
|
| 74 |
+
while (true) {
|
| 75 |
+
const { value, done } = await reader.read();
|
| 76 |
+
if (done) break;
|
| 77 |
+
buffer += decoder.decode(value, { stream: true });
|
| 78 |
+
|
| 79 |
+
// SSE frames are separated by blank lines; each `data:` line is a JSON
|
| 80 |
+
// chunk or the literal `[DONE]` sentinel.
|
| 81 |
+
let nl: number;
|
| 82 |
+
while ((nl = buffer.indexOf("\n")) !== -1) {
|
| 83 |
+
const line = buffer.slice(0, nl).trim();
|
| 84 |
+
buffer = buffer.slice(nl + 1);
|
| 85 |
+
if (!line.startsWith("data:")) continue;
|
| 86 |
+
const payload = line.slice(5).trim();
|
| 87 |
+
if (payload === "[DONE]") return accumulated;
|
| 88 |
+
try {
|
| 89 |
+
const chunk = JSON.parse(payload);
|
| 90 |
+
const delta = chunk?.choices?.[0]?.delta?.content ?? "";
|
| 91 |
+
if (delta) {
|
| 92 |
+
accumulated += delta;
|
| 93 |
+
opts.onChunk(delta, accumulated);
|
| 94 |
+
}
|
| 95 |
+
} catch {
|
| 96 |
+
// Malformed frame β skip; the next one usually recovers.
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
} finally {
|
| 101 |
+
try {
|
| 102 |
+
reader.releaseLock();
|
| 103 |
+
} catch {
|
| 104 |
+
/* noop */
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return accumulated;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/**
|
| 112 |
+
* Pipeline tags eligible for browser-side streaming. Only text-generation
|
| 113 |
+
* variants benefit β image / audio / classification tasks are
|
| 114 |
+
* single-shot in nature, so the streaming router endpoint adds no value
|
| 115 |
+
* and would in fact be incorrect (it's a chat-completions API).
|
| 116 |
+
*/
|
| 117 |
+
export function is_streamable_text_task(
|
| 118 |
+
pipelineTag: string | undefined
|
| 119 |
+
): boolean {
|
| 120 |
+
if (!pipelineTag) return false;
|
| 121 |
+
return (
|
| 122 |
+
pipelineTag === "text-generation" ||
|
| 123 |
+
pip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|
+
import { PORT_REGISTRY } from "./workflow-modalities";
|
| 3 |
+
import type { PortMeta } from "./workflow-modalities";
|
| 4 |
+
|
| 5 |
+
export interface NodeTemplate {
|
| 6 |
+
label: string;
|
| 7 |
+
kind: "input" | "transform" | "output" | "component";
|
| 8 |
+
source: "local" | "space" | "model" | "dataset";
|
| 9 |
+
space_id?: string;
|
| 10 |
+
model_id?: string;
|
| 11 |
+
dataset_id?: string;
|
| 12 |
+
dataset_config?: string;
|
| 13 |
+
dataset_split?: string;
|
| 14 |
+
pipeline_tag?: string;
|
| 15 |
+
endpoint?: string;
|
| 16 |
+
category?: string;
|
| 17 |
+
inputs: { id: string; label: string; type: PortType }[];
|
| 18 |
+
outputs: { id: string; label: string; type: PortType }[];
|
| 19 |
+
width: number;
|
| 20 |
+
height: number;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
/* ββ HF Inference API task β port schemas ββ */
|
| 24 |
+
|
| 25 |
+
export interface TaskSchema {
|
| 26 |
+
inputs: { id: string; label: string; type: PortType }[];
|
| 27 |
+
outputs: { id: string; label: string; type: PortType }[];
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
export const TASK_SCHEMAS: Record<string, TaskSchema> = {
|
| 31 |
+
// Text β Text
|
| 32 |
+
"text-generation": {
|
| 33 |
+
inputs: [{ id: "in_0", label: "Prompt", type: "text" }],
|
| 34 |
+
outputs: [{ id: "out_0", label: "Text", type: "text" }]
|
| 35 |
+
},
|
| 36 |
+
"text2text-generation": {
|
| 37 |
+
inputs: [{ id: "in_0", label: "Text", type: "text" }],
|
| 38 |
+
outputs: [{ id: "out_0", label: "Text", type: "text" }]
|
| 39 |
+
},
|
| 40 |
+
summarization: {
|
| 41 |
+
inputs: [{ id: "in_0", label: "Text", type: "text" }],
|
| 42 |
+
outputs: [{ id: "out_0", label: "Summary", type: "text" }]
|
| 43 |
+
},
|
| 44 |
+
translation: {
|
| 45 |
+
inputs: [{ id: "in_0", label: "Text", type: "text" }],
|
| 46 |
+
outputs: [{ id: "out_0", label: "Translation", type: "text" }]
|
| 47 |
+
},
|
| 48 |
+
"fill-mask": {
|
| 49 |
+
inputs: [{ id: "in_0", label: "Text", type: "text" }],
|
| 50 |
+
outputs: [{ id: "out_0", label: "Result", type: "json" }]
|
| 51 |
+
},
|
| 52 |
+
conversational: {
|
| 53 |
+
inputs: [{ id: "in_0", label: "Message", type: "text" }],
|
| 54 |
+
outputs: [{ id: "out_0", label: "Reply", type: "text" }]
|
| 55 |
+
},
|
| 56 |
+
// Text β Classification
|
| 57 |
+
"text-classification": {
|
| 58 |
+
inputs: [{ id: "in_0", label: "Text", type: "text" }],
|
| 59 |
+
outputs: [{ id: "out_0", label: "Labels", type: "json" }]
|
| 60 |
+
},
|
| 61 |
+
"token-classification": {
|
| 62 |
+
inputs: [{ id: "in_0", label: "Text", type: "text" }],
|
| 63 |
+
outputs: [{ id: "out_0", label: "Entities", type: "json" }]
|
| 64 |
+
},
|
| 65 |
+
"zero-shot-classification": {
|
| 66 |
+
inputs: [
|
| 67 |
+
{ id: "in_0", label: "Text", type: "text" },
|
| 68 |
+
{ id: "in_1", label: "Labels", type: "text" }
|
| 69 |
+
],
|
| 70 |
+
outputs: [{ id: "out_0", label: "Scores", type: "json" }]
|
| 71 |
+
},
|
| 72 |
+
"sentence-similarity": {
|
| 73 |
+
inputs: [
|
| 74 |
+
{ id: "in_0", label: "Source", type: "text" },
|
| 75 |
+
{ id: "in_1", label: "Sentences", type: "text" }
|
| 76 |
+
],
|
| 77 |
+
outputs: [{ id: "out_0", label: "Scores", type: "json" }]
|
| 78 |
+
},
|
| 79 |
+
"question-answering": {
|
| 80 |
+
inputs: [
|
| 81 |
+
{ id: "in_0", label: "Question", type: "text" },
|
| 82 |
+
{ id: "in_1", label: "Context", type: "text" }
|
| 83 |
+
],
|
| 84 |
+
outputs: [{ id: "out_0", label: "Answer", type: "text" }]
|
| 85 |
+
},
|
| 86 |
+
"feature-extraction": {
|
| 87 |
+
inputs: [{ id: "in_0", label: "Text", type: "text" }],
|
| 88 |
+
outputs: [{ id: "out_0", label: "Embeddings", type: "json" }]
|
| 89 |
+
},
|
| 90 |
+
// Text β Image
|
| 91 |
+
"text-to-image": {
|
| 92 |
+
inputs: [{ id: "in_0", label: "Prompt", type: "text" }],
|
| 93 |
+
outputs: [{ id: "out_0", label: "Image", type: "image" }]
|
| 94 |
+
},
|
| 95 |
+
// Text β Audio
|
| 96 |
+
"text-to-speech": {
|
| 97 |
+
inputs: [{ id: "in_0", label: "Text", type: "text" }],
|
| 98 |
+
outputs: [{ id: "out_0", label: "Audio", type: "audio" }]
|
| 99 |
+
},
|
| 100 |
+
"text-to-audio": {
|
| 101 |
+
inputs: [{ id: "in_0", label: "Prompt", type: "text" }],
|
| 102 |
+
outputs: [{ id: "out_0", label: "Audio", type: "audio" }]
|
| 103 |
+
},
|
| 104 |
+
// Text β Video
|
| 105 |
+
"text-to-video": {
|
| 106 |
+
inputs: [{ id: "in_0", label: "Prompt", type: "text" }],
|
| 107 |
+
outputs: [{ id: "out_0", label: "Video", type: "video" }]
|
| 108 |
+
},
|
| 109 |
+
// Image β *
|
| 110 |
+
"image-classification": {
|
| 111 |
+
inputs: [{ id: "in_0", label: "Image", type: "image" }],
|
| 112 |
+
outputs: [{ id: "out_0", label: "Labels", type: "json" }]
|
| 113 |
+
},
|
| 114 |
+
"object-detection": {
|
| 115 |
+
inputs: [{ id: "in_0", label: "Image", type: "image" }],
|
| 116 |
+
outputs: [{ id: "out_0", label: "Detections", type: "json" }]
|
| 117 |
+
},
|
| 118 |
+
"image-segmentation": {
|
| 119 |
+
inputs: [{ id: "in_0", label: "Image", type: "image" }],
|
| 120 |
+
outputs: [{ id: "out_0", label: "Segments", type: "json" }]
|
| 121 |
+
},
|
| 122 |
+
"image-to-text": {
|
| 123 |
+
inputs: [{ id: "in_0", label: "Image", type: "image" }],
|
| 124 |
+
outputs: [{ id: "out_0", label: "Text", type: "text" }]
|
| 125 |
+
},
|
| 126 |
+
"image-to-image": {
|
| 127 |
+
inputs: [
|
| 128 |
+
{ id: "in_0", label: "Image", type: "image" },
|
| 129 |
+
{ id: "in_1", label: "Prompt", type: "text" }
|
| 130 |
+
],
|
| 131 |
+
outputs: [{ id: "out_0", label: "Image", type: "image" }]
|
| 132 |
+
},
|
| 133 |
+
"image-to-video": {
|
| 134 |
+
inputs: [{ id: "in_0", label: "Image", type: "image" }],
|
| 135 |
+
outputs: [{ id: "out_0", label: "Video", type: "video" }]
|
| 136 |
+
},
|
| 137 |
+
"depth-estimation": {
|
| 138 |
+
inputs: [{ id: "in_0", label: "Image", type: "image" }],
|
| 139 |
+
outputs: [{ id: "out_0", label: "Depth", type: "image" }]
|
| 140 |
+
},
|
| 141 |
+
"image-text-to-text": {
|
| 142 |
+
inputs: [
|
| 143 |
+
{ id: "in_0", label: "Image", type: "image" },
|
| 144 |
+
{ id: "in_1", label: "Prompt", type: "text" }
|
| 145 |
+
],
|
| 146 |
+
outputs: [{ id: "out_0", label: "Text", type: "text" }]
|
| 147 |
+
},
|
| 148 |
+
// Audio β *
|
| 149 |
+
"automatic-speech-recognition": {
|
| 150 |
+
inputs: [{ id: "in_0", label: "Audio", type: "audio" }],
|
| 151 |
+
outputs: [{ id: "out_0", label: "Text", type: "text" }]
|
| 152 |
+
},
|
| 153 |
+
"audio-classification": {
|
| 154 |
+
inputs: [{ id: "in_0", label: "Audio", type: "audio" }],
|
| 155 |
+
outputs: [{ id: "out_0", label: "Labels", type: "json" }]
|
| 156 |
+
},
|
| 157 |
+
"audio-to-audio": {
|
| 158 |
+
inputs: [{ id: "in_0", label: "Audio", type: "audio" }],
|
| 159 |
+
outputs: [{ id: "out_0", label: "Audio", type: "audio" }]
|
| 160 |
+
},
|
| 161 |
+
// Multimodal
|
| 162 |
+
"visual-question-answering": {
|
| 163 |
+
inputs: [
|
| 164 |
+
{ id: "in_0", label: "Image", type: "image" },
|
| 165 |
+
{ id: "in_1", label: "Question", type: "text" }
|
| 166 |
+
],
|
| 167 |
+
outputs: [{ id: "out_0", label: "Answer", type: "text" }]
|
| 168 |
+
},
|
| 169 |
+
"document-question-answering": {
|
| 170 |
+
inputs: [
|
| 171 |
+
{ id: "in_0", label: "Document", type: "image" },
|
| 172 |
+
{ id: "in_1", label: "Question", type: "text" }
|
| 173 |
+
],
|
| 174 |
+
outputs: [{ id: "out_0", label: "Answer", type: "text" }]
|
| 175 |
+
}
|
| 176 |
+
};
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* Build a reference/subject template for a port-registry entry. Reference
|
| 180 |
+
* and subject nodes share the same shape today (in/out of the same type) β
|
| 181 |
+
* the role tag in the workflow store disambiguates them at the data layer.
|
| 182 |
+
* Width/height stay constant; the runtime widget decides actual rendering.
|
| 183 |
+
*/
|
| 184 |
+
function componentTemplate(meta: PortMeta): NodeTemplate {
|
| 185 |
+
const height = meta.port_type === "number" ? 130 : 160;
|
| 186 |
+
return {
|
| 187 |
+
label: meta.label,
|
| 188 |
+
kind: "component",
|
| 189 |
+
source: "local",
|
| 190 |
+
inputs: [{ id: "in", label: meta.label, type: meta.port_type }],
|
| 191 |
+
outputs: [{ id: "out", label: meta.label, type: meta.port_type }],
|
| 192 |
+
width: 220,
|
| 193 |
+
height
|
| 194 |
+
};
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
export const LIBRARY: Record<string, NodeTemplate[]> = {
|
| 198 |
+
components: PORT_REGISTRY.map(componentTemplate),
|
| 199 |
+
spaces: [] as NodeTemplate[]
|
| 200 |
+
};
|
| 201 |
+
|
| 202 |
+
export function getComponentForPortType(type: string): NodeTemplate | null {
|
| 203 |
+
// `any`/`file` are inference-only fallbacks β default them to Image so
|
| 204 |
+
// the user gets a usable picker entry rather than nothing.
|
| 205 |
+
const lookup = (
|
| 206 |
+
type === "any" || type === "file" ? "image" : type
|
| 207 |
+
) as PortType;
|
| 208 |
+
return LIBRARY.components.find((c) => c.outputs[0]?.type === lookup) ?? null;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
/* ββ Expanded categories & pipeline-tag mapping ββ */
|
| 212 |
+
|
| 213 |
+
export const SPACE_CATEGORIES = [
|
| 214 |
+
{ key: "image", label: "Image" },
|
| 215 |
+
{ key: "audio", label: "Audio" },
|
| 216 |
+
{ key: "text", label: "Text" },
|
| 217 |
+
{ key: "video", label: "Video" },
|
| 218 |
+
{ key: "multimodal", label: "Multimodal" },
|
| 219 |
+
{ key: "3d", label: "3D" },
|
| 220 |
+
{ key: "chat", label: "Chat" },
|
| 221 |
+
{ key: "code", label: "Code" }
|
| 222 |
+
];
|
| 223 |
+
|
| 224 |
+
export const PIPELINE_TO_CATEGORY: Record<string, string> = {
|
| 225 |
+
// Image
|
| 226 |
+
"text-to-image": "image",
|
| 227 |
+
"image-to-image": "image",
|
| 228 |
+
"image-classification": "image",
|
| 229 |
+
"image-segmentation": "image",
|
| 230 |
+
"object-detection": "image",
|
| 231 |
+
"unconditional-image-generation": "image",
|
| 232 |
+
"image-feature-extraction": "image",
|
| 233 |
+
"depth-estimation": "image",
|
| 234 |
+
"image-to-text": "image",
|
| 235 |
+
// Audio
|
| 236 |
+
"text-to-speech": "audio",
|
| 237 |
+
"automatic-speech-recognition": "audio",
|
| 238 |
+
"audio-to-audio": "audio",
|
| 239 |
+
"audio-classification": "audio",
|
| 240 |
+
"voice-activity-detection": "audio",
|
| 241 |
+
// Text
|
| 242 |
+
"text-generation": "text",
|
| 243 |
+
"text2text-generation": "text",
|
| 244 |
+
translation: "text",
|
| 245 |
+
summarization: "text",
|
| 246 |
+
"text-classification": "text",
|
| 247 |
+
"question-answering": "text",
|
| 248 |
+
"fill-mask": "text",
|
| 249 |
+
"token-classification": "text",
|
| 250 |
+
"sentence-similarity": "text",
|
| 251 |
+
"feature-extraction": "text",
|
| 252 |
+
"zero-shot-classification": "text",
|
| 253 |
+
"table-question-answering": "text",
|
| 254 |
+
// Video
|
| 255 |
+
"text-to-video": "video",
|
| 256 |
+
"image-to-video": "video",
|
| 257 |
+
"video-classification": "video",
|
| 258 |
+
// 3D
|
| 259 |
+
"text-to-3d": "3d",
|
| 260 |
+
"image-to-3d": "3d",
|
| 261 |
+
// Multimodal
|
| 262 |
+
"visual-question-answering": "multimodal",
|
| 263 |
+
"image-text-to-text": "multimodal",
|
| 264 |
+
"document-question-answering": "multimodal",
|
| 265 |
+
"zero-shot-image-classification": "multimodal",
|
| 266 |
+
"video-text-to-text": "multimodal",
|
| 267 |
+
// Chat
|
| 268 |
+
conversational: "chat"
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
const KEYWORD_PATTERNS: [RegExp, string][] = [
|
| 272 |
+
// Video β check before image since "image to video" should be video
|
| 273 |
+
[/\b(video|animate|animation|motion|film|movie)\b/i, "video"],
|
| 274 |
+
// 3D
|
| 275 |
+
[/\b(3d|mesh|point.?cloud|nerf|gaussian.?splat|triposr)\b/i, "3d"],
|
| 276 |
+
// Audio
|
| 277 |
+
[/\b(audio|voice|speech|tts|whisper|music|sound|sing|talk)\b/i, "audio"],
|
| 278 |
+
// Chat
|
| 279 |
+
[
|
| 280 |
+
/\b(chat|conversation|assistant|llm|gpt|gemma|llama|mistral|qwen(?!.*(?:image|edit|video)))\b/i,
|
| 281 |
+
"chat"
|
| 282 |
+
],
|
| 283 |
+
// Multimodal
|
| 284 |
+
[/\b(multimodal|vision.?language|vqa|document.?q|ocr)\b/i, "multimodal"],
|
| 285 |
+
// Code
|
| 286 |
+
[/\b(code|program|compiler|debug|ide)\b/i, "code"],
|
| 287 |
+
// Image β broad, check last
|
| 288 |
+
[
|
| 289 |
+
/\b(image|photo|picture|paint|draw|sketch|pixel|diffus|flux|stable|edit.*image|image.*edit|face|swap|background|segm|detect|caption|upscal|super.?res|inpaint|outpaint|style.?transfer|lora|controlnet)\b/i,
|
| 290 |
+
"image"
|
| 291 |
+
]
|
| 292 |
+
];
|
| 293 |
+
|
| 294 |
+
export function categorizeSpace(
|
| 295 |
+
pipelineTag?: string | null,
|
| 296 |
+
tags?: string[] | null,
|
| 297 |
+
description?: string | null,
|
| 298 |
+
spaceId?: string | null
|
| 299 |
+
): string | null {
|
| 300 |
+
if (pipelineTag && PIPELINE_TO_CATEGORY[pipelineTag]) {
|
| 301 |
+
return PIPELINE_TO_CATEGORY[pipelineTag];
|
| 302 |
+
}
|
| 303 |
+
if (tags) {
|
| 304 |
+
for (const tag of tags) {
|
| 305 |
+
if (PIPELINE_TO_CATEGORY[tag]) return PIPELINE_TO_CATEGORY[tag];
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
// Fall back to keyword matching on description + space ID
|
| 309 |
+
const text = [description ?? "", spaceId ?? ""].join(" ");
|
| 310 |
+
if (text.trim()) {
|
| 311 |
+
for (const [pattern, category] of KEYWORD_PATTERNS) {
|
| 312 |
+
if (pattern.test(text)) return category;
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
return null;
|
| 316 |
+
}
|
6.17.1/workflowcanvas/workflow/space-api.ts
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { PortType, Port } from "./workflow-types";
|
| 2 |
+
import { modalityForPort } from "./workflow-modalities";
|
| 3 |
+
import type { ModalityConfig } from "./workflow-modalities";
|
| 4 |
+
|
| 5 |
+
export function normalize_space_id(raw: string): string | null {
|
| 6 |
+
const trimmed = raw.trim().replace(/\/+$/, "");
|
| 7 |
+
if (!trimmed) return null;
|
| 8 |
+
|
| 9 |
+
if (/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(trimmed)) {
|
| 10 |
+
return trimmed;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const pageMatch = trimmed.match(
|
| 14 |
+
/^https?:\/\/(?:www\.)?huggingface\.co\/spaces\/([^/\s?#]+)\/([^/\s?#]+)/i
|
| 15 |
+
);
|
| 16 |
+
if (pageMatch) return `${pageMatch[1]}/${pageMatch[2]}`;
|
| 17 |
+
|
| 18 |
+
const sub = trimmed.match(/^https?:\/\/([^/]+)\.hf\.space/i);
|
| 19 |
+
if (sub) {
|
| 20 |
+
const parts = sub[1].split("-");
|
| 21 |
+
if (parts.length >= 2) {
|
| 22 |
+
return `${parts[0]}/${parts.slice(1).join("-")}`;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
return null;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/** Map Gradio component types to our port types */
|
| 30 |
+
export function componentToPortType(
|
| 31 |
+
component: string,
|
| 32 |
+
type?: string,
|
| 33 |
+
pythonType?: string,
|
| 34 |
+
labelHint?: string
|
| 35 |
+
): PortType {
|
| 36 |
+
const c = component.toLowerCase();
|
| 37 |
+
if (pythonType) {
|
| 38 |
+
const cleaned = pythonType
|
| 39 |
+
.toLowerCase()
|
| 40 |
+
.replace(/^none\s*\|\s*/, "")
|
| 41 |
+
.replace(/\s*\|\s*none$/, "")
|
| 42 |
+
.trim();
|
| 43 |
+
if (cleaned === "str" || cleaned === "string") return "text";
|
| 44 |
+
if (cleaned === "int" || cleaned === "integer" || cleaned === "float")
|
| 45 |
+
return "number";
|
| 46 |
+
if (cleaned === "bool" || cleaned === "boolean") return "boolean";
|
| 47 |
+
}
|
| 48 |
+
if (c === "image" || c === "imageeditor" || c === "imageslider")
|
| 49 |
+
return "image";
|
| 50 |
+
if (c === "gallery") return "gallery";
|
| 51 |
+
if (c === "audio") return "audio";
|
| 52 |
+
if (c === "video") return "video";
|
| 53 |
+
if (c === "number" || c === "slider") return "number";
|
| 54 |
+
if (c === "checkbox") return "boolean";
|
| 55 |
+
if (c === "file" || c === "uploadbutton" || c === "downloadbutton")
|
| 56 |
+
return "file";
|
| 57 |
+
if (c === "model3d") return "model3d";
|
| 58 |
+
if (c === "json" || c === "dataframe") return "json";
|
| 59 |
+
if (c === "state") return "__skip__" as PortType; // internal, not user I/O
|
| 60 |
+
if (
|
| 61 |
+
c === "textbox" ||
|
| 62 |
+
c === "text" ||
|
| 63 |
+
c === "markdown" ||
|
| 64 |
+
c === "chatbot" ||
|
| 65 |
+
c === "label" ||
|
| 66 |
+
c === "code" ||
|
| 67 |
+
c === "highlightedtext" ||
|
| 68 |
+
c === "dropdown" ||
|
| 69 |
+
c === "radio" ||
|
| 70 |
+
c === "checkboxgroup" ||
|
| 71 |
+
c === "colorpicker" ||
|
| 72 |
+
c === "html"
|
| 73 |
+
)
|
| 74 |
+
return "text";
|
| 75 |
+
|
| 76 |
+
// gr.api endpoints use component="Api" with python_type carrying the
|
| 77 |
+
// real hint β primitives already handled at the top of the function.
|
| 78 |
+
if (pythonType) {
|
| 79 |
+
const cleaned = pythonType
|
| 80 |
+
.toLowerCase()
|
| 81 |
+
.replace(/^none\s*\|\s*/, "")
|
| 82 |
+
.replace(/\s*\|\s*none$/, "")
|
| 83 |
+
.trim();
|
| 84 |
+
if (
|
| 85 |
+
cleaned === "filepath" ||
|
| 86 |
+
cleaned === "file" ||
|
| 87 |
+
cleaned.includes("filedata")
|
| 88 |
+
) {
|
| 89 |
+
const l = (labelHint ?? "").toLowerCase();
|
| 90 |
+
if (/audio|wav|mp3|voice|sound|speech|tts|asr/.test(l)) return "audio";
|
| 91 |
+
if (/image|img|photo|picture|pic\b/.test(l)) return "image";
|
| 92 |
+
if (/video|mp4|movie|clip/.test(l)) return "video";
|
| 93 |
+
if (/model3d|mesh|glb|gltf|obj\b/.test(l)) return "model3d";
|
| 94 |
+
return "file";
|
| 95 |
+
}
|
| 96 |
+
if (
|
| 97 |
+
cleaned.includes("dict") ||
|
| 98 |
+
cleaned.includes("list") ||
|
| 99 |
+
cleaned.includes("any")
|
| 100 |
+
)
|
| 101 |
+
return "json";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// Fallback: check the type field from the API
|
| 105 |
+
if (type) {
|
| 106 |
+
const t = typeof type === "string" ? type.toLowerCase() : "";
|
| 107 |
+
if (t.includes("image") || t.includes("pil")) return "image";
|
| 108 |
+
if (t.includes("video") || t.includes("mp4")) return "video";
|
| 109 |
+
if (t.includes("audio") || t.includes("wav") || t.includes("mp3"))
|
| 110 |
+
return "audio";
|
| 111 |
+
if (t.includes("filepath") || t.includes("file")) return "file";
|
| 112 |
+
if (t === "number" || t === "float" || t === "int" || t === "integer")
|
| 113 |
+
return "number";
|
| 114 |
+
if (t === "bool" || t === "boolean") return "boolean";
|
| 115 |
+
if (t === "str" || t === "string") return "text";
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
return "any";
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/** Prefixes that indicate utility/event-handler endpoints β skip these */
|
| 122 |
+
const UTILITY_PREFIXES = [
|
| 123 |
+
"/on_",
|
| 124 |
+
"/handle_",
|
| 125 |
+
"/update_",
|
| 126 |
+
"/prepare_",
|
| 127 |
+
"/load_",
|
| 128 |
+
"/clear_",
|
| 129 |
+
"/reset_"
|
| 130 |
+
];
|
| 131 |
+
|
| 132 |
+
export interface EndpointSig {
|
| 133 |
+
name: string;
|
| 134 |
+
inputs: Port[];
|
| 135 |
+
outputs: Port[];
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
export interface SpaceApiInfo {
|
| 139 |
+
endpoint: string;
|
| 140 |
+
inputs: Port[];
|
| 141 |
+
outputs: Port[];
|
| 142 |
+
width: number;
|
| 143 |
+
endpoints: EndpointSig[];
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
const ORDINAL_LABEL = /^\d+(st|nd|rd|th)$/i;
|
| 147 |
+
|
| 148 |
+
function parse_endpoint_sig(name: string, ep: any): EndpointSig {
|
| 149 |
+
const inputs = (ep.parameters ?? [])
|
| 150 |
+
.map((p: any, i: number) => {
|
| 151 |
+
const isApi = (p.component ?? "").toLowerCase() === "api";
|
| 152 |
+
const pyType = p.python_type?.type;
|
| 153 |
+
const labelHint = p.parameter_name || p.label || "";
|
| 154 |
+
const portType = componentToPortType(
|
| 155 |
+
p.component ?? "",
|
| 156 |
+
typeof p.type === "string" ? p.type : "",
|
| 157 |
+
pyType,
|
| 158 |
+
labelHint
|
| 159 |
+
);
|
| 160 |
+
if (portType === "__skip__") return null;
|
| 161 |
+
const hasDefault = p.parameter_has_default === true;
|
| 162 |
+
const useParamName =
|
| 163 |
+
(isApi || ORDINAL_LABEL.test(p.label ?? "")) && p.parameter_name;
|
| 164 |
+
const rawLabel = useParamName
|
| 165 |
+
? p.parameter_name
|
| 166 |
+
: p.label || p.parameter_name || `Input ${i}`;
|
| 167 |
+
return {
|
| 168 |
+
id: `in_${i}`,
|
| 169 |
+
label: rawLabel,
|
| 170 |
+
type: portType,
|
| 171 |
+
required: !hasDefault,
|
| 172 |
+
default_value:
|
| 173 |
+
hasDefault && p.default !== undefined ? p.default : undefined
|
| 174 |
+
};
|
| 175 |
+
})
|
| 176 |
+
.filter(Boolean) as Port[];
|
| 177 |
+
|
| 178 |
+
const outputs = (ep.returns ?? [])
|
| 179 |
+
.map((r: any, i: number) => {
|
| 180 |
+
const isApi = (r.component ?? "").toLowerCase() === "api";
|
| 181 |
+
const pyType = r.python_type?.type;
|
| 182 |
+
const labelHint = isApi
|
| 183 |
+
? `${r.parameter_name ?? ""} ${name ?? ""}`.trim()
|
| 184 |
+
: r.parameter_name || r.label || "";
|
| 185 |
+
const portType = componentToPortType(
|
| 186 |
+
r.component ?? "",
|
| 187 |
+
typeof r.type === "string" ? r.type : "",
|
| 188 |
+
pyType,
|
| 189 |
+
labelHint
|
| 190 |
+
);
|
| 191 |
+
if (portType === "__skip__") return null;
|
| 192 |
+
const useParamName =
|
| 193 |
+
(isApi || ORDINAL_LABEL.test(r.label ?? "")) && r.parameter_name;
|
| 194 |
+
const rawLabel = useParamName
|
| 195 |
+
? r.parameter_name
|
| 196 |
+
: r.label || `Output ${i}`;
|
| 197 |
+
return {
|
| 198 |
+
id: `out_${i}`,
|
| 199 |
+
label: rawLabel,
|
| 200 |
+
type: portType,
|
| 201 |
+
output_index: i
|
| 202 |
+
};
|
| 203 |
+
})
|
| 204 |
+
.filter(Boolean) as Port[];
|
| 205 |
+
|
| 206 |
+
if (inputs.length === 0)
|
| 207 |
+
inputs.push({ id: "in", label: "Input", type: "any" as PortType });
|
| 208 |
+
if (outputs.length === 0)
|
| 209 |
+
outputs.push({ id: "out", label: "Output", type: "any" as PortType });
|
| 210 |
+
|
| 211 |
+
return { name, inputs, outputs };
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/** Cache for fetched API info */
|
| 215 |
+
const spaceApiCache = new Map<string, SpaceApiInfo>();
|
| 216 |
+
|
| 217 |
+
/**
|
| 218 |
+
* Fetch API info from a Space and return endpoint, inputs, outputs.
|
| 219 |
+
* Results are cached by space_id.
|
| 220 |
+
*/
|
| 221 |
+
export async function fetchSpaceApi(spaceId: string): Promise<SpaceApiInfo> {
|
| 222 |
+
const cached = spaceApiCache.get(spaceId);
|
| 223 |
+
if (cached) return cached;
|
| 224 |
+
|
| 225 |
+
const spaceUrl = spaceId.startsWith("http")
|
| 226 |
+
? spaceId
|
| 227 |
+
: `https://${spaceId.replace("/", "-").replaceAll(".", "-").toLowerCase()}.hf.space`;
|
| 228 |
+
|
| 229 |
+
// Try multiple API paths β older Spaces use /info, newer use /gradio_api/info
|
| 230 |
+
let infoRes: Response | null = null;
|
| 231 |
+
for (const path of ["/gradio_api/info", "/info", "/api/info"]) {
|
| 232 |
+
try {
|
| 233 |
+
const res = await Promise.race([
|
| 234 |
+
fetch(`${spaceUrl}${path}`),
|
| 235 |
+
new Promise<never>((_, reject) =>
|
| 236 |
+
setTimeout(() => reject(new Error("Timed out")), 10000)
|
| 237 |
+
)
|
| 238 |
+
]);
|
| 239 |
+
if (res.ok) {
|
| 240 |
+
infoRes = res;
|
| 241 |
+
break;
|
| 242 |
+
}
|
| 243 |
+
} catch {
|
| 244 |
+
/* try next */
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
if (!infoRes)
|
| 248 |
+
throw new Error(
|
| 249 |
+
"Could not connect to Space β it may be sleeping or have no Gradio API"
|
| 250 |
+
);
|
| 251 |
+
|
| 252 |
+
const api = await infoRes.json();
|
| 253 |
+
const named = api.named_endpoints ?? {};
|
| 254 |
+
const unnamed = api.unnamed_endpoints ?? {};
|
| 255 |
+
|
| 256 |
+
const all_endpoints: Array<[string, any]> = [
|
| 257 |
+
...Object.entries(named),
|
| 258 |
+
...Object.entries(unnamed)
|
| 259 |
+
].filter(([n]) => !UTILITY_PREFIXES.some((p) => n.startsWith(p)));
|
| 260 |
+
|
| 261 |
+
if (all_endpoints.length === 0) {
|
| 262 |
+
throw new Error("No suitable endpoints found");
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
// Default to /predict if present (most common Gradio convention), else
|
| 266 |
+
// the first non-utility endpoint. Users can switch via the node dropdown.
|
| 267 |
+
const default_index = Math.max(
|
| 268 |
+
0,
|
| 269 |
+
all_endpoints.findIndex(([n]) => n === "/predict")
|
| 270 |
+
);
|
| 271 |
+
const [epName, ep] = all_endpoints[default_index];
|
| 272 |
+
const endpoints: EndpointSig[] = all_endpoints.map(([n, e]) =>
|
| 273 |
+
parse_endpoint_sig(n, e)
|
| 274 |
+
);
|
| 275 |
+
|
| 276 |
+
const picked = parse_endpoint_sig(epName, ep);
|
| 277 |
+
const inputs = picked.inputs;
|
| 278 |
+
const outputs = picked.outputs;
|
| 279 |
+
|
| 280 |
+
const label = spaceId.split("/").pop() ?? spaceId;
|
| 281 |
+
const maxPortLen = Math.max(
|
| 282 |
+
...inputs.map((p: any) => (p.label as string).length),
|
| 283 |
+
...outputs.map((p: any) => (p.label as string).length),
|
| 284 |
+
label.length
|
| 285 |
+
);
|
| 286 |
+
const width = Math.max(280, Math.min(400, maxPortLen * 9 + 100));
|
| 287 |
+
|
| 288 |
+
const result = { endpoint: epName, inputs, outputs, width, endpoints };
|
| 289 |
+
spaceApiCache.set(spaceId, result);
|
| 290 |
+
return result;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* Clamp inferred port types so a fallback `any` or `file` becomes the
|
| 295 |
+
* modality's canonical type when the modality is known. Models picked via
|
| 296 |
+
* `pipeline_tag` and Spaces picked via the modality picker carry that hint;
|
| 297 |
+
* passing it lets us avoid surfacing generic `any`/`file` ports in the UI.
|
| 298 |
+
*
|
| 299 |
+
* If `modality` is null (e.g. unknown), ports are returned unchanged.
|
| 300 |
+
*/
|
| 301 |
+
export function normalizeOperatorPorts(
|
| 302 |
+
modality: ModalityConfig | null,
|
| 303 |
+
ports: Port[]
|
| 304 |
+
): Port[] {
|
| 305 |
+
if (!modality?.port_type) return ports;
|
| 306 |
+
const canonical = modality.port_type;
|
| 307 |
+
return ports.map((p) => {
|
| 308 |
+
if (p.type === "any" || p.type === "file") {
|
| 309 |
+
return { ...p, type: canonical };
|
| 310 |
+
}
|
| 311 |
+
return p;
|
| 312 |
+
});
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
/**
|
| 316 |
+
* Canonicalize a single port type using the modality registry. Used by
|
| 317 |
+
* schema lookups (TASK_SCHEMAS) to clamp legacy `any`/`file` entries.
|
| 318 |
+
* Pass-through for already-specific types.
|
| 319 |
+
*/
|
| 320 |
+
export function canonicalizePort(type: PortType, hint?: PortType): PortType {
|
| 321 |
+
if (type !== "any" && type !== "file") return type;
|
| 322 |
+
if (!hint) return type;
|
| 323 |
+
const modality = modalityForPort(hint);
|
| 324 |
+
return modality?.port_type ?? type;
|
| 325 |
+
}
|
6.17.1/workflowcanvas/workflow/viewport-persistence.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export interface Viewport {
|
| 2 |
+
x: number;
|
| 3 |
+
y: number;
|
| 4 |
+
zoom: number;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
const DEFAULT_VIEWPORT: Viewport = { x: 0, y: 0, zoom: 1 };
|
| 8 |
+
|
| 9 |
+
export function viewport_storage_key(name: string): string {
|
| 10 |
+
return `gradio_workflow_viewport:${name}`;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export function load_viewport(
|
| 14 |
+
name: string,
|
| 15 |
+
storage: Storage | undefined = typeof localStorage !== "undefined"
|
| 16 |
+
? localStorage
|
| 17 |
+
: undefined
|
| 18 |
+
): Viewport {
|
| 19 |
+
if (!storage) return { ...DEFAULT_VIEWPORT };
|
| 20 |
+
try {
|
| 21 |
+
const raw = storage.getItem(viewport_storage_key(name));
|
| 22 |
+
if (!raw) return { ...DEFAULT_VIEWPORT };
|
| 23 |
+
const v = JSON.parse(raw);
|
| 24 |
+
if (
|
| 25 |
+
typeof v?.x === "number" &&
|
| 26 |
+
typeof v?.y === "number" &&
|
| 27 |
+
typeof v?.zoom === "number"
|
| 28 |
+
) {
|
| 29 |
+
return { x: v.x, y: v.y, zoom: v.zoom };
|
| 30 |
+
}
|
| 31 |
+
} catch {}
|
| 32 |
+
return { ...DEFAULT_VIEWPORT };
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
export function save_viewport(
|
| 36 |
+
name: string,
|
| 37 |
+
viewport: Viewport,
|
| 38 |
+
storage: Storage | undefined = typeof localStorage !== "undefined"
|
| 39 |
+
? localStorage
|
| 40 |
+
: undefined
|
| 41 |
+
): void {
|
| 42 |
+
if (!storage) return;
|
| 43 |
+
try {
|
| 44 |
+
storage.setItem(viewport_storage_key(name), JSON.stringify(viewport));
|
| 45 |
+
} catch {}
|
| 46 |
+
}
|
6.17.1/workflowcanvas/workflow/workflow-executor.ts
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ue,
|
| 6 |
+
NodeStatus,
|
| 7 |
+
FileValue
|
| 8 |
+
} from "./workflow-types";
|
| 9 |
+
import { toLegacyShape } from "./workflow-migration";
|
| 10 |
+
import { topoSort } from "./workflow-graph";
|
| 11 |
+
|
| 12 |
+
type StatusCallback = (
|
| 13 |
+
nodeId: string,
|
| 14 |
+
status: NodeStatus,
|
| 15 |
+
error?: string,
|
| 16 |
+
errorType?: string
|
| 17 |
+
) => void;
|
| 18 |
+
type OutputCallback = (
|
| 19 |
+
nodeId: string,
|
| 20 |
+
portId: string,
|
| 21 |
+
value: NodeDataValue
|
| 22 |
+
) => void;
|
| 23 |
+
type ServerCallFn = (
|
| 24 |
+
spaceId: string,
|
| 25 |
+
endpoint: string,
|
| 26 |
+
argsJson: string
|
| 27 |
+
) => Promise<string>;
|
| 28 |
+
type ServerCallModelFn = (
|
| 29 |
+
modelId: string,
|
| 30 |
+
pipelineTag: string,
|
| 31 |
+
argsJson: string,
|
| 32 |
+
provider?: string
|
| 33 |
+
) => Promise<string>;
|
| 34 |
+
type ServerFetchDatasetFn = (
|
| 35 |
+
datasetId: string,
|
| 36 |
+
config: string,
|
| 37 |
+
split: string,
|
| 38 |
+
offset: string,
|
| 39 |
+
length: string
|
| 40 |
+
) => Promise<string>;
|
| 41 |
+
type ServerCallPyFn = (fnName: string, argsJson: string) => Promise<string>;
|
| 42 |
+
/**
|
| 43 |
+
* Browser-side streaming for text-generation tasks. Returns the final
|
| 44 |
+
* accumulated string. `onChunk` fires per delta so the executor can call
|
| 45 |
+
* `onOutput` incrementally and the UI updates live as tokens arrive.
|
| 46 |
+
*/
|
| 47 |
+
type StreamTextFn = (
|
| 48 |
+
modelId: string,
|
| 49 |
+
prompt: string,
|
| 50 |
+
provider: string | undefined,
|
| 51 |
+
signal: AbortSignal | undefined,
|
| 52 |
+
onChunk: (delta: string, accumulated: string) => void
|
| 53 |
+
) => Promise<string>;
|
| 54 |
+
|
| 55 |
+
function resolveInputs(
|
| 56 |
+
node: WFNode,
|
| 57 |
+
edges: WFEdge[],
|
| 58 |
+
dataMap: Record<string, Record<string, NodeDataValue>>
|
| 59 |
+
): Record<string, NodeDataValue> {
|
| 60 |
+
const resolved: Record<string, NodeDataValue> = {};
|
| 61 |
+
for (const port of node.inputs) {
|
| 62 |
+
const edge = edges.find(
|
| 63 |
+
(e) => e.to_node_id === node.id && e.to_port_id === port.id
|
| 64 |
+
);
|
| 65 |
+
if (edge) {
|
| 66 |
+
resolved[port.id] =
|
| 67 |
+
dataMap[edge.from_node_id]?.[edge.from_port_id] ?? null;
|
| 68 |
+
} else {
|
| 69 |
+
resolved[port.id] =
|
| 70 |
+
node.data?.[port.id] ?? (port.default_value as NodeDataValue) ?? null;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
return resolved;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
async function toGradioArg(value: NodeDataValue): Promise<unknown> {
|
| 77 |
+
if (value === null) return null;
|
| 78 |
+
if (typeof value === "string") return value;
|
| 79 |
+
if (typeof value === "number") return value;
|
| 80 |
+
if (typeof value === "boolean") return value;
|
| 81 |
+
const fileVal = value as FileValue;
|
| 82 |
+
// Blob URLs need to be uploaded to our Gradio server first
|
| 83 |
+
if (fileVal.url.startsWith("blob:") || fileVal.url.startsWith("data:")) {
|
| 84 |
+
try {
|
| 85 |
+
const response = await fetch(fileVal.url);
|
| 86 |
+
if (!response.ok)
|
| 87 |
+
throw new Error(`Blob fetch failed: ${response.status}`);
|
| 88 |
+
const blob = await response.blob();
|
| 89 |
+
const formData = new FormData();
|
| 90 |
+
formData.append("files", blob, fileVal.name || "file");
|
| 91 |
+
// Try /gradio_api/upload first, then /upload
|
| 92 |
+
for (const path of ["/gradio_api/upload", "/upload"]) {
|
| 93 |
+
const uploadRes = await fetch(path, { method: "POST", body: formData });
|
| 94 |
+
if (uploadRes.ok) {
|
| 95 |
+
const files = await uploadRes.json();
|
| 96 |
+
return { path: files[0], url: files[0] };
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
throw new Error("Upload failed");
|
| 100 |
+
} catch (err) {
|
| 101 |
+
console.error("[Executor] File upload error:", err);
|
| 102 |
+
throw new Error(
|
| 103 |
+
`Failed to upload file: ${err instanceof Error ? err.message : err}`
|
| 104 |
+
);
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
// Remote URLs can be passed directly
|
| 108 |
+
return { url: fileVal.url };
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
const MEDIA_PORT_TYPES = new Set([
|
| 112 |
+
"image",
|
| 113 |
+
"audio",
|
| 114 |
+
"video",
|
| 115 |
+
"file",
|
| 116 |
+
"gallery",
|
| 117 |
+
"model3d"
|
| 118 |
+
]);
|
| 119 |
+
|
| 120 |
+
function output_matches_port_type(item: unknown, portType: string): boolean {
|
| 121 |
+
if (item === null || item === undefined) return false;
|
| 122 |
+
if (MEDIA_PORT_TYPES.has(portType)) {
|
| 123 |
+
if (typeof item === "string") {
|
| 124 |
+
return /^(https?:|blob:|data:|\/)/.test(item);
|
| 125 |
+
}
|
| 126 |
+
return (
|
| 127 |
+
typeof item === "object" &&
|
| 128 |
+
("path" in (item as object) || "url" in (item as object))
|
| 129 |
+
);
|
| 130 |
+
}
|
| 131 |
+
if (portType === "text") return typeof item === "string";
|
| 132 |
+
if (portType === "number") return typeof item === "number";
|
| 133 |
+
if (portType === "boolean") return typeof item === "boolean";
|
| 134 |
+
if (portType === "json")
|
| 135 |
+
return typeof item === "object" || Array.isArray(item);
|
| 136 |
+
return true;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
function pick_response_item(
|
| 140 |
+
port: { type: string; output_index?: number },
|
| 141 |
+
port_index: number,
|
| 142 |
+
output_data: unknown[],
|
| 143 |
+
total_ports: number
|
| 144 |
+
): unknown {
|
| 145 |
+
const primary =
|
| 146 |
+
typeof port.output_index === "number"
|
| 147 |
+
? output_data[port.output_index]
|
| 148 |
+
: total_ports === 1 && output_data.length > 1
|
| 149 |
+
? null
|
| 150 |
+
: output_data[port_index];
|
| 151 |
+
|
| 152 |
+
if (primary != null && output_matches_port_type(primary, port.type)) {
|
| 153 |
+
return primary;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
const shape_match = output_data.find((item) =>
|
| 157 |
+
output_matches_port_type(item, port.type)
|
| 158 |
+
);
|
| 159 |
+
if (shape_match !== undefined) return shape_match;
|
| 160 |
+
|
| 161 |
+
return primary ?? output_data[0] ?? null;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
function fromGradioOutput(result: unknown, portType: string): NodeDataValue {
|
| 165 |
+
if (result === null || result === undefined) return null;
|
| 166 |
+
if (
|
| 167 |
+
typeof result === "object" &&
|
| 168 |
+
!Array.isArray(result) &&
|
| 169 |
+
(result as Record<string, unknown>).__type__ === "update" &&
|
| 170 |
+
"value" in (result as Record<string, unknown>)
|
| 171 |
+
) {
|
| 172 |
+
return fromGradioOutput(
|
| 173 |
+
(result as Record<string, unknown>).value,
|
| 174 |
+
portType
|
| 175 |
+
);
|
| 176 |
+
}
|
| 177 |
+
if (Array.isArray(result)) {
|
| 178 |
+
if (result.length === 0) return null;
|
| 179 |
+
return fromGradioOutput(result[result.length - 1], portType);
|
| 180 |
+
}
|
| 181 |
+
if (typeof result === "number") return result;
|
| 182 |
+
if (typeof result === "boolean") return result;
|
| 183 |
+
if (typeof result === "string") {
|
| 184 |
+
if (
|
| 185 |
+
portType !== "text" &&
|
| 186 |
+
(result.startsWith("http://") ||
|
| 187 |
+
result.startsWith("https://") ||
|
| 188 |
+
result.startsWith("blob:") ||
|
| 189 |
+
result.startsWith("data:"))
|
| 190 |
+
) {
|
| 191 |
+
return {
|
| 192 |
+
name: "output",
|
| 193 |
+
url: result,
|
| 194 |
+
mime:
|
| 195 |
+
portType === "image"
|
| 196 |
+
? "image/png"
|
| 197 |
+
: portType === "audio"
|
| 198 |
+
? "audio/wav"
|
| 199 |
+
: "video/mp4"
|
| 200 |
+
} satisfies FileValue;
|
| 201 |
+
}
|
| 202 |
+
return result;
|
| 203 |
+
}
|
| 204 |
+
if (
|
| 205 |
+
typeof result === "object" &&
|
| 206 |
+
"url" in (result as Record<string, unknown>)
|
| 207 |
+
) {
|
| 208 |
+
const obj = result as Record<string, unknown>;
|
| 209 |
+
return {
|
| 210 |
+
name: (obj.orig_name as string) ?? "output",
|
| 211 |
+
url: obj.url as string,
|
| 212 |
+
mime: (obj.mime_type as string) ?? "application/octet-stream"
|
| 213 |
+
} satisfies FileValue;
|
| 214 |
+
}
|
| 215 |
+
return String(result);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
export async function executeWorkflow(
|
| 219 |
+
workflow: Workflow,
|
| 220 |
+
onStatus: StatusCallback,
|
| 221 |
+
onOutput: OutputCallback,
|
| 222 |
+
signal?: AbortSignal,
|
| 223 |
+
serverCallSpace?: ServerCallFn,
|
| 224 |
+
serverCallModel?: ServerCallModelFn,
|
| 225 |
+
serverFetchDataset?: ServerFetchDatasetFn,
|
| 226 |
+
serverCallFn?: ServerCallPyFn,
|
| 227 |
+
stream_text_generation?: StreamTextFn
|
| 228 |
+
): Promise<void> {
|
| 229 |
+
const { nodes, edges } = toLegacyShape(workflow);
|
| 230 |
+
const dataMap: Record<string, Record<string, NodeDataValue>> = {};
|
| 231 |
+
const failed_nodes = new Map<string, string>();
|
| 232 |
+
|
| 233 |
+
function mark_node_failed(node: WFNode, err: unknown): void {
|
| 234 |
+
const msg = err instanceof Error ? err.message : String(err);
|
| 235 |
+
const errorType = (err as { errorType?: string })?.errorType;
|
| 236 |
+
onStatus(node.id, "error", msg, errorType);
|
| 237 |
+
failed_nodes.set(node.id, node.label);
|
| 238 |
+
dataMap[node.id] = {};
|
| 239 |
+
for (const port of node.outputs) dataMap[node.id][port.id] = null;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
function missing_input_message(node: WFNode, port: Port): string {
|
| 243 |
+
const edge = edges.find(
|
| 244 |
+
(e) => e.to_node_id === node.id && e.to_port_id === port.id
|
| 245 |
+
);
|
| 246 |
+
if (edge) {
|
| 247 |
+
const upstream = nodes.find((n) => n.id === edge.from_node_id);
|
| 248 |
+
if (upstream && failed_nodes.has(upstream.id)) {
|
| 249 |
+
return `"${port.label}" is missing β upstream node "${upstream.label}" failed`;
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
return `"${port.label}" is missing β an upstream node may have failed`;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
// Seed input nodes (including component nodes with no incoming edges)
|
| 256 |
+
for (const node of nodes.filter((n) => {
|
| 257 |
+
if (n.kind === "input") return true;
|
| 258 |
+
if (n.kind === "component") {
|
| 259 |
+
return !edges.some((e) => e.to_node_id === n.id);
|
| 260 |
+
}
|
| 261 |
+
return false;
|
| 262 |
+
})) {
|
| 263 |
+
dataMap[node.id] = { ...(node.data ?? {}) };
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
// Build layers for parallel execution
|
| 267 |
+
const sorted = topoSort(nodes, edges);
|
| 268 |
+
const layers: WFNode[][] = [];
|
| 269 |
+
for (const node of sorted) {
|
| 270 |
+
const depDepth = edges
|
| 271 |
+
.filter((e) => e.to_node_id === node.id)
|
| 272 |
+
.map((e) =>
|
| 273 |
+
layers.findIndex((layer) => layer.some((n) => n.id === e.from_node_id))
|
| 274 |
+
)
|
| 275 |
+
.reduce((max, d) => Math.max(max, d), -1);
|
| 276 |
+
const layerIdx = depDepth + 1;
|
| 277 |
+
while (layers.length <= layerIdx) layers.push([]);
|
| 278 |
+
layers[layerIdx].push(node);
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
async function executeNode(node: WFNode): Promise<void> {
|
| 282 |
+
if (signal?.aborted) return;
|
| 283 |
+
|
| 284 |
+
// Component nodes with no incoming edges act as inputs
|
| 285 |
+
const isComponentInput =
|
| 286 |
+
node.kind === "component" && !edges.some((e) => e.to_node_id === node.id);
|
| 287 |
+
|
| 288 |
+
// Dataset operators take a single scalar "row_index" input. When wired,
|
| 289 |
+
// upstream supplies the offset; when unwired the inline default (set at
|
| 290 |
+
// picker time, edited on the node body) is used.
|
| 291 |
+
if (node.source === "dataset" && node.dataset_id) {
|
| 292 |
+
onStatus(node.id, "running");
|
| 293 |
+
try {
|
| 294 |
+
if (!serverFetchDataset)
|
| 295 |
+
throw new Error("Dataset fetch function not available");
|
| 296 |
+
const inputs = resolveInputs(node, edges, dataMap);
|
| 297 |
+
const raw = inputs["row_index"] ?? 0;
|
| 298 |
+
const n = typeof raw === "number" ? raw : Number(raw);
|
| 299 |
+
const offset = Math.max(0, Math.trunc(Number.isFinite(n) ? n : 0));
|
| 300 |
+
const resultJson = await serverFetchDataset(
|
| 301 |
+
node.dataset_id,
|
| 302 |
+
node.dataset_config ?? "default",
|
| 303 |
+
node.dataset_split ?? "train",
|
| 304 |
+
String(offset),
|
| 305 |
+
"1"
|
| 306 |
+
);
|
| 307 |
+
const result = JSON.parse(resultJson);
|
| 308 |
+
if (result.error) throw new Error(result.error);
|
| 309 |
+
|
| 310 |
+
const row = result.rows?.[0] ?? {};
|
| 311 |
+
dataMap[node.id] = {};
|
| 312 |
+
for (const port of node.outputs) {
|
| 313 |
+
const value = row[port.label] ?? null;
|
| 314 |
+
// Convert image/audio objects to file values
|
| 315 |
+
if (value && typeof value === "object" && "src" in value) {
|
| 316 |
+
const fileVal = {
|
| 317 |
+
name: port.label,
|
| 318 |
+
url: value.src,
|
| 319 |
+
mime: "application/octet-stream"
|
| 320 |
+
};
|
| 321 |
+
dataMap[node.id][port.id] = fileVal as NodeDataValue;
|
| 322 |
+
onOutput(node.id, port.id, fileVal as NodeDataValue);
|
| 323 |
+
} else {
|
| 324 |
+
dataMap[node.id][port.id] = value as NodeDataValue;
|
| 325 |
+
onOutput(node.id, port.id, value as NodeDataValue);
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
onStatus(node.id, "done");
|
| 329 |
+
} catch (err) {
|
| 330 |
+
mark_node_failed(node, err);
|
| 331 |
+
}
|
| 332 |
+
return;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
if (node.kind === "input" || isComponentInput) {
|
| 336 |
+
onStatus(node.id, "done");
|
| 337 |
+
return;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
// Component nodes with incoming edges act as outputs
|
| 341 |
+
const isComponentOutput =
|
| 342 |
+
node.kind === "component" && edges.some((e) => e.to_node_id === node.id);
|
| 343 |
+
if (node.kind === "output" || isComponentOutput) {
|
| 344 |
+
const inputs = resolveInputs(node, edges, dataMap);
|
| 345 |
+
const inputPort = node.inputs[0];
|
| 346 |
+
if (inputPort) {
|
| 347 |
+
const value = inputs[inputPort.id];
|
| 348 |
+
dataMap[node.id] = { [inputPort.id]: value };
|
| 349 |
+
onOutput(node.id, inputPort.id, value);
|
| 350 |
+
const outputPort = node.outputs[0];
|
| 351 |
+
if (outputPort) {
|
| 352 |
+
dataMap[node.id][outputPort.id] = value;
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
onStatus(node.id, "done");
|
| 356 |
+
return;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
// Python function nodes (FnNode) call back to the Python server
|
| 360 |
+
if (node.source === "fn" && node.fn) {
|
| 361 |
+
onStatus(node.id, "running");
|
| 362 |
+
try {
|
| 363 |
+
if (!serverCallFn)
|
| 364 |
+
throw new Error("Python function call not available");
|
| 365 |
+
const inputs = resolveInputs(node, edges, dataMap);
|
| 366 |
+
for (const port of node.inputs) {
|
| 367 |
+
if (port.required && inputs[port.id] === null) {
|
| 368 |
+
throw new Error(missing_input_message(node, port));
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
const args = node.inputs.map((port) => inputs[port.id]);
|
| 372 |
+
const resultJson = await serverCallFn(node.fn, JSON.stringify(args));
|
| 373 |
+
const resultData = JSON.parse(resultJson);
|
| 374 |
+
if (
|
| 375 |
+
resultData &&
|
| 376 |
+
typeof resultData === "object" &&
|
| 377 |
+
"error" in resultData
|
| 378 |
+
) {
|
| 379 |
+
throw new Error(resultData.error);
|
| 380 |
+
}
|
| 381 |
+
dataMap[node.id] = {};
|
| 382 |
+
const outputData = Array.isArray(resultData)
|
| 383 |
+
? resultData
|
| 384 |
+
: [resultData];
|
| 385 |
+
node.outputs.forEach((port, i) => {
|
| 386 |
+
const value = fromGradioOutput(outputData[i] ?? null, port.type);
|
| 387 |
+
dataMap[node.id][port.id] = value;
|
| 388 |
+
onOutput(node.id, port.id, value);
|
| 389 |
+
});
|
| 390 |
+
onStatus(node.id, "done");
|
| 391 |
+
} catch (err) {
|
| 392 |
+
mark_node_failed(node, err);
|
| 393 |
+
}
|
| 394 |
+
return;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
if (node.kind === "transform" && (node.space_id || node.model_id)) {
|
| 398 |
+
onStatus(node.id, "running");
|
| 399 |
+
|
| 400 |
+
try {
|
| 401 |
+
const inputs = resolveInputs(node, edges, dataMap);
|
| 402 |
+
for (const port of node.inputs) {
|
| 403 |
+
if (port.required && inputs[port.id] === null) {
|
| 404 |
+
throw new Error(missing_input_message(node, port));
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
const args = await Promise.all(
|
| 408 |
+
node.inputs.map((port) => toGradioArg(inputs[port.id]))
|
| 409 |
+
);
|
| 410 |
+
|
| 411 |
+
let resultJson: string;
|
| 412 |
+
|
| 413 |
+
if (node.source === "model" && node.model_id) {
|
| 414 |
+
if (!serverCallModel) {
|
| 415 |
+
throw new Error("Model call function not available");
|
| 416 |
+
}
|
| 417 |
+
// Prefer browser-side streaming for chat-completion-compatible
|
| 418 |
+
// text tasks so the UI receives tokens as they arrive. The
|
| 419 |
+
// Python path stays for every other task.
|
| 420 |
+
const tag = node.pipeline_tag ?? "text-generation";
|
| 421 |
+
const streamable =
|
| 422 |
+
(tag === "text-generation" ||
|
| 423 |
+
tag === "text2text-generation" ||
|
| 424 |
+
tag === "conversational") &&
|
| 425 |
+
!!stream_text_generation;
|
| 426 |
+
if (streamable) {
|
| 427 |
+
const prompt =
|
| 428 |
+
typeof args[0] === "string" ? args[0] : String(args[0] ?? "");
|
| 429 |
+
const outputPort = node.outputs[0];
|
| 430 |
+
const final = await stream_text_generation!(
|
| 431 |
+
node.model_id,
|
| 432 |
+
prompt,
|
| 433 |
+
node.provider,
|
| 434 |
+
signal,
|
| 435 |
+
(_delta, accumulated) => {
|
| 436 |
+
if (outputPort) onOutput(node.id, outputPort.id, accumulated);
|
| 437 |
+
}
|
| 438 |
+
);
|
| 439 |
+
resultJson = JSON.stringify([final]);
|
| 440 |
+
} else {
|
| 441 |
+
resultJson = await Promise.race([
|
| 442 |
+
serverCallModel(
|
| 443 |
+
node.model_id,
|
| 444 |
+
tag,
|
| 445 |
+
JSON.stringify(args),
|
| 446 |
+
node.provider
|
| 447 |
+
),
|
| 448 |
+
new Promise<never>((_, reject) =>
|
| 449 |
+
setTimeout(
|
| 450 |
+
() =>
|
| 451 |
+
reject(
|
| 452 |
+
new Error("Request timed out β model may be loading")
|
| 453 |
+
),
|
| 454 |
+
300000
|
| 455 |
+
)
|
| 456 |
+
)
|
| 457 |
+
]);
|
| 458 |
+
}
|
| 459 |
+
} else {
|
| 460 |
+
const endpointName = node.endpoint ?? "/predict";
|
| 461 |
+
if (!serverCallSpace) {
|
| 462 |
+
throw new Error("Server call function not available");
|
| 463 |
+
}
|
| 464 |
+
resultJson = await Promise.race([
|
| 465 |
+
serverCallSpace(node.space_id!, endpointName, JSON.stringify(args)),
|
| 466 |
+
new Promise<never>((_, reject) =>
|
| 467 |
+
setTimeout(
|
| 468 |
+
() =>
|
| 469 |
+
reject(
|
| 470 |
+
new Error("Request timed out β Space may be overloaded")
|
| 471 |
+
),
|
| 472 |
+
300000
|
| 473 |
+
)
|
| 474 |
+
)
|
| 475 |
+
]);
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
const resultData = JSON.parse(resultJson);
|
| 479 |
+
|
| 480 |
+
// Check for structured error from Python
|
| 481 |
+
if (
|
| 482 |
+
resultData &&
|
| 483 |
+
typeof resultData === "object" &&
|
| 484 |
+
"error" in resultData
|
| 485 |
+
) {
|
| 486 |
+
const suggestion = resultData.suggestion;
|
| 487 |
+
const errorType = resultData.error_type;
|
| 488 |
+
const title = resultData.title;
|
| 489 |
+
const rawMsg = title
|
| 490 |
+
? `${title}: ${resultData.error}`
|
| 491 |
+
: resultData.error;
|
| 492 |
+
const msg = suggestion || rawMsg;
|
| 493 |
+
const err = new Error(msg);
|
| 494 |
+
(err as any).errorType = errorType;
|
| 495 |
+
throw err;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
dataMap[node.id] = {};
|
| 499 |
+
const outputData = Array.isArray(resultData)
|
| 500 |
+
? resultData
|
| 501 |
+
: [resultData];
|
| 502 |
+
node.outputs.forEach((port, i) => {
|
| 503 |
+
const raw = pick_response_item(
|
| 504 |
+
port,
|
| 505 |
+
i,
|
| 506 |
+
outputData,
|
| 507 |
+
node.outputs.length
|
| 508 |
+
);
|
| 509 |
+
const value = fromGradioOutput(raw, port.type);
|
| 510 |
+
dataMap[node.id][port.id] = value;
|
| 511 |
+
onOutput(node.id, port.id, value);
|
| 512 |
+
});
|
| 513 |
+
|
| 514 |
+
onStatus(node.id, "done");
|
| 515 |
+
} catch (err) {
|
| 516 |
+
mark_node_failed(node, err);
|
| 517 |
+
}
|
| 518 |
+
}
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
// Execute layers in parallel
|
| 522 |
+
for (const layer of layers) {
|
| 523 |
+
if (signal?.aborted) break;
|
| 524 |
+
await Promise.all(layer.map(executeNode));
|
| 525 |
+
}
|
| 526 |
+
}
|
6.17.1/workflowcanvas/workflow/workflow-graph.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Pure graph utilities used by the canvas β extracted so they can be
|
| 3 |
+
* unit-tested without standing up a Svelte component. Anything that
|
| 4 |
+
* computes a value from the workflow / node lists / edges and doesn't
|
| 5 |
+
* touch the DOM lives here.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
import type { NodeStatus, WFEdge, WFNode, Workflow } from "./workflow-types";
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* Walk diagonally from (x, y) in 28px steps until an open spot is found
|
| 12 |
+
* that doesn't visually overlap an existing node. Used by code paths
|
| 13 |
+
* that drop a fresh node at a fixed fallback position (canvas center,
|
| 14 |
+
* picker create, etc.) β without this, successive adds stack identically.
|
| 15 |
+
*/
|
| 16 |
+
export function findFreeSpot(
|
| 17 |
+
nodes: { x: number; y: number }[],
|
| 18 |
+
x: number,
|
| 19 |
+
y: number
|
| 20 |
+
): { x: number; y: number } {
|
| 21 |
+
let nx = x;
|
| 22 |
+
let ny = y;
|
| 23 |
+
while (nodes.some((n) => Math.abs(n.x - nx) < 8 && Math.abs(n.y - ny) < 8)) {
|
| 24 |
+
nx += 28;
|
| 25 |
+
ny += 28;
|
| 26 |
+
}
|
| 27 |
+
return { x: nx, y: ny };
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Topological sort: returns a sorted list of nodes such that every edge
|
| 32 |
+
* goes from an earlier node to a later one. Standard Kahn's algorithm.
|
| 33 |
+
*/
|
| 34 |
+
export function topoSort(nodes: WFNode[], edges: WFEdge[]): WFNode[] {
|
| 35 |
+
const deg = new Map(nodes.map((n) => [n.id, 0]));
|
| 36 |
+
for (const e of edges)
|
| 37 |
+
deg.set(e.to_node_id, (deg.get(e.to_node_id) ?? 0) + 1);
|
| 38 |
+
const q = nodes.filter((n) => deg.get(n.id) === 0);
|
| 39 |
+
const out: WFNode[] = [];
|
| 40 |
+
while (q.length) {
|
| 41 |
+
const n = q.shift()!;
|
| 42 |
+
out.push(n);
|
| 43 |
+
for (const e of edges.filter((e) => e.from_node_id === n.id)) {
|
| 44 |
+
const d = (deg.get(e.to_node_id) ?? 1) - 1;
|
| 45 |
+
deg.set(e.to_node_id, d);
|
| 46 |
+
if (d === 0) q.push(nodes.find((nd) => nd.id === e.to_node_id)!);
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
return out;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Compute the effective input values for a node right now β mirrors the
|
| 54 |
+
* executor's `resolveInputs` so the canvas can detect staleness without
|
| 55 |
+
* re-running the graph. For each input port:
|
| 56 |
+
* - if wired, take the upstream node's stored data for that output port,
|
| 57 |
+
* - otherwise fall back to the node's own inline data or port default.
|
| 58 |
+
*/
|
| 59 |
+
export function resolveCurrentInputs(
|
| 60 |
+
node: WFNode,
|
| 61 |
+
allNodes: WFNode[],
|
| 62 |
+
edges: WFEdge[]
|
| 63 |
+
): Record<string, unknown> {
|
| 64 |
+
const resolved: Record<string, unknown> = {};
|
| 65 |
+
for (const port of node.inputs) {
|
| 66 |
+
const edge = edges.find(
|
| 67 |
+
(e) => e.to_node_id === node.id && e.to_port_id === port.id
|
| 68 |
+
);
|
| 69 |
+
if (edge) {
|
| 70 |
+
const upstream = allNodes.find((n) => n.id === edge.from_node_id);
|
| 71 |
+
resolved[port.id] = upstream?.data?.[edge.from_port_id] ?? null;
|
| 72 |
+
} else {
|
| 73 |
+
resolved[port.id] = node.data?.[port.id] ?? port.default_value ?? null;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
return resolved;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Compute the set of node IDs that are currently "stale": their last
|
| 81 |
+
* successful run happened with inputs that no longer match the current
|
| 82 |
+
* ones, OR an upstream node is stale (so re-running will change this
|
| 83 |
+
* one's inputs). Walks in topological order so transitive staleness
|
| 84 |
+
* propagates in a single pass.
|
| 85 |
+
*
|
| 86 |
+
* Pattern lifted from `gradio-app/daggr`'s edge-stale derivation.
|
| 87 |
+
*/
|
| 88 |
+
export function computeStaleNodes(
|
| 89 |
+
nodes: WFNode[],
|
| 90 |
+
edges: WFEdge[],
|
| 91 |
+
nodeStatus: Record<string, NodeStatus>,
|
| 92 |
+
inputSnapshots: Record<string, string>
|
| 93 |
+
): Set<string> {
|
| 94 |
+
const stale = new Set<string>();
|
| 95 |
+
const sorted = topoSort(nodes, edges);
|
| 96 |
+
for (const node of sorted) {
|
| 97 |
+
if (nodeStatus[node.id] !== "done") continue;
|
| 98 |
+
const snapshot = inputSnapshots[node.id];
|
| 99 |
+
if (
|
| 100 |
+
snapshot &&
|
| 101 |
+
JSON.stringify(resolveCurrentInputs(node, nodes, edges)) !== snapshot
|
| 102 |
+
) {
|
| 103 |
+
stale.add(node.id);
|
| 104 |
+
continue;
|
| 105 |
+
}
|
| 106 |
+
for (const edge of edges) {
|
| 107 |
+
if (edge.to_node_id === node.id && stale.has(edge.from_node_id)) {
|
| 108 |
+
stale.add(node.id);
|
| 109 |
+
break;
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
return stale;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Build a sub-workflow containing `targetId` plus all of its transitive
|
| 118 |
+
* upstream dependencies. Used by per-node "run this" so we don't execute
|
| 119 |
+
* unrelated branches. Node IDs are stable, so callbacks from the executor
|
| 120 |
+
* still target the same status / output maps in the caller.
|
| 121 |
+
*/
|
| 122 |
+
export function buildUpstreamSubgraph(
|
| 123 |
+
workflow: Workflow,
|
| 124 |
+
targetId: string
|
| 125 |
+
): Workflow {
|
| 126 |
+
const include = new Set<string>([targetId]);
|
| 127 |
+
const queue = [targetId];
|
| 128 |
+
while (queue.length) {
|
| 129 |
+
const cur = queue.shift()!;
|
| 130 |
+
for (const e of workflow.edges) {
|
| 131 |
+
if (e.to_node_id === cur && !include.has(e.from_node_id)) {
|
| 132 |
+
include.add(e.from_node_id);
|
| 133 |
+
queue.push(e.from_node_id);
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
return {
|
| 138 |
+
...workflow,
|
| 139 |
+
references: workflow.references.filter((n) => include.has(n.id)),
|
| 140 |
+
operators: workflow.operators.filter((n) => include.has(n.id)),
|
| 141 |
+
subjects: workflow.subjects.filter((n) => include.has(n.id)),
|
| 142 |
+
edges: workflow.edges.filter(
|
| 143 |
+
(e) => include.has(e.from_node_id) && include.has(e.to_node_id)
|
| 144 |
+
)
|
| 145 |
+
};
|
| 146 |
+
}
|
6.17.1/workflowcanv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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Schema v1 β v2 migration.
|
| 3 |
+
*
|
| 4 |
+
* v1 stored a flat `nodes` array tagged with `kind: "component" | "transform" | β¦`.
|
| 5 |
+
* v2 splits that into three role-collections (references / operators / subjects)
|
| 6 |
+
* so the data model expresses authoring intent, not just data flow. The graph
|
| 7 |
+
* topology is preserved exactly β edges still reference node ids β but the role
|
| 8 |
+
* tag drives studio-view rendering and lets future tooling reason about a
|
| 9 |
+
* workflow without re-deriving roles from edge topology every time.
|
| 10 |
+
*
|
| 11 |
+
* The migration is purposely conservative: when in doubt, prefer the role that
|
| 12 |
+
* keeps existing behavior (e.g. transforms always become operators, components
|
| 13 |
+
* become references unless they have incoming edges, in which case they're
|
| 14 |
+
* subjects).
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
import type {
|
| 18 |
+
AnyNode,
|
| 19 |
+
OperatorKind,
|
| 20 |
+
OperatorNode,
|
| 21 |
+
PortType,
|
| 22 |
+
ReferenceNode,
|
| 23 |
+
SubjectNode,
|
| 24 |
+
WFEdge,
|
| 25 |
+
WFNode,
|
| 26 |
+
Workflow,
|
| 27 |
+
WorkflowV1
|
| 28 |
+
} from "./workflow-types";
|
| 29 |
+
|
| 30 |
+
export function isV2(wf: unknown): wf is Workflow {
|
| 31 |
+
if (!wf || typeof wf !== "object") return false;
|
| 32 |
+
const w = wf as Record<string, unknown>;
|
| 33 |
+
return (
|
| 34 |
+
w.schema_version === "2" &&
|
| 35 |
+
Array.isArray(w.references) &&
|
| 36 |
+
Array.isArray(w.operators) &&
|
| 37 |
+
Array.isArray(w.subjects) &&
|
| 38 |
+
Array.isArray(w.edges)
|
| 39 |
+
);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
export function migrateToV2(raw: unknown): Workflow {
|
| 43 |
+
if (isV2(raw)) return raw;
|
| 44 |
+
|
| 45 |
+
const legacy = (raw ?? {}) as WorkflowV1;
|
| 46 |
+
const legacyNodes: WFNode[] = Array.isArray(legacy.nodes) ? legacy.nodes : [];
|
| 47 |
+
const edges: WFEdge[] = Array.isArray(legacy.edges) ? legacy.edges : [];
|
| 48 |
+
|
| 49 |
+
// Nodes with at least one incoming edge are "consumers" β when promoted from
|
| 50 |
+
// a v1 component, those become subjects (output tiles); otherwise references.
|
| 51 |
+
const hasIncoming = new Set<string>();
|
| 52 |
+
for (const e of edges) hasIncoming.add(e.to_node_id);
|
| 53 |
+
|
| 54 |
+
const references: ReferenceNode[] = [];
|
| 55 |
+
const operators: OperatorNode[] = [];
|
| 56 |
+
const subjects: SubjectNode[] = [];
|
| 57 |
+
|
| 58 |
+
for (const n of legacyNodes) {
|
| 59 |
+
const base = {
|
| 60 |
+
id: n.id,
|
| 61 |
+
label: n.label ?? "",
|
| 62 |
+
inputs: n.inputs ?? [],
|
| 63 |
+
outputs: n.outputs ?? [],
|
| 64 |
+
data: n.data ?? {},
|
| 65 |
+
x: n.x ?? 0,
|
| 66 |
+
y: n.y ?? 0,
|
| 67 |
+
width: n.width ?? 200,
|
| 68 |
+
height: n.height ?? 100
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
if (n.kind === "transform") {
|
| 72 |
+
const kind = inferOperatorKind(n);
|
| 73 |
+
operators.push({
|
| 74 |
+
...base,
|
| 75 |
+
role: "operator",
|
| 76 |
+
kind,
|
| 77 |
+
source: deriveSourceUri(n, kind),
|
| 78 |
+
space_id: n.space_id,
|
| 79 |
+
model_id: n.model_id,
|
| 80 |
+
dataset_id: n.dataset_id,
|
| 81 |
+
dataset_config: n.dataset_config,
|
| 82 |
+
dataset_split: n.dataset_split,
|
| 83 |
+
endpoint: n.endpoint,
|
| 84 |
+
pipeline_tag: n.pipeline_tag,
|
| 85 |
+
provider: n.provider,
|
| 86 |
+
fn: n.fn,
|
| 87 |
+
runtime: "client"
|
| 88 |
+
});
|
| 89 |
+
continue;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// Everything else (component / input / output / unknown) maps to either
|
| 93 |
+
// reference or subject based on edge topology.
|
| 94 |
+
const assetType: PortType = (n.outputs?.[0]?.type ??
|
| 95 |
+
n.inputs?.[0]?.type ??
|
| 96 |
+
"any") as PortType;
|
| 97 |
+
|
| 98 |
+
if (hasIncoming.has(n.id)) {
|
| 99 |
+
subjects.push({ ...base, role: "subject", asset_type: assetType });
|
| 100 |
+
} else {
|
| 101 |
+
references.push({ ...base, role: "reference", asset_type: assetType });
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
return {
|
| 106 |
+
schema_version: "2",
|
| 107 |
+
name: legacy.name ?? "My workflow",
|
| 108 |
+
runtime: { default: "client" },
|
| 109 |
+
references,
|
| 110 |
+
operators,
|
| 111 |
+
subjects,
|
| 112 |
+
edges,
|
| 113 |
+
view: { default: "canvas" }
|
| 114 |
+
};
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
function inferOperatorKind(n: WFNode): OperatorKind {
|
| 118 |
+
if (n.space_id || n.source === "space") return "space";
|
| 119 |
+
if (n.model_id || n.source === "model") return "model";
|
| 120 |
+
if (n.dataset_id || n.source === "dataset") return "dataset";
|
| 121 |
+
return "fn";
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function deriveSourceUri(n: WFNode, kind: OperatorKind): string | undefined {
|
| 125 |
+
if (kind === "space" && n.space_id) return `hf://spaces/${n.space_id}`;
|
| 126 |
+
if (kind === "model" && n.model_id) return `hf://${n.model_id}`;
|
| 127 |
+
if (kind === "dataset" && n.dataset_id)
|
| 128 |
+
return `hf://datasets/${n.dataset_id}`;
|
| 129 |
+
if (kind === "fn") return n.fn ?? undefined;
|
| 130 |
+
return undefined;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
// βββ Read helpers β keep store consumers from caring about which array a node lives in β
|
| 134 |
+
|
| 135 |
+
export function allNodes(wf: Workflow): AnyNode[] {
|
| 136 |
+
return [...wf.references, ...wf.operators, ...wf.subjects];
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
export function findNode(wf: Workflow, id: string): AnyNode | undefined {
|
| 140 |
+
return (
|
| 141 |
+
wf.references.find((n) => n.id === id) ??
|
| 142 |
+
wf.operators.find((n) => n.id === id) ??
|
| 143 |
+
wf.subjects.find((n) => n.id === id)
|
| 144 |
+
);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
// βββ v2 β v1 adapter ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 148 |
+
//
|
| 149 |
+
// The executor still reasons about v1 fields (`kind`, `source`, etc.). Rather
|
| 150 |
+
// than rewriting it in the same pass, we expose a one-way projection that
|
| 151 |
+
// reconstructs a v1-shaped node from a v2 node. Cheap, pure, deterministic.
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Project a v2 workflow into the legacy v1 shape that executor + any other
|
| 155 |
+
* still-v1 consumers expect. The migration sets the source identifiers and
|
| 156 |
+
* derives `kind` from role + edge topology so the v1 contract holds exactly.
|
| 157 |
+
*/
|
| 158 |
+
export function toLegacyShape(wf: Workflow): {
|
| 159 |
+
version: "1";
|
| 160 |
+
name: string;
|
| 161 |
+
nodes: WFNode[];
|
| 162 |
+
edges: WFEdge[];
|
| 163 |
+
} {
|
| 164 |
+
const hasIncoming = new Set<string>();
|
| 165 |
+
for (const e of wf.edges) hasIncoming.add(e.to_node_id);
|
| 166 |
+
|
| 167 |
+
const nodes: WFNode[] = [];
|
| 168 |
+
for (const n of wf.references) {
|
| 169 |
+
nodes.push({
|
| 170 |
+
id: n.id,
|
| 171 |
+
kind: "component",
|
| 172 |
+
label: n.label,
|
| 173 |
+
source: "local",
|
| 174 |
+
inputs: n.inputs,
|
| 175 |
+
outputs: n.outputs,
|
| 176 |
+
x: n.x,
|
| 177 |
+
y: n.y,
|
| 178 |
+
width: n.width,
|
| 179 |
+
height: n.height,
|
| 180 |
+
data: n.data
|
| 181 |
+
});
|
| 182 |
+
}
|
| 183 |
+
for (const n of wf.operators) {
|
| 184 |
+
nodes.push({
|
| 185 |
+
id: n.id,
|
| 186 |
+
kind: "transform",
|
| 187 |
+
label: n.label,
|
| 188 |
+
source: n.kind,
|
| 189 |
+
space_id: n.space_id,
|
| 190 |
+
model_id: n.model_id,
|
| 191 |
+
dataset_id: n.dataset_id,
|
| 192 |
+
dataset_config: n.dataset_config,
|
| 193 |
+
dataset_split: n.dataset_split,
|
| 194 |
+
endpoint: n.endpoint,
|
| 195 |
+
endpoints: n.endpoints,
|
| 196 |
+
pipeline_tag: n.pipeline_tag,
|
| 197 |
+
provider: n.provider,
|
| 198 |
+
fn: n.fn,
|
| 199 |
+
inputs: n.inputs,
|
| 200 |
+
outputs: n.outputs,
|
| 201 |
+
x: n.x,
|
| 202 |
+
y: n.y,
|
| 203 |
+
width: n.width,
|
| 204 |
+
height: n.height,
|
| 205 |
+
data: n.data
|
| 206 |
+
});
|
| 207 |
+
}
|
| 208 |
+
for (const n of wf.subjects) {
|
| 209 |
+
nodes.push({
|
| 210 |
+
id: n.id,
|
| 211 |
+
kind: "component",
|
| 212 |
+
label: n.label,
|
| 213 |
+
source: "local",
|
| 214 |
+
inputs: n.inputs,
|
| 215 |
+
outputs: n.outputs,
|
| 216 |
+
x: n.x,
|
| 217 |
+
y: n.y,
|
| 218 |
+
width: n.width,
|
| 219 |
+
height: n.height,
|
| 220 |
+
data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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { PortType } from "./workflow-types";
|
| 2 |
+
|
| 3 |
+
export interface SubTab {
|
| 4 |
+
key: string;
|
| 5 |
+
label: string;
|
| 6 |
+
/**
|
| 7 |
+
* Used as `pipeline_tag=` on the models API AND as `filter=` on the
|
| 8 |
+
* spaces API. For subtabs where Spaces have a category that differs
|
| 9 |
+
* from the model pipeline tag (e.g. Edit β `image-editing` Space
|
| 10 |
+
* category vs `image-to-image` model pipeline tag), use
|
| 11 |
+
* `spaceTags` / `modelTags` to override.
|
| 12 |
+
*/
|
| 13 |
+
pipelineTags: string[];
|
| 14 |
+
/** Override for the spaces API. Falls back to `pipelineTags` when unset. */
|
| 15 |
+
spaceTags?: string[];
|
| 16 |
+
/** Override for the models API. Falls back to `pipelineTags` when unset. */
|
| 17 |
+
modelTags?: string[];
|
| 18 |
+
/** Freetext query fallback (used when no API tag exists, e.g. Enhance for models). */
|
| 19 |
+
query?: string;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
export interface ModalityConfig {
|
| 23 |
+
key: string;
|
| 24 |
+
label: string;
|
| 25 |
+
category: string;
|
| 26 |
+
/**
|
| 27 |
+
* Canonical port type produced by operators in this modality. Reference and
|
| 28 |
+
* subject templates derived from this modality use this type for their port.
|
| 29 |
+
* `null` for datasets (outputs are per-feature, no single canonical type).
|
| 30 |
+
*/
|
| 31 |
+
port_type: PortType | null;
|
| 32 |
+
acceptedCategories?: string[];
|
| 33 |
+
subtabs: SubTab[];
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export const DATASET_MODALITY: ModalityConfig = {
|
| 37 |
+
key: "data",
|
| 38 |
+
label: "Data",
|
| 39 |
+
category: "data",
|
| 40 |
+
port_type: null,
|
| 41 |
+
subtabs: [{ key: "all", label: "All", pipelineTags: [] }]
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
export const MODEL_MODALITY: ModalityConfig = {
|
| 45 |
+
key: "model",
|
| 46 |
+
label: "Models",
|
| 47 |
+
category: "model",
|
| 48 |
+
port_type: null,
|
| 49 |
+
subtabs: [
|
| 50 |
+
{ key: "all", label: "All", pipelineTags: [] },
|
| 51 |
+
{
|
| 52 |
+
key: "text-to-image",
|
| 53 |
+
label: "TextβImage",
|
| 54 |
+
pipelineTags: ["text-to-image"]
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
key: "text-generation",
|
| 58 |
+
label: "Text Gen",
|
| 59 |
+
pipelineTags: ["text-generation"]
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
key: "image-to-text",
|
| 63 |
+
label: "ImageβText",
|
| 64 |
+
pipelineTags: ["image-to-text"]
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
key: "asr",
|
| 68 |
+
label: "ASR",
|
| 69 |
+
pipelineTags: ["automatic-speech-recognition"]
|
| 70 |
+
},
|
| 71 |
+
{ key: "tts", label: "TTS", pipelineTags: ["text-to-speech"] },
|
| 72 |
+
{
|
| 73 |
+
key: "text-to-video",
|
| 74 |
+
label: "TextβVideo",
|
| 75 |
+
pipelineTags: ["text-to-video"]
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
key: "image-to-image",
|
| 79 |
+
label: "ImageβImage",
|
| 80 |
+
pipelineTags: ["image-to-image"]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
key: "image-to-video",
|
| 84 |
+
label: "ImageβVideo",
|
| 85 |
+
pipelineTags: ["image-to-video"]
|
| 86 |
+
}
|
| 87 |
+
]
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
export const MODALITIES: ModalityConfig[] = [
|
| 91 |
+
{
|
| 92 |
+
key: "image",
|
| 93 |
+
label: "Image",
|
| 94 |
+
category: "image",
|
| 95 |
+
port_type: "image",
|
| 96 |
+
subtabs: [
|
| 97 |
+
{ key: "all", label: "All", pipelineTags: [] },
|
| 98 |
+
{
|
| 99 |
+
key: "generate",
|
| 100 |
+
label: "Generate",
|
| 101 |
+
pipelineTags: ["text-to-image"],
|
| 102 |
+
spaceTags: ["image-generation"]
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
key: "edit",
|
| 106 |
+
label: "Edit",
|
| 107 |
+
pipelineTags: ["image-to-image"],
|
| 108 |
+
spaceTags: ["image-editing"]
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
key: "enhance",
|
| 112 |
+
label: "Enhance",
|
| 113 |
+
pipelineTags: [],
|
| 114 |
+
spaceTags: ["image-upscaling"],
|
| 115 |
+
query: "upscale super resolution restore enhance denoise"
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
key: "detect",
|
| 119 |
+
label: "Detect",
|
| 120 |
+
pipelineTags: ["object-detection", "image-segmentation"]
|
| 121 |
+
},
|
| 122 |
+
{
|
| 123 |
+
key: "removebg",
|
| 124 |
+
label: "Remove Background",
|
| 125 |
+
pipelineTags: [],
|
| 126 |
+
spaceTags: ["background-removal"],
|
| 127 |
+
query: "background removal remove background matting"
|
| 128 |
+
}
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
key: "audio",
|
| 133 |
+
label: "Audio",
|
| 134 |
+
category: "audio",
|
| 135 |
+
port_type: "audio",
|
| 136 |
+
subtabs: [
|
| 137 |
+
{ key: "all", label: "All", pipelineTags: [] },
|
| 138 |
+
{
|
| 139 |
+
key: "speech",
|
| 140 |
+
label: "Speech",
|
| 141 |
+
pipelineTags: ["text-to-speech"],
|
| 142 |
+
spaceTags: ["speech-synthesis"]
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
key: "music",
|
| 146 |
+
label: "Music",
|
| 147 |
+
pipelineTags: ["text-to-audio"],
|
| 148 |
+
spaceTags: ["music-generation"],
|
| 149 |
+
query: "music generation"
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
key: "transcribe",
|
| 153 |
+
label: "Transcribe",
|
| 154 |
+
pipelineTags: ["automatic-speech-recognition"],
|
| 155 |
+
// No matching HF Space category for ASR; freeform query
|
| 156 |
+
// catches the major transcription Spaces.
|
| 157 |
+
query: "speech recognition transcription whisper subtitle"
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
key: "clone",
|
| 161 |
+
label: "Clone Voice",
|
| 162 |
+
pipelineTags: [],
|
| 163 |
+
spaceTags: ["voice-cloning"],
|
| 164 |
+
query: "voice clone"
|
| 165 |
+
}
|
| 166 |
+
]
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
key: "video",
|
| 170 |
+
label: "Video",
|
| 171 |
+
category: "video",
|
| 172 |
+
port_type: "video",
|
| 173 |
+
subtabs: [
|
| 174 |
+
{ key: "all", label: "All", pipelineTags: [] },
|
| 175 |
+
{
|
| 176 |
+
key: "generate",
|
| 177 |
+
label: "Generate",
|
| 178 |
+
pipelineTags: ["text-to-video"],
|
| 179 |
+
spaceTags: ["video-generation"]
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
key: "animate",
|
| 183 |
+
label: "Animate",
|
| 184 |
+
pipelineTags: ["image-to-video"],
|
| 185 |
+
spaceTags: ["character-animation"]
|
| 186 |
+
}
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
key: "3d",
|
| 191 |
+
label: "3D",
|
| 192 |
+
category: "3d",
|
| 193 |
+
port_type: "model3d",
|
| 194 |
+
subtabs: [
|
| 195 |
+
{ key: "all", label: "All", pipelineTags: [] },
|
| 196 |
+
{
|
| 197 |
+
key: "from-text",
|
| 198 |
+
label: "From Text",
|
| 199 |
+
pipelineTags: ["text-to-3d"],
|
| 200 |
+
spaceTags: ["3d-modeling"]
|
| 201 |
+
},
|
| 202 |
+
{
|
| 203 |
+
key: "from-image",
|
| 204 |
+
label: "From Image",
|
| 205 |
+
pipelineTags: ["image-to-3d"],
|
| 206 |
+
spaceTags: ["3d-modeling"]
|
| 207 |
+
}
|
| 208 |
+
]
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
key: "text",
|
| 212 |
+
label: "Text",
|
| 213 |
+
category: "text",
|
| 214 |
+
port_type: "text",
|
| 215 |
+
acceptedCategories: ["text", "chat"],
|
| 216 |
+
subtabs: [
|
| 217 |
+
{ key: "all", label: "All", pipelineTags: [] },
|
| 218 |
+
{
|
| 219 |
+
key: "generate",
|
| 220 |
+
label: "Generate",
|
| 221 |
+
pipelineTags: ["text-generation"],
|
| 222 |
+
spaceTags: ["text-generation"]
|
| 223 |
+
},
|
| 224 |
+
{
|
| 225 |
+
key: "summarize",
|
| 226 |
+
label: "Summarize",
|
| 227 |
+
pipelineTags: ["summarization"],
|
| 228 |
+
spaceTags: ["text-summarization"]
|
| 229 |
+
},
|
| 230 |
+
{
|
| 231 |
+
key: "translate",
|
| 232 |
+
label: "Translate",
|
| 233 |
+
pipelineTags: ["translation"],
|
| 234 |
+
spaceTags: ["language-translation"]
|
| 235 |
+
},
|
| 236 |
+
{
|
| 237 |
+
key: "code",
|
| 238 |
+
label: "Code",
|
| 239 |
+
pipelineTags: [],
|
| 240 |
+
spaceTags: ["code-generation"],
|
| 241 |
+
query: "code generation programming copilot"
|
| 242 |
+
}
|
| 243 |
+
]
|
| 244 |
+
}
|
| 245 |
+
];
|
| 246 |
+
|
| 247 |
+
/**
|
| 248 |
+
* Port registry β single source of truth for every user-facing port type.
|
| 249 |
+
* Drives reference/subject template generation, port labels in the UI, and
|
| 250 |
+
* modality routing for the compatible-nodes popup. `any` and `file` are
|
| 251 |
+
* deliberately omitted: they exist only as schema-inference fallbacks and
|
| 252 |
+
* never appear as user-selectable reference / subject options.
|
| 253 |
+
*/
|
| 254 |
+
export interface PortMeta {
|
| 255 |
+
port_type: PortType;
|
| 256 |
+
/** Human label used for reference / subject templates and popup options. */
|
| 257 |
+
label: string;
|
| 258 |
+
/** MODALITIES key this port routes to in the picker, if any. */
|
| 259 |
+
modality_key?: string;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
export const PORT_REGISTRY: PortMeta[] = [
|
| 263 |
+
{ port_type: "image", label: "Image", modality_key: "image" },
|
| 264 |
+
{ port_type: "audio", label: "Audio", modality_key: "audio" },
|
| 265 |
+
{ port_type: "video", label: "Video", modality_key: "video" },
|
| 266 |
+
{ port_type: "model3d", label: "3D", modality_key: "3d" },
|
| 267 |
+
{ port_type: "text", label: "Text", modality_key: "text" },
|
| 268 |
+
{ port_type: "number", label: "Number" },
|
| 269 |
+
{ port_type: "boolean", label: "Toggle" },
|
| 270 |
+
{ port_type: "json", label: "JSON" },
|
| 271 |
+
{ port_type: "gallery", label: "Gallery", modality_key: "image" }
|
| 272 |
+
];
|
| 273 |
+
|
| 274 |
+
export function portMeta(type: PortType): PortMeta | null {
|
| 275 |
+
return PORT_REGISTRY.find((p) => p.port_type === type) ?? null;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
export function modalityForPort(type: PortType): ModalityConfig | null {
|
| 279 |
+
const meta = portMeta(type);
|
| 280 |
+
if (!meta?.modality_key) return null;
|
| 281 |
+
return MODALITIES.find((m) => m.key === meta.modality_key) ?? null;
|
| 282 |
+
}
|
6.17.1/workflowcanvas/workflow/workflow-store.ts
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
ReferenceNode,
|
| 12 |
+
SubjectNode,
|
| 13 |
+
WFEdge,
|
| 14 |
+
Workflow
|
| 15 |
+
} from "./workflow-types";
|
| 16 |
+
import { ports_compatible } from "./workflow-types";
|
| 17 |
+
import { allNodes, findNode, isV2, migrateToV2 } from "./workflow-migration";
|
| 18 |
+
|
| 19 |
+
function uuid(): string {
|
| 20 |
+
return crypto.randomUUID();
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
const DEFAULT: Workflow = {
|
| 24 |
+
schema_version: "2",
|
| 25 |
+
name: "My workflow",
|
| 26 |
+
runtime: { default: "client" },
|
| 27 |
+
references: [
|
| 28 |
+
{
|
| 29 |
+
id: "ref_default",
|
| 30 |
+
role: "reference",
|
| 31 |
+
label: "Image",
|
| 32 |
+
asset_type: "image",
|
| 33 |
+
inputs: [{ id: "in", label: "Image", type: "image" }],
|
| 34 |
+
outputs: [{ id: "out", label: "Image", type: "image" }],
|
| 35 |
+
data: {},
|
| 36 |
+
x: 80,
|
| 37 |
+
y: 120,
|
| 38 |
+
width: 200,
|
| 39 |
+
height: 160
|
| 40 |
+
}
|
| 41 |
+
],
|
| 42 |
+
operators: [],
|
| 43 |
+
subjects: [],
|
| 44 |
+
edges: [],
|
| 45 |
+
view: { default: "canvas" }
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
// The canonical store of truth for the workflow body is the Python-side
|
| 49 |
+
// `workflow.json` (server function `save_workflow` writes; `initialValue`
|
| 50 |
+
// reads). The frontend store seeds with DEFAULT and is overwritten on mount
|
| 51 |
+
// by the file's contents β see `WorkflowCanvas.svelte` `$effect` reading
|
| 52 |
+
// `initialValue`. No localStorage persistence for the workflow body;
|
| 53 |
+
// `hf_token` and other auth bits persist separately in `hf-auth.svelte.ts`.
|
| 54 |
+
export const workflow = writable<Workflow>(DEFAULT);
|
| 55 |
+
|
| 56 |
+
// Re-export read helpers so callers import them from one place
|
| 57 |
+
export { allNodes, findNode, isV2, migrateToV2 };
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Strip session-bound media (blob: / data: URLs) from node data before
|
| 61 |
+
* serialising the workflow. blob: URLs die with the page that minted
|
| 62 |
+
* them, and data: URLs would bloat workflow.json with base64 payloads β
|
| 63 |
+
* so we drop the field entirely and let the user re-upload on refresh.
|
| 64 |
+
* Other data (text, numbers, server-served file paths) passes through.
|
| 65 |
+
*/
|
| 66 |
+
function is_session_url(v: unknown): boolean {
|
| 67 |
+
const url = (v as { url?: string } | null)?.url;
|
| 68 |
+
return (
|
| 69 |
+
typeof url === "string" &&
|
| 70 |
+
(url.startsWith("blob:") || url.startsWith("data:"))
|
| 71 |
+
);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
export function revoke_blob_urls(
|
| 75 |
+
data: Record<string, unknown> | undefined
|
| 76 |
+
): void {
|
| 77 |
+
for (const v of Object.values(data ?? {})) {
|
| 78 |
+
const url = (v as { url?: string } | null)?.url;
|
| 79 |
+
if (typeof url === "string" && url.startsWith("blob:")) {
|
| 80 |
+
URL.revokeObjectURL(url);
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
export function sanitize_for_save(wf: Workflow): Workflow {
|
| 86 |
+
return mapAllRoles(wf, (n) => {
|
| 87 |
+
if (!n.data) return n;
|
| 88 |
+
const cleaned: NodeData = {};
|
| 89 |
+
for (const [k, v] of Object.entries(n.data)) {
|
| 90 |
+
if (!is_session_url(v)) cleaned[k] = v as NodeDataValue;
|
| 91 |
+
}
|
| 92 |
+
return { ...n, data: cleaned };
|
| 93 |
+
});
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// βββ Actions ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 97 |
+
|
| 98 |
+
function addReference(
|
| 99 |
+
template: Omit<ReferenceNode, "id" | "role" | "x" | "y" | "data">,
|
| 100 |
+
x: number,
|
| 101 |
+
y: number
|
| 102 |
+
): string {
|
| 103 |
+
const id = uuid();
|
| 104 |
+
const data: Record<string, NodeDataValue> = {};
|
| 105 |
+
for (const port of template.inputs) {
|
| 106 |
+
if (port.default_value !== undefined) {
|
| 107 |
+
data[port.id] = port.default_value as NodeDataValue;
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
const node: ReferenceNode = {
|
| 111 |
+
...template,
|
| 112 |
+
role: "reference",
|
| 113 |
+
id,
|
| 114 |
+
x,
|
| 115 |
+
y,
|
| 116 |
+
data
|
| 117 |
+
};
|
| 118 |
+
workflow.update((wf) => ({ ...wf, references: [...wf.references, node] }));
|
| 119 |
+
return id;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
export function addOperator(
|
| 123 |
+
template: Omit<OperatorNode, "id" | "role" | "x" | "y" | "data">,
|
| 124 |
+
x: number,
|
| 125 |
+
y: number
|
| 126 |
+
): string {
|
| 127 |
+
const id = uuid();
|
| 128 |
+
const data: Record<string, NodeDataValue> = {};
|
| 129 |
+
for (const port of template.inputs) {
|
| 130 |
+
if (port.default_value !== undefined) {
|
| 131 |
+
data[port.id] = port.default_value as NodeDataValue;
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
const node: OperatorNode = { ...template, role: "operator", id, x, y, data };
|
| 135 |
+
workflow.update((wf) => ({ ...wf, operators: [...wf.operators, node] }));
|
| 136 |
+
return id;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
function addSubject(
|
| 140 |
+
template: Omit<SubjectNode, "id" | "role" | "x" | "y" | "data">,
|
| 141 |
+
x: number,
|
| 142 |
+
y: number
|
| 143 |
+
): string {
|
| 144 |
+
const id = uuid();
|
| 145 |
+
const node: SubjectNode = {
|
| 146 |
+
...template,
|
| 147 |
+
role: "subject",
|
| 148 |
+
id,
|
| 149 |
+
x,
|
| 150 |
+
y,
|
| 151 |
+
data: {}
|
| 152 |
+
};
|
| 153 |
+
workflow.update((wf) => ({ ...wf, subjects: [...wf.subjects, node] }));
|
| 154 |
+
return id;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Single entry point for adding a node. Accepts both v2-shaped templates and
|
| 159 |
+
* legacy v1-shaped ones (which still come from `node-library.ts` and the
|
| 160 |
+
* picker) and normalizes missing role-specific fields. Picks the matching
|
| 161 |
+
* array based on `role`.
|
| 162 |
+
*/
|
| 163 |
+
export function addNode(
|
| 164 |
+
role: NodeRole,
|
| 165 |
+
template: any,
|
| 166 |
+
x: number,
|
| 167 |
+
y: number
|
| 168 |
+
): string {
|
| 169 |
+
const baseFields = {
|
| 170 |
+
label: template.label ?? "",
|
| 171 |
+
inputs: template.inputs ?? [],
|
| 172 |
+
outputs: template.outputs ?? [],
|
| 173 |
+
width: template.width ?? 200,
|
| 174 |
+
height: template.height ?? 100
|
| 175 |
+
};
|
| 176 |
+
|
| 177 |
+
if (role === "reference") {
|
| 178 |
+
const asset_type: PortType =
|
| 179 |
+
template.asset_type ??
|
| 180 |
+
template.outputs?.[0]?.type ??
|
| 181 |
+
template.inputs?.[0]?.type ??
|
| 182 |
+
"any";
|
| 183 |
+
return addReference({ ...baseFields, asset_type }, x, y);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
if (role === "operator") {
|
| 187 |
+
// v1 templates carry `kind: "transform"` + `source: "space" | "model" | ...`
|
| 188 |
+
// v2 templates carry `kind: OperatorKind` directly. Normalize.
|
| 189 |
+
const opKind: OperatorKind =
|
| 190 |
+
template.source === "space" ||
|
| 191 |
+
template.source === "model" ||
|
| 192 |
+
template.source === "dataset" ||
|
| 193 |
+
template.source === "fn"
|
| 194 |
+
? template.source
|
| 195 |
+
: template.kind === "space" ||
|
| 196 |
+
template.kind === "model" ||
|
| 197 |
+
template.kind === "dataset" ||
|
| 198 |
+
template.kind === "fn"
|
| 199 |
+
? template.kind
|
| 200 |
+
: template.space_id
|
| 201 |
+
? "space"
|
| 202 |
+
: template.model_id
|
| 203 |
+
? "model"
|
| 204 |
+
: template.dataset_id
|
| 205 |
+
? "dataset"
|
| 206 |
+
: "fn";
|
| 207 |
+
return addOperator(
|
| 208 |
+
{
|
| 209 |
+
...baseFields,
|
| 210 |
+
kind: opKind,
|
| 211 |
+
source:
|
| 212 |
+
template.source &&
|
| 213 |
+
typeof template.source === "string" &&
|
| 214 |
+
template.source.startsWith("hf://")
|
| 215 |
+
? template.source
|
| 216 |
+
: undefined,
|
| 217 |
+
space_id: template.space_id,
|
| 218 |
+
model_id: template.model_id,
|
| 219 |
+
dataset_id: template.dataset_id,
|
| 220 |
+
dataset_config: template.dataset_config,
|
| 221 |
+
dataset_split: template.dataset_split,
|
| 222 |
+
endpoint: template.endpoint,
|
| 223 |
+
endpoints: template.endpoints,
|
| 224 |
+
pipeline_tag: template.pipeline_tag,
|
| 225 |
+
provider: template.provider,
|
| 226 |
+
fn: template.fn,
|
| 227 |
+
runtime: template.runtime
|
| 228 |
+
},
|
| 229 |
+
x,
|
| 230 |
+
y
|
| 231 |
+
);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
// subject
|
| 235 |
+
const asset_type: PortType =
|
| 236 |
+
template.asset_type ??
|
| 237 |
+
template.inputs?.[0]?.type ??
|
| 238 |
+
template.outputs?.[0]?.type ??
|
| 239 |
+
"any";
|
| 240 |
+
return addSubject({ ...baseFields, asset_type }, x, y);
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
function mapAllRoles(wf: Workflow, fn: (node: AnyNode) => AnyNode): Workflow {
|
| 244 |
+
return {
|
| 245 |
+
...wf,
|
| 246 |
+
references: wf.references.map((n) => fn(n) as ReferenceNode),
|
| 247 |
+
operators: wf.operators.map((n) => fn(n) as OperatorNode),
|
| 248 |
+
subjects: wf.subjects.map((n) => fn(n) as SubjectNode)
|
| 249 |
+
};
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
export function moveNode(id: string, x: number, y: number): void {
|
| 253 |
+
workflow.update((wf) =>
|
| 254 |
+
mapAllRoles(wf, (n) => (n.id === id ? { ...n, x, y } : n))
|
| 255 |
+
);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
export function resizeNode(id: string, width: number, height: number): void {
|
| 259 |
+
workflow.update((wf) =>
|
| 260 |
+
mapAllRoles(wf, (n) => (n.id === id ? { ...n, width, height } : n))
|
| 261 |
+
);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
export function updateNodeData(
|
| 265 |
+
nodeId: string,
|
| 266 |
+
portId: string,
|
| 267 |
+
value: NodeDataValue
|
| 268 |
+
): void {
|
| 269 |
+
workflow.update((wf) =>
|
| 270 |
+
mapAllRoles(wf, (n) =>
|
| 271 |
+
n.id === nodeId ? { ...n, data: { ...n.data, [portId]: value } } : n
|
| 272 |
+
)
|
| 273 |
+
);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
export function removeNode(id: string): void {
|
| 277 |
+
workflow.update((wf) => {
|
| 278 |
+
const node = findNode(wf, id);
|
| 279 |
+
if (node) revoke_blob_urls(node.data);
|
| 280 |
+
return {
|
| 281 |
+
...wf,
|
| 282 |
+
references: wf.references.filter((n) => n.id !== id),
|
| 283 |
+
operators: wf.operators.filter((n) => n.id !== id),
|
| 284 |
+
subjects: wf.subjects.filter((n) => n.id !== id),
|
| 285 |
+
edges: wf.edges.filter(
|
| 286 |
+
(e) => e.from_node_id !== id && e.to_node_id !== id
|
| 287 |
+
)
|
| 288 |
+
};
|
| 289 |
+
});
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
export function addEdge(e: Omit<WFEdge, "id">): void {
|
| 293 |
+
workflow.update((wf) => ({
|
| 294 |
+
...wf,
|
| 295 |
+
edges: [...wf.edges, { ...e, id: uuid() }]
|
| 296 |
+
}));
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
export function removeEdge(id: string): void {
|
| 300 |
+
workflow.update((wf) => ({
|
| 301 |
+
...wf,
|
| 302 |
+
edges: wf.edges.filter((e) => e.id !== id)
|
| 303 |
+
}));
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
export function hydrate_endpoints(
|
| 307 |
+
nodeId: string,
|
| 308 |
+
endpoints: { name: string; inputs: Port[]; outputs: Port[] }[]
|
| 309 |
+
): void {
|
| 310 |
+
workflow.update((wf) => ({
|
| 311 |
+
...wf,
|
| 312 |
+
operators: wf.operators.map((n) =>
|
| 313 |
+
n.id === nodeId ? { ...n, endpoints } : n
|
| 314 |
+
)
|
| 315 |
+
}));
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
export function switch_endpoint(nodeId: string, endpointName: string): void {
|
| 319 |
+
workflow.update((wf) => {
|
| 320 |
+
const node = wf.operators.find((n) => n.id === nodeId);
|
| 321 |
+
if (!node || !node.endpoints) return wf;
|
| 322 |
+
const sig = node.endpoints.find((e) => e.name === endpointName);
|
| 323 |
+
if (!sig || sig.name === node.endpoint) return wf;
|
| 324 |
+
|
| 325 |
+
const input_by_id = new Map(sig.inputs.map((p) => [p.id, p]));
|
| 326 |
+
const output_by_id = new Map(sig.outputs.map((p) => [p.id, p]));
|
| 327 |
+
|
| 328 |
+
return {
|
| 329 |
+
...wf,
|
| 330 |
+
operators: wf.operators.map((n) =>
|
| 331 |
+
n.id === nodeId
|
| 332 |
+
? {
|
| 333 |
+
...n,
|
| 334 |
+
endpoint: sig.name,
|
| 335 |
+
inputs: sig.inputs,
|
| 336 |
+
outputs: sig.outputs,
|
| 337 |
+
data: {}
|
| 338 |
+
}
|
| 339 |
+
: n
|
| 340 |
+
),
|
| 341 |
+
edges: wf.edges.filter((e) => {
|
| 342 |
+
if (e.from_node_id === nodeId) {
|
| 343 |
+
const new_port = output_by_id.get(e.from_port_id);
|
| 344 |
+
if (!new_port) return false;
|
| 345 |
+
if (!ports_compatible(new_port.type, e.type)) return false;
|
| 346 |
+
}
|
| 347 |
+
if (e.to_node_id === nodeId) {
|
| 348 |
+
const new_port = input_by_id.get(e.to_port_id);
|
| 349 |
+
if (!new_port) return false;
|
| 350 |
+
if (!ports_compatible(new_port.type, e.type)) return false;
|
| 351 |
+
}
|
| 352 |
+
return true;
|
| 353 |
+
})
|
| 354 |
+
};
|
| 355 |
+
});
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
/**
|
| 359 |
+
* Replace an operator's source identity (Space β different Space, Space β Model,
|
| 360 |
+
* etc.). Clears all source-specific fields before applying the new template so
|
| 361 |
+
* stale ids can't linger.
|
| 362 |
+
*/
|
| 363 |
+
export function replaceNodeSource(
|
| 364 |
+
nodeId: string,
|
| 365 |
+
template: {
|
| 366 |
+
label?: string;
|
| 367 |
+
kind?: OperatorKind;
|
| 368 |
+
source?: string;
|
| 369 |
+
space_id?: string;
|
| 370 |
+
model_id?: string;
|
| 371 |
+
dataset_id?: string;
|
| 372 |
+
dataset_config?: string;
|
| 373 |
+
dataset_split?: string;
|
| 374 |
+
endpoint?: string;
|
| 375 |
+
pipeline_tag?: string;
|
| 376 |
+
inputs: Port[];
|
| 377 |
+
outputs: Port[];
|
| 378 |
+
width?: number;
|
| 379 |
+
}
|
| 380 |
+
): void {
|
| 381 |
+
workflow.update((wf) => ({
|
| 382 |
+
...wf,
|
| 383 |
+
operators: wf.operators.map((n) => {
|
| 384 |
+
if (n.id !== nodeId) return n;
|
| 385 |
+
const stripped = { ...n } as OperatorNode;
|
| 386 |
+
delete stripped.space_id;
|
| 387 |
+
delete stripped.model_id;
|
| 388 |
+
delete stripped.dataset_id;
|
| 389 |
+
delete stripped.dataset_config;
|
| 390 |
+
delete stripped.dataset_split;
|
| 391 |
+
delete stripped.endpoint;
|
| 392 |
+
delete stripped.pipeline_tag;
|
| 393 |
+
delete stripped.source;
|
| 394 |
+
return {
|
| 395 |
+
...stripped,
|
| 396 |
+
...(template.kind && { kind: template.kind }),
|
| 397 |
+
...(template.source !== undefined && { source: template.source }),
|
| 398 |
+
...(template.space_id !== undefined && { space_id: template.space_id }),
|
| 399 |
+
...(template.model_id !== undefined && { model_id: template.model_id }),
|
| 400 |
+
...(template.dataset_id !== undefined && {
|
| 401 |
+
dataset_id: template.dataset_id
|
| 402 |
+
}),
|
| 403 |
+
...(template.dataset_config !== undefined && {
|
| 404 |
+
dataset_config: template.dataset_config
|
| 405 |
+
}),
|
| 406 |
+
...(template.dataset_split !== undefined && {
|
| 407 |
+
dataset_split: template.dataset_split
|
| 408 |
+
}),
|
| 409 |
+
...(template.endpoint !== undefined && { endpoint: template.endpoint }),
|
| 410 |
+
...(template.pipeline_tag !== undefined && {
|
| 411 |
+
pipeline_tag: template.pipeline_tag
|
| 412 |
+
}),
|
| 413 |
+
inputs: template.inputs,
|
| 414 |
+
outputs: template.outputs,
|
| 415 |
+
label: template.label ?? n.label,
|
| 416 |
+
width: template.width ?? n.width,
|
| 417 |
+
data: {}
|
| 418 |
+
};
|
| 419 |
+
})
|
| 420 |
+
}));
|
| 421 |
+
}
|
6.17.1/workflowcanvas/workflow/workflow-types.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Port types. The first nine are user-facing and have entries in
|
| 3 |
+
* `PORT_REGISTRY` (workflow-modalities.ts). `file` and `any` are
|
| 4 |
+
* inference-only fallbacks emitted by schema introspection when a more
|
| 5 |
+
* specific type can't be determined β they are never offered as
|
| 6 |
+
* reference / subject templates and should not appear in pickers.
|
| 7 |
+
*/
|
| 8 |
+
export type PortType =
|
| 9 |
+
| "image"
|
| 10 |
+
| "text"
|
| 11 |
+
| "audio"
|
| 12 |
+
| "video"
|
| 13 |
+
| "number"
|
| 14 |
+
| "boolean"
|
| 15 |
+
| "file"
|
| 16 |
+
| "json"
|
| 17 |
+
| "gallery"
|
| 18 |
+
| "model3d"
|
| 19 |
+
| "any";
|
| 20 |
+
|
| 21 |
+
export function ports_compatible(a: PortType, b: PortType): boolean {
|
| 22 |
+
return a === "any" || b === "any" || a === b;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
export interface Port {
|
| 26 |
+
id: string;
|
| 27 |
+
label: string;
|
| 28 |
+
type: PortType;
|
| 29 |
+
required?: boolean;
|
| 30 |
+
default_value?: unknown;
|
| 31 |
+
output_index?: number;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
export interface FileValue {
|
| 35 |
+
name: string;
|
| 36 |
+
url: string;
|
| 37 |
+
mime: string;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
export type NodeDataValue = string | number | boolean | FileValue | null;
|
| 41 |
+
export type NodeData = Record<string, NodeDataValue>;
|
| 42 |
+
export type NodeStatus = "idle" | "running" | "done" | "error";
|
| 43 |
+
|
| 44 |
+
export interface WFNode {
|
| 45 |
+
id: string;
|
| 46 |
+
kind: "input" | "transform" | "output" | "component";
|
| 47 |
+
label: string;
|
| 48 |
+
source: "local" | "space" | "model" | "dataset" | "fn";
|
| 49 |
+
space_id?: string;
|
| 50 |
+
model_id?: string;
|
| 51 |
+
dataset_id?: string;
|
| 52 |
+
dataset_config?: string;
|
| 53 |
+
dataset_split?: string;
|
| 54 |
+
pipeline_tag?: string;
|
| 55 |
+
provider?: string;
|
| 56 |
+
endpoint?: string;
|
| 57 |
+
endpoints?: EndpointChoice[];
|
| 58 |
+
fn?: string;
|
| 59 |
+
inputs: Port[];
|
| 60 |
+
outputs: Port[];
|
| 61 |
+
x: number;
|
| 62 |
+
y: number;
|
| 63 |
+
width: number;
|
| 64 |
+
height: number;
|
| 65 |
+
data: NodeData;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
export interface WFEdge {
|
| 69 |
+
id: string;
|
| 70 |
+
from_node_id: string;
|
| 71 |
+
from_port_id: string;
|
| 72 |
+
to_node_id: string;
|
| 73 |
+
to_port_id: string;
|
| 74 |
+
type: PortType;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Legacy v1 workflow shape. Stays here only to make the migration code
|
| 79 |
+
* (workflow-migration.ts) type-checkable; the live store is v2.
|
| 80 |
+
*/
|
| 81 |
+
export interface WorkflowV1 {
|
| 82 |
+
version?: "1";
|
| 83 |
+
name?: string;
|
| 84 |
+
nodes?: WFNode[];
|
| 85 |
+
edges?: WFEdge[];
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
// βββ v2 schema ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 89 |
+
//
|
| 90 |
+
// The graph is split into three role-collections at the JSON level:
|
| 91 |
+
// references β inputs you bring in (uploaded files, prompts, literals)
|
| 92 |
+
// operators β transformations (spaces / models / datasets / Python fns)
|
| 93 |
+
// subjects β the things being created (typed output tiles)
|
| 94 |
+
//
|
| 95 |
+
// All three share BaseNode. The role tag drives visual presentation
|
| 96 |
+
// (studio view) and authoring intent; the data structure stays uniform
|
| 97 |
+
// enough that the executor and canvas can treat them as peer nodes.
|
| 98 |
+
|
| 99 |
+
export type NodeRole = "reference" | "operator" | "subject";
|
| 100 |
+
|
| 101 |
+
export type OperatorKind = "space" | "model" | "dataset" | "fn";
|
| 102 |
+
|
| 103 |
+
export type Runtime = "client" | "server" | "job";
|
| 104 |
+
|
| 105 |
+
export interface BaseNode {
|
| 106 |
+
id: string;
|
| 107 |
+
label: string;
|
| 108 |
+
inputs: Port[];
|
| 109 |
+
outputs: Port[];
|
| 110 |
+
data: NodeData;
|
| 111 |
+
x: number;
|
| 112 |
+
y: number;
|
| 113 |
+
width: number;
|
| 114 |
+
height: number;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
export interface ReferenceNode extends BaseNode {
|
| 118 |
+
role: "reference";
|
| 119 |
+
asset_type: PortType;
|
| 120 |
+
/** Inline literal value, or in a later iteration an `hf://...` URI. */
|
| 121 |
+
value?: NodeDataValue;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
export interface EndpointChoice {
|
| 125 |
+
name: string;
|
| 126 |
+
inputs: Port[];
|
| 127 |
+
outputs: Port[];
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
export interface OperatorNode extends BaseNode {
|
| 131 |
+
role: "operator";
|
| 132 |
+
kind: OperatorKind;
|
| 133 |
+
/** Canonical hub-native identifier when available (hf://...) or fn name. */
|
| 134 |
+
source?: string;
|
| 135 |
+
space_id?: string;
|
| 136 |
+
model_id?: string;
|
| 137 |
+
dataset_id?: string;
|
| 138 |
+
dataset_config?: string;
|
| 139 |
+
dataset_split?: string;
|
| 140 |
+
endpoint?: string;
|
| 141 |
+
endpoints?: EndpointChoice[];
|
| 142 |
+
pipeline_tag?: string;
|
| 143 |
+
fn?: string;
|
| 144 |
+
/** HF Inference provider override (e.g. "hf-inference", "together", "replicate"). Defaults to "auto" β let HF route. */
|
| 145 |
+
provider?: string;
|
| 146 |
+
/** Where this operator executes. Default inherited from workflow.runtime.default. */
|
| 147 |
+
runtime?: Runtime;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
export interface SubjectNode extends BaseNode {
|
| 151 |
+
role: "subject";
|
| 152 |
+
asset_type: PortType;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
export type AnyNode = ReferenceNode | OperatorNode | SubjectNode;
|
| 156 |
+
|
| 157 |
+
export interface Workflow {
|
| 158 |
+
schema_version: "2";
|
| 159 |
+
/** Optional hub repo identifier, e.g. "username/my-workflow". */
|
| 160 |
+
id?: string;
|
| 161 |
+
name: string;
|
| 162 |
+
description?: string;
|
| 163 |
+
/** Lineage hook β set when a workflow was forked from another. */
|
| 164 |
+
parent?: string;
|
| 165 |
+
runtime?: {
|
| 166 |
+
default: Runtime;
|
| 167 |
+
};
|
| 168 |
+
references: ReferenceNode[];
|
| 169 |
+
operators: OperatorNode[];
|
| 170 |
+
subjects: SubjectNode[];
|
| 171 |
+
edges: WFEdge[];
|
| 172 |
+
view?: {
|
| 173 |
+
default?: "studio" | "canvas";
|
| 174 |
+
};
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
export const PORT_COLOR: Record<PortType, string> = {
|
| 178 |
+
image: "#4fd1a5",
|
| 179 |
+
text: "#8b83e8",
|
| 180 |
+
audio: "#f5a623",
|
| 181 |
+
video: "#4d9cf5",
|
| 182 |
+
number: "#e879a8",
|
| 183 |
+
boolean: "#f59e0b",
|
| 184 |
+
file: "#94a3b8",
|
| 185 |
+
json: "#22d3ee",
|
| 186 |
+
gallery: "#34d399",
|
| 187 |
+
model3d: "#a78bfa",
|
| 188 |
+
any: "#6b6e78"
|
| 189 |
+
};
|
| 190 |
+
|
| 191 |
+
export const PORT_COLOR_DIM: Record<PortType, string> = {
|
| 192 |
+
image: "rgba(79, 209, 165, 0.15)",
|
| 193 |
+
text: "rgba(139, 131, 232, 0.15)",
|
| 194 |
+
audio: "rgba(245, 166, 35, 0.15)",
|
| 195 |
+
video: "rgba(77, 156, 245, 0.15)",
|
| 196 |
+
number: "rgba(232, 121, 168, 0.15)",
|
| 197 |
+
boolean: "rgba(245, 158, 11, 0.15)",
|
| 198 |
+
file: "rgba(148, 163, 184, 0.15)",
|
| 199 |
+
json: "rgba(34, 211, 238, 0.15)",
|
| 200 |
+
gallery: "rgba(52, 211, 153, 0.15)",
|
| 201 |
+
model3d: "rgba(167, 139, 250, 0.15)",
|
| 202 |
+
any: "rgba(107, 110, 120, 0.10)"
|
| 203 |
+
};
|