@quantumwake/kgraph 0.1.2 → 0.2.1

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.
@@ -0,0 +1,60 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { N as NodeComponentProps, E as EdgeComponentProps, a as KGraphNode, b as KGraphEdge } from '../types-C9DQLToO.js';
3
+ import { CSSProperties } from 'react';
4
+
5
+ declare const NODE_WIDTH = 208;
6
+ declare const NODE_HEIGHT = 120;
7
+ declare const NODE_COLLAPSED = 44;
8
+ type StudioNodeKind = 'state' | 'processor' | 'transform' | 'function' | 'connector';
9
+ interface StudioNodeData {
10
+ kind?: StudioNodeKind;
11
+ typeLabel?: string;
12
+ title?: string;
13
+ subtitle?: string;
14
+ collapsed?: boolean;
15
+ onToggleCollapse?: () => void;
16
+ [key: string]: unknown;
17
+ }
18
+ declare function kindForNodeType(nodeType: string): StudioNodeKind;
19
+ declare function displayType(nodeType: string): string;
20
+ /**
21
+ * StudioNode — read-only kgraph node card in the Alethic ISM studio aesthetic
22
+ * (gradient tinted by type, neon accent header, glowing border when selected).
23
+ * Display fields come from node.data (StudioNodeData).
24
+ */
25
+ declare function StudioNode({ data, selected }: NodeComponentProps): react_jsx_runtime.JSX.Element;
26
+
27
+ /**
28
+ * CleanEdge — read-only kgraph edge for the dark studio (kgraph's default edge
29
+ * is hardcoded purple). Dashed bezier that reads on a dark canvas, with an
30
+ * arrowhead; brighter on hover/selection.
31
+ */
32
+ declare function CleanEdge({ sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, selected }: EdgeComponentProps): react_jsx_runtime.JSX.Element;
33
+
34
+ interface StudioGraphProps {
35
+ /** Pre-mapped kgraph nodes; node.data should carry StudioNodeData fields. */
36
+ nodes: KGraphNode[];
37
+ /** Pre-mapped kgraph edges. */
38
+ edges: KGraphEdge[];
39
+ /** Fired when a node is clicked. */
40
+ onNodeClick?: (node: KGraphNode) => void;
41
+ /** Allow per-node collapse (default true). */
42
+ collapsible?: boolean;
43
+ /**
44
+ * Id of the node to render as selected (glowing accent border). Selection is
45
+ * host-controlled — clicking a node reports via onNodeClick; the host decides
46
+ * what is selected and passes it back here.
47
+ */
48
+ selectedNodeId?: string;
49
+ className?: string;
50
+ style?: CSSProperties;
51
+ }
52
+ /**
53
+ * StudioGraph — a read-only kgraph canvas with the Alethic ISM studio look:
54
+ * every node renders as StudioNode, every edge as CleanEdge, non-interactive
55
+ * (no drag/connect), fit-to-view. Manages per-node collapse: collapsed nodes
56
+ * shrink to an icon and their kgraph dimensions/edge anchors shrink with them.
57
+ */
58
+ declare function StudioGraph({ nodes, edges, onNodeClick, collapsible, selectedNodeId, className, style }: StudioGraphProps): react_jsx_runtime.JSX.Element;
59
+
60
+ export { CleanEdge, NODE_COLLAPSED, NODE_HEIGHT, NODE_WIDTH, StudioGraph, type StudioGraphProps, StudioNode, type StudioNodeData, type StudioNodeKind, displayType, kindForNodeType };
@@ -0,0 +1,197 @@
1
+ import { Handle_default, getBezierPath, KGraphCanvas_default } from '../chunk-374K6PXA.js';
2
+ import { Plug, FunctionSquare, Shuffle, Cpu, Database, Plus, Minus } from 'lucide-react';
3
+ import { jsxs, jsx } from 'react/jsx-runtime';
4
+ import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
5
+
6
+ var NODE_WIDTH = 208;
7
+ var NODE_HEIGHT = 120;
8
+ var NODE_COLLAPSED = 44;
9
+ var KIND = {
10
+ state: { accent: "#34d399", glow: "rgba(16,185,129,0.18)", icon: Database },
11
+ // emerald
12
+ processor: { accent: "#fbbf24", glow: "rgba(245,158,11,0.18)", icon: Cpu },
13
+ // amber
14
+ transform: { accent: "#a78bfa", glow: "rgba(139,92,246,0.18)", icon: Shuffle },
15
+ // violet
16
+ function: { accent: "#38bdf8", glow: "rgba(14,165,233,0.18)", icon: FunctionSquare },
17
+ // sky
18
+ connector: { accent: "#94a3b8", glow: "rgba(100,116,139,0.18)", icon: Plug }
19
+ // slate
20
+ };
21
+ function kindForNodeType(nodeType) {
22
+ if (nodeType === "state") return "state";
23
+ if (nodeType.includes("coalescer") || nodeType.includes("composite")) return "transform";
24
+ if (nodeType.startsWith("function")) return "function";
25
+ if (nodeType.startsWith("connector")) return "connector";
26
+ return "processor";
27
+ }
28
+ var PROCESSOR_LABELS = {
29
+ processor_openai: "OpenAI",
30
+ processor_visual_openai: "Vision",
31
+ processor_anthropic: "Anthropic",
32
+ processor_google_ai: "Google AI",
33
+ processor_llama: "Llama",
34
+ processor_mistral: "Mistral",
35
+ processor_python: "Python",
36
+ processor_provider: "Provider",
37
+ processor_state_coalescer: "Coalescer",
38
+ processor_state_composite: "Composite",
39
+ function_datasource_sql: "SQL Source",
40
+ connector_source: "Source",
41
+ connector_sink: "Sink",
42
+ trainer: "Trainer",
43
+ processor: "Processor"
44
+ };
45
+ function displayType(nodeType) {
46
+ if (PROCESSOR_LABELS[nodeType]) return PROCESSOR_LABELS[nodeType];
47
+ const cleaned = nodeType.replace(/^processor_/, "").replace(/_/g, " ");
48
+ return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
49
+ }
50
+ var HANDLES = [
51
+ { id: "target-1", type: "target", position: "top" },
52
+ { id: "target-2", type: "target", position: "left" },
53
+ { id: "target-3", type: "target", position: "right" },
54
+ { id: "target-4", type: "target", position: "bottom" },
55
+ { id: "source-1", type: "source", position: "top" },
56
+ { id: "source-2", type: "source", position: "left" },
57
+ { id: "source-3", type: "source", position: "right" },
58
+ { id: "source-4", type: "source", position: "bottom" }
59
+ ];
60
+ var hiddenHandle = { opacity: 0, width: 8, height: 8, pointerEvents: "none" };
61
+ function StudioNode({ data, selected }) {
62
+ const d = data;
63
+ const kind = d.kind && d.kind in KIND ? d.kind : "processor";
64
+ const cfg = KIND[kind];
65
+ const Icon = cfg.icon;
66
+ const title = d.title || d.typeLabel || kind;
67
+ const shellStyle = {
68
+ backgroundImage: `linear-gradient(135deg, ${cfg.glow} 0%, #1e1e22 55%, #161618 100%)`,
69
+ border: `1.5px solid ${selected ? cfg.accent : "#33333a"}`,
70
+ boxShadow: selected ? `0 0 0 1px ${cfg.accent}, 0 0 18px ${cfg.glow}` : "0 1px 3px rgba(0,0,0,0.4)"
71
+ };
72
+ const toggle = (e) => {
73
+ e.stopPropagation();
74
+ d.onToggleCollapse?.();
75
+ };
76
+ if (d.collapsed) {
77
+ return /* @__PURE__ */ jsxs("div", { className: "group relative flex items-center justify-center rounded-lg", style: { width: NODE_COLLAPSED, height: NODE_COLLAPSED, ...shellStyle }, title: `${d.typeLabel ?? ""} \xB7 ${title}`, children: [
78
+ HANDLES.map((h) => /* @__PURE__ */ jsx(Handle_default, { id: h.id, type: h.type, position: h.position, style: hiddenHandle }, `${h.type}-${h.position}`)),
79
+ /* @__PURE__ */ jsx(Icon, { className: "h-5 w-5", style: { color: cfg.accent } }),
80
+ /* @__PURE__ */ jsx(
81
+ "button",
82
+ {
83
+ onClick: toggle,
84
+ title: "Expand",
85
+ className: "absolute right-0.5 top-0.5 hidden rounded p-0.5 text-slate-400 hover:bg-white/10 hover:text-slate-100 group-hover:block",
86
+ children: /* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" })
87
+ }
88
+ )
89
+ ] });
90
+ }
91
+ return /* @__PURE__ */ jsxs("div", { className: "group relative overflow-hidden rounded-lg", style: { width: NODE_WIDTH, height: NODE_HEIGHT, ...shellStyle }, children: [
92
+ HANDLES.map((h) => /* @__PURE__ */ jsx(Handle_default, { id: h.id, type: h.type, position: h.position, style: hiddenHandle }, `${h.type}-${h.position}`)),
93
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-2", style: { borderBottom: "1px solid rgba(255,255,255,0.06)" }, children: [
94
+ /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4 flex-shrink-0", style: { color: cfg.accent } }),
95
+ /* @__PURE__ */ jsx("span", { className: "truncate text-[11px] font-semibold uppercase tracking-wide", style: { color: cfg.accent }, children: d.typeLabel }),
96
+ d.onToggleCollapse ? /* @__PURE__ */ jsx("button", { onClick: toggle, title: "Collapse", className: "ml-auto rounded p-0.5 text-slate-500 hover:bg-white/10 hover:text-slate-200", children: /* @__PURE__ */ jsx(Minus, { className: "h-3.5 w-3.5" }) }) : null
97
+ ] }),
98
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2", children: [
99
+ /* @__PURE__ */ jsx("div", { className: "truncate text-sm font-medium", style: { color: "#f1f5f9" }, title, children: title }),
100
+ d.subtitle ? /* @__PURE__ */ jsx("div", { className: "mt-0.5 truncate text-xs", style: { color: "#94a3b8" }, children: d.subtitle }) : null
101
+ ] })
102
+ ] });
103
+ }
104
+ function CleanEdge({ sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, selected }) {
105
+ const [d] = getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition });
106
+ const stroke = selected ? "#c4b5fd" : "#7c8499";
107
+ return /* @__PURE__ */ jsxs("g", { children: [
108
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("marker", { id: "kgraph-ism-arrow", markerWidth: "10", markerHeight: "10", refX: "7", refY: "3", orient: "auto", markerUnits: "strokeWidth", children: /* @__PURE__ */ jsx("path", { d: "M0,0 L6,3 L0,6 Z", fill: stroke }) }) }),
109
+ /* @__PURE__ */ jsx("path", { d, fill: "none", stroke: "transparent", strokeWidth: 18 }),
110
+ /* @__PURE__ */ jsx(
111
+ "path",
112
+ {
113
+ d,
114
+ fill: "none",
115
+ stroke,
116
+ strokeWidth: selected ? 2 : 1.5,
117
+ strokeDasharray: "6 3",
118
+ markerEnd: "url(#kgraph-ism-arrow)"
119
+ }
120
+ )
121
+ ] });
122
+ }
123
+ function seedCollapsed(nodes) {
124
+ return new Set(nodes.filter((n) => n.data?.collapsed).map((n) => n.id));
125
+ }
126
+ function StudioGraph({ nodes, edges, onNodeClick, collapsible = true, selectedNodeId, className, style }) {
127
+ const [collapsed, setCollapsed] = useState(() => seedCollapsed(nodes));
128
+ const seedKey = useRef("");
129
+ useEffect(() => {
130
+ const key = nodes.map((n) => n.id).sort().join("\0");
131
+ if (key !== seedKey.current) {
132
+ seedKey.current = key;
133
+ setCollapsed(seedCollapsed(nodes));
134
+ }
135
+ }, [nodes]);
136
+ const toggleCollapse = useCallback((id) => {
137
+ setCollapsed((prev) => {
138
+ const next = new Set(prev);
139
+ if (next.has(id)) next.delete(id);
140
+ else next.add(id);
141
+ return next;
142
+ });
143
+ }, []);
144
+ const renderNodes = useMemo(
145
+ () => nodes.map((n) => {
146
+ const isCollapsed = collapsed.has(n.id);
147
+ return {
148
+ ...n,
149
+ width: isCollapsed ? NODE_COLLAPSED : NODE_WIDTH,
150
+ height: isCollapsed ? NODE_COLLAPSED : NODE_HEIGHT,
151
+ selected: selectedNodeId != null && n.id === selectedNodeId,
152
+ data: {
153
+ ...n.data,
154
+ collapsed: isCollapsed,
155
+ onToggleCollapse: collapsible ? () => toggleCollapse(n.id) : void 0
156
+ }
157
+ };
158
+ }),
159
+ [nodes, collapsed, collapsible, toggleCollapse, selectedNodeId]
160
+ );
161
+ const nodeTypes = useMemo(() => {
162
+ const m = { state: StudioNode, processor: StudioNode };
163
+ renderNodes.forEach((n) => {
164
+ m[n.type] = StudioNode;
165
+ });
166
+ return m;
167
+ }, [renderNodes]);
168
+ const edgeTypes = useMemo(() => {
169
+ const m = { default: CleanEdge };
170
+ edges.forEach((e) => {
171
+ if (e.type) m[e.type] = CleanEdge;
172
+ });
173
+ return m;
174
+ }, [edges]);
175
+ return /* @__PURE__ */ jsx(
176
+ KGraphCanvas_default,
177
+ {
178
+ nodes: renderNodes,
179
+ edges,
180
+ nodeTypes,
181
+ edgeTypes,
182
+ nodesDraggable: false,
183
+ nodesConnectable: false,
184
+ elementsSelectable: true,
185
+ fitView: true,
186
+ showMiniMap: false,
187
+ showBackground: true,
188
+ className,
189
+ style: { width: "100%", height: "100%", background: "#0e0e10", ...style },
190
+ onNodeClick: onNodeClick ? (_evt, node) => onNodeClick(node) : void 0
191
+ }
192
+ );
193
+ }
194
+
195
+ export { CleanEdge, NODE_COLLAPSED, NODE_HEIGHT, NODE_WIDTH, StudioGraph, StudioNode, displayType, kindForNodeType };
196
+ //# sourceMappingURL=index.js.map
197
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ism/nodes.tsx","../../src/ism/edges.tsx","../../src/ism/StudioGraph.tsx"],"names":["jsxs","jsx"],"mappings":";;;;;AAMO,IAAM,UAAA,GAAa;AACnB,IAAM,WAAA,GAAc;AACpB,IAAM,cAAA,GAAiB;AAiB9B,IAAM,IAAA,GAAmF;AAAA,EACrF,OAAO,EAAE,MAAA,EAAQ,WAAW,IAAA,EAAM,uBAAA,EAAyB,MAAM,QAAA,EAAS;AAAA;AAAA,EAC1E,WAAW,EAAE,MAAA,EAAQ,WAAW,IAAA,EAAM,uBAAA,EAAyB,MAAM,GAAA,EAAI;AAAA;AAAA,EACzE,WAAW,EAAE,MAAA,EAAQ,WAAW,IAAA,EAAM,uBAAA,EAAyB,MAAM,OAAA,EAAQ;AAAA;AAAA,EAC7E,UAAU,EAAE,MAAA,EAAQ,WAAW,IAAA,EAAM,uBAAA,EAAyB,MAAM,cAAA,EAAe;AAAA;AAAA,EACnF,WAAW,EAAE,MAAA,EAAQ,WAAW,IAAA,EAAM,wBAAA,EAA0B,MAAM,IAAA;AAAK;AAC/E,CAAA;AAEO,SAAS,gBAAgB,QAAA,EAAkC;AAC9D,EAAA,IAAI,QAAA,KAAa,SAAS,OAAO,OAAA;AACjC,EAAA,IAAI,QAAA,CAAS,SAAS,WAAW,CAAA,IAAK,SAAS,QAAA,CAAS,WAAW,GAAG,OAAO,WAAA;AAC7E,EAAA,IAAI,QAAA,CAAS,UAAA,CAAW,UAAU,CAAA,EAAG,OAAO,UAAA;AAC5C,EAAA,IAAI,QAAA,CAAS,UAAA,CAAW,WAAW,CAAA,EAAG,OAAO,WAAA;AAC7C,EAAA,OAAO,WAAA;AACX;AAEA,IAAM,gBAAA,GAA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,CAAE,IAAA,EAAM,CAAA,CAAE,CAAA,CAAE,IAAI,CAAA,GAAI,SAAA;AAAA,IAC5B,CAAC,CAAA;AACD,IAAA,OAAO,CAAA;AAAA,EACX,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AAEV,EAAA,uBACIA,GAAAA;AAAA,IAAC,oBAAA;AAAA,IAAA;AAAA,MACG,KAAA,EAAO,WAAA;AAAA,MACP,KAAA;AAAA,MACA,SAAA;AAAA,MACA,SAAA;AAAA,MACA,cAAA,EAAgB,KAAA;AAAA,MAChB,gBAAA,EAAkB,KAAA;AAAA,MAClB,kBAAA,EAAkB,IAAA;AAAA,MAClB,OAAA,EAAO,IAAA;AAAA,MACP,WAAA,EAAa,KAAA;AAAA,MACb,cAAA,EAAc,IAAA;AAAA,MACd,SAAA;AAAA,MACA,KAAA,EAAO,EAAE,KAAA,EAAO,MAAA,EAAQ,QAAQ,MAAA,EAAQ,UAAA,EAAY,SAAA,EAAW,GAAG,KAAA,EAAM;AAAA,MACxE,aAAa,WAAA,GAAc,CAAC,MAAM,IAAA,KAAS,WAAA,CAAY,IAAI,CAAA,GAAI;AAAA;AAAA,GACnE;AAER","file":"index.js","sourcesContent":["import type { MouseEvent } from 'react';\nimport { Handle } from '../index';\nimport type { NodeComponentProps, HandleType, HandlePosition } from '../types';\nimport { Database, Cpu, Shuffle, FunctionSquare, Plug, Minus, Plus, type LucideIcon } from 'lucide-react';\n\n// Footprint matches the Alethic ISM studio so published/exported layouts align.\nexport const NODE_WIDTH = 208;\nexport const NODE_HEIGHT = 120;\nexport const NODE_COLLAPSED = 44;\n\nexport type StudioNodeKind = 'state' | 'processor' | 'transform' | 'function' | 'connector';\n\n// Display fields precomputed by the host and placed on node.data.\nexport interface StudioNodeData {\n kind?: StudioNodeKind;\n typeLabel?: string;\n title?: string;\n subtitle?: string;\n // Injected by StudioGraph for collapse support.\n collapsed?: boolean;\n onToggleCollapse?: () => void;\n [key: string]: unknown;\n}\n\n// Dark studio palette (self-contained — no consumer Tailwind tokens needed).\nconst KIND: Record<StudioNodeKind, { accent: string; glow: string; icon: LucideIcon }> = {\n state: { accent: '#34d399', glow: 'rgba(16,185,129,0.18)', icon: Database }, // emerald\n processor: { accent: '#fbbf24', glow: 'rgba(245,158,11,0.18)', icon: Cpu }, // amber\n transform: { accent: '#a78bfa', glow: 'rgba(139,92,246,0.18)', icon: Shuffle }, // violet\n function: { accent: '#38bdf8', glow: 'rgba(14,165,233,0.18)', icon: FunctionSquare }, // sky\n connector: { accent: '#94a3b8', glow: 'rgba(100,116,139,0.18)', icon: Plug }, // slate\n};\n\nexport function kindForNodeType(nodeType: string): StudioNodeKind {\n if (nodeType === 'state') return 'state';\n if (nodeType.includes('coalescer') || nodeType.includes('composite')) return 'transform';\n if (nodeType.startsWith('function')) return 'function';\n if (nodeType.startsWith('connector')) return 'connector';\n return 'processor';\n}\n\nconst PROCESSOR_LABELS: Record<string, string> = {\n processor_openai: 'OpenAI',\n processor_visual_openai: 'Vision',\n processor_anthropic: 'Anthropic',\n processor_google_ai: 'Google AI',\n processor_llama: 'Llama',\n processor_mistral: 'Mistral',\n processor_python: 'Python',\n processor_provider: 'Provider',\n processor_state_coalescer: 'Coalescer',\n processor_state_composite: 'Composite',\n function_datasource_sql: 'SQL Source',\n connector_source: 'Source',\n connector_sink: 'Sink',\n trainer: 'Trainer',\n processor: 'Processor',\n};\n\nexport function displayType(nodeType: string): string {\n if (PROCESSOR_LABELS[nodeType]) return PROCESSOR_LABELS[nodeType];\n const cleaned = nodeType.replace(/^processor_/, '').replace(/_/g, ' ');\n return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);\n}\n\nconst HANDLES: { id: string; type: HandleType; position: HandlePosition }[] = [\n { id: 'target-1', type: 'target', position: 'top' },\n { id: 'target-2', type: 'target', position: 'left' },\n { id: 'target-3', type: 'target', position: 'right' },\n { id: 'target-4', type: 'target', position: 'bottom' },\n { id: 'source-1', type: 'source', position: 'top' },\n { id: 'source-2', type: 'source', position: 'left' },\n { id: 'source-3', type: 'source', position: 'right' },\n { id: 'source-4', type: 'source', position: 'bottom' },\n];\nconst hiddenHandle = { opacity: 0, width: 8, height: 8, pointerEvents: 'none' as const };\n\n/**\n * StudioNode — read-only kgraph node card in the Alethic ISM studio aesthetic\n * (gradient tinted by type, neon accent header, glowing border when selected).\n * Display fields come from node.data (StudioNodeData).\n */\nexport function StudioNode({ data, selected }: NodeComponentProps) {\n const d = data as StudioNodeData;\n const kind: StudioNodeKind = d.kind && d.kind in KIND ? d.kind : 'processor';\n const cfg = KIND[kind];\n const Icon = cfg.icon;\n const title = d.title || d.typeLabel || kind;\n\n const shellStyle = {\n backgroundImage: `linear-gradient(135deg, ${cfg.glow} 0%, #1e1e22 55%, #161618 100%)`,\n border: `1.5px solid ${selected ? cfg.accent : '#33333a'}`,\n boxShadow: selected ? `0 0 0 1px ${cfg.accent}, 0 0 18px ${cfg.glow}` : '0 1px 3px rgba(0,0,0,0.4)',\n };\n\n const toggle = (e: MouseEvent) => {\n e.stopPropagation();\n d.onToggleCollapse?.();\n };\n\n if (d.collapsed) {\n return (\n <div className=\"group relative flex items-center justify-center rounded-lg\" style={{ width: NODE_COLLAPSED, height: NODE_COLLAPSED, ...shellStyle }} title={`${d.typeLabel ?? ''} · ${title}`}>\n {HANDLES.map((h) => (\n <Handle key={`${h.type}-${h.position}`} id={h.id} type={h.type} position={h.position} style={hiddenHandle} />\n ))}\n <Icon className=\"h-5 w-5\" style={{ color: cfg.accent }} />\n <button\n onClick={toggle}\n title=\"Expand\"\n className=\"absolute right-0.5 top-0.5 hidden rounded p-0.5 text-slate-400 hover:bg-white/10 hover:text-slate-100 group-hover:block\"\n >\n <Plus className=\"h-3 w-3\" />\n </button>\n </div>\n );\n }\n\n return (\n <div className=\"group relative overflow-hidden rounded-lg\" style={{ width: NODE_WIDTH, height: NODE_HEIGHT, ...shellStyle }}>\n {HANDLES.map((h) => (\n <Handle key={`${h.type}-${h.position}`} id={h.id} type={h.type} position={h.position} style={hiddenHandle} />\n ))}\n\n <div className=\"flex items-center gap-2 px-3 py-2\" style={{ borderBottom: '1px solid rgba(255,255,255,0.06)' }}>\n <Icon className=\"h-4 w-4 flex-shrink-0\" style={{ color: cfg.accent }} />\n <span className=\"truncate text-[11px] font-semibold uppercase tracking-wide\" style={{ color: cfg.accent }}>\n {d.typeLabel}\n </span>\n {d.onToggleCollapse ? (\n <button onClick={toggle} title=\"Collapse\" className=\"ml-auto rounded p-0.5 text-slate-500 hover:bg-white/10 hover:text-slate-200\">\n <Minus className=\"h-3.5 w-3.5\" />\n </button>\n ) : null}\n </div>\n\n <div className=\"px-3 py-2\">\n <div className=\"truncate text-sm font-medium\" style={{ color: '#f1f5f9' }} title={title}>\n {title}\n </div>\n {d.subtitle ? (\n <div className=\"mt-0.5 truncate text-xs\" style={{ color: '#94a3b8' }}>\n {d.subtitle}\n </div>\n ) : null}\n </div>\n </div>\n );\n}\n","import { getBezierPath } from '../index';\nimport type { EdgeComponentProps } from '../types';\n\n/**\n * CleanEdge — read-only kgraph edge for the dark studio (kgraph's default edge\n * is hardcoded purple). Dashed bezier that reads on a dark canvas, with an\n * arrowhead; brighter on hover/selection.\n */\nexport function CleanEdge({ sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, selected }: EdgeComponentProps) {\n const [d] = getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition });\n const stroke = selected ? '#c4b5fd' : '#7c8499'; // violet-300 / slate\n return (\n <g>\n <defs>\n <marker id=\"kgraph-ism-arrow\" markerWidth=\"10\" markerHeight=\"10\" refX=\"7\" refY=\"3\" orient=\"auto\" markerUnits=\"strokeWidth\">\n <path d=\"M0,0 L6,3 L0,6 Z\" fill={stroke} />\n </marker>\n </defs>\n <path d={d} fill=\"none\" stroke=\"transparent\" strokeWidth={18} />\n <path\n d={d}\n fill=\"none\"\n stroke={stroke}\n strokeWidth={selected ? 2 : 1.5}\n strokeDasharray=\"6 3\"\n markerEnd=\"url(#kgraph-ism-arrow)\"\n />\n </g>\n );\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport type { CSSProperties } from 'react';\nimport { KGraphCanvas } from '../index';\nimport type { KGraphNode, KGraphEdge } from '../types';\nimport { StudioNode, NODE_WIDTH, NODE_HEIGHT, NODE_COLLAPSED } from './nodes';\nimport { CleanEdge } from './edges';\n\nexport interface StudioGraphProps {\n /** Pre-mapped kgraph nodes; node.data should carry StudioNodeData fields. */\n nodes: KGraphNode[];\n /** Pre-mapped kgraph edges. */\n edges: KGraphEdge[];\n /** Fired when a node is clicked. */\n onNodeClick?: (node: KGraphNode) => void;\n /** Allow per-node collapse (default true). */\n collapsible?: boolean;\n /**\n * Id of the node to render as selected (glowing accent border). Selection is\n * host-controlled — clicking a node reports via onNodeClick; the host decides\n * what is selected and passes it back here.\n */\n selectedNodeId?: string;\n className?: string;\n style?: CSSProperties;\n}\n\n/** Node ids whose data carries a truthy `collapsed` flag (seeded from the host). */\nfunction seedCollapsed(nodes: KGraphNode[]): Set<string> {\n return new Set(nodes.filter((n) => (n.data as { collapsed?: boolean })?.collapsed).map((n) => n.id));\n}\n\n/**\n * StudioGraph — a read-only kgraph canvas with the Alethic ISM studio look:\n * every node renders as StudioNode, every edge as CleanEdge, non-interactive\n * (no drag/connect), fit-to-view. Manages per-node collapse: collapsed nodes\n * shrink to an icon and their kgraph dimensions/edge anchors shrink with them.\n */\nexport function StudioGraph({ nodes, edges, onNodeClick, collapsible = true, selectedNodeId, className, style }: StudioGraphProps) {\n // Seed collapse from each node's data.collapsed (carried from the manifest);\n // the user can then toggle. Re-seed only when the node id set changes (a new\n // graph is loaded) so selection re-renders don't discard user toggles.\n const [collapsed, setCollapsed] = useState<Set<string>>(() => seedCollapsed(nodes));\n const seedKey = useRef<string>('');\n useEffect(() => {\n const key = nodes.map((n) => n.id).sort().join('\u0000');\n if (key !== seedKey.current) {\n seedKey.current = key;\n setCollapsed(seedCollapsed(nodes));\n }\n }, [nodes]);\n\n const toggleCollapse = useCallback((id: string) => {\n setCollapsed((prev) => {\n const next = new Set(prev);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n return next;\n });\n }, []);\n\n const renderNodes = useMemo<KGraphNode[]>(\n () =>\n nodes.map((n) => {\n const isCollapsed = collapsed.has(n.id);\n return {\n ...n,\n width: isCollapsed ? NODE_COLLAPSED : NODE_WIDTH,\n height: isCollapsed ? NODE_COLLAPSED : NODE_HEIGHT,\n selected: selectedNodeId != null && n.id === selectedNodeId,\n data: {\n ...n.data,\n collapsed: isCollapsed,\n onToggleCollapse: collapsible ? () => toggleCollapse(n.id) : undefined,\n },\n };\n }),\n [nodes, collapsed, collapsible, toggleCollapse, selectedNodeId],\n );\n\n const nodeTypes = useMemo(() => {\n const m: Record<string, typeof StudioNode> = { state: StudioNode, processor: StudioNode };\n renderNodes.forEach((n) => {\n m[n.type] = StudioNode;\n });\n return m;\n }, [renderNodes]);\n\n const edgeTypes = useMemo(() => {\n const m: Record<string, typeof CleanEdge> = { default: CleanEdge };\n edges.forEach((e) => {\n if (e.type) m[e.type] = CleanEdge;\n });\n return m;\n }, [edges]);\n\n return (\n <KGraphCanvas\n nodes={renderNodes}\n edges={edges}\n nodeTypes={nodeTypes}\n edgeTypes={edgeTypes}\n nodesDraggable={false}\n nodesConnectable={false}\n elementsSelectable\n fitView\n showMiniMap={false}\n showBackground\n className={className}\n style={{ width: '100%', height: '100%', background: '#0e0e10', ...style }}\n onNodeClick={onNodeClick ? (_evt, node) => onNodeClick(node) : undefined}\n />\n );\n}\n"]}
@@ -0,0 +1,172 @@
1
+ import React__default from 'react';
2
+
3
+ interface KGraphNode {
4
+ id: string;
5
+ type: string;
6
+ position: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ data: Record<string, any>;
11
+ selected?: boolean;
12
+ dragging?: boolean;
13
+ hidden?: boolean;
14
+ width?: number;
15
+ height?: number;
16
+ group?: string;
17
+ }
18
+ interface KGraphEdge {
19
+ id: string;
20
+ source: string;
21
+ target: string;
22
+ sourceHandle?: string;
23
+ targetHandle?: string;
24
+ type?: string;
25
+ data?: Record<string, any>;
26
+ selected?: boolean;
27
+ animated?: boolean;
28
+ }
29
+ interface KGraphConnection {
30
+ source: string;
31
+ target: string;
32
+ sourceHandle?: string;
33
+ targetHandle?: string;
34
+ }
35
+ type HandlePosition = 'top' | 'right' | 'bottom' | 'left';
36
+ type HandleType = 'source' | 'target';
37
+ interface HandleInfo {
38
+ nodeId: string;
39
+ handleId: string;
40
+ type: HandleType;
41
+ position: HandlePosition;
42
+ x: number;
43
+ y: number;
44
+ }
45
+ type NodeChange = {
46
+ type: 'position';
47
+ id: string;
48
+ position?: {
49
+ x: number;
50
+ y: number;
51
+ };
52
+ dragging: boolean;
53
+ } | {
54
+ type: 'select';
55
+ id: string;
56
+ selected: boolean;
57
+ } | {
58
+ type: 'remove';
59
+ id: string;
60
+ } | {
61
+ type: 'add';
62
+ item: KGraphNode;
63
+ } | {
64
+ type: 'dimensions';
65
+ id: string;
66
+ dimensions: {
67
+ width: number;
68
+ height: number;
69
+ };
70
+ };
71
+ type EdgeChange = {
72
+ type: 'select';
73
+ id: string;
74
+ selected: boolean;
75
+ } | {
76
+ type: 'remove';
77
+ id: string;
78
+ } | {
79
+ type: 'add';
80
+ item: KGraphEdge;
81
+ };
82
+ interface KGraphViewport {
83
+ x: number;
84
+ y: number;
85
+ zoom: number;
86
+ }
87
+ interface NodeComponentProps {
88
+ id: string;
89
+ data: Record<string, any>;
90
+ selected: boolean;
91
+ type: string;
92
+ }
93
+ interface EdgeComponentProps {
94
+ id: string;
95
+ sourceX: number;
96
+ sourceY: number;
97
+ targetX: number;
98
+ targetY: number;
99
+ sourcePosition: HandlePosition;
100
+ targetPosition: HandlePosition;
101
+ selected: boolean;
102
+ data?: Record<string, any>;
103
+ animated?: boolean;
104
+ style?: React__default.CSSProperties;
105
+ }
106
+ interface HandleProps {
107
+ id: string;
108
+ type: HandleType;
109
+ position: HandlePosition;
110
+ style?: React__default.CSSProperties;
111
+ className?: string;
112
+ }
113
+ interface KGraphCanvasProps {
114
+ nodes: KGraphNode[];
115
+ edges: KGraphEdge[];
116
+ onNodesChange?: (changes: NodeChange[]) => void;
117
+ onEdgesChange?: (changes: EdgeChange[]) => void;
118
+ onConnect?: (connection: KGraphConnection) => void;
119
+ onNodeClick?: (event: React__default.MouseEvent, node: KGraphNode) => void;
120
+ onEdgeClick?: (event: React__default.MouseEvent, edge: KGraphEdge) => void;
121
+ onPaneClick?: (event: React__default.MouseEvent) => void;
122
+ onDrop?: (event: React__default.DragEvent, position: {
123
+ x: number;
124
+ y: number;
125
+ }) => void;
126
+ onDragOver?: (event: React__default.DragEvent) => void;
127
+ nodeTypes?: Record<string, React__default.ComponentType<NodeComponentProps>>;
128
+ edgeTypes?: Record<string, React__default.ComponentType<EdgeComponentProps>>;
129
+ snapToGrid?: boolean;
130
+ snapGrid?: [number, number];
131
+ panOnDrag?: boolean;
132
+ zoomOnScroll?: boolean;
133
+ nodesDraggable?: boolean;
134
+ nodesConnectable?: boolean;
135
+ elementsSelectable?: boolean;
136
+ fitView?: boolean;
137
+ showMiniMap?: boolean;
138
+ showBackground?: boolean;
139
+ backgroundGap?: number;
140
+ minZoom?: number;
141
+ maxZoom?: number;
142
+ className?: string;
143
+ style?: React__default.CSSProperties;
144
+ children?: React__default.ReactNode;
145
+ }
146
+ interface KGraphContextValue {
147
+ viewport: KGraphViewport;
148
+ setViewport: React__default.Dispatch<React__default.SetStateAction<KGraphViewport>>;
149
+ screenToCanvasPosition: (screenX: number, screenY: number) => {
150
+ x: number;
151
+ y: number;
152
+ };
153
+ canvasToScreenPosition: (canvasX: number, canvasY: number) => {
154
+ x: number;
155
+ y: number;
156
+ };
157
+ fitView: (options?: {
158
+ padding?: number;
159
+ }) => void;
160
+ zoomIn: () => void;
161
+ zoomOut: () => void;
162
+ zoomTo: (level: number) => void;
163
+ registerHandle: (info: HandleInfo) => void;
164
+ unregisterHandle: (nodeId: string, handleId: string) => void;
165
+ getHandlePosition: (nodeId: string, handleId: string) => HandleInfo | undefined;
166
+ getAllHandles: () => Map<string, HandleInfo>;
167
+ containerRef: React__default.RefObject<HTMLDivElement | null>;
168
+ nodes: KGraphNode[];
169
+ edges: KGraphEdge[];
170
+ }
171
+
172
+ export type { EdgeComponentProps as E, HandleProps as H, KGraphCanvasProps as K, NodeComponentProps as N, KGraphNode as a, KGraphEdge as b, KGraphViewport as c, KGraphContextValue as d, NodeChange as e, HandlePosition as f, EdgeChange as g, HandleInfo as h, HandleType as i, KGraphConnection as j };
@@ -0,0 +1,172 @@
1
+ import React__default from 'react';
2
+
3
+ interface KGraphNode {
4
+ id: string;
5
+ type: string;
6
+ position: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ data: Record<string, any>;
11
+ selected?: boolean;
12
+ dragging?: boolean;
13
+ hidden?: boolean;
14
+ width?: number;
15
+ height?: number;
16
+ group?: string;
17
+ }
18
+ interface KGraphEdge {
19
+ id: string;
20
+ source: string;
21
+ target: string;
22
+ sourceHandle?: string;
23
+ targetHandle?: string;
24
+ type?: string;
25
+ data?: Record<string, any>;
26
+ selected?: boolean;
27
+ animated?: boolean;
28
+ }
29
+ interface KGraphConnection {
30
+ source: string;
31
+ target: string;
32
+ sourceHandle?: string;
33
+ targetHandle?: string;
34
+ }
35
+ type HandlePosition = 'top' | 'right' | 'bottom' | 'left';
36
+ type HandleType = 'source' | 'target';
37
+ interface HandleInfo {
38
+ nodeId: string;
39
+ handleId: string;
40
+ type: HandleType;
41
+ position: HandlePosition;
42
+ x: number;
43
+ y: number;
44
+ }
45
+ type NodeChange = {
46
+ type: 'position';
47
+ id: string;
48
+ position?: {
49
+ x: number;
50
+ y: number;
51
+ };
52
+ dragging: boolean;
53
+ } | {
54
+ type: 'select';
55
+ id: string;
56
+ selected: boolean;
57
+ } | {
58
+ type: 'remove';
59
+ id: string;
60
+ } | {
61
+ type: 'add';
62
+ item: KGraphNode;
63
+ } | {
64
+ type: 'dimensions';
65
+ id: string;
66
+ dimensions: {
67
+ width: number;
68
+ height: number;
69
+ };
70
+ };
71
+ type EdgeChange = {
72
+ type: 'select';
73
+ id: string;
74
+ selected: boolean;
75
+ } | {
76
+ type: 'remove';
77
+ id: string;
78
+ } | {
79
+ type: 'add';
80
+ item: KGraphEdge;
81
+ };
82
+ interface KGraphViewport {
83
+ x: number;
84
+ y: number;
85
+ zoom: number;
86
+ }
87
+ interface NodeComponentProps {
88
+ id: string;
89
+ data: Record<string, any>;
90
+ selected: boolean;
91
+ type: string;
92
+ }
93
+ interface EdgeComponentProps {
94
+ id: string;
95
+ sourceX: number;
96
+ sourceY: number;
97
+ targetX: number;
98
+ targetY: number;
99
+ sourcePosition: HandlePosition;
100
+ targetPosition: HandlePosition;
101
+ selected: boolean;
102
+ data?: Record<string, any>;
103
+ animated?: boolean;
104
+ style?: React__default.CSSProperties;
105
+ }
106
+ interface HandleProps {
107
+ id: string;
108
+ type: HandleType;
109
+ position: HandlePosition;
110
+ style?: React__default.CSSProperties;
111
+ className?: string;
112
+ }
113
+ interface KGraphCanvasProps {
114
+ nodes: KGraphNode[];
115
+ edges: KGraphEdge[];
116
+ onNodesChange?: (changes: NodeChange[]) => void;
117
+ onEdgesChange?: (changes: EdgeChange[]) => void;
118
+ onConnect?: (connection: KGraphConnection) => void;
119
+ onNodeClick?: (event: React__default.MouseEvent, node: KGraphNode) => void;
120
+ onEdgeClick?: (event: React__default.MouseEvent, edge: KGraphEdge) => void;
121
+ onPaneClick?: (event: React__default.MouseEvent) => void;
122
+ onDrop?: (event: React__default.DragEvent, position: {
123
+ x: number;
124
+ y: number;
125
+ }) => void;
126
+ onDragOver?: (event: React__default.DragEvent) => void;
127
+ nodeTypes?: Record<string, React__default.ComponentType<NodeComponentProps>>;
128
+ edgeTypes?: Record<string, React__default.ComponentType<EdgeComponentProps>>;
129
+ snapToGrid?: boolean;
130
+ snapGrid?: [number, number];
131
+ panOnDrag?: boolean;
132
+ zoomOnScroll?: boolean;
133
+ nodesDraggable?: boolean;
134
+ nodesConnectable?: boolean;
135
+ elementsSelectable?: boolean;
136
+ fitView?: boolean;
137
+ showMiniMap?: boolean;
138
+ showBackground?: boolean;
139
+ backgroundGap?: number;
140
+ minZoom?: number;
141
+ maxZoom?: number;
142
+ className?: string;
143
+ style?: React__default.CSSProperties;
144
+ children?: React__default.ReactNode;
145
+ }
146
+ interface KGraphContextValue {
147
+ viewport: KGraphViewport;
148
+ setViewport: React__default.Dispatch<React__default.SetStateAction<KGraphViewport>>;
149
+ screenToCanvasPosition: (screenX: number, screenY: number) => {
150
+ x: number;
151
+ y: number;
152
+ };
153
+ canvasToScreenPosition: (canvasX: number, canvasY: number) => {
154
+ x: number;
155
+ y: number;
156
+ };
157
+ fitView: (options?: {
158
+ padding?: number;
159
+ }) => void;
160
+ zoomIn: () => void;
161
+ zoomOut: () => void;
162
+ zoomTo: (level: number) => void;
163
+ registerHandle: (info: HandleInfo) => void;
164
+ unregisterHandle: (nodeId: string, handleId: string) => void;
165
+ getHandlePosition: (nodeId: string, handleId: string) => HandleInfo | undefined;
166
+ getAllHandles: () => Map<string, HandleInfo>;
167
+ containerRef: React__default.RefObject<HTMLDivElement | null>;
168
+ nodes: KGraphNode[];
169
+ edges: KGraphEdge[];
170
+ }
171
+
172
+ export type { EdgeComponentProps as E, HandleProps as H, KGraphCanvasProps as K, NodeComponentProps as N, KGraphNode as a, KGraphEdge as b, KGraphViewport as c, KGraphContextValue as d, NodeChange as e, HandlePosition as f, EdgeChange as g, HandleInfo as h, HandleType as i, KGraphConnection as j };