@particle-academy/fancy-flow 0.4.0 → 0.5.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.
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/registry/index.d.cts +4 -120
- package/dist/registry/index.d.ts +4 -120
- package/dist/styles.css +563 -0
- package/dist/styles.css.map +1 -1
- package/dist/types-BodwZiST.d.ts +121 -0
- package/dist/types-D5RERHIP.d.cts +121 -0
- package/dist/ux.cjs +74 -0
- package/dist/ux.cjs.map +1 -0
- package/dist/ux.d.cts +51 -0
- package/dist/ux.d.ts +51 -0
- package/dist/ux.js +52 -0
- package/dist/ux.js.map +1 -0
- package/package.json +12 -1
package/dist/ux.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { registerNodeKind } from './chunk-WNVBXXOL.js';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { createEffectDispatcher } from '@particle-academy/fancy-auto-common';
|
|
4
|
+
|
|
5
|
+
var defaultKindFor = (name) => `ux_${name}`;
|
|
6
|
+
function createFlowRunnerUx(options) {
|
|
7
|
+
const {
|
|
8
|
+
effects,
|
|
9
|
+
meta = {},
|
|
10
|
+
actor = { id: "flow", source: "flow" },
|
|
11
|
+
kindFor = defaultKindFor
|
|
12
|
+
} = options;
|
|
13
|
+
const dispatcher = createEffectDispatcher(effects, { actor, targetKind: "ux" });
|
|
14
|
+
const executors = {};
|
|
15
|
+
for (const name of Object.keys(effects)) {
|
|
16
|
+
executors[kindFor(name)] = async ({ node }) => {
|
|
17
|
+
const params = node.data?.config ?? {};
|
|
18
|
+
const result = await dispatcher.dispatch(name, params);
|
|
19
|
+
return { effect: name, result };
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const registerKinds = () => {
|
|
23
|
+
for (const name of Object.keys(effects)) {
|
|
24
|
+
const m = meta[name] ?? {};
|
|
25
|
+
registerNodeKind({
|
|
26
|
+
name: kindFor(name),
|
|
27
|
+
category: m.category ?? "output",
|
|
28
|
+
label: m.label ?? name,
|
|
29
|
+
description: m.description ?? `Flow-driven UX effect: ${name}.`,
|
|
30
|
+
icon: m.icon ?? "\u2728",
|
|
31
|
+
accent: m.accent ?? "#8b5cf6",
|
|
32
|
+
inputs: [{ id: "in" }],
|
|
33
|
+
outputs: [],
|
|
34
|
+
configSchema: m.configSchema
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
executors,
|
|
40
|
+
dispatch: dispatcher.dispatch,
|
|
41
|
+
effectNames: dispatcher.names,
|
|
42
|
+
registerKinds
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function useFlowRunnerUx(options) {
|
|
46
|
+
const key = `${Object.keys(options.effects).sort().join(",")}|${options.actor?.id ?? "flow"}`;
|
|
47
|
+
return useMemo(() => createFlowRunnerUx(options), [key]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { createFlowRunnerUx, useFlowRunnerUx };
|
|
51
|
+
//# sourceMappingURL=ux.js.map
|
|
52
|
+
//# sourceMappingURL=ux.js.map
|
package/dist/ux.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ux.ts"],"names":[],"mappings":";;;;AAyEA,IAAM,cAAA,GAAiB,CAAC,IAAA,KAAiB,CAAA,GAAA,EAAM,IAAI,CAAA,CAAA;AAG5C,SAAS,mBAAmB,OAAA,EAA4C;AAC7E,EAAA,MAAM;AAAA,IACJ,OAAA;AAAA,IACA,OAAO,EAAC;AAAA,IACR,KAAA,GAAQ,EAAE,EAAA,EAAI,MAAA,EAAQ,QAAQ,MAAA,EAAO;AAAA,IACrC,OAAA,GAAU;AAAA,GACZ,GAAI,OAAA;AAEJ,EAAA,MAAM,aAAa,sBAAA,CAAuB,OAA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A,CAAW,QAAA;AAAA,IACrB,aAAa,UAAA,CAAW,KAAA;AAAA,IACxB;AAAA,GACF;AACF;AAMO,SAAS,gBAAgB,OAAA,EAA4C;AAC1E,EAAA,MAAM,MAAM,CAAA,EAAG,MAAA,CAAO,IAAA,CAAK,OAAA,CAAQ,OAAO,CAAA,CAAE,IAAA,EAAK,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,EAAI,OAAA,CAAQ,KAAA,EAAO,MAAM,MAAM,CAAA,CAAA;AAE3F,EAAA,OAAO,QAAQ,MAAM,kBAAA,CAAmB,OAAO,CAAA,EAAG,CAAC,GAAG,CAAC,CAAA;AACzD","file":"ux.js","sourcesContent":["/**\n * FlowRunnerUx — the **flow-driven UX** bridge. The headless counterpart to\n * agent-integrations: where that wires an *agent* to host UI surfaces, this\n * wires a *running flow* to host UX. Both share the same primitives from\n * `@particle-academy/fancy-auto-common` (activity bus, effect dispatch).\n *\n * The host registers named UX effects (toast, navigate, confirm, …); this turns\n * each into a flow executor keyed by a node kind (`ux_<effect>` by default), so\n * dropping a `ux_toast` node into a `<FlowEditor>` and running it fires the\n * host's toast. Every dispatch broadcasts an `AutoActivityEvent` (source:\"flow\")\n * for presence / logging. Human-in-the-loop is free: an effect that returns a\n * Promise (e.g. an approval dialog) pauses the run until the user resolves it.\n *\n * const ux = createFlowRunnerUx({\n * effects: {\n * toast: ({ message }) => toast({ title: message }),\n * navigate:({ to }) => router.visit(to),\n * confirm: ({ prompt }) => new Promise(res => openDialog(prompt, res)), // pauses the run\n * },\n * });\n * ux.registerKinds(); // adds ux_toast / ux_navigate / ux_confirm to the palette\n * <FlowEditor initial={graph} executors={ux.executors} />\n */\nimport { useMemo } from \"react\";\nimport {\n createEffectDispatcher,\n type DispatchActor,\n type EffectRegistry,\n} from \"@particle-academy/fancy-auto-common\";\nimport { registerNodeKind } from \"./registry/registry\";\nimport type { ConfigField, NodeCategory } from \"./registry/types\";\nimport type { ExecutorRegistry, FlowNode } from \"./types\";\n\nexport type { AutoActivityEvent } from \"@particle-academy/fancy-auto-common\";\n\n/** Per-effect presentation for the palette node kind that drives it. */\nexport type UxEffectMeta = {\n /** Palette label. Default: the effect name. */\n label?: string;\n /** One-line palette description. */\n description?: string;\n /** Emoji / glyph for the node header. */\n icon?: string;\n /** Header accent color. */\n accent?: string;\n /** Palette grouping. Default \"output\". */\n category?: NodeCategory;\n /** Config form fields = the effect's params. */\n configSchema?: ConfigField[];\n};\n\nexport type FlowRunnerUxOptions = {\n /** Named host UX effects the flow can invoke. */\n effects: EffectRegistry;\n /** Optional per-effect palette metadata (used by `registerKinds`). */\n meta?: Record<string, UxEffectMeta>;\n /** Identifies the flow run in emitted activity. Default `{ id: \"flow\", source: \"flow\" }`. */\n actor?: DispatchActor;\n /** Map an effect name to its node-kind name. Default `ux_<effect>`. */\n kindFor?: (effectName: string) => string;\n};\n\nexport type FlowRunnerUx = {\n /** Executor registry to hand to `<FlowEditor executors>` or `runFlow`. */\n executors: ExecutorRegistry;\n /** Invoke an effect imperatively (also emits activity). */\n dispatch: <R = unknown>(name: string, params?: unknown) => Promise<R>;\n /** All effect names. */\n effectNames: () => string[];\n /** Register a palette node kind per effect (`ux_<effect>`). Idempotent. */\n registerKinds: () => void;\n};\n\nconst defaultKindFor = (name: string) => `ux_${name}`;\n\n/** Build a FlowRunnerUx from a set of host effects. Framework-agnostic. */\nexport function createFlowRunnerUx(options: FlowRunnerUxOptions): FlowRunnerUx {\n const {\n effects,\n meta = {},\n actor = { id: \"flow\", source: \"flow\" },\n kindFor = defaultKindFor,\n } = options;\n\n const dispatcher = createEffectDispatcher(effects, { actor, targetKind: \"ux\" });\n\n const executors: ExecutorRegistry = {};\n for (const name of Object.keys(effects)) {\n executors[kindFor(name)] = async ({ node }: { node: FlowNode }) => {\n const params = (node.data as { config?: Record<string, unknown> } | undefined)?.config ?? {};\n const result = await dispatcher.dispatch(name, params);\n return { effect: name, result };\n };\n }\n\n const registerKinds = () => {\n for (const name of Object.keys(effects)) {\n const m = meta[name] ?? {};\n registerNodeKind({\n name: kindFor(name),\n category: m.category ?? \"output\",\n label: m.label ?? name,\n description: m.description ?? `Flow-driven UX effect: ${name}.`,\n icon: m.icon ?? \"✨\",\n accent: m.accent ?? \"#8b5cf6\",\n inputs: [{ id: \"in\" }],\n outputs: [],\n configSchema: m.configSchema,\n });\n }\n };\n\n return {\n executors,\n dispatch: dispatcher.dispatch as FlowRunnerUx[\"dispatch\"],\n effectNames: dispatcher.names,\n registerKinds,\n };\n}\n\n/**\n * React hook form — memoizes on the effect-name set + actor id so the returned\n * executors keep a stable identity across renders.\n */\nexport function useFlowRunnerUx(options: FlowRunnerUxOptions): FlowRunnerUx {\n const key = `${Object.keys(options.effects).sort().join(\",\")}|${options.actor?.id ?? \"flow\"}`;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => createFlowRunnerUx(options), [key]);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@particle-academy/fancy-flow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Workflow editor + runner. Six built-in node kits (trigger / action / decision / output / note / subgraph), tokenized theme, topological execution with per-node status. React-flow bundled; consumers npm install fancy-flow and get nothing extra.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,6 +43,16 @@
|
|
|
43
43
|
"default": "./dist/engine.cjs"
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
|
+
"./ux": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/ux.d.ts",
|
|
49
|
+
"default": "./dist/ux.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/ux.d.cts",
|
|
53
|
+
"default": "./dist/ux.cjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
46
56
|
"./styles.css": "./dist/styles.css"
|
|
47
57
|
},
|
|
48
58
|
"files": [
|
|
@@ -70,6 +80,7 @@
|
|
|
70
80
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
71
81
|
},
|
|
72
82
|
"dependencies": {
|
|
83
|
+
"@particle-academy/fancy-auto-common": "^0.1.0",
|
|
73
84
|
"@xyflow/react": "^12.4.0",
|
|
74
85
|
"clsx": "^2.1.0"
|
|
75
86
|
},
|