@tansy/ai 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/admin.d.ts +2 -0
  4. package/admin.js +17 -0
  5. package/ai.css +280 -0
  6. package/api.d.ts +91 -0
  7. package/api.js +79 -0
  8. package/assistant.d.ts +3 -0
  9. package/assistant.js +290 -0
  10. package/attach.d.ts +48 -0
  11. package/attach.js +141 -0
  12. package/attachments.d.ts +34 -0
  13. package/attachments.js +66 -0
  14. package/chats.d.ts +35 -0
  15. package/chats.js +78 -0
  16. package/client.d.ts +3 -0
  17. package/client.js +88 -0
  18. package/composer.d.ts +38 -0
  19. package/composer.js +155 -0
  20. package/errors.d.ts +5 -0
  21. package/errors.js +25 -0
  22. package/history.d.ts +15 -0
  23. package/history.js +47 -0
  24. package/icons.generated.d.ts +5 -0
  25. package/icons.generated.js +66 -0
  26. package/images.d.ts +21 -0
  27. package/images.js +23 -0
  28. package/index.d.ts +26 -0
  29. package/index.js +701 -0
  30. package/logic.d.ts +77 -0
  31. package/logic.js +166 -0
  32. package/markdown.d.ts +38 -0
  33. package/markdown.js +142 -0
  34. package/media.d.ts +24 -0
  35. package/media.js +64 -0
  36. package/messages.d.ts +891 -0
  37. package/messages.js +689 -0
  38. package/models.d.ts +7 -0
  39. package/models.js +47 -0
  40. package/package.json +46 -4
  41. package/parts.d.ts +59 -0
  42. package/parts.js +110 -0
  43. package/provider.d.ts +134 -0
  44. package/provider.js +117 -0
  45. package/role.d.ts +24 -0
  46. package/role.js +25 -0
  47. package/workflow/check.d.ts +46 -0
  48. package/workflow/check.js +63 -0
  49. package/workflow/client.d.ts +90 -0
  50. package/workflow/client.js +51 -0
  51. package/workflow/editor.d.ts +13 -0
  52. package/workflow/editor.js +133 -0
  53. package/workflow/engine.d.ts +232 -0
  54. package/workflow/engine.js +779 -0
  55. package/workflow/icons.d.ts +26 -0
  56. package/workflow/icons.js +67 -0
  57. package/workflow/model-picker.d.ts +22 -0
  58. package/workflow/model-picker.js +69 -0
  59. package/workflow/page.d.ts +3 -0
  60. package/workflow/page.js +118 -0
  61. package/workflow/routes.d.ts +12 -0
  62. package/workflow/routes.js +418 -0
  63. package/workflow/run.d.ts +8 -0
  64. package/workflow/run.js +162 -0
  65. package/workflow/schema.d.ts +183 -0
  66. package/workflow/schema.js +143 -0
  67. package/workflow/templates.d.ts +9 -0
  68. package/workflow/templates.js +81 -0
  69. package/workflow/workflow.css +241 -0
