@insmind/cli 2.1.0 → 2.1.1
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/contracts/operations/agent.send/input.schema.json +1 -77
- package/contracts/operations/dam.folder.list/input.schema.json +0 -1
- package/contracts/operations/dam.folder.list/output.schema.json +1 -2
- package/contracts/operations/dam.list/input.schema.json +3 -6
- package/contracts/operations/dam.list/output.schema.json +1 -2
- package/contracts/operations/dam.search/input.schema.json +3 -6
- package/contracts/operations/dam.search/output.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-edit-smart.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-expand-smart.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-layers-smart.schema.json +1 -3
- package/contracts/operations/tool.call/models/video-edit-smart.schema.json +0 -3
- package/contracts/operations/tool.call/ocr-payload.schema.json +4 -5
- package/dist/bin/postinstall.js +22 -6
- package/dist/bin/task-worker.js +2 -2
- package/dist/src/bootstrap/create-cli.js +13 -6
- package/dist/src/bootstrap/create-runtime.js +98 -28
- package/dist/src/bootstrap/run-task-worker.js +6 -2
- package/dist/src/bootstrap/validators.js +1 -1
- package/dist/src/cli/action-binding.js +14 -37
- package/dist/src/cli/agent-commands.js +11 -11
- 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 +7 -5
- package/dist/src/cli/errors.js +81 -22
- package/dist/src/cli/host-input.js +64 -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/task-commands.js +6 -2
- package/dist/src/cli/tool-commands.js +12 -11
- 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/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/repository-catalog.js +30 -21
- package/dist/src/features/dam/use-cases.js +12 -7
- package/dist/src/features/editor/bridge-client.js +0 -2
- package/dist/src/features/editor/public-url.js +1 -36
- 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 +37 -10
- package/dist/src/features/task/task-background.js +5 -2
- 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 +100 -52
- 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 +79 -87
- 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/dynamic-schema.js +39 -40
- 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-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/update-service.js +95 -21
- package/dist/src/platform/media-type.js +46 -0
- 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 +36 -41
- 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/telemetry/command-route.js +38 -0
- package/dist/src/telemetry/command-routes.json +1 -0
- package/dist/src/telemetry/failure-summary.js +1 -1
- 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 +8 -0
- package/package.json +4 -4
- package/skills/insmind-cli/SKILL.md +18 -5
- package/skills/insmind-cli/references/agent.md +9 -4
- package/skills/insmind-cli/references/creation.md +3 -1
- package/skills/insmind-cli/references/editor.md +7 -5
- package/skills/insmind-cli/references/errors.md +20 -9
- package/skills/insmind-cli/references/matting.md +3 -5
- package/skills/insmind-cli/references/media-tools.md +10 -4
- package/skills/insmind-cli/references/tool.md +9 -15
|
@@ -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
|
},
|
|
@@ -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);
|
|
@@ -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
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
3
4
|
import { DamAssetNotDownloadableError } from "./dam-api-adapter.js";
|
|
4
5
|
import { DamInputError, normalizeDamAssetId } from "./input.js";
|
|
5
6
|
import { damAssetSourcePresent } from "./asset-projection.js";
|
|
@@ -19,8 +20,8 @@ function nonblank(value) {
|
|
|
19
20
|
return value !== undefined && value.trim() !== "";
|
|
20
21
|
}
|
|
21
22
|
function assertPageSize(value) {
|
|
22
|
-
if (value !== undefined && (!Number.
|
|
23
|
-
invalid("
|
|
23
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value < 1))
|
|
24
|
+
invalid("positive_integer", "pageSize");
|
|
24
25
|
}
|
|
25
26
|
function assertPage(value) {
|
|
26
27
|
if (value !== undefined && (!Number.isInteger(value) || value < 1))
|
|
@@ -97,8 +98,6 @@ export function createDamUseCases(dependencies) {
|
|
|
97
98
|
invalid("nonblank", "targetFolderId");
|
|
98
99
|
assertOptionalNonblank(input.repositoryId, "repositoryId");
|
|
99
100
|
assertOptionalNonblank(input.targetRepositoryId, "targetRepositoryId");
|
|
100
|
-
if (input.kind === "folder" && input.entry_id === input.targetFolderId)
|
|
101
|
-
invalid("cannot_target_self", "targetFolderId");
|
|
102
101
|
}
|
|
103
102
|
async function entryOperation(input) {
|
|
104
103
|
assertEntryOperationInput(input.request);
|
|
@@ -110,6 +109,9 @@ export function createDamUseCases(dependencies) {
|
|
|
110
109
|
if (sourceRepository === undefined)
|
|
111
110
|
throw new DamRepositoryNotFoundError();
|
|
112
111
|
const targetRepositoryId = input.request.targetRepositoryId ?? sourceRepository.id;
|
|
112
|
+
if (input.request.kind === "folder" && input.request.entry_id === input.request.targetFolderId
|
|
113
|
+
&& targetRepositoryId === sourceRepository.id)
|
|
114
|
+
invalid("cannot_target_self", "targetFolderId");
|
|
113
115
|
const locationRequest = {
|
|
114
116
|
entryId: input.request.entry_id,
|
|
115
117
|
kind: input.request.kind,
|
|
@@ -165,13 +167,16 @@ export function createDamUseCases(dependencies) {
|
|
|
165
167
|
if (input.repositoryId !== undefined)
|
|
166
168
|
return [{ id: input.repositoryId }];
|
|
167
169
|
signal.throwIfAborted();
|
|
168
|
-
const available = await dependencies.repositories.list({ access, signal });
|
|
170
|
+
const available = await dependencies.repositories.list({ access, signal, allowPartial: input.allRepositories === true });
|
|
169
171
|
signal.throwIfAborted();
|
|
170
172
|
if (available.length === 0)
|
|
171
173
|
throw new DamRepositoryNotFoundError();
|
|
174
|
+
const preferred = available.find(repository => repository.is_default);
|
|
175
|
+
if (!input.allRepositories && !preferred)
|
|
176
|
+
throw new RemoteProtocolError({}, undefined, "DAM_DEFAULT_REPOSITORY_UNKNOWN");
|
|
172
177
|
const selected = input.allRepositories === true
|
|
173
178
|
? available
|
|
174
|
-
: [
|
|
179
|
+
: [preferred];
|
|
175
180
|
return selected.map((repository) => ({
|
|
176
181
|
id: repository.repository_id,
|
|
177
182
|
...(repository.name === undefined ? {} : { name: repository.name })
|
|
@@ -180,7 +185,7 @@ export function createDamUseCases(dependencies) {
|
|
|
180
185
|
return {
|
|
181
186
|
async repositoryList({ access, signal }) {
|
|
182
187
|
signal.throwIfAborted();
|
|
183
|
-
const repositories = await dependencies.repositories.list({ access, signal });
|
|
188
|
+
const repositories = await dependencies.repositories.list({ access, signal, allowPartial: true });
|
|
184
189
|
signal.throwIfAborted();
|
|
185
190
|
if (repositories.length === 0)
|
|
186
191
|
throw new DamRepositoryNotFoundError();
|
|
@@ -19,7 +19,6 @@ export function createEditorBridgeClient(options) {
|
|
|
19
19
|
async health(signal) {
|
|
20
20
|
const value = await request("/health", "GET", undefined, signal);
|
|
21
21
|
if (!isRecord(value) ||
|
|
22
|
-
!hasExactKeys(value, ["status", "pageConnected", "protocolVersion"]) ||
|
|
23
22
|
value.status !== "ok" ||
|
|
24
23
|
typeof value.pageConnected !== "boolean" ||
|
|
25
24
|
typeof value.protocolVersion !== "number") {
|
|
@@ -42,7 +41,6 @@ export function createEditorBridgeClient(options) {
|
|
|
42
41
|
async disconnect(signal) {
|
|
43
42
|
const value = await request("/disconnect", "POST", {}, signal);
|
|
44
43
|
if (!isRecord(value) ||
|
|
45
|
-
!hasExactKeys(value, ["status"]) ||
|
|
46
44
|
value.status !== "disconnected") {
|
|
47
45
|
throw invalidResponse();
|
|
48
46
|
}
|