@gaoding/cli 2.1.0 → 2.1.2
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/README.md +30 -0
- package/contracts/operations/agent.send/input.schema.json +8 -84
- package/contracts/operations/agent.send/output.schema.json +6 -6
- package/contracts/operations/dam.folder.list/input.schema.json +1 -1
- package/contracts/operations/dam.folder.list/output.schema.json +1 -1
- package/contracts/operations/dam.list/input.schema.json +2 -5
- package/contracts/operations/dam.list/output.schema.json +1 -1
- package/contracts/operations/dam.search/input.schema.json +2 -5
- package/contracts/operations/dam.search/output.schema.json +1 -1
- package/contracts/operations/model.get/output.schema.json +6 -5
- package/contracts/operations/model.list/output.schema.json +5 -4
- package/contracts/operations/task.get/output.schema.json +22 -11
- package/contracts/operations/tool.call/models/image-edit-smart.schema.json +7 -5
- package/contracts/operations/tool.call/models/image-edit-standard.schema.json +6 -4
- package/contracts/operations/tool.call/models/image-enhance-smart.schema.json +5 -3
- package/contracts/operations/tool.call/models/image-enhance-standard.schema.json +3 -2
- package/contracts/operations/tool.call/models/image-expand-smart.schema.json +16 -10
- package/contracts/operations/tool.call/models/image-expand-standard.schema.json +13 -8
- package/contracts/operations/tool.call/models/image-layers-layout.schema.json +3 -2
- package/contracts/operations/tool.call/models/image-layers-smart.schema.json +3 -4
- package/contracts/operations/tool.call/models/image-matting-smart.schema.json +6 -4
- package/contracts/operations/tool.call/models/image-matting-standard.schema.json +3 -2
- package/contracts/operations/tool.call/models/image-ocr.schema.json +3 -2
- package/contracts/operations/tool.call/models/image-remove-smart.schema.json +6 -4
- package/contracts/operations/tool.call/models/image-remove-standard.schema.json +4 -3
- package/contracts/operations/tool.call/models/image-text-edit.schema.json +5 -3
- package/contracts/operations/tool.call/models/image-vectorize.schema.json +3 -2
- package/contracts/operations/tool.call/models/video-edit-smart.schema.json +6 -6
- package/contracts/operations/tool.call/models/video-enhance-smart.schema.json +7 -4
- package/contracts/operations/tool.call/models/video-enhance-standard.schema.json +5 -3
- package/contracts/operations/tool.call/ocr-payload.schema.json +4 -5
- package/contracts/operations/tool.call/output.schema.json +9 -8
- package/dist/bin/postinstall.js +22 -6
- package/dist/bin/sync-skill.js +33 -0
- package/dist/bin/task-worker.js +2 -2
- package/dist/src/bootstrap/create-cli.js +13 -6
- package/dist/src/bootstrap/create-runtime.js +103 -29
- package/dist/src/bootstrap/run-task-worker.js +6 -2
- package/dist/src/bootstrap/validators.js +87 -151
- package/dist/src/cli/action-binding.js +14 -37
- package/dist/src/cli/agent-commands.js +13 -13
- package/dist/src/cli/auth-commands.js +2 -1
- package/dist/src/cli/creation-help.js +9 -0
- package/dist/src/cli/dam-commands.js +10 -14
- package/dist/src/cli/editor-commands.js +16 -12
- package/dist/src/cli/errors.js +84 -26
- package/dist/src/cli/host-input.js +62 -5
- package/dist/src/cli/model-commands.js +9 -3
- package/dist/src/cli/observed-errors.js +7 -3
- package/dist/src/cli/org-commands.js +3 -1
- package/dist/src/cli/presenter.js +4 -5
- package/dist/src/cli/task-commands.js +6 -2
- package/dist/src/cli/tool-commands.js +12 -11
- package/dist/src/contracts/creation-input.js +20 -17
- package/dist/src/features/agent/creative-agent-adapter.js +6 -2
- package/dist/src/features/agent/creative-protocol.js +8 -29
- package/dist/src/features/agent/resource-authorizer.js +25 -17
- package/dist/src/features/agent/result-reader.js +31 -14
- package/dist/src/features/agent/use-cases.js +6 -31
- package/dist/src/features/auth/credential-store.js +1 -0
- package/dist/src/features/credits/use-cases.js +55 -28
- package/dist/src/features/dam/asset-projection.js +3 -6
- package/dist/src/features/dam/dam-api-adapter.js +30 -15
- package/dist/src/features/dam/object-storage.js +2 -1
- package/dist/src/features/dam/repository-catalog.js +30 -21
- package/dist/src/features/dam/use-cases.js +14 -9
- package/dist/src/features/editor/bridge-client.js +0 -2
- package/dist/src/features/editor/bridge-process.js +3 -2
- package/dist/src/features/editor/public-url.js +1 -36
- package/dist/src/features/editor/session-state.js +1 -0
- package/dist/src/features/editor/session.js +3 -2
- package/dist/src/features/editor/use-cases.js +27 -2
- package/dist/src/features/org/org-service.js +10 -1
- package/dist/src/features/org/use-cases.js +18 -4
- package/dist/src/features/task/process-owner.js +54 -0
- package/dist/src/features/task/store.js +102 -32
- package/dist/src/features/task/task-background.js +8 -4
- package/dist/src/features/task/use-cases.js +184 -84
- package/dist/src/features/tool/argument-paths.js +14 -0
- package/dist/src/features/tool/canvas-copy.js +28 -15
- package/dist/src/features/tool/canvas-matting.js +123 -0
- package/dist/src/features/tool/canvas-media.js +102 -55
- package/dist/src/features/tool/canvas-models.js +66 -33
- package/dist/src/features/tool/canvas-pricing.js +12 -0
- package/dist/src/features/tool/canvas-recovery.js +13 -30
- package/dist/src/features/tool/canvas-results.js +92 -93
- package/dist/src/features/tool/canvas-tool-adapter.js +134 -157
- package/dist/src/features/tool/canvas-video.js +44 -37
- package/dist/src/features/tool/catalog.js +2 -23
- package/dist/src/features/tool/dynamic-schema.js +42 -46
- package/dist/src/features/tool/ffprobe-executable.js +21 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +61 -24
- package/dist/src/features/tool/resource-authorizer.js +11 -3
- package/dist/src/features/tool/tool-api-adapter.js +73 -82
- package/dist/src/features/tool/tool-definitions.js +23 -0
- package/dist/src/features/tool/tool-errors.js +25 -0
- package/dist/src/features/tool/tool-output.js +15 -0
- package/dist/src/features/tool/use-cases.js +74 -98
- package/dist/src/features/update/package-manager.js +124 -0
- package/dist/src/features/update/update-service.js +195 -55
- package/dist/src/platform/detached-spawn.js +9 -0
- package/dist/src/platform/file-lock.js +12 -4
- package/dist/src/platform/input-uri.js +23 -1
- package/dist/src/platform/local-json-file.js +97 -15
- package/dist/src/platform/media-type.js +46 -0
- package/dist/src/platform/open-browser.js +5 -2
- package/dist/src/platform/public-url.js +35 -0
- package/dist/src/platform/remote-error-evidence.js +33 -6
- package/dist/src/platform/resource-auth-key.js +35 -1
- package/dist/src/platform/safe-upload-file.js +38 -44
- package/dist/src/platform/schema-compiler.js +16 -0
- package/dist/src/platform/signature.js +2 -2
- package/dist/src/platform/signed-http-transport.js +4 -1
- package/dist/src/platform/url-safety.js +6 -1
- package/dist/src/platform/webm-header.js +41 -0
- package/dist/src/platform/windows-acl/LICENSE-mingw-w64 +43 -0
- package/dist/src/platform/windows-acl/arm64.node +0 -0
- package/dist/src/platform/windows-acl/ia32.node +0 -0
- package/dist/src/platform/windows-acl/x64.node +0 -0
- package/dist/src/platform/windows-host-job/arm64.exe +0 -0
- package/dist/src/platform/windows-host-job/ia32.exe +0 -0
- package/dist/src/platform/windows-host-job/sha256.json +7 -0
- package/dist/src/platform/windows-host-job/x64.exe +0 -0
- package/dist/src/platform/windows-private-state.js +72 -0
- package/dist/src/product/config.js +1 -1
- package/dist/src/telemetry/command-route.js +38 -0
- package/dist/src/telemetry/command-routes.json +1 -0
- package/dist/src/telemetry/failure-summary.js +3 -3
- package/dist/src/telemetry/invocation.js +1 -2
- package/dist/src/telemetry/process-errors.js +17 -33
- package/dist/src/telemetry/sanitize.js +19 -4
- package/dist/src/telemetry/sls-sink.js +45 -20
- package/package.json +4 -4
- package/skills/gd-cli/SKILL.md +18 -5
- package/skills/gd-cli/references/agent.md +9 -4
- package/skills/gd-cli/references/creation.md +3 -1
- package/skills/gd-cli/references/editor.md +7 -5
- package/skills/gd-cli/references/errors.md +19 -8
- package/skills/gd-cli/references/matting.md +3 -5
- package/skills/gd-cli/references/media-tools.md +10 -4
- package/skills/gd-cli/references/tool.md +9 -15
|
@@ -375,36 +375,14 @@ function parseQuestionPart(message) {
|
|
|
375
375
|
}
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
-
function
|
|
379
|
-
const texts = new Set();
|
|
380
|
-
const urls = new Set();
|
|
381
|
-
return parts.filter((part) => {
|
|
382
|
-
if ("text" in part) {
|
|
383
|
-
if (texts.has(part.text))
|
|
384
|
-
return false;
|
|
385
|
-
texts.add(part.text);
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
if ("url" in part) {
|
|
389
|
-
if (urls.has(part.url))
|
|
390
|
-
return false;
|
|
391
|
-
urls.add(part.url);
|
|
392
|
-
}
|
|
393
|
-
return true;
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
export function normalizeCreativeMessages(messages, onUsageModelMissing) {
|
|
378
|
+
export function normalizeCreativeMessages(messages, onUsageModelMissing, onUsageAmountMissing) {
|
|
397
379
|
const contextId = creativeContextId(messages);
|
|
398
380
|
const latest = new Map();
|
|
399
|
-
const anonymous = [];
|
|
400
381
|
for (const message of messages) {
|
|
401
382
|
const id = nonEmptyString(message.message_id);
|
|
402
|
-
|
|
403
|
-
anonymous.push(message);
|
|
404
|
-
else
|
|
405
|
-
latest.set(id, message);
|
|
383
|
+
latest.set(id ?? Symbol(), message);
|
|
406
384
|
}
|
|
407
|
-
const normalized = [...latest.values()
|
|
385
|
+
const normalized = [...latest.values()];
|
|
408
386
|
const parts = [];
|
|
409
387
|
for (const message of normalized) {
|
|
410
388
|
if (hasHiddenTransportRole(message))
|
|
@@ -434,7 +412,7 @@ export function normalizeCreativeMessages(messages, onUsageModelMissing) {
|
|
|
434
412
|
return fail();
|
|
435
413
|
parts.push(parseQuestionPart(question));
|
|
436
414
|
}
|
|
437
|
-
const publicParts =
|
|
415
|
+
const publicParts = parts;
|
|
438
416
|
if (publicParts.length === 0)
|
|
439
417
|
return fail("AGENT_RESULT_EMPTY", { messageCount: normalized.length, publicPartCount: 0 });
|
|
440
418
|
const usageItems = [];
|
|
@@ -444,10 +422,11 @@ export function normalizeCreativeMessages(messages, onUsageModelMissing) {
|
|
|
444
422
|
continue;
|
|
445
423
|
const extra = record(message.extra);
|
|
446
424
|
const amount = extra?.deduct_points;
|
|
447
|
-
if (amount
|
|
425
|
+
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0) {
|
|
426
|
+
if (amount !== undefined || (nonEmptyString(extra?.task_id) && nonEmptyString(extra?.scene_code)))
|
|
427
|
+
onUsageAmountMissing?.();
|
|
448
428
|
continue;
|
|
449
|
-
|
|
450
|
-
return fail();
|
|
429
|
+
}
|
|
451
430
|
totalCost += amount;
|
|
452
431
|
const model = nonEmptyString(extra?.scene_code);
|
|
453
432
|
if (model === undefined) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
2
|
-
|
|
2
|
+
import { isFilemsResource, withFilemsAuthKey } from "../../platform/resource-auth-key.js";
|
|
3
|
+
function privateResource(value, refreshSigned) {
|
|
3
4
|
let url;
|
|
4
5
|
try {
|
|
5
6
|
url = new URL(value);
|
|
@@ -7,34 +8,41 @@ function unsignedPrivateUrl(value) {
|
|
|
7
8
|
catch {
|
|
8
9
|
throw new RemoteProtocolError();
|
|
9
10
|
}
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
if (url.protocol !== "https:" || url.username !== "" || url.password !== ""
|
|
18
|
-
|| url.port !== "")
|
|
19
|
-
throw new RemoteProtocolError();
|
|
20
|
-
return url;
|
|
11
|
+
const signed = !!url.searchParams.get("auth_key")?.trim();
|
|
12
|
+
if (signed && !refreshSigned)
|
|
13
|
+
return;
|
|
14
|
+
// An existing link outside the authorized origin is opaque. Never attach our token.
|
|
15
|
+
if (signed && (url.protocol !== "https:" || url.username || url.password || url.port))
|
|
16
|
+
return;
|
|
17
|
+
return isFilemsResource(url) ? { signed } : undefined;
|
|
21
18
|
}
|
|
22
19
|
export function createAgentResourceAuthorizer(dependencies) {
|
|
23
20
|
return {
|
|
24
|
-
async authorize(output, access, signal) {
|
|
21
|
+
async authorize(output, access, signal, _observe, hasOtherContent) {
|
|
25
22
|
signal.throwIfAborted();
|
|
26
|
-
const urls = output.message.parts.map((part) => ("url" in part ?
|
|
23
|
+
const urls = output.message.parts.map((part) => ("url" in part ? privateResource(part.url, !!dependencies.onSignedRefreshFailure) : undefined));
|
|
27
24
|
if (urls.every((url) => url === undefined))
|
|
28
25
|
return output;
|
|
29
26
|
// One token serves this result only; do not retain it across identities or commands.
|
|
30
|
-
|
|
27
|
+
let authKey;
|
|
28
|
+
try {
|
|
29
|
+
authKey = await dependencies.authKeys.getAuthKey(access, signal);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
signal.throwIfAborted();
|
|
33
|
+
if (urls.every(url => !url || url.signed) && dependencies.onSignedRefreshFailure?.(error))
|
|
34
|
+
return output;
|
|
35
|
+
if (urls.some(url => url && !url.signed) && (hasOtherContent || urls.some(url => !url || url.signed))
|
|
36
|
+
&& dependencies.onPartialResourceFailure?.(error))
|
|
37
|
+
return output;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
31
40
|
signal.throwIfAborted();
|
|
32
41
|
const parts = output.message.parts.map((part, index) => {
|
|
33
42
|
const url = urls[index];
|
|
34
43
|
if (url === undefined || !("url" in part))
|
|
35
44
|
return part;
|
|
36
|
-
url.
|
|
37
|
-
return { ...part, url: url.href };
|
|
45
|
+
return { ...part, url: withFilemsAuthKey(part.url, authKey) };
|
|
38
46
|
});
|
|
39
47
|
return {
|
|
40
48
|
...output,
|
|
@@ -1,32 +1,49 @@
|
|
|
1
|
+
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
1
2
|
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
2
3
|
import { creativeTurnMessages, normalizeCreativeMessages } from "./creative-protocol.js";
|
|
3
4
|
/** History is a snapshot, not proof that this particular invocation finished. */
|
|
4
5
|
export async function readAgentResult(transport, request) {
|
|
5
6
|
const path = `/ai-agent/v1/thread/${encodeURIComponent(request.contextId)}`;
|
|
6
|
-
const access = { credential: request.credential, signal: request.signal,
|
|
7
|
+
const access = { credential: request.credential, signal: request.signal, sensitiveResponse: true,
|
|
7
8
|
...(request.organizationId === undefined ? {} : { organizationId: request.organizationId }) };
|
|
8
9
|
const messages = await transport.getJson({ ...access, path: `${path}/messages` });
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
let connectionState = "unknown";
|
|
11
|
+
let connectionError;
|
|
12
|
+
try {
|
|
13
|
+
const connection = await transport.getJson({ ...access, path: `${path}/connection` });
|
|
14
|
+
if (connection && typeof connection === "object" && "state" in connection && typeof connection.state === "string")
|
|
15
|
+
connectionState = connection.state;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
request.signal.throwIfAborted();
|
|
19
|
+
if (error instanceof RemoteRequestError && (error.status === 401 || error.status === 403))
|
|
20
|
+
throw error;
|
|
21
|
+
connectionError = error;
|
|
22
|
+
}
|
|
14
23
|
if (!Array.isArray(messages))
|
|
15
24
|
throw new RemoteProtocolError();
|
|
16
25
|
if (!messages.some(m => m && typeof m === "object" && m.local_message_id === request.localMessageId)) {
|
|
17
|
-
|
|
26
|
+
if (connectionError)
|
|
27
|
+
throw connectionError;
|
|
28
|
+
return { connectionState };
|
|
18
29
|
}
|
|
19
30
|
const turn = creativeTurnMessages(messages, request.localMessageId);
|
|
20
|
-
if (!turn.some(m => m.role !== "user" && m.content))
|
|
21
|
-
|
|
31
|
+
if (!turn.some(m => m.role !== "user" && m.content)) {
|
|
32
|
+
if (connectionError)
|
|
33
|
+
throw connectionError;
|
|
34
|
+
return { connectionState };
|
|
35
|
+
}
|
|
22
36
|
try {
|
|
23
|
-
let usageModelMissing = false;
|
|
24
|
-
const partialResult = normalizeCreativeMessages(turn, () => { usageModelMissing = true; });
|
|
25
|
-
return { connectionState
|
|
37
|
+
let usageModelMissing = false, usageAmountMissing = false;
|
|
38
|
+
const partialResult = normalizeCreativeMessages(turn, () => { usageModelMissing = true; }, () => { usageAmountMissing = true; });
|
|
39
|
+
return { connectionState, partialResult, ...(usageModelMissing ? { usageModelMissing: true } : {}), ...(usageAmountMissing ? { usageAmountMissing: true } : {}) };
|
|
26
40
|
}
|
|
27
41
|
catch (error) {
|
|
28
|
-
if (error instanceof RemoteProtocolError)
|
|
29
|
-
|
|
42
|
+
if (error instanceof RemoteProtocolError) {
|
|
43
|
+
if (connectionError)
|
|
44
|
+
throw connectionError;
|
|
45
|
+
return { connectionState };
|
|
46
|
+
}
|
|
30
47
|
throw error;
|
|
31
48
|
}
|
|
32
49
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { mediaFilename, mediaTypeFromFilename } from "../../platform/media-type.js";
|
|
1
2
|
import { canvasModelBindings, canvasRemoteControlArguments } from "../tool/canvas-models.js";
|
|
2
|
-
import {
|
|
3
|
+
import { parseHttpAssetUrl, UrlSafetyError } from "../../platform/url-safety.js";
|
|
3
4
|
export class AgentInputError extends Error {
|
|
4
5
|
reason;
|
|
5
6
|
field;
|
|
@@ -10,33 +11,6 @@ export class AgentInputError extends Error {
|
|
|
10
11
|
this.name = "AgentInputError";
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
const mediaTypes = {
|
|
14
|
-
avif: "image/avif",
|
|
15
|
-
gif: "image/gif",
|
|
16
|
-
heic: "image/heic",
|
|
17
|
-
jpeg: "image/jpeg",
|
|
18
|
-
jpg: "image/jpeg",
|
|
19
|
-
mp4: "video/mp4",
|
|
20
|
-
png: "image/png",
|
|
21
|
-
webp: "image/webp"
|
|
22
|
-
};
|
|
23
|
-
function pathnameFilename(url) {
|
|
24
|
-
const segment = url.pathname.split("/").filter(Boolean).at(-1);
|
|
25
|
-
if (segment === undefined)
|
|
26
|
-
return "creative-media";
|
|
27
|
-
try {
|
|
28
|
-
return decodeURIComponent(segment) || "creative-media";
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return segment;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function inferMediaType(filename) {
|
|
35
|
-
const extension = filename.split(".").at(-1)?.toLowerCase();
|
|
36
|
-
return extension === undefined || extension === filename.toLowerCase()
|
|
37
|
-
? "application/octet-stream"
|
|
38
|
-
: mediaTypes[extension] ?? "application/octet-stream";
|
|
39
|
-
}
|
|
40
14
|
export function createAgentUseCases(dependencies) {
|
|
41
15
|
async function prepare({ input, access, signal }) {
|
|
42
16
|
signal.throwIfAborted();
|
|
@@ -77,19 +51,20 @@ export function createAgentUseCases(dependencies) {
|
|
|
77
51
|
}
|
|
78
52
|
let url;
|
|
79
53
|
try {
|
|
80
|
-
url =
|
|
54
|
+
url = parseHttpAssetUrl(part.url);
|
|
81
55
|
}
|
|
82
56
|
catch (error) {
|
|
83
57
|
if (error instanceof UrlSafetyError)
|
|
84
58
|
throw new AgentInputError("invalid_asset_url", `/message/parts/${input.message.parts.indexOf(part)}/url`, error);
|
|
85
59
|
throw error;
|
|
86
60
|
}
|
|
87
|
-
const
|
|
61
|
+
const urlFilename = mediaFilename(url);
|
|
62
|
+
const filename = part.filename ?? urlFilename;
|
|
88
63
|
prepared.push({
|
|
89
64
|
kind: "asset",
|
|
90
65
|
asset: {
|
|
91
66
|
url: part.url,
|
|
92
|
-
mediaType: part.mediaType ??
|
|
67
|
+
mediaType: part.mediaType ?? mediaTypeFromFilename(filename) ?? mediaTypeFromFilename(urlFilename) ?? "application/octet-stream",
|
|
93
68
|
filename,
|
|
94
69
|
fromUserUpload: false
|
|
95
70
|
},
|
|
@@ -5,6 +5,7 @@ import { AuthStateInvalidError, AuthStateUnavailableError, parseStoredAuthState
|
|
|
5
5
|
export function createLocalCredentialStore(options = {}) {
|
|
6
6
|
const file = options.file ?? createLocalJsonFile({
|
|
7
7
|
directory: join(options.homeDirectory ?? homedir(), options.stateDirectory ?? ".gd"),
|
|
8
|
+
protectWindowsAcl: true,
|
|
8
9
|
filename: "credentials.json",
|
|
9
10
|
role: "credentials"
|
|
10
11
|
});
|
|
@@ -2,6 +2,31 @@ import { withResponseDiagnostics } from "../../platform/signed-http-transport.js
|
|
|
2
2
|
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
3
3
|
import { availableCreditAmount, creditAmountNumber, readCreditAmount, sumCreditAmounts } from "./amount.js";
|
|
4
4
|
import { parseCreditsResponse } from "./response.js";
|
|
5
|
+
export class CreditsPageCursorError extends RemoteProtocolError {
|
|
6
|
+
partialResult;
|
|
7
|
+
constructor(partialResult) {
|
|
8
|
+
super({}, undefined, "CREDITS_NEXT_CURSOR_MISSING");
|
|
9
|
+
this.partialResult = partialResult;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function readableRows(values, project, warning) {
|
|
13
|
+
const kept = [];
|
|
14
|
+
for (const row of values) {
|
|
15
|
+
try {
|
|
16
|
+
kept.push(project(row));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (!(error instanceof RemoteProtocolError))
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (kept.length !== values.length) {
|
|
24
|
+
if (!kept.length)
|
|
25
|
+
throw new RemoteProtocolError({}, undefined, "CREDITS_NO_READABLE_ROWS");
|
|
26
|
+
warning?.();
|
|
27
|
+
}
|
|
28
|
+
return kept;
|
|
29
|
+
}
|
|
5
30
|
export function createCreditsUseCases(options) {
|
|
6
31
|
return {
|
|
7
32
|
async get(input) {
|
|
@@ -18,7 +43,7 @@ export function createCreditsUseCases(options) {
|
|
|
18
43
|
const total = readCreditAmount(source.total);
|
|
19
44
|
const used = readCreditAmount(source.used);
|
|
20
45
|
const pending = readCreditAmount(source.wait);
|
|
21
|
-
const identifier = optionalString(source.identifier);
|
|
46
|
+
const identifier = optionalString(source.identifier, options.onPartial);
|
|
22
47
|
const memberPeriodLimit = source.member_period_limit == null ? undefined : amount(source.member_period_limit);
|
|
23
48
|
return { ...(identifier === undefined ? {} : { identifier }), total, used, pending,
|
|
24
49
|
...(memberPeriodLimit === undefined ? {} : { memberPeriodLimit }) };
|
|
@@ -51,16 +76,14 @@ export function createCreditsUseCases(options) {
|
|
|
51
76
|
});
|
|
52
77
|
if (!isRecord(body) || !Array.isArray(body.items) || typeof body.has_more !== "boolean")
|
|
53
78
|
throw new RemoteProtocolError();
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
nextCursor: body.has_more ? cursor : null
|
|
63
|
-
};
|
|
79
|
+
const page = { unit: options.billingUnit, range: { from: normalized.from, to: normalized.to },
|
|
80
|
+
items: readableRows(body.items, item => readUsageRecord(item, options.onPartial), options.onPartial), hasMore: body.has_more };
|
|
81
|
+
if (!body.has_more)
|
|
82
|
+
return { ...page, nextCursor: null };
|
|
83
|
+
const cursor = body.next_cursor;
|
|
84
|
+
if (typeof cursor !== "string" || !cursor.trim())
|
|
85
|
+
throw new CreditsPageCursorError(page);
|
|
86
|
+
return { ...page, nextCursor: cursor };
|
|
64
87
|
});
|
|
65
88
|
},
|
|
66
89
|
async getUsage({ input, ...access }) {
|
|
@@ -77,14 +100,14 @@ export function createCreditsUseCases(options) {
|
|
|
77
100
|
return {
|
|
78
101
|
id: input.id,
|
|
79
102
|
unit: options.billingUnit,
|
|
80
|
-
breakdown: body.usage_logs
|
|
103
|
+
breakdown: readableRows(body.usage_logs, value => {
|
|
81
104
|
if (!isRecord(value))
|
|
82
105
|
throw new RemoteProtocolError();
|
|
83
|
-
const usageType = optionalNumber(value.usage_type);
|
|
84
|
-
const sourceType = optionalString(value.source_type);
|
|
106
|
+
const usageType = optionalNumber(value.usage_type, options.onPartial);
|
|
107
|
+
const sourceType = optionalString(value.source_type, options.onPartial);
|
|
85
108
|
return { amount: amount(value.usage), ...(usageType === undefined ? {} : { usageType }),
|
|
86
109
|
...(sourceType === undefined ? {} : { sourceType }) };
|
|
87
|
-
})
|
|
110
|
+
}, options.onPartial)
|
|
88
111
|
};
|
|
89
112
|
});
|
|
90
113
|
}
|
|
@@ -118,7 +141,7 @@ function findCreditsRecords(value) {
|
|
|
118
141
|
throw new RemoteProtocolError();
|
|
119
142
|
return [record];
|
|
120
143
|
}
|
|
121
|
-
function readUsageRecord(value) {
|
|
144
|
+
function readUsageRecord(value, warn) {
|
|
122
145
|
if (!isRecord(value))
|
|
123
146
|
throw new RemoteProtocolError();
|
|
124
147
|
let recordedAt;
|
|
@@ -128,12 +151,12 @@ function readUsageRecord(value) {
|
|
|
128
151
|
catch {
|
|
129
152
|
throw new RemoteProtocolError();
|
|
130
153
|
}
|
|
131
|
-
const recordMode = optionalString(value.record_mode);
|
|
132
|
-
const description = optionalString(value.consume_desc);
|
|
133
|
-
const scene = optionalNumber(value.consume_scene);
|
|
134
|
-
const referenceId = optionalString(value.reference_id);
|
|
135
|
-
const userId = optionalString(value.uc_id);
|
|
136
|
-
const userName = optionalString(value.user_name);
|
|
154
|
+
const recordMode = optionalString(value.record_mode, warn);
|
|
155
|
+
const description = optionalString(value.consume_desc, warn);
|
|
156
|
+
const scene = optionalNumber(value.consume_scene, warn);
|
|
157
|
+
const referenceId = optionalString(value.reference_id, warn);
|
|
158
|
+
const userId = optionalString(value.uc_id, warn);
|
|
159
|
+
const userName = optionalString(value.user_name, warn);
|
|
137
160
|
return {
|
|
138
161
|
id: requiredString(value.record_id), changeType: requiredString(value.change_type),
|
|
139
162
|
amount: amount(value.usage), recordedAt,
|
|
@@ -152,18 +175,22 @@ function requiredString(value) {
|
|
|
152
175
|
throw new RemoteProtocolError();
|
|
153
176
|
return value;
|
|
154
177
|
}
|
|
155
|
-
function optionalString(value) {
|
|
178
|
+
function optionalString(value, warn) {
|
|
156
179
|
if (value == null)
|
|
157
180
|
return undefined;
|
|
158
|
-
if (typeof value !== "string")
|
|
159
|
-
|
|
181
|
+
if (typeof value !== "string") {
|
|
182
|
+
warn?.();
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
160
185
|
return value;
|
|
161
186
|
}
|
|
162
|
-
function optionalNumber(value) {
|
|
187
|
+
function optionalNumber(value, warn) {
|
|
163
188
|
if (value == null)
|
|
164
189
|
return undefined;
|
|
165
|
-
if (typeof value !== "number" || !Number.isFinite(value))
|
|
166
|
-
|
|
190
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
191
|
+
warn?.();
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
167
194
|
return value;
|
|
168
195
|
}
|
|
169
196
|
function timestamp(value) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { filterUrlParameters } from "../../platform/public-url.js";
|
|
2
2
|
import { parseSafeRemoteAssetUrl } from "../../platform/url-safety.js";
|
|
3
3
|
const sourcePresence = new WeakMap();
|
|
4
4
|
/** Internal presence evidence survives public URL safety filtering without exposing the URL. */
|
|
@@ -91,11 +91,8 @@ function safePublicUrl(value) {
|
|
|
91
91
|
return undefined;
|
|
92
92
|
try {
|
|
93
93
|
const url = parseSafeRemoteAssetUrl(raw);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
url.searchParams.delete(key);
|
|
97
|
-
}
|
|
98
|
-
return url.href;
|
|
94
|
+
const publicUrl = filterUrlParameters(url);
|
|
95
|
+
return publicUrl.href === url.href ? raw : publicUrl.href;
|
|
99
96
|
}
|
|
100
97
|
catch {
|
|
101
98
|
return undefined;
|
|
@@ -45,6 +45,8 @@ function nonblank(value) {
|
|
|
45
45
|
function finiteNumber(value) {
|
|
46
46
|
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
47
47
|
}
|
|
48
|
+
// 2.1.x promises numeric tag/folder counts. An omitted count deliberately remains 0 for compatibility.
|
|
49
|
+
// This exception does not apply to prices, usage, or balances.
|
|
48
50
|
function nonnegativeInteger(value) {
|
|
49
51
|
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : 0;
|
|
50
52
|
}
|
|
@@ -61,10 +63,16 @@ function optionalString(value) {
|
|
|
61
63
|
const projected = String(value);
|
|
62
64
|
return projected.trim() === "" ? undefined : projected;
|
|
63
65
|
}
|
|
64
|
-
function
|
|
66
|
+
function warnSkipped(total, kept, warn) {
|
|
67
|
+
if (total > 0 && !kept)
|
|
68
|
+
throw new RemoteProtocolError({}, undefined, "DAM_NO_READABLE_ROWS");
|
|
69
|
+
if (total > kept)
|
|
70
|
+
warn?.(total - kept);
|
|
71
|
+
}
|
|
72
|
+
function folderRows(value, warn) {
|
|
65
73
|
if (!Array.isArray(value))
|
|
66
74
|
throw new RemoteProtocolError();
|
|
67
|
-
|
|
75
|
+
const result = value.flatMap((candidate) => {
|
|
68
76
|
const item = record(candidate);
|
|
69
77
|
const folderId = nonblank(item?.id);
|
|
70
78
|
const title = nonblank(item?.title);
|
|
@@ -92,6 +100,8 @@ function folderRows(value) {
|
|
|
92
100
|
...(updatedAt === undefined ? {} : { updated_at: updatedAt })
|
|
93
101
|
}];
|
|
94
102
|
});
|
|
103
|
+
warnSkipped(value.length, result.length, warn);
|
|
104
|
+
return result;
|
|
95
105
|
}
|
|
96
106
|
function folderPagination(headers) {
|
|
97
107
|
const raw = headers.get("x-pagination");
|
|
@@ -109,16 +119,16 @@ function folderPagination(headers) {
|
|
|
109
119
|
const pageSize = pagination?.size;
|
|
110
120
|
const total = pagination?.total;
|
|
111
121
|
if (!Number.isInteger(page) || page < 1
|
|
112
|
-
|| !Number.isInteger(pageSize) || pageSize < 1
|
|
122
|
+
|| !Number.isInteger(pageSize) || pageSize < 1
|
|
113
123
|
|| !Number.isInteger(total) || total < 0) {
|
|
114
124
|
throw new RemoteProtocolError();
|
|
115
125
|
}
|
|
116
126
|
return { page: page, pageSize: pageSize, total: total };
|
|
117
127
|
}
|
|
118
|
-
function tagRows(value) {
|
|
128
|
+
function tagRows(value, warn) {
|
|
119
129
|
if (!Array.isArray(value))
|
|
120
130
|
throw new RemoteProtocolError();
|
|
121
|
-
|
|
131
|
+
const result = value.flatMap((candidate) => {
|
|
122
132
|
const item = record(candidate);
|
|
123
133
|
const tagId = nonblank(item?.id);
|
|
124
134
|
const name = nonblank(item?.name);
|
|
@@ -132,6 +142,8 @@ function tagRows(value) {
|
|
|
132
142
|
asset_count: nonnegativeInteger(item?.file_count)
|
|
133
143
|
}];
|
|
134
144
|
});
|
|
145
|
+
warnSkipped(value.length, result.length, warn);
|
|
146
|
+
return result;
|
|
135
147
|
}
|
|
136
148
|
function downloadUrls(value, headers, status) {
|
|
137
149
|
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
@@ -321,7 +333,7 @@ function firstValue(response, keys) {
|
|
|
321
333
|
}
|
|
322
334
|
return undefined;
|
|
323
335
|
}
|
|
324
|
-
function searchResult(response, input) {
|
|
336
|
+
function searchResult(response, input, warn, warnPagination) {
|
|
325
337
|
const items = searchItems(response);
|
|
326
338
|
if (items === undefined)
|
|
327
339
|
throw new RemoteRequestError();
|
|
@@ -329,13 +341,16 @@ function searchResult(response, input) {
|
|
|
329
341
|
const asset = projectDamAssetSummary(item);
|
|
330
342
|
return asset === undefined ? [] : [asset];
|
|
331
343
|
});
|
|
344
|
+
warnSkipped(items.length, assets.length, warn);
|
|
332
345
|
const suppliedTotal = finiteNumber(firstValue(response, ["total", "count"]));
|
|
333
|
-
const
|
|
346
|
+
const knownTotal = suppliedTotal !== undefined && suppliedTotal >= 0;
|
|
347
|
+
const total = knownTotal ? suppliedTotal : items.length;
|
|
334
348
|
const suppliedFinish = firstValue(response, ["finish"]);
|
|
335
|
-
const finish = typeof suppliedFinish === "boolean"
|
|
336
|
-
? suppliedFinish
|
|
337
|
-
: items.length >= total;
|
|
338
349
|
const cursor = nonblank(firstValue(response, ["query_id", "cursor"]));
|
|
350
|
+
const finish = typeof suppliedFinish === "boolean" ? suppliedFinish
|
|
351
|
+
: knownTotal ? items.length >= total : cursor === undefined;
|
|
352
|
+
if (!knownTotal || typeof suppliedFinish !== "boolean")
|
|
353
|
+
warnPagination?.();
|
|
339
354
|
return {
|
|
340
355
|
repository_ids: input.repositoryIds,
|
|
341
356
|
page_size: input.pageSize,
|
|
@@ -378,16 +393,16 @@ export function createDamApiAdapter(dependencies) {
|
|
|
378
393
|
...(input.type === undefined
|
|
379
394
|
? {}
|
|
380
395
|
: { content_format_list: contentFormats[input.type] }),
|
|
381
|
-
...(input.assetFormats === undefined
|
|
396
|
+
...(input.assetFormats === undefined
|
|
382
397
|
? {}
|
|
383
398
|
: { format: input.assetFormats }),
|
|
384
|
-
...(input.tagIds === undefined
|
|
399
|
+
...(input.tagIds === undefined
|
|
385
400
|
? {}
|
|
386
401
|
: { tag_ids: input.tagIds })
|
|
387
402
|
},
|
|
388
403
|
...requestContext(input)
|
|
389
404
|
});
|
|
390
|
-
return searchResult(response, input);
|
|
405
|
+
return searchResult(response, input, dependencies.onPartial, dependencies.onPaginationFallback);
|
|
391
406
|
},
|
|
392
407
|
async listFolders(input) {
|
|
393
408
|
const response = await dependencies.transport.getJsonResponse({
|
|
@@ -411,7 +426,7 @@ export function createDamApiAdapter(dependencies) {
|
|
|
411
426
|
page: pagination.page,
|
|
412
427
|
page_size: pagination.pageSize,
|
|
413
428
|
total: pagination.total,
|
|
414
|
-
folders: folderRows(response.body)
|
|
429
|
+
folders: folderRows(response.body, dependencies.onPartial)
|
|
415
430
|
};
|
|
416
431
|
},
|
|
417
432
|
async listTags(input) {
|
|
@@ -424,7 +439,7 @@ export function createDamApiAdapter(dependencies) {
|
|
|
424
439
|
},
|
|
425
440
|
...requestContext(input)
|
|
426
441
|
});
|
|
427
|
-
return { repository_id: input.repositoryId, tags: tagRows(response) };
|
|
442
|
+
return { repository_id: input.repositoryId, tags: tagRows(response, dependencies.onPartial) };
|
|
428
443
|
},
|
|
429
444
|
async getDownloadUrls(input) {
|
|
430
445
|
const assetId = normalizeDamAssetId(input.assetId);
|
|
@@ -3,7 +3,6 @@ import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
|
3
3
|
import { createHmac } from "node:crypto";
|
|
4
4
|
import { createReadStream } from "node:fs";
|
|
5
5
|
import { stat } from "node:fs/promises";
|
|
6
|
-
import OSS from "ali-oss";
|
|
7
6
|
export class ObjectStorageUploadError extends Error {
|
|
8
7
|
constructor(cause) {
|
|
9
8
|
super("素材上传失败。", { cause });
|
|
@@ -63,6 +62,8 @@ function sleepWithSignal(milliseconds, signal) {
|
|
|
63
62
|
});
|
|
64
63
|
}
|
|
65
64
|
const defaultPutOss = async (input) => {
|
|
65
|
+
input.signal.throwIfAborted();
|
|
66
|
+
const { default: OSS } = await import("ali-oss");
|
|
66
67
|
input.signal.throwIfAborted();
|
|
67
68
|
const client = new OSS({
|
|
68
69
|
accessKeyId: input.token.accessKeyId,
|
|
@@ -77,12 +77,18 @@ function enterpriseRepositories(value) {
|
|
|
77
77
|
}];
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
export function normalizeRepositoryCatalog(privateRows, teamRows, enterpriseRows) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
export function normalizeRepositoryCatalog(privateRows, teamRows, enterpriseRows, onUnrepresented) {
|
|
81
|
+
const personal = privateRepositories(privateRows), teams = teamRepositories(teamRows), enterprise = enterpriseRepositories(enterpriseRows);
|
|
82
|
+
const groups = [
|
|
83
|
+
["personal", rows(privateRows).filter(row => record(row)?.type !== 8).length, personal.length],
|
|
84
|
+
["team", rows(teamRows).length, teams.length], ["enterprise", rows(enterpriseRows).length, enterprise.length]
|
|
85
85
|
];
|
|
86
|
+
const incomplete = groups.filter(([, total, count]) => total > count);
|
|
87
|
+
const merged = [...personal, ...teams, ...enterprise];
|
|
88
|
+
if (incomplete.length && !merged.length)
|
|
89
|
+
throw new RemoteProtocolError({}, undefined, "DAM_NO_READABLE_REPOSITORIES");
|
|
90
|
+
for (const [source] of incomplete)
|
|
91
|
+
onUnrepresented?.(source);
|
|
86
92
|
const seen = new Set();
|
|
87
93
|
const unique = merged.filter((repository) => {
|
|
88
94
|
if (seen.has(repository.repository_id))
|
|
@@ -91,7 +97,7 @@ export function normalizeRepositoryCatalog(privateRows, teamRows, enterpriseRows
|
|
|
91
97
|
return true;
|
|
92
98
|
});
|
|
93
99
|
const defaultIndex = unique.findIndex((repository) => repository.type === "personal");
|
|
94
|
-
const selectedIndex = defaultIndex === -1 && unique.length > 0 ? 0 : defaultIndex;
|
|
100
|
+
const selectedIndex = defaultIndex === -1 && !incomplete.length && unique.length > 0 ? 0 : defaultIndex;
|
|
95
101
|
return unique.map((repository, index) => ({
|
|
96
102
|
...repository,
|
|
97
103
|
is_default: index === selectedIndex
|
|
@@ -107,21 +113,24 @@ function requestContext(input) {
|
|
|
107
113
|
export function createDamRepositoryCatalog(dependencies) {
|
|
108
114
|
return {
|
|
109
115
|
async list(input) {
|
|
110
|
-
const [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
const sources = ["/tb-dam/repositories", "/tb-dam/teams", "/dam/org-repositories"];
|
|
117
|
+
const results = await Promise.allSettled(sources.map(async (path) => rows(await dependencies.transport.getJson({
|
|
118
|
+
path, ...requestContext(input)
|
|
119
|
+
}))));
|
|
120
|
+
input.signal.throwIfAborted();
|
|
121
|
+
const failures = results.flatMap((r, i) => r.status === "rejected" ? [{ i, error: r.reason }] : []);
|
|
122
|
+
const [p, t, e] = results.map(r => r.status === "fulfilled" ? r.value : []);
|
|
123
|
+
const repositories = normalizeRepositoryCatalog(p, t, e, dependencies.onPartial);
|
|
124
|
+
if (failures.length && !repositories.length)
|
|
125
|
+
throw failures[0].error;
|
|
126
|
+
for (const failure of failures)
|
|
127
|
+
dependencies.onPartial?.(["personal", "team", "enterprise"][failure.i]);
|
|
128
|
+
if (failures.length && !repositories.some(r => r.type === "personal")) {
|
|
129
|
+
if (!input.allowPartial)
|
|
130
|
+
throw failures[0].error;
|
|
131
|
+
return repositories.map(r => ({ ...r, is_default: false }));
|
|
132
|
+
}
|
|
133
|
+
return repositories;
|
|
125
134
|
}
|
|
126
135
|
};
|
|
127
136
|
}
|