@project-ava-supernova/core 0.2.199 → 0.2.201
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +14 -2
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/system-prompt.d.ts.map +1 -1
- package/dist/agent/system-prompt.js +10 -7
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/audit/cost.d.ts.map +1 -1
- package/dist/audit/cost.js +2 -1
- package/dist/audit/cost.js.map +1 -1
- package/dist/docs/data/providers.d.ts.map +1 -1
- package/dist/docs/data/providers.js +1 -0
- package/dist/docs/data/providers.js.map +1 -1
- package/dist/docs/data/tools.d.ts.map +1 -1
- package/dist/docs/data/tools.js +2 -1
- package/dist/docs/data/tools.js.map +1 -1
- package/dist/providers/nvidia/models.d.ts.map +1 -1
- package/dist/providers/nvidia/models.js +28 -0
- package/dist/providers/nvidia/models.js.map +1 -1
- package/dist/providers/qwen/models.d.ts.map +1 -1
- package/dist/providers/qwen/models.js +12 -5
- package/dist/providers/qwen/models.js.map +1 -1
- package/dist/providers/request-shaping/model-ids.d.ts.map +1 -1
- package/dist/providers/request-shaping/model-ids.js +3 -0
- package/dist/providers/request-shaping/model-ids.js.map +1 -1
- package/dist/tools/browse-library.d.ts +51 -2
- package/dist/tools/browse-library.d.ts.map +1 -1
- package/dist/tools/browse-library.js +377 -152
- package/dist/tools/browse-library.js.map +1 -1
- package/dist/tools/design-studio-tools.d.ts.map +1 -1
- package/dist/tools/design-studio-tools.js +44 -6
- package/dist/tools/design-studio-tools.js.map +1 -1
- package/dist/tools/library-rename.d.ts +20 -0
- package/dist/tools/library-rename.d.ts.map +1 -0
- package/dist/tools/library-rename.js +182 -0
- package/dist/tools/library-rename.js.map +1 -0
- package/dist/tools/tool-registry.d.ts.map +1 -1
- package/dist/tools/tool-registry.js +2 -0
- package/dist/tools/tool-registry.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,188 +1,413 @@
|
|
|
1
|
-
import { readdir, stat } from 'node:fs/promises';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* (2) used to be missing entirely: the tool only ever scanned project-relative
|
|
15
|
-
* dirs, so every icon, logo, image and voiceover the user made in the Studio
|
|
16
|
-
* was invisible to Ava — she'd report "no assets" and offer to generate a fresh
|
|
17
|
-
* one, spending their money on something they already owned.
|
|
18
|
-
*/
|
|
19
|
-
const ASSET_EXTENSIONS = {
|
|
20
|
-
// Images
|
|
21
|
-
'.png': 'image', '.jpg': 'image', '.jpeg': 'image', '.gif': 'image',
|
|
22
|
-
'.svg': 'image', '.webp': 'image', '.ico': 'image', '.bmp': 'image',
|
|
23
|
-
// Video
|
|
1
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { basename, extname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { creativeDir as defaultCreativeDir } from './blender/paths.js';
|
|
5
|
+
import { findFolder, folderPath } from '../creative/library-folders.js';
|
|
6
|
+
const KINDS = ['image', 'logo', 'icon', 'video', 'audio', 'model', 'design', 'document', 'spreadsheet', 'font'];
|
|
7
|
+
export const KIND_LABEL = {
|
|
8
|
+
image: 'image', logo: 'logo', icon: 'icon', video: 'video', audio: 'audio',
|
|
9
|
+
model: '3D model', design: 'GIMP design', document: 'document', spreadsheet: 'spreadsheet', font: 'font',
|
|
10
|
+
};
|
|
11
|
+
const EXT_KIND = {
|
|
12
|
+
'.png': 'image', '.jpg': 'image', '.jpeg': 'image', '.gif': 'image', '.svg': 'image',
|
|
13
|
+
'.webp': 'image', '.ico': 'image', '.bmp': 'image', '.avif': 'image',
|
|
24
14
|
'.mp4': 'video', '.webm': 'video', '.mov': 'video',
|
|
25
|
-
|
|
26
|
-
'.
|
|
27
|
-
|
|
15
|
+
'.mp3': 'audio', '.wav': 'audio', '.ogg': 'audio', '.m4a': 'audio', '.flac': 'audio',
|
|
16
|
+
'.glb': 'model', '.gltf': 'model', '.fbx': 'model', '.obj': 'model', '.blend': 'model',
|
|
17
|
+
'.stl': 'model', '.usdz': 'model', '.usd': 'model', '.dae': 'model',
|
|
18
|
+
'.xcf': 'design', '.psd': 'design',
|
|
28
19
|
'.pdf': 'document', '.docx': 'document',
|
|
29
20
|
'.xlsx': 'spreadsheet',
|
|
21
|
+
'.ttf': 'font', '.otf': 'font', '.woff': 'font', '.woff2': 'font',
|
|
22
|
+
};
|
|
23
|
+
/** Where a project's assets usually live. */
|
|
24
|
+
const PROJECT_DIRS = ['images', '.ava/creative', 'public', 'src/assets', 'assets', 'static', 'media'];
|
|
25
|
+
/** Never assets: build output, and the working parts of a Studio work. */
|
|
26
|
+
const SKIP_DIRS = new Set(['node_modules', 'dist', 'build', '.next', '__pycache__', 'history', 'versions', 'scripts']);
|
|
27
|
+
/** Library subfolders that hold one work per subfolder. */
|
|
28
|
+
const WORK_ROOTS = { blender: 'model', gimp: 'design', uploads: 'model' };
|
|
29
|
+
const PAGE = 40;
|
|
30
|
+
const str = (v) => (typeof v === 'string' && v.trim() ? v.trim() : undefined);
|
|
31
|
+
function size(n) {
|
|
32
|
+
if (typeof n !== 'number')
|
|
33
|
+
return '';
|
|
34
|
+
return n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${(n / 1024).toFixed(1)} KB` : `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
35
|
+
}
|
|
36
|
+
function kindOfMeta(m) {
|
|
37
|
+
const dt = (str(m.designType) ?? '').toLowerCase();
|
|
38
|
+
const k = (str(m.kind) ?? '').toLowerCase();
|
|
39
|
+
if (k === 'model' || dt === 'model')
|
|
40
|
+
return 'model';
|
|
41
|
+
if (k === 'gimp' || dt === 'gimp')
|
|
42
|
+
return 'design';
|
|
43
|
+
if (dt === 'logo')
|
|
44
|
+
return 'logo';
|
|
45
|
+
if (dt === 'icon')
|
|
46
|
+
return 'icon';
|
|
47
|
+
if (k === 'video')
|
|
48
|
+
return 'video';
|
|
49
|
+
if (k === 'voice' || k === 'music' || k === 'sfx' || k === 'audio')
|
|
50
|
+
return 'audio';
|
|
51
|
+
const ext = extname(str(m.path) ?? '').toLowerCase();
|
|
52
|
+
return EXT_KIND[ext] ?? 'image';
|
|
53
|
+
}
|
|
54
|
+
/** "logo_1793811750994_mono-dark" → ["logo_1793811750994", "mono-dark"]. */
|
|
55
|
+
export function logoParts(name) {
|
|
56
|
+
const m = /^(logo_\d+)_([a-z0-9-]+)$/i.exec(name);
|
|
57
|
+
return m ? [m[1], m[2]] : null;
|
|
58
|
+
}
|
|
59
|
+
const timeOf = (v) => {
|
|
60
|
+
const t = typeof v === 'string' ? Date.parse(v) : NaN;
|
|
61
|
+
return Number.isFinite(t) ? t : 0;
|
|
30
62
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
63
|
+
async function listFiles(dir, depth = 0, out = []) {
|
|
64
|
+
if (depth > 6)
|
|
65
|
+
return out;
|
|
66
|
+
let entries;
|
|
67
|
+
try {
|
|
68
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
for (const e of entries) {
|
|
74
|
+
if (e.name.startsWith('.') && e.name !== '.ava')
|
|
75
|
+
continue;
|
|
76
|
+
const full = join(dir, e.name);
|
|
77
|
+
if (e.isDirectory()) {
|
|
78
|
+
if (!SKIP_DIRS.has(e.name))
|
|
79
|
+
await listFiles(full, depth + 1, out);
|
|
80
|
+
}
|
|
81
|
+
else if (e.isFile() && EXT_KIND[extname(e.name).toLowerCase()]) {
|
|
82
|
+
out.push(full);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
async function readJson(file) {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(await readFile(file, 'utf-8'));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** One Studio work folder (a model or a GIMP design): what to use, and the rest. */
|
|
96
|
+
async function workFiles(folder, listed, kind) {
|
|
97
|
+
const all = listed && listed.length
|
|
98
|
+
? listed.map((f) => join(folder, f)).filter((f) => existsSync(f))
|
|
99
|
+
: await listFiles(folder);
|
|
100
|
+
const isPreview = (f) => basename(f).toLowerCase() === 'preview.png';
|
|
101
|
+
let main;
|
|
102
|
+
if (kind === 'model') {
|
|
103
|
+
main = all.find((f) => /\.glb$/i.test(f)) ?? all.find((f) => /\.(gltf|fbx|obj)$/i.test(f)) ?? all.find((f) => /\.blend$/i.test(f));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// A GIMP work's finals are the pieces they signed off; finals.json names them.
|
|
107
|
+
const finals = await readJson(join(folder, 'finals.json'));
|
|
108
|
+
const firstFinal = Array.isArray(finals) ? finals.find((f) => typeof f === 'string') : undefined;
|
|
109
|
+
if (firstFinal && existsSync(join(folder, firstFinal)))
|
|
110
|
+
main = join(folder, firstFinal);
|
|
111
|
+
main ??= all.find((f) => /[\\/]final[\\/]/i.test(f)) ?? all.find((f) => /\.png$/i.test(f) && !isPreview(f)) ?? all[0];
|
|
112
|
+
}
|
|
113
|
+
main ??= all.find(isPreview) ?? folder;
|
|
114
|
+
return { main, others: all.filter((f) => f !== main && !isPreview(f)) };
|
|
115
|
+
}
|
|
116
|
+
/** Everything in the Library, as works. */
|
|
117
|
+
export async function readLibrary(root) {
|
|
118
|
+
const items = [];
|
|
119
|
+
const covered = new Set(); // files already part of an item
|
|
120
|
+
const coveredDirs = new Set(); // work folders already read
|
|
121
|
+
const norm = (p) => resolve(p).toLowerCase();
|
|
122
|
+
const meta = await readJson(join(root, 'metadata.json'));
|
|
123
|
+
const entries = Array.isArray(meta) ? meta.filter((m) => !!m && typeof m === 'object') : [];
|
|
124
|
+
// A logo is saved as one file per variant (logo_<n>_primary, _wordmark, …):
|
|
125
|
+
// one set, with the primary as the file to use.
|
|
126
|
+
const logos = new Map();
|
|
127
|
+
const addLogo = (group, variant, file, when, title, prompt) => {
|
|
128
|
+
let set = logos.get(group);
|
|
129
|
+
if (!set) {
|
|
130
|
+
set = { key: group, kind: 'logo', title: 'Logo', main: file, others: [], folders: [], when };
|
|
131
|
+
logos.set(group, set);
|
|
132
|
+
items.push(set);
|
|
133
|
+
}
|
|
134
|
+
else if (variant === 'primary') {
|
|
135
|
+
set.others.unshift(set.main);
|
|
136
|
+
set.main = file;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
set.others.push(file);
|
|
140
|
+
}
|
|
141
|
+
// Titles are saved per variant ("Acme — mono dark"); the set takes the name without it.
|
|
142
|
+
if (title && set.title === 'Logo') {
|
|
143
|
+
const v = variant.replace(/[^a-z0-9]+/gi, '[ _-]');
|
|
144
|
+
set.title = title.replace(new RegExp(`\\s*[-–—(:]?\\s*${v}\\)?$`, 'i'), '').trim() || 'Logo';
|
|
145
|
+
}
|
|
146
|
+
if (prompt && !set.prompt)
|
|
147
|
+
set.prompt = prompt;
|
|
148
|
+
set.when = Math.max(set.when, when);
|
|
149
|
+
set.detail = `${1 + set.others.length} variants`;
|
|
150
|
+
};
|
|
151
|
+
for (const m of entries) {
|
|
152
|
+
const id = str(m.id);
|
|
153
|
+
if (!id)
|
|
154
|
+
continue;
|
|
155
|
+
const kind = kindOfMeta(m);
|
|
156
|
+
const when = timeOf(m.updatedAt) || timeOf(m.createdAt);
|
|
157
|
+
const title = str(m.title);
|
|
158
|
+
const prompt = str(m.prompt);
|
|
159
|
+
const folderRel = str(m.folder);
|
|
160
|
+
if ((kind === 'model' || kind === 'design') && folderRel) {
|
|
161
|
+
const folder = str(m.absoluteFolder) && existsSync(String(m.absoluteFolder)) ? String(m.absoluteFolder) : join(root, folderRel);
|
|
162
|
+
const files = Array.isArray(m.files) ? m.files.filter((f) => typeof f === 'string') : undefined;
|
|
163
|
+
const { main, others } = await workFiles(folder, files, kind);
|
|
164
|
+
const bits = [];
|
|
165
|
+
if (typeof m.triangles === 'number')
|
|
166
|
+
bits.push(`${m.triangles.toLocaleString('en-GB')} triangles`);
|
|
167
|
+
if (Array.isArray(m.sizeM) && m.sizeM.every((n) => typeof n === 'number'))
|
|
168
|
+
bits.push(`${m.sizeM.map((n) => +n.toFixed(2)).join(' × ')} m`);
|
|
169
|
+
coveredDirs.add(norm(folder));
|
|
170
|
+
items.push({ key: id, kind, title: title ?? basename(folder), prompt, detail: bits.join(' · ') || undefined, main, others, folders: [], when, bytes: typeof m.bytes === 'number' ? m.bytes : undefined });
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const abs = str(m.absolutePath) && existsSync(String(m.absolutePath)) ? String(m.absolutePath) : str(m.path) ? join(root, String(m.path)) : undefined;
|
|
174
|
+
if (!abs)
|
|
175
|
+
continue;
|
|
176
|
+
covered.add(norm(abs));
|
|
177
|
+
const lp = logoParts(id);
|
|
178
|
+
if (lp) {
|
|
179
|
+
addLogo(lp[0], lp[1], abs, when, title, prompt);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
items.push({ key: id, kind, title: title ?? (prompt ? prompt.slice(0, 60) : basename(abs)), prompt, main: abs, others: [], folders: [], when, bytes: typeof m.bytes === 'number' ? m.bytes : undefined });
|
|
183
|
+
}
|
|
184
|
+
// Work folders with no index entry: one item per folder.
|
|
185
|
+
for (const [dir, kind] of Object.entries(WORK_ROOTS)) {
|
|
186
|
+
let subs;
|
|
187
|
+
try {
|
|
188
|
+
subs = await readdir(join(root, dir), { withFileTypes: true });
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
for (const s of subs) {
|
|
194
|
+
if (!s.isDirectory() || s.name.startsWith('.'))
|
|
195
|
+
continue;
|
|
196
|
+
const folder = join(root, dir, s.name);
|
|
197
|
+
if (coveredDirs.has(norm(folder)))
|
|
198
|
+
continue;
|
|
199
|
+
const { main, others } = await workFiles(folder, undefined, kind);
|
|
200
|
+
if (main === folder)
|
|
201
|
+
continue; // nothing usable in it
|
|
202
|
+
let when = 0;
|
|
203
|
+
try {
|
|
204
|
+
when = (await stat(folder)).mtimeMs;
|
|
205
|
+
}
|
|
206
|
+
catch { /* keep 0 */ }
|
|
207
|
+
coveredDirs.add(norm(folder));
|
|
208
|
+
items.push({ key: `${dir}/${s.name}`, kind, title: s.name.replace(/[-_]+/g, ' '), main, others, folders: [], when });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Loose files with no index entry (older work): logos grouped, the rest one each.
|
|
212
|
+
for (const file of await listFiles(root)) {
|
|
213
|
+
const n = norm(file);
|
|
214
|
+
if (covered.has(n))
|
|
215
|
+
continue;
|
|
216
|
+
if ([...coveredDirs].some((d) => n.startsWith(d + '\\') || n.startsWith(d + '/')))
|
|
217
|
+
continue;
|
|
218
|
+
const rel = relative(root, file).replace(/\\/g, '/');
|
|
219
|
+
const top = rel.split('/')[0];
|
|
220
|
+
if (WORK_ROOTS[top])
|
|
221
|
+
continue;
|
|
222
|
+
let st;
|
|
223
|
+
try {
|
|
224
|
+
st = await stat(file);
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const name = basename(file, extname(file));
|
|
230
|
+
const lp = logoParts(name);
|
|
231
|
+
if (lp) {
|
|
232
|
+
addLogo(lp[0], lp[1], file, st.mtimeMs);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const kind = top === 'icons' ? 'icon' : top === 'logos' ? 'logo' : EXT_KIND[extname(file).toLowerCase()] ?? 'image';
|
|
236
|
+
items.push({ key: file, kind, title: basename(file), main: file, others: [], folders: [], when: st.mtimeMs, bytes: st.size });
|
|
237
|
+
}
|
|
238
|
+
// Folders: which work sits in which, by the same references the Library uses.
|
|
239
|
+
const raw = await readJson(join(root, 'folders.json'));
|
|
240
|
+
const folders = Array.isArray(raw?.folders)
|
|
241
|
+
? raw.folders.filter((f) => f && typeof f.id === 'string' && typeof f.name === 'string' && Array.isArray(f.members))
|
|
242
|
+
: [];
|
|
243
|
+
const byKey = new Map(items.map((i) => [i.key, i]));
|
|
244
|
+
for (const f of folders) {
|
|
245
|
+
const name = folderPath(folders, f);
|
|
246
|
+
for (const mem of f.members) {
|
|
247
|
+
const ref = String(mem?.ref ?? '');
|
|
248
|
+
const it = ref.startsWith('creative:') ? byKey.get(ref.slice(9)) ?? byKey.get(logoParts(ref.slice(9))?.[0] ?? '')
|
|
249
|
+
: ref.startsWith('logo:') ? byKey.get(ref.slice(5))
|
|
250
|
+
: undefined;
|
|
251
|
+
if (it && !it.folders.includes(name))
|
|
252
|
+
it.folders.push(name);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
items.sort((a, b) => b.when - a.when);
|
|
256
|
+
return { items, folders };
|
|
257
|
+
}
|
|
258
|
+
async function readProject(cwd, dirs) {
|
|
259
|
+
const out = [];
|
|
260
|
+
for (const d of dirs) {
|
|
261
|
+
for (const file of await listFiles(join(cwd, d))) {
|
|
262
|
+
let st;
|
|
263
|
+
try {
|
|
264
|
+
st = await stat(file);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const rel = relative(cwd, file).replace(/\\/g, '/');
|
|
270
|
+
out.push({ key: rel, kind: EXT_KIND[extname(file).toLowerCase()] ?? 'image', title: rel, main: rel, others: [], folders: [], when: st.mtimeMs, bytes: st.size });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return out;
|
|
274
|
+
}
|
|
275
|
+
function matches(it, words) {
|
|
276
|
+
if (!words.length)
|
|
277
|
+
return true;
|
|
278
|
+
const hay = [it.title, it.prompt, it.key, it.kind, KIND_LABEL[it.kind], it.detail, ...it.folders, basename(it.main), ...it.others.map((o) => basename(o))]
|
|
279
|
+
.filter(Boolean).join(' ').toLowerCase();
|
|
280
|
+
return words.every((w) => hay.includes(w));
|
|
281
|
+
}
|
|
282
|
+
function describe(it, inProject) {
|
|
283
|
+
const head = [KIND_LABEL[it.kind], it.detail, it.bytes ? size(it.bytes) : '', it.when ? new Date(it.when).toISOString().slice(0, 10) : '']
|
|
284
|
+
.filter(Boolean).join(' · ');
|
|
285
|
+
const lines = [`• ${inProject ? it.main : it.title} (${head})`];
|
|
286
|
+
if (it.folders.length)
|
|
287
|
+
lines.push(` in folder: ${it.folders.map((f) => `"${f}"`).join(', ')}`);
|
|
288
|
+
if (it.prompt && it.prompt !== it.title)
|
|
289
|
+
lines.push(` made from: ${it.prompt.length > 140 ? it.prompt.slice(0, 140) + '…' : it.prompt}`);
|
|
290
|
+
if (!inProject)
|
|
291
|
+
lines.push(` use: ${it.main}`);
|
|
292
|
+
// The handle library_rename takes. A loose file's handle is its path, already shown.
|
|
293
|
+
if (!inProject && it.key !== it.main)
|
|
294
|
+
lines.push(` id: ${it.key}`);
|
|
295
|
+
if (it.others.length) {
|
|
296
|
+
const shown = it.others.slice(0, 10).map((o) => (inProject ? o : basename(o)));
|
|
297
|
+
lines.push(` also: ${shown.join(', ')}${it.others.length > 10 ? ` … and ${it.others.length - 10} more` : ''}`);
|
|
298
|
+
}
|
|
299
|
+
return lines.join('\n');
|
|
300
|
+
}
|
|
40
301
|
export class BrowseLibraryTool {
|
|
41
302
|
name = 'browse_library';
|
|
42
|
-
description = '
|
|
303
|
+
description = 'Find what the user has already made — in their Library (images, logos, icons, video, voice and music, 3D models, GIMP designs) and in the open project — with each piece\'s name, folder and real file path, so it can be used in their work.';
|
|
43
304
|
riskLevel = 'safe';
|
|
44
305
|
requiresConfirmation = false;
|
|
45
306
|
schema = {
|
|
46
307
|
name: 'browse_library',
|
|
47
|
-
description: '
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
308
|
+
description: 'Find what the user has already made, so it can be used: everything in their Library (made in the Creative Studio or brought in: ' +
|
|
309
|
+
'images, logos, icons, video, voice and music, 3D models with their .glb/.fbx/.blend files, GIMP designs with their finals and .xcf sources) ' +
|
|
310
|
+
'and the assets already in the open project. Each piece comes back with its name, what it was made from, its folders and its real file path. ' +
|
|
311
|
+
'Use it whenever a project or plan needs an asset, and before suggesting that something be made: making new media costs the user money, ' +
|
|
312
|
+
'reusing what they own does not. Never invent or guess a filename; take the path from here. ' +
|
|
313
|
+
'Library paths are absolute and outside the project, so copy a file into the project to use it there. ' +
|
|
314
|
+
'Narrow with query (words in the name, prompt or folder), type, or folder; results come in pages of 40, so pass offset for the next page.',
|
|
53
315
|
parameters: {
|
|
54
316
|
type: 'object',
|
|
55
317
|
properties: {
|
|
318
|
+
query: {
|
|
319
|
+
type: 'string',
|
|
320
|
+
description: 'Words to look for in the name, what it was made from, its files or its folder, e.g. "crate" or "dawnsets logo".',
|
|
321
|
+
},
|
|
56
322
|
type: {
|
|
57
323
|
type: 'string',
|
|
58
|
-
enum: ['all',
|
|
59
|
-
description: '
|
|
324
|
+
enum: ['all', ...KINDS],
|
|
325
|
+
description: 'Only this kind. model = 3D models; design = GIMP work. Default: all.',
|
|
326
|
+
},
|
|
327
|
+
folder: {
|
|
328
|
+
type: 'string',
|
|
329
|
+
description: 'Only what is in this Library folder (its name, or a path like "Pack / Icons"); includes its subfolders.',
|
|
330
|
+
},
|
|
331
|
+
where: {
|
|
332
|
+
type: 'string',
|
|
333
|
+
enum: ['both', 'library', 'project'],
|
|
334
|
+
description: 'Look in the Library, the open project, or both. Default: both.',
|
|
335
|
+
},
|
|
336
|
+
offset: {
|
|
337
|
+
type: 'number',
|
|
338
|
+
description: 'Skip this many results, for the next page. Default 0.',
|
|
60
339
|
},
|
|
61
340
|
directory: {
|
|
62
341
|
type: 'string',
|
|
63
|
-
description: 'Scan
|
|
342
|
+
description: 'Scan one directory of the project (relative to its root) instead of the usual asset folders.',
|
|
64
343
|
},
|
|
65
344
|
},
|
|
66
345
|
},
|
|
67
346
|
};
|
|
68
347
|
async execute(args, context) {
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
await this.scanDirectory(fullDir, cwd, assets, filterType);
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
// Directory doesn't exist — skip
|
|
81
|
-
}
|
|
348
|
+
const type = typeof args.type === 'string' && KINDS.includes(args.type) ? args.type : null;
|
|
349
|
+
const words = String(args.query ?? '').toLowerCase().split(/\s+/).filter(Boolean);
|
|
350
|
+
const where = args.where === 'library' || args.where === 'project' ? args.where : 'both';
|
|
351
|
+
const offset = Math.max(0, Math.floor(Number(args.offset) || 0));
|
|
352
|
+
const dirArg = typeof args.directory === 'string' && args.directory.trim() ? args.directory.trim() : undefined;
|
|
353
|
+
const root = typeof context.sharedState?.creativeDir === 'string' ? context.sharedState.creativeDir : defaultCreativeDir();
|
|
354
|
+
if (dirArg && (isAbsolute(dirArg) || relative(context.cwd, resolve(context.cwd, dirArg)).startsWith('..'))) {
|
|
355
|
+
return { success: false, output: 'directory must be a folder inside the project.' };
|
|
82
356
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// Root the relative-path calc AT the creative dir, so entries read
|
|
92
|
-
// "icons/foo.png" rather than a pile of ../../.. escaping the project.
|
|
93
|
-
await this.scanDirectory(creativeDir, creativeDir, studioAssets, filterType);
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
// No library yet — skip
|
|
357
|
+
const lib = where !== 'project' && !dirArg ? await readLibrary(root) : { items: [], folders: [] };
|
|
358
|
+
const project = where !== 'library' ? await readProject(context.cwd, dirArg ? [dirArg] : PROJECT_DIRS) : [];
|
|
359
|
+
let libItems = lib.items;
|
|
360
|
+
if (typeof args.folder === 'string' && args.folder.trim()) {
|
|
361
|
+
const f = findFolder(lib.folders, args.folder);
|
|
362
|
+
if (!f) {
|
|
363
|
+
const names = lib.folders.map((x) => `"${folderPath(lib.folders, x)}"`).join(', ');
|
|
364
|
+
return { success: true, output: `There is no Library folder called "${args.folder}".${names ? ` The folders are: ${names}.` : ' The Library has no folders yet.'}` };
|
|
97
365
|
}
|
|
366
|
+
const under = new Set();
|
|
367
|
+
const walk = (id) => { under.add(folderPath(lib.folders, lib.folders.find((x) => x.id === id))); for (const c of lib.folders.filter((x) => x.parentId === id))
|
|
368
|
+
walk(c.id); };
|
|
369
|
+
walk(f.id);
|
|
370
|
+
libItems = libItems.filter((i) => i.folders.some((n) => under.has(n)));
|
|
371
|
+
}
|
|
372
|
+
const pick = (list) => list.filter((i) => (!type || i.kind === type) && matches(i, words));
|
|
373
|
+
const libHits = pick(libItems);
|
|
374
|
+
const projHits = typeof args.folder === 'string' && args.folder.trim() ? [] : pick(project);
|
|
375
|
+
const total = libHits.length + projHits.length;
|
|
376
|
+
const what = [type ? KIND_LABEL[type] : '', words.length ? `matching "${words.join(' ')}"` : ''].filter(Boolean).join(' ');
|
|
377
|
+
if (total === 0) {
|
|
378
|
+
const looked = [where !== 'project' && !dirArg ? 'the Library' : '', where !== 'library' ? (dirArg ? `the project's ${dirArg}` : 'the project\'s asset folders') : ''].filter(Boolean).join(' and ');
|
|
379
|
+
return { success: true, output: `Nothing ${what || 'made yet'} in ${looked}.`, metadata: { totalAssets: 0 } };
|
|
98
380
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
: `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
110
|
-
const section = (entries, prefix = '') => {
|
|
111
|
-
const grouped = {};
|
|
112
|
-
for (const a of entries)
|
|
113
|
-
(grouped[a.type] ??= []).push(a);
|
|
114
|
-
let out = '';
|
|
115
|
-
for (const [type, items] of Object.entries(grouped).sort()) {
|
|
116
|
-
out += `${type.toUpperCase()} (${items.length})\n`;
|
|
117
|
-
for (const item of items.slice(0, 50)) { // Cap at 50 per type
|
|
118
|
-
out += ` ${prefix}${item.path} (${size(item.size)})\n`;
|
|
119
|
-
}
|
|
120
|
-
if (items.length > 50)
|
|
121
|
-
out += ` ... and ${items.length - 50} more\n`;
|
|
122
|
-
out += '\n';
|
|
381
|
+
// One page across both lists: the Library first, then the project.
|
|
382
|
+
const all = [...libHits.map((i) => ({ i, p: false })), ...projHits.map((i) => ({ i, p: true }))];
|
|
383
|
+
const page = all.slice(offset, offset + PAGE);
|
|
384
|
+
let out = '';
|
|
385
|
+
const libPage = page.filter((x) => !x.p);
|
|
386
|
+
const projPage = page.filter((x) => x.p);
|
|
387
|
+
if (libPage.length) {
|
|
388
|
+
out += `In their Library — ${libHits.length} piece${libHits.length === 1 ? '' : 's'}${what ? ` ${what}` : ''}. These live outside the project, so the paths are absolute: copy a file into the project to use it there.\n`;
|
|
389
|
+
if (lib.folders.length && offset === 0 && !args.folder) {
|
|
390
|
+
out += `Folders: ${lib.folders.map((f) => `"${folderPath(lib.folders, f)}" (${f.members.length})${f.note ? ` — ${f.note}` : ''}`).join('; ')}\n`;
|
|
123
391
|
}
|
|
124
|
-
|
|
125
|
-
};
|
|
126
|
-
let output = '';
|
|
127
|
-
if (assets.length > 0) {
|
|
128
|
-
output += `In the project (${assets.length} asset${assets.length !== 1 ? 's' : ''}) — paths are project-relative, use them as-is:\n\n`;
|
|
129
|
-
output += section(assets);
|
|
392
|
+
out += '\n' + libPage.map((x) => describe(x.i, false)).join('\n') + '\n\n';
|
|
130
393
|
}
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
output += `In their Creative Studio library (${studioAssets.length} asset${studioAssets.length !== 1 ? 's' : ''}) — these live outside the project, so the path is absolute. To use one in the project, copy it in rather than referencing it from here:\n\n`;
|
|
135
|
-
output += section(studioAssets, `${creativeDir}/`);
|
|
394
|
+
if (projPage.length) {
|
|
395
|
+
out += `In the project — ${projHits.length} file${projHits.length === 1 ? '' : 's'}${what ? ` ${what}` : ''}. Paths are project-relative; use them as they are.\n\n`;
|
|
396
|
+
out += projPage.map((x) => describe(x.i, true)).join('\n') + '\n\n';
|
|
136
397
|
}
|
|
398
|
+
const shownTo = offset + page.length;
|
|
399
|
+
if (shownTo < total)
|
|
400
|
+
out += `Showing ${offset + 1}–${shownTo} of ${total}. For more, call again with offset ${shownTo}, or narrow it with query, type or folder.\n`;
|
|
401
|
+
else if (offset > 0)
|
|
402
|
+
out += `Showing ${offset + 1}–${shownTo} of ${total}; that is the end.\n`;
|
|
137
403
|
const byType = {};
|
|
138
|
-
for (const
|
|
139
|
-
byType[
|
|
404
|
+
for (const x of all)
|
|
405
|
+
byType[x.i.kind] = (byType[x.i.kind] ?? 0) + 1;
|
|
140
406
|
return {
|
|
141
407
|
success: true,
|
|
142
|
-
output,
|
|
143
|
-
metadata: {
|
|
144
|
-
totalAssets: assets.length + studioAssets.length,
|
|
145
|
-
projectAssets: assets.length,
|
|
146
|
-
studioAssets: studioAssets.length,
|
|
147
|
-
byType,
|
|
148
|
-
},
|
|
408
|
+
output: out.trimEnd(),
|
|
409
|
+
metadata: { totalAssets: total, projectAssets: projHits.length, studioAssets: libHits.length, byType },
|
|
149
410
|
};
|
|
150
411
|
}
|
|
151
|
-
async scanDirectory(dir, cwd, assets, filterType, depth = 0) {
|
|
152
|
-
if (depth > 5)
|
|
153
|
-
return; // Prevent deep recursion
|
|
154
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
155
|
-
for (const entry of entries) {
|
|
156
|
-
const fullPath = join(dir, entry.name);
|
|
157
|
-
if (entry.isDirectory()) {
|
|
158
|
-
// Skip node_modules, .git, dist, etc.
|
|
159
|
-
if (entry.name.startsWith('.') && entry.name !== '.ava')
|
|
160
|
-
continue;
|
|
161
|
-
if (['node_modules', 'dist', 'build', '.next', '__pycache__'].includes(entry.name))
|
|
162
|
-
continue;
|
|
163
|
-
await this.scanDirectory(fullPath, cwd, assets, filterType, depth + 1);
|
|
164
|
-
}
|
|
165
|
-
else if (entry.isFile()) {
|
|
166
|
-
const ext = extname(entry.name).toLowerCase();
|
|
167
|
-
const type = ASSET_EXTENSIONS[ext];
|
|
168
|
-
if (!type)
|
|
169
|
-
continue;
|
|
170
|
-
if (filterType !== 'all' && type !== filterType)
|
|
171
|
-
continue;
|
|
172
|
-
try {
|
|
173
|
-
const info = await stat(fullPath);
|
|
174
|
-
assets.push({
|
|
175
|
-
path: relative(cwd, fullPath).replace(/\\/g, '/'),
|
|
176
|
-
type,
|
|
177
|
-
size: info.size,
|
|
178
|
-
name: entry.name,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
catch {
|
|
182
|
-
// Stat failed — skip
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
412
|
}
|
|
188
413
|
//# sourceMappingURL=browse-library.js.map
|