colonies-ts 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 +21 -0
- package/README.md +341 -0
- package/dist/index.d.mts +274 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +976 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +944 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Johan Kristiansson, RISE Research Institutes of Sweden AB
|
|
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,341 @@
|
|
|
1
|
+
# Colonies TS Client Library
|
|
2
|
+
|
|
3
|
+
[](https://github.com/colonyos/colonies-ts/actions/workflows/node.yml)
|
|
4
|
+
[](https://codecov.io/gh/colonyos/colonies-ts)
|
|
5
|
+
[](https://www.npmjs.com/package/colonies-ts)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
TypeScript client library for ColonyOS - a distributed meta-orchestrator for compute continuums.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install colonies-ts
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Three Execution Patterns
|
|
17
|
+
|
|
18
|
+
ColonyOS supports three patterns for distributed task execution:
|
|
19
|
+
|
|
20
|
+
### 1. Batch Processing
|
|
21
|
+
|
|
22
|
+
Traditional request-response pattern for discrete tasks. Submit a job, an executor picks it up, processes it, and returns the result.
|
|
23
|
+
|
|
24
|
+
```mermaid
|
|
25
|
+
sequenceDiagram
|
|
26
|
+
participant Client
|
|
27
|
+
participant Colonies Server
|
|
28
|
+
participant Executor
|
|
29
|
+
|
|
30
|
+
Client->>Colonies Server: submitFunctionSpec()
|
|
31
|
+
Colonies Server-->>Client: Process (WAITING)
|
|
32
|
+
Client->>Colonies Server: subscribeProcess(SUCCESS)
|
|
33
|
+
|
|
34
|
+
Executor->>Colonies Server: assign()
|
|
35
|
+
Colonies Server-->>Executor: Process (RUNNING)
|
|
36
|
+
|
|
37
|
+
Note over Executor: Execute task
|
|
38
|
+
|
|
39
|
+
Executor->>Colonies Server: closeProcess(output)
|
|
40
|
+
Colonies Server-->>Client: Process (SUCCESS)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// Submit a batch job
|
|
45
|
+
const process = await client.submitFunctionSpec({
|
|
46
|
+
funcname: 'process-image',
|
|
47
|
+
kwargs: { imageUrl: 'https://example.com/image.jpg' },
|
|
48
|
+
conditions: {
|
|
49
|
+
colonyname: 'my-colony',
|
|
50
|
+
executortype: 'image-processor',
|
|
51
|
+
},
|
|
52
|
+
maxexectime: 300,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Subscribe to process completion
|
|
56
|
+
client.subscribeProcess(
|
|
57
|
+
'my-colony', process.processid, ProcessState.SUCCESS, 300,
|
|
58
|
+
(result) => console.log('Output:', result.output),
|
|
59
|
+
console.error,
|
|
60
|
+
() => {}
|
|
61
|
+
);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Blueprint Reconciliation
|
|
65
|
+
|
|
66
|
+
Declarative desired-state pattern for managing resources. Define the desired state in a blueprint, and a reconciler continuously ensures the actual state matches.
|
|
67
|
+
|
|
68
|
+
```mermaid
|
|
69
|
+
sequenceDiagram
|
|
70
|
+
participant User
|
|
71
|
+
participant Colonies Server
|
|
72
|
+
participant Reconciler
|
|
73
|
+
participant Device
|
|
74
|
+
|
|
75
|
+
User->>Colonies Server: updateBlueprint(spec)
|
|
76
|
+
Note over Colonies Server: Generation++
|
|
77
|
+
|
|
78
|
+
Colonies Server->>Colonies Server: Create reconcile process
|
|
79
|
+
Reconciler->>Colonies Server: assign()
|
|
80
|
+
Colonies Server-->>Reconciler: Process (RUNNING)
|
|
81
|
+
|
|
82
|
+
Reconciler->>Colonies Server: getBlueprint()
|
|
83
|
+
Colonies Server-->>Reconciler: spec + status
|
|
84
|
+
|
|
85
|
+
Reconciler->>Device: Apply changes
|
|
86
|
+
Device-->>Reconciler: Current state
|
|
87
|
+
|
|
88
|
+
Reconciler->>Colonies Server: updateBlueprintStatus()
|
|
89
|
+
Reconciler->>Colonies Server: closeProcess()
|
|
90
|
+
Note over Colonies Server: spec == status
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Create a blueprint with desired state
|
|
95
|
+
await client.addBlueprint({
|
|
96
|
+
kind: 'HomeDevice',
|
|
97
|
+
metadata: { name: 'living-room-light', colonyname: 'home' },
|
|
98
|
+
handler: { executortype: 'home-reconciler' },
|
|
99
|
+
spec: { power: true, brightness: 80 }, // Desired state
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Update desired state - reconciler will sync
|
|
103
|
+
const bp = await client.getBlueprint('home', 'living-room-light');
|
|
104
|
+
bp.spec.brightness = 50;
|
|
105
|
+
await client.updateBlueprint(bp);
|
|
106
|
+
|
|
107
|
+
// Or via CLI: colonies blueprint set --name living-room-light --key spec.brightness --value 50
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 3. Real-time Channels
|
|
111
|
+
|
|
112
|
+
Bidirectional streaming for interactive workloads like chat, live data, or long-running processes with progress updates.
|
|
113
|
+
|
|
114
|
+
```mermaid
|
|
115
|
+
sequenceDiagram
|
|
116
|
+
participant Client
|
|
117
|
+
participant Colonies Server
|
|
118
|
+
participant Executor
|
|
119
|
+
|
|
120
|
+
Client->>Colonies Server: submitFunctionSpec(channels)
|
|
121
|
+
Colonies Server-->>Client: Process (WAITING)
|
|
122
|
+
Client->>Colonies Server: subscribeProcess(RUNNING)
|
|
123
|
+
|
|
124
|
+
Executor->>Colonies Server: assign()
|
|
125
|
+
Colonies Server-->>Executor: Process (RUNNING)
|
|
126
|
+
Colonies Server-->>Client: Process (RUNNING)
|
|
127
|
+
|
|
128
|
+
Client->>Colonies Server: subscribeChannel()
|
|
129
|
+
Note over Client,Executor: WebSocket streams open
|
|
130
|
+
|
|
131
|
+
Client->>Colonies Server: channelAppend("prompt")
|
|
132
|
+
Colonies Server-->>Executor: Message
|
|
133
|
+
|
|
134
|
+
loop Streaming response
|
|
135
|
+
Executor->>Colonies Server: channelAppend("token")
|
|
136
|
+
Colonies Server-->>Client: Message
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
Executor->>Colonies Server: closeProcess()
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// Submit process with channel
|
|
144
|
+
const process = await client.submitFunctionSpec({
|
|
145
|
+
funcname: 'chat',
|
|
146
|
+
kwargs: { model: 'llama3' },
|
|
147
|
+
conditions: { colonyname: 'ai', executortype: 'llm' },
|
|
148
|
+
channels: ['chat'],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Wait for process to be assigned, then subscribe to channel
|
|
152
|
+
client.subscribeProcess(
|
|
153
|
+
'ai', process.processid, ProcessState.RUNNING, 60,
|
|
154
|
+
(runningProcess) => {
|
|
155
|
+
// Now subscribe to channel for streaming
|
|
156
|
+
client.subscribeChannel(
|
|
157
|
+
runningProcess.processid, 'chat', 0, 300,
|
|
158
|
+
(entries) => entries.forEach(e => console.log(e.payload)),
|
|
159
|
+
console.error,
|
|
160
|
+
() => {}
|
|
161
|
+
);
|
|
162
|
+
// Send message
|
|
163
|
+
client.channelAppend(runningProcess.processid, 'chat', 1, 0, 'Hello!');
|
|
164
|
+
},
|
|
165
|
+
console.error,
|
|
166
|
+
() => {}
|
|
167
|
+
);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Crypto
|
|
171
|
+
|
|
172
|
+
The library includes a self-contained secp256k1 ECDSA implementation:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { Crypto } from 'colonies-ts';
|
|
176
|
+
|
|
177
|
+
const crypto = new Crypto();
|
|
178
|
+
|
|
179
|
+
// Generate a new private key
|
|
180
|
+
const privateKey = crypto.generatePrivateKey();
|
|
181
|
+
|
|
182
|
+
// Derive the public ID from a private key
|
|
183
|
+
const id = crypto.id(privateKey);
|
|
184
|
+
|
|
185
|
+
// Sign a message
|
|
186
|
+
const signature = crypto.sign('message', privateKey);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Examples
|
|
190
|
+
|
|
191
|
+
- [Home Automation](examples/blueprint/) - Complete web app for managing smart home devices using blueprints
|
|
192
|
+
|
|
193
|
+
## Documentation
|
|
194
|
+
|
|
195
|
+
- [Getting Started](docs/getting-started.md) - Introduction to ColonyOS and basic usage
|
|
196
|
+
- [Using Channels](docs/channels.md) - Real-time messaging between clients and executors
|
|
197
|
+
- [Building Reconcilers](docs/reconciler.md) - Blueprint and reconciler tutorial
|
|
198
|
+
- [API Reference](docs/api-reference.md) - Complete API documentation
|
|
199
|
+
|
|
200
|
+
## Development
|
|
201
|
+
|
|
202
|
+
### Prerequisites
|
|
203
|
+
|
|
204
|
+
- Node.js >= 18
|
|
205
|
+
- npm
|
|
206
|
+
|
|
207
|
+
### Install dependencies
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
npm install
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Run tests
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
npm test # Unit tests
|
|
217
|
+
npm run test:integration # Integration tests (requires running server)
|
|
218
|
+
npm run test:all # All tests
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Integration tests require a running ColonyOS server:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
cd /path/to/colonies
|
|
225
|
+
docker-compose up -d
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Build
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
npm run build
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
This generates ESM and CommonJS builds in the `dist/` directory.
|
|
235
|
+
|
|
236
|
+
## API Reference
|
|
237
|
+
|
|
238
|
+
### ColoniesClient
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
new ColoniesClient({
|
|
242
|
+
host: string, // Server hostname
|
|
243
|
+
port: number, // Server port
|
|
244
|
+
tls?: boolean, // Enable TLS (default: false)
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### Colony & Server
|
|
249
|
+
|
|
250
|
+
| Method | Description |
|
|
251
|
+
|--------|-------------|
|
|
252
|
+
| `setPrivateKey(key)` | Set the private key for signing requests |
|
|
253
|
+
| `getColonies()` | List all colonies |
|
|
254
|
+
| `getStatistics()` | Get server statistics |
|
|
255
|
+
| `addColony(colony)` | Add a new colony |
|
|
256
|
+
| `removeColony(colonyName)` | Remove a colony |
|
|
257
|
+
|
|
258
|
+
#### Executors
|
|
259
|
+
|
|
260
|
+
| Method | Description |
|
|
261
|
+
|--------|-------------|
|
|
262
|
+
| `getExecutors(colonyName)` | List executors in a colony |
|
|
263
|
+
| `getExecutor(colonyName, executorName)` | Get a specific executor |
|
|
264
|
+
| `addExecutor(executor)` | Register a new executor |
|
|
265
|
+
| `approveExecutor(colonyName, executorName)` | Approve an executor |
|
|
266
|
+
| `removeExecutor(colonyName, executorName)` | Remove an executor |
|
|
267
|
+
|
|
268
|
+
#### Processes
|
|
269
|
+
|
|
270
|
+
| Method | Description |
|
|
271
|
+
|--------|-------------|
|
|
272
|
+
| `submitFunctionSpec(spec)` | Submit a process |
|
|
273
|
+
| `assign(colonyName, timeout, prvKey)` | Assign a process to execute |
|
|
274
|
+
| `getProcess(processId)` | Get process details |
|
|
275
|
+
| `getProcesses(colonyName, count, state)` | List processes by state |
|
|
276
|
+
| `closeProcess(processId, output)` | Close a process successfully |
|
|
277
|
+
| `failProcess(processId, errors)` | Close a process with failure |
|
|
278
|
+
| `removeProcess(processId)` | Remove a process |
|
|
279
|
+
| `removeAllProcesses(colonyName, state)` | Remove all processes |
|
|
280
|
+
|
|
281
|
+
#### Workflows
|
|
282
|
+
|
|
283
|
+
| Method | Description |
|
|
284
|
+
|--------|-------------|
|
|
285
|
+
| `submitWorkflowSpec(spec)` | Submit a workflow (DAG) |
|
|
286
|
+
| `getProcessGraph(graphId)` | Get workflow details |
|
|
287
|
+
| `getProcessGraphs(colonyName, count, state?)` | List workflows |
|
|
288
|
+
| `removeProcessGraph(graphId)` | Remove a workflow |
|
|
289
|
+
| `removeAllProcessGraphs(colonyName, state?)` | Remove all workflows |
|
|
290
|
+
|
|
291
|
+
#### Channels
|
|
292
|
+
|
|
293
|
+
| Method | Description |
|
|
294
|
+
|--------|-------------|
|
|
295
|
+
| `channelAppend(processId, channelName, seq, inReplyTo, payload)` | Send message to channel |
|
|
296
|
+
| `channelRead(processId, channelName, afterSeq, limit)` | Read messages from channel |
|
|
297
|
+
| `subscribeChannel(...)` | Subscribe to channel via WebSocket |
|
|
298
|
+
| `subscribeProcess(...)` | Subscribe to process state changes |
|
|
299
|
+
|
|
300
|
+
#### Blueprints
|
|
301
|
+
|
|
302
|
+
| Method | Description |
|
|
303
|
+
|--------|-------------|
|
|
304
|
+
| `addBlueprintDefinition(definition)` | Add a blueprint definition |
|
|
305
|
+
| `getBlueprintDefinition(colonyName, name)` | Get a blueprint definition |
|
|
306
|
+
| `getBlueprintDefinitions(colonyName)` | List blueprint definitions |
|
|
307
|
+
| `removeBlueprintDefinition(colonyName, name)` | Remove a blueprint definition |
|
|
308
|
+
| `addBlueprint(blueprint)` | Add a blueprint |
|
|
309
|
+
| `getBlueprint(colonyName, name)` | Get a blueprint |
|
|
310
|
+
| `getBlueprints(colonyName, kind?, location?)` | List blueprints |
|
|
311
|
+
| `updateBlueprint(blueprint, forceGeneration?)` | Update a blueprint |
|
|
312
|
+
| `removeBlueprint(colonyName, name)` | Remove a blueprint |
|
|
313
|
+
| `updateBlueprintStatus(colonyName, name, status)` | Update blueprint status |
|
|
314
|
+
| `reconcileBlueprint(colonyName, name, force?)` | Trigger reconciliation |
|
|
315
|
+
|
|
316
|
+
#### Crons & Generators
|
|
317
|
+
|
|
318
|
+
| Method | Description |
|
|
319
|
+
|--------|-------------|
|
|
320
|
+
| `getCrons(colonyName)` | List cron jobs |
|
|
321
|
+
| `getCron(cronId)` | Get a cron job |
|
|
322
|
+
| `addCron(cronSpec)` | Add a cron job |
|
|
323
|
+
| `removeCron(cronId)` | Remove a cron job |
|
|
324
|
+
| `getGenerators(colonyName)` | List generators |
|
|
325
|
+
| `getGenerator(generatorId)` | Get a generator |
|
|
326
|
+
| `addGenerator(generatorSpec)` | Add a generator |
|
|
327
|
+
|
|
328
|
+
### ProcessState
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
enum ProcessState {
|
|
332
|
+
WAITING = 0,
|
|
333
|
+
RUNNING = 1,
|
|
334
|
+
SUCCESS = 2,
|
|
335
|
+
FAILED = 3,
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## License
|
|
340
|
+
|
|
341
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a new random private key
|
|
3
|
+
* @returns Hex-encoded private key (64 characters)
|
|
4
|
+
*/
|
|
5
|
+
declare function generatePrivateKey(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Derive the public ID from a private key
|
|
8
|
+
* Uses SHA3-256 hash of "04" + hex(publicKey)
|
|
9
|
+
* @param privateKey - Hex-encoded private key
|
|
10
|
+
* @returns Hex-encoded ID (64 characters)
|
|
11
|
+
*/
|
|
12
|
+
declare function deriveId(privateKey: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Sign a message with a private key
|
|
15
|
+
* @param message - Message to sign
|
|
16
|
+
* @param privateKey - Hex-encoded private key
|
|
17
|
+
* @returns Hex-encoded signature (130 characters: r + s + v)
|
|
18
|
+
*/
|
|
19
|
+
declare function sign(message: string, privateKey: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Crypto utility class for convenience
|
|
22
|
+
*/
|
|
23
|
+
declare class Crypto {
|
|
24
|
+
generatePrivateKey(): string;
|
|
25
|
+
id(privateKey: string): string;
|
|
26
|
+
sign(message: string, privateKey: string): string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* ColonyOS Client
|
|
31
|
+
* Ported from colonyspace/aila/src/lib/api/colony.ts
|
|
32
|
+
*/
|
|
33
|
+
interface ColoniesClientConfig {
|
|
34
|
+
host: string;
|
|
35
|
+
port: number;
|
|
36
|
+
tls?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface RPCMessage {
|
|
39
|
+
payloadtype: string;
|
|
40
|
+
payload: string;
|
|
41
|
+
signature: string;
|
|
42
|
+
}
|
|
43
|
+
interface FunctionSpec {
|
|
44
|
+
nodename?: string;
|
|
45
|
+
funcname: string;
|
|
46
|
+
args?: any[];
|
|
47
|
+
kwargs?: Record<string, any>;
|
|
48
|
+
priority?: number;
|
|
49
|
+
maxwaittime?: number;
|
|
50
|
+
maxexectime?: number;
|
|
51
|
+
maxretries?: number;
|
|
52
|
+
conditions?: {
|
|
53
|
+
colonyname?: string;
|
|
54
|
+
executornames?: string[];
|
|
55
|
+
executortype?: string;
|
|
56
|
+
dependencies?: string[];
|
|
57
|
+
nodes?: number;
|
|
58
|
+
cpu?: string;
|
|
59
|
+
processes?: number;
|
|
60
|
+
processespernode?: number;
|
|
61
|
+
mem?: string;
|
|
62
|
+
storage?: string;
|
|
63
|
+
gpu?: {
|
|
64
|
+
name?: string;
|
|
65
|
+
mem?: string;
|
|
66
|
+
count?: number;
|
|
67
|
+
nodecount?: number;
|
|
68
|
+
};
|
|
69
|
+
walltime?: number;
|
|
70
|
+
};
|
|
71
|
+
label?: string;
|
|
72
|
+
fs?: any;
|
|
73
|
+
env?: Record<string, string>;
|
|
74
|
+
channels?: string[];
|
|
75
|
+
}
|
|
76
|
+
declare enum ProcessState {
|
|
77
|
+
WAITING = 0,
|
|
78
|
+
RUNNING = 1,
|
|
79
|
+
SUCCESS = 2,
|
|
80
|
+
FAILED = 3
|
|
81
|
+
}
|
|
82
|
+
declare class ColoniesClient {
|
|
83
|
+
private host;
|
|
84
|
+
private port;
|
|
85
|
+
private tls;
|
|
86
|
+
private crypto;
|
|
87
|
+
private privateKey;
|
|
88
|
+
constructor(config: ColoniesClientConfig);
|
|
89
|
+
setPrivateKey(privateKey: string): void;
|
|
90
|
+
private getBaseUrl;
|
|
91
|
+
private createRPCMsg;
|
|
92
|
+
private sendRPC;
|
|
93
|
+
getColonies(): Promise<any>;
|
|
94
|
+
getStatistics(): Promise<any>;
|
|
95
|
+
/**
|
|
96
|
+
* Add a new colony (requires server private key)
|
|
97
|
+
* @param colony - Colony object with colonyid and name
|
|
98
|
+
*/
|
|
99
|
+
addColony(colony: {
|
|
100
|
+
colonyid: string;
|
|
101
|
+
name: string;
|
|
102
|
+
}): Promise<any>;
|
|
103
|
+
/**
|
|
104
|
+
* Remove a colony (requires server private key)
|
|
105
|
+
* @param colonyName - Name of the colony to remove
|
|
106
|
+
*/
|
|
107
|
+
removeColony(colonyName: string): Promise<any>;
|
|
108
|
+
getExecutors(colonyName: string): Promise<any>;
|
|
109
|
+
getExecutor(colonyName: string, executorName: string): Promise<any>;
|
|
110
|
+
addExecutor(executor: {
|
|
111
|
+
executorid: string;
|
|
112
|
+
executortype: string;
|
|
113
|
+
executorname: string;
|
|
114
|
+
colonyname: string;
|
|
115
|
+
}): Promise<any>;
|
|
116
|
+
approveExecutor(colonyName: string, executorName: string): Promise<any>;
|
|
117
|
+
removeExecutor(colonyName: string, executorName: string): Promise<any>;
|
|
118
|
+
submitFunctionSpec(spec: FunctionSpec): Promise<any>;
|
|
119
|
+
getProcess(processId: string): Promise<any>;
|
|
120
|
+
getProcesses(colonyName: string, count: number, state: ProcessState): Promise<any>;
|
|
121
|
+
removeProcess(processId: string): Promise<any>;
|
|
122
|
+
removeAllProcesses(colonyName: string, state?: number): Promise<any>;
|
|
123
|
+
assign(colonyName: string, timeout: number, executorPrvKey: string): Promise<any>;
|
|
124
|
+
closeProcess(processId: string, output: string[]): Promise<any>;
|
|
125
|
+
failProcess(processId: string, errors: string[]): Promise<any>;
|
|
126
|
+
submitWorkflowSpec(workflowSpec: {
|
|
127
|
+
colonyname: string;
|
|
128
|
+
functionspecs: FunctionSpec[];
|
|
129
|
+
}): Promise<any>;
|
|
130
|
+
getProcessGraph(processGraphId: string): Promise<any>;
|
|
131
|
+
getProcessGraphs(colonyName: string, count: number, state?: ProcessState): Promise<any>;
|
|
132
|
+
removeProcessGraph(processGraphId: string): Promise<any>;
|
|
133
|
+
removeAllProcessGraphs(colonyName: string, state?: ProcessState): Promise<any>;
|
|
134
|
+
addLog(processId: string, message: string, executorPrvKey: string): Promise<any>;
|
|
135
|
+
getLogs(colonyName: string, processId: string, executorName: string, count?: number, since?: number): Promise<any>;
|
|
136
|
+
getFunctions(executorName: string, colonyName: string): Promise<any>;
|
|
137
|
+
getCrons(colonyName: string, count?: number): Promise<any>;
|
|
138
|
+
getCron(cronId: string): Promise<any>;
|
|
139
|
+
addCron(cronSpec: any): Promise<any>;
|
|
140
|
+
removeCron(cronId: string): Promise<any>;
|
|
141
|
+
getGenerators(colonyName: string, count?: number): Promise<any>;
|
|
142
|
+
getGenerator(generatorId: string): Promise<any>;
|
|
143
|
+
addGenerator(generatorSpec: any): Promise<any>;
|
|
144
|
+
getUsers(colonyName: string): Promise<any>;
|
|
145
|
+
addUser(user: {
|
|
146
|
+
colonyname: string;
|
|
147
|
+
userid: string;
|
|
148
|
+
name: string;
|
|
149
|
+
email: string;
|
|
150
|
+
phone: string;
|
|
151
|
+
}): Promise<any>;
|
|
152
|
+
removeUser(colonyName: string, name: string): Promise<any>;
|
|
153
|
+
getFileLabels(colonyName: string, name?: string, exact?: boolean): Promise<any>;
|
|
154
|
+
getFiles(colonyName: string, label: string): Promise<any>;
|
|
155
|
+
addAttribute(attribute: {
|
|
156
|
+
targetid: string;
|
|
157
|
+
targetcolonyname: string;
|
|
158
|
+
targetprocessgraphid: string;
|
|
159
|
+
attributetype: number;
|
|
160
|
+
key: string;
|
|
161
|
+
value: string;
|
|
162
|
+
}): Promise<any>;
|
|
163
|
+
getAttribute(attributeId: string): Promise<any>;
|
|
164
|
+
/**
|
|
165
|
+
* Append a message to a process channel
|
|
166
|
+
* @param processId - ID of the process
|
|
167
|
+
* @param channelName - Name of the channel
|
|
168
|
+
* @param sequence - Client-assigned sequence number
|
|
169
|
+
* @param inReplyTo - Sequence number this message is replying to (0 if not a reply)
|
|
170
|
+
* @param payload - Message content (string or Uint8Array)
|
|
171
|
+
*/
|
|
172
|
+
channelAppend(processId: string, channelName: string, sequence: number, inReplyTo: number, payload: string | Uint8Array): Promise<any>;
|
|
173
|
+
/**
|
|
174
|
+
* Read messages from a process channel
|
|
175
|
+
* @param processId - ID of the process
|
|
176
|
+
* @param channelName - Name of the channel
|
|
177
|
+
* @param afterSeq - Read messages after this sequence number (use 0 for all)
|
|
178
|
+
* @param limit - Maximum number of messages to return (0 for no limit)
|
|
179
|
+
*/
|
|
180
|
+
channelRead(processId: string, channelName: string, afterSeq: number, limit: number): Promise<any[]>;
|
|
181
|
+
/**
|
|
182
|
+
* Subscribe to a channel using WebSocket for real-time updates
|
|
183
|
+
* @param processId - ID of the process
|
|
184
|
+
* @param channelName - Name of the channel
|
|
185
|
+
* @param afterSeq - Start reading after this sequence number
|
|
186
|
+
* @param timeout - Timeout in seconds for the subscription
|
|
187
|
+
* @param onMessage - Callback for new messages
|
|
188
|
+
* @param onError - Callback for errors
|
|
189
|
+
* @param onClose - Callback when connection closes
|
|
190
|
+
* @returns WebSocket instance for cleanup
|
|
191
|
+
*/
|
|
192
|
+
subscribeChannel(processId: string, channelName: string, afterSeq: number, timeout: number, onMessage: (entries: any[]) => void, onError: (error: Error) => void, onClose: () => void): WebSocket;
|
|
193
|
+
/**
|
|
194
|
+
* Add a blueprint definition
|
|
195
|
+
* @param definition - Blueprint definition object
|
|
196
|
+
*/
|
|
197
|
+
addBlueprintDefinition(definition: any): Promise<any>;
|
|
198
|
+
/**
|
|
199
|
+
* Get a blueprint definition by name
|
|
200
|
+
* @param colonyName - Name of the colony
|
|
201
|
+
* @param name - Name of the blueprint definition
|
|
202
|
+
*/
|
|
203
|
+
getBlueprintDefinition(colonyName: string, name: string): Promise<any>;
|
|
204
|
+
/**
|
|
205
|
+
* Get all blueprint definitions in a colony
|
|
206
|
+
* @param colonyName - Name of the colony
|
|
207
|
+
*/
|
|
208
|
+
getBlueprintDefinitions(colonyName: string): Promise<any[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Remove a blueprint definition
|
|
211
|
+
* @param colonyName - Name of the colony (namespace)
|
|
212
|
+
* @param name - Name of the blueprint definition to remove
|
|
213
|
+
*/
|
|
214
|
+
removeBlueprintDefinition(colonyName: string, name: string): Promise<void>;
|
|
215
|
+
/**
|
|
216
|
+
* Add a blueprint instance
|
|
217
|
+
* @param blueprint - Blueprint object
|
|
218
|
+
*/
|
|
219
|
+
addBlueprint(blueprint: any): Promise<any>;
|
|
220
|
+
/**
|
|
221
|
+
* Get a blueprint by name
|
|
222
|
+
* @param colonyName - Name of the colony (namespace)
|
|
223
|
+
* @param name - Name of the blueprint
|
|
224
|
+
*/
|
|
225
|
+
getBlueprint(colonyName: string, name: string): Promise<any>;
|
|
226
|
+
/**
|
|
227
|
+
* Get blueprints in a colony, optionally filtered by kind and location
|
|
228
|
+
* @param colonyName - Name of the colony (namespace)
|
|
229
|
+
* @param kind - Optional kind filter
|
|
230
|
+
* @param location - Optional location filter
|
|
231
|
+
*/
|
|
232
|
+
getBlueprints(colonyName: string, kind?: string, location?: string): Promise<any[]>;
|
|
233
|
+
/**
|
|
234
|
+
* Update an existing blueprint
|
|
235
|
+
* @param blueprint - Updated blueprint object
|
|
236
|
+
* @param forceGeneration - Force generation bump even if spec unchanged
|
|
237
|
+
*/
|
|
238
|
+
updateBlueprint(blueprint: any, forceGeneration?: boolean): Promise<any>;
|
|
239
|
+
/**
|
|
240
|
+
* Remove a blueprint
|
|
241
|
+
* @param colonyName - Name of the colony (namespace)
|
|
242
|
+
* @param name - Name of the blueprint to remove
|
|
243
|
+
*/
|
|
244
|
+
removeBlueprint(colonyName: string, name: string): Promise<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Update blueprint status (current state)
|
|
247
|
+
* @param colonyName - Name of the colony
|
|
248
|
+
* @param name - Name of the blueprint
|
|
249
|
+
* @param status - Status object representing current state
|
|
250
|
+
*/
|
|
251
|
+
updateBlueprintStatus(colonyName: string, name: string, status: any): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Trigger reconciliation for a blueprint
|
|
254
|
+
* @param colonyName - Name of the colony (namespace)
|
|
255
|
+
* @param name - Name of the blueprint
|
|
256
|
+
* @param force - Force reconciliation even if no changes detected
|
|
257
|
+
*/
|
|
258
|
+
reconcileBlueprint(colonyName: string, name: string, force?: boolean): Promise<any>;
|
|
259
|
+
/**
|
|
260
|
+
* Subscribe to process state changes using WebSocket
|
|
261
|
+
* Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels
|
|
262
|
+
* @param colonyName - Name of the colony
|
|
263
|
+
* @param processId - ID of the process to watch
|
|
264
|
+
* @param state - Target state to wait for (0=WAITING, 1=RUNNING, 2=SUCCESS, 3=FAILED)
|
|
265
|
+
* @param timeout - Timeout in seconds for the subscription
|
|
266
|
+
* @param onProcess - Callback when process reaches the target state
|
|
267
|
+
* @param onError - Callback for errors
|
|
268
|
+
* @param onClose - Callback when connection closes
|
|
269
|
+
* @returns WebSocket instance for cleanup
|
|
270
|
+
*/
|
|
271
|
+
subscribeProcess(colonyName: string, processId: string, state: number, timeout: number, onProcess: (process: any) => void, onError: (error: Error) => void, onClose: () => void): WebSocket;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { ColoniesClient, type ColoniesClientConfig, Crypto, type FunctionSpec, ProcessState, type RPCMessage, deriveId, generatePrivateKey, sign };
|