@workflow-code/cli 0.1.1 → 0.1.3
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/dist/chunk-ONAQ5F5R.js +10822 -0
- package/dist/index.js +13 -22
- package/dist/{local-XBULJ25O.js → local-ZIUEP53J.js} +46 -33
- package/dist/workspace-MLJHPOLS.js +2501 -0
- package/package.json +2 -1
- package/dist/workspace-WJOCEGA6.js +0 -1044
package/dist/index.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
i18n,
|
|
4
|
+
prepareCliInvocation,
|
|
5
|
+
translateWorkflowCodeError
|
|
6
|
+
} from "./chunk-ONAQ5F5R.js";
|
|
2
7
|
|
|
3
8
|
// src/index.ts
|
|
4
9
|
import path from "path";
|
|
5
10
|
import { pathToFileURL } from "url";
|
|
6
11
|
async function main(argv = process.argv.slice(2)) {
|
|
12
|
+
const prepared = prepareCliInvocation(argv);
|
|
13
|
+
argv = prepared.argv;
|
|
7
14
|
if (argv[0] === "workspace") {
|
|
8
|
-
const workspaceCli = await import("./workspace-
|
|
9
|
-
await workspaceCli.main(argv.slice(1));
|
|
15
|
+
const workspaceCli = await import("./workspace-MLJHPOLS.js");
|
|
16
|
+
await workspaceCli.main(argv.slice(1), { localeInitialized: true });
|
|
10
17
|
return typeof process.exitCode === "number" ? process.exitCode : 0;
|
|
11
18
|
}
|
|
12
19
|
if (argv.length === 0 || argv[0] === "help" || argv[0] === "--help" || argv[0] === "-h") {
|
|
@@ -16,33 +23,17 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
16
23
|
}
|
|
17
24
|
const { register } = await import("tsx/esm/api");
|
|
18
25
|
register();
|
|
19
|
-
const localCli = await import("./local-
|
|
20
|
-
return localCli.main(argv);
|
|
26
|
+
const localCli = await import("./local-ZIUEP53J.js");
|
|
27
|
+
return localCli.main(argv, { localeInitialized: true });
|
|
21
28
|
}
|
|
22
29
|
function formatHelp() {
|
|
23
|
-
return
|
|
24
|
-
"Usage:",
|
|
25
|
-
" workflow-code <run|json|structure|resolve-params> [workflow-dir] [args]",
|
|
26
|
-
" workflow-code workspace <command> [args]",
|
|
27
|
-
"",
|
|
28
|
-
"Local commands:",
|
|
29
|
-
" run Run a workflow locally",
|
|
30
|
-
" json Run locally and print the JSON report",
|
|
31
|
-
" structure Inspect workflow structure",
|
|
32
|
-
" resolve-params Resolve dynamic workflow parameters",
|
|
33
|
-
"",
|
|
34
|
-
"Workspace commands:",
|
|
35
|
-
" login, logout, status, health, pack, upload, preparation,",
|
|
36
|
-
" download, publish, run, debug-node, versions",
|
|
37
|
-
"",
|
|
38
|
-
"Run `workflow-code workspace --help` for workspace command details."
|
|
39
|
-
].join("\n");
|
|
30
|
+
return i18n.t("rootHelp", { ns: "cli" });
|
|
40
31
|
}
|
|
41
32
|
if (process.argv[1] !== void 0 && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
|
|
42
33
|
main().then((exitCode) => {
|
|
43
34
|
process.exitCode = exitCode;
|
|
44
35
|
}).catch((error) => {
|
|
45
|
-
console.error(
|
|
36
|
+
console.error(translateWorkflowCodeError(error));
|
|
46
37
|
process.exitCode = 1;
|
|
47
38
|
});
|
|
48
39
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
i18n,
|
|
4
|
+
prepareCliInvocation,
|
|
5
|
+
translateWorkflowCodeError
|
|
6
|
+
} from "./chunk-ONAQ5F5R.js";
|
|
2
7
|
|
|
3
8
|
// src/local.ts
|
|
4
9
|
import path from "path";
|
|
@@ -15,9 +20,13 @@ import {
|
|
|
15
20
|
} from "workflow-code";
|
|
16
21
|
var WORKFLOW_APP_RUNTIME_EVENTS_ENV = "WORKFLOW_APP_RUNTIME_EVENTS";
|
|
17
22
|
var WORKFLOW_APP_RUNTIME_EVENT_PREFIX = "__WORKFLOW_CODE_RUNTIME_EVENT__";
|
|
23
|
+
var WORKFLOW_PARAM_ERROR_MARKER = "__WORKFLOW_CODE_PARAM_ERROR__";
|
|
18
24
|
var RESUME_RUNTIME_EVENT_AFTER_REQUEST_ID = "__workflowResumeRuntimeEventAfterRequestId";
|
|
19
|
-
async function main(argv = process.argv.slice(2)) {
|
|
25
|
+
async function main(argv = process.argv.slice(2), options = {}) {
|
|
20
26
|
disableAiSdkWarningLogs();
|
|
27
|
+
if (options.localeInitialized !== true) {
|
|
28
|
+
argv = prepareCliInvocation(argv).argv;
|
|
29
|
+
}
|
|
21
30
|
const abortController = createProcessAbortController();
|
|
22
31
|
const command = parseCommand(argv[0]);
|
|
23
32
|
const args = command === "help" ? argv.slice(1) : argv.slice(1);
|
|
@@ -36,6 +45,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
36
45
|
});
|
|
37
46
|
const report = await runLocalWorkflowWithReport({
|
|
38
47
|
workflowDir: parsed.workflowDir,
|
|
48
|
+
entrypointId: parsed.entrypointId,
|
|
39
49
|
args: parsed.args,
|
|
40
50
|
runId: parsed.runId,
|
|
41
51
|
conversationId: parsed.conversationId,
|
|
@@ -81,29 +91,39 @@ function parseCommand(value) {
|
|
|
81
91
|
if (value === "run" || value === "json" || value === "structure" || value === "resolve-params") {
|
|
82
92
|
return value;
|
|
83
93
|
}
|
|
84
|
-
throw new Error(
|
|
94
|
+
throw new Error(i18n.t("unknownLocalCommand", { ns: "cli", command: value }));
|
|
85
95
|
}
|
|
86
96
|
async function runResolveParamsCommand(argv, abortSignal) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
try {
|
|
98
|
+
const parsed = parseWorkflowArgs(argv, { json: true });
|
|
99
|
+
const request = parseParamResolveRequest(readFileSync(0, "utf8"));
|
|
100
|
+
const result = await resolveLocalWorkflowParams({
|
|
101
|
+
workflowDir: parsed.workflowDir,
|
|
102
|
+
entrypointId: parsed.entrypointId,
|
|
103
|
+
request,
|
|
104
|
+
abortSignal
|
|
105
|
+
});
|
|
106
|
+
console.log(JSON.stringify(result));
|
|
107
|
+
return 0;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(formatParamResolverFailure(error));
|
|
110
|
+
return 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function formatParamResolverFailure(error) {
|
|
114
|
+
return `${WORKFLOW_PARAM_ERROR_MARKER}${JSON.stringify(createWorkflowFailure(error).error)}`;
|
|
96
115
|
}
|
|
97
116
|
function parseParamResolveRequest(value) {
|
|
98
117
|
const parsed = JSON.parse(value);
|
|
99
118
|
if (typeof parsed !== "object" || parsed === null || typeof parsed.draftText !== "string" || !Array.isArray(parsed.args) || !parsed.args.every((arg) => typeof arg === "string") || parsed.inputMode !== "form" && parsed.inputMode !== "raw" || typeof parsed.trigger !== "object" || parsed.trigger === null || parsed.trigger.kind !== "init" && parsed.trigger.kind !== "input" && parsed.trigger.kind !== "param" || parsed.trigger.kind === "param" && typeof parsed.trigger.paramName !== "string") {
|
|
100
|
-
throw new Error("
|
|
119
|
+
throw new Error(i18n.t("invalidParamResolveRequest", { ns: "cli" }));
|
|
101
120
|
}
|
|
102
121
|
return parsed;
|
|
103
122
|
}
|
|
104
123
|
function parseWorkflowArgs(argv, options) {
|
|
105
124
|
let json = options.json;
|
|
106
125
|
let runId;
|
|
126
|
+
let entrypointId;
|
|
107
127
|
let conversationId;
|
|
108
128
|
let fileStoreDir;
|
|
109
129
|
let resolvedUserInputs = [];
|
|
@@ -127,6 +147,10 @@ function parseWorkflowArgs(argv, options) {
|
|
|
127
147
|
runId = readWorkflowArgValue(argv, ++index, "--run-id");
|
|
128
148
|
continue;
|
|
129
149
|
}
|
|
150
|
+
if (arg === "--entrypoint") {
|
|
151
|
+
entrypointId = readWorkflowArgValue(argv, ++index, "--entrypoint");
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
130
154
|
if (arg === "--file-store-dir") {
|
|
131
155
|
fileStoreDir = readWorkflowArgValue(argv, ++index, "--file-store-dir");
|
|
132
156
|
continue;
|
|
@@ -152,6 +176,7 @@ function parseWorkflowArgs(argv, options) {
|
|
|
152
176
|
args: removePnpmRunSeparator(rest),
|
|
153
177
|
json,
|
|
154
178
|
runId,
|
|
179
|
+
entrypointId,
|
|
155
180
|
conversationId,
|
|
156
181
|
fileStoreDir,
|
|
157
182
|
resolvedUserInputs,
|
|
@@ -163,6 +188,7 @@ function parseWorkflowArgs(argv, options) {
|
|
|
163
188
|
args: removePnpmRunSeparator(filteredArgv),
|
|
164
189
|
json,
|
|
165
190
|
runId,
|
|
191
|
+
entrypointId,
|
|
166
192
|
conversationId,
|
|
167
193
|
fileStoreDir,
|
|
168
194
|
resolvedUserInputs,
|
|
@@ -177,7 +203,7 @@ function createCliUserInputContext(resolvedInputs) {
|
|
|
177
203
|
},
|
|
178
204
|
requestInput() {
|
|
179
205
|
throw new Error(
|
|
180
|
-
"
|
|
206
|
+
i18n.t("waitingForUserInput", { ns: "cli" })
|
|
181
207
|
);
|
|
182
208
|
}
|
|
183
209
|
};
|
|
@@ -185,11 +211,11 @@ function createCliUserInputContext(resolvedInputs) {
|
|
|
185
211
|
function parseResolvedUserInputs(value) {
|
|
186
212
|
const parsed = JSON.parse(value);
|
|
187
213
|
if (!Array.isArray(parsed)) {
|
|
188
|
-
throw new Error("
|
|
214
|
+
throw new Error(i18n.t("resolvedInputsMustBeArray", { ns: "cli" }));
|
|
189
215
|
}
|
|
190
216
|
return parsed.map((item) => {
|
|
191
217
|
if (typeof item !== "object" || item === null || typeof item.requestId !== "string" || typeof item.nodeName !== "string" || typeof item.values !== "object" || item.values === null || typeof item.submittedAt !== "string") {
|
|
192
|
-
throw new Error("
|
|
218
|
+
throw new Error(i18n.t("invalidResolvedInput", { ns: "cli" }));
|
|
193
219
|
}
|
|
194
220
|
return {
|
|
195
221
|
requestId: item.requestId,
|
|
@@ -237,7 +263,7 @@ function createRuntimeEventJsonReplacer() {
|
|
|
237
263
|
function readWorkflowArgValue(argv, index, name) {
|
|
238
264
|
const value = argv[index];
|
|
239
265
|
if (value === void 0) {
|
|
240
|
-
throw new Error(
|
|
266
|
+
throw new Error(i18n.t("missingOptionValue", { ns: "cli", name }));
|
|
241
267
|
}
|
|
242
268
|
return value;
|
|
243
269
|
}
|
|
@@ -300,22 +326,7 @@ function formatWorkflowStructureError(error) {
|
|
|
300
326
|
);
|
|
301
327
|
}
|
|
302
328
|
function formatHelp() {
|
|
303
|
-
return
|
|
304
|
-
"Usage:",
|
|
305
|
-
" workflow-code run [workflow-dir] [--] [...args]",
|
|
306
|
-
" workflow-code json [workflow-dir] [--] [...args]",
|
|
307
|
-
" workflow-code json [workflow-dir] --conversation-id <id> [--] [...args]",
|
|
308
|
-
" workflow-code structure [workflow-dir]",
|
|
309
|
-
" workflow-code resolve-params [workflow-dir] < request.json",
|
|
310
|
-
"",
|
|
311
|
-
"Examples:",
|
|
312
|
-
" workflow-code run .",
|
|
313
|
-
" workflow-code run . -- --target aliyun --dry-run",
|
|
314
|
-
" workflow-code json . -- --target aliyun --dry-run",
|
|
315
|
-
" workflow-code json . --run-id <id> --resolved-user-inputs-json <json> -- [...args]",
|
|
316
|
-
" workflow-code structure .",
|
|
317
|
-
" workflow-code resolve-params . < request.json"
|
|
318
|
-
].join("\n");
|
|
329
|
+
return i18n.t("localHelp", { ns: "cli" });
|
|
319
330
|
}
|
|
320
331
|
function disableAiSdkWarningLogs() {
|
|
321
332
|
globalThis.AI_SDK_LOG_WARNINGS = false;
|
|
@@ -324,7 +335,7 @@ if (isCliEntrypoint()) {
|
|
|
324
335
|
main().then((exitCode) => {
|
|
325
336
|
process.exitCode = exitCode;
|
|
326
337
|
}).catch((error) => {
|
|
327
|
-
console.error(
|
|
338
|
+
console.error(translateWorkflowCodeError(error));
|
|
328
339
|
process.exitCode = 1;
|
|
329
340
|
});
|
|
330
341
|
}
|
|
@@ -332,6 +343,8 @@ function isCliEntrypoint() {
|
|
|
332
343
|
return process.argv[1] !== void 0 && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href;
|
|
333
344
|
}
|
|
334
345
|
export {
|
|
346
|
+
WORKFLOW_PARAM_ERROR_MARKER,
|
|
347
|
+
formatParamResolverFailure,
|
|
335
348
|
main,
|
|
336
349
|
parseWorkflowArgs
|
|
337
350
|
};
|