@graphrefly/graphrefly 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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +234 -0
  3. package/dist/chunk-5X3LAO3B.js +1571 -0
  4. package/dist/chunk-5X3LAO3B.js.map +1 -0
  5. package/dist/chunk-6W5SGIGB.js +1793 -0
  6. package/dist/chunk-6W5SGIGB.js.map +1 -0
  7. package/dist/chunk-CP6MNKAA.js +97 -0
  8. package/dist/chunk-CP6MNKAA.js.map +1 -0
  9. package/dist/chunk-HP7OKEOE.js +107 -0
  10. package/dist/chunk-HP7OKEOE.js.map +1 -0
  11. package/dist/chunk-KWXPDASV.js +781 -0
  12. package/dist/chunk-KWXPDASV.js.map +1 -0
  13. package/dist/chunk-O3PI7W45.js +68 -0
  14. package/dist/chunk-O3PI7W45.js.map +1 -0
  15. package/dist/chunk-QW7H3ICI.js +1372 -0
  16. package/dist/chunk-QW7H3ICI.js.map +1 -0
  17. package/dist/chunk-VPS7L64N.js +4785 -0
  18. package/dist/chunk-VPS7L64N.js.map +1 -0
  19. package/dist/chunk-Z4Y4FMQN.js +1097 -0
  20. package/dist/chunk-Z4Y4FMQN.js.map +1 -0
  21. package/dist/compat/nestjs/index.cjs +4883 -0
  22. package/dist/compat/nestjs/index.cjs.map +1 -0
  23. package/dist/compat/nestjs/index.d.cts +7 -0
  24. package/dist/compat/nestjs/index.d.ts +7 -0
  25. package/dist/compat/nestjs/index.js +84 -0
  26. package/dist/compat/nestjs/index.js.map +1 -0
  27. package/dist/core/index.cjs +1632 -0
  28. package/dist/core/index.cjs.map +1 -0
  29. package/dist/core/index.d.cts +2 -0
  30. package/dist/core/index.d.ts +2 -0
  31. package/dist/core/index.js +90 -0
  32. package/dist/core/index.js.map +1 -0
  33. package/dist/extra/index.cjs +6885 -0
  34. package/dist/extra/index.cjs.map +1 -0
  35. package/dist/extra/index.d.cts +5 -0
  36. package/dist/extra/index.d.ts +5 -0
  37. package/dist/extra/index.js +290 -0
  38. package/dist/extra/index.js.map +1 -0
  39. package/dist/graph/index.cjs +3225 -0
  40. package/dist/graph/index.cjs.map +1 -0
  41. package/dist/graph/index.d.cts +3 -0
  42. package/dist/graph/index.d.ts +3 -0
  43. package/dist/graph/index.js +25 -0
  44. package/dist/graph/index.js.map +1 -0
  45. package/dist/graph-CL_ZDAj9.d.cts +605 -0
  46. package/dist/graph-D18qmsNm.d.ts +605 -0
  47. package/dist/index-B6SsZs2h.d.cts +3463 -0
  48. package/dist/index-B7eOdgEx.d.ts +449 -0
  49. package/dist/index-BHUvlQ3v.d.ts +3463 -0
  50. package/dist/index-BtK55IE2.d.ts +231 -0
  51. package/dist/index-BvhgZRHK.d.cts +231 -0
  52. package/dist/index-Bvy_6CaN.d.ts +452 -0
  53. package/dist/index-C3BMRmmp.d.cts +449 -0
  54. package/dist/index-C5mqLhMX.d.cts +452 -0
  55. package/dist/index-CP_QvbWu.d.ts +940 -0
  56. package/dist/index-D_geH2Bm.d.cts +940 -0
  57. package/dist/index.cjs +14843 -0
  58. package/dist/index.cjs.map +1 -0
  59. package/dist/index.d.cts +1517 -0
  60. package/dist/index.d.ts +1517 -0
  61. package/dist/index.js +3649 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/meta-BsF6Sag9.d.cts +607 -0
  64. package/dist/meta-BsF6Sag9.d.ts +607 -0
  65. package/dist/patterns/reactive-layout/index.cjs +4143 -0
  66. package/dist/patterns/reactive-layout/index.cjs.map +1 -0
  67. package/dist/patterns/reactive-layout/index.d.cts +3 -0
  68. package/dist/patterns/reactive-layout/index.d.ts +3 -0
  69. package/dist/patterns/reactive-layout/index.js +38 -0
  70. package/dist/patterns/reactive-layout/index.js.map +1 -0
  71. package/dist/reactive-log-BfvfNWQh.d.cts +137 -0
  72. package/dist/reactive-log-ohLmTXoZ.d.ts +137 -0
  73. package/package.json +256 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 David Chen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,234 @@