@@ -0,0 +1,26 @@
1
+ /** The icon for a model: its family by name, else its vendor, else none. */
2
+ export declare function modelIconKey(id: string): string | null;
3
+ export declare const providerIconKey: (provider: string, icon?: string) => string;
4
+ /**
5
+ * An icon from @lobehub/icons by name. One-colour icons follow the text colour through a
6
+ * mask, so they read in dark mode; colour icons are drawn as they are.
7
+ */
8
+ export declare function BrandIcon({ name, size, fallback, title }: {
9
+ name: string | null;
10
+ size?: number;
11
+ fallback?: string;
12
+ title?: string;
13
+ }): import("react").JSX.Element;
14
+ export declare const ProviderIcon: ({ provider, icon, label, size }: {
15
+ provider: string;
16
+ icon?: string;
17
+ label?: string;
18
+ size?: number;
19
+ }) => import("react").JSX.Element;
20
+ /** A model's family icon, or its provider's when the family isn't known. */
21
+ export declare const ModelIcon: ({ model, provider, icon, size }: {
22
+ model: string;
23
+ provider: string;
24
+ icon?: string;
25
+ size?: number;
26
+ }) => import("react").JSX.Element;
@@ -0,0 +1,67 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { ICONS } from "../icons.generated";
4
+ /** The icon of each provider Tansy ships an adapter for. Others name theirs with `icon`. */
5
+ const PROVIDERS = {
6
+ openai: "openai",
7
+ anthropic: "claude",
8
+ google: "gemini",
9
+ gateway: "vercel",
10
+ mistral: "mistral",
11
+ xai: "xai",
12
+ groq: "groq",
13
+ deepseek: "deepseek",
14
+ openrouter: "openrouter",
15
+ opencode: "opencode",
16
+ commandcode: "commandcode",
17
+ compatible: "ollama",
18
+ };
19
+ /** A model id's vendor, as routers write it: "anthropic/claude-…", "meta-llama/llama-…". */
20
+ const VENDORS = {
21
+ openai: "openai", anthropic: "claude", google: "gemini", "meta-llama": "meta", meta: "meta", mistralai: "mistral", mistral: "mistral",
22
+ "x-ai": "grok", xai: "grok", deepseek: "deepseek", "deepseek-ai": "deepseek", qwen: "qwen", alibaba: "qwen", moonshotai: "kimi",
23
+ "z-ai": "zhipu", zai: "zhipu", thudm: "zhipu", cohere: "cohere", microsoft: "microsoft", nvidia: "nvidia", perplexity: "perplexity",
24
+ "black-forest-labs": "flux", bfl: "flux", stabilityai: "stability", amazon: "nova", minimax: "minimax", ai21: "ai21",
25
+ "nousresearch": "nousresearch", liquid: "liquid", bytedance: "doubao", inflection: "inflection", recraft: "recraft", ideogram: "ideogram",
26
+ };
27
+ /** Model families by name, checked in order. */
28
+ const FAMILIES = [
29
+ [/dall-e/, "dalle"], [/sora/, "sora"], [/^(gpt|o\d|chatgpt|codex|text-|davinci|babbage|omni)/, "openai"],
30
+ [/claude/, "claude"], [/gemma/, "gemma"], [/gemini|nano-banana|learnlm/, "gemini"], [/imagen|veo|palm/, "google"],
31
+ [/mistral|mixtral|codestral|magistral|pixtral|ministral|devstral|voxtral/, "mistral"], [/grok/, "grok"], [/deepseek/, "deepseek"],
32
+ [/llama/, "meta"], [/qwen|qwq/, "qwen"], [/kimi|moonshot/, "kimi"], [/glm|chatglm/, "zhipu"], [/minimax|abab/, "minimax"],
33
+ [/command|aya/, "cohere"], [/^phi-|wizardlm/, "microsoft"], [/nemotron/, "nvidia"], [/sonar|pplx/, "perplexity"],
34
+ [/flux/, "flux"], [/stable-diffusion|sdxl|sd3/, "stability"], [/ideogram/, "ideogram"], [/recraft/, "recraft"],
35
+ [/nova|titan/, "nova"], [/jamba/, "ai21"], [/^yi-/, "yi"], [/hunyuan/, "hunyuan"], [/doubao|seed/, "doubao"], [/^step-/, "stepfun"],
36
+ [/internlm/, "internlm"], [/lfm/, "liquid"], [/hermes/, "nousresearch"], [/ernie/, "wenxin"],
37
+ ];
38
+ /** The icon for a model: its family by name, else its vendor, else none. */
39
+ export function modelIconKey(id) {
40
+ const [vendor, ...rest] = id.toLowerCase().split("/");
41
+ const name = rest.length ? rest.join("/") : vendor;
42
+ for (const [pattern, key] of FAMILIES)
43
+ if (pattern.test(name))
44
+ return key;
45
+ return rest.length && VENDORS[vendor] ? VENDORS[vendor] : null;
46
+ }
47
+ export const providerIconKey = (provider, icon) => icon ?? PROVIDERS[provider] ?? null;
48
+ const dataUri = (svg) => `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
49
+ /**
50
+ * An icon from @lobehub/icons by name. One-colour icons follow the text colour through a
51
+ * mask, so they read in dark mode; colour icons are drawn as they are.
52
+ */
53
+ export function BrandIcon({ name, size = 18, fallback, title }) {
54
+ const icon = name ? ICONS[name] : undefined;
55
+ const style = { width: size, height: size };
56
+ if (!icon)
57
+ return _jsx("span", { className: "wf-brand wf-brand-letter", style: { ...style, fontSize: size * 0.55 }, title: title, "aria-hidden": !title, children: (fallback ?? "?").slice(0, 1).toUpperCase() });
58
+ const uri = dataUri(icon.svg);
59
+ if (icon.mono)
60
+ return _jsx("span", { className: "wf-brand wf-brand-mono", style: { ...style, maskImage: `url("${uri}")`, WebkitMaskImage: `url("${uri}")` }, title: title, "aria-hidden": !title });
61
+ // A data: image can't run anything, whatever it holds.
62
+ // eslint-disable-next-line @next/next/no-img-element -- an inline SVG icon, which next/image has nothing to optimize in
63
+ return _jsx("img", { className: "wf-brand", src: uri, width: size, height: size, alt: title ?? "", title: title });
64
+ }
65
+ export const ProviderIcon = ({ provider, icon, label, size }) => (_jsx(BrandIcon, { name: providerIconKey(provider, icon), fallback: label ?? provider, title: label, size: size }));
66
+ /** A model's family icon, or its provider's when the family isn't known. */
67
+ export const ModelIcon = ({ model, provider, icon, size }) => (_jsx(BrandIcon, { name: modelIconKey(model) ?? providerIconKey(provider, icon), fallback: model, size: size }));
@@ -0,0 +1,22 @@
1
+ import type { ModelCapabilities } from "../provider";
2
+ import { type Catalog } from "./check";
3
+ import type { Task } from "./schema";
4
+ /** What a model can do, as small labels: the parts a workflow cares about. */
5
+ export declare function CapabilityChips({ capabilities }: {
6
+ capabilities?: ModelCapabilities;
7
+ }): import("react").JSX.Element;
8
+ /**
9
+ * Chooses a provider and model, from every ready provider's list, showing what each model
10
+ * can do as its provider reports it. Models that can't do the agent's tasks are shown but
11
+ * can't be chosen. Any id can still be typed, for a model a provider doesn't list.
12
+ */
13
+ export declare function ModelPicker({ catalog, provider, model, tasks, onChange }: {
14
+ catalog: Catalog;
15
+ provider: string;
16
+ model: string;
17
+ tasks: Task[];
18
+ onChange: (value: {
19
+ provider: string;
20
+ model: string;
21
+ }) => void;
22
+ }): import("react").JSX.Element;
@@ -0,0 +1,69 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useT } from "tansy/admin";
4
+ import { useCallback, useMemo, useRef, useState } from "react";
5
+ import { Check, ChevronDown, Search, useDismiss } from "../parts";
6
+ import { supports } from "./check";
7
+ import { ModelIcon, ProviderIcon } from "./icons";
8
+ const SHOWN = 150;
9
+ /** What a model can do, as small labels: the parts a workflow cares about. */
10
+ export function CapabilityChips({ capabilities }) {
11
+ const { t } = useT();
12
+ if (!capabilities)
13
+ return _jsx("span", { className: "wf-chip wf-chip-unknown", children: t("ext.ai.workflows.caps.unknown") });
14
+ const chips = [];
15
+ if (capabilities.output?.includes("text"))
16
+ chips.push("text");
17
+ if (capabilities.output?.includes("image"))
18
+ chips.push("draws");
19
+ if (capabilities.input?.includes("image"))
20
+ chips.push("vision");
21
+ if (capabilities.tools)
22
+ chips.push("tools");
23
+ if (capabilities.reasoning)
24
+ chips.push("thinks");
25
+ if (capabilities.structured)
26
+ chips.push("json");
27
+ return _jsxs(_Fragment, { children: [chips.map((chip) => _jsx("span", { className: `wf-chip wf-chip-${chip}`, children: t(`ext.ai.workflows.caps.${chip}`) }, chip)), !capabilities.reported ? _jsx("span", { className: "wf-chip wf-chip-unknown", title: t("ext.ai.workflows.caps.guessedHint"), children: t("ext.ai.workflows.caps.guessed") }) : null] });
28
+ }
29
+ /** Whether a model can do every task asked of it, and the first it can't. */
30
+ function fit(capabilities, tasks) {
31
+ const results = tasks.map((task) => [task, supports(capabilities, task)]);
32
+ const no = results.find(([, support]) => support === "no");
33
+ return { ok: !no, missing: no?.[0], unknown: results.some(([, support]) => support === "unknown") };
34
+ }
35
+ /**
36
+ * Chooses a provider and model, from every ready provider's list, showing what each model
37
+ * can do as its provider reports it. Models that can't do the agent's tasks are shown but
38
+ * can't be chosen. Any id can still be typed, for a model a provider doesn't list.
39
+ */
40
+ export function ModelPicker({ catalog, provider, model, tasks, onChange }) {
41
+ const { t } = useT();
42
+ const [open, setOpen] = useState(false);
43
+ const [query, setQuery] = useState("");
44
+ const [only, setOnly] = useState(null);
45
+ const [onlyFit, setOnlyFit] = useState(true);
46
+ const root = useRef(null);
47
+ const close = useCallback(() => { setOpen(false); setQuery(""); }, []);
48
+ useDismiss(root, open, close);
49
+ const entry = catalog.providers.find((item) => item.id === provider);
50
+ const current = entry?.models?.find((item) => item.value === model);
51
+ const ready = catalog.providers.filter((item) => item.ready);
52
+ const groups = useMemo(() => {
53
+ const words = query.trim().toLowerCase();
54
+ return ready.filter((item) => !only || item.id === only).map((item) => {
55
+ const models = (item.models ?? []).filter((choice) => (!words || `${choice.value} ${choice.label ?? ""}`.toLowerCase().includes(words)) && (!onlyFit || fit(choice.capabilities, tasks).ok));
56
+ return { entry: item, models: models.slice(0, SHOWN), more: Math.max(0, models.length - SHOWN) };
57
+ });
58
+ }, [ready, only, query, onlyFit, tasks]);
59
+ const choose = (value) => { onChange(value); close(); };
60
+ const typed = query.trim();
61
+ const typedProvider = only ?? provider ?? ready[0]?.id;
62
+ const row = (item, choice) => {
63
+ const { ok, missing } = fit(choice.capabilities, tasks);
64
+ const selected = item.id === provider && choice.value === model;
65
+ return (_jsx("li", { children: _jsxs("button", { type: "button", className: `wf-model-row${selected ? " is-selected" : ""}`, disabled: !ok, title: !ok && missing ? t("ext.ai.workflows.picker.cannot", { task: t(`ext.ai.workflows.tasks.${missing}`) }) : choice.value, onClick: () => choose({ provider: item.id, model: choice.value }), children: [_jsx(ModelIcon, { model: choice.value, provider: item.id, icon: item.icon, size: 20 }), _jsxs("span", { className: "wf-model-text", children: [_jsx("span", { className: "wf-model-name", children: choice.label ?? choice.value }), choice.label ? _jsx("span", { className: "wf-model-id", children: choice.value }) : null] }), _jsx("span", { className: "wf-model-chips", children: _jsx(CapabilityChips, { capabilities: choice.capabilities }) }), selected ? _jsx(Check, {}) : null] }) }, `${item.id}:${choice.value}`));
66
+ };
67
+ return (_jsxs("div", { className: "wf-picker", ref: root, children: [_jsxs("button", { type: "button", className: "wf-picker-button", "aria-haspopup": "listbox", "aria-expanded": open, onClick: () => setOpen((value) => !value), children: [_jsx(ModelIcon, { model: model, provider: provider, icon: entry?.icon, size: 22 }), _jsxs("span", { className: "wf-model-text", children: [_jsx("span", { className: "wf-model-name", children: current?.label ?? (model || t("ext.ai.workflows.picker.choose")) }), _jsxs("span", { className: "wf-model-id", children: [_jsx(ProviderIcon, { provider: provider, icon: entry?.icon, label: entry?.label, size: 12 }), " ", entry?.label ?? provider] })] }), _jsx(ChevronDown, {})] }), open ? (_jsxs("div", { className: "wf-picker-pop", role: "dialog", "aria-label": t("ext.ai.workflows.picker.title"), children: [_jsxs("div", { className: "wf-picker-search", children: [_jsx(Search, {}), _jsx("input", { autoFocus: true, value: query, placeholder: t("ext.ai.workflows.picker.search"), onChange: (event) => setQuery(event.target.value), onKeyDown: (event) => { if (event.key === "Escape")
68
+ close(); } })] }), _jsxs("div", { className: "wf-picker-providers", children: [_jsx("button", { type: "button", className: `wf-pill${only === null ? " is-on" : ""}`, onClick: () => setOnly(null), children: t("ext.ai.workflows.picker.all") }), ready.map((item) => (_jsxs("button", { type: "button", className: `wf-pill${only === item.id ? " is-on" : ""}`, onClick: () => setOnly(item.id), children: [_jsx(ProviderIcon, { provider: item.id, icon: item.icon, size: 14 }), item.label] }, item.id))), _jsxs("label", { className: "wf-picker-fit", children: [_jsx("input", { type: "checkbox", checked: onlyFit, onChange: (event) => setOnlyFit(event.target.checked) }), t("ext.ai.workflows.picker.onlyFit")] })] }), _jsxs("div", { className: "wf-picker-list", children: [!ready.length ? _jsx("p", { className: "wf-muted wf-pad", children: t("ext.ai.workflows.picker.noProviders") }) : null, groups.map(({ entry: item, models, more }) => (_jsxs("section", { children: [_jsxs("h4", { className: "wf-picker-group", children: [_jsx(ProviderIcon, { provider: item.id, icon: item.icon, size: 14 }), item.label] }), item.error ? _jsx("p", { className: "wf-muted wf-pad", children: item.error }) : null, !item.models && !item.error ? _jsx("p", { className: "wf-muted wf-pad", children: t("ext.ai.workflows.picker.noList") }) : null, _jsx("ul", { children: models.map((choice) => row(item, choice)) }), more ? _jsx("p", { className: "wf-muted wf-pad", children: t("ext.ai.workflows.picker.more", { count: more }) }) : null] }, item.id))), typed && typedProvider ? (_jsxs("button", { type: "button", className: "wf-model-row", onClick: () => choose({ provider: typedProvider, model: typed }), children: [_jsx(ModelIcon, { model: typed, provider: typedProvider, size: 20 }), _jsxs("span", { className: "wf-model-text", children: [_jsx("span", { className: "wf-model-name", children: t("ext.ai.workflows.picker.useTyped", { model: typed }) }), _jsx("span", { className: "wf-model-id", children: catalog.providers.find((item) => item.id === typedProvider)?.label })] })] })) : null] })] })) : null] }));
69
+ }
@@ -0,0 +1,3 @@
1
+ import "../ai.css";
2
+ import "./workflow.css";
3
+ export declare function Workflows(): import("react").JSX.Element;
@@ -0,0 +1,118 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { PageSkeleton, Skeleton, useT } from "tansy/admin";
4
+ import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
5
+ import { Plus, Spark, Trash } from "../parts";
6
+ import { deleteWorkflow, listWorkflows, loadCatalog, loadWorkflow, startRun } from "./client";
7
+ import { WorkflowEditor } from "./editor";
8
+ import { ProviderIcon } from "./icons";
9
+ import { RunView, StatusPill } from "./run";
10
+ import { fromTemplate, TEMPLATES } from "./templates";
11
+ import "../ai.css";
12
+ import "./workflow.css";
13
+ function screenOf(search) {
14
+ const params = new URLSearchParams(search);
15
+ const run = params.get("run");
16
+ if (run && /^[a-z0-9]{8,32}$/.test(run))
17
+ return { kind: "run", id: run };
18
+ const workflow = params.get("workflow");
19
+ if (workflow && /^[a-z0-9][a-z0-9-]{0,39}$/.test(workflow))
20
+ return { kind: "edit", id: workflow };
21
+ const template = params.get("new");
22
+ if (template && TEMPLATES.includes(template))
23
+ return { kind: "new", template };
24
+ return { kind: "home" };
25
+ }
26
+ function go(screen) {
27
+ const url = new URL(window.location.href);
28
+ for (const key of ["run", "workflow", "new"])
29
+ url.searchParams.delete(key);
30
+ if (screen.kind === "run")
31
+ url.searchParams.set("run", screen.id);
32
+ if (screen.kind === "edit")
33
+ url.searchParams.set("workflow", screen.id);
34
+ if (screen.kind === "new")
35
+ url.searchParams.set("new", screen.template);
36
+ window.history.pushState(null, "", url);
37
+ window.dispatchEvent(new PopStateEvent("popstate"));
38
+ }
39
+ const subscribe = (change) => {
40
+ window.addEventListener("popstate", change);
41
+ return () => window.removeEventListener("popstate", change);
42
+ };
43
+ /** The inputs a run asks for, then starts it. */
44
+ function RunDialog({ workflow, onClose, onStarted }) {
45
+ const { t } = useT();
46
+ const [inputs, setInputs] = useState({});
47
+ const [error, setError] = useState(null);
48
+ const [busy, setBusy] = useState(false);
49
+ return (_jsx("div", { className: "wf-dialog-scrim", role: "presentation", onClick: onClose, children: _jsxs("form", { className: "wf-dialog", role: "dialog", "aria-modal": "true", "aria-label": t("ext.ai.workflows.start.title"), onClick: (event) => event.stopPropagation(), onSubmit: async (event) => {
50
+ event.preventDefault();
51
+ setBusy(true);
52
+ setError(null);
53
+ try {
54
+ const { run } = await startRun(workflow.id, inputs);
55
+ onStarted(run.id);
56
+ }
57
+ catch (caught) {
58
+ setError(caught instanceof Error ? caught.message : String(caught));
59
+ setBusy(false);
60
+ }
61
+ }, children: [_jsxs("h2", { children: [_jsx(Spark, { className: "ai-icon" }), workflow.name] }), workflow.description ? _jsx("p", { className: "wf-muted", children: workflow.description }) : null, (workflow.inputs ?? []).map((input) => (_jsxs("label", { className: "wf-field wf-field-wide", children: [_jsxs("span", { className: "wf-label", children: [input.label, input.required === false ? ` (${t("ext.ai.workflows.start.optional")})` : ""] }), input.multiline
62
+ ? _jsx("textarea", { className: "wf-input wf-textarea", required: input.required !== false, value: inputs[input.name] ?? "", onChange: (event) => setInputs({ ...inputs, [input.name]: event.target.value }) })
63
+ : _jsx("input", { className: "wf-input", required: input.required !== false, value: inputs[input.name] ?? "", onChange: (event) => setInputs({ ...inputs, [input.name]: event.target.value }) })] }, input.name))), _jsx("p", { className: "wf-muted", children: t("ext.ai.workflows.start.hint") }), error ? _jsx("p", { className: "wf-problem wf-problem-error", children: error }) : null, _jsxs("div", { className: "wf-dialog-actions", children: [_jsx("button", { type: "button", className: "wf-button wf-button-ghost", onClick: onClose, children: t("ext.ai.workflows.start.cancel") }), _jsx("button", { type: "submit", className: "wf-button", disabled: busy, children: busy ? t("ext.ai.workflows.start.starting") : t("ext.ai.workflows.start.go") })] })] }) }));
64
+ }
65
+ export function Workflows() {
66
+ const { t } = useT();
67
+ const w = (key, values) => t(`ext.ai.workflows.${key}`, values);
68
+ const search = useSyncExternalStore(subscribe, () => window.location.search, () => "");
69
+ const screen = useMemo(() => screenOf(search), [search]);
70
+ const [list, setList] = useState(null);
71
+ const [catalog, setCatalog] = useState(null);
72
+ const [loaded, setLoaded] = useState(null);
73
+ const [running, setRunning] = useState(null);
74
+ const [error, setError] = useState(null);
75
+ const open = useCallback((next) => go(next), []);
76
+ const refresh = useCallback(() => listWorkflows().then(setList).catch((caught) => setError(caught.message)), []);
77
+ useEffect(() => { if (screen.kind === "home")
78
+ void refresh(); }, [screen, refresh]);
79
+ // Models and collections, for the builder and for showing each workflow's team.
80
+ useEffect(() => { void loadCatalog().then(setCatalog).catch((caught) => setError(caught.message)); }, []);
81
+ const editId = screen.kind === "edit" ? screen.id : null;
82
+ useEffect(() => {
83
+ if (editId)
84
+ void loadWorkflow(editId).then(({ workflow }) => setLoaded(workflow)).catch((caught) => setError(caught.message));
85
+ }, [editId]);
86
+ const template = screen.kind === "new" ? screen.template : null;
87
+ const templateName = template ? w(`templates.${template}.name`) : "";
88
+ const fresh = useMemo(() => (template && catalog ? fromTemplate(template, catalog, catalog.collections.map((item) => item.slug), templateName) : null), [template, catalog, templateName]);
89
+ const editing = screen.kind === "new" ? fresh : loaded?.id === editId ? loaded : null;
90
+ const runWorkflow = async (id) => {
91
+ try {
92
+ const { workflow } = await loadWorkflow(id);
93
+ if (!(workflow.inputs ?? []).length) {
94
+ const { run } = await startRun(id, {});
95
+ open({ kind: "run", id: run.id });
96
+ }
97
+ else
98
+ setRunning(workflow);
99
+ }
100
+ catch (caught) {
101
+ setError(caught instanceof Error ? caught.message : String(caught));
102
+ }
103
+ };
104
+ const dialog = running ? _jsx(RunDialog, { workflow: running, onClose: () => setRunning(null), onStarted: (id) => { setRunning(null); open({ kind: "run", id }); } }) : null;
105
+ if (screen.kind === "run")
106
+ return _jsxs(_Fragment, { children: [_jsx(RunView, { id: screen.id, onBack: () => open({ kind: "home" }), onEdit: (id) => open({ kind: "edit", id }) }, screen.id), dialog] });
107
+ if (screen.kind === "edit" || screen.kind === "new") {
108
+ if (error)
109
+ return _jsx("div", { className: "wf-page", children: _jsx("p", { className: "wf-problem wf-problem-error", children: error }) });
110
+ if (!editing || !catalog)
111
+ return _jsx(PageSkeleton, { kind: "form" });
112
+ return (_jsxs(_Fragment, { children: [_jsx(WorkflowEditor, { initial: editing, catalog: catalog, collections: catalog.collections, onBack: () => open({ kind: "home" }), onSaved: (saved) => { if (screen.kind === "new") {
113
+ go({ kind: "edit", id: saved.id });
114
+ } }, onRun: (id) => void runWorkflow(id) }, editing.id), dialog] }));
115
+ }
116
+ return (_jsxs("div", { className: "wf-page wf-home", children: [_jsxs("header", { className: "wf-hero", children: [_jsxs("div", { children: [_jsxs("h1", { children: [_jsx(Spark, { className: "ai-icon" }), w("title")] }), _jsx("p", { className: "wf-muted", children: w("intro") })] }), catalog ? (_jsx("div", { className: "wf-hero-providers", "aria-label": w("providers"), children: catalog.providers.map((entry) => _jsx("span", { className: `wf-provider${entry.ready ? " is-ready" : ""}`, title: `${entry.label}: ${entry.ready ? w("ready") : w("notSetUp")}`, children: _jsx(ProviderIcon, { provider: entry.id, icon: entry.icon, size: 18 }) }, entry.id)) })) : null] }), error ? _jsx("p", { className: "wf-problem wf-problem-error", children: error }) : null, _jsxs("section", { children: [_jsx("h2", { className: "wf-h2", children: w("startFrom") }), _jsx("div", { className: "wf-templates", children: TEMPLATES.map((template) => (_jsxs("button", { type: "button", className: "wf-template", disabled: !catalog, onClick: () => open({ kind: "new", template }), children: [_jsx("span", { className: "wf-template-icon", children: template === "blank" ? _jsx(Plus, {}) : _jsx(Spark, { className: "ai-icon" }) }), _jsx("strong", { children: w(`templates.${template}.name`) }), _jsx("span", { className: "wf-muted", children: w(`templates.${template}.hint`) })] }, template))) })] }), _jsxs("section", { children: [_jsx("h2", { className: "wf-h2", children: w("yours") }), !list ? _jsx("div", { className: "cms-stack-2", "aria-busy": "true", children: [0, 1, 2].map((row) => _jsx(Skeleton, { height: "control" }, row)) }) : !list.workflows.length ? _jsx("p", { className: "wf-muted", children: w("empty") }) : (_jsx("div", { className: "wf-cards-grid", children: list.workflows.map((summary) => (_jsxs("article", { className: "wf-workflow", children: [_jsxs("button", { type: "button", className: "wf-workflow-main", onClick: () => open({ kind: "edit", id: summary.id }), children: [_jsx("strong", { children: summary.name }), summary.description ? _jsx("span", { className: "wf-muted", children: summary.description }) : null, _jsx("span", { className: "wf-workflow-meta", children: w("meta", { agents: summary.agents, steps: summary.steps }) })] }), _jsxs("div", { className: "wf-workflow-actions", children: [_jsxs("button", { type: "button", className: "wf-button", onClick: () => void runWorkflow(summary.id), children: [_jsx(Spark, { className: "ai-icon" }), w("run.start")] }), _jsx("button", { type: "button", className: "ai-ghost ai-ghost-icon", "aria-label": w("delete"), title: w("delete"), onClick: () => { if (window.confirm(w("deleteConfirm", { name: summary.name })))
117
+ void deleteWorkflow(summary.id).then(refresh); }, children: _jsx(Trash, {}) })] })] }, summary.id))) }))] }), list?.runs.length ? (_jsxs("section", { children: [_jsx("h2", { className: "wf-h2", children: w("runs") }), _jsx("ul", { className: "wf-runs", children: list.runs.map((run) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "wf-run-row", onClick: () => open({ kind: "run", id: run.id }), children: [_jsx(StatusPill, { status: run.status }), _jsx("strong", { children: run.workflowName }), _jsx("span", { className: "wf-muted", children: w("runRow", { ready: run.ready, items: run.items, created: run.created }) }), _jsxs("span", { className: "wf-muted", children: [run.createdBy, " \u00B7 ", new Date(run.createdAt).toLocaleString()] })] }) }, run.id))) })] })) : null, dialog] }));
118
+ }
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ import { type JobDefinition } from "tansy/plugin";
3
+ import type { AiProvider } from "../provider";
4
+ /** Building, running and reviewing workflows. They choose which paid models run, so they have their own permission. */
5
+ export declare const WORKFLOWS = "ext.ai:workflows";
6
+ export declare function workflowRoutes(providers: AiProvider[]): import("tansy/plugin").ExtensionRoute<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>[];
7
+ /**
8
+ * Picks up runs a stopped server left, once a minute. Each run is worked on by one server at a
9
+ * time. Where background work runs in passes with a deadline, as on Vercel, this is what moves
10
+ * runs on: each pass works on them until just before its deadline, and the next carries on.
11
+ */
12
+ export declare function workflowJob(providers: AiProvider[]): JobDefinition;