maoda-commander-tt 0.0.24 → 0.0.26
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 +97 -134
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2609,9 +2609,72 @@ import { spawn as spawn3 } from "child_process";
|
|
|
2609
2609
|
import * as fs5 from "fs/promises";
|
|
2610
2610
|
import { homedir as homedir7 } from "os";
|
|
2611
2611
|
import * as path6 from "path";
|
|
2612
|
-
|
|
2612
|
+
|
|
2613
|
+
// src/bedrock/uuid/uuid.ts
|
|
2614
|
+
var generateUuid = (() => {
|
|
2615
|
+
if (typeof crypto === "object" && typeof crypto.randomUUID === "function") {
|
|
2616
|
+
return crypto.randomUUID.bind(crypto);
|
|
2617
|
+
}
|
|
2618
|
+
let getRandomValues;
|
|
2619
|
+
if (typeof crypto === "object" && typeof crypto.getRandomValues === "function") {
|
|
2620
|
+
getRandomValues = crypto.getRandomValues.bind(crypto);
|
|
2621
|
+
} else {
|
|
2622
|
+
getRandomValues = function(bucket) {
|
|
2623
|
+
for (let i = 0; i < bucket.length; i++) {
|
|
2624
|
+
bucket[i] = Math.floor(Math.random() * 256);
|
|
2625
|
+
}
|
|
2626
|
+
return bucket;
|
|
2627
|
+
};
|
|
2628
|
+
}
|
|
2629
|
+
const data = new Uint8Array(16);
|
|
2630
|
+
const hex = [];
|
|
2631
|
+
for (let i = 0; i < 256; i++) {
|
|
2632
|
+
hex.push(i.toString(16).padStart(2, "0"));
|
|
2633
|
+
}
|
|
2634
|
+
return () => {
|
|
2635
|
+
getRandomValues(data);
|
|
2636
|
+
data[6] = data[6] & 15 | 64;
|
|
2637
|
+
data[8] = data[8] & 63 | 128;
|
|
2638
|
+
let i = 0;
|
|
2639
|
+
let result = "";
|
|
2640
|
+
result += hex[data[i++]];
|
|
2641
|
+
result += hex[data[i++]];
|
|
2642
|
+
result += hex[data[i++]];
|
|
2643
|
+
result += hex[data[i++]];
|
|
2644
|
+
result += "-";
|
|
2645
|
+
result += hex[data[i++]];
|
|
2646
|
+
result += hex[data[i++]];
|
|
2647
|
+
result += "-";
|
|
2648
|
+
result += hex[data[i++]];
|
|
2649
|
+
result += hex[data[i++]];
|
|
2650
|
+
result += "-";
|
|
2651
|
+
result += hex[data[i++]];
|
|
2652
|
+
result += hex[data[i++]];
|
|
2653
|
+
result += "-";
|
|
2654
|
+
result += hex[data[i++]];
|
|
2655
|
+
result += hex[data[i++]];
|
|
2656
|
+
result += hex[data[i++]];
|
|
2657
|
+
result += hex[data[i++]];
|
|
2658
|
+
result += hex[data[i++]];
|
|
2659
|
+
result += hex[data[i++]];
|
|
2660
|
+
return result;
|
|
2661
|
+
};
|
|
2662
|
+
})();
|
|
2663
|
+
|
|
2664
|
+
// src/commands/ai/ai-image-command-v2.ts
|
|
2665
|
+
var GENERATED_IMAGES_SUBDIR = "generated_imgs";
|
|
2666
|
+
var GENERATED_IMAGES_DIR = path6.join(
|
|
2667
|
+
homedir7(),
|
|
2668
|
+
".codex",
|
|
2669
|
+
GENERATED_IMAGES_SUBDIR
|
|
2670
|
+
);
|
|
2671
|
+
var GENERATED_IMAGES_PROMPT_DIR = `~/.codex/${GENERATED_IMAGES_SUBDIR}`;
|
|
2672
|
+
var LEGACY_GENERATED_IMAGES_DIR = path6.join(
|
|
2673
|
+
homedir7(),
|
|
2674
|
+
".codex",
|
|
2675
|
+
"generated_images"
|
|
2676
|
+
);
|
|
2613
2677
|
var CODEX_EMPTY_WORKDIR = path6.join(homedir7(), ".codex-empty");
|
|
2614
|
-
var CREATED_AT_TOLERANCE_MS = 1e3;
|
|
2615
2678
|
var AiImageCommandV2 = class extends AiBaseCommand {
|
|
2616
2679
|
_meta() {
|
|
2617
2680
|
return {
|
|
@@ -2631,13 +2694,14 @@ var AiImageCommandV2 = class extends AiBaseCommand {
|
|
|
2631
2694
|
this._outputJsonError(1, "\u8BF7\u8F93\u5165\u751F\u56FE\u63D0\u793A\u8BCD");
|
|
2632
2695
|
return this._makeOk();
|
|
2633
2696
|
}
|
|
2634
|
-
const
|
|
2635
|
-
const
|
|
2697
|
+
const uuid = generateUuid();
|
|
2698
|
+
const imagePath = getGeneratedImagePath(uuid);
|
|
2699
|
+
const runResult = await this._runCodexImagePrompt(prompt, uuid);
|
|
2636
2700
|
if (!runResult.ok) {
|
|
2637
2701
|
this._outputJsonError(runResult.code, runResult.msg);
|
|
2638
2702
|
return this._makeOk();
|
|
2639
2703
|
}
|
|
2640
|
-
const imagePathResult = await
|
|
2704
|
+
const imagePathResult = await findGeneratedImageFile(imagePath);
|
|
2641
2705
|
if (!imagePathResult.ok) {
|
|
2642
2706
|
this._outputJsonError(imagePathResult.code, imagePathResult.msg);
|
|
2643
2707
|
return this._makeOk();
|
|
@@ -2647,7 +2711,7 @@ var AiImageCommandV2 = class extends AiBaseCommand {
|
|
|
2647
2711
|
});
|
|
2648
2712
|
return this._makeOk();
|
|
2649
2713
|
}
|
|
2650
|
-
async _runCodexImagePrompt(prompt) {
|
|
2714
|
+
async _runCodexImagePrompt(prompt, uuid) {
|
|
2651
2715
|
try {
|
|
2652
2716
|
await fs5.mkdir(CODEX_EMPTY_WORKDIR, { recursive: true });
|
|
2653
2717
|
} catch (error) {
|
|
@@ -2657,8 +2721,19 @@ var AiImageCommandV2 = class extends AiBaseCommand {
|
|
|
2657
2721
|
`\u521B\u5EFA codex \u7A7A\u5DE5\u4F5C\u76EE\u5F55\u5931\u8D25: ${CODEX_EMPTY_WORKDIR}: ${message}`
|
|
2658
2722
|
);
|
|
2659
2723
|
}
|
|
2724
|
+
try {
|
|
2725
|
+
await fs5.mkdir(GENERATED_IMAGES_DIR, { recursive: true });
|
|
2726
|
+
} catch (error) {
|
|
2727
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2728
|
+
return this._makeError(
|
|
2729
|
+
1,
|
|
2730
|
+
`\u521B\u5EFA codex \u751F\u56FE\u8F93\u51FA\u76EE\u5F55\u5931\u8D25: ${GENERATED_IMAGES_DIR}: ${message}`
|
|
2731
|
+
);
|
|
2732
|
+
}
|
|
2660
2733
|
const codexPrompt = `\u751F\u6210\u56FE\u7247(\u4F7F\u7528\u975ECLI\u6A21\u5F0F\u6765\u751F\u6210\uFF0C\u4F7F\u7528\u53EF\u652F\u6301\u7684\u9AD8\u753B\u8D28)\uFF0C\u5177\u4F53\u8981\u6C42\u5982\u4E0B:
|
|
2661
|
-
${prompt}
|
|
2734
|
+
${prompt}
|
|
2735
|
+
|
|
2736
|
+
<system-reminder>\u751F\u6210\u7ED3\u675F\u540E\u5C06\u751F\u6210\u7684\u56FE\u7247\u62F7\u8D1D\u5230\u6307\u5B9A\u8DEF\u5F84: \`${getGeneratedImagePromptPath(uuid)}\`\u3002</system-reminder>`;
|
|
2662
2737
|
const args = [
|
|
2663
2738
|
"exec",
|
|
2664
2739
|
"-C",
|
|
@@ -2697,88 +2772,27 @@ var AiImageCommandV2 = class extends AiBaseCommand {
|
|
|
2697
2772
|
});
|
|
2698
2773
|
}
|
|
2699
2774
|
};
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
GENERATED_IMAGES_DIR,
|
|
2703
|
-
minCreatedAt
|
|
2704
|
-
);
|
|
2705
|
-
if (!latestDirectoryResult.ok) {
|
|
2706
|
-
return latestDirectoryResult;
|
|
2707
|
-
}
|
|
2708
|
-
return findLatestCreatedFile(latestDirectoryResult.value);
|
|
2775
|
+
function getGeneratedImagePath(uuid) {
|
|
2776
|
+
return path6.join(GENERATED_IMAGES_DIR, `${uuid}.png`);
|
|
2709
2777
|
}
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
if (!entriesResult.ok) {
|
|
2713
|
-
return entriesResult;
|
|
2714
|
-
}
|
|
2715
|
-
const directories = await collectCreatedEntries(
|
|
2716
|
-
directoryPath,
|
|
2717
|
-
entriesResult.value.filter((entry) => entry.isDirectory()).map((entry) => entry.name)
|
|
2718
|
-
);
|
|
2719
|
-
if (!directories.ok) {
|
|
2720
|
-
return directories;
|
|
2721
|
-
}
|
|
2722
|
-
const latest = directories.value.filter(
|
|
2723
|
-
(entry) => entry.createdAt >= minCreatedAt - CREATED_AT_TOLERANCE_MS
|
|
2724
|
-
).sort(compareCreatedEntryDesc)[0];
|
|
2725
|
-
if (!latest) {
|
|
2726
|
-
return makeErrorForPath(
|
|
2727
|
-
1,
|
|
2728
|
-
"\u672A\u627E\u5230\u672C\u6B21 codex \u751F\u56FE\u8F93\u51FA\u5B50\u76EE\u5F55",
|
|
2729
|
-
directoryPath
|
|
2730
|
-
);
|
|
2731
|
-
}
|
|
2732
|
-
return makeOkWith(latest.filePath);
|
|
2778
|
+
function getGeneratedImagePromptPath(uuid) {
|
|
2779
|
+
return `${GENERATED_IMAGES_PROMPT_DIR}/${uuid}.png`;
|
|
2733
2780
|
}
|
|
2734
|
-
async function
|
|
2735
|
-
const entriesResult = await readDirectoryEntries(directoryPath);
|
|
2736
|
-
if (!entriesResult.ok) {
|
|
2737
|
-
return entriesResult;
|
|
2738
|
-
}
|
|
2739
|
-
const files = await collectCreatedEntries(
|
|
2740
|
-
directoryPath,
|
|
2741
|
-
entriesResult.value.filter((entry) => entry.isFile()).map((entry) => entry.name)
|
|
2742
|
-
);
|
|
2743
|
-
if (!files.ok) {
|
|
2744
|
-
return files;
|
|
2745
|
-
}
|
|
2746
|
-
const latest = files.value.sort(compareCreatedEntryDesc)[0];
|
|
2747
|
-
if (!latest) {
|
|
2748
|
-
return makeErrorForPath(1, "\u6700\u65B0\u751F\u56FE\u8F93\u51FA\u76EE\u5F55\u4E2D\u672A\u627E\u5230\u6587\u4EF6", directoryPath);
|
|
2749
|
-
}
|
|
2750
|
-
return makeOkWith(path6.resolve(latest.filePath));
|
|
2751
|
-
}
|
|
2752
|
-
async function readDirectoryEntries(directoryPath) {
|
|
2781
|
+
async function findGeneratedImageFile(filePath) {
|
|
2753
2782
|
try {
|
|
2754
|
-
|
|
2783
|
+
const stats = await fs5.stat(filePath);
|
|
2784
|
+
if (!stats.isFile()) {
|
|
2785
|
+
return makeErrorForPath(1, "\u672C\u6B21 codex \u751F\u56FE\u8F93\u51FA\u8DEF\u5F84\u4E0D\u662F\u6587\u4EF6", filePath);
|
|
2786
|
+
}
|
|
2787
|
+
return makeOkWith(path6.resolve(filePath));
|
|
2755
2788
|
} catch (error) {
|
|
2756
2789
|
const message = error instanceof Error ? error.message : String(error);
|
|
2757
|
-
return makeErrorForPath(
|
|
2758
|
-
|
|
2759
|
-
}
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
for (const name of names) {
|
|
2763
|
-
const filePath = path6.join(parentPath, name);
|
|
2764
|
-
try {
|
|
2765
|
-
const stats = await fs5.stat(filePath);
|
|
2766
|
-
entries.push({
|
|
2767
|
-
filePath,
|
|
2768
|
-
createdAt: getCreatedAt(stats)
|
|
2769
|
-
});
|
|
2770
|
-
} catch (error) {
|
|
2771
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2772
|
-
return makeErrorForPath(1, `\u8BFB\u53D6\u8DEF\u5F84\u72B6\u6001\u5931\u8D25: ${message}`, filePath);
|
|
2773
|
-
}
|
|
2790
|
+
return makeErrorForPath(
|
|
2791
|
+
1,
|
|
2792
|
+
`\u672A\u627E\u5230\u672C\u6B21 codex \u751F\u56FE\u8F93\u51FA\u6587\u4EF6: ${message}`,
|
|
2793
|
+
filePath
|
|
2794
|
+
);
|
|
2774
2795
|
}
|
|
2775
|
-
return makeOkWith(entries);
|
|
2776
|
-
}
|
|
2777
|
-
function getCreatedAt(stats) {
|
|
2778
|
-
return stats.birthtimeMs || stats.ctimeMs || stats.mtimeMs;
|
|
2779
|
-
}
|
|
2780
|
-
function compareCreatedEntryDesc(a, b) {
|
|
2781
|
-
return b.createdAt - a.createdAt || b.filePath.localeCompare(a.filePath);
|
|
2782
2796
|
}
|
|
2783
2797
|
function makeErrorForPath(code, message, filePath) {
|
|
2784
2798
|
return makeError(code, `${message}: ${filePath}`);
|
|
@@ -2788,57 +2802,6 @@ function makeErrorForPath(code, message, filePath) {
|
|
|
2788
2802
|
import * as path7 from "path";
|
|
2789
2803
|
import { Option as Option8 } from "commander";
|
|
2790
2804
|
|
|
2791
|
-
// src/bedrock/uuid/uuid.ts
|
|
2792
|
-
var generateUuid = (() => {
|
|
2793
|
-
if (typeof crypto === "object" && typeof crypto.randomUUID === "function") {
|
|
2794
|
-
return crypto.randomUUID.bind(crypto);
|
|
2795
|
-
}
|
|
2796
|
-
let getRandomValues;
|
|
2797
|
-
if (typeof crypto === "object" && typeof crypto.getRandomValues === "function") {
|
|
2798
|
-
getRandomValues = crypto.getRandomValues.bind(crypto);
|
|
2799
|
-
} else {
|
|
2800
|
-
getRandomValues = function(bucket) {
|
|
2801
|
-
for (let i = 0; i < bucket.length; i++) {
|
|
2802
|
-
bucket[i] = Math.floor(Math.random() * 256);
|
|
2803
|
-
}
|
|
2804
|
-
return bucket;
|
|
2805
|
-
};
|
|
2806
|
-
}
|
|
2807
|
-
const data = new Uint8Array(16);
|
|
2808
|
-
const hex = [];
|
|
2809
|
-
for (let i = 0; i < 256; i++) {
|
|
2810
|
-
hex.push(i.toString(16).padStart(2, "0"));
|
|
2811
|
-
}
|
|
2812
|
-
return () => {
|
|
2813
|
-
getRandomValues(data);
|
|
2814
|
-
data[6] = data[6] & 15 | 64;
|
|
2815
|
-
data[8] = data[8] & 63 | 128;
|
|
2816
|
-
let i = 0;
|
|
2817
|
-
let result = "";
|
|
2818
|
-
result += hex[data[i++]];
|
|
2819
|
-
result += hex[data[i++]];
|
|
2820
|
-
result += hex[data[i++]];
|
|
2821
|
-
result += hex[data[i++]];
|
|
2822
|
-
result += "-";
|
|
2823
|
-
result += hex[data[i++]];
|
|
2824
|
-
result += hex[data[i++]];
|
|
2825
|
-
result += "-";
|
|
2826
|
-
result += hex[data[i++]];
|
|
2827
|
-
result += hex[data[i++]];
|
|
2828
|
-
result += "-";
|
|
2829
|
-
result += hex[data[i++]];
|
|
2830
|
-
result += hex[data[i++]];
|
|
2831
|
-
result += "-";
|
|
2832
|
-
result += hex[data[i++]];
|
|
2833
|
-
result += hex[data[i++]];
|
|
2834
|
-
result += hex[data[i++]];
|
|
2835
|
-
result += hex[data[i++]];
|
|
2836
|
-
result += hex[data[i++]];
|
|
2837
|
-
result += hex[data[i++]];
|
|
2838
|
-
return result;
|
|
2839
|
-
};
|
|
2840
|
-
})();
|
|
2841
|
-
|
|
2842
2805
|
// src/commands/pippit/modules/submit-direct/submit-direct-cn.ts
|
|
2843
2806
|
var SUBMIT_DIRECT_URL = "https://xyq.jianying.com/api/biz/v1/agent/submit_run";
|
|
2844
2807
|
function normalizeToken5(token) {
|