1
+ # GraphReFly
2
+
3
+ **Reactive graph protocol for human + LLM co-operation.**
4
+
5
+ One primitive. Zero dependencies. Composable nodes with glitch-free diamond resolution, two-phase push propagation, durable streaming, and framework adapters for React, Vue, Svelte, Solid, and NestJS.
6
+
7
+ [![npm](https://img.shields.io/npm/v/@graphrefly/graphrefly-ts?color=blue)](https://www.npmjs.com/package/@graphrefly/graphrefly-ts)
8
+ [![license](https://img.shields.io/github/license/graphrefly/graphrefly-ts)](./LICENSE)
9
+
10
+ [Docs](https://graphrefly.dev) | [Spec](https://graphrefly.dev/spec/) | [Python](https://py.graphrefly.dev) | [API Reference](https://graphrefly.dev/api/node/)
11
+
12
+ ---
13
+
14
+ ## Quick start
15
+
16
+ ```bash
17
+ npm install @graphrefly/graphrefly-ts
18
+ ```
19
+
20
+ ```ts
21
+ import { state, derived, effect } from "@graphrefly/graphrefly-ts";
22
+
23
+ const count = state(0);
24
+ const doubled = derived([count], ([c]) => c * 2);
25
+
26
+ effect([doubled], ([d]) => console.log("doubled:", d));
27
+ // → doubled: 0
28
+
29
+ count.set(3);
30
+ // → doubled: 6
31
+ ```
32
+
33
+ ## Why GraphReFly?
34
+
35
+ Most state libraries solve **one** problem well. GraphReFly solves the space between them:
36
+
37
+ | | Zustand / Jotai | RxJS | XState | TC39 Signals | **GraphReFly** |
38
+ |--|-----------------|------|--------|-------------|---------------|
39
+ | Simple store API | yes | no | no | yes | **yes** |
40
+ | Streaming operators | no | yes | no | no | **yes** |
41
+ | Diamond resolution | no | n/a | n/a | partial | **glitch-free** |
42
+ | Graph introspection | no | no | visual | no | **describe / observe / diagram** |
43
+ | Durable checkpoints | no | no | persistence | no | **file / SQLite / IndexedDB** |
44
+ | LLM orchestration | no | no | no | no | **agentLoop / chatStream / toolRegistry** |
45
+ | Framework adapters | React | Angular | React / Vue | varies | **React / Vue / Svelte / Solid / NestJS** |
46
+ | Dependencies | 0 | 0 | 0 | n/a | **0** |
47
+
48
+ ## One primitive
49
+
50
+ Everything is a `node`. Sugar constructors give you the right shape:
51
+
52
+ ```ts
53
+ import { state, derived, producer, effect, pipe } from "@graphrefly/graphrefly-ts";
54
+
55
+ // Writable state
56
+ const name = state("world");
57
+
58
+ // Computed (re-runs when deps change)
59
+ const greeting = derived([name], ([n]) => `Hello, ${n}!`);
60
+
61
+ // Push source (timers, events, async streams)
62
+ const clock = producer((emit) => {
63
+ const id = setInterval(() => emit([[DATA, Date.now()]]), 1000);
64
+ return () => clearInterval(id);
65
+ });
66
+
67
+ // Side effect
68
+ effect([greeting], ([g]) => document.title = g);
69
+
70
+ // Operator pipeline
71
+ const delayed = pipe(clock, delay(500), map(([, ts]) => new Date(ts)));
72
+ ```
73
+
74
+ ## Streaming & operators
75
+
76
+ 70+ operators — transform, combine, buffer, window, rate-limit, retry, circuit-break:
77
+
78
+ ```ts
79
+ import { pipe, merge, switchMap, debounceTime, retry } from "@graphrefly/graphrefly-ts";
80
+
81
+ const search = pipe(
82
+ input,
83
+ debounceTime(300),
84
+ switchMap((query) => fromPromise(fetch(`/api?q=${query}`))),
85
+ retry({ strategy: "exponential", maxAttempts: 3 }),
86
+ );
87
+ ```
88
+
89
+ ## Graph container
90
+
91
+ Register nodes in a `Graph` for introspection, snapshot, and persistence:
92
+
93
+ ```ts
94
+ import { Graph, state, derived } from "@graphrefly/graphrefly-ts";
95
+
96
+ const g = new Graph("pricing");
97
+ const price = g.register("price", state(100));
98
+ const tax = g.register("tax", derived([price], ([p]) => p * 0.1));
99
+ const total = g.register("total", derived([price, tax], ([p, t]) => p + t));
100
+
101
+ g.describe(); // → full graph topology as JSON
102
+ g.diagram(); // → Mermaid diagram string
103
+ g.observe((e) => console.log(e)); // → live change stream
104
+ ```
105
+
106
+ ## AI & orchestration
107
+
108
+ First-class patterns for LLM streaming, agent loops, and human-in-the-loop workflows:
109
+
110
+ ```ts
111
+ import { chatStream, agentLoop, toolRegistry } from "@graphrefly/graphrefly-ts";
112
+
113
+ // Streaming chat with tool use
114
+ const chat = chatStream("assistant", {
115
+ model: "claude-sonnet-4-20250514",
116
+ tools: toolRegistry("tools", { search, calculate }),
117
+ });
118
+
119
+ // Full agent loop: observe → think → act → memory
120
+ const agent = agentLoop("researcher", {
121
+ llm: chat,
122
+ memory: agentMemory({ decay: "openviking" }),
123
+ });
124
+ ```
125
+
126
+ ## Framework adapters
127
+
128
+ Drop-in bindings — your framework, your way:
129
+
130
+ ```tsx
131
+ // React
132
+ import { useNode } from "@graphrefly/graphrefly-ts/compat/react";
133
+ const [value, setValue] = useNode(count);
134
+
135
+ // Vue
136
+ import { useNode } from "@graphrefly/graphrefly-ts/compat/vue";
137
+ const value = useNode(count); // → Ref<number>
138
+
139
+ // Svelte
140
+ import { toStore } from "@graphrefly/graphrefly-ts/compat/svelte";
141
+ const value = toStore(count); // → Svelte store
142
+
143
+ // Solid
144
+ import { useNode } from "@graphrefly/graphrefly-ts/compat/solid";
145
+ const value = useNode(count); // → Signal<number>
146
+
147
+ // NestJS
148
+ import { GraphReflyModule } from "@graphrefly/graphrefly-ts/compat/nestjs";
149
+ @Module({ imports: [GraphReflyModule.forRoot()] })
150
+ ```
151
+
152
+ ## Tree-shaking imports
153
+
154
+ Prefer subpath imports for minimal bundle:
155
+
156
+ ```ts
157
+ import { node, batch, DATA } from "@graphrefly/graphrefly-ts/core";
158
+ import { map, switchMap } from "@graphrefly/graphrefly-ts/extra";
159
+ import { Graph } from "@graphrefly/graphrefly-ts/graph";
160
+ ```
161
+
162
+ The root entry re-exports everything:
163
+
164
+ ```ts
165
+ import { node, map, Graph } from "@graphrefly/graphrefly-ts";
166
+ ```
167
+
168
+ ## Resilience & checkpoints
169
+
170
+ Built-in retry, circuit breakers, rate limiters, and persistent checkpoints:
171
+
172
+ ```ts
173
+ import { retry, circuitBreaker, saveGraphCheckpoint, FileCheckpointAdapter } from "@graphrefly/graphrefly-ts";
174
+
175
+ // Retry with exponential backoff
176
+ const resilient = pipe(source, retry({ strategy: "exponential" }));
177
+
178
+ // Circuit breaker
179
+ const breaker = circuitBreaker({ threshold: 5, resetTimeout: 30_000 });
180
+
181
+ // Checkpoint to file system
182
+ const adapter = new FileCheckpointAdapter("./checkpoints");
183
+ await saveGraphCheckpoint(graph, adapter);
184
+ ```
185
+
186
+ ## Project layout
187
+
188
+ | Path | Contents |
189
+ |------|----------|
190
+ | `src/core/` | Message protocol, `node` primitive, batch, sugar constructors |
191
+ | `src/extra/` | Operators, sources, data structures, resilience, checkpoints |
192
+ | `src/graph/` | `Graph` container, describe/observe, snapshot, persistence |
193
+ | `src/patterns/` | Orchestration, messaging, memory, AI, CQRS, reactive layout |
194
+ | `src/compat/` | Framework adapters (React, Vue, Svelte, Solid, NestJS) |
195
+ | `docs/` | Roadmap, guidance, benchmarks |
196
+ | `website/` | Astro + Starlight docs site ([graphrefly.dev](https://graphrefly.dev)) |
197
+
198
+ ## Scripts
199
+
200
+ ```bash
201
+ pnpm test # vitest run
202
+ pnpm run lint # biome check
203
+ pnpm run build # tsup (ESM + CJS + .d.ts)
204
+ pnpm bench # vitest bench
205
+ ```
206
+
207
+ ## Acknowledgments
208
+
209
+ GraphReFly builds on ideas from many projects and papers:
210
+
211
+ **Protocol & predecessor:**
212
+ - **[Callbag](https://github.com/callbag/callbag)** (Andre Staltz) — the original reactive protocol spec. GraphReFly's message-based node communication descends from callbag's function-calling-function model.
213
+ - **[callbag-recharge](https://github.com/Callbag-Recharge/callbag-recharge)** — GraphReFly's direct predecessor. 170+ modules, 4 architecture iterations, and 30 engineering blog posts that shaped every design decision.
214
+
215
+ **Reactive design patterns:**
216
+ - **[SolidJS](https://github.com/solidjs/solid)** — two-phase execution (DIRTY propagation + value flow), automatic caching, and effect batching. Identified as the closest philosophical neighbor during design research.
217
+ - **[Preact Signals](https://github.com/preactjs/signals)** — fine-grained reactivity and cached-flag optimization patterns that informed RESOLVED signal design.
218
+ - **[TC39 Signals Proposal](https://github.com/tc39/proposal-signals)** — the `.get()/.set()` contract and the push toward language-level reactivity that clarified where signals end and graphs begin.
219
+ - **[RxJS](https://github.com/ReactiveX/rxjs)** — operator naming conventions (aliases like `combineLatest`, `mergeMap`, `catchError`) and the DevTools observability philosophy that inspired the Inspector pattern.
220
+
221
+ **AI & memory:**
222
+ - **[OpenViking](https://github.com/volcengine/openviking)** (Volcengine) — the memory decay formula (`sigmoid(log1p(count)) * exp_decay(age, 7d)`) and L0/L1/L2 progressive loading strategy used in `agentMemory()`.
223
+ - **[FadeMem](https://arxiv.org/abs/2501.09399)** (Wei et al., ICASSP 2026) — biologically-inspired dual-layer memory with adaptive exponential decay, validating the decay approach independently.
224
+ - **[MAGMA](https://arxiv.org/abs/2501.13920)** (Jiang et al., 2026) — four-parallel-graph model (semantic/temporal/causal/entity) that informed `knowledgeGraph()` design.
225
+ - **[Letta/MemGPT](https://github.com/letta-ai/letta)**, **[Mem0](https://github.com/mem0ai/mem0)**, **[Zep/Graphiti](https://github.com/getzep/graphiti)**, **[Cognee](https://github.com/topoteretes/cognee)** — production memory architectures surveyed during `agentMemory()` design.
226
+
227
+ **Layout & other:**
228
+ - **[Pretext](https://github.com/chenglou/pretext)** (Cheng Lou) — inspired the reactive layout engine's DOM-free text measurement pipeline, rebuilt as a `state -> derived` graph.
229
+ - **[CASL](https://github.com/stalniy/casl)** — declarative `allow()`/`deny()` policy builder DX that inspired `policy()`, though CASL itself was rejected as a dependency.
230
+ - **[Nanostores](https://github.com/nanostores/nanostores)** — tiny framework-agnostic API with near 1:1 `.get()/.set()/.subscribe()` mapping that validated the store ergonomics.
231
+
232
+ ## License
233
+
234
+ [MIT](./LICENSE)