@arcadia-eternity/content-sdk 4.3.4 → 4.4.0
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 +3 -3
- package/bin/arcadia-content-mcp.mjs +2 -0
- package/bin/arcadia-content.mjs +2 -0
- package/dist/asset-inspect.d.ts +30 -0
- package/dist/asset-inspect.js +84 -0
- package/dist/author-api.d.ts +48 -0
- package/dist/author-api.js +128 -0
- package/dist/author-reference.d.ts +61 -0
- package/dist/author-reference.js +130 -0
- package/dist/build-content.d.ts +2 -0
- package/dist/build-content.js +29 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +81 -0
- package/dist/content-query.d.ts +30 -0
- package/dist/content-query.js +326 -0
- package/dist/content-workspace.d.ts +204 -0
- package/dist/content-workspace.js +981 -0
- package/dist/debug-environments.d.ts +96 -0
- package/dist/debug-environments.js +135 -0
- package/dist/demo.d.ts +1 -0
- package/dist/demo.js +18 -0
- package/dist/effect-build.d.ts +3 -0
- package/dist/effect-build.js +44 -0
- package/dist/environment-rules.d.ts +7 -0
- package/dist/environment-rules.js +94 -0
- package/dist/environment.d.ts +48 -0
- package/dist/environment.js +184 -0
- package/dist/job-journal.d.ts +19 -0
- package/dist/job-journal.js +110 -0
- package/dist/jobs.d.ts +103 -0
- package/dist/jobs.js +626 -0
- package/dist/lib/content.d.ts +24 -0
- package/dist/lib/content.js +106 -0
- package/dist/lib/presentation.d.ts +26 -0
- package/dist/lib/presentation.js +252 -0
- package/dist/lib/yaml-sharing.d.ts +16 -0
- package/dist/lib/yaml-sharing.js +130 -0
- package/dist/managed-projects.d.ts +37 -0
- package/dist/managed-projects.js +305 -0
- package/dist/managed-sources.d.ts +28 -0
- package/dist/managed-sources.js +541 -0
- package/dist/mcp-contracts.d.ts +420 -0
- package/dist/mcp-contracts.js +146 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +228 -0
- package/dist/module-path.d.ts +1 -0
- package/dist/module-path.js +8 -0
- package/dist/pack-project.d.ts +10 -0
- package/dist/pack-project.js +178 -0
- package/dist/preview-control.d.ts +17 -0
- package/dist/preview-control.js +273 -0
- package/dist/preview.d.ts +24 -0
- package/dist/preview.js +332 -0
- package/dist/project-teams.d.ts +51 -0
- package/dist/project-teams.js +106 -0
- package/dist/project.d.ts +18 -0
- package/dist/project.js +146 -0
- package/dist/rename.d.ts +2 -0
- package/dist/rename.js +128 -0
- package/dist/setup.d.ts +2 -0
- package/dist/setup.js +117 -0
- package/dist/source-lock.d.ts +9 -0
- package/dist/source-lock.js +117 -0
- package/dist/template/README.md +2 -0
- package/dist/template/docs/presentation.md +3 -3
- package/dist/template/package.json +3 -7
- package/dist/template/test/pack.test.mjs +10 -7
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +205 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +14 -0
- package/dist/workbench-context.d.ts +10 -0
- package/dist/workbench-context.js +27 -0
- package/dist/workspace-cli.d.ts +1 -0
- package/dist/workspace-cli.js +66 -0
- package/dist/workspace-materials.d.ts +19 -0
- package/dist/workspace-materials.js +165 -0
- package/dist/workspace.d.ts +190 -0
- package/dist/workspace.js +726 -0
- package/package.json +34 -27
- package/dist/asset-inspect.mjs +0 -67
- package/dist/author-api.mjs +0 -112
- package/dist/author-reference.mjs +0 -121
- package/dist/build-content.mjs +0 -30
- package/dist/cli.mjs +0 -76
- package/dist/content-query.mjs +0 -283
- package/dist/content-workspace.d.mts +0 -161
- package/dist/content-workspace.mjs +0 -936
- package/dist/debug-environments.mjs +0 -154
- package/dist/demo.mjs +0 -22
- package/dist/effect-build.d.mts +0 -2
- package/dist/effect-build.mjs +0 -46
- package/dist/environment-rules.d.mts +0 -5
- package/dist/environment-rules.mjs +0 -92
- package/dist/environment.mjs +0 -183
- package/dist/job-journal.mjs +0 -94
- package/dist/jobs.mjs +0 -579
- package/dist/lib/content.mjs +0 -95
- package/dist/lib/presentation.mjs +0 -240
- package/dist/lib/yaml-sharing.mjs +0 -101
- package/dist/managed-projects.d.mts +0 -35
- package/dist/managed-projects.mjs +0 -303
- package/dist/managed-sources.d.mts +0 -19
- package/dist/managed-sources.mjs +0 -503
- package/dist/mcp-contracts.mjs +0 -153
- package/dist/mcp.mjs +0 -369
- package/dist/pack-project.mjs +0 -157
- package/dist/preview-control.mjs +0 -260
- package/dist/preview.mjs +0 -313
- package/dist/project-teams.mjs +0 -98
- package/dist/project.mjs +0 -140
- package/dist/rename.mjs +0 -112
- package/dist/setup.mjs +0 -134
- package/dist/source-lock.mjs +0 -103
- package/dist/testing.mjs +0 -204
- package/dist/workbench-context.mjs +0 -18
- package/dist/workspace-cli.mjs +0 -60
- package/dist/workspace-materials.mjs +0 -153
- package/dist/workspace.mjs +0 -684
- /package/dist/{index.d.mts → index.d.ts} +0 -0
- /package/dist/{index.mjs → index.js} +0 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { lstat, readFile, realpath } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { AuthorWorkspace, WorkspaceError, diagnostic, } from './workspace.js';
|
|
4
|
+
import { recordSharing } from './lib/yaml-sharing.js';
|
|
5
|
+
import { errorCode, isRecord } from './types.js';
|
|
6
|
+
const kinds = ['content', 'presentations', 'resources', 'assets', 'files', 'locales', 'diagnostics'];
|
|
7
|
+
const contentKinds = ['species', 'skills', 'marks', 'behaviors', 'presentations', 'resources'];
|
|
8
|
+
const scopes = ['project', 'dependencies', 'all'];
|
|
9
|
+
const details = ['summary', 'full'];
|
|
10
|
+
const localeKinds = {
|
|
11
|
+
species: 'species',
|
|
12
|
+
skill: 'skills',
|
|
13
|
+
mark: 'marks',
|
|
14
|
+
mark_ability: 'marks',
|
|
15
|
+
mark_emblem: 'marks',
|
|
16
|
+
mark_global: 'marks',
|
|
17
|
+
};
|
|
18
|
+
const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
19
|
+
function invalid(message) {
|
|
20
|
+
throw new WorkspaceError('QUERY_INVALID', message);
|
|
21
|
+
}
|
|
22
|
+
const pageBytes = 2 * 1024 * 1024;
|
|
23
|
+
const packageLimit = 256;
|
|
24
|
+
const packageNamePattern = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9][a-z0-9_.-]*$/i;
|
|
25
|
+
function options(input = {}) {
|
|
26
|
+
const kind = input.kind ?? 'content';
|
|
27
|
+
const scope = input.scope ?? 'project';
|
|
28
|
+
const detail = input.detail ?? 'summary';
|
|
29
|
+
if (typeof kind !== 'string' || !kinds.includes(kind))
|
|
30
|
+
invalid('查询类型无效');
|
|
31
|
+
if (typeof scope !== 'string' || !scopes.includes(scope))
|
|
32
|
+
invalid('查询范围无效');
|
|
33
|
+
if (typeof detail !== 'string' || !details.includes(detail))
|
|
34
|
+
invalid('查询详情级别无效');
|
|
35
|
+
const contentKind = input.contentKind;
|
|
36
|
+
if (contentKind !== undefined &&
|
|
37
|
+
(typeof contentKind !== 'string' || !contentKinds.includes(contentKind)))
|
|
38
|
+
invalid('内容类型无效');
|
|
39
|
+
for (const key of ['search', 'id', 'locale', 'namespace', 'packageName']) {
|
|
40
|
+
const value = input[key];
|
|
41
|
+
if (value !== undefined && (typeof value !== 'string' || value.length > 200))
|
|
42
|
+
invalid(`${key} 需要不超过 200 字符的文本`);
|
|
43
|
+
}
|
|
44
|
+
const offset = input.offset ?? 0;
|
|
45
|
+
const limit = input.limit ?? 50;
|
|
46
|
+
if (typeof offset !== 'number' || !Number.isInteger(offset) || offset < 0)
|
|
47
|
+
invalid('offset 需要非负整数');
|
|
48
|
+
if (typeof limit !== 'number' || !Number.isInteger(limit) || limit < 1 || limit > 100)
|
|
49
|
+
invalid('limit 需要 1–100 的整数');
|
|
50
|
+
return {
|
|
51
|
+
kind: kind,
|
|
52
|
+
scope: scope,
|
|
53
|
+
detail: detail,
|
|
54
|
+
search: typeof input.search === 'string' ? input.search : '',
|
|
55
|
+
offset,
|
|
56
|
+
limit,
|
|
57
|
+
...(typeof contentKind === 'string' ? { contentKind } : {}),
|
|
58
|
+
...(typeof input.id === 'string' ? { id: input.id } : {}),
|
|
59
|
+
...(typeof input.locale === 'string' ? { locale: input.locale } : {}),
|
|
60
|
+
...(typeof input.namespace === 'string' ? { namespace: input.namespace } : {}),
|
|
61
|
+
...(typeof input.packageName === 'string' ? { packageName: input.packageName } : {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function runtimeDependencies(manifest) {
|
|
65
|
+
const entries = new Map();
|
|
66
|
+
const metadata = isRecord(manifest.peerDependenciesMeta) ? manifest.peerDependenciesMeta : {};
|
|
67
|
+
for (const field of ['dependencies', 'peerDependencies', 'optionalDependencies']) {
|
|
68
|
+
const value = manifest[field];
|
|
69
|
+
if (!isRecord(value))
|
|
70
|
+
continue;
|
|
71
|
+
for (const name of Object.keys(value).sort(compare)) {
|
|
72
|
+
if (!packageNamePattern.test(name))
|
|
73
|
+
throw new WorkspaceError('DEPENDENCY_INVALID', '依赖包名无效', 'package.json');
|
|
74
|
+
const optional = isRecord(metadata[name]) && metadata[name].optional === true;
|
|
75
|
+
entries.set(name, field === 'optionalDependencies' || optional);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [...entries].sort(([a], [b]) => compare(a, b));
|
|
79
|
+
}
|
|
80
|
+
// Resolve declared packages without executing package exports or consulting global module paths.
|
|
81
|
+
async function installedPackage(from, name) {
|
|
82
|
+
for (let directory = from;; directory = dirname(directory)) {
|
|
83
|
+
const candidate = join(directory, 'node_modules', name);
|
|
84
|
+
try {
|
|
85
|
+
const root = await realpath(candidate);
|
|
86
|
+
const file = join(root, 'package.json');
|
|
87
|
+
const info = await lstat(file);
|
|
88
|
+
if (!info.isFile() || info.size > pageBytes)
|
|
89
|
+
throw new WorkspaceError('DEPENDENCY_INVALID', '依赖清单需要不超过 2 MiB 的普通文件', file);
|
|
90
|
+
return { root, manifest: JSON.parse(await readFile(file, 'utf8')) };
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (errorCode(error) !== 'ENOENT')
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
if (dirname(directory) === directory)
|
|
97
|
+
throw new WorkspaceError('DEPENDENCY_MISSING', `未安装声明的依赖:${name}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function provenance(snapshot, scope, manifest) {
|
|
101
|
+
return {
|
|
102
|
+
namespace: snapshot.project.namespace,
|
|
103
|
+
packageName: manifest.name,
|
|
104
|
+
packageVersion: manifest.version,
|
|
105
|
+
projectId: snapshot.project.projectId,
|
|
106
|
+
scope,
|
|
107
|
+
readOnly: scope === 'dependencies' || !snapshot.capabilities.sourceEditing,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async function catalogs(workspace, scope) {
|
|
111
|
+
const manifest = JSON.parse((await workspace.read('package.json')).text);
|
|
112
|
+
const project = await workspace.snapshot();
|
|
113
|
+
const own = { snapshot: project, owner: provenance(project, 'project', manifest) };
|
|
114
|
+
const result = scope === 'dependencies' ? [] : [own];
|
|
115
|
+
const diagnostics = [];
|
|
116
|
+
if (scope === 'project')
|
|
117
|
+
return { catalogs: result, diagnostics };
|
|
118
|
+
const queue = runtimeDependencies(manifest).map(([name, optional]) => ({
|
|
119
|
+
from: workspace.root,
|
|
120
|
+
name,
|
|
121
|
+
optional,
|
|
122
|
+
}));
|
|
123
|
+
const visited = new Set([workspace.root]);
|
|
124
|
+
const identities = new Map([[project.project.namespace, manifest.name]]);
|
|
125
|
+
let inspected = 0;
|
|
126
|
+
while (queue.length) {
|
|
127
|
+
if (++inspected > packageLimit) {
|
|
128
|
+
diagnostics.push({
|
|
129
|
+
code: 'DEPENDENCY_QUERY_LIMIT',
|
|
130
|
+
severity: 'warning',
|
|
131
|
+
message: '依赖查询超过 256 项,请缩小依赖树;结果不完整',
|
|
132
|
+
});
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
const next = queue.shift();
|
|
136
|
+
if (!next)
|
|
137
|
+
break;
|
|
138
|
+
const { from, name, optional } = next;
|
|
139
|
+
let dependency;
|
|
140
|
+
try {
|
|
141
|
+
const { root, manifest: metadata } = await installedPackage(from, name);
|
|
142
|
+
if (visited.has(root))
|
|
143
|
+
continue;
|
|
144
|
+
visited.add(root);
|
|
145
|
+
if (metadata.arcadia || metadata.name === '@arcadia-eternity/data-pack-base') {
|
|
146
|
+
dependency = await AuthorWorkspace.open(root, { watch: false, readOnly: true, published: !!metadata.arcadia });
|
|
147
|
+
const snapshot = await dependency.snapshot();
|
|
148
|
+
const owner = provenance(snapshot, 'dependencies', metadata);
|
|
149
|
+
const previous = identities.get(owner.namespace);
|
|
150
|
+
if (previous !== undefined)
|
|
151
|
+
diagnostics.push({
|
|
152
|
+
...owner,
|
|
153
|
+
code: 'NAMESPACE_CONFLICT',
|
|
154
|
+
severity: 'error',
|
|
155
|
+
message: `命名空间 ${owner.namespace} 同时用于 ${previous} 和 ${metadata.name}`,
|
|
156
|
+
});
|
|
157
|
+
identities.set(owner.namespace, metadata.name);
|
|
158
|
+
result.push({ snapshot, owner });
|
|
159
|
+
// Match the loader's visible content dependencies: stop at each content package.
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
queue.push(...runtimeDependencies(metadata).map(([child, absentAllowed]) => ({
|
|
163
|
+
from: root,
|
|
164
|
+
name: child,
|
|
165
|
+
optional: absentAllowed,
|
|
166
|
+
})));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
if (!(optional && errorCode(error) === 'DEPENDENCY_MISSING'))
|
|
171
|
+
diagnostics.push({ ...diagnostic(error), packageName: name, scope: 'dependencies', readOnly: true });
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
await dependency?.close();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return { catalogs: result, diagnostics };
|
|
178
|
+
}
|
|
179
|
+
function translations(snapshot, row, locale) {
|
|
180
|
+
return snapshot.localeSources
|
|
181
|
+
.flatMap((source) => {
|
|
182
|
+
const entries = isRecord(source.entries) ? source.entries : undefined;
|
|
183
|
+
const entry = entries?.[row.record.id];
|
|
184
|
+
return localeKinds[source.namespace] === row.kind && (!locale || source.language === locale) && isRecord(entry)
|
|
185
|
+
? [{ locale: source.language, localeNamespace: source.namespace, ...entry }]
|
|
186
|
+
: [];
|
|
187
|
+
})
|
|
188
|
+
.sort((a, b) => compare(a.locale, b.locale) || compare(a.localeNamespace, b.localeNamespace));
|
|
189
|
+
}
|
|
190
|
+
function nameFields(localizations, requested, fallback) {
|
|
191
|
+
const locale = requested ?? localizations.find(entry => entry.locale === 'zh-CN')?.locale ?? localizations[0]?.locale;
|
|
192
|
+
const names = [
|
|
193
|
+
...new Set(localizations
|
|
194
|
+
.filter(entry => entry.locale === locale)
|
|
195
|
+
.map(entry => entry.name)
|
|
196
|
+
.filter((value) => typeof value === 'string' && value.length > 0)),
|
|
197
|
+
];
|
|
198
|
+
return {
|
|
199
|
+
...(locale ? { locale } : {}),
|
|
200
|
+
...(names.length === 1
|
|
201
|
+
? { name: names[0].slice(0, 200) }
|
|
202
|
+
: !names.length && typeof fallback === 'string'
|
|
203
|
+
? { name: fallback.slice(0, 200) }
|
|
204
|
+
: {}),
|
|
205
|
+
...(names.length > 1 ? { ambiguousName: true } : {}),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function rowsFor(catalog, query) {
|
|
209
|
+
const { snapshot, owner } = catalog;
|
|
210
|
+
const identify = (id, kind, source = {}) => ({
|
|
211
|
+
...owner,
|
|
212
|
+
kind,
|
|
213
|
+
id,
|
|
214
|
+
qualifiedId: `${owner.namespace}:${id}`,
|
|
215
|
+
...source,
|
|
216
|
+
});
|
|
217
|
+
if (query.kind === 'locales')
|
|
218
|
+
return snapshot.localeSources.flatMap(source => {
|
|
219
|
+
const entries = isRecord(source.entries) ? source.entries : {};
|
|
220
|
+
return Object.entries(entries).flatMap(([id, record]) => {
|
|
221
|
+
if (!isRecord(record))
|
|
222
|
+
return [];
|
|
223
|
+
const row = identify(id, 'locales', {
|
|
224
|
+
contentKind: localeKinds[source.namespace],
|
|
225
|
+
file: source.file,
|
|
226
|
+
version: source.version,
|
|
227
|
+
locale: source.language,
|
|
228
|
+
localeNamespace: source.namespace,
|
|
229
|
+
...(source.locations?.[id] ?? {}),
|
|
230
|
+
});
|
|
231
|
+
return [
|
|
232
|
+
{
|
|
233
|
+
row,
|
|
234
|
+
text: JSON.stringify({ ...row, ...record }),
|
|
235
|
+
full: { ...row, record, sharedFields: recordSharing(source.sharedFields, id) },
|
|
236
|
+
summary: {
|
|
237
|
+
...row,
|
|
238
|
+
...(typeof record.name === 'string' ? { name: record.name.slice(0, 200) } : {}),
|
|
239
|
+
...(typeof record.description === 'string'
|
|
240
|
+
? { descriptionPreview: record.description.slice(0, 240) }
|
|
241
|
+
: {}),
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
];
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
if (query.kind === 'files' || query.kind === 'diagnostics')
|
|
248
|
+
return (query.kind === 'files' ? snapshot.files : snapshot.diagnostics).map((entry) => {
|
|
249
|
+
const row = { ...owner, kind: query.kind, ...entry };
|
|
250
|
+
return { row, text: JSON.stringify(row), full: row, summary: row };
|
|
251
|
+
});
|
|
252
|
+
if (query.kind === 'assets')
|
|
253
|
+
return snapshot.assets.map((asset) => {
|
|
254
|
+
const definition = snapshot.records.find(row => row.kind === 'resources' && row.record.id === asset.id && row.file === asset.definition);
|
|
255
|
+
const { kind: resourceKind, ...metadata } = asset;
|
|
256
|
+
const row = identify(asset.id, 'assets', {
|
|
257
|
+
contentKind: 'resources',
|
|
258
|
+
resourceKind,
|
|
259
|
+
...metadata,
|
|
260
|
+
...(definition ? { version: definition.version, index: definition.index } : {}),
|
|
261
|
+
});
|
|
262
|
+
const { references, ...summary } = row;
|
|
263
|
+
return {
|
|
264
|
+
row,
|
|
265
|
+
text: JSON.stringify(row),
|
|
266
|
+
full: row,
|
|
267
|
+
summary: { ...summary, referenceCount: Array.isArray(references) ? references.length : 0 },
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
return snapshot.records
|
|
271
|
+
.filter(row => !['presentations', 'resources'].includes(query.kind) || row.kind === query.kind)
|
|
272
|
+
.map((source) => {
|
|
273
|
+
const localizations = translations(snapshot, source, query.locale);
|
|
274
|
+
const row = identify(source.record.id, source.kind, {
|
|
275
|
+
contentKind: source.kind,
|
|
276
|
+
file: source.file,
|
|
277
|
+
version: source.version,
|
|
278
|
+
index: source.index,
|
|
279
|
+
...(source.line ? { line: source.line, column: source.column } : {}),
|
|
280
|
+
...nameFields(localizations, query.locale, source.record.name),
|
|
281
|
+
});
|
|
282
|
+
return {
|
|
283
|
+
row,
|
|
284
|
+
text: JSON.stringify({ ...row, record: source.record, localizations }),
|
|
285
|
+
summary: row,
|
|
286
|
+
full: { ...row, record: source.record, sharedFields: source.sharedFields, localizations },
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/** Read-only discovery over disk data. Never loads effects or changes workbench selection/drafts. */
|
|
291
|
+
export async function queryContent(workspace, input = {}) {
|
|
292
|
+
const query = options(input);
|
|
293
|
+
const { catalogs: sources, diagnostics } = await catalogs(workspace, query.scope);
|
|
294
|
+
const needle = query.search.toLowerCase();
|
|
295
|
+
const rows = sources
|
|
296
|
+
.flatMap(source => rowsFor(source, query))
|
|
297
|
+
.filter(({ row, text }) => (query.id === undefined || row.id === query.id || row.qualifiedId === query.id) &&
|
|
298
|
+
(query.contentKind === undefined || row.contentKind === query.contentKind) &&
|
|
299
|
+
(query.namespace === undefined || row.namespace === query.namespace) &&
|
|
300
|
+
(query.packageName === undefined || row.packageName === query.packageName) &&
|
|
301
|
+
(query.kind !== 'locales' || query.locale === undefined || row.locale === query.locale) &&
|
|
302
|
+
text.toLowerCase().includes(needle));
|
|
303
|
+
if (query.id !== undefined &&
|
|
304
|
+
['content', 'presentations', 'resources', 'assets'].includes(query.kind) &&
|
|
305
|
+
rows.length > 1)
|
|
306
|
+
diagnostics.push({
|
|
307
|
+
code: 'CONTENT_AMBIGUOUS',
|
|
308
|
+
severity: 'warning',
|
|
309
|
+
message: '此 ID 对应多个对象;请使用 contentKind、namespace 或 packageName 明确目标',
|
|
310
|
+
});
|
|
311
|
+
const items = [];
|
|
312
|
+
let bytes = 0;
|
|
313
|
+
for (const candidate of rows.slice(query.offset, query.offset + query.limit)) {
|
|
314
|
+
const item = candidate[query.detail === 'full' ? 'full' : 'summary'];
|
|
315
|
+
const size = Buffer.byteLength(JSON.stringify(item));
|
|
316
|
+
if (bytes + size > pageBytes) {
|
|
317
|
+
if (!items.length)
|
|
318
|
+
throw new WorkspaceError('QUERY_ITEM_TOO_LARGE', '此详情超过 2 MiB,请查询摘要并读取对应源码文件');
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
bytes += size;
|
|
322
|
+
items.push(item);
|
|
323
|
+
}
|
|
324
|
+
const next = query.offset + items.length;
|
|
325
|
+
return { total: rows.length, offset: query.offset, nextOffset: next < rows.length ? next : null, items, diagnostics };
|
|
326
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
export interface EnvironmentRules {
|
|
2
|
+
schemaVersion: 1;
|
|
3
|
+
tier?: string;
|
|
4
|
+
allow?: {
|
|
5
|
+
species?: string[];
|
|
6
|
+
skills?: string[];
|
|
7
|
+
marks?: string[];
|
|
8
|
+
};
|
|
9
|
+
deny?: {
|
|
10
|
+
species?: string[];
|
|
11
|
+
skills?: string[];
|
|
12
|
+
marks?: string[];
|
|
13
|
+
};
|
|
14
|
+
team?: {
|
|
15
|
+
minSize?: number;
|
|
16
|
+
maxSize?: number;
|
|
17
|
+
uniqueSpecies?: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface EnvironmentDocument {
|
|
21
|
+
schemaVersion: 2;
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
packages: Record<string, string>;
|
|
25
|
+
sources: string[];
|
|
26
|
+
disabled?: {
|
|
27
|
+
packages: Record<string, string>;
|
|
28
|
+
sources: string[];
|
|
29
|
+
};
|
|
30
|
+
rules: EnvironmentRules;
|
|
31
|
+
requires: {
|
|
32
|
+
engine?: string;
|
|
33
|
+
sdk?: string;
|
|
34
|
+
capabilities?: string[];
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface EnvironmentDraft {
|
|
38
|
+
document: EnvironmentDocument;
|
|
39
|
+
revision: string;
|
|
40
|
+
}
|
|
41
|
+
export interface EnvironmentVersion {
|
|
42
|
+
format: 'arcadia.environment-version/1';
|
|
43
|
+
versionId: string;
|
|
44
|
+
workspaceId: string;
|
|
45
|
+
environmentId: string;
|
|
46
|
+
document: EnvironmentDocument;
|
|
47
|
+
draftRevision: string;
|
|
48
|
+
contentRevision: string;
|
|
49
|
+
members?: EnvironmentMember[];
|
|
50
|
+
packages: unknown[];
|
|
51
|
+
createdAt: number;
|
|
52
|
+
adopted: boolean;
|
|
53
|
+
materialDirectory: string;
|
|
54
|
+
directory: string;
|
|
55
|
+
status: 'ready';
|
|
56
|
+
}
|
|
57
|
+
export interface UnavailableVersion {
|
|
58
|
+
versionId: string;
|
|
59
|
+
workspaceId: string;
|
|
60
|
+
environmentId?: string;
|
|
61
|
+
status: 'unavailable';
|
|
62
|
+
reason: string;
|
|
63
|
+
}
|
|
64
|
+
export interface PrepareVersionInput {
|
|
65
|
+
onProgress?: (progress: {
|
|
66
|
+
stage: string;
|
|
67
|
+
completed?: number;
|
|
68
|
+
total?: number;
|
|
69
|
+
}) => void | Promise<void>;
|
|
70
|
+
environmentId: string;
|
|
71
|
+
expectedRevision: string;
|
|
72
|
+
projectDirectory?: string;
|
|
73
|
+
directory?: string;
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
beforeCommit?: () => Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export type StaticPreparer = (input: {
|
|
78
|
+
directory: string;
|
|
79
|
+
draft: EnvironmentDocument;
|
|
80
|
+
signal?: AbortSignal;
|
|
81
|
+
}) => Promise<{
|
|
82
|
+
contentRevision: string;
|
|
83
|
+
packages?: unknown[];
|
|
84
|
+
}>;
|
|
85
|
+
export interface ContentWorkspaceOptions {
|
|
86
|
+
maxBytes?: number;
|
|
87
|
+
maxFiles?: number;
|
|
88
|
+
stagingRetentionMs?: number;
|
|
89
|
+
resolveProject?: (environmentId: string) => string | undefined | Promise<string | undefined>;
|
|
90
|
+
acquireMaterials?: (directory: string, versionId: string) => Promise<() => void | Promise<void>>;
|
|
91
|
+
retentions?: {
|
|
92
|
+
list(versionId: string): Promise<Record<string, unknown>[]>;
|
|
93
|
+
put?(versionId: string, retentionId: string): Promise<void>;
|
|
94
|
+
remove?(retentionId: string): Promise<void>;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface EnvironmentExport {
|
|
98
|
+
format: 'arcadia.environment-export/1';
|
|
99
|
+
document: EnvironmentDocument;
|
|
100
|
+
contentRevision: string;
|
|
101
|
+
files: {
|
|
102
|
+
path: string;
|
|
103
|
+
data: string;
|
|
104
|
+
}[];
|
|
105
|
+
}
|
|
106
|
+
export interface WorkspaceSnapshot {
|
|
107
|
+
format: 'arcadia.workspace-snapshot/1';
|
|
108
|
+
workspaceId: string;
|
|
109
|
+
drafts: EnvironmentDraft[];
|
|
110
|
+
versions: {
|
|
111
|
+
version: Pick<EnvironmentVersion, 'versionId' | 'environmentId' | 'document' | 'draftRevision' | 'contentRevision' | 'packages' | 'createdAt'>;
|
|
112
|
+
files: {
|
|
113
|
+
path: string;
|
|
114
|
+
data: string;
|
|
115
|
+
}[];
|
|
116
|
+
}[];
|
|
117
|
+
}
|
|
118
|
+
export interface WorkspaceSnapshotStamp {
|
|
119
|
+
workspaceId: string;
|
|
120
|
+
bootId: string;
|
|
121
|
+
generation: number;
|
|
122
|
+
}
|
|
123
|
+
export interface WorkspaceSnapshotCapture {
|
|
124
|
+
snapshot: WorkspaceSnapshot;
|
|
125
|
+
stamp: WorkspaceSnapshotStamp;
|
|
126
|
+
}
|
|
127
|
+
export interface ContentWorkspace {
|
|
128
|
+
readonly root: string;
|
|
129
|
+
readonly workspaceId: string;
|
|
130
|
+
readonly bootId: string;
|
|
131
|
+
listDrafts(): Promise<EnvironmentDraft[]>;
|
|
132
|
+
getDraft(environmentId: string): Promise<EnvironmentDraft>;
|
|
133
|
+
saveDraft(input: {
|
|
134
|
+
document: unknown;
|
|
135
|
+
expectedRevision: string | null;
|
|
136
|
+
}): Promise<EnvironmentDraft>;
|
|
137
|
+
deleteDraft(input: {
|
|
138
|
+
environmentId: string;
|
|
139
|
+
expectedRevision: string;
|
|
140
|
+
}): Promise<void>;
|
|
141
|
+
prepareVersion(input: PrepareVersionInput, preparer: StaticPreparer): Promise<EnvironmentVersion>;
|
|
142
|
+
adoptVersion(input: PrepareVersionInput, preparer: StaticPreparer): Promise<EnvironmentVersion>;
|
|
143
|
+
getVersion(versionId: string): Promise<EnvironmentVersion>;
|
|
144
|
+
listVersions(environmentId?: string): Promise<(EnvironmentVersion | UnavailableVersion)[]>;
|
|
145
|
+
acquire(versionId: string, owner?: string): Promise<EnvironmentVersion & {
|
|
146
|
+
release(): Promise<void>;
|
|
147
|
+
}>;
|
|
148
|
+
retain(versionId: string, retentionId: string): Promise<void>;
|
|
149
|
+
releaseRetention(retentionId: string): Promise<void>;
|
|
150
|
+
references(versionId: string): Promise<Record<string, unknown>[]>;
|
|
151
|
+
deleteVersion(versionId: string): Promise<void>;
|
|
152
|
+
exportVersion(versionId: string): Promise<EnvironmentExport>;
|
|
153
|
+
exportSnapshot(): Promise<WorkspaceSnapshot>;
|
|
154
|
+
captureSnapshot(): Promise<WorkspaceSnapshotCapture>;
|
|
155
|
+
isSnapshotCurrent(stamp: WorkspaceSnapshotStamp): Promise<boolean>;
|
|
156
|
+
restoreSnapshot(snapshot: WorkspaceSnapshot, input: {
|
|
157
|
+
mode: 'restore' | 'clone';
|
|
158
|
+
}, preparer: StaticPreparer): Promise<{
|
|
159
|
+
workspaceId: string;
|
|
160
|
+
versionIds: Record<string, string>;
|
|
161
|
+
}>;
|
|
162
|
+
importVersion(bundle: EnvironmentExport, input: {
|
|
163
|
+
environmentId?: string;
|
|
164
|
+
expectedRevision?: string | null;
|
|
165
|
+
signal?: AbortSignal;
|
|
166
|
+
beforeCommit?: () => Promise<void>;
|
|
167
|
+
importId?: string;
|
|
168
|
+
}, preparer: StaticPreparer): Promise<EnvironmentVersion>;
|
|
169
|
+
recoverImport(importId: string): Promise<EnvironmentVersion>;
|
|
170
|
+
forgetImport(importId: string, input?: {
|
|
171
|
+
discard?: boolean;
|
|
172
|
+
}): Promise<void>;
|
|
173
|
+
reconcile(): Promise<{
|
|
174
|
+
workspaceId: string;
|
|
175
|
+
versions: (EnvironmentVersion | UnavailableVersion)[];
|
|
176
|
+
abandoned: string[];
|
|
177
|
+
}>;
|
|
178
|
+
close(input?: {
|
|
179
|
+
force?: boolean;
|
|
180
|
+
}): Promise<void>;
|
|
181
|
+
cleanupStaging(): Promise<string[]>;
|
|
182
|
+
}
|
|
183
|
+
export interface ContentWorkspaceConstructor {
|
|
184
|
+
new (root: string, options?: ContentWorkspaceOptions): ContentWorkspace;
|
|
185
|
+
open(directory: string, options?: ContentWorkspaceOptions): Promise<ContentWorkspace>;
|
|
186
|
+
}
|
|
187
|
+
export interface EnvironmentMember {
|
|
188
|
+
name: string;
|
|
189
|
+
version: string;
|
|
190
|
+
projectId: string;
|
|
191
|
+
namespace: string;
|
|
192
|
+
direct: boolean;
|
|
193
|
+
dependencies: string[];
|
|
194
|
+
requiredBy: string[];
|
|
195
|
+
}
|
|
196
|
+
export declare const ContentWorkspace: ContentWorkspaceConstructor;
|
|
197
|
+
/** Change desired roots only. Resolved material and all published versions remain immutable. */
|
|
198
|
+
export declare function setEnvironmentPackageEnabled(workspace: Pick<ContentWorkspace, 'listDrafts' | 'listVersions' | 'saveDraft'>, input: {
|
|
199
|
+
environmentId: string;
|
|
200
|
+
expectedRevision: string;
|
|
201
|
+
name: string;
|
|
202
|
+
enabled: boolean;
|
|
203
|
+
cascade?: boolean;
|
|
204
|
+
}): Promise<EnvironmentDraft>;
|