tongflow 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +145 -0
- package/abi/tongflow.abi.json +2590 -0
- package/dist/canvas-messages.cjs +4069 -0
- package/dist/canvas-messages.d.cts +13 -0
- package/dist/canvas-messages.d.ts +13 -0
- package/dist/canvas-messages.js +4066 -0
- package/dist/canvas.cjs +24711 -0
- package/dist/canvas.css +2 -0
- package/dist/canvas.d.cts +4121 -0
- package/dist/canvas.d.ts +4121 -0
- package/dist/canvas.js +24495 -0
- package/dist/index.cjs +7584 -0
- package/dist/index.d.cts +5799 -0
- package/dist/index.d.ts +5799 -0
- package/dist/index.js +7461 -0
- package/package.json +143 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# tongflow
|
|
2
|
+
|
|
3
|
+
The core of [TongFlow](https://github.com/tong-io/tongflow), the multi-modal
|
|
4
|
+
AIGC workflow studio, as an npm package with two entries:
|
|
5
|
+
|
|
6
|
+
- **`tongflow`** — framework-free: the ABI contract, the static node
|
|
7
|
+
registry, connection validation, the workflow exporter, canvas layout, a
|
|
8
|
+
**headless canvas model** and the **agent graph tools** that let an external
|
|
9
|
+
agent build and edit workflows programmatically. No React, no Next.js, no
|
|
10
|
+
I/O — it runs in Node, browsers and workers alike.
|
|
11
|
+
- **`tongflow/canvas`** — the React canvas (`FlowCanvas`, every node/edge
|
|
12
|
+
component, hooks, UI primitives) that renders and edits that model against a
|
|
13
|
+
TongFlow-compatible API.
|
|
14
|
+
|
|
15
|
+
Execution is not in this package: export a workflow and hand it to the
|
|
16
|
+
Python SDK engine (`pip install tongflow`, `python -m tongflow.engine`).
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install tongflow zustand # core
|
|
20
|
+
npm install react react-dom @xyflow/react use-intl # + canvas peers
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`zustand` is a peer dependency (the headless store is a `zustand/vanilla`
|
|
24
|
+
store). `@xyflow/react`, `react`, `react-dom` and `use-intl` are optional
|
|
25
|
+
peers only the canvas entry needs.
|
|
26
|
+
|
|
27
|
+
## What's inside
|
|
28
|
+
|
|
29
|
+
| Area | Exports (selection) |
|
|
30
|
+
|---|---|
|
|
31
|
+
| ABI contract | `ABI_NODES`, `ABI_DEFINITIONS`, `NodeSlot`, generated per-slot input/output types, `TONGFLOW_ABI_VERSION`; the JSON itself at `tongflow/abi` |
|
|
32
|
+
| Static node registry | `NODE_TYPE_TO_ABI_FEATURE`, `NODE_TYPE_SOURCE_SPEC`, `abiSpecForNodeType`, `resolvedSpecForNodeType`, `resolveEdgeHandles`, `getAbiTopology`, `resolveSpec` |
|
|
33
|
+
| Workflow | `exportWorkflow` → `ExecutableWorkflow`, `WorkflowParser`, `isWorkflowValid`, `isValidFlowConnection`, `getEdgeTargetOptions`, `parseWorkflowImportJson` |
|
|
34
|
+
| Layout | `computeAutoLayout`, `componentsContaining`, `estimateNodeSize` |
|
|
35
|
+
| Headless store | `createFlowStore`, `createFlowSlice`, `FlowCoreState`, `addEdgeIfAbsent` |
|
|
36
|
+
| Agent tools | `TONGFLOW_TOOL_DEFS`, `applyGraphPatch`, `readCanvas`, `validateWorkflow`, `describeNodeType`, `executeGraphTool`, `renderCanvas` |
|
|
37
|
+
| Registry schemas | `PluginsRegistrySchema`, `FeatureRegistryBundleSchema` (zod) |
|
|
38
|
+
|
|
39
|
+
## Build a workflow headlessly
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import {
|
|
43
|
+
createFlowStore,
|
|
44
|
+
applyGraphPatch,
|
|
45
|
+
validateWorkflow,
|
|
46
|
+
exportWorkflow,
|
|
47
|
+
} from "tongflow";
|
|
48
|
+
|
|
49
|
+
const store = createFlowStore();
|
|
50
|
+
|
|
51
|
+
// One coherent change: nodes to create, edges to draw, params to set.
|
|
52
|
+
const result = applyGraphPatch(store, {
|
|
53
|
+
add_nodes: [
|
|
54
|
+
{ alias: "t1", type: "textNode", data: { texts: ["a cat, cartoon"] } },
|
|
55
|
+
{ alias: "gen", type: "textGenImageNode", data: { width: 1024, height: 1024 } },
|
|
56
|
+
{ alias: "img", type: "imageNode" },
|
|
57
|
+
],
|
|
58
|
+
add_edges: [
|
|
59
|
+
{ from: "t1", to: "gen" },
|
|
60
|
+
{ from: "gen", to: "img" },
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
console.log(result.ok, result.steps);
|
|
64
|
+
|
|
65
|
+
// Health-check (cycles, unconnected required inputs, empty config, plugins).
|
|
66
|
+
console.log(validateWorkflow(store, { registry: myPluginsRegistry }));
|
|
67
|
+
|
|
68
|
+
// Export the executable form the Python engine runs.
|
|
69
|
+
const { nodes, edges } = store.getState();
|
|
70
|
+
const executable = exportWorkflow(nodes, edges, { name: "cat" });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Give an LLM the tools with your provider's envelope and dispatch by name:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { TONGFLOW_TOOL_DEFS, executeGraphTool } from "tongflow";
|
|
77
|
+
|
|
78
|
+
const openaiTools = TONGFLOW_TOOL_DEFS.map((t) => ({
|
|
79
|
+
type: "function",
|
|
80
|
+
function: { name: t.name, description: t.description, parameters: t.parameters },
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
// ...when the model calls a tool:
|
|
84
|
+
const out = executeGraphTool(store, call.name, call.arguments, {
|
|
85
|
+
historySource: `agent:${turnId}`,
|
|
86
|
+
registry: myPluginsRegistry,
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The graph rules an agent must follow (the strict
|
|
91
|
+
`add → data → executable → data → …` alternation, never inventing ids, etc.)
|
|
92
|
+
are documented in
|
|
93
|
+
[`docs/agent-workflow-manual.md`](https://github.com/tong-io/tongflow/blob/main/docs/agent-workflow-manual.md).
|
|
94
|
+
|
|
95
|
+
## The React canvas (`tongflow/canvas`)
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import "@xyflow/react/dist/style.css";
|
|
99
|
+
import "tongflow/canvas.css";
|
|
100
|
+
import { ReactFlowProvider } from "@xyflow/react";
|
|
101
|
+
import { IntlProvider } from "use-intl";
|
|
102
|
+
import { CanvasProvider, FlowCanvas, canvasMessages, useFlow } from "tongflow/canvas";
|
|
103
|
+
|
|
104
|
+
export function Studio() {
|
|
105
|
+
return (
|
|
106
|
+
<IntlProvider locale="en" messages={canvasMessages.en}>
|
|
107
|
+
<CanvasProvider apiBaseUrl="https://my-tongflow-server" locale="en">
|
|
108
|
+
<ReactFlowProvider>
|
|
109
|
+
<div style={{ width: "100%", height: "100vh" }}>
|
|
110
|
+
<FlowCanvas />
|
|
111
|
+
</div>
|
|
112
|
+
</ReactFlowProvider>
|
|
113
|
+
</CanvasProvider>
|
|
114
|
+
</IntlProvider>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- `FlowCanvas` renders the whole TongFlow node set over the flow store
|
|
120
|
+
(`useFlow`), validates connections against the ABI while dragging, and
|
|
121
|
+
exposes `fitView` / `focusNode` / `tidyLayout` through a ref. Overlays go in
|
|
122
|
+
as `children`.
|
|
123
|
+
- `CanvasProvider` / `configureCanvasHost` point the canvas at a
|
|
124
|
+
TongFlow-compatible HTTP API (`/api/task/create`, `/api/task/wait` SSE,
|
|
125
|
+
`/api/upload`, `/api/plugins/registry`, …), optionally with a custom
|
|
126
|
+
`fetch` and an asset-URL resolver. Defaults are same-origin.
|
|
127
|
+
- `canvasMessages[locale]` are the i18n catalogs (`en` / `zh` / `ja` / `ko`);
|
|
128
|
+
merge them into your `use-intl` (or `next-intl`) provider. Import them from
|
|
129
|
+
`tongflow/canvas/messages` in server code (RSC / SSR) — that entry carries no
|
|
130
|
+
`"use client"` directive.
|
|
131
|
+
- Styling is Tailwind v4 utilities + TongFlow's tokens in `tongflow/canvas.css`
|
|
132
|
+
(no preflight — bring your own base styles). React 18 and 19 are supported.
|
|
133
|
+
|
|
134
|
+
The TongFlow app itself is the first host: its `useFlow` is
|
|
135
|
+
`createFlowSlice` + React Flow callbacks + a localStorage subscription, and its
|
|
136
|
+
workspace shell composes navigation, dialogs and persistence around
|
|
137
|
+
`FlowCanvas`.
|
|
138
|
+
|
|
139
|
+
## Versioning
|
|
140
|
+
|
|
141
|
+
The ABI (`tongflow/abi`) is versioned independently (`TONGFLOW_ABI_VERSION`);
|
|
142
|
+
the Python SDK bundles the same JSON. Keep the npm package and
|
|
143
|
+
`pip install tongflow` on matching ABI versions.
|
|
144
|
+
|
|
145
|
+
License: AGPL-3.0-only.
|