@rotorsoft/act-diagram 0.3.6 → 0.3.8
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/README.md +35 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/client/lib/evaluate.d.ts.map +1 -1
- package/dist/@types/client/types/index.d.ts +1 -1
- package/dist/@types/client/types/index.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ Interactive domain model diagram for [@rotorsoft/act](https://www.npmjs.com/pack
|
|
|
14
14
|
- **Bottom-up model building** — states → slices → act, each level independently validated
|
|
15
15
|
- **IDE-agnostic** — works over props, postMessage, or WebSocket (see [act-nvim](https://github.com/Rotorsoft/act-nvim) for Neovim integration)
|
|
16
16
|
- **Embeddable** — React component for any host (IDE webview, standalone app, docs site)
|
|
17
|
-
- **AI refinement** — optional prompt bar to generate code via a streaming endpoint
|
|
18
|
-
- **
|
|
17
|
+
- **AI refinement** — optional prompt bar to generate code via a streaming endpoint (see [AI server](#ai-server-optional))
|
|
18
|
+
- **High test coverage** — over 300 tests covering extraction, layout, navigation, and error paths
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
@@ -27,6 +27,12 @@ pnpm add @rotorsoft/act-diagram
|
|
|
27
27
|
|
|
28
28
|
**Peer dependencies:** `react >= 18`, `react-dom >= 18`
|
|
29
29
|
|
|
30
|
+
The component ships its own stylesheet — import it once at the host's entry point:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import "@rotorsoft/act-diagram/styles.css";
|
|
34
|
+
```
|
|
35
|
+
|
|
30
36
|
## How It Works
|
|
31
37
|
|
|
32
38
|
```
|
|
@@ -128,7 +134,7 @@ const result = navigateToCode(files, "OpenTicket", "action");
|
|
|
128
134
|
|
|
129
135
|
| Component | Props | Description |
|
|
130
136
|
|-----------|-------|-------------|
|
|
131
|
-
| `ActDiagram` | `files?`, `onNavigate
|
|
137
|
+
| `ActDiagram` | `files?`, `onNavigate?(file, line, col, type?)`, `usePostMessage?`, `onAiRequest?`, `generating?` | Standalone wrapper: pipeline + diagram + optional AI bar. `onNavigate`'s 4th argument carries the diagram element type (`state`, `slice`, `event`, …) for callers that want type-aware routing. |
|
|
132
138
|
| `Diagram` | `model`, `warnings`, `onClickElement?`, `onFixWithAi?`, `toolbarExtra?` | Raw SVG diagram with pan/zoom/model tree/warnings |
|
|
133
139
|
| `AiBar` | `onSubmit`, `generating?` | Resizable prompt input with model and token controls |
|
|
134
140
|
| `Logo` | `size?` | Act logo SVG |
|
|
@@ -138,25 +144,34 @@ const result = navigateToCode(files, "OpenTicket", "action");
|
|
|
138
144
|
|
|
139
145
|
| Function | Signature | Description |
|
|
140
146
|
|----------|-----------|-------------|
|
|
141
|
-
| `extractModel` | `(files: FileTab[]) => { model: DomainModel; error?: string }` | Extract domain model from TypeScript source files |
|
|
147
|
+
| `extractModel` | `(files: FileTab[]) => { model: DomainModel; error?: string }` | Extract domain model from TypeScript source files (orchestrates `topoSort` + `buildModel`) |
|
|
148
|
+
| `buildModel` | `(files: FileTab[]) => ExecuteResult` | Lower-level: transpile + execute one file at a time, returns the merged inventory and per-file errors. Use when you want to drive the pipeline yourself |
|
|
142
149
|
| `validate` | `(model: DomainModel) => ValidationWarning[]` | Validate model for missing emits, etc. |
|
|
143
150
|
| `navigateToCode` | `(files, name, type?, targetFile?) => { file, line, col } \| undefined` | Find source location of a named element |
|
|
144
151
|
| `topoSort` | `(files: FileTab[]) => FileTab[]` | Sort files by import dependency order |
|
|
145
152
|
| `computeLayout` | `(model: DomainModel) => Layout` | Pure layout computation — positions all nodes, edges, and slice boxes |
|
|
146
153
|
| `emptyModel` | `() => DomainModel` | Create an empty domain model |
|
|
154
|
+
| `parseMultiFileResponse` | `(text: string) => FileTab[]` | Parse a multi-file AI response into individual `FileTab`s |
|
|
155
|
+
| `stripFences` | `(text: string) => string` | Strip Markdown code fences from a block — used by the AI pipeline to extract raw code |
|
|
156
|
+
| `deriveProjectName` | `(files: FileTab[]) => string` | Best-effort project name from the file set — used in the AI prompt context |
|
|
147
157
|
|
|
148
158
|
### Types
|
|
149
159
|
|
|
150
160
|
```typescript
|
|
151
161
|
type FileTab = { path: string; content: string };
|
|
152
162
|
|
|
163
|
+
type ExecuteResult = {
|
|
164
|
+
model: DomainModel;
|
|
165
|
+
errors: Record<string, string>; // keyed by file path
|
|
166
|
+
};
|
|
167
|
+
|
|
153
168
|
type DomainModel = {
|
|
154
169
|
entries: EntryPoint[];
|
|
155
170
|
states: StateNode[];
|
|
156
171
|
slices: SliceNode[];
|
|
157
172
|
projections: ProjectionNode[];
|
|
158
173
|
reactions: ReactionNode[];
|
|
159
|
-
orchestrator?: ActNode;
|
|
174
|
+
orchestrator?: ActNode; // present only after `act()` is composed
|
|
160
175
|
};
|
|
161
176
|
|
|
162
177
|
type StateNode = { name, varName, events: EventNode[], actions: ActionNode[], file?, line? };
|
|
@@ -187,6 +202,20 @@ type DiagramMessage =
|
|
|
187
202
|
| { type: "aiRequest"; prompt: string; files: FileTab[] };
|
|
188
203
|
```
|
|
189
204
|
|
|
205
|
+
## AI server (optional)
|
|
206
|
+
|
|
207
|
+
The `AiBar` component dispatches refinement prompts to a streaming endpoint. The package ships with a reference server at `src/server/server.ts` (port 4002) that forwards prompts to Anthropic's API:
|
|
208
|
+
|
|
209
|
+
```sh
|
|
210
|
+
# In one terminal
|
|
211
|
+
ANTHROPIC_API_KEY=sk-ant-... pnpm -F @rotorsoft/act-diagram dev:server
|
|
212
|
+
|
|
213
|
+
# In your host app, pass onAiRequest to ActDiagram
|
|
214
|
+
<ActDiagram onAiRequest={(prompt, files) => fetch("http://localhost:4002/api/generate", { ... })} />
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The reference server is a thin SSE relay — bring your own API key, your own model selection, and your own prompt strategy. AI mode is opt-in: omit `onAiRequest` and the `AiBar` doesn't render.
|
|
218
|
+
|
|
190
219
|
## Neovim Integration
|
|
191
220
|
|
|
192
221
|
See [@rotorsoft/act-nvim](https://github.com/Rotorsoft/act-nvim) — a Neovim plugin that renders act-diagram in the browser with bidirectional navigation, live refresh, and LSP diagnostic forwarding.
|
|
@@ -197,7 +226,7 @@ See [@rotorsoft/act-nvim](https://github.com/Rotorsoft/act-nvim) — a Neovim pl
|
|
|
197
226
|
# Visual dev server with sample diagram
|
|
198
227
|
pnpm -F @rotorsoft/act-diagram dev
|
|
199
228
|
|
|
200
|
-
# Run
|
|
229
|
+
# Run the test suite
|
|
201
230
|
pnpm -F @rotorsoft/act-diagram test
|
|
202
231
|
|
|
203
232
|
# Build library
|