-
Notifications
You must be signed in to change notification settings - Fork 15
feat: viz-node #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: viz-node #187
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d75e91f
feat: viz-node
thucpn 5cf7b32
add example
thucpn 4516824
add canvas to build deps
thucpn 7f15045
make graph look better
thucpn 553dce8
fix format
thucpn 3e8803f
add change set
thucpn 7a54442
Merge branch 'main' into tp/viz-node
thucpn 3470827
fix readme
thucpn 28fc97c
fix typo
thucpn 12922c9
keep shared workflow and divide readme
thucpn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@llamaindex/workflow-viz-node": patch | ||
| "@llamaindex/workflow-viz": patch | ||
| --- | ||
|
|
||
| Generate workflow visualization in Node.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { createWorkflow, workflowEvent } from "@llamaindex/workflow-core"; | ||
| import { withDrawingNode } from "@llamaindex/workflow-viz-node"; | ||
|
|
||
| //#region define workflow events | ||
| const startEvent = workflowEvent<string>({ | ||
| debugLabel: "start", | ||
| }); | ||
| const branchAEvent = workflowEvent<string>({ | ||
| debugLabel: "branchA", | ||
| }); | ||
| const branchBEvent = workflowEvent<string>({ | ||
| debugLabel: "branchB", | ||
| }); | ||
| const branchCEvent = workflowEvent<string>({ | ||
| debugLabel: "branchC", | ||
| }); | ||
| const branchCompleteEvent = workflowEvent<string>({ | ||
| debugLabel: "branchComplete", | ||
| }); | ||
| const allCompleteEvent = workflowEvent<string>({ | ||
| debugLabel: "allComplete", | ||
| }); | ||
| const stopEvent = workflowEvent<string>({ | ||
| debugLabel: "stop", | ||
| }); | ||
| //#endregion | ||
|
|
||
| //#region defines workflow | ||
| const workflow = withDrawingNode(createWorkflow()); | ||
|
|
||
| workflow.handle([startEvent], async (ctx) => { | ||
| const { sendEvent, stream } = ctx; | ||
| // emit 3 different events, handled separately | ||
|
|
||
| sendEvent(branchAEvent.with("Branch A")); | ||
| sendEvent(branchBEvent.with("Branch B")); | ||
| sendEvent(branchCEvent.with("Branch C")); | ||
|
|
||
| const results = await stream.filter(branchCompleteEvent).take(3).toArray(); | ||
|
|
||
| return allCompleteEvent.with(results.map((e) => e.data).join(", ")); | ||
| }); | ||
|
|
||
| workflow.handle([branchAEvent], (_context1, branchA) => { | ||
| return branchCompleteEvent.with(branchA.data); | ||
| }); | ||
|
|
||
| workflow.handle([branchBEvent], (_context2, branchB) => { | ||
| return branchCompleteEvent.with(branchB.data); | ||
| }); | ||
|
|
||
| workflow.handle([branchCEvent], (_context3, branchC) => { | ||
| return branchCompleteEvent.with(branchC.data); | ||
| }); | ||
|
|
||
| workflow.handle([allCompleteEvent], (_context4, allComplete) => { | ||
| return stopEvent.with(allComplete.data); | ||
| }); | ||
|
|
||
| async function main() { | ||
| await workflow.drawToImage({ | ||
| layout: "force", | ||
| width: 800, | ||
| height: 600, | ||
| output: "workflow.png", | ||
| }); | ||
| } | ||
|
|
||
| main().catch(console.error); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "root": false, | ||
| "extends": "//", | ||
| "files": { | ||
| "includes": ["src/**", "tests/**"] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| { | ||
| "name": "@llamaindex/workflow-graph", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "description": "Shared graph utilities", | ||
| "type": "module", | ||
| "main": "dist/index.cjs", | ||
| "types": "dist/index.d.ts", | ||
| "module": "dist/index.js", | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| }, | ||
| "default": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
| } | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "build": "bunchee", | ||
| "dev": "bunchee --watch", | ||
| "test": "vitest run", | ||
| "test:ui": "vitest --ui", | ||
| "test:watch": "vitest" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/types": "^7.27.1", | ||
| "@llamaindex/workflow-core": "workspace:*", | ||
| "@types/node": "^22.15.19", | ||
| "bunchee": "^6.5.1", | ||
| "vitest": "^2.0.0", | ||
| "@vitest/ui": "^2.0.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "@llamaindex/workflow-core": "workspace:*" | ||
| }, | ||
| "license": "MIT", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/run-llama/workflow-ts.git", | ||
| "directory": "packages/graph" | ||
| }, | ||
| "dependencies": { | ||
| "@babel/parser": "^7.27.2", | ||
| "graphology": "^0.26.0", | ||
| "graphology-layout-force": "^0.2.4" | ||
| } | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { withGraph, type WithGraphWorkflow } from "./graph"; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "./lib", | ||
| "tsBuildInfoFile": "./lib/.tsbuildinfo", | ||
| "paths": { | ||
| "@llamaindex/workflow-viz": ["./src/index.ts"] | ||
| } | ||
| }, | ||
| "include": ["./src", "./examples"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| globals: true, | ||
| environment: "node", | ||
| include: ["**/*.test.ts", "**/*.spec.ts"], | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "root": false, | ||
| "extends": "//", | ||
| "files": { | ||
| "includes": ["src/**", "tests/**"] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| { | ||
| "name": "@llamaindex/workflow-viz-node", | ||
| "version": "1.0.0", | ||
| "description": "Visualization components for drawing LlamaIndex Workflows in the node", | ||
thucpn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "type": "module", | ||
| "main": "dist/index.cjs", | ||
| "types": "dist/index.d.ts", | ||
| "module": "dist/index.js", | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| }, | ||
| "default": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
| } | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "build": "bunchee", | ||
| "dev": "bunchee --watch", | ||
| "test": "vitest run", | ||
| "test:ui": "vitest --ui", | ||
| "test:watch": "vitest" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/types": "^7.27.1", | ||
| "@llamaindex/workflow-core": "workspace:*", | ||
| "@types/node": "^22.15.19", | ||
| "bunchee": "^6.5.1", | ||
| "vitest": "^2.0.0", | ||
| "@vitest/ui": "^2.0.0", | ||
| "graphology": "^0.26.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "@llamaindex/workflow-core": "workspace:*" | ||
| }, | ||
| "license": "MIT", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/run-llama/workflow-ts.git", | ||
| "directory": "packages/viz-node" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@llamaindex/workflow-graph": "workspace:*", | ||
| "@babel/parser": "^7.27.2", | ||
| "graphology-layout-force": "^0.2.4", | ||
| "canvas": "^3.2.0", | ||
| "graphology-canvas": "^0.4.2" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import type Graph from "graphology"; | ||
|
|
||
| export function toNodeCanvasGraph(graph: Graph): Graph { | ||
| const g = graph.copy(); | ||
|
|
||
| g.forEachNode((node, attr) => { | ||
| if (attr.type === "handler") { | ||
| g.mergeNodeAttributes(node, { size: 20, color: "red" }); | ||
| g.removeNodeAttribute(node, "type"); | ||
| } | ||
| if (attr.type === "event") { | ||
| g.mergeNodeAttributes(node, { size: 10, color: "blue" }); | ||
| g.removeNodeAttribute(node, "type"); | ||
| } | ||
| }); | ||
|
|
||
| g.forEachEdge((edge) => { | ||
| g.mergeEdgeAttributes(edge, { size: 3, color: "#999" }); | ||
| }); | ||
|
|
||
| return g; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.