@assemblyline/al-orc 0.9.0 → 0.10.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/CHANGELOG.md +19 -0
- package/README.md +44 -5
- package/package.json +1 -1
- package/src/cli/lines/copy.js +96 -0
- package/src/cli/lines/index.js +54 -2
- package/src/cli/lines/show.js +1 -1
- package/src/cli/lines/write.js +51 -0
- package/src/cli/shared/print-warnings.js +11 -0
- package/src/cli/stations/archive.js +3 -0
- package/src/cli/stations/create.js +21 -0
- package/src/cli/stations/definition.js +83 -0
- package/src/cli/stations/edit.js +28 -15
- package/src/cli/stations/index.js +16 -5
- package/src/cli/stations/show.js +8 -12
- package/src/resources/lines.js +12 -1
- package/src/resources/stations.js +11 -5
- package/src/types/api/Line.types.js +1 -0
- package/src/types/api/Station.types.js +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.10.0] - 2026-12-04
|
|
11
|
+
|
|
12
|
+
The Orchestrator holds every station and line definition; these commands change it there
|
|
13
|
+
(lib-factory simplify stage 7).
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- `stations create <code> --line --name [--from] [--config] [--set] [--schedule] …`.
|
|
17
|
+
- `stations edit` changes every definition field: `--set`/`--unset` a config key, `--config`,
|
|
18
|
+
`--from`, `--schedule`, `--timezone`, `--enabled`, `--schedule-enabled`,
|
|
19
|
+
`--auto-drain-enabled`, `--name`, `--description`, `--line`, besides `--short-code` and tags.
|
|
20
|
+
- `lines create`, `lines edit`, `lines archive`, `lines unarchive`.
|
|
21
|
+
- `lines export` and `lines import [--as CODE] [--location]`: copy a line and its stations.
|
|
22
|
+
- Restart warnings: a change the factory session reads only at start prints
|
|
23
|
+
`⚠ Restart the factory session at <location> …`. The client keeps them as `warnings` on the
|
|
24
|
+
returned record.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- `stations show` prints From, Enabled, Schedule and Auto-drain instead of Dependencies.
|
|
28
|
+
|
|
10
29
|
## [0.9.0] - 2026-12-03
|
|
11
30
|
|
|
12
31
|
### Changed
|
package/README.md
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
# @assemblyline/al-orc
|
|
2
2
|
|
|
3
3
|
The [Assembly Line](https://assemblyline.sh) Orchestrator's client + `al-orc` CLI — a **2-in-1**:
|
|
4
|
-
import the client in code, or use the CLI to
|
|
5
|
-
records.
|
|
4
|
+
import the client in code, or use the CLI to create and change lines and stations, run them, and
|
|
5
|
+
read work records. The Orchestrator holds every line and station definition; you change it here
|
|
6
|
+
or in its UI, and the factory session reads it when it starts.
|
|
6
7
|
|
|
7
8
|
```bash
|
|
8
9
|
npm install -g @assemblyline/al-orc
|
|
9
10
|
al-orc login # pick orgs in the browser; one profile per org
|
|
10
11
|
al-orc status # org and key the profile belongs to
|
|
11
|
-
al-orc lines
|
|
12
|
+
al-orc lines create EX --location my-laptop --name "Example"
|
|
13
|
+
al-orc stations create EX1 --line EX --name "Check" --from EX0/output --auto-drain-enabled
|
|
14
|
+
al-orc stations edit EX1 --set batch_size=20 # one config key; the value is read as JSON
|
|
12
15
|
al-orc stations run EX0
|
|
13
16
|
al-orc stations run EX1 --set dry_run=true # change a config key for this run
|
|
14
17
|
al-orc work-records list --station EX0
|
|
@@ -19,6 +22,41 @@ printed link on any device). Orgs you already have a profile for show as connect
|
|
|
19
22
|
profile changes only when there was none. To add a key by hand instead:
|
|
20
23
|
`al-orc config profiles add acme --api-key <key> --api-secret <secret>`.
|
|
21
24
|
|
|
25
|
+
## Changing a definition
|
|
26
|
+
|
|
27
|
+
`stations edit` changes one field at a time, never a whole definition from a file:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
al-orc stations edit EM1 --set ignore_senders='["a.com","b.com"]' # a top-level config key
|
|
31
|
+
al-orc stations edit EM1 --unset model
|
|
32
|
+
al-orc stations edit EM1 --config '{"batch_size": 20}' # replace the whole config
|
|
33
|
+
al-orc stations edit EM1 --from EM0/output # --from "" removes the conveyor
|
|
34
|
+
al-orc stations edit EM1 --schedule "0 * * * *" --timezone Asia/Kolkata
|
|
35
|
+
al-orc stations edit EM1 --enabled false | --schedule-enabled false | --auto-drain-enabled true
|
|
36
|
+
al-orc stations edit EM1 --name "Classify email" --short-code EM2 --add-tag email
|
|
37
|
+
al-orc lines edit EM --location alex-linux-pc
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The factory session reads definitions when it starts. A change it acts on (`from`,
|
|
41
|
+
`auto_drain_enabled`, a line-head's `watch_path`, a code, a line's location, creating or archiving)
|
|
42
|
+
prints a warning to restart the session at the line's location:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
$ al-orc stations edit EM1 --from EM0/out2
|
|
46
|
+
Updated EM1: conveyor.
|
|
47
|
+
⚠ Restart the factory session at alex-linux-pc for this to take effect (from).
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Config, cron, `schedule_enabled`, `is_enabled`, names and tags take effect at once.
|
|
51
|
+
|
|
52
|
+
To copy a line to another org, or under a new code:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
al-orc lines export BK-SR > bk-sr.json # the line and its stations, without ids
|
|
56
|
+
al-orc lines import bk-sr.json --profile chisel # create them in another org
|
|
57
|
+
al-orc lines import bk-sr.json --as BK-SR2 # or a copy: BK-SR1 becomes BK-SR21
|
|
58
|
+
```
|
|
59
|
+
|
|
22
60
|
Profiles live in `~/.al/al-orc/config.yml` (mode 0600; override the folder with
|
|
23
61
|
`AL_ORC_CONFIG_DIR`). The CLI never reads `.env`.
|
|
24
62
|
|
|
@@ -40,7 +78,7 @@ Credentials are **explicit** — the client never reads `process.env`. Code serv
|
|
|
40
78
|
|
|
41
79
|
| Namespace | Methods |
|
|
42
80
|
|---|---|
|
|
43
|
-
| `orc.lines` | `list · getAll · get · create · update · delete` — a line owns the location its stations run at |
|
|
81
|
+
| `orc.lines` | `list · getAll · get · create · update · delete · archive · unarchive` — a line owns the location its stations run at |
|
|
44
82
|
| `orc.stations` | `list · getAll · get · create · update · delete · archive · unarchive · run · getTags · setTags` |
|
|
45
83
|
| `orc.workRecords` | `list · getAll · get · activity · cancel · getTags · setTags` |
|
|
46
84
|
| `orc.tags` | `list · create · update · delete · resolveNames · ensure` |
|
|
@@ -49,7 +87,8 @@ Credentials are **explicit** — the client never reads `process.env`. Code serv
|
|
|
49
87
|
| `orc.me()` | the org and API key the credentials belong to |
|
|
50
88
|
| `orc.checkConnection()` | credentials check via `me`; never throws and never claims work |
|
|
51
89
|
|
|
52
|
-
Return shapes: single-record ops return the unwrapped record
|
|
90
|
+
Return shapes: single-record ops return the unwrapped record (a write adds `warnings` when the
|
|
91
|
+
factory session must restart for it); `list` returns `{ data, page_context }`;
|
|
53
92
|
`getAll` returns a flat array.
|
|
54
93
|
|
|
55
94
|
## Endpoint contract
|
package/package.json
CHANGED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* `al-orc lines export` and `import`: copy a line and its stations, to another org or under a
|
|
4
|
+
* new code. The export file is made once and imported once, like a database dump; it is never
|
|
5
|
+
* kept or edited as the definition, which lives in the orchestrator.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import { clientFor } from '../_helpers.js';
|
|
10
|
+
import { printWarnings } from '../shared/print-warnings.js';
|
|
11
|
+
|
|
12
|
+
/** The station fields an export carries: the definition, without ids or orchestrator state. */
|
|
13
|
+
const STATION_FIELDS = [
|
|
14
|
+
'short_code', 'name', 'description', 'config', 'conveyor', 'is_enabled',
|
|
15
|
+
'schedule_cron', 'schedule_timezone', 'schedule_enabled', 'auto_drain_enabled',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {Object} LineExport
|
|
20
|
+
* @property {{ code: string, name: string, description: string|null, location: string }} line
|
|
21
|
+
* @property {Array<Record<string, any>>} stations
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The export of a line and its stations, ordered by code.
|
|
26
|
+
*
|
|
27
|
+
* @param {Record<string, any>} line - As the API returns it
|
|
28
|
+
* @param {Array<Record<string, any>>} stations - The line's stations, as the API returns them
|
|
29
|
+
* @returns {LineExport}
|
|
30
|
+
*/
|
|
31
|
+
export function buildExport(line, stations) {
|
|
32
|
+
return {
|
|
33
|
+
line: { code: line.code, name: line.name, description: line.description ?? null, location: line.location },
|
|
34
|
+
stations: [...stations]
|
|
35
|
+
.sort((a, b) => String(a.short_code).localeCompare(String(b.short_code)))
|
|
36
|
+
.map((s) => Object.fromEntries(STATION_FIELDS.filter((f) => s[f] !== undefined).map((f) => [f, s[f]]))),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Rename a line on import: the line's code, every station code that starts with it, and the
|
|
42
|
+
* bins in `conveyor.from` that name those stations. `BK-SR` → `BK-SR2` turns `BK-SR1` into
|
|
43
|
+
* `BK-SR21` and `BK-SR0/output` into `BK-SR20/output`.
|
|
44
|
+
*
|
|
45
|
+
* @param {LineExport} data
|
|
46
|
+
* @param {string} new_code
|
|
47
|
+
* @returns {LineExport}
|
|
48
|
+
*/
|
|
49
|
+
export function renameLine(data, new_code) {
|
|
50
|
+
const old_code = data.line.code;
|
|
51
|
+
const rename = (code) => (typeof code === 'string' && code.startsWith(old_code) ? new_code + code.slice(old_code.length) : code);
|
|
52
|
+
const renameBin = (bin) => {
|
|
53
|
+
const [code, ...rest] = bin.split('/');
|
|
54
|
+
return [rename(code), ...rest].join('/');
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
line: { ...data.line, code: new_code, name: data.line.name === old_code ? new_code : data.line.name },
|
|
58
|
+
stations: data.stations.map((s) => {
|
|
59
|
+
const from = s.conveyor?.from;
|
|
60
|
+
return {
|
|
61
|
+
...s,
|
|
62
|
+
short_code: rename(s.short_code),
|
|
63
|
+
...(from ? { conveyor: { from: Array.isArray(from) ? from.map(renameBin) : renameBin(from) } } : {}),
|
|
64
|
+
};
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** `al-orc lines export <code>` — the line and its stations as JSON, on stdout. */
|
|
70
|
+
export async function exportLineHandler(argv) {
|
|
71
|
+
const orc = clientFor();
|
|
72
|
+
const line = await orc.lines.get(argv.id);
|
|
73
|
+
if (!line) throw new Error(`Line not found: ${argv.id}`);
|
|
74
|
+
const stations = await orc.stations.getAll({ line: line.code });
|
|
75
|
+
console.log(JSON.stringify(buildExport(line, stations), null, 2));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `al-orc lines import <file> [--as CODE] [--location LOC]` — create the line and its stations. */
|
|
79
|
+
export async function importLineHandler(argv) {
|
|
80
|
+
let data = /** @type {LineExport} */ (JSON.parse(fs.readFileSync(argv.file, 'utf8')));
|
|
81
|
+
if (!data?.line?.code || !Array.isArray(data.stations)) {
|
|
82
|
+
throw new Error(`${argv.file} is not a line export: it needs { line: { code, … }, stations: [ … ] }`);
|
|
83
|
+
}
|
|
84
|
+
if (argv.as) data = renameLine(data, argv.as);
|
|
85
|
+
if (argv.location) data = { ...data, line: { ...data.line, location: argv.location } };
|
|
86
|
+
|
|
87
|
+
const orc = clientFor();
|
|
88
|
+
const line = await orc.lines.create(data.line);
|
|
89
|
+
console.log(`Created line ${line?.code ?? data.line.code} at ${data.line.location}.`);
|
|
90
|
+
let last = null;
|
|
91
|
+
for (const station of data.stations) {
|
|
92
|
+
last = await orc.stations.create({ ...station, line: data.line.code });
|
|
93
|
+
console.log(`Created ${last?.short_code ?? station.short_code}.`);
|
|
94
|
+
}
|
|
95
|
+
printWarnings(last ?? line);
|
|
96
|
+
}
|
package/src/cli/lines/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* A line is a sequence of stations that runs at exactly one location.
|
|
6
6
|
* The line owns `location`; stations name their line by `code` and inherit it.
|
|
7
|
-
*
|
|
7
|
+
* The orchestrator holds the definition; create and edit change it there.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { safe, paginationOptions, localOptions } from '../_helpers.js';
|
|
@@ -13,6 +13,8 @@ import { listLinesHandler } from './list.js';
|
|
|
13
13
|
import { showLineHandler } from './show.js';
|
|
14
14
|
import { pullLinesHandler } from './pull.js';
|
|
15
15
|
import { pushLinesHandler } from './push.js';
|
|
16
|
+
import { createLineHandler, editLineHandler, archiveLineHandler, unarchiveLineHandler } from './write.js';
|
|
17
|
+
import { exportLineHandler, importLineHandler } from './copy.js';
|
|
16
18
|
|
|
17
19
|
export function buildLinesSubcommands(yargs) {
|
|
18
20
|
return yargs
|
|
@@ -34,6 +36,56 @@ export function buildLinesSubcommands(yargs) {
|
|
|
34
36
|
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
35
37
|
safe(showLineHandler),
|
|
36
38
|
)
|
|
39
|
+
.command(
|
|
40
|
+
'create <code>',
|
|
41
|
+
'Create a line: al-orc lines create EM --location alex-linux-pc --name "Email"',
|
|
42
|
+
(y) =>
|
|
43
|
+
localOptions(y.positional('code', { describe: 'Line code, e.g. EM', type: 'string' }))
|
|
44
|
+
.option('location', { describe: 'Where the line runs (FACTORY_LOCATION of its session)', type: 'string', demandOption: true })
|
|
45
|
+
.option('name', { describe: 'Display name (defaults to the code)', type: 'string' })
|
|
46
|
+
.option('description', { describe: 'What the line does', type: 'string' })
|
|
47
|
+
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
48
|
+
safe(createLineHandler),
|
|
49
|
+
)
|
|
50
|
+
.command(
|
|
51
|
+
'edit <id>',
|
|
52
|
+
'Change a line\'s code, name, description or location',
|
|
53
|
+
(y) =>
|
|
54
|
+
localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' }))
|
|
55
|
+
.option('code', { describe: 'New code', type: 'string' })
|
|
56
|
+
.option('name', { describe: 'Display name', type: 'string' })
|
|
57
|
+
.option('description', { describe: 'What the line does ("" clears it)', type: 'string' })
|
|
58
|
+
.option('location', { describe: 'Where the line runs', type: 'string' })
|
|
59
|
+
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
60
|
+
safe(editLineHandler),
|
|
61
|
+
)
|
|
62
|
+
.command(
|
|
63
|
+
'archive <id>',
|
|
64
|
+
'Archive a line (its stations must be archived first)',
|
|
65
|
+
(y) => localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' })),
|
|
66
|
+
safe(archiveLineHandler),
|
|
67
|
+
)
|
|
68
|
+
.command(
|
|
69
|
+
'unarchive <id>',
|
|
70
|
+
'Unarchive a line (its stations stay archived)',
|
|
71
|
+
(y) => localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' })),
|
|
72
|
+
safe(unarchiveLineHandler),
|
|
73
|
+
)
|
|
74
|
+
.command(
|
|
75
|
+
'export <id>',
|
|
76
|
+
'Print a line and its stations as JSON, without ids, to import elsewhere',
|
|
77
|
+
(y) => localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' })),
|
|
78
|
+
safe(exportLineHandler),
|
|
79
|
+
)
|
|
80
|
+
.command(
|
|
81
|
+
'import <file>',
|
|
82
|
+
'Create a line and its stations from an export (into the --profile org)',
|
|
83
|
+
(y) =>
|
|
84
|
+
localOptions(y.positional('file', { describe: 'A file from al-orc lines export', type: 'string' }))
|
|
85
|
+
.option('as', { describe: 'Import under a new line code; station codes and from bins follow', type: 'string' })
|
|
86
|
+
.option('location', { describe: 'Run the line at another location', type: 'string' }),
|
|
87
|
+
safe(importLineHandler),
|
|
88
|
+
)
|
|
37
89
|
.command(
|
|
38
90
|
'pull [id]',
|
|
39
91
|
'Pull line definitions to .orchestrator/lines/ (--all for every line)',
|
|
@@ -50,5 +102,5 @@ export function buildLinesSubcommands(yargs) {
|
|
|
50
102
|
.option('all', { describe: 'Push every local line file', type: 'boolean' }),
|
|
51
103
|
safe(pushLinesHandler),
|
|
52
104
|
)
|
|
53
|
-
.demandCommand(1, 'Specify an action: list, show, pull, push');
|
|
105
|
+
.demandCommand(1, 'Specify an action: list, show, create, edit, archive, unarchive, export, import, pull, push');
|
|
54
106
|
}
|
package/src/cli/lines/show.js
CHANGED
|
@@ -30,7 +30,7 @@ export async function showLineHandler(argv) {
|
|
|
30
30
|
const stations = line.stations || [];
|
|
31
31
|
console.log(formatSection(`Stations (${stations.length})`));
|
|
32
32
|
if (stations.length === 0) {
|
|
33
|
-
console.log(' (none —
|
|
33
|
+
console.log(' (none — al-orc stations create <CODE> --line ' + line.code + ')');
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
console.log(formatTable(['CODE', 'ID', 'NAME'], stations.map((s) => [s.short_code || '—', s.id, s.name || '—'])));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { clientFor } from '../_helpers.js';
|
|
3
|
+
import { printWarnings } from '../shared/print-warnings.js';
|
|
4
|
+
|
|
5
|
+
/** `al-orc lines create <code> --location <loc> [--name] [--description]` */
|
|
6
|
+
export async function createLineHandler(argv) {
|
|
7
|
+
const { code, location, name, description, json } = argv;
|
|
8
|
+
const line = await clientFor().lines.create({ code, location, name, description });
|
|
9
|
+
if (json) {
|
|
10
|
+
console.log(JSON.stringify(line, null, 2));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
console.log(`Created line ${line?.code ?? code} at ${line?.location ?? location}.`);
|
|
14
|
+
printWarnings(line);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** `al-orc lines edit <id> [--code] [--name] [--description] [--location]` */
|
|
18
|
+
export async function editLineHandler(argv) {
|
|
19
|
+
const { id, code, name, description, location, json } = argv;
|
|
20
|
+
/** @type {Record<string, any>} */
|
|
21
|
+
const body = {};
|
|
22
|
+
if (code !== undefined) body.code = code;
|
|
23
|
+
if (name !== undefined) body.name = name;
|
|
24
|
+
if (description !== undefined) body.description = description || null;
|
|
25
|
+
if (location !== undefined) body.location = location;
|
|
26
|
+
if (Object.keys(body).length === 0) {
|
|
27
|
+
throw new Error('Nothing to change: give --code, --name, --description or --location');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const line = await clientFor().lines.update(id, body);
|
|
31
|
+
if (json) {
|
|
32
|
+
console.log(JSON.stringify(line, null, 2));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
console.log(`Updated line ${line?.code ?? id}: ${Object.keys(body).join(', ')}.`);
|
|
36
|
+
printWarnings(line);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** `al-orc lines archive <id>` */
|
|
40
|
+
export async function archiveLineHandler(argv) {
|
|
41
|
+
const line = await clientFor().lines.archive(argv.id);
|
|
42
|
+
console.log(`Archived line ${argv.id}.`);
|
|
43
|
+
printWarnings(line);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `al-orc lines unarchive <id>` */
|
|
47
|
+
export async function unarchiveLineHandler(argv) {
|
|
48
|
+
const line = await clientFor().lines.unarchive(argv.id);
|
|
49
|
+
console.log(`Unarchived line ${argv.id}.`);
|
|
50
|
+
printWarnings(line);
|
|
51
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Print the restart warnings an orchestrator write returned: changes the factory session reads
|
|
5
|
+
* only when it starts. To stderr, like every diagnostic.
|
|
6
|
+
*
|
|
7
|
+
* @param {{ warnings?: string[] } | null | undefined} record
|
|
8
|
+
*/
|
|
9
|
+
export function printWarnings(record) {
|
|
10
|
+
for (const warning of record?.warnings ?? []) console.error(`⚠ ${warning}`);
|
|
11
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { clientFor } from '../_helpers.js';
|
|
3
|
+
import { printWarnings } from '../shared/print-warnings.js';
|
|
3
4
|
|
|
4
5
|
/** `al-orc stations archive <id>` — hide from default list, preserve history, block execution. */
|
|
5
6
|
export async function archiveStationHandler(argv) {
|
|
@@ -11,6 +12,7 @@ export async function archiveStationHandler(argv) {
|
|
|
11
12
|
}
|
|
12
13
|
// The API response carries short_code; `id` is only what the user typed.
|
|
13
14
|
console.log(`Archived station ${station?.short_code || id}.`);
|
|
15
|
+
printWarnings(station);
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
/** `al-orc stations unarchive <id>` — undo archive. */
|
|
@@ -22,4 +24,5 @@ export async function unarchiveStationHandler(argv) {
|
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
26
|
console.log(`Unarchived station ${station?.short_code || id}.`);
|
|
27
|
+
printWarnings(station);
|
|
25
28
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { clientFor } from '../_helpers.js';
|
|
3
|
+
import { printWarnings } from '../shared/print-warnings.js';
|
|
4
|
+
import { definitionBody } from './definition.js';
|
|
5
|
+
|
|
6
|
+
/** `al-orc stations create <code> --line <code> --name "…"` — create a station in the orchestrator. */
|
|
7
|
+
export async function createStationHandler(argv) {
|
|
8
|
+
const { code, json } = argv;
|
|
9
|
+
/** @type {Record<string, any>} */
|
|
10
|
+
const body = { short_code: code, ...definitionBody(argv) };
|
|
11
|
+
if (!body.line) throw new Error('--line is required: every station is on a line');
|
|
12
|
+
if (!body.name) throw new Error('--name is required');
|
|
13
|
+
|
|
14
|
+
const station = await clientFor().stations.create(body);
|
|
15
|
+
if (json) {
|
|
16
|
+
console.log(JSON.stringify(station, null, 2));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
console.log(`Created ${station?.short_code ?? code} (${station?.id}).`);
|
|
20
|
+
printWarnings(station);
|
|
21
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* The definition options `stations create` and `stations edit` share, and the request body
|
|
4
|
+
* they build. A definition is changed one field at a time, never sent whole from a file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { parseSets } from './run.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Register the definition options on a command.
|
|
11
|
+
* @param {any} yargs
|
|
12
|
+
*/
|
|
13
|
+
export function definitionOptions(yargs) {
|
|
14
|
+
return yargs
|
|
15
|
+
.option('name', { describe: 'Display name', type: 'string' })
|
|
16
|
+
.option('description', { describe: 'What the station does', type: 'string' })
|
|
17
|
+
.option('line', { describe: 'Line code (moves the station when editing)', type: 'string' })
|
|
18
|
+
.option('config', { describe: 'The whole config, as a JSON object (replaces it)', type: 'string' })
|
|
19
|
+
.option('set', {
|
|
20
|
+
describe: 'Set one top-level config key; repeatable. The value is read as JSON (true, 2, "x", [..]), else text',
|
|
21
|
+
type: 'string',
|
|
22
|
+
array: true,
|
|
23
|
+
})
|
|
24
|
+
.option('unset', { describe: 'Remove a top-level config key; repeatable', type: 'string', array: true })
|
|
25
|
+
.option('from', {
|
|
26
|
+
describe: 'Bin(s) the conveyor moves work from, e.g. EM0/output; repeatable. --from "" removes the conveyor',
|
|
27
|
+
type: 'string',
|
|
28
|
+
array: true,
|
|
29
|
+
})
|
|
30
|
+
.option('schedule', { describe: 'Cron expression ("" clears it)', type: 'string' })
|
|
31
|
+
.option('timezone', { describe: 'IANA timezone for the schedule, e.g. Asia/Kolkata', type: 'string' })
|
|
32
|
+
.option('enabled', { describe: 'Station on or off (off: nothing runs, not even by hand)', type: 'boolean' })
|
|
33
|
+
.option('schedule-enabled', { describe: 'Cron on or off, keeping its expression', type: 'boolean' })
|
|
34
|
+
.option('auto-drain-enabled', {
|
|
35
|
+
describe: 'Run automatically whenever work is waiting (input/, or a line-head\'s watch_path)',
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The API body for the definition options given.
|
|
42
|
+
*
|
|
43
|
+
* @param {Record<string, any>} argv
|
|
44
|
+
* @param {Record<string, any>} [current_config] - The station's config now; --set and --unset change a copy of it
|
|
45
|
+
* @returns {Record<string, any>}
|
|
46
|
+
*/
|
|
47
|
+
export function definitionBody(argv, current_config = {}) {
|
|
48
|
+
/** @type {Record<string, any>} */
|
|
49
|
+
const body = {};
|
|
50
|
+
if (argv.name !== undefined) body.name = argv.name;
|
|
51
|
+
if (argv.description !== undefined) body.description = argv.description || null;
|
|
52
|
+
if (argv.line !== undefined) body.line = argv.line;
|
|
53
|
+
|
|
54
|
+
const sets = argv.set ?? [];
|
|
55
|
+
const unsets = argv.unset ?? [];
|
|
56
|
+
if (argv.config !== undefined || sets.length > 0 || unsets.length > 0) {
|
|
57
|
+
let config = { ...current_config };
|
|
58
|
+
if (argv.config !== undefined) {
|
|
59
|
+
try {
|
|
60
|
+
config = JSON.parse(argv.config);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
throw new Error(`--config is not valid JSON: ${err.message}`);
|
|
63
|
+
}
|
|
64
|
+
if (config === null || typeof config !== 'object' || Array.isArray(config)) {
|
|
65
|
+
throw new Error('--config must be a JSON object');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
Object.assign(config, parseSets(sets));
|
|
69
|
+
for (const key of unsets) delete config[key];
|
|
70
|
+
body.config = config;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (argv.from !== undefined) {
|
|
74
|
+
const bins = argv.from.filter((bin) => bin !== '');
|
|
75
|
+
body.conveyor = bins.length === 0 ? null : { from: bins.length === 1 ? bins[0] : bins };
|
|
76
|
+
}
|
|
77
|
+
if (argv.schedule !== undefined) body.schedule_cron = argv.schedule || null;
|
|
78
|
+
if (argv.timezone !== undefined) body.schedule_timezone = argv.timezone;
|
|
79
|
+
if (argv.enabled !== undefined) body.is_enabled = argv.enabled;
|
|
80
|
+
if (argv.scheduleEnabled !== undefined) body.schedule_enabled = argv.scheduleEnabled;
|
|
81
|
+
if (argv.autoDrainEnabled !== undefined) body.auto_drain_enabled = argv.autoDrainEnabled;
|
|
82
|
+
return body;
|
|
83
|
+
}
|
package/src/cli/stations/edit.js
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { clientFor } from '../_helpers.js';
|
|
3
3
|
import { editEntityTags } from '../shared/edit-tags.js';
|
|
4
|
+
import { printWarnings } from '../shared/print-warnings.js';
|
|
5
|
+
import { definitionBody } from './definition.js';
|
|
4
6
|
|
|
5
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* `al-orc stations edit <id> [options]` — change a station's definition in the orchestrator,
|
|
9
|
+
* field by field, and its tags.
|
|
10
|
+
*/
|
|
6
11
|
export async function editStationHandler(argv) {
|
|
7
|
-
const { id, shortCode: short_code, addTag: add_tag, removeTag: remove_tag } = argv;
|
|
12
|
+
const { id, shortCode: short_code, addTag: add_tag, removeTag: remove_tag, json } = argv;
|
|
8
13
|
|
|
9
14
|
const add_tags = add_tag ? [].concat(add_tag) : [];
|
|
10
15
|
const remove_tags = remove_tag ? [].concat(remove_tag) : [];
|
|
11
|
-
const
|
|
16
|
+
const orc = clientFor();
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
+
const changes_config = (argv.set ?? []).length > 0 || (argv.unset ?? []).length > 0;
|
|
19
|
+
const current = changes_config ? await orc.stations.get(id) : null;
|
|
20
|
+
if (changes_config && !current) throw new Error(`Station not found: ${id}`);
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
const body = definitionBody(argv, current?.config ?? {});
|
|
23
|
+
if (short_code !== undefined) body.short_code = short_code || null;
|
|
21
24
|
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
console.log(`Short code set: ${short_code || '(cleared)'}`);
|
|
25
|
+
if (Object.keys(body).length === 0 && add_tags.length === 0 && remove_tags.length === 0) {
|
|
26
|
+
throw new Error('Nothing to change: give at least one option (see al-orc stations edit --help)');
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
let station = null;
|
|
30
|
+
if (Object.keys(body).length > 0) {
|
|
31
|
+
station = await orc.stations.update(id, body);
|
|
32
|
+
}
|
|
33
|
+
if (add_tags.length > 0 || remove_tags.length > 0) {
|
|
28
34
|
await editEntityTags(orc.stations, orc.tags, id, add_tags, remove_tags);
|
|
29
|
-
console.log('Tags updated');
|
|
30
35
|
}
|
|
36
|
+
|
|
37
|
+
if (json) {
|
|
38
|
+
console.log(JSON.stringify(station ?? (await orc.stations.get(id)), null, 2));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const changed = [...Object.keys(body), ...(add_tags.length || remove_tags.length ? ['tags'] : [])];
|
|
42
|
+
console.log(`Updated ${station?.short_code ?? id}: ${changed.join(', ')}.`);
|
|
43
|
+
printWarnings(station);
|
|
31
44
|
}
|
|
@@ -13,6 +13,8 @@ import { runStationHandler } from './run.js';
|
|
|
13
13
|
import { archiveStationHandler, unarchiveStationHandler } from './archive.js';
|
|
14
14
|
import { deleteStationHandler } from './delete.js';
|
|
15
15
|
import { editStationHandler } from './edit.js';
|
|
16
|
+
import { createStationHandler } from './create.js';
|
|
17
|
+
import { definitionOptions } from './definition.js';
|
|
16
18
|
import { pullStationsHandler } from './pull.js';
|
|
17
19
|
import { pushStationsHandler } from './push.js';
|
|
18
20
|
|
|
@@ -45,21 +47,30 @@ export function buildStationsSubcommands(yargs) {
|
|
|
45
47
|
(y) =>
|
|
46
48
|
localOptions(y.positional('id', { describe: 'Station ID or short_code', type: 'string' }))
|
|
47
49
|
.option('set', {
|
|
48
|
-
describe: 'Change a config key
|
|
50
|
+
describe: 'Change a config key for this run; repeatable. The value is read as JSON (true, 2, "x"), else text',
|
|
49
51
|
type: 'string',
|
|
50
52
|
array: true,
|
|
51
53
|
})
|
|
52
54
|
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
53
55
|
safe(runStationHandler),
|
|
54
56
|
)
|
|
57
|
+
.command(
|
|
58
|
+
'create <code>',
|
|
59
|
+
'Create a station: al-orc stations create EM5 --line EM --name "…" --from EM4/output',
|
|
60
|
+
(y) =>
|
|
61
|
+
definitionOptions(localOptions(y.positional('code', { describe: 'Station code, e.g. EM5', type: 'string' })))
|
|
62
|
+
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
63
|
+
safe(createStationHandler),
|
|
64
|
+
)
|
|
55
65
|
.command(
|
|
56
66
|
'edit <id>',
|
|
57
|
-
'
|
|
67
|
+
'Change a station\'s definition, field by field: config keys, from, schedule, switches, name, code, tags',
|
|
58
68
|
(y) =>
|
|
59
|
-
localOptions(y.positional('id', { describe: 'Station ID or short_code', type: 'string' }))
|
|
69
|
+
definitionOptions(localOptions(y.positional('id', { describe: 'Station ID or short_code', type: 'string' })))
|
|
60
70
|
.option('short-code', { describe: 'Set the short_code (empty string clears it)', type: 'string' })
|
|
61
71
|
.option('add-tag', { describe: 'Tag name to add (repeatable)', type: 'string', array: true })
|
|
62
|
-
.option('remove-tag', { describe: 'Tag name to remove (repeatable)', type: 'string', array: true })
|
|
72
|
+
.option('remove-tag', { describe: 'Tag name to remove (repeatable)', type: 'string', array: true })
|
|
73
|
+
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
63
74
|
safe(editStationHandler),
|
|
64
75
|
)
|
|
65
76
|
.command(
|
|
@@ -103,5 +114,5 @@ export function buildStationsSubcommands(yargs) {
|
|
|
103
114
|
.option('cascade', { describe: 'Also delete its work records (otherwise refused while any exist)', type: 'boolean' }),
|
|
104
115
|
safe(deleteStationHandler),
|
|
105
116
|
)
|
|
106
|
-
.demandCommand(1, 'Specify an action: list, show, run, edit, pull, push, archive, unarchive, delete');
|
|
117
|
+
.demandCommand(1, 'Specify an action: list, show, run, create, edit, pull, push, archive, unarchive, delete');
|
|
107
118
|
}
|
package/src/cli/stations/show.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { clientFor } from '../_helpers.js';
|
|
3
|
-
import { buildStationLabelMap, stationLabel } from '../utils/station-labels.js';
|
|
4
3
|
import { formatHeader, formatField, formatTable, formatSection, formatDate, formatDuration, localTzLabel, truncate } from '../utils/format.js';
|
|
5
4
|
|
|
6
5
|
/** `al-orc stations show <id>` — one station's definition, optionally with recent work records. */
|
|
@@ -30,17 +29,14 @@ export async function showStationHandler(argv) {
|
|
|
30
29
|
const tags = station.tags?.map((t) => (typeof t === 'string' ? t : t.name)).join(', ');
|
|
31
30
|
if (tags) console.log(formatField('Tags', tags, lw));
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.join(', ');
|
|
42
|
-
}
|
|
43
|
-
console.log(formatField('Dependencies', deps, lw));
|
|
32
|
+
const from = station.conveyor?.from;
|
|
33
|
+
console.log(formatField('From', from ? [].concat(from).join(', ') : 'none', lw));
|
|
34
|
+
console.log(formatField('Enabled', station.is_enabled ? 'yes' : 'no', lw));
|
|
35
|
+
const schedule = station.schedule_cron
|
|
36
|
+
? `${station.schedule_cron} (${station.schedule_timezone || 'UTC'}), ${station.schedule_enabled ? 'on' : 'off'}`
|
|
37
|
+
: 'none';
|
|
38
|
+
console.log(formatField('Schedule', schedule, lw));
|
|
39
|
+
console.log(formatField('Auto-drain', (station.auto_drain_enabled ?? station.watch_enabled) ? 'on' : 'off', lw));
|
|
44
40
|
|
|
45
41
|
console.log(formatSection('Config'));
|
|
46
42
|
console.log(JSON.stringify(station.config ?? {}, null, 2));
|
package/src/resources/lines.js
CHANGED
|
@@ -23,10 +23,15 @@
|
|
|
23
23
|
* @property {(data: object) => Promise<Line|null>} create
|
|
24
24
|
* @property {(id: string, data: object) => Promise<Line|null>} update
|
|
25
25
|
* @property {(id: string) => Promise<any>} delete
|
|
26
|
+
* @property {(id: string) => Promise<Line|null>} archive
|
|
27
|
+
* @property {(id: string) => Promise<Line|null>} unarchive
|
|
26
28
|
*/
|
|
27
29
|
|
|
28
30
|
/** @param {any} r @returns {any} */
|
|
29
31
|
const unwrap = (r) => r?.data ?? null;
|
|
32
|
+
/** Unwrap a write's response, keeping the restart warnings the orchestrator sent with it.
|
|
33
|
+
* @param {any} r @returns {any} */
|
|
34
|
+
const unwrapWithWarnings = (r) => (r?.data && r.warnings ? { ...r.data, warnings: r.warnings } : unwrap(r));
|
|
30
35
|
/** @param {string} s */
|
|
31
36
|
const enc = (s) => encodeURIComponent(s);
|
|
32
37
|
|
|
@@ -49,7 +54,13 @@ export function buildLines(ctx) {
|
|
|
49
54
|
create: (data) => ctx.post('/api/v1/lines', data).then(unwrap),
|
|
50
55
|
|
|
51
56
|
/** Update line fields (PUT). Returns the updated record. */
|
|
52
|
-
update: (id, data) => ctx.put(`/api/v1/lines/${enc(id)}`, data).then(
|
|
57
|
+
update: (id, data) => ctx.put(`/api/v1/lines/${enc(id)}`, data).then(unwrapWithWarnings),
|
|
58
|
+
|
|
59
|
+
/** Archive a line. Refused by the server while a station on it is not archived. */
|
|
60
|
+
archive: (id) => ctx.post(`/api/v1/lines/${enc(id)}/archive`).then(unwrapWithWarnings),
|
|
61
|
+
|
|
62
|
+
/** Unarchive a line. Its stations stay archived. */
|
|
63
|
+
unarchive: (id) => ctx.post(`/api/v1/lines/${enc(id)}/unarchive`).then(unwrapWithWarnings),
|
|
53
64
|
|
|
54
65
|
/** Delete a line. Refused by the server while stations are still on it. */
|
|
55
66
|
delete: (id) => ctx.delete(`/api/v1/lines/${enc(id)}`).then(unwrap),
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Every route lives under `/api/v1/stations/*`.
|
|
6
6
|
*
|
|
7
|
-
* Return shapes: single-record ops return the unwrapped record
|
|
7
|
+
* Return shapes: single-record ops return the unwrapped record (a write adds the orchestrator's
|
|
8
|
+
* restart `warnings` when there are any); `list` returns
|
|
8
9
|
* the raw `{ data, page_context }` envelope; `getAll` returns a flat array.
|
|
9
10
|
*/
|
|
10
11
|
|
|
@@ -37,6 +38,11 @@
|
|
|
37
38
|
* @returns {any} */
|
|
38
39
|
const unwrap = (r) => r?.data ?? null;
|
|
39
40
|
|
|
41
|
+
/** Unwrap a write's response, keeping the restart warnings the orchestrator sent with it.
|
|
42
|
+
* @param {any} r
|
|
43
|
+
* @returns {any} */
|
|
44
|
+
const unwrapWithWarnings = (r) => (r?.data && r.warnings ? { ...r.data, warnings: r.warnings } : unwrap(r));
|
|
45
|
+
|
|
40
46
|
/** @param {string} s */
|
|
41
47
|
const enc = (s) => encodeURIComponent(s);
|
|
42
48
|
|
|
@@ -56,20 +62,20 @@ export function buildStations(ctx) {
|
|
|
56
62
|
get: (id) => ctx.get(`/api/v1/stations/${enc(id)}`).then(unwrap),
|
|
57
63
|
|
|
58
64
|
/** Create a station (`data` uses API field names). Returns the created record. */
|
|
59
|
-
create: (data) => ctx.post('/api/v1/stations', data).then(
|
|
65
|
+
create: (data) => ctx.post('/api/v1/stations', data).then(unwrapWithWarnings),
|
|
60
66
|
|
|
61
67
|
/** Update station fields (PUT). Returns the updated record. */
|
|
62
|
-
update: (id, data) => ctx.put(`/api/v1/stations/${enc(id)}`, data).then(
|
|
68
|
+
update: (id, data) => ctx.put(`/api/v1/stations/${enc(id)}`, data).then(unwrapWithWarnings),
|
|
63
69
|
|
|
64
70
|
/** Delete a station. Refused while it has work records, unless `cascade` (which deletes them too). */
|
|
65
71
|
delete: (id, { cascade } = {}) =>
|
|
66
72
|
ctx.delete(`/api/v1/stations/${enc(id)}`, cascade ? { searchParams: { cascade: true } } : undefined).then(unwrap),
|
|
67
73
|
|
|
68
74
|
/** Archive — preserves history, hides from default list, blocks execution. Canonical /stations/* surface. */
|
|
69
|
-
archive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/archive`).then(
|
|
75
|
+
archive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/archive`).then(unwrapWithWarnings),
|
|
70
76
|
|
|
71
77
|
/** Unarchive — undoes archive. */
|
|
72
|
-
unarchive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/unarchive`).then(
|
|
78
|
+
unarchive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/unarchive`).then(unwrapWithWarnings),
|
|
73
79
|
|
|
74
80
|
/**
|
|
75
81
|
* Trigger a station run. `overrides` are shallow-merged into the station's config
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* @property {LineStationRef[]} [stations] Live stations on the line (read-only, server-derived).
|
|
12
12
|
* @property {string} [created_at]
|
|
13
13
|
* @property {string|null} [archived_at]
|
|
14
|
+
* @property {string[]} [warnings] Restart warnings returned by a write.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -9,7 +9,14 @@
|
|
|
9
9
|
* @property {string} [description]
|
|
10
10
|
* @property {Record<string, any>} [config] The station's config, passed to its handler.
|
|
11
11
|
* @property {{ from: string | string[] } | null} [conveyor] Bins the factory session moves workpieces from into input/
|
|
12
|
-
* @property {
|
|
12
|
+
* @property {boolean} [is_enabled] Off: nothing runs, not even by hand.
|
|
13
|
+
* @property {string|null} [schedule_cron]
|
|
14
|
+
* @property {string|null} [schedule_timezone]
|
|
15
|
+
* @property {boolean} [schedule_enabled] Cron on or off.
|
|
16
|
+
* @property {boolean} [auto_drain_enabled] The factory session runs it whenever work is waiting (was watch_enabled).
|
|
17
|
+
* @property {boolean} [watch_enabled] The old name of auto_drain_enabled, returned until the orchestrator drops it.
|
|
18
|
+
* @property {(string|{ id: string, short_code?: string })[]} [dependencies] Being removed: order comes from conveyor.from.
|
|
19
|
+
* @property {string[]} [warnings] Restart warnings returned by a write.
|
|
13
20
|
* @property {(string|Tag)[]} [tags]
|
|
14
21
|
* @property {string} [applies_to]
|
|
15
22
|
* @property {boolean} [archived]
|