@gaoding/cli 0.0.0 → 1.0.0-alpha.25
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/LICENSE +21 -0
- package/README.md +40 -3
- package/contracts/operations/agent.send/input.schema.json +353 -0
- package/contracts/operations/agent.send/output.schema.json +271 -0
- package/contracts/operations/auth.status/input.schema.json +7 -0
- package/contracts/operations/auth.status/output.schema.json +132 -0
- package/contracts/operations/dam.copy/input.schema.json +19 -0
- package/contracts/operations/dam.copy/output.schema.json +19 -0
- package/contracts/operations/dam.delete/input.schema.json +23 -0
- package/contracts/operations/dam.delete/output.schema.json +6 -0
- package/contracts/operations/dam.download/input.schema.json +14 -0
- package/contracts/operations/dam.download/output.schema.json +25 -0
- package/contracts/operations/dam.folder.list/input.schema.json +15 -0
- package/contracts/operations/dam.folder.list/output.schema.json +37 -0
- package/contracts/operations/dam.get/input.schema.json +16 -0
- package/contracts/operations/dam.get/output.schema.json +46 -0
- package/contracts/operations/dam.list/input.schema.json +44 -0
- package/contracts/operations/dam.list/output.schema.json +71 -0
- package/contracts/operations/dam.move/input.schema.json +19 -0
- package/contracts/operations/dam.move/output.schema.json +18 -0
- package/contracts/operations/dam.recycle.list/input.schema.json +13 -0
- package/contracts/operations/dam.recycle.list/output.schema.json +34 -0
- package/contracts/operations/dam.recycle.restore/input.schema.json +14 -0
- package/contracts/operations/dam.recycle.restore/output.schema.json +6 -0
- package/contracts/operations/dam.rename/input.schema.json +18 -0
- package/contracts/operations/dam.rename/output.schema.json +18 -0
- package/contracts/operations/dam.repository.list/input.schema.json +8 -0
- package/contracts/operations/dam.repository.list/output.schema.json +52 -0
- package/contracts/operations/dam.search/input.schema.json +46 -0
- package/contracts/operations/dam.search/output.schema.json +71 -0
- package/contracts/operations/dam.tag.list/input.schema.json +12 -0
- package/contracts/operations/dam.tag.list/output.schema.json +26 -0
- package/contracts/operations/dam.upload/input.schema.json +31 -0
- package/contracts/operations/dam.upload/output.schema.json +46 -0
- package/contracts/operations/editor.apply/input.schema.json +134 -0
- package/contracts/operations/editor.apply/output.schema.json +15 -0
- package/contracts/operations/editor.connect/input.schema.json +15 -0
- package/contracts/operations/editor.connect/output.schema.json +17 -0
- package/contracts/operations/editor.disconnect/input.schema.json +8 -0
- package/contracts/operations/editor.disconnect/output.schema.json +14 -0
- package/contracts/operations/editor.save/input.schema.json +8 -0
- package/contracts/operations/editor.save/output.schema.json +23 -0
- package/contracts/operations/editor.screenshot/input.schema.json +8 -0
- package/contracts/operations/editor.screenshot/output.schema.json +16 -0
- package/contracts/operations/editor.snapshot/input.schema.json +8 -0
- package/contracts/operations/editor.snapshot/output.schema.json +113 -0
- package/contracts/operations/model.get/input.schema.json +18 -0
- package/contracts/operations/model.get/output.schema.json +191 -0
- package/contracts/operations/model.list/input.schema.json +15 -0
- package/contracts/operations/model.list/output.schema.json +111 -0
- package/contracts/operations/org.current/input.schema.json +7 -0
- package/contracts/operations/org.current/output.schema.json +49 -0
- package/contracts/operations/org.list/input.schema.json +7 -0
- package/contracts/operations/org.list/output.schema.json +71 -0
- package/contracts/operations/tool.call/input.schema.json +35 -0
- package/contracts/operations/tool.call/output.schema.json +129 -0
- package/contracts/operations/tool.list/input.schema.json +7 -0
- package/contracts/operations/tool.list/output.schema.json +45 -0
- package/dist/bin/gd-cli.js +60 -0
- package/dist/bin/postinstall.js +42 -0
- package/dist/src/bootstrap/create-cli.js +112 -0
- package/dist/src/bootstrap/create-runtime.js +290 -0
- package/dist/src/bootstrap/validators.js +157 -0
- package/dist/src/cli/action-binding.js +109 -0
- package/dist/src/cli/agent-commands.js +49 -0
- package/dist/src/cli/auth-commands.js +55 -0
- package/dist/src/cli/dam-commands.js +469 -0
- package/dist/src/cli/editor-commands.js +73 -0
- package/dist/src/cli/errors.js +157 -0
- package/dist/src/cli/model-commands.js +61 -0
- package/dist/src/cli/org-commands.js +58 -0
- package/dist/src/cli/presenter.js +105 -0
- package/dist/src/cli/prompt.js +30 -0
- package/dist/src/cli/tool-commands.js +77 -0
- package/dist/src/cli/update-command.js +14 -0
- package/dist/src/contracts/schema.js +4 -0
- package/dist/src/features/agent/creative-agent-adapter.js +36 -0
- package/dist/src/features/agent/creative-protocol.js +432 -0
- package/dist/src/features/agent/creative-stream.js +127 -0
- package/dist/src/features/agent/use-cases.js +150 -0
- package/dist/src/features/auth/access-policy.js +101 -0
- package/dist/src/features/auth/credential-store.js +62 -0
- package/dist/src/features/auth/sso-service.js +194 -0
- package/dist/src/features/auth/state.js +129 -0
- package/dist/src/features/auth/use-cases.js +136 -0
- package/dist/src/features/dam/asset-projection.js +278 -0
- package/dist/src/features/dam/dam-api-adapter.js +562 -0
- package/dist/src/features/dam/file-downloader.js +242 -0
- package/dist/src/features/dam/object-storage.js +193 -0
- package/dist/src/features/dam/operation-executor.js +72 -0
- package/dist/src/features/dam/registered-uploader.js +247 -0
- package/dist/src/features/dam/repository-catalog.js +127 -0
- package/dist/src/features/dam/storage-upload.js +141 -0
- package/dist/src/features/dam/transient-uploader.js +17 -0
- package/dist/src/features/dam/use-cases.js +470 -0
- package/dist/src/features/editor/bridge-client.js +109 -0
- package/dist/src/features/editor/bridge-process.js +222 -0
- package/dist/src/features/editor/bridge-server.js +337 -0
- package/dist/src/features/editor/protocol.js +1 -0
- package/dist/src/features/editor/public-url.js +36 -0
- package/dist/src/features/editor/session-state.js +78 -0
- package/dist/src/features/editor/session.js +207 -0
- package/dist/src/features/editor/use-cases.js +88 -0
- package/dist/src/features/org/org-service.js +76 -0
- package/dist/src/features/org/use-cases.js +156 -0
- package/dist/src/features/skill/bundled-skills.js +55 -0
- package/dist/src/features/skill/installer.js +271 -0
- package/dist/src/features/tool/catalog.js +83 -0
- package/dist/src/features/tool/dynamic-schema.js +128 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +265 -0
- package/dist/src/features/tool/tool-api-adapter.js +352 -0
- package/dist/src/features/tool/use-cases.js +177 -0
- package/dist/src/features/update/latest-version.js +37 -0
- package/dist/src/features/update/update-notification.js +262 -0
- package/dist/src/features/update/update-service.js +183 -0
- package/dist/src/platform/json-input.js +67 -0
- package/dist/src/platform/local-json-file.js +59 -0
- package/dist/src/platform/open-browser.js +8 -0
- package/dist/src/platform/redact.js +80 -0
- package/dist/src/platform/remote-error-evidence.js +80 -0
- package/dist/src/platform/remote-protocol.js +10 -0
- package/dist/src/platform/safe-upload-file.js +146 -0
- package/dist/src/platform/signature.js +20 -0
- package/dist/src/platform/signed-http-transport.js +143 -0
- package/dist/src/platform/url-safety.js +100 -0
- package/dist/src/telemetry/invocation.js +156 -0
- package/dist/src/telemetry/sls-sink.js +31 -0
- package/package.json +54 -8
- package/skills/gd-cli/SKILL.md +15 -0
- package/skills/gd-cli/references/auth-org.md +9 -0
- package/skills/gd-cli/references/creation.md +115 -0
- package/skills/gd-cli/references/dam.md +52 -0
- package/skills/gd-cli/references/editor.md +254 -0
- package/skills/gd-cli/references/errors.md +13 -0
- package/skills/gd-cli/references/update.md +13 -0
- package/index.js +0 -3
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { isSensitiveKey } from "../../platform/redact.js";
|
|
2
|
+
import { parseSafeRemoteAssetUrl } from "../../platform/url-safety.js";
|
|
3
|
+
const publicAssetTypes = new Set([
|
|
4
|
+
"image",
|
|
5
|
+
"video",
|
|
6
|
+
"audio",
|
|
7
|
+
"font",
|
|
8
|
+
"template",
|
|
9
|
+
"file"
|
|
10
|
+
]);
|
|
11
|
+
const internalAssetTypes = new Map([
|
|
12
|
+
["gdpic", "image"],
|
|
13
|
+
["gdimage", "image"],
|
|
14
|
+
["gdvideo", "video"],
|
|
15
|
+
["gdaudio", "audio"],
|
|
16
|
+
["gdfont", "font"],
|
|
17
|
+
["gdtemplate", "template"],
|
|
18
|
+
["gdfile", "file"],
|
|
19
|
+
["gdslide", "file"]
|
|
20
|
+
]);
|
|
21
|
+
const recognizableAssetKeys = new Set([
|
|
22
|
+
"asset_id",
|
|
23
|
+
"id",
|
|
24
|
+
"content_id",
|
|
25
|
+
"title",
|
|
26
|
+
"name",
|
|
27
|
+
"description",
|
|
28
|
+
"format",
|
|
29
|
+
"type",
|
|
30
|
+
"content_format",
|
|
31
|
+
"storage_format",
|
|
32
|
+
"origin_info",
|
|
33
|
+
"originInfo",
|
|
34
|
+
"origin_url",
|
|
35
|
+
"url",
|
|
36
|
+
"preview",
|
|
37
|
+
"preview_info",
|
|
38
|
+
"previewInfo",
|
|
39
|
+
"cover",
|
|
40
|
+
"cover_url",
|
|
41
|
+
"analysis_result",
|
|
42
|
+
"analysis_status"
|
|
43
|
+
]);
|
|
44
|
+
function record(value) {
|
|
45
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
46
|
+
? value
|
|
47
|
+
: undefined;
|
|
48
|
+
}
|
|
49
|
+
function nonblank(value) {
|
|
50
|
+
return typeof value === "string" && value.trim() !== "" ? value : undefined;
|
|
51
|
+
}
|
|
52
|
+
function publicSourceFormat(value) {
|
|
53
|
+
const format = nonblank(value);
|
|
54
|
+
return format !== undefined && !internalAssetTypes.has(format.toLowerCase())
|
|
55
|
+
? format
|
|
56
|
+
: undefined;
|
|
57
|
+
}
|
|
58
|
+
function finiteNumber(value) {
|
|
59
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
60
|
+
}
|
|
61
|
+
function findAssetRecord(value) {
|
|
62
|
+
const queue = [value];
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
while (queue.length > 0) {
|
|
65
|
+
const candidate = queue.shift();
|
|
66
|
+
if (Array.isArray(candidate)) {
|
|
67
|
+
queue.push(...candidate);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const item = record(candidate);
|
|
71
|
+
if (item === undefined || seen.has(item))
|
|
72
|
+
continue;
|
|
73
|
+
seen.add(item);
|
|
74
|
+
if (Object.keys(item).some((key) => recognizableAssetKeys.has(key)))
|
|
75
|
+
return item;
|
|
76
|
+
for (const key of ["data", "asset", "asset_info", "item", "result"]) {
|
|
77
|
+
if (item[key] !== undefined)
|
|
78
|
+
queue.push(item[key]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
function safePublicUrl(value) {
|
|
84
|
+
const raw = nonblank(value);
|
|
85
|
+
if (raw === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
try {
|
|
88
|
+
const url = parseSafeRemoteAssetUrl(raw);
|
|
89
|
+
for (const key of [...url.searchParams.keys()]) {
|
|
90
|
+
if (isSensitiveKey(key))
|
|
91
|
+
url.searchParams.delete(key);
|
|
92
|
+
}
|
|
93
|
+
return url.href;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function timestamp(value) {
|
|
100
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
101
|
+
const milliseconds = Math.abs(value) < 1_000_000_000_000 ? value * 1000 : value;
|
|
102
|
+
const date = new Date(milliseconds);
|
|
103
|
+
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
|
104
|
+
}
|
|
105
|
+
const text = nonblank(value);
|
|
106
|
+
if (text === undefined)
|
|
107
|
+
return undefined;
|
|
108
|
+
const date = new Date(text);
|
|
109
|
+
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
|
110
|
+
}
|
|
111
|
+
function tags(value) {
|
|
112
|
+
if (!Array.isArray(value))
|
|
113
|
+
return undefined;
|
|
114
|
+
const result = value
|
|
115
|
+
.map((item) => typeof item === "string" ? nonblank(item) : nonblank(record(item)?.name))
|
|
116
|
+
.filter((item) => item !== undefined);
|
|
117
|
+
return result.length === 0 ? undefined : result;
|
|
118
|
+
}
|
|
119
|
+
function tagIds(tagIdsValue, tagsValue) {
|
|
120
|
+
const candidates = Array.isArray(tagIdsValue)
|
|
121
|
+
? tagIdsValue
|
|
122
|
+
: Array.isArray(tagsValue)
|
|
123
|
+
? tagsValue.map((item) => record(item)?.id)
|
|
124
|
+
: [];
|
|
125
|
+
const result = candidates.filter((item) => (typeof item === "string" && item.trim() !== "")
|
|
126
|
+
|| (typeof item === "number" && Number.isFinite(item)));
|
|
127
|
+
return result.length === 0 ? undefined : result;
|
|
128
|
+
}
|
|
129
|
+
function assetType(item, format, mediaType) {
|
|
130
|
+
const explicit = nonblank(item.type)?.toLowerCase();
|
|
131
|
+
if (explicit !== undefined && publicAssetTypes.has(explicit))
|
|
132
|
+
return explicit;
|
|
133
|
+
for (const candidate of [item.content_format, item.storage_format, item.format]) {
|
|
134
|
+
const internalType = internalAssetTypes.get(nonblank(candidate)?.toLowerCase() ?? "");
|
|
135
|
+
if (internalType !== undefined)
|
|
136
|
+
return internalType;
|
|
137
|
+
}
|
|
138
|
+
const mediaCategory = mediaType?.split("/", 1)[0]?.toLowerCase();
|
|
139
|
+
if (mediaCategory !== undefined && publicAssetTypes.has(mediaCategory))
|
|
140
|
+
return mediaCategory;
|
|
141
|
+
const normalizedFormat = format?.toLowerCase();
|
|
142
|
+
if (normalizedFormat !== undefined
|
|
143
|
+
&& ["png", "jpg", "jpeg", "gif", "webp", "svg", "avif", "heic"].includes(normalizedFormat)) {
|
|
144
|
+
return "image";
|
|
145
|
+
}
|
|
146
|
+
if (normalizedFormat !== undefined
|
|
147
|
+
&& ["mp4", "mov", "webm", "mkv"].includes(normalizedFormat))
|
|
148
|
+
return "video";
|
|
149
|
+
if (normalizedFormat !== undefined
|
|
150
|
+
&& ["mp3", "wav", "m4a", "aac", "ogg", "flac"].includes(normalizedFormat)) {
|
|
151
|
+
return "audio";
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
function compact(value) {
|
|
156
|
+
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined));
|
|
157
|
+
}
|
|
158
|
+
function normalizeAsset(value, fallback) {
|
|
159
|
+
const item = findAssetRecord(value);
|
|
160
|
+
if (item === undefined)
|
|
161
|
+
return undefined;
|
|
162
|
+
const fallbackAsset = typeof fallback === "object" ? fallback : undefined;
|
|
163
|
+
const origin = record(item.origin_info) ?? record(item.originInfo);
|
|
164
|
+
const design = record(item.design_info) ?? record(item.designInfo);
|
|
165
|
+
const preview = record(item.preview)
|
|
166
|
+
?? record(item.preview_info)
|
|
167
|
+
?? record(item.previewInfo)
|
|
168
|
+
?? record(item.cover);
|
|
169
|
+
const repository = record(item.repository_info) ?? record(item.repositoryInfo);
|
|
170
|
+
const folder = record(item.folder_info) ?? record(item.folderInfo);
|
|
171
|
+
const format = publicSourceFormat(origin?.format) ?? publicSourceFormat(item.format);
|
|
172
|
+
const mediaType = nonblank(origin?.mime_type)
|
|
173
|
+
?? nonblank(item.mime_type)
|
|
174
|
+
?? nonblank(item.mimeType);
|
|
175
|
+
const assetId = nonblank(item.asset_id)
|
|
176
|
+
?? nonblank(item.id)
|
|
177
|
+
?? nonblank(item.content_id)
|
|
178
|
+
?? (typeof fallback === "string" ? fallback : fallbackAsset?.asset_id);
|
|
179
|
+
if (assetId === undefined)
|
|
180
|
+
return undefined;
|
|
181
|
+
return compact({
|
|
182
|
+
...fallbackAsset,
|
|
183
|
+
asset_id: assetId,
|
|
184
|
+
title: nonblank(item.title) ?? nonblank(item.name) ?? fallbackAsset?.title,
|
|
185
|
+
description: nonblank(item.description) ?? fallbackAsset?.description,
|
|
186
|
+
format: format ?? fallbackAsset?.format,
|
|
187
|
+
type: assetType(item, format, mediaType) ?? fallbackAsset?.type,
|
|
188
|
+
size: finiteNumber(origin?.size) ?? finiteNumber(item.size) ?? fallbackAsset?.size,
|
|
189
|
+
url: safePublicUrl(origin?.url ?? item.origin_url ?? item.url) ?? fallbackAsset?.url,
|
|
190
|
+
cover_url: safePublicUrl(preview?.url ?? item.cover_url ?? item.preview_url) ?? fallbackAsset?.cover_url,
|
|
191
|
+
width: finiteNumber(design?.width)
|
|
192
|
+
?? finiteNumber(preview?.width)
|
|
193
|
+
?? finiteNumber(item.width)
|
|
194
|
+
?? fallbackAsset?.width,
|
|
195
|
+
height: finiteNumber(design?.height)
|
|
196
|
+
?? finiteNumber(preview?.height)
|
|
197
|
+
?? finiteNumber(item.height)
|
|
198
|
+
?? fallbackAsset?.height,
|
|
199
|
+
duration: finiteNumber(design?.duration)
|
|
200
|
+
?? finiteNumber(preview?.duration)
|
|
201
|
+
?? finiteNumber(item.duration)
|
|
202
|
+
?? fallbackAsset?.duration,
|
|
203
|
+
repository_id: nonblank(item.repository_id)
|
|
204
|
+
?? nonblank(repository?.id)
|
|
205
|
+
?? nonblank(repository?.repository_id)
|
|
206
|
+
?? fallbackAsset?.repository_id,
|
|
207
|
+
repository_name: nonblank(item.repository_name)
|
|
208
|
+
?? nonblank(repository?.name)
|
|
209
|
+
?? nonblank(repository?.title)
|
|
210
|
+
?? fallbackAsset?.repository_name,
|
|
211
|
+
folder_id: nonblank(item.folder_id)
|
|
212
|
+
?? nonblank(folder?.id)
|
|
213
|
+
?? fallbackAsset?.folder_id,
|
|
214
|
+
folder_name: nonblank(item.folder_name)
|
|
215
|
+
?? nonblank(folder?.name)
|
|
216
|
+
?? nonblank(folder?.title)
|
|
217
|
+
?? fallbackAsset?.folder_name,
|
|
218
|
+
tags: tags(item.tags),
|
|
219
|
+
tag_ids: tagIds(item.tag_ids, item.tags) ?? fallbackAsset?.tag_ids,
|
|
220
|
+
analysis_status: finiteNumber(item.analysis_result)
|
|
221
|
+
?? finiteNumber(item.analysis_status)
|
|
222
|
+
?? nonblank(item.analysis_result)
|
|
223
|
+
?? nonblank(item.analysis_status)
|
|
224
|
+
?? fallbackAsset?.analysis_status,
|
|
225
|
+
created_at: timestamp(item.created_at) ?? fallbackAsset?.created_at,
|
|
226
|
+
updated_at: timestamp(item.updated_at) ?? fallbackAsset?.updated_at
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
export function projectDamAssetDetail(value, fallback) {
|
|
230
|
+
const asset = normalizeAsset(value, fallback);
|
|
231
|
+
if (asset === undefined)
|
|
232
|
+
return undefined;
|
|
233
|
+
return compact({
|
|
234
|
+
asset_id: asset.asset_id,
|
|
235
|
+
title: asset.title,
|
|
236
|
+
description: asset.description,
|
|
237
|
+
format: asset.format,
|
|
238
|
+
type: asset.type,
|
|
239
|
+
size: asset.size,
|
|
240
|
+
url: asset.url,
|
|
241
|
+
cover_url: asset.cover_url,
|
|
242
|
+
width: asset.width,
|
|
243
|
+
height: asset.height,
|
|
244
|
+
duration: asset.duration,
|
|
245
|
+
repository_id: asset.repository_id,
|
|
246
|
+
repository_name: asset.repository_name,
|
|
247
|
+
folder_id: asset.folder_id,
|
|
248
|
+
folder_name: asset.folder_name,
|
|
249
|
+
tag_ids: asset.tag_ids,
|
|
250
|
+
analysis_status: asset.analysis_status,
|
|
251
|
+
created_at: asset.created_at,
|
|
252
|
+
updated_at: asset.updated_at
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
export function projectDamAssetSummary(value) {
|
|
256
|
+
const asset = normalizeAsset(value);
|
|
257
|
+
if (asset === undefined)
|
|
258
|
+
return undefined;
|
|
259
|
+
return compact({
|
|
260
|
+
asset_id: asset.asset_id,
|
|
261
|
+
title: asset.title,
|
|
262
|
+
format: asset.format,
|
|
263
|
+
type: asset.type,
|
|
264
|
+
size: asset.size,
|
|
265
|
+
url: asset.url,
|
|
266
|
+
cover_url: asset.cover_url,
|
|
267
|
+
width: asset.width,
|
|
268
|
+
height: asset.height,
|
|
269
|
+
repository_id: asset.repository_id,
|
|
270
|
+
folder_id: asset.folder_id,
|
|
271
|
+
folder_name: asset.folder_name,
|
|
272
|
+
tags: asset.tags,
|
|
273
|
+
tag_ids: asset.tag_ids,
|
|
274
|
+
analysis_status: asset.analysis_status,
|
|
275
|
+
created_at: asset.created_at,
|
|
276
|
+
updated_at: asset.updated_at
|
|
277
|
+
});
|
|
278
|
+
}
|