maoda-commander-tt 0.0.22 → 0.0.24

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
@@ -1799,6 +1799,154 @@ var PippitAssetGetCommand = class extends BaseCommand {
1799
1799
  }
1800
1800
  };
1801
1801
 
1802
+ // src/commands/pippit/modules/douyin-video/errors.ts
1803
+ var BASE6 = 15e3;
1804
+ var DouyinVideoError = ((DouyinVideoError2) => {
1805
+ DouyinVideoError2[DouyinVideoError2["MissingUserInput"] = BASE6 + 1] = "MissingUserInput";
1806
+ DouyinVideoError2[DouyinVideoError2["MissingWebToken"] = BASE6 + 2] = "MissingWebToken";
1807
+ DouyinVideoError2[DouyinVideoError2["NetworkRequestFailed"] = BASE6 + 3] = "NetworkRequestFailed";
1808
+ DouyinVideoError2[DouyinVideoError2["ResponseParseFailed"] = BASE6 + 4] = "ResponseParseFailed";
1809
+ DouyinVideoError2[DouyinVideoError2["RequestFailed"] = BASE6 + 5] = "RequestFailed";
1810
+ return DouyinVideoError2;
1811
+ })(DouyinVideoError || {});
1812
+ var missingUserInputError = lvErrorConst(
1813
+ DouyinVideoError.MissingUserInput,
1814
+ "\u7F3A\u5C11\u6296\u97F3\u94FE\u63A5\u53C2\u6570\u3002"
1815
+ );
1816
+ var missingWebTokenError2 = lvErrorConst(
1817
+ DouyinVideoError.MissingWebToken,
1818
+ "\u7F3A\u5C11\u53EF\u7528\u7684 sessionid_pippitcn_web token\uFF0C\u8BF7\u5148\u4F7F\u7528 `tt pippit web-token --region=cn <token>` \u914D\u7F6E token\u3002"
1819
+ );
1820
+ var networkRequestFailedError6 = lvErrorConst(
1821
+ DouyinVideoError.NetworkRequestFailed,
1822
+ "\u8BF7\u6C42\u6296\u97F3\u89C6\u9891\u89E3\u6790\u63A5\u53E3\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u548C\u767B\u5F55\u6001\u3002"
1823
+ );
1824
+ var responseParseFailedError5 = lvErrorConst(
1825
+ DouyinVideoError.ResponseParseFailed,
1826
+ "\u89E3\u6790\u6296\u97F3\u89C6\u9891\u89E3\u6790\u63A5\u53E3\u54CD\u5E94\u5931\u8D25\u3002"
1827
+ );
1828
+ var requestFailedError2 = lvErrorConst(
1829
+ DouyinVideoError.RequestFailed,
1830
+ "\u83B7\u53D6\u6296\u97F3\u89C6\u9891\u5730\u5740\u5931\u8D25\u3002"
1831
+ );
1832
+
1833
+ // src/commands/pippit/modules/douyin-video/cn-douyin-video.ts
1834
+ var PARSE_URL = "https://xyq.jianying.com/api/biz/v1/parse/check_input_valid";
1835
+ function normalizeToken4(token) {
1836
+ const trimmed = token.trim();
1837
+ const prefix = "sessionid_pippitcn_web=";
1838
+ if (trimmed.startsWith(prefix)) {
1839
+ return trimmed.slice(prefix.length).trim();
1840
+ }
1841
+ return trimmed;
1842
+ }
1843
+ function createCookieHeader3(token) {
1844
+ return `sessionid_pippitcn_web=${normalizeToken4(token)}`;
1845
+ }
1846
+ function readRecord(value) {
1847
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
1848
+ return void 0;
1849
+ }
1850
+ return value;
1851
+ }
1852
+ function parseVideoUrl(data) {
1853
+ const dataRecord = readRecord(data);
1854
+ const videoInfoRecord = readRecord(dataRecord?.video_info);
1855
+ const videoUrl = videoInfoRecord?.video_url;
1856
+ if (typeof videoUrl !== "string") {
1857
+ return void 0;
1858
+ }
1859
+ const trimmed = videoUrl.trim();
1860
+ return trimmed.length > 0 ? trimmed : void 0;
1861
+ }
1862
+ function parseErrorCode2(ret) {
1863
+ const parsed = typeof ret === "number" ? ret : typeof ret === "string" ? Number.parseInt(ret, 10) : Number.NaN;
1864
+ return Number.isFinite(parsed) ? parsed : DouyinVideoError.RequestFailed;
1865
+ }
1866
+ async function fetchDouyinVideoCn(options) {
1867
+ const webContextResult = await readWebContext("cn" /* CN */);
1868
+ if (!webContextResult.ok) {
1869
+ return webContextResult;
1870
+ }
1871
+ const tokenResult = await readWebToken("cn" /* CN */);
1872
+ if (!tokenResult.ok) {
1873
+ return tokenResult;
1874
+ }
1875
+ const token = tokenResult.value?.trim();
1876
+ if (!token) {
1877
+ return missingWebTokenError2();
1878
+ }
1879
+ const responseResult = await requestJson(
1880
+ PARSE_URL,
1881
+ {
1882
+ method: "POST",
1883
+ headers: {
1884
+ accept: "application/json, text/plain, */*",
1885
+ "content-type": "application/json",
1886
+ cookie: createCookieHeader3(token),
1887
+ Referer: "https://xyq.jianying.com/"
1888
+ },
1889
+ body: JSON.stringify({
1890
+ uid: webContextResult.value.uid,
1891
+ user_input: options.userInput
1892
+ })
1893
+ },
1894
+ {
1895
+ networkRequestFailed: (message) => networkRequestFailedError6(message),
1896
+ responseParseFailed: (message) => responseParseFailedError5(message)
1897
+ }
1898
+ );
1899
+ if (!responseResult.ok) {
1900
+ return responseResult;
1901
+ }
1902
+ const response = responseResult.value;
1903
+ const videoUrl = parseVideoUrl(response.data);
1904
+ if (videoUrl) {
1905
+ return makeOkWith({ video_url: videoUrl });
1906
+ }
1907
+ if (response.ret !== void 0 && String(response.ret) !== "0") {
1908
+ return makeError(
1909
+ parseErrorCode2(response.ret),
1910
+ response.errmsg?.trim() || "\u6296\u97F3\u89C6\u9891\u89E3\u6790\u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF\u3002"
1911
+ );
1912
+ }
1913
+ return requestFailedError2("\u63A5\u53E3\u672A\u8FD4\u56DE data.video_info.video_url\u3002");
1914
+ }
1915
+
1916
+ // src/commands/pippit/modules/douyin-video/douyin-video.ts
1917
+ async function fetchDouyinVideo(options) {
1918
+ return fetchDouyinVideoCn(options);
1919
+ }
1920
+
1921
+ // src/commands/pippit/pippit-douyin-video-command.ts
1922
+ var PippitDouyinVideoCommand = class extends BaseCommand {
1923
+ _meta() {
1924
+ return {
1925
+ name: "douyin-video",
1926
+ description: "\u901A\u8FC7\u6296\u97F3\u94FE\u63A5\u83B7\u53D6\u89C6\u9891\u5730\u5740"
1927
+ };
1928
+ }
1929
+ _configureArguments(cmd) {
1930
+ cmd.argument("<user_input...>", "\u8981\u89E3\u6790\u7684\u6296\u97F3\u94FE\u63A5\u6216\u5B8C\u6574\u5206\u4EAB\u6587\u6848");
1931
+ }
1932
+ async _execute(ctx) {
1933
+ const userInputParts = ctx.args[0] ?? [];
1934
+ const userInput = userInputParts.join(" ").trim();
1935
+ if (!userInput) {
1936
+ const error = missingUserInputError();
1937
+ this._outputJsonError(error.code, error.msg);
1938
+ return this._makeOk();
1939
+ }
1940
+ const result = await fetchDouyinVideo({ userInput });
1941
+ if (!result.ok) {
1942
+ this._outputJsonError(result.code, result.msg);
1943
+ return this._makeOk();
1944
+ }
1945
+ this._outputJsonOk(result.value);
1946
+ return this._makeOk();
1947
+ }
1948
+ };
1949
+
1802
1950
  // src/commands/pippit/pippit-command.ts
