@cadenza.io/service 1.0.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/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Cadenza Service
2
+
3
+ ## Overview
4
+
5
+ Cadenza is an innovative framework that extends traditional orchestration with event-driven choreography, providing "structured freedom" for building distributed, self-evolving systems.
6
+
7
+ The core package (@Cadenza.io/core) includes the foundational primitives for defining and executing graphs of tasks, managing contexts, handling signals, and bootstrapping executions. It's designed to be language-agnostic in model, with this TypeScript implementation serving as the reference.
8
+
9
+ Cadenza's design philosophy emphasizes:
10
+ - **Structured Freedom**: Explicit graphs for dependencies (orchestration) combined with signals for loose coupling (choreography).
11
+ - **Meta-Layer Extension**: A self-reflective layer for monitoring, optimization, and auto-generation, enabling AI-driven self-development. Essentially extending the core, using the core.
12
+ - **Introspectability**: Exportable graphs, traceable executions, and metadata separation for transparency and debugging.
13
+ - **Modularity**: Lightweight core with extensions (e.g., distribution, UI integration) as separate packages.
14
+
15
+ The core is suitable for local dynamic workflows using tasks and signals. But thanks to the meta layer, it also serves as the foundation for the distributed, agentic AI applications, and more, abstracting complexities like networking and security in extensions.
16
+
17
+ ## Installation
18
+
19
+ Install the core package via npm:
20
+
21
+ ```bash
22
+ npm install @cadenza.io/service
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Creating Tasks
28
+ Tasks are the atomic units of work in Cadenza. They can be chained to form graphs.
29
+
30
+ ```typescript
31
+ import Cadenza from '@cadenza.io/service';
32
+
33
+ const task1 = Cadenza.createTask('task1', (context) => {
34
+ console.log(context.foo);
35
+ return { bar: 'baz' };
36
+ }, 'First task');
37
+
38
+ const task2 = Cadenza.createTask('task2', (context) => {
39
+ return {...context, qux: 'quux'};
40
+ }, 'Second task');
41
+
42
+ const task3 = Cadenza.createTask('task3', (context) => {
43
+ return {...context, cadenza: 'is awesome'};
44
+ }, 'Third task');
45
+
46
+ task1.then(
47
+ task2.then(
48
+ task3
49
+ ),
50
+ );
51
+
52
+ ```
53
+
54
+ ### Creating Routines
55
+ Routines are named entry points to graphs.
56
+
57
+ ```typescript
58
+ const routine = Cadenza.createRoutine('myRoutine', [task1], 'Test routine');
59
+ ```
60
+
61
+ ### Running Graphs
62
+ Use a Runner to execute routines or tasks.
63
+
64
+ ```typescript
65
+ const runner = Cadenza.runner;
66
+ await runner.run(routine, {foo: 'bar'});
67
+ ```
68
+
69
+ ### Signals
70
+ Signals provide event-driven coordination.
71
+
72
+ ```typescript
73
+ task1.emits('my.signal');
74
+ task2.doOn('my.other.signal');
75
+
76
+ Cadenza.broker.emit('my.other.signal', {foo: 'bar'}); // This will trigger task2
77
+ ```
78
+
79
+ ### Using the Meta Layer
80
+
81
+ The meta layer serves as a tool for extending the core features. It follows the same rules and primitives as the user layer but runs on a separate meta runner. It consists of MetaTasks, MetaRoutines and meta signals. To trigger a meta flow you need to emit a meta signal (meta.[domain].[action]).
82
+
83
+ ```typescript
84
+ Cadenza.createTask('My task', (ctx) => {
85
+ console.log(ctx.foo);
86
+ return ctx;
87
+ }).emits('meta.some.signal'); // Emits a on task execution
88
+
89
+ Cadenza.createMetaTask('My meta task', (ctx) => {
90
+ console.log(ctx.__task.name);
91
+ return true;
92
+ }).doOn('meta.some.signal');
93
+
94
+ Cadenza.broker.emit('meta.some.signal', {foo: 'bar'}); // Trigger from anywhere
95
+ ```
96
+
97
+ For full examples, see the [docs folder](docs/examples.md) or the test suite.
98
+
99
+ ## Features
100
+ - **Graph-Based Orchestration**: Define tasks and routines with chaining for dependencies, failovers, and layering.
101
+ - **Event-Driven Choreography**: Signals for loose coupling, with meta-signals for self-management.
102
+ - **Context Management**: Immutable contexts with metadata separation and schema validation.
103
+ - **Execution Engine**: Sync/async strategies, throttling, debouncing, and unique merging.
104
+ - **Bootstrapping**: Lazy initialization with seed tasks for registry and signal handling.
105
+
106
+ ## Architecture Overview
107
+ Cadenza's core is divided into:
108
+ - **Definition Layer**: Task, Routine for static graphs.
109
+ - **Execution Layer**: Node, Layer, Builder, Run for runtime.
110
+ - **Signal Layer**: SignalBroker, SignalParticipant for coordination.
111
+ - **Context Layer**: GraphContext for data flow.
112
+ - **Registry Layer**: GraphRegistry for introspection.
113
+ - **Factory**: Cadenza for creation and bootstrap.
114
+
115
+ ## Contributing
116
+ Contributions are welcome! Please fork the repo, create a branch, and submit a PR. Follow the code style and add tests for new features.
117
+
118
+ ## License
119
+ MIT License
120
+
121
+ Copyright (c) 2025 Cadenza.io
122
+
123
+ Permission is hereby granted, free of charge, to any person obtaining a copy
124
+ of this software and associated documentation files (the "Software"), to deal
125
+ in the Software without restriction, including without limitation the rights
126
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
127
+ copies of the Software, and to permit persons to whom the Software is
128
+ furnished to do so, subject to the following conditions:
129
+
130
+ The above copyright notice and this permission notice shall be included in all
131
+ copies or substantial portions of the Software.
132
+
133
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
134
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
135
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
136
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
137
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
138
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
139
+ SOFTWARE.