maoda-commander-tt 0.0.70 → 0.0.71

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.
@@ -3062,93 +3062,94 @@ async function readXyqGenerationPpeHeaders(settingsReader) {
3062
3062
  });
3063
3063
  }
3064
3064
 
3065
- // src/modules/xyq/xyq-image-results.ts
3065
+ // src/modules/xyq/xyq-asset-results.ts
3066
3066
  import { ok as ok20 } from "rockbed/error";
3067
- function collectXyqImageReferences(value) {
3067
+ function collectXyqAssetReferences(value, kind) {
3068
3068
  const references = /* @__PURE__ */ new Map();
3069
- collect(value, void 0, references, 0);
3069
+ collect(value, kind, void 0, references, 0);
3070
3070
  return [...references.values()];
3071
3071
  }
3072
- async function resolveXyqImageArtifacts(input) {
3073
- const references = input.artifacts.flatMap((artifact) => artifact.images);
3072
+ async function resolveXyqAssetArtifacts(input) {
3073
+ const { kind } = input;
3074
+ const label = kind === "image" ? "\u56FE\u7247" : "\u89C6\u9891";
3075
+ const originalLabel = kind === "image" ? "\u65E0\u6C34\u5370\u539F\u56FE" : "\u65E0\u6C34\u5370\u89C6\u9891";
3076
+ const references = input.artifacts.flatMap((artifact) => artifact.references);
3074
3077
  if (references.length === 0) {
3075
- return ok20(input.artifacts.map((artifact) => ({ ...artifact, images: [] })));
3078
+ return ok20(input.artifacts.map((artifact) => ({ raw: artifact.raw, outputs: [] })));
3076
3079
  }
3077
- if (references.some((image) => !image.pippitAssetId)) {
3078
- return invalidResult("XYQ \u56FE\u7247\u751F\u6210\u7ED3\u679C\u7F3A\u5C11 pippit_asset_id\uFF0C\u65E0\u6CD5\u67E5\u8BE2\u65E0\u6C34\u5370\u539F\u56FE");
3080
+ if (references.some((reference) => !reference.pippitAssetId)) {
3081
+ return invalidResult(kind, `XYQ ${label}\u751F\u6210\u7ED3\u679C\u7F3A\u5C11 pippit_asset_id\uFF0C\u65E0\u6CD5\u67E5\u8BE2${originalLabel}`);
3079
3082
  }
3080
- const runExtra = parseRecord(input.run.extra);
3081
- const projectId = normalize(input.thread.project_id) ?? normalize(input.run.project_id) ?? normalize(parseRecord(runExtra?.client_extra)?.project_id) ?? /^p(\d+)_/.exec(input.threadId)?.[1];
3082
- if (!projectId) {
3083
- return invalidResult("XYQ \u56FE\u7247\u4EFB\u52A1\u7F3A\u5C11 project_id\uFF0C\u65E0\u6CD5\u67E5\u8BE2\u65E0\u6C34\u5370\u539F\u56FE");
3084
- }
3085
- const pippitAssetIds = [...new Set(references.map((image) => image.pippitAssetId))];
3083
+ const pippitAssetIds = [...new Set(references.map((reference) => reference.pippitAssetId))];
3086
3084
  const response = await requestXyqJson(
3087
3085
  input.fetcher,
3088
3086
  `${XYQ_ORIGIN}/api/biz/v1/asset/query`,
3089
3087
  {
3090
3088
  method: "POST",
3091
3089
  headers: { ...input.headers, "content-type": "application/json" },
3092
- body: JSON.stringify({ Base: { Client: "web" }, project_id: projectId, pippit_asset_ids: pippitAssetIds })
3090
+ body: JSON.stringify({ Base: { Client: "web" }, pippit_asset_ids: pippitAssetIds })
3093
3091
  },
3094
3092
  {
3095
- requestFailedCode: XyqErrorCode.ImageQueryRequestFailed,
3096
- responseInvalidCode: XyqErrorCode.ImageQueryResponseInvalid,
3097
- operation: "\u67E5\u8BE2 XYQ \u56FE\u7247\u65E0\u6C34\u5370\u539F\u56FE"
3093
+ requestFailedCode: kind === "image" ? XyqErrorCode.ImageQueryRequestFailed : XyqErrorCode.VideoQueryRequestFailed,
3094
+ responseInvalidCode: kind === "image" ? XyqErrorCode.ImageQueryResponseInvalid : XyqErrorCode.VideoQueryResponseInvalid,
3095
+ operation: `\u67E5\u8BE2 XYQ ${originalLabel}`
3098
3096
  }
3099
3097
  );
3100
3098
  if (!response.ok) return response;
3101
3099
  const data = isRecord7(response.value.data) ? response.value.data : {};
3102
3100
  if (!Array.isArray(data.Assets)) {
3103
- return invalidResult("XYQ \u56FE\u7247\u8D44\u4EA7\u54CD\u5E94\u7F3A\u5C11 Assets\uFF0C\u65E0\u6CD5\u83B7\u53D6\u65E0\u6C34\u5370\u539F\u56FE");
3101
+ return invalidResult(kind, `XYQ ${label}\u8D44\u4EA7\u54CD\u5E94\u7F3A\u5C11 Assets\uFF0C\u65E0\u6CD5\u83B7\u53D6${originalLabel}`);
3104
3102
  }
3105
3103
  const urls = /* @__PURE__ */ new Map();
3106
3104
  for (const asset of data.Assets) {
3107
- if (!isRecord7(asset) || asset.AssetType !== 1) continue;
3105
+ if (!isRecord7(asset) || asset.AssetType !== (kind === "image" ? 1 : 2)) continue;
3108
3106
  const id = normalize(asset.PippitAssetID);
3109
3107
  if (!id || !pippitAssetIds.includes(id)) continue;
3110
- const image = isRecord7(asset.Image) ? asset.Image : {};
3111
- const preview = isRecord7(image.not_watermark_preview) ? image.not_watermark_preview : {};
3112
- const original = isRecord7(preview.previewinfo) ? preview.previewinfo : {};
3113
- const url = httpUrl(original.preview_url);
3108
+ const media = asset[kind === "image" ? "Image" : "Video"];
3109
+ const url = isRecord7(media) ? originalUrl(kind, media) : void 0;
3114
3110
  if (url) urls.set(id, url);
3115
3111
  }
3116
3112
  const missingId = pippitAssetIds.find((id) => !urls.has(id));
3117
3113
  if (missingId) {
3118
- return invalidResult(`XYQ \u56FE\u7247\u8D44\u4EA7 ${missingId} \u7F3A\u5C11\u65E0\u6C34\u5370\u539F\u56FE\u5730\u5740`);
3114
+ return invalidResult(kind, `XYQ ${label}\u8D44\u4EA7 ${missingId} \u7F3A\u5C11${originalLabel}\u5730\u5740`);
3119
3115
  }
3120
3116
  return ok20(input.artifacts.map((artifact) => ({
3121
- ...artifact,
3122
- images: artifact.images.map((image) => ({ ...image, downloadUrl: urls.get(image.pippitAssetId) }))
3117
+ raw: artifact.raw,
3118
+ outputs: artifact.references.map((reference) => ({
3119
+ ...reference,
3120
+ downloadUrl: urls.get(reference.pippitAssetId)
3121
+ }))
3123
3122
  })));
3124
3123
  }
3125
- function collect(value, inheritedId, references, depth) {
3124
+ function collect(value, kind, inheritedId, references, depth) {
3126
3125
  if (depth > 10) return;
3127
3126
  if (typeof value === "string") {
3128
3127
  const parsed = parseValue(value);
3129
- if (parsed !== void 0) collect(parsed, inheritedId, references, depth + 1);
3128
+ if (parsed !== void 0) collect(parsed, kind, inheritedId, references, depth + 1);
3130
3129
  return;
3131
3130
  }
3132
3131
  if (Array.isArray(value)) {
3133
- for (const child of value) collect(child, inheritedId, references, depth + 1);
3132
+ for (const child of value) collect(child, kind, inheritedId, references, depth + 1);
3134
3133
  return;
3135
3134
  }
3136
3135
  if (!isRecord7(value)) return;
3137
3136
  const pippitAssetId = normalize(value.pippit_asset_id ?? value.pippitAssetId) ?? inheritedId;
3138
3137
  for (const [key, child] of Object.entries(value)) {
3139
- if (key === "image" || key === "images") collectExplicit(child, pippitAssetId, references, depth + 1);
3140
- collect(child, pippitAssetId, references, depth + 1);
3138
+ if (key === kind || key === `${kind}s`) {
3139
+ collectExplicit(child, kind, pippitAssetId, references, depth + 1);
3140
+ }
3141
+ collect(child, kind, pippitAssetId, references, depth + 1);
3141
3142
  }
3142
3143
  }
3143
- function collectExplicit(value, inheritedId, references, depth) {
3144
+ function collectExplicit(value, kind, inheritedId, references, depth) {
3144
3145
  if (depth > 10) return;
3145
3146
  if (typeof value === "string") {
3146
3147
  const parsed = parseValue(value);
3147
- if (parsed !== void 0) collectExplicit(parsed, inheritedId, references, depth + 1);
3148
+ if (parsed !== void 0) collectExplicit(parsed, kind, inheritedId, references, depth + 1);
3148
3149
  return;
3149
3150
  }
3150
3151
  if (Array.isArray(value)) {
3151
- for (const child of value) collectExplicit(child, inheritedId, references, depth + 1);
3152
+ for (const child of value) collectExplicit(child, kind, inheritedId, references, depth + 1);
3152
3153
  return;
3153
3154
  }
3154
3155
  if (!isRecord7(value)) return;
@@ -3160,19 +3161,40 @@ function collectExplicit(value, inheritedId, references, depth) {
3160
3161
  if (!assetId && !pippitAssetId && !agentUrl && !sceneUrls) return;
3161
3162
  const width = number(metadata.width ?? value.width);
3162
3163
  const height = number(metadata.height ?? value.height);
3163
- const name = normalize(value.name);
3164
+ const name = kind === "image" ? normalize(value.name) : void 0;
3165
+ const extra = parseRecord(value.extra) ?? {};
3166
+ const durationMs = kind === "video" ? number(metadata.duration_ms ?? value.duration_ms ?? extra.ark_video_duration_ms) : void 0;
3164
3167
  const reference = {
3165
3168
  ...assetId ? { assetId } : {},
3166
3169
  ...pippitAssetId ? { pippitAssetId } : {},
3167
3170
  ...width !== void 0 ? { width } : {},
3168
3171
  ...height !== void 0 ? { height } : {},
3169
- ...name ? { name } : {}
3172
+ ...name ? { name } : {},
3173
+ ...durationMs !== void 0 ? { durationMs } : {}
3170
3174
  };
3171
- const identity = assetId ? `asset:${assetId}` : pippitAssetId ? `pippit:${pippitAssetId}` : `image:${references.size}`;
3172
- references.set(identity, reference);
3175
+ const identity = assetId ? `asset:${assetId}` : pippitAssetId ? `pippit:${pippitAssetId}` : `${kind}:${references.size}`;
3176
+ const existing = references.get(identity);
3177
+ if (kind === "image" || !existing || qualityScore(reference) > qualityScore(existing)) {
3178
+ references.set(identity, reference);
3179
+ }
3180
+ }
3181
+ function qualityScore(reference) {
3182
+ return (reference.width ?? 0) * (reference.height ?? 0);
3183
+ }
3184
+ function originalUrl(kind, media) {
3185
+ if (kind === "video") {
3186
+ const noWatermark = isRecord7(media.no_watermark_video_url) ? media.no_watermark_video_url : {};
3187
+ return httpUrl(normalize(media.origin_url) ?? noWatermark.download_url);
3188
+ }
3189
+ const preview = isRecord7(media.not_watermark_preview) ? media.not_watermark_preview : {};
3190
+ const original = isRecord7(preview.previewinfo) ? preview.previewinfo : {};
3191
+ return httpUrl(original.preview_url);
3173
3192
  }
3174
- function invalidResult(message) {
3175
- return xyqError(XyqErrorCode.ImageQueryResponseInvalid, message);
3193
+ function invalidResult(kind, message) {
3194
+ return xyqError(
3195
+ kind === "image" ? XyqErrorCode.ImageQueryResponseInvalid : XyqErrorCode.VideoQueryResponseInvalid,
3196
+ message
3197
+ );
3176
3198
  }
3177
3199
  function httpUrl(value) {
3178
3200
  const normalized = typeof value === "string" ? value.trim() : "";
@@ -3335,18 +3357,19 @@ var XyqSession = class {
3335
3357
  const runRecord = isRecord7(run) ? run : {};
3336
3358
  const serverRunId = normalizeString2(runRecord.run_id);
3337
3359
  const entryList = Array.isArray(runRecord.entry_list) ? runRecord.entry_list : [];
3338
- const artifactReferences = entryList.map(extractImageArtifact).filter((artifact) => artifact !== void 0);
3339
3360
  const state = mapXyqRunState(toNumber(runRecord.state));
3340
- const artifactsResult = state === "completed" ? await resolveXyqImageArtifacts({
3361
+ const artifactReferences = entryList.map((entry) => extractAssetArtifact(entry, "image", state === "completed")).filter((artifact) => artifact !== void 0);
3362
+ const artifactsResult = await resolveXyqAssetArtifacts({
3341
3363
  fetcher: this._fetcher,
3342
3364
  headers: { ...this._headers(), ...ppeHeadersResult.value },
3343
- threadId,
3344
- thread,
3345
- run: runRecord,
3365
+ kind: "image",
3346
3366
  artifacts: artifactReferences
3347
- }) : ok21(artifactReferences.map((artifact) => ({ ...artifact, images: [] })));
3367
+ });
3348
3368
  if (!artifactsResult.ok) return artifactsResult;
3349
- const artifacts = artifactsResult.value;
3369
+ const artifacts = artifactsResult.value.map((artifact) => ({
3370
+ images: artifact.outputs,
3371
+ raw: artifact.raw
3372
+ }));
3350
3373
  return ok21({
3351
3374
  taskId: `${XYQ_IMAGE_TASK_ID_PREFIX}${threadId}`,
3352
3375
  threadId,
@@ -3699,9 +3722,19 @@ var XyqSession = class {
3699
3722
  const runRecord = isRecord7(run) ? run : {};
3700
3723
  const serverRunId = normalizeString2(runRecord.run_id);
3701
3724
  const entryList = Array.isArray(runRecord.entry_list) ? runRecord.entry_list : [];
3702
- const artifacts = entryList.map(extractVideoArtifact).filter((artifact) => artifact !== void 0);
3703
- const providerState = mapXyqRunState(toNumber(runRecord.state));
3704
- const state = hasUsableVideoOutput(artifacts) ? "completed" : providerState;
3725
+ const state = mapXyqRunState(toNumber(runRecord.state));
3726
+ const artifactReferences = entryList.map((entry) => extractAssetArtifact(entry, "video", state === "completed")).filter((artifact) => artifact !== void 0);
3727
+ const artifactsResult = await resolveXyqAssetArtifacts({
3728
+ fetcher: this._fetcher,
3729
+ headers: { ...this._headers(), ...ppeHeadersResult.value },
3730
+ kind: "video",
3731
+ artifacts: artifactReferences
3732
+ });
3733
+ if (!artifactsResult.ok) return artifactsResult;
3734
+ const artifacts = artifactsResult.value.map((artifact) => ({
3735
+ videos: artifact.outputs,
3736
+ raw: artifact.raw
3737
+ }));
3705
3738
  const retryAfterSeconds = isTerminalXyqTaskState(state) ? 0 : VIDEO_POLL_INTERVAL_SECONDS;
3706
3739
  return ok21({
3707
3740
  taskId: threadId,
@@ -4236,9 +4269,6 @@ function mapXyqRunState(stateCode) {
4236
4269
  function isTerminalXyqTaskState(state) {
4237
4270
  return ["completed", "failed", "canceled", "inputRequired"].includes(state);
4238
4271
  }
4239
- function hasUsableVideoOutput(artifacts) {
4240
- return artifacts.some((artifact) => artifact.videos.length > 0);
4241
- }
4242
4272
  function hasUsableAudioOutput(artifacts) {
4243
4273
  return artifacts.some((artifact) => artifact.audios.length > 0);
4244
4274
  }
@@ -4255,25 +4285,15 @@ function extractAudioArtifact(entry) {
4255
4285
  raw: camelizeValue(artifact)
4256
4286
  };
4257
4287
  }
4258
- function extractVideoArtifact(entry) {
4259
- if (!isRecord7(entry)) {
4260
- return void 0;
4261
- }
4288
+ function extractAssetArtifact(entry, kind, completed) {
4289
+ if (!isRecord7(entry)) return void 0;
4262
4290
  const artifact = parseJsonRecord(entry.artifact);
4263
- if (!artifact) {
4264
- return void 0;
4265
- }
4291
+ if (!artifact) return void 0;
4266
4292
  return {
4267
- videos: deepCollectVideoOutputs(artifact),
4293
+ references: completed ? collectXyqAssetReferences(artifact, kind) : [],
4268
4294
  raw: camelizeValue(artifact)
4269
4295
  };
4270
4296
  }
4271
- function extractImageArtifact(entry) {
4272
- if (!isRecord7(entry)) return void 0;
4273
- const artifact = parseJsonRecord(entry.artifact);
4274
- if (!artifact) return void 0;
4275
- return { images: collectXyqImageReferences(artifact), raw: camelizeValue(artifact) };
4276
- }
4277
4297
  function deepCollectAudioOutputs(value) {
4278
4298
  const results = /* @__PURE__ */ new Map();
4279
4299
  collectAudioOutputs(value, void 0, results, 0);
@@ -4370,89 +4390,6 @@ function collectExplicitAudio(value, inheritedPippitAssetId, results, depth) {
4370
4390
  const identity = assetId ? `asset:${assetId}` : pippitAssetId ? `pippit:${pippitAssetId}` : `url:${downloadUrl}`;
4371
4391
  results.set(identity, output);
4372
4392
  }
4373
- function deepCollectVideoOutputs(value) {
4374
- const results = /* @__PURE__ */ new Map();
4375
- collectVideoOutputs(value, void 0, results, 0);
4376
- return [...results.values()];
4377
- }
4378
- function collectVideoOutputs(value, inheritedPippitAssetId, results, depth) {
4379
- if (depth > 10) {
4380
- return;
4381
- }
4382
- if (typeof value === "string") {
4383
- const parsed = parseJsonValue(value);
4384
- if (parsed !== void 0) {
4385
- collectVideoOutputs(parsed, inheritedPippitAssetId, results, depth + 1);
4386
- }
4387
- return;
4388
- }
4389
- if (Array.isArray(value)) {
4390
- for (const item of value) {
4391
- collectVideoOutputs(item, inheritedPippitAssetId, results, depth + 1);
4392
- }
4393
- return;
4394
- }
4395
- if (!isRecord7(value)) {
4396
- return;
4397
- }
4398
- const pippitAssetId = normalizeString2(value.pippit_asset_id) ?? inheritedPippitAssetId;
4399
- for (const [key, child] of Object.entries(value)) {
4400
- if (key === "video" || key === "videos") {
4401
- collectExplicitVideo(child, pippitAssetId, results, depth + 1);
4402
- }
4403
- collectVideoOutputs(child, pippitAssetId, results, depth + 1);
4404
- }
4405
- }
4406
- function collectExplicitVideo(value, inheritedPippitAssetId, results, depth) {
4407
- if (depth > 10) {
4408
- return;
4409
- }
4410
- if (typeof value === "string") {
4411
- const parsed = parseJsonValue(value);
4412
- if (parsed !== void 0) {
4413
- collectExplicitVideo(parsed, inheritedPippitAssetId, results, depth + 1);
4414
- }
4415
- return;
4416
- }
4417
- if (Array.isArray(value)) {
4418
- for (const item of value) {
4419
- collectExplicitVideo(item, inheritedPippitAssetId, results, depth + 1);
4420
- }
4421
- return;
4422
- }
4423
- if (!isRecord7(value)) {
4424
- return;
4425
- }
4426
- const downloadUrl = normalizeString2(value.download_url) ?? normalizeString2(value.url);
4427
- if (!downloadUrl) {
4428
- return;
4429
- }
4430
- const metadata = isRecord7(value.metadata) ? value.metadata : {};
4431
- const extra = isRecord7(value.extra) ? value.extra : {};
4432
- const assetId = normalizeString2(value.asset_id);
4433
- const pippitAssetId = normalizeString2(value.pippit_asset_id) ?? inheritedPippitAssetId;
4434
- const width = toNumber(metadata.width ?? value.width);
4435
- const height = toNumber(metadata.height ?? value.height);
4436
- const durationMs = toNumber(
4437
- metadata.duration_ms ?? value.duration_ms ?? extra.ark_video_duration_ms
4438
- );
4439
- const output = {
4440
- downloadUrl,
4441
- ...assetId ? { assetId } : {},
4442
- ...pippitAssetId ? { pippitAssetId } : {},
4443
- ...width !== void 0 ? { width } : {},
4444
- ...height !== void 0 ? { height } : {},
4445
- ...durationMs !== void 0 ? { durationMs } : {}
4446
- };
4447
- const identity = assetId ? `asset:${assetId}` : pippitAssetId ? `pippit:${pippitAssetId}` : `url:${downloadUrl}`;
4448
- const existing = results.get(identity);
4449
- if (!existing || videoQualityScore(output) > videoQualityScore(existing)) {
4450
- results.set(identity, output);
4451
- }
4452
- }
4453
- function videoQualityScore(output) {
4454
- return (output.width ?? 0) * (output.height ?? 0);
4455
- }
4456
4393
  function parseJsonRecord(value) {
4457
4394
  if (isRecord7(value)) {
4458
4395
  return value;
@@ -4746,14 +4683,14 @@ function collectTaskVideoOutputs(result) {
4746
4683
  for (const video of artifact.videos) {
4747
4684
  const identity = video.assetId ? `asset:${video.assetId}` : video.pippitAssetId ? `pippit:${video.pippitAssetId}` : `url:${video.downloadUrl}`;
4748
4685
  const existing = outputs.get(identity);
4749
- if (!existing || qualityScore(video) > qualityScore(existing)) {
4686
+ if (!existing || qualityScore2(video) > qualityScore2(existing)) {
4750
4687
  outputs.set(identity, video);
4751
4688
  }
4752
4689
  }
4753
4690
  }
4754
4691
  return [...outputs.values()];
4755
4692
  }
4756
- function qualityScore(output) {
4693
+ function qualityScore2(output) {
4757
4694
  return (output.width ?? 0) * (output.height ?? 0);
4758
4695
  }
4759
4696
 
@@ -9185,4 +9122,4 @@ export {
9185
9122
  TraexCommand,
9186
9123
  createRootCommands
9187
9124
  };
9188
- //# sourceMappingURL=chunk-X52PJANF.js.map
9125
+ //# sourceMappingURL=chunk-YZFLZ22B.js.map