@zalosai/zalos-cli 0.2.21 → 0.2.23
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/PUBLISHING.md +9 -0
- package/README.md +36 -0
- package/dist/commands/workflow-schedule.js +216 -0
- package/dist/commands/workflow.js +28 -3
- package/package.json +1 -1
package/PUBLISHING.md
CHANGED
|
@@ -59,6 +59,15 @@ Do not publish with uncommitted package changes or reuse an existing version.
|
|
|
59
59
|
|
|
60
60
|
## Central developer access release
|
|
61
61
|
|
|
62
|
+
Version 0.2.23 adds explicit `--include-internal` reads for workflow setup and
|
|
63
|
+
scheduled tasks. Deploy the schedule-preview visibility option first. The
|
|
64
|
+
existing server-side team-owner check remains authoritative.
|
|
65
|
+
|
|
66
|
+
Version 0.2.22 adds `workflow activate` and `workflow schedule
|
|
67
|
+
list/upsert/remove/preview/run`. Deploy the schedule-preview API and scoped-token
|
|
68
|
+
route grants before publishing. Schedule tests use the CLI caller, not the
|
|
69
|
+
scheduler bot; saving task edits, publication and activation remain separate.
|
|
70
|
+
|
|
62
71
|
Version 0.2.21 adds `workflow view --published` and `workflow export --published`
|
|
63
72
|
for reading client-facing workflow definitions through the existing API. These
|
|
64
73
|
reads omit draft update checksums and reject protected workflows that resolve to
|
package/README.md
CHANGED
|
@@ -144,6 +144,42 @@ Workflow import/update/publish require `--apply`; without it they validate and p
|
|
|
144
144
|
from the signed-in human's team membership, role, and token scopes. Credential reads
|
|
145
145
|
return metadata only. No product command loads database credentials.
|
|
146
146
|
|
|
147
|
+
### Scheduled chat tasks
|
|
148
|
+
|
|
149
|
+
For internal workflows, team owners can add `--include-internal` to workflow
|
|
150
|
+
list/view/export and schedule commands. The default continues to hide internal
|
|
151
|
+
workflows, and the existing API owner check still applies.
|
|
152
|
+
|
|
153
|
+
Workers are workflows with one Chat Trigger. Manage their existing scheduled tasks
|
|
154
|
+
without exporting or replacing the full workflow graph:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
zl --environment staging workflow schedule list <id> --published
|
|
158
|
+
zl --environment staging workflow schedule upsert <id> --input task.json
|
|
159
|
+
zl --environment staging workflow schedule upsert <id> --input task.json --apply
|
|
160
|
+
zl --environment staging workflow schedule preview <id> <task-id> --count 3
|
|
161
|
+
zl --environment staging workflow publish <id> --apply
|
|
162
|
+
zl --environment staging workflow activate <id> --apply
|
|
163
|
+
zl --environment staging workflow schedule remove <id> <task-id> --apply
|
|
164
|
+
zl --environment staging workflow deactivate <id> --apply
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`task.json` contains one existing `scheduledChatTasks` entry, including its stable
|
|
168
|
+
`id`, `name`, `enabled`, `targetChatNodeId`, version-2 `schedule`, `openingRequest`,
|
|
169
|
+
and `inputs` bindings. Upsert and remove preserve other tasks/settings and use the
|
|
170
|
+
current workflow checksum. The API reuses the scheduler compiler and chat input
|
|
171
|
+
validation. Protected workflow edits require publication; activation is separate.
|
|
172
|
+
Deactivation pauses schedules without stopping existing chats.
|
|
173
|
+
|
|
174
|
+
Use `preview --published --at 2027-01-01T09:00:00Z` to evaluate inputs at an exact
|
|
175
|
+
occurrence; without `--at`, previews start at the next fire time. `--count` is 1–10.
|
|
176
|
+
`workflow schedule run <id> <task-id>` previews a manual test using published task
|
|
177
|
+
inputs evaluated at the current time (or `--at`). Add `--apply` to start it through
|
|
178
|
+
the normal workflow execution API. This runs as the CLI caller, **not the scheduler
|
|
179
|
+
bot**; it does not prove scheduled-identity access. Disabled tasks can be tested
|
|
180
|
+
without enabling them. No schedule command publishes, activates, or executes as a
|
|
181
|
+
side effect of editing. Unlike `workflow run`, schedule test runs require `--apply`.
|
|
182
|
+
|
|
147
183
|
### Workflow evaluations
|
|
148
184
|
|
|
149
185
|
Evaluation commands use the selected environment and profile's team. They require
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { client } from '../client.js';
|
|
3
|
+
import { ApiError, ValidationError } from '../utils/errors.js';
|
|
4
|
+
import { printJson } from '../utils/output.js';
|
|
5
|
+
import { action, dataRow, integer, isRow, resourceId } from '../utils/product-api.js';
|
|
6
|
+
import { parseJson } from '../utils/validate.js';
|
|
7
|
+
import { parseWorkflowFile } from '../workflow-file.js';
|
|
8
|
+
function path(id) {
|
|
9
|
+
return `/workflows/${resourceId(id)}`;
|
|
10
|
+
}
|
|
11
|
+
function readPath(id, options) {
|
|
12
|
+
const query = new URLSearchParams();
|
|
13
|
+
if (options.published)
|
|
14
|
+
query.set('resolvePublished', 'true');
|
|
15
|
+
if (options.includeInternal)
|
|
16
|
+
query.set('includeInternal', 'true');
|
|
17
|
+
return `${path(id)}${query.size ? `?${query}` : ''}`;
|
|
18
|
+
}
|
|
19
|
+
function taskId(id) {
|
|
20
|
+
if (id.length > 100)
|
|
21
|
+
throw new ValidationError('taskId', 'Task IDs must be 1–100 characters');
|
|
22
|
+
return resourceId(id);
|
|
23
|
+
}
|
|
24
|
+
function tasksFrom(workflow) {
|
|
25
|
+
const settings = workflow.settings;
|
|
26
|
+
if (settings !== undefined && !isRow(settings))
|
|
27
|
+
throw new ApiError(502, 'Invalid workflow settings');
|
|
28
|
+
const tasks = settings?.scheduledChatTasks ?? [];
|
|
29
|
+
if (!Array.isArray(tasks) || !tasks.every(isRow))
|
|
30
|
+
throw new ApiError(502, 'Invalid scheduled chat tasks');
|
|
31
|
+
return tasks;
|
|
32
|
+
}
|
|
33
|
+
async function preview(id, body) {
|
|
34
|
+
const result = dataRow(await client.post(`${path(id)}/schedule-preview`, body));
|
|
35
|
+
if (body.published && result.publishedVersionId && result.versionId !== result.publishedVersionId)
|
|
36
|
+
throw new ApiError(502, 'API did not resolve the published workflow; refusing draft fallback');
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function previewBody(options) {
|
|
40
|
+
if (options.at !== undefined &&
|
|
41
|
+
(!/^\d{4}-\d\d-\d\dT.*(?:Z|[+-]\d\d:\d\d)$/.test(options.at) ||
|
|
42
|
+
!Number.isFinite(Date.parse(options.at))))
|
|
43
|
+
throw new ValidationError('at', 'Use an ISO timestamp with an explicit timezone');
|
|
44
|
+
return {
|
|
45
|
+
published: options.published ?? false,
|
|
46
|
+
...(options.includeInternal ? { includeInternal: true } : {}),
|
|
47
|
+
count: integer(options.count, 3, 1, 10),
|
|
48
|
+
...(options.at ? { at: options.at } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export async function listWorkflowSchedulesAction(id, options) {
|
|
52
|
+
const workflow = dataRow(await client.get(readPath(id, options)));
|
|
53
|
+
if (options.published &&
|
|
54
|
+
workflow.publishedVersionId &&
|
|
55
|
+
workflow.versionId !== workflow.publishedVersionId)
|
|
56
|
+
throw new ApiError(502, 'API did not resolve the published workflow');
|
|
57
|
+
printJson({
|
|
58
|
+
workflowId: id,
|
|
59
|
+
active: workflow.active,
|
|
60
|
+
versionId: workflow.versionId,
|
|
61
|
+
publishedVersionId: workflow.publishedVersionId,
|
|
62
|
+
tasks: tasksFrom(workflow),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export async function previewWorkflowScheduleAction(id, selected, options) {
|
|
66
|
+
printJson(await preview(id, { ...previewBody(options), taskId: taskId(selected) }));
|
|
67
|
+
}
|
|
68
|
+
export async function editWorkflowScheduleAction(id, options) {
|
|
69
|
+
const endpoint = path(id);
|
|
70
|
+
let task;
|
|
71
|
+
if (options.input) {
|
|
72
|
+
const value = parseJson(await readFile(options.input, 'utf8'));
|
|
73
|
+
if (!isRow(value) || typeof value.id !== 'string')
|
|
74
|
+
throw new ValidationError('input', 'Provide one scheduled chat task with an id');
|
|
75
|
+
taskId(value.id);
|
|
76
|
+
task = value;
|
|
77
|
+
}
|
|
78
|
+
else if (options.remove)
|
|
79
|
+
taskId(options.remove);
|
|
80
|
+
else
|
|
81
|
+
throw new ValidationError('input', 'Provide a task file or a task ID to remove');
|
|
82
|
+
const workflow = dataRow(await client.get(readPath(id, options)));
|
|
83
|
+
// PUT is a full workflow replacement, not a settings patch. Validate the
|
|
84
|
+
// response graph and carry forward all editable fields before changing tasks.
|
|
85
|
+
parseWorkflowFile(JSON.stringify(workflow), id);
|
|
86
|
+
if (typeof workflow.checksum !== 'string' || !workflow.checksum.trim())
|
|
87
|
+
throw new ApiError(502, 'Workflow update checksum unavailable; refresh the API before editing');
|
|
88
|
+
const existing = tasksFrom(workflow);
|
|
89
|
+
const selected = task?.id ?? options.remove;
|
|
90
|
+
const index = existing.findIndex((entry) => entry.id === selected);
|
|
91
|
+
if (!task && index < 0)
|
|
92
|
+
throw new ValidationError('taskId', 'Scheduled chat task not found');
|
|
93
|
+
const tasks = existing.filter((entry) => entry.id !== selected);
|
|
94
|
+
if (task)
|
|
95
|
+
tasks.splice(index < 0 ? tasks.length : index, 0, task);
|
|
96
|
+
// The server reuses the scheduler compiler, expression evaluator and chat input validator.
|
|
97
|
+
await preview(id, {
|
|
98
|
+
tasks,
|
|
99
|
+
count: 1,
|
|
100
|
+
...(options.includeInternal ? { includeInternal: true } : {}),
|
|
101
|
+
});
|
|
102
|
+
const content = Object.fromEntries([
|
|
103
|
+
'name',
|
|
104
|
+
'description',
|
|
105
|
+
'nodes',
|
|
106
|
+
'connections',
|
|
107
|
+
'parentFolderId',
|
|
108
|
+
'pinData',
|
|
109
|
+
'timeSavedPerExecution',
|
|
110
|
+
'timeSavedPerMonth',
|
|
111
|
+
]
|
|
112
|
+
.filter((key) => Object.hasOwn(workflow, key))
|
|
113
|
+
.map((key) => [key, workflow[key]]));
|
|
114
|
+
const payload = {
|
|
115
|
+
...content,
|
|
116
|
+
settings: {
|
|
117
|
+
...workflow.settings,
|
|
118
|
+
scheduledChatTasks: tasks,
|
|
119
|
+
},
|
|
120
|
+
expectedChecksum: workflow.checksum,
|
|
121
|
+
};
|
|
122
|
+
if (!options.apply || options.dryRun) {
|
|
123
|
+
printJson({ dryRun: true, method: 'PUT', path: endpoint, payload });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const saved = dataRow(await client.put(endpoint, payload));
|
|
127
|
+
printJson({
|
|
128
|
+
workflowId: saved.id,
|
|
129
|
+
versionId: saved.versionId,
|
|
130
|
+
publishedVersionId: saved.publishedVersionId,
|
|
131
|
+
message: saved.publishedVersionId
|
|
132
|
+
? 'Saved schedule draft. Publish to update scheduled runs; activation is separate.'
|
|
133
|
+
: 'Saved current schedule settings on an unprotected workflow; activation is separate.',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
export async function runWorkflowScheduleAction(id, selected, options) {
|
|
137
|
+
const result = await preview(id, {
|
|
138
|
+
...previewBody({
|
|
139
|
+
published: true,
|
|
140
|
+
includeInternal: options.includeInternal,
|
|
141
|
+
at: options.at ?? new Date().toISOString(),
|
|
142
|
+
count: '1',
|
|
143
|
+
}),
|
|
144
|
+
taskId: taskId(selected),
|
|
145
|
+
});
|
|
146
|
+
const previews = result.previews;
|
|
147
|
+
const first = Array.isArray(previews) && isRow(previews[0]) ? previews[0] : undefined;
|
|
148
|
+
const occurrences = first?.occurrences;
|
|
149
|
+
const occurrence = Array.isArray(occurrences) && isRow(occurrences[0]) ? occurrences[0] : undefined;
|
|
150
|
+
if (!occurrence || !isRow(occurrence.triggerData) || typeof first?.startNodeName !== 'string')
|
|
151
|
+
throw new ApiError(502, 'Schedule preview did not return evaluated inputs');
|
|
152
|
+
const endpoint = `${path(id)}/run`;
|
|
153
|
+
const payload = {
|
|
154
|
+
triggerData: occurrence.triggerData,
|
|
155
|
+
triggerSource: 'chat',
|
|
156
|
+
startNodeName: first.startNodeName,
|
|
157
|
+
};
|
|
158
|
+
const identity = 'CLI caller (manual test), not the scheduled bot';
|
|
159
|
+
if (!options.apply || options.dryRun) {
|
|
160
|
+
printJson({
|
|
161
|
+
dryRun: true,
|
|
162
|
+
method: 'POST',
|
|
163
|
+
path: endpoint,
|
|
164
|
+
payload,
|
|
165
|
+
identity,
|
|
166
|
+
versionId: result.versionId,
|
|
167
|
+
scheduledFor: occurrence.scheduledFor,
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
// Use the existing launch endpoint and its execution permissions; never impersonate a bot.
|
|
172
|
+
printJson({
|
|
173
|
+
...dataRow(await client.post(endpoint, payload)),
|
|
174
|
+
identity,
|
|
175
|
+
scheduledFor: occurrence.scheduledFor,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
export function registerWorkflowScheduleCommand(workflow) {
|
|
179
|
+
const cmd = workflow
|
|
180
|
+
.command('schedule')
|
|
181
|
+
.description('Manage workflow-owned scheduled chat tasks');
|
|
182
|
+
cmd
|
|
183
|
+
.command('list <id>')
|
|
184
|
+
.option('--include-internal', 'Read internal workflow tasks (team owners only)')
|
|
185
|
+
.option('--published', 'Read published tasks')
|
|
186
|
+
.action(async (id, o) => action(() => listWorkflowSchedulesAction(id, o)));
|
|
187
|
+
cmd
|
|
188
|
+
.command('upsert <id>')
|
|
189
|
+
.option('--include-internal', 'Edit internal workflow tasks (team owners only)')
|
|
190
|
+
.requiredOption('--input <file>', 'One scheduled chat task as JSON')
|
|
191
|
+
.option('--apply', 'Save schedule draft')
|
|
192
|
+
.option('--dry-run', 'Validate and preview only')
|
|
193
|
+
.action(async (id, o) => action(() => editWorkflowScheduleAction(id, o)));
|
|
194
|
+
cmd
|
|
195
|
+
.command('remove <id> <task-id>')
|
|
196
|
+
.option('--include-internal', 'Edit internal workflow tasks (team owners only)')
|
|
197
|
+
.option('--apply', 'Remove task from draft')
|
|
198
|
+
.option('--dry-run', 'Preview removal')
|
|
199
|
+
.action(async (id, selected, o) => action(() => editWorkflowScheduleAction(id, { ...o, remove: selected })));
|
|
200
|
+
cmd
|
|
201
|
+
.command('preview <id> <task-id>')
|
|
202
|
+
.option('--include-internal', 'Preview internal workflow tasks (team owners only)')
|
|
203
|
+
.option('--published', 'Preview published tasks')
|
|
204
|
+
.option('--at <timestamp>', 'Evaluate first occurrence at this ISO timestamp; otherwise use next fire time')
|
|
205
|
+
.option('--count <n>', 'Number of occurrences (1–10)', '3')
|
|
206
|
+
.action(async (id, selected, o) => action(() => previewWorkflowScheduleAction(id, selected, o)));
|
|
207
|
+
cmd
|
|
208
|
+
.command('run <id> <task-id>')
|
|
209
|
+
.option('--include-internal', 'Read the internal task definition (team owners only)')
|
|
210
|
+
.description('Test published task inputs as the CLI caller; does not test scheduler bot identity')
|
|
211
|
+
.option('--at <timestamp>', 'Evaluate inputs at this ISO timestamp (default now)')
|
|
212
|
+
.option('--apply', 'Start a real execution')
|
|
213
|
+
.option('--dry-run', 'Preview evaluated inputs only')
|
|
214
|
+
.action(async (id, selected, o) => action(() => runWorkflowScheduleAction(id, selected, o)));
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=workflow-schedule.js.map
|
|
@@ -6,9 +6,15 @@ import { ApiError, ValidationError } from '../utils/errors.js';
|
|
|
6
6
|
import { filterSingle, printJson } from '../utils/output.js';
|
|
7
7
|
import { action, dataRow, dataRows, fields, isRow, printPage, resourceId, } from '../utils/product-api.js';
|
|
8
8
|
import { parseJson } from '../utils/validate.js';
|
|
9
|
+
import { registerWorkflowScheduleCommand } from './workflow-schedule.js';
|
|
9
10
|
import { registerWorkflowEvalCommand } from './workflow-eval.js';
|
|
10
11
|
async function readWorkflow(id, options) {
|
|
11
|
-
const
|
|
12
|
+
const query = new URLSearchParams();
|
|
13
|
+
if (options.published)
|
|
14
|
+
query.set('resolvePublished', 'true');
|
|
15
|
+
if (options.includeInternal)
|
|
16
|
+
query.set('includeInternal', 'true');
|
|
17
|
+
const workflow = dataRow(await client.get(`/workflows/${resourceId(id)}${query.size ? `?${query}` : ''}`));
|
|
12
18
|
if (!options.published)
|
|
13
19
|
return workflow;
|
|
14
20
|
if (workflow.publishedVersionId && workflow.versionId !== workflow.publishedVersionId) {
|
|
@@ -56,7 +62,9 @@ function warnIfWorkflowDraftIsUnpublished(workflow) {
|
|
|
56
62
|
})}\n`);
|
|
57
63
|
}
|
|
58
64
|
export async function listWorkflowsAction(options) {
|
|
59
|
-
const path = options.allTeams
|
|
65
|
+
const path = options.allTeams
|
|
66
|
+
? '/developer/workflows'
|
|
67
|
+
: `/workflows${options.includeInternal ? '?includeInternal=true' : ''}`;
|
|
60
68
|
printPage(dataRows(await client.get(path)), options);
|
|
61
69
|
}
|
|
62
70
|
export async function viewWorkflowAction(id, options) {
|
|
@@ -87,7 +95,7 @@ export async function exportWorkflowAction(id, options) {
|
|
|
87
95
|
else {
|
|
88
96
|
ids = id
|
|
89
97
|
? [id]
|
|
90
|
-
: dataRows(await client.get(
|
|
98
|
+
: dataRows(await client.get(`/workflows${options.includeInternal ? '?includeInternal=true' : ''}`)).map((row) => {
|
|
91
99
|
if (typeof row.id !== 'string')
|
|
92
100
|
throw new ValidationError('id', 'Workflow response is missing ID');
|
|
93
101
|
return resourceId(row.id);
|
|
@@ -173,6 +181,14 @@ export async function publishWorkflowAction(id, options) {
|
|
|
173
181
|
const published = dataRow(await client.post(path));
|
|
174
182
|
printJson({ workflow: published, publication: publicationStatus(published, true) });
|
|
175
183
|
}
|
|
184
|
+
export async function activateWorkflowAction(id, options) {
|
|
185
|
+
const path = `/workflows/${resourceId(id)}/activate`;
|
|
186
|
+
if (!options.apply || options.dryRun) {
|
|
187
|
+
printJson({ dryRun: true, method: 'PATCH', path });
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
printJson(dataRow(await client.patch(path, {})));
|
|
191
|
+
}
|
|
176
192
|
export async function deactivateWorkflowAction(id, options) {
|
|
177
193
|
const path = `/workflows/${resourceId(id)}/deactivate`;
|
|
178
194
|
if (!options.apply || options.dryRun) {
|
|
@@ -206,18 +222,22 @@ export async function runWorkflowAction(id, options) {
|
|
|
206
222
|
export function registerWorkflowCommand(program) {
|
|
207
223
|
const cmd = program.command('workflow').description('Manage workflows through the regional API');
|
|
208
224
|
registerWorkflowEvalCommand(cmd, program);
|
|
225
|
+
registerWorkflowScheduleCommand(cmd);
|
|
209
226
|
cmd
|
|
210
227
|
.command('list')
|
|
228
|
+
.option('--include-internal', 'Include internal workflows (team owners only)')
|
|
211
229
|
.option('--all-teams', 'List workflows across every team in the selected region')
|
|
212
230
|
.option('--limit <n>', 'Maximum results', '100')
|
|
213
231
|
.option('--offset <n>', 'Result offset', '0')
|
|
214
232
|
.action(async (o) => action(() => listWorkflowsAction({ ...o, ...fields(program) })));
|
|
215
233
|
cmd
|
|
216
234
|
.command('view <id>')
|
|
235
|
+
.option('--include-internal', 'Read an internal workflow (team owners only)')
|
|
217
236
|
.option('--published', 'Read the definition clients run (current when unprotected)')
|
|
218
237
|
.action(async (id, o) => action(() => viewWorkflowAction(id, { ...o, ...fields(program) })));
|
|
219
238
|
cmd
|
|
220
239
|
.command('export [id]')
|
|
240
|
+
.option('--include-internal', 'Export internal workflows (team owners only)')
|
|
221
241
|
.option('--all', 'Export every accessible workflow')
|
|
222
242
|
.option('--all-teams', 'Export workflows across every team in the selected region')
|
|
223
243
|
.option('--published', 'Export the definition clients run (current when unprotected); omits update checksum')
|
|
@@ -244,6 +264,11 @@ export function registerWorkflowCommand(program) {
|
|
|
244
264
|
.option('--apply', 'Publish workflow')
|
|
245
265
|
.option('--dry-run', 'Preview publish')
|
|
246
266
|
.action(async (id, o) => action(() => publishWorkflowAction(id, o)));
|
|
267
|
+
cmd
|
|
268
|
+
.command('activate <id>')
|
|
269
|
+
.option('--apply', 'Activate published workflow schedules')
|
|
270
|
+
.option('--dry-run', 'Preview activation')
|
|
271
|
+
.action(async (id, o) => action(() => activateWorkflowAction(id, o)));
|
|
247
272
|
cmd
|
|
248
273
|
.command('deactivate <id>')
|
|
249
274
|
.option('--apply', 'Deactivate workflow')
|