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