Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ca644dabaa | |||
| 9d9c00df98 | |||
| a1c5dc3e92 | |||
| c85980f604 | |||
| eff5fb332a | |||
| 658a4a24ef | |||
| aabfd90a87 | |||
| 0207f93303 | |||
| e1423f196b | |||
| ae6954a02f | |||
| aede8f7613 | |||
| 6d1e0498ba | |||
| 6cce5e2593 | |||
| d3a7ed9062 | |||
| e7f733c393 | |||
| d4bb4a9324 | |||
| 39540d9ae8 |
+2
-2
@@ -13,8 +13,8 @@
|
||||
"link": "./scripts/link-all.sh",
|
||||
"link:consume": "./scripts/link-all.sh --consume",
|
||||
"link:unlink": "./scripts/link-all.sh --unlink",
|
||||
"publish:gitea": "./scripts/publish-all.sh",
|
||||
"publish:gitea:dry": "./scripts/publish-all.sh --dry-run"
|
||||
"publish:gitea": "./scripts/publish.sh patch",
|
||||
"publish:gitea:dry": "./scripts/publish.sh --dry-run patch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.4.14",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/cli-workflow",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"src",
|
||||
"dist",
|
||||
@@ -11,13 +11,13 @@
|
||||
"uncaged-workflow": "src/cli.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-gateway": "workspace:*",
|
||||
"@uncaged/workflow-protocol": "workspace:*",
|
||||
"@uncaged/workflow-util": "workspace:*",
|
||||
"@uncaged/workflow-cas": "workspace:*",
|
||||
"@uncaged/workflow-execute": "workspace:*",
|
||||
"@uncaged/workflow-register": "workspace:*",
|
||||
"@uncaged/workflow-runtime": "workspace:*",
|
||||
"@uncaged/workflow-gateway": "workspace:^",
|
||||
"@uncaged/workflow-protocol": "workspace:^",
|
||||
"@uncaged/workflow-util": "workspace:^",
|
||||
"@uncaged/workflow-cas": "workspace:^",
|
||||
"@uncaged/workflow-execute": "workspace:^",
|
||||
"@uncaged/workflow-register": "workspace:^",
|
||||
"@uncaged/workflow-runtime": "workspace:^",
|
||||
"hono": "^4.12.18",
|
||||
"yaml": "^2.8.4"
|
||||
},
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-agent-cursor",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-protocol": "workspace:*",
|
||||
"@uncaged/workflow-reactor": "workspace:*",
|
||||
"@uncaged/workflow-runtime": "workspace:*",
|
||||
"@uncaged/workflow-util": "workspace:*",
|
||||
"@uncaged/workflow-util-agent": "workspace:*",
|
||||
"@uncaged/workflow-protocol": "workspace:^",
|
||||
"@uncaged/workflow-reactor": "workspace:^",
|
||||
"@uncaged/workflow-runtime": "workspace:^",
|
||||
"@uncaged/workflow-util": "workspace:^",
|
||||
"@uncaged/workflow-util-agent": "workspace:^",
|
||||
"zod": "^4.0.0"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-agent-hermes",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-runtime": "workspace:*",
|
||||
"@uncaged/workflow-util-agent": "workspace:*"
|
||||
"@uncaged/workflow-runtime": "workspace:^",
|
||||
"@uncaged/workflow-util-agent": "workspace:^"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-agent-llm",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-runtime": "workspace:*",
|
||||
"@uncaged/workflow-util-agent": "workspace:*"
|
||||
"@uncaged/workflow-runtime": "workspace:^",
|
||||
"@uncaged/workflow-util-agent": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"zod": "^4.0.0"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-agent-react",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"default": "./src/index.ts"
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-protocol": "workspace:*",
|
||||
"@uncaged/workflow-reactor": "workspace:*",
|
||||
"@uncaged/workflow-util-agent": "workspace:*"
|
||||
"@uncaged/workflow-protocol": "workspace:^",
|
||||
"@uncaged/workflow-reactor": "workspace:^",
|
||||
"@uncaged/workflow-util-agent": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"zod": "^4.0.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-cas",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
@@ -11,13 +11,14 @@
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-protocol": "workspace:*",
|
||||
"@uncaged/workflow-util": "workspace:*",
|
||||
"@uncaged/workflow-protocol": "workspace:^",
|
||||
"@uncaged/workflow-util": "workspace:^",
|
||||
"xxhashjs": "^0.2.2",
|
||||
"yaml": "^2.7.1"
|
||||
},
|
||||
|
||||
@@ -13,9 +13,7 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dagrejs/dagre": "^3.0.0",
|
||||
"@xyflow/react": "^12.10.2",
|
||||
"elkjs": "^0.11.1",
|
||||
"react": "^19.2.6",
|
||||
"react-dom": "^19.2.6",
|
||||
"react-markdown": "^10.1.0",
|
||||
|
||||
@@ -6,6 +6,42 @@ import {
|
||||
} from "@xyflow/react";
|
||||
import type { ConditionEdgeData } from "./types.ts";
|
||||
|
||||
// Must match the FEEDBACK_OFFSET_X in use-layout.ts
|
||||
const FEEDBACK_OFFSET_X = 100;
|
||||
// Radius for feedback edge corners
|
||||
const FEEDBACK_RADIUS = 16;
|
||||
|
||||
/**
|
||||
* Build an SVG path for a feedback (back) edge that routes to the right of the nodes.
|
||||
* The path goes: source right → arc → vertical up → arc → target right
|
||||
*/
|
||||
function feedbackPath(
|
||||
sourceX: number,
|
||||
sourceY: number,
|
||||
targetX: number,
|
||||
targetY: number,
|
||||
): string {
|
||||
const rightX = Math.max(sourceX, targetX) + FEEDBACK_OFFSET_X;
|
||||
const r = FEEDBACK_RADIUS;
|
||||
|
||||
// Start from source right side, go right, then up, then left to target right side
|
||||
const segments = [
|
||||
`M ${sourceX} ${sourceY}`,
|
||||
// Horizontal to the right
|
||||
`L ${rightX - r} ${sourceY}`,
|
||||
// Arc turning upward
|
||||
`Q ${rightX} ${sourceY} ${rightX} ${sourceY - r}`,
|
||||
// Vertical upward
|
||||
`L ${rightX} ${targetY + r}`,
|
||||
// Arc turning left
|
||||
`Q ${rightX} ${targetY} ${rightX - r} ${targetY}`,
|
||||
// Horizontal left to target
|
||||
`L ${targetX} ${targetY}`,
|
||||
];
|
||||
|
||||
return segments.join(" ");
|
||||
}
|
||||
|
||||
export function ConditionEdge(props: EdgeProps) {
|
||||
const {
|
||||
id,
|
||||
@@ -23,25 +59,41 @@ export function ConditionEdge(props: EdgeProps) {
|
||||
const edgeData = data as ConditionEdgeData | undefined;
|
||||
const isFallback = edgeData?.isFallback ?? false;
|
||||
const isSelfLoop = source === target;
|
||||
const isFeedback = edgeData?.isFeedback ?? false;
|
||||
|
||||
const [path, defaultLabelX, defaultLabelY] = getSmoothStepPath({
|
||||
sourceX,
|
||||
sourceY,
|
||||
targetX,
|
||||
targetY,
|
||||
sourcePosition,
|
||||
targetPosition,
|
||||
borderRadius: isSelfLoop ? 20 : 8,
|
||||
offset: isSelfLoop ? 50 : undefined,
|
||||
});
|
||||
let path: string;
|
||||
let defaultLabelX: number;
|
||||
let defaultLabelY: number;
|
||||
|
||||
if (isFeedback) {
|
||||
// Custom feedback path routed to the right
|
||||
path = feedbackPath(sourceX, sourceY, targetX, targetY);
|
||||
const rightX = Math.max(sourceX, targetX) + FEEDBACK_OFFSET_X;
|
||||
defaultLabelX = rightX;
|
||||
defaultLabelY = (sourceY + targetY) / 2;
|
||||
} else {
|
||||
const result = getSmoothStepPath({
|
||||
sourceX,
|
||||
sourceY,
|
||||
targetX,
|
||||
targetY,
|
||||
sourcePosition,
|
||||
targetPosition,
|
||||
borderRadius: isSelfLoop ? 20 : 8,
|
||||
offset: isSelfLoop ? 50 : undefined,
|
||||
});
|
||||
path = result[0];
|
||||
defaultLabelX = result[1];
|
||||
defaultLabelY = result[2];
|
||||
}
|
||||
|
||||
const stroke = isFallback ? "var(--color-text-muted)" : "var(--color-accent)";
|
||||
const strokeDasharray = isFallback ? "5 4" : undefined;
|
||||
const label = edgeData?.condition ?? "";
|
||||
|
||||
// Use ELK-computed label position if available, otherwise fall back to ReactFlow default
|
||||
const labelX = edgeData?.elkLabelX ?? defaultLabelX;
|
||||
const labelY = edgeData?.elkLabelY ?? defaultLabelY;
|
||||
// Use pre-computed label position if available, otherwise fall back to default
|
||||
const labelX = edgeData?.labelX ?? defaultLabelX;
|
||||
const labelY = edgeData?.labelY ?? defaultLabelY;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -21,8 +21,10 @@ export type ConditionEdgeData = {
|
||||
condition: string;
|
||||
conditionDescription: string | null;
|
||||
isFallback: boolean;
|
||||
elkLabelX: number | null;
|
||||
elkLabelY: number | null;
|
||||
isFeedback: boolean;
|
||||
isSelfLoop: boolean;
|
||||
labelX: number | null;
|
||||
labelY: number | null;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { Edge, Node } from "@xyflow/react";
|
||||
import ELK, { type ElkExtendedEdge, type ElkNode } from "elkjs/lib/elk.bundled.js";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useMemo } from "react";
|
||||
import type { WorkflowGraphEdge } from "../../api.ts";
|
||||
import type { ConditionEdgeData, NodeState, RoleNodeData, TerminalNodeData } from "./types.ts";
|
||||
|
||||
@@ -10,6 +9,11 @@ const ROLE_NODE_WIDTH = 180;
|
||||
const ROLE_NODE_HEIGHT = 60;
|
||||
const TERMINAL_NODE_SIZE = 40;
|
||||
|
||||
// Vertical gap between nodes in the spine
|
||||
const LAYER_GAP = 80;
|
||||
// Horizontal offset for feedback (back) edges routed on the right side
|
||||
const FEEDBACK_OFFSET_X = 100;
|
||||
|
||||
type LayoutInput = {
|
||||
edges: readonly WorkflowGraphEdge[];
|
||||
roles: Record<string, { description: string }>;
|
||||
@@ -21,15 +25,6 @@ type LayoutResult = {
|
||||
edges: Edge[];
|
||||
};
|
||||
|
||||
function collectNodeIds(edges: readonly WorkflowGraphEdge[]): Set<string> {
|
||||
const ids = new Set<string>();
|
||||
for (const e of edges) {
|
||||
ids.add(e.from);
|
||||
ids.add(e.to);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
function nodeSize(id: string): { width: number; height: number } {
|
||||
if (id === START_ID || id === END_ID) {
|
||||
return { width: TERMINAL_NODE_SIZE, height: TERMINAL_NODE_SIZE };
|
||||
@@ -41,6 +36,75 @@ function edgeKey(e: WorkflowGraphEdge): string {
|
||||
return `${e.from}->${e.to}::${e.condition}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the linear spine from the graph using topological ordering.
|
||||
* Forward edges go from lower rank to higher rank; feedback edges go backwards.
|
||||
* Self-loops are neither forward nor feedback — they're handled separately.
|
||||
*/
|
||||
function extractSpine(edges: readonly WorkflowGraphEdge[]): string[] {
|
||||
// Collect all node IDs
|
||||
const ids = new Set<string>();
|
||||
for (const e of edges) {
|
||||
ids.add(e.from);
|
||||
ids.add(e.to);
|
||||
}
|
||||
|
||||
// Build adjacency for forward edges only (non-self-loop, non-FALLBACK-back)
|
||||
// Strategy: BFS from __start__, picking the first non-FALLBACK forward edge,
|
||||
// or FALLBACK if no other option.
|
||||
const forwardAdj = new Map<string, string[]>();
|
||||
for (const e of edges) {
|
||||
if (e.from === e.to) continue;
|
||||
const existing = forwardAdj.get(e.from) ?? [];
|
||||
existing.push(e.to);
|
||||
forwardAdj.set(e.from, existing);
|
||||
}
|
||||
|
||||
// Walk the main path: prefer non-FALLBACK edges for the spine ordering
|
||||
const visited = new Set<string>();
|
||||
const spine: string[] = [];
|
||||
|
||||
// Build a set of "primary" next targets per node (non-FALLBACK first)
|
||||
const primaryNext = new Map<string, string>();
|
||||
const edgesByFrom = new Map<string, WorkflowGraphEdge[]>();
|
||||
for (const e of edges) {
|
||||
if (e.from === e.to) continue;
|
||||
const list = edgesByFrom.get(e.from) ?? [];
|
||||
list.push(e);
|
||||
edgesByFrom.set(e.from, list);
|
||||
}
|
||||
|
||||
// For each node, the "primary" next is the first non-FALLBACK target,
|
||||
// or the FALLBACK target if all edges are FALLBACK
|
||||
for (const [from, edgeList] of edgesByFrom) {
|
||||
const nonFallback = edgeList.find((e) => e.condition !== "FALLBACK");
|
||||
const fallback = edgeList.find((e) => e.condition === "FALLBACK");
|
||||
primaryNext.set(from, nonFallback?.to ?? fallback?.to ?? "");
|
||||
}
|
||||
|
||||
// Walk the spine from __start__
|
||||
let current: string | null = START_ID;
|
||||
while (current !== null && !visited.has(current)) {
|
||||
visited.add(current);
|
||||
spine.push(current);
|
||||
const next = primaryNext.get(current);
|
||||
if (next !== undefined && next !== "" && !visited.has(next)) {
|
||||
current = next;
|
||||
} else {
|
||||
current = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Add any remaining nodes not on the main path (shouldn't normally happen)
|
||||
for (const id of ids) {
|
||||
if (!visited.has(id)) {
|
||||
spine.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
return spine;
|
||||
}
|
||||
|
||||
function buildRoleNode(
|
||||
id: string,
|
||||
pos: { x: number; y: number },
|
||||
@@ -72,143 +136,95 @@ function buildTerminalNode(
|
||||
};
|
||||
}
|
||||
|
||||
function buildEdge(e: WorkflowGraphEdge, elkEdgeMap: Map<string, ElkExtendedEdge>): Edge<ConditionEdgeData> {
|
||||
const isFallback = e.condition === "FALLBACK";
|
||||
const key = edgeKey(e);
|
||||
const elkEdge = elkEdgeMap.get(key);
|
||||
|
||||
// Extract ELK's computed label position
|
||||
let labelX: number | null = null;
|
||||
let labelY: number | null = null;
|
||||
if (elkEdge?.labels && elkEdge.labels.length > 0) {
|
||||
const label = elkEdge.labels[0];
|
||||
if (label.x !== undefined && label.y !== undefined) {
|
||||
labelX = label.x + (label.width ?? 0) / 2;
|
||||
labelY = label.y + (label.height ?? 0) / 2;
|
||||
}
|
||||
function computeLayout(input: LayoutInput): LayoutResult {
|
||||
const spine = extractSpine(input.edges);
|
||||
const rank = new Map<string, number>();
|
||||
for (let i = 0; i < spine.length; i++) {
|
||||
rank.set(spine[i], i);
|
||||
}
|
||||
|
||||
return {
|
||||
id: key,
|
||||
source: e.from,
|
||||
target: e.to,
|
||||
type: "condition",
|
||||
data: {
|
||||
condition: e.condition,
|
||||
conditionDescription: e.conditionDescription,
|
||||
isFallback,
|
||||
elkLabelX: labelX,
|
||||
elkLabelY: labelY,
|
||||
},
|
||||
};
|
||||
}
|
||||
// Position nodes along a vertical spine, centered horizontally
|
||||
const centerX = ROLE_NODE_WIDTH / 2; // left edge at x=0, center at width/2
|
||||
const nodePositions = new Map<string, { x: number; y: number; w: number; h: number }>();
|
||||
|
||||
const elk = new ELK();
|
||||
|
||||
async function computeLayout(input: LayoutInput): Promise<LayoutResult> {
|
||||
const ids = collectNodeIds(input.edges);
|
||||
|
||||
const elkNodes: ElkNode[] = [];
|
||||
for (const id of ids) {
|
||||
let y = 0;
|
||||
for (const id of spine) {
|
||||
const size = nodeSize(id);
|
||||
elkNodes.push({ id, width: size.width, height: size.height });
|
||||
}
|
||||
|
||||
const elkEdges: ElkExtendedEdge[] = input.edges
|
||||
.filter((e) => e.from !== e.to)
|
||||
.map((e) => ({
|
||||
id: edgeKey(e),
|
||||
sources: [e.from],
|
||||
targets: [e.to],
|
||||
labels: e.condition !== ""
|
||||
? [{ text: e.condition, width: Math.max(e.condition.length * 7 + 16, 60), height: 22 }]
|
||||
: [],
|
||||
}));
|
||||
|
||||
const graph: ElkNode = {
|
||||
id: "root",
|
||||
layoutOptions: {
|
||||
"elk.algorithm": "layered",
|
||||
"elk.direction": "DOWN",
|
||||
// Node spacing
|
||||
"elk.spacing.nodeNode": "30",
|
||||
"elk.layered.spacing.nodeNodeBetweenLayers": "50",
|
||||
// Edge spacing — keep edges apart from each other and from nodes
|
||||
"elk.spacing.edgeNode": "25",
|
||||
"elk.spacing.edgeEdge": "15",
|
||||
"elk.layered.spacing.edgeNodeBetweenLayers": "25",
|
||||
"elk.layered.spacing.edgeEdgeBetweenLayers": "15",
|
||||
// Edge routing
|
||||
"elk.edgeRouting": "ORTHOGONAL",
|
||||
"elk.layered.mergeEdges": "false",
|
||||
// Node placement
|
||||
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
|
||||
// Edge label placement
|
||||
"elk.edgeLabels.placement": "CENTER",
|
||||
// Crossing minimization
|
||||
"elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
|
||||
// Compaction
|
||||
"elk.layered.compaction.postCompaction.strategy": "EDGE_LENGTH",
|
||||
// Cycle breaking — keep main flow top-to-bottom
|
||||
"elk.layered.cycleBreaking.strategy": "DEPTH_FIRST",
|
||||
},
|
||||
children: elkNodes,
|
||||
edges: elkEdges,
|
||||
};
|
||||
|
||||
const laid = await elk.layout(graph);
|
||||
|
||||
// Build map of ELK edge results for label positions
|
||||
const elkEdgeMap = new Map<string, ElkExtendedEdge>();
|
||||
for (const e of laid.edges ?? []) {
|
||||
elkEdgeMap.set(e.id, e);
|
||||
// Center-align all nodes on the spine
|
||||
const x = centerX - size.width / 2;
|
||||
nodePositions.set(id, { x, y, w: size.width, h: size.height });
|
||||
y += size.height + LAYER_GAP;
|
||||
}
|
||||
|
||||
// Build nodes
|
||||
const nodes: Node[] = [];
|
||||
for (const child of laid.children ?? []) {
|
||||
const pos = { x: child.x ?? 0, y: child.y ?? 0 };
|
||||
const state = input.nodeStates.get(child.id) ?? "default";
|
||||
if (child.id === START_ID || child.id === END_ID) {
|
||||
nodes.push(buildTerminalNode(child.id, pos, state));
|
||||
for (const id of spine) {
|
||||
const pos = nodePositions.get(id);
|
||||
if (pos === undefined) continue;
|
||||
const state = input.nodeStates.get(id) ?? "default";
|
||||
if (id === START_ID || id === END_ID) {
|
||||
nodes.push(buildTerminalNode(id, { x: pos.x, y: pos.y }, state));
|
||||
} else {
|
||||
nodes.push(buildRoleNode(child.id, pos, input.roles, state));
|
||||
nodes.push(buildRoleNode(id, { x: pos.x, y: pos.y }, input.roles, state));
|
||||
}
|
||||
}
|
||||
|
||||
const edges: Edge[] = input.edges.map((e) => buildEdge(e, elkEdgeMap));
|
||||
// Build edges with label positions
|
||||
// For feedback edges (target rank < source rank), we'll compute label at midpoint
|
||||
// of the right-side arc. The actual SVG path is drawn by ConditionEdge component.
|
||||
const edges: Edge[] = input.edges.map((e) => {
|
||||
const isFallback = e.condition === "FALLBACK";
|
||||
const isSelfLoop = e.from === e.to;
|
||||
const sourceRank = rank.get(e.from) ?? 0;
|
||||
const targetRank = rank.get(e.to) ?? 0;
|
||||
const isFeedback = !isSelfLoop && targetRank <= sourceRank;
|
||||
|
||||
const sourcePos = nodePositions.get(e.from);
|
||||
const targetPos = nodePositions.get(e.to);
|
||||
|
||||
let labelX: number | null = null;
|
||||
let labelY: number | null = null;
|
||||
|
||||
if (sourcePos !== undefined && targetPos !== undefined) {
|
||||
if (isFeedback) {
|
||||
// Label on the right side of the feedback arc
|
||||
const rightX = centerX + ROLE_NODE_WIDTH / 2 + FEEDBACK_OFFSET_X;
|
||||
const midY = (sourcePos.y + sourcePos.h / 2 + targetPos.y + targetPos.h / 2) / 2;
|
||||
labelX = rightX;
|
||||
labelY = midY;
|
||||
} else if (!isSelfLoop) {
|
||||
// Forward edge: label between source bottom and target top
|
||||
const midX = centerX;
|
||||
const midY = (sourcePos.y + sourcePos.h + targetPos.y) / 2;
|
||||
labelX = midX;
|
||||
labelY = midY;
|
||||
}
|
||||
// Self-loop: let ReactFlow default handle it
|
||||
}
|
||||
|
||||
return {
|
||||
id: edgeKey(e),
|
||||
source: e.from,
|
||||
target: e.to,
|
||||
type: "condition",
|
||||
data: {
|
||||
condition: e.condition,
|
||||
conditionDescription: e.conditionDescription,
|
||||
isFallback,
|
||||
isFeedback,
|
||||
isSelfLoop,
|
||||
labelX,
|
||||
labelY,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return { nodes, edges };
|
||||
}
|
||||
|
||||
const EMPTY_LAYOUT: LayoutResult = { nodes: [], edges: [] };
|
||||
|
||||
export function useLayout(input: LayoutInput): LayoutResult {
|
||||
const [layout, setLayout] = useState<LayoutResult>(EMPTY_LAYOUT);
|
||||
|
||||
const edgeJson = JSON.stringify(input.edges);
|
||||
const roleJson = JSON.stringify(input.roles);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const parsed = {
|
||||
edges: JSON.parse(edgeJson) as readonly WorkflowGraphEdge[],
|
||||
roles: JSON.parse(roleJson) as Record<string, { description: string }>,
|
||||
nodeStates: input.nodeStates,
|
||||
};
|
||||
computeLayout(parsed)
|
||||
.then((result) => {
|
||||
if (!cancelled) setLayout(result);
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
if (!cancelled) {
|
||||
// biome-ignore lint/suspicious/noConsole: layout error reporting
|
||||
console.error("ELK layout failed:", err);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [edgeJson, roleJson, input.nodeStates]);
|
||||
|
||||
return layout;
|
||||
return useMemo(
|
||||
() => computeLayout(input),
|
||||
[input.edges, input.roles, input.nodeStates],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,9 @@ import {
|
||||
type NodeTypes,
|
||||
type OnNodeClick,
|
||||
ReactFlow,
|
||||
ReactFlowProvider,
|
||||
useReactFlow,
|
||||
} from "@xyflow/react";
|
||||
import "@xyflow/react/dist/style.css";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useMemo } from "react";
|
||||
import type { WorkflowGraph as WorkflowGraphData } from "../../api.ts";
|
||||
import { ConditionEdge } from "./condition-edge.tsx";
|
||||
import { RoleNode } from "./role-node.tsx";
|
||||
@@ -39,30 +37,12 @@ function handleRoleNodeClick(onRoleClick: (roleName: string) => void, node: Node
|
||||
onRoleClick(node.id);
|
||||
}
|
||||
|
||||
function WorkflowGraphInner({ graph, roles, nodeStates, onNodeClick }: Props) {
|
||||
export function WorkflowGraph({ graph, roles, nodeStates, onNodeClick }: Props) {
|
||||
const layout = useLayout({ edges: graph.edges, roles, nodeStates });
|
||||
const { fitView } = useReactFlow();
|
||||
|
||||
const onNodeClickHandler: OnNodeClick | undefined =
|
||||
onNodeClick !== null ? (_e, node) => handleRoleNodeClick(onNodeClick, node) : undefined;
|
||||
|
||||
// Re-fit when layout changes (ELK is async)
|
||||
// Use requestAnimationFrame + setTimeout to ensure ReactFlow has processed nodes
|
||||
useEffect(() => {
|
||||
if (layout.nodes.length > 0) {
|
||||
let cancelled = false;
|
||||
requestAnimationFrame(() => {
|
||||
if (cancelled) return;
|
||||
setTimeout(() => {
|
||||
if (!cancelled) fitView({ padding: 0.1, duration: 300 });
|
||||
}, 300);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}
|
||||
}, [layout.nodes, layout.edges, fitView]);
|
||||
|
||||
const styledEdges = useMemo(
|
||||
() =>
|
||||
layout.edges.map((e) => ({
|
||||
@@ -77,25 +57,17 @@ function WorkflowGraphInner({ graph, roles, nodeStates, onNodeClick }: Props) {
|
||||
[layout.edges],
|
||||
);
|
||||
|
||||
// Generate a stable key that changes when layout changes, to force ReactFlow remount + fitView
|
||||
const layoutKey = useMemo(
|
||||
() => layout.nodes.map((n) => `${n.id}:${n.position.x}:${n.position.y}`).join(","),
|
||||
[layout.nodes],
|
||||
);
|
||||
|
||||
return (
|
||||
<ReactFlow
|
||||
key={layoutKey}
|
||||
nodes={layout.nodes}
|
||||
edges={styledEdges}
|
||||
nodeTypes={nodeTypes}
|
||||
edgeTypes={edgeTypes}
|
||||
onNodeClick={onNodeClickHandler}
|
||||
fitView
|
||||
fitViewOptions={{ padding: 0.1, minZoom: 0.1, maxZoom: 1.5 }}
|
||||
minZoom={0.1}
|
||||
maxZoom={1.5}
|
||||
defaultViewport={{ x: 0, y: 0, zoom: 0.5 }}
|
||||
fitViewOptions={{ padding: 0.15 }}
|
||||
minZoom={0.3}
|
||||
maxZoom={2}
|
||||
nodesDraggable={false}
|
||||
nodesConnectable={false}
|
||||
elementsSelectable={false}
|
||||
@@ -107,11 +79,3 @@ function WorkflowGraphInner({ graph, roles, nodeStates, onNodeClick }: Props) {
|
||||
</ReactFlow>
|
||||
);
|
||||
}
|
||||
|
||||
export function WorkflowGraph(props: Props) {
|
||||
return (
|
||||
<ReactFlowProvider>
|
||||
<WorkflowGraphInner {...props} />
|
||||
</ReactFlowProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-execute",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
@@ -8,20 +8,21 @@
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-protocol": "workspace:*",
|
||||
"@uncaged/workflow-runtime": "workspace:*",
|
||||
"@uncaged/workflow-util": "workspace:*",
|
||||
"@uncaged/workflow-cas": "workspace:*",
|
||||
"@uncaged/workflow-reactor": "workspace:*",
|
||||
"@uncaged/workflow-register": "workspace:*",
|
||||
"@uncaged/workflow-protocol": "workspace:^",
|
||||
"@uncaged/workflow-runtime": "workspace:^",
|
||||
"@uncaged/workflow-util": "workspace:^",
|
||||
"@uncaged/workflow-cas": "workspace:^",
|
||||
"@uncaged/workflow-reactor": "workspace:^",
|
||||
"@uncaged/workflow-register": "workspace:^",
|
||||
"yaml": "^2.7.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-gateway",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-protocol",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
@@ -8,12 +8,14 @@
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
},
|
||||
"./moderator-table.js": {
|
||||
"bun": "./src/moderator-table.ts",
|
||||
"types": "./dist/moderator-table.d.ts",
|
||||
"import": "./src/moderator-table.ts"
|
||||
"import": "./dist/moderator-table.js"
|
||||
}
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-reactor",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
@@ -8,12 +8,13 @@
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-protocol": "workspace:*"
|
||||
"@uncaged/workflow-protocol": "workspace:^"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"zod": "^4.0.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-register",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
@@ -8,13 +8,14 @@
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-protocol": "workspace:*",
|
||||
"@uncaged/workflow-util": "workspace:*"
|
||||
"@uncaged/workflow-protocol": "workspace:^",
|
||||
"@uncaged/workflow-util": "workspace:^"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"acorn": "^8.0.0",
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-runtime",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-cas": "workspace:*",
|
||||
"@uncaged/workflow-protocol": "workspace:*"
|
||||
"@uncaged/workflow-cas": "workspace:^",
|
||||
"@uncaged/workflow-protocol": "workspace:^"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"zod": "^4.0.0"
|
||||
@@ -23,8 +22,9 @@
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-template-develop",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
@@ -8,19 +8,20 @@
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-register": "workspace:*",
|
||||
"@uncaged/workflow-runtime": "workspace:*",
|
||||
"@uncaged/workflow-register": "workspace:^",
|
||||
"@uncaged/workflow-runtime": "workspace:^",
|
||||
"zod": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@uncaged/workflow-protocol": "workspace:*"
|
||||
"@uncaged/workflow-protocol": "workspace:^"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-template-solve-issue",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
@@ -8,21 +8,22 @@
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-register": "workspace:*",
|
||||
"@uncaged/workflow-runtime": "workspace:*",
|
||||
"@uncaged/workflow-register": "workspace:^",
|
||||
"@uncaged/workflow-runtime": "workspace:^",
|
||||
"zod": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@uncaged/workflow-cas": "workspace:*",
|
||||
"@uncaged/workflow-execute": "workspace:*",
|
||||
"@uncaged/workflow-protocol": "workspace:*"
|
||||
"@uncaged/workflow-cas": "workspace:^",
|
||||
"@uncaged/workflow-execute": "workspace:^",
|
||||
"@uncaged/workflow-protocol": "workspace:^"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-util-agent",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"default": "./src/index.ts"
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-runtime": "workspace:*",
|
||||
"@uncaged/workflow-cas": "workspace:*",
|
||||
"@uncaged/workflow-runtime": "workspace:^",
|
||||
"@uncaged/workflow-cas": "workspace:^",
|
||||
"zod": "^4.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@uncaged/workflow-util",
|
||||
"version": "0.3.18",
|
||||
"version": "0.4.0",
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json"
|
||||
@@ -8,12 +8,13 @@
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"bun": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@uncaged/workflow-protocol": "workspace:*"
|
||||
"@uncaged/workflow-protocol": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.8.3"
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Link / unlink all @uncaged/* packages from the workflow monorepo.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/link-all.sh # Register all packages (run from monorepo root)
|
||||
# ./scripts/link-all.sh --consume # Link all packages into CWD's project
|
||||
# ./scripts/link-all.sh --unlink # Unregister all packages and restore CWD's deps
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
MONOREPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
# Iterate package dirs, calling callback(dir, name) for each
|
||||
each_pkg() {
|
||||
local cb="$1"
|
||||
for dir in "$MONOREPO_ROOT"/packages/*/; do
|
||||
[[ -f "$dir/package.json" ]] || continue
|
||||
local name
|
||||
name=$(grep -m1 '"name"' "$dir/package.json" | sed 's/.*: *"\(.*\)".*/\1/')
|
||||
"$cb" "$dir" "$name"
|
||||
done
|
||||
}
|
||||
|
||||
do_register() { printf " register %s\n" "$2"; (cd "$1" && bun link 2>&1) > /dev/null; }
|
||||
do_consume() { printf " link %s\n" "$2"; (bun link "$2" 2>&1) > /dev/null; }
|
||||
do_unlink() { printf " unlink %s\n" "$2"; (cd "$1" && bun unlink 2>&1) > /dev/null || true; }
|
||||
|
||||
case "${1:-}" in
|
||||
--consume)
|
||||
each_pkg do_consume
|
||||
echo "✅ All @uncaged/* packages linked into $(pwd)"
|
||||
echo " ⚠️ Do NOT run 'bun install' after this — it will overwrite the links"
|
||||
echo " To restore: $0 --unlink"
|
||||
;;
|
||||
--unlink)
|
||||
each_pkg do_unlink
|
||||
if [[ -f "package.json" ]]; then
|
||||
echo " reinstalling deps..."
|
||||
bun install 2>&1 > /dev/null || true
|
||||
fi
|
||||
echo "✅ All @uncaged/* packages unlinked, deps restored"
|
||||
;;
|
||||
*)
|
||||
each_pkg do_register
|
||||
echo "✅ All @uncaged/* packages registered"
|
||||
echo " cd <project> && $0 --consume"
|
||||
;;
|
||||
esac
|
||||
@@ -1,137 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Publish all public @uncaged/* packages to Gitea npm registry.
|
||||
#
|
||||
# PITFALL: After bumping versions in package.json, bun pm pack still reads the
|
||||
# old bun.lock and resolves workspace:* to the previous (stale) versions.
|
||||
# This script deletes bun.lock and runs bun install before packing to force
|
||||
# correct resolution of workspace:* dependencies.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/publish-all.sh # Publish all packages
|
||||
# ./scripts/publish-all.sh --dry-run # Show what would be published
|
||||
#
|
||||
# Package order is auto-resolved via topological sort of workspace:* dependencies.
|
||||
#
|
||||
# Prerequisites:
|
||||
# - .npmrc in monorepo root with Gitea auth token
|
||||
# - bun (for packing with workspace:* resolution)
|
||||
# - npm (for publishing tarballs)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
MONOREPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
REGISTRY="https://git.shazhou.work/api/packages/uncaged/npm/"
|
||||
DRY_RUN=""
|
||||
|
||||
if [[ "${1:-}" == "--dry-run" ]]; then
|
||||
DRY_RUN="--dry-run"
|
||||
echo "🔍 Dry run mode — no packages will be published"
|
||||
echo
|
||||
fi
|
||||
|
||||
# Topological sort: read all package.json files, build dependency graph, emit leaf-first order
|
||||
ORDERED=$(python3 -c "
|
||||
import json, os, sys
|
||||
from pathlib import Path
|
||||
|
||||
pkgs_dir = Path('$MONOREPO_ROOT/packages')
|
||||
# name -> dir_name, and dependency edges
|
||||
name_to_dir = {}
|
||||
deps_graph = {} # name -> set of @uncaged/* dependency names
|
||||
|
||||
for d in sorted(pkgs_dir.iterdir()):
|
||||
pj = d / 'package.json'
|
||||
if not pj.exists():
|
||||
continue
|
||||
data = json.loads(pj.read_text())
|
||||
name = data.get('name', '')
|
||||
if not name.startswith('@uncaged/'):
|
||||
continue
|
||||
if data.get('private'):
|
||||
continue
|
||||
name_to_dir[name] = d.name
|
||||
local_deps = set()
|
||||
for section in ('dependencies', 'devDependencies', 'peerDependencies'):
|
||||
for dep, ver in data.get(section, {}).items():
|
||||
if dep.startswith('@uncaged/') and dep in name_to_dir or ver == 'workspace:*':
|
||||
local_deps.add(dep)
|
||||
deps_graph[name] = local_deps
|
||||
|
||||
# Kahn's algorithm
|
||||
in_degree = {n: 0 for n in deps_graph}
|
||||
for n, ds in deps_graph.items():
|
||||
for d in ds:
|
||||
if d in in_degree:
|
||||
in_degree[d] = in_degree.get(d, 0) # ensure exists
|
||||
|
||||
# Recount
|
||||
in_degree = {n: 0 for n in deps_graph}
|
||||
for n, ds in deps_graph.items():
|
||||
for d in ds:
|
||||
if d in in_degree:
|
||||
in_degree[d] += 1
|
||||
|
||||
# Wait, direction is wrong. If A depends on B, B must be published first.
|
||||
# So edge is: A -> B means B must come before A.
|
||||
# in_degree[A] = number of deps A has (that are in our set)
|
||||
in_degree = {n: 0 for n in deps_graph}
|
||||
for n, ds in deps_graph.items():
|
||||
for d in ds:
|
||||
if d in in_degree:
|
||||
pass # d is a dependency of n
|
||||
in_degree[n] = len([d for d in ds if d in deps_graph])
|
||||
|
||||
queue = [n for n, deg in in_degree.items() if deg == 0]
|
||||
queue.sort() # stable order
|
||||
result = []
|
||||
while queue:
|
||||
node = queue.pop(0)
|
||||
result.append(node)
|
||||
for n, ds in deps_graph.items():
|
||||
if node in ds:
|
||||
in_degree[n] -= 1
|
||||
if in_degree[n] == 0:
|
||||
queue.append(n)
|
||||
queue.sort()
|
||||
|
||||
for name in result:
|
||||
print(name_to_dir[name])
|
||||
")
|
||||
|
||||
# Regenerate lockfile so bun pm pack resolves workspace:* to freshly-bumped versions
|
||||
cd "$MONOREPO_ROOT"
|
||||
rm -f bun.lock
|
||||
bun install
|
||||
|
||||
ok=0
|
||||
fail=0
|
||||
|
||||
while IFS= read -r pkg; do
|
||||
dir="$MONOREPO_ROOT/packages/$pkg"
|
||||
name=$(grep -m1 '"name"' "$dir/package.json" | sed 's/.*: *"\(.*\)".*/\1/')
|
||||
|
||||
cd "$dir"
|
||||
|
||||
# bun pm pack resolves workspace:* → actual versions
|
||||
tgz=$(bun pm pack 2>&1 | grep '\.tgz' | grep -v packed | head -1 | tr -d ' ')
|
||||
|
||||
if [[ -z "$tgz" || ! -f "$tgz" ]]; then
|
||||
echo "❌ $name — pack failed"
|
||||
((fail++)) || true
|
||||
continue
|
||||
fi
|
||||
|
||||
if npm publish "$tgz" --registry="$REGISTRY" $DRY_RUN 2>&1 | tail -1 | grep -q '+'; then
|
||||
echo "✅ $name"
|
||||
((ok++)) || true
|
||||
else
|
||||
echo "⚠️ $name (may already exist at this version)"
|
||||
fi
|
||||
|
||||
rm -f "$tgz"
|
||||
done <<< "$ORDERED"
|
||||
|
||||
echo
|
||||
echo "Published: $ok Skipped/Failed: $fail"
|
||||
+105
-79
@@ -1,20 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# publish.sh — Bump version & publish all @uncaged/workflow-* packages
|
||||
# publish.sh — Bump version, build, test, topologically publish @uncaged/* to Gitea npm
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/publish.sh 0.4.0 # explicit version
|
||||
# ./scripts/publish.sh patch # 0.3.1 → 0.3.2
|
||||
# ./scripts/publish.sh minor # 0.3.1 → 0.4.0
|
||||
# ./scripts/publish.sh 0.4.0 # explicit version
|
||||
# ./scripts/publish.sh patch # 0.3.1 → 0.3.2
|
||||
# ./scripts/publish.sh minor # 0.3.1 → 0.4.0
|
||||
# ./scripts/publish.sh major # 0.3.1 → 1.0.0
|
||||
# ./scripts/publish.sh --dry-run patch # dry-run bun publish only (no git commit/push)
|
||||
#
|
||||
# Env (via `cfg` or export):
|
||||
# GITEA_TOKEN — Gitea npm registry auth
|
||||
# GITEA_TOKEN — Gitea npm registry auth (see root .npmrc)
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
GITEA_TOKEN="${GITEA_TOKEN:?GITEA_TOKEN is required}"
|
||||
GITEA_NPM_REGISTRY="https://git.shazhou.work/api/packages/uncaged/npm/"
|
||||
|
||||
REGISTRY="https://git.shazhou.work/api/packages/uncaged/npm/"
|
||||
DRY_RUN=""
|
||||
|
||||
if [[ "${1:-}" == "--dry-run" ]]; then
|
||||
DRY_RUN="--dry-run"
|
||||
shift
|
||||
echo "🔍 Dry run — bun publish will not upload; git commit/push skipped"
|
||||
echo
|
||||
fi
|
||||
|
||||
# ─── Version ─────────────────────────────────────────────────────────────────
|
||||
current_version() {
|
||||
@@ -33,28 +44,10 @@ bump_version() {
|
||||
}
|
||||
|
||||
CURRENT=$(current_version)
|
||||
VERSION=$(bump_version "$CURRENT" "${1:?Usage: publish.sh <version|patch|minor|major>}")
|
||||
VERSION=$(bump_version "$CURRENT" "${1:?Usage: publish.sh [--dry-run] <version|patch|minor|major>}")
|
||||
echo "📦 Publish: $CURRENT → $VERSION"
|
||||
|
||||
# ─── Topological publish order ───────────────────────────────────────────────
|
||||
PUBLISH_ORDER=(
|
||||
workflow-protocol
|
||||
workflow-util
|
||||
workflow-cas
|
||||
workflow-runtime
|
||||
workflow-reactor
|
||||
workflow-register
|
||||
workflow-execute
|
||||
cli-workflow
|
||||
workflow-util-agent
|
||||
workflow-agent-cursor
|
||||
workflow-agent-hermes
|
||||
workflow-agent-llm
|
||||
workflow-template-develop
|
||||
workflow-template-solve-issue
|
||||
)
|
||||
|
||||
# ─── Bump version ────────────────────────────────────────────────────────────
|
||||
# ─── Bump version ─────────────────────────────────────────────────────────────
|
||||
echo "🔢 Bumping versions..."
|
||||
for dir in packages/*/; do
|
||||
pkg="$dir/package.json"
|
||||
@@ -69,66 +62,99 @@ for dir in packages/*/; do
|
||||
"
|
||||
done
|
||||
|
||||
# ─── Replace workspace:* ─────────────────────────────────────────────────────
|
||||
echo "🔗 Replacing workspace:* → $VERSION..."
|
||||
for dir in packages/*/; do
|
||||
pkg="$dir/package.json"
|
||||
[[ -f "$pkg" ]] || continue
|
||||
node -e "
|
||||
const fs = require('fs');
|
||||
const p = JSON.parse(fs.readFileSync('$pkg','utf8'));
|
||||
let c = false;
|
||||
for (const k of ['dependencies','peerDependencies','devDependencies']) {
|
||||
if (!p[k]) continue;
|
||||
for (const [n, v] of Object.entries(p[k])) {
|
||||
if (n.startsWith('@uncaged/') && v === 'workspace:*') { p[k][n] = '$VERSION'; c = true; }
|
||||
}
|
||||
}
|
||||
if (c) fs.writeFileSync('$pkg', JSON.stringify(p, null, 2) + '\n');
|
||||
"
|
||||
done
|
||||
# ─── Topological publish order (workspace:* deps first) ───────────────────────
|
||||
ORDERED=$(python3 -c "
|
||||
import json, sys
|
||||
from pathlib import Path
|
||||
|
||||
# ─── Build ───────────────────────────────────────────────────────────────────
|
||||
pkgs_dir = Path('$REPO_ROOT/packages')
|
||||
name_to_dir = {}
|
||||
for d in sorted(pkgs_dir.iterdir()):
|
||||
pj = d / 'package.json'
|
||||
if not pj.exists():
|
||||
continue
|
||||
data = json.loads(pj.read_text())
|
||||
name = data.get('name', '')
|
||||
if not name.startswith('@uncaged/') or data.get('private'):
|
||||
continue
|
||||
name_to_dir[name] = d.name
|
||||
|
||||
deps_graph = {}
|
||||
for name, dirname in name_to_dir.items():
|
||||
pj = pkgs_dir / dirname / 'package.json'
|
||||
data = json.loads(pj.read_text())
|
||||
local_deps = set()
|
||||
for section in ('dependencies', 'devDependencies', 'peerDependencies'):
|
||||
for dep, ver in data.get(section, {}).items():
|
||||
if dep.startswith('@uncaged/') and dep in name_to_dir and ver.startswith('workspace:'):
|
||||
local_deps.add(dep)
|
||||
deps_graph[name] = local_deps
|
||||
|
||||
in_degree = {n: 0 for n in deps_graph}
|
||||
for n, ds in deps_graph.items():
|
||||
in_degree[n] = len(ds)
|
||||
|
||||
queue = sorted([n for n, deg in in_degree.items() if deg == 0])
|
||||
result = []
|
||||
while queue:
|
||||
node = queue.pop(0)
|
||||
result.append(node)
|
||||
for n, ds in deps_graph.items():
|
||||
if node in ds:
|
||||
in_degree[n] -= 1
|
||||
if in_degree[n] == 0:
|
||||
queue.append(n)
|
||||
queue.sort()
|
||||
|
||||
if len(result) != len(deps_graph):
|
||||
missing = set(deps_graph) - set(result)
|
||||
sys.stderr.write('publish: cyclic @uncaged/ workspace:* dependencies among: ' + ', '.join(sorted(missing)) + '\n')
|
||||
sys.exit(1)
|
||||
|
||||
for name in result:
|
||||
print(name_to_dir[name])
|
||||
")
|
||||
|
||||
# ─── Build ────────────────────────────────────────────────────────────────────
|
||||
echo "🔨 Building..."
|
||||
npm run build
|
||||
bun run build
|
||||
|
||||
# ─── Publish ─────────────────────────────────────────────────────────────────
|
||||
echo "🚀 Publishing..."
|
||||
cat > "$REPO_ROOT/.npmrc" <<EOF
|
||||
@uncaged:registry=${GITEA_NPM_REGISTRY}
|
||||
//${GITEA_NPM_REGISTRY#https://}:_authToken=${GITEA_TOKEN}
|
||||
EOF
|
||||
# ─── Self-test ────────────────────────────────────────────────────────────────
|
||||
echo "🧪 Running tests..."
|
||||
if ! bun test; then
|
||||
echo "❌ Tests failed — aborting publish"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FAIL=0
|
||||
for pkg_dir in "${PUBLISH_ORDER[@]}"; do
|
||||
if (cd "packages/$pkg_dir" && npm publish 2>&1); then
|
||||
echo " ✅ @uncaged/$pkg_dir@$VERSION"
|
||||
# ─── Publish (bun resolves workspace:* for publish) ──────────────────────────
|
||||
echo "🚀 Publishing to $REGISTRY ..."
|
||||
ok=0
|
||||
fail=0
|
||||
|
||||
while IFS= read -r pkg; do
|
||||
[[ -n "$pkg" ]] || continue
|
||||
dir="$REPO_ROOT/packages/$pkg"
|
||||
name=$(node -e "console.log(require('$dir/package.json').name)")
|
||||
|
||||
if ( cd "$dir" && bun publish --registry="$REGISTRY" ${DRY_RUN:+"$DRY_RUN"} ); then
|
||||
echo "✅ $name"
|
||||
ok=$((ok + 1))
|
||||
else
|
||||
echo " ❌ @uncaged/$pkg_dir"
|
||||
FAIL=1
|
||||
echo "⚠️ $name (publish failed or version may already exist)"
|
||||
fail=$((fail + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
# ─── Restore workspace:* ─────────────────────────────────────────────────────
|
||||
echo "🔄 Restoring workspace:*..."
|
||||
for dir in packages/*/; do
|
||||
pkg="$dir/package.json"
|
||||
[[ -f "$pkg" ]] || continue
|
||||
node -e "
|
||||
const fs = require('fs');
|
||||
const p = JSON.parse(fs.readFileSync('$pkg','utf8'));
|
||||
let c = false;
|
||||
for (const k of ['dependencies','peerDependencies','devDependencies']) {
|
||||
if (!p[k]) continue;
|
||||
for (const [n, v] of Object.entries(p[k])) {
|
||||
if (n.startsWith('@uncaged/') && v === '$VERSION') { p[k][n] = 'workspace:*'; c = true; }
|
||||
}
|
||||
}
|
||||
if (c) fs.writeFileSync('$pkg', JSON.stringify(p, null, 2) + '\n');
|
||||
"
|
||||
done
|
||||
done <<< "$ORDERED"
|
||||
|
||||
echo
|
||||
echo "Published: $ok Skipped/Failed: $fail"
|
||||
|
||||
# ─── Commit ───────────────────────────────────────────────────────────────────
|
||||
if [[ -n "$DRY_RUN" ]]; then
|
||||
echo "⏭️ Skipping git commit/push (dry run). Revert bumps with: git checkout -- packages/*/package.json"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ─── Commit ──────────────────────────────────────────────────────────────────
|
||||
echo "📝 Committing..."
|
||||
git add -A
|
||||
git commit -m "chore: publish v${VERSION}
|
||||
@@ -136,4 +162,4 @@ git commit -m "chore: publish v${VERSION}
|
||||
小橘 <xiaoju@shazhou.work>"
|
||||
git push
|
||||
|
||||
[[ "$FAIL" -eq 0 ]] && echo "✅ v${VERSION} published" || echo "⚠️ v${VERSION} published with errors"
|
||||
echo "✅ v${VERSION} published"
|
||||
|
||||
Reference in New Issue
Block a user