@cadenza.io/service 1.22.0 → 1.23.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 +26 -76
- package/dist/index.d.mts +1043 -1041
- package/dist/index.d.ts +1043 -1041
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,21 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
Cadenza is an innovative framework that extends traditional orchestration with event-driven choreography, providing "structured freedom" for building distributed, self-evolving systems.
|
|
5
|
+
Cadenza is an innovative framework that extends traditional orchestration with event-driven choreography, providing "structured freedom" for building distributed, self-evolving systems.
|
|
6
6
|
|
|
7
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
8
|
|
|
9
9
|
Cadenza's design philosophy emphasizes:
|
|
10
|
-
- **
|
|
11
|
-
- **Meta-Layer Extension**: A self-reflective layer for monitoring, optimization, and auto-generation, enabling AI-driven self-development. Essentially extending the core
|
|
10
|
+
- **Decentralized Adaptive Orchestration (DAO)**: Explicit graphs for dependencies (orchestration) combined with signals for loose coupling (choreography). This combination allows for flexible and dynamic workflows, while still maintaining the benefits of traditional orchestration.
|
|
11
|
+
- **Meta-Layer Extension**: A self-reflective layer for monitoring, optimization, and auto-generation, enabling AI-driven self-development. Essentially used for extending the core features by using the core features.
|
|
12
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.
|
|
13
|
+
- **Modularity**: Lightweight core with extensions (e.g., distribution, UI integration) as separate packages using the meta layer.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
This repository (@Cadenza.io/service) is an extension of the core package, providing the infrastructure for making the Cadenza model truly distributed. It makes use of the core meta-layer extension, and provides a set of tools for building distributed applications, abstracting complexities like networking and security.
|
|
16
|
+
|
|
17
|
+
The service package provides everything in the core package plus the following:
|
|
18
|
+
- **Service Extension**: A Service exposes the local graphs and signals to other Services in the system and enables them to interact with tasks and signals across other Services in the system via socket and/or REST.
|
|
19
|
+
- **Database Service Extension**: A Database Service takes a schema and auto generates the necessary tasks and signals to interact with that database using the cadenza model. It exposes those tasks using by creating a Service.
|
|
20
|
+
- **CadenzaDB compatibility**: A service can connect to the official CadenzaDB service and will automatically sync realtime data for introspection and visualization.
|
|
21
|
+
|
|
22
|
+
There is no need to install the core package separately. Instead, install the service package, which includes everything in the core package plus the distributed extensions.
|
|
16
23
|
|
|
17
24
|
## Installation
|
|
18
25
|
|
|
19
|
-
Install the
|
|
26
|
+
Install the service package via npm:
|
|
20
27
|
|
|
21
28
|
```bash
|
|
22
29
|
npm install @cadenza.io/service
|
|
@@ -24,93 +31,36 @@ npm install @cadenza.io/service
|
|
|
24
31
|
|
|
25
32
|
## Usage
|
|
26
33
|
|
|
27
|
-
### Creating
|
|
28
|
-
|
|
34
|
+
### Creating a service
|
|
35
|
+
Creating a Service will create a REST server and a socket server. It will sync with the CadenzaDB service if available.
|
|
29
36
|
|
|
30
37
|
```typescript
|
|
31
38
|
import Cadenza from '@cadenza.io/service';
|
|
32
39
|
|
|
33
|
-
|
|
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'});
|
|
40
|
+
Cadenza.createCadenzaService('MyService'); // Name should start with an uppercase letter and contain no spaces.
|
|
67
41
|
```
|
|
68
42
|
|
|
69
|
-
###
|
|
70
|
-
|
|
43
|
+
### Working with distribution
|
|
44
|
+
Distribution is easy with Cadenza. You can delegate the flow by using a DeputyTask, or subscribe to foreign signals by prefixing them with the service name.
|
|
71
45
|
|
|
72
46
|
```typescript
|
|
73
|
-
|
|
74
|
-
|
|
47
|
+
// Creates a proxy Task for the specified task or routine on the specified service.
|
|
48
|
+
// The local flow will await the result of the remote flow.
|
|
49
|
+
Cadenza.createDeputyTask('Process context', 'ContextService');
|
|
75
50
|
|
|
76
|
-
|
|
51
|
+
// This will subscribe to the signal on the remote service.
|
|
52
|
+
localTask.doOn('ContextService.process.failed');
|
|
77
53
|
```
|
|
78
54
|
|
|
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
55
|
|
|
83
|
-
|
|
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');
|
|
56
|
+
For full examples, see this repository or the test suite.
|
|
93
57
|
|
|
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
58
|
|
|
99
59
|
## 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
60
|
|
|
106
61
|
## Architecture Overview
|
|
107
|
-
Cadenza's
|
|
108
|
-
|
|
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.
|
|
62
|
+
Cadenza's service package is divided into:
|
|
63
|
+
|
|
114
64
|
|
|
115
65
|
## Contributing
|
|
116
66
|
Contributions are welcome! Please fork the repo, create a branch, and submit a PR. Follow the code style and add tests for new features.
|