maoda-commander-tt 0.0.17 → 0.0.18

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/main.js CHANGED
@@ -3662,6 +3662,132 @@ function inferVideoExtension(remoteUrl, response) {
3662
3662
  return "mp4";
3663
3663
  }
3664
3664
 
3665
+ // src/commands/ai/ai-querytask-command.ts
3666
+ import { spawn as spawn3 } from "child_process";
3667
+ var BIN = "xx";
3668
+ var PPE_ENV = "ppe_new_login_cli";
3669
+ var POLL_INTERVAL_MS2 = 5e3;
3670
+ var POLL_TIMEOUT_MS2 = 10 * 60 * 1e3;
3671
+ var RUNNING_STATUS = "running";
3672
+ var AiQueryTaskCommand = class extends AiBaseCommand {
3673
+ _meta() {
3674
+ return {
3675
+ name: "querytask",
3676
+ description: "\u8F6E\u8BE2 xx query-video-direct \u4EFB\u52A1\u7ED3\u679C\uFF0Crunning \u65F6\u81EA\u52A8\u91CD\u8BD5\u76F4\u81F3\u5B8C\u6210\u6216\u8D85\u65F6"
3677
+ };
3678
+ }
3679
+ _configureArguments(cmd) {
3680
+ cmd.argument("<task_id>", "\u8981\u67E5\u8BE2\u7684\u4EFB\u52A1 ID");
3681
+ }
3682
+ async _execute(ctx) {
3683
+ const taskId = String(ctx.args[0] ?? "").trim();
3684
+ if (!taskId) {
3685
+ return this._makeError(1, "\u8BF7\u4F20\u5165 task_id");
3686
+ }
3687
+ const startedAt = Date.now();
3688
+ while (true) {
3689
+ const queryResult = await this._runQuery(taskId);
3690
+ if (!queryResult.ok) {
3691
+ return this._makeError(queryResult.code, queryResult.msg);
3692
+ }
3693
+ const { stdout, stderr } = queryResult.value;
3694
+ const status = extractStatus(stdout);
3695
+ if (status !== RUNNING_STATUS) {
3696
+ if (stderr.trim().length > 0) {
3697
+ process.stderr.write(stderr);
3698
+ }
3699
+ process.stdout.write(stdout.endsWith("\n") ? stdout : `${stdout}
3700
+ `);
3701
+ return this._makeOk();
3702
+ }
3703
+ const elapsed = Date.now() - startedAt;
3704
+ if (elapsed + POLL_INTERVAL_MS2 >= POLL_TIMEOUT_MS2) {
3705
+ return this._makeError(
3706
+ 1,
3707
+ `\u8F6E\u8BE2\u8D85\u65F6 ${Math.round(POLL_TIMEOUT_MS2 / 1e3)}s\uFF0C\u4EFB\u52A1 ${taskId} \u4ECD\u4E3A ${RUNNING_STATUS} \u72B6\u6001`
3708
+ );
3709
+ }
3710
+ await delay2(POLL_INTERVAL_MS2);
3711
+ }
3712
+ }
3713
+ _runQuery(taskId) {
3714
+ const args = [
3715
+ "query-video-direct",
3716
+ "--task-id",
3717
+ taskId,
3718
+ "--ppe-env",
3719
+ PPE_ENV,
3720
+ "--json"
3721
+ ];
3722
+ return new Promise((resolve8) => {
3723
+ const child = spawn3(BIN, args, { cwd: process.cwd() });
3724
+ let stdout = "";
3725
+ let stderr = "";
3726
+ child.stdout.on("data", (chunk) => {
3727
+ stdout += chunk.toString();
3728
+ });
3729
+ child.stderr.on("data", (chunk) => {
3730
+ stderr += chunk.toString();
3731
+ });
3732
+ child.on("error", (error) => {
3733
+ resolve8(
3734
+ makeError(
3735
+ 1,
3736
+ `\u6267\u884C ${BIN} ${args.join(" ")} \u5931\u8D25: ${error.message}`
3737
+ )
3738
+ );
3739
+ });
3740
+ child.on("close", (code, signal) => {
3741
+ if (code === 0) {
3742
+ resolve8(makeOkWith({ stdout, stderr }));
3743
+ return;
3744
+ }
3745
+ const signalText = signal ? `, signal: ${signal}` : "";
3746
+ const stderrText = stderr.trim() ? `
3747
+ ${stderr.trim()}` : "";
3748
+ resolve8(
3749
+ makeError(
3750
+ code ?? 1,
3751
+ `\u6267\u884C ${BIN} ${args.join(" ")} \u5931\u8D25${signalText}${stderrText}`
3752
+ )
3753
+ );
3754
+ });
3755
+ });
3756
+ }
3757
+ };
3758
+ function extractStatus(stdout) {
3759
+ const trimmed = stdout.trim();
3760
+ if (!trimmed) {
3761
+ return void 0;
3762
+ }
3763
+ const parsed = tryParseJson(trimmed);
3764
+ if (!parsed || typeof parsed !== "object") {
3765
+ return void 0;
3766
+ }
3767
+ const record = parsed;
3768
+ if (typeof record.status === "string" && record.status.trim()) {
3769
+ return record.status.trim();
3770
+ }
3771
+ const data = record.data;
3772
+ if (data && typeof data === "object") {
3773
+ const dataRecord = data;
3774
+ if (typeof dataRecord.status === "string" && dataRecord.status.trim()) {
3775
+ return dataRecord.status.trim();
3776
+ }
3777
+ }
3778
+ return void 0;
3779
+ }
3780
+ function tryParseJson(text) {
3781
+ try {
3782
+ return JSON.parse(text);
3783
+ } catch {
3784
+ return void 0;
3785
+ }
3786
+ }
3787
+ function delay2(ms) {
3788
+ return new Promise((resolve8) => setTimeout(resolve8, ms));
3789
+ }
3790
+
3665
3791
  // src/commands/ai/ai-command.ts
3666
3792
  var AiCommand = class extends BaseSubcommandHost {
3667
3793
  _meta() {
@@ -3678,6 +3804,7 @@ var AiCommand = class extends BaseSubcommandHost {
3678
3804
  this._addSubcommand(new AiImageCommand());
3679
3805
  this._addSubcommand(new AiVideoCommand());
3680
3806
  this._addSubcommand(new AiVidCommand());
3807
+ this._addSubcommand(new AiQueryTaskCommand());
3681
3808
  }
3682
3809
  };
3683
3810