1803
1951
  var PippitCommand = class extends BaseSubcommandHost {
1804
1952
  _meta() {
@@ -1816,6 +1964,7 @@ var PippitCommand = class extends BaseSubcommandHost {
1816
1964
  this._addSubcommand(new PippitAssetUploadCommand());
1817
1965
  this._addSubcommand(new PippitWebTokenCommand());
1818
1966
  this._addSubcommand(new PippitAssetGetCommand());
1967
+ this._addSubcommand(new PippitDouyinVideoCommand());
1819
1968
  }
1820
1969
  };
1821
1970
 
@@ -2692,7 +2841,7 @@ var generateUuid = (() => {
2692
2841
 
2693
2842
  // src/commands/pippit/modules/submit-direct/submit-direct-cn.ts
2694
2843
  var SUBMIT_DIRECT_URL = "https://xyq.jianying.com/api/biz/v1/agent/submit_run";
2695
- function normalizeToken4(token) {
2844
+ function normalizeToken5(token) {
2696
2845
  const trimmed = token.trim();
2697
2846
  const prefix = "sessionid_pippitcn_web=";
2698
2847
  if (trimmed.startsWith(prefix)) {
@@ -2700,10 +2849,10 @@ function normalizeToken4(token) {
2700
2849
  }
2701
2850
  return trimmed;
2702
2851
  }
2703
- function createCookieHeader3(token) {
2704
- return `sessionid_pippitcn_web=${normalizeToken4(token)}`;
2852
+ function createCookieHeader4(token) {
2853
+ return `sessionid_pippitcn_web=${normalizeToken5(token)}`;
2705
2854
  }
2706
- function parseErrorCode2(ret) {
2855
+ function parseErrorCode3(ret) {
2707
2856
  const parsed = typeof ret === "number" ? ret : typeof ret === "string" ? Number.parseInt(ret, 10) : Number.NaN;
2708
2857
  return Number.isFinite(parsed) ? parsed : 1;
2709
2858
  }
@@ -2789,7 +2938,7 @@ async function submitDirectCn(options) {
2789
2938
  headers: {
2790
2939
  accept: "application/json, text/plain, */*",
2791
2940
  "content-type": "application/json",
2792
- cookie: createCookieHeader3(token),
2941
+ cookie: createCookieHeader4(token),
2793
2942
  Referer: "https://xyq.jianying.com/"
2794
2943
  },
2795
2944
  body: JSON.stringify({
@@ -2812,7 +2961,7 @@ async function submitDirectCn(options) {
2812
2961
  console.log("=====response", response);
2813
2962
  if (String(response.ret) !== "0") {
2814
2963
  return makeError(
2815
- parseErrorCode2(response.ret),
2964
+ parseErrorCode3(response.ret),
2816
2965
  response.errmsg?.trim() || "\u76F4\u63A5\u63D0\u4EA4\u5931\u8D25\u3002"
2817
2966
  );
2818
2967
  }
@@ -3947,6 +4096,213 @@ function compareCanvasMatches(a, b) {
3947
4096
  return a.nodeIndex - b.nodeIndex;
3948
4097
  }
3949
4098
 
4099
+ // src/commands/tool/tool-draw-command.ts
4100
+ var ToolDrawCommand = class extends BaseCommand {
4101
+ _meta() {
4102
+ return {
4103
+ name: "draw",
4104
+ description: "\u6309\u6982\u7387\u5206\u5E03\u62BD\u7B7E"
4105
+ };
4106
+ }
4107
+ _configureArguments(cmd) {
4108
+ cmd.argument("<count>", "\u8981\u62BD\u53D6\u7684\u4E2A\u6570");
4109
+ cmd.argument("<distribution...>", "\u6982\u7387\u5206\u5E03\uFF0C\u652F\u6301\u7B80\u5199\u6216 JSON \u6570\u7EC4");
4110
+ cmd.addHelpText(
4111
+ "after",
4112
+ [
4113
+ "",
4114
+ "\u8F93\u5165\u6848\u4F8B:",
4115
+ ' tt tool draw 3 "A A:50,B B:30,C C:20"',
4116
+ ` tt tool draw 3 '[{"name":"\u4E2D\u56FD \u6210\u90FD","weight":50},{"name":"Los Angeles","weight":50}]'`
4117
+ ].join("\n")
4118
+ );
4119
+ }
4120
+ async _execute(ctx) {
4121
+ const countResult = parseCount(ctx.args[0]);
4122
+ if (!countResult.ok) {
4123
+ return this._makeError(1, countResult.msg);
4124
+ }
4125
+ const distributionText = stringifyDistributionArg(ctx.args[1]);
4126
+ if (!distributionText) {
4127
+ return this._makeError(1, "\u6982\u7387\u5206\u5E03\u4E0D\u80FD\u4E3A\u7A7A");
4128
+ }
4129
+ const distributionResult = parseDistribution(distributionText);
4130
+ if (!distributionResult.ok) {
4131
+ return this._makeError(1, distributionResult.msg);
4132
+ }
4133
+ this._outputJson({
4134
+ items: drawWeightedItems(countResult.value, distributionResult.value)
4135
+ });
4136
+ return this._makeOk();
4137
+ }
4138
+ _outputJson(data) {
4139
+ this._output(JSON.stringify(data, null, 2));
4140
+ }
4141
+ };
4142
+ function parseCount(value) {
4143
+ const count = Number(String(value ?? "").trim());
4144
+ if (!Number.isInteger(count) || count <= 0) {
4145
+ return { ok: false, msg: "\u62BD\u53D6\u4E2A\u6570\u5FC5\u987B\u662F\u6B63\u6574\u6570" };
4146
+ }
4147
+ return { ok: true, value: count };
4148
+ }
4149
+ function stringifyDistributionArg(value) {
4150
+ if (Array.isArray(value)) {
4151
+ return value.map((item) => String(item)).join(" ").trim();
4152
+ }
4153
+ return String(value ?? "").trim();
4154
+ }
4155
+ function parseDistribution(value) {
4156
+ if (value.trimStart().startsWith("[")) {
4157
+ return parseJsonDistribution(value);
4158
+ }
4159
+ return parseShorthandDistribution(value);
4160
+ }
4161
+ function parseJsonDistribution(value) {
4162
+ let parsed;
4163
+ try {
4164
+ parsed = JSON.parse(value);
4165
+ } catch (err) {
4166
+ const msg = err instanceof Error ? err.message : String(err);
4167
+ return { ok: false, msg: `JSON \u6982\u7387\u5206\u5E03\u89E3\u6790\u5931\u8D25: ${msg}` };
4168
+ }
4169
+ if (!Array.isArray(parsed)) {
4170
+ return { ok: false, msg: "JSON \u6982\u7387\u5206\u5E03\u5FC5\u987B\u662F\u6570\u7EC4" };
4171
+ }
4172
+ const entries = [];
4173
+ for (let index = 0; index < parsed.length; index += 1) {
4174
+ const entryResult = parseJsonDistributionEntry(parsed[index], index);
4175
+ if (!entryResult.ok) {
4176
+ return entryResult;
4177
+ }
4178
+ entries.push(entryResult.value);
4179
+ }
4180
+ return validateDistribution(entries);
4181
+ }
4182
+ function parseJsonDistributionEntry(value, index) {
4183
+ const record = asRecord2(value);
4184
+ if (!record) {
4185
+ return { ok: false, msg: `\u7B2C ${index + 1} \u9879\u5FC5\u987B\u662F\u5BF9\u8C61` };
4186
+ }
4187
+ const nameResult = parseEntryName(record.name, `\u7B2C ${index + 1} \u9879`);
4188
+ if (!nameResult.ok) {
4189
+ return nameResult;
4190
+ }
4191
+ const weightResult = parseWeight(
4192
+ getJsonWeightValue(record),
4193
+ `\u7B2C ${index + 1} \u9879`
4194
+ );
4195
+ if (!weightResult.ok) {
4196
+ return weightResult;
4197
+ }
4198
+ return {
4199
+ ok: true,
4200
+ value: {
4201
+ name: nameResult.value,
4202
+ weight: weightResult.value
4203
+ }
4204
+ };
4205
+ }
4206
+ function getJsonWeightValue(record) {
4207
+ if ("weight" in record) {
4208
+ return record.weight;
4209
+ }
4210
+ if ("probability" in record) {
4211
+ return record.probability;
4212
+ }
4213
+ if ("prob" in record) {
4214
+ return record.prob;
4215
+ }
4216
+ return record.p;
4217
+ }
4218
+ function parseShorthandDistribution(value) {
4219
+ const parts = value.split(/[,,]/);
4220
+ const entries = [];
4221
+ for (let index = 0; index < parts.length; index += 1) {
4222
+ const part = parts[index].trim();
4223
+ if (!part) {
4224
+ return { ok: false, msg: `\u7B2C ${index + 1} \u9879\u4E3A\u7A7A` };
4225
+ }
4226
+ const separatorIndex = findLastWeightSeparator(part);
4227
+ if (separatorIndex < 0) {
4228
+ return {
4229
+ ok: false,
4230
+ msg: `\u7B2C ${index + 1} \u9879\u7F3A\u5C11\u6982\u7387\u5206\u9694\u7B26 ":"`
4231
+ };
4232
+ }
4233
+ const nameResult = parseEntryName(
4234
+ part.slice(0, separatorIndex),
4235
+ `\u7B2C ${index + 1} \u9879`
4236
+ );
4237
+ if (!nameResult.ok) {
4238
+ return nameResult;
4239
+ }
4240
+ const weightResult = parseWeight(
4241
+ part.slice(separatorIndex + 1),
4242
+ `\u7B2C ${index + 1} \u9879`
4243
+ );
4244
+ if (!weightResult.ok) {
4245
+ return weightResult;
4246
+ }
4247
+ entries.push({
4248
+ name: nameResult.value,
4249
+ weight: weightResult.value
4250
+ });
4251
+ }
4252
+ return validateDistribution(entries);
4253
+ }
4254
+ function findLastWeightSeparator(value) {
4255
+ return Math.max(value.lastIndexOf(":"), value.lastIndexOf("\uFF1A"));
4256
+ }
4257
+ function parseEntryName(value, label) {
4258
+ if (typeof value !== "string") {
4259
+ return { ok: false, msg: `${label}\u7684\u540D\u79F0\u5FC5\u987B\u662F\u5B57\u7B26\u4E32` };
4260
+ }
4261
+ const name = value.trim();
4262
+ if (!name) {
4263
+ return { ok: false, msg: `${label}\u7684\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A` };
4264
+ }
4265
+ return { ok: true, value: name };
4266
+ }
4267
+ function parseWeight(value, label) {
4268
+ const rawValue = typeof value === "string" ? value.trim().replace(/[%%]$/, "") : value;
4269
+ const weight = Number(rawValue);
4270
+ if (!Number.isFinite(weight) || weight <= 0) {
4271
+ return { ok: false, msg: `${label}\u7684\u6982\u7387\u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57` };
4272
+ }
4273
+ return { ok: true, value: weight };
4274
+ }
4275
+ function validateDistribution(entries) {
4276
+ if (entries.length === 0) {
4277
+ return { ok: false, msg: "\u6982\u7387\u5206\u5E03\u81F3\u5C11\u9700\u8981 1 \u9879" };
4278
+ }
4279
+ return { ok: true, value: entries };
4280
+ }
4281
+ function drawWeightedItems(count, entries) {
4282
+ const totalWeight = entries.reduce((sum, entry) => sum + entry.weight, 0);
4283
+ const items = [];
4284
+ for (let index = 0; index < count; index += 1) {
4285
+ items.push(drawWeightedItem(entries, totalWeight));
4286
+ }
4287
+ return items;
4288
+ }
4289
+ function drawWeightedItem(entries, totalWeight) {
4290
+ let cursor = Math.random() * totalWeight;
4291
+ for (const entry of entries) {
4292
+ cursor -= entry.weight;
4293
+ if (cursor < 0) {
4294
+ return entry.name;
4295
+ }
4296
+ }
4297
+ return entries[entries.length - 1].name;
4298
+ }
4299
+ function asRecord2(value) {
4300
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
4301
+ return void 0;
4302
+ }
4303
+ return value;
4304
+ }
4305
+
3950
4306
  // src/commands/tool/tool-command.ts
3951
4307
  var ToolCommand = class extends BaseSubcommandHost {
3952
4308
  _meta() {
@@ -3957,6 +4313,7 @@ var ToolCommand = class extends BaseSubcommandHost {
3957
4313
  }
3958
4314
  _registerSubcommands() {
3959
4315
  this._addSubcommand(new ToolCanvasCommand());
4316
+ this._addSubcommand(new ToolDrawCommand());
3960
4317
  }
3961
4318
  };
3962
4319