@arcadia-eternity/content-sdk 4.3.4 → 4.4.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/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 +171 -0
- package/dist/content-workspace.js +981 -0
- package/dist/debug-environments.d.ts +117 -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 +13 -0
- package/dist/pack-project.js +179 -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
package/README.md
CHANGED
|
@@ -47,12 +47,12 @@ For an unpublished host build, build and stage packages from a trusted checkout:
|
|
|
47
47
|
pnpm --filter @arcadia-eternity/content-sdk... --filter @arcadia-eternity/protocol... run build
|
|
48
48
|
node scripts/stage-author-sdk.mjs /new/author-sdk
|
|
49
49
|
cd /path/to/content-pack
|
|
50
|
-
node /path/to/main-repo/packages/content-dev/src/setup.
|
|
50
|
+
node /path/to/main-repo/packages/content-dev/src/setup.ts --sdk-dir /new/author-sdk
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
The installer checks the seven required archives and SDK API version, installs the tool and SDK together without changing the pack's package metadata or creating a lockfile, and records the installation under `.arcadia/`.
|
|
54
54
|
|
|
55
|
-
The optional source-bootstrap `setup:source` entry in the independent template fetches this repository's `src/setup.
|
|
55
|
+
The optional source-bootstrap `setup:source` entry in the independent template fetches this repository's `src/setup.ts` from the exact revision in `arcadia-sdk.json`. This standalone installer uses only Node built-ins. It builds the pinned source with its lockfile, stages the development tool and SDK, and installs them. There is no copied installer in the template. After installation, `npm exec --offline -- arcadia-content setup --sdk-dir ... --offline` supports cached/offline updates. Normal template installation uses the registry release and a standard npm lockfile; the source bootstrap remains available for local SDK development.
|
|
56
56
|
|
|
57
57
|
## Object drafts and reviewed saves
|
|
58
58
|
|
|
@@ -96,4 +96,4 @@ Workspace files own environment definitions and immutable versions. Database ada
|
|
|
96
96
|
|
|
97
97
|
## Repository development
|
|
98
98
|
|
|
99
|
-
`pnpm --filter @arcadia-eternity/content-sdk watch` builds once, then rebuilds when `src`, `template`, or either bundled skill directory under `docs/guides` changes. Rebuilds are serialized, include deletions, and recover after a failed build. The root `pnpm watch` includes this watcher. `pnpm --filter @arcadia-eternity/content-sdk clear` removes `dist`; root `pnpm clear` includes it as well. The package `typecheck` validates
|
|
99
|
+
`pnpm --filter @arcadia-eternity/content-sdk watch` builds once, then rebuilds when `src`, `template`, or either bundled skill directory under `docs/guides` changes. Rebuilds are serialized, include deletions, and recover after a failed build. The root `pnpm watch` includes this watcher. `pnpm --filter @arcadia-eternity/content-sdk clear` removes `dist`; root `pnpm clear` includes it as well. The package `typecheck` validates the TypeScript implementation and generated declarations; Node tests exercise the source modules directly.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type AuthorWorkspace } from './workspace.js';
|
|
2
|
+
export declare const imageByteLimit: number;
|
|
3
|
+
interface AssetMetadata {
|
|
4
|
+
id: string | undefined;
|
|
5
|
+
kind: unknown;
|
|
6
|
+
source: unknown;
|
|
7
|
+
definition: string;
|
|
8
|
+
definitionVersion: string;
|
|
9
|
+
remote?: boolean;
|
|
10
|
+
imageAvailable?: boolean;
|
|
11
|
+
reason?: string;
|
|
12
|
+
bytes?: number;
|
|
13
|
+
mimeType?: string;
|
|
14
|
+
imageByteLimit?: number;
|
|
15
|
+
version?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface AssetInspection {
|
|
18
|
+
metadata: AssetMetadata;
|
|
19
|
+
image?: {
|
|
20
|
+
type: 'image';
|
|
21
|
+
mimeType: string;
|
|
22
|
+
data: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Read declared local resources only; remote URLs remain metadata and are never fetched. */
|
|
26
|
+
export declare function inspectAsset(workspace: AuthorWorkspace, { id, includeImage }?: {
|
|
27
|
+
id?: string;
|
|
28
|
+
includeImage?: boolean;
|
|
29
|
+
}): Promise<AssetInspection>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { stat } from 'node:fs/promises';
|
|
2
|
+
import { lookup } from 'mime-types';
|
|
3
|
+
import { validResourceId } from './lib/presentation.js';
|
|
4
|
+
import { WorkspaceError } from './workspace.js';
|
|
5
|
+
export const imageByteLimit = 2 * 1024 * 1024;
|
|
6
|
+
function fail(code, message) {
|
|
7
|
+
throw new WorkspaceError(code, message);
|
|
8
|
+
}
|
|
9
|
+
/** Read declared local resources only; remote URLs remain metadata and are never fetched. */
|
|
10
|
+
export async function inspectAsset(workspace, { id, includeImage = false } = {}) {
|
|
11
|
+
if (!validResourceId(id))
|
|
12
|
+
fail('RESOURCE_INVALID', '需要已声明资源的稳定 ID');
|
|
13
|
+
if (typeof includeImage !== 'boolean')
|
|
14
|
+
fail('RESOURCE_INVALID', 'includeImage 必须是布尔值');
|
|
15
|
+
const resourceId = id;
|
|
16
|
+
const snapshot = await workspace.snapshot();
|
|
17
|
+
const resources = snapshot.records.filter(row => row.kind === 'resources' && row.record.id === resourceId);
|
|
18
|
+
if (!resources.length)
|
|
19
|
+
fail('RESOURCE_UNKNOWN', '此项目没有声明该资源');
|
|
20
|
+
if (resources.length !== 1)
|
|
21
|
+
fail('RESOURCE_AMBIGUOUS', '资源 ID 不唯一,请先修复重复声明');
|
|
22
|
+
const definition = resources[0];
|
|
23
|
+
const { kind, source } = definition.record;
|
|
24
|
+
if (typeof source !== 'string')
|
|
25
|
+
fail('RESOURCE_INVALID', '资源缺少有效位置');
|
|
26
|
+
const metadata = {
|
|
27
|
+
id: resourceId,
|
|
28
|
+
kind,
|
|
29
|
+
source,
|
|
30
|
+
definition: definition.file,
|
|
31
|
+
definitionVersion: definition.version,
|
|
32
|
+
};
|
|
33
|
+
if (/^https?:\/\//.test(source)) {
|
|
34
|
+
const url = parseRemoteUrl(source);
|
|
35
|
+
if (url.username || url.password)
|
|
36
|
+
fail('RESOURCE_INVALID', '资源 URL 不能含有凭据');
|
|
37
|
+
return { metadata: { ...metadata, remote: true, imageAvailable: false, reason: 'REMOTE_NOT_FETCHED' } };
|
|
38
|
+
}
|
|
39
|
+
const path = await workspace.path(source);
|
|
40
|
+
const info = await stat(path);
|
|
41
|
+
if (!info.isFile())
|
|
42
|
+
fail('RESOURCE_INVALID', '资源必须是普通文件');
|
|
43
|
+
// Follow the source filename, as the authoring resource pipeline does. Decoding belongs to the client.
|
|
44
|
+
const mimeType = lookup(source) || 'application/octet-stream';
|
|
45
|
+
if (kind !== 'image' && mimeType.startsWith('image/'))
|
|
46
|
+
fail('RESOURCE_KIND_MISMATCH', '声明的资源类型与图片文件名不同');
|
|
47
|
+
const reason = kind !== 'image'
|
|
48
|
+
? 'NOT_IMAGE'
|
|
49
|
+
: !mimeType.startsWith('image/')
|
|
50
|
+
? 'IMAGE_FORMAT_UNKNOWN'
|
|
51
|
+
: info.size > imageByteLimit
|
|
52
|
+
? 'IMAGE_TOO_LARGE'
|
|
53
|
+
: undefined;
|
|
54
|
+
const result = {
|
|
55
|
+
metadata: {
|
|
56
|
+
...metadata,
|
|
57
|
+
remote: false,
|
|
58
|
+
bytes: info.size,
|
|
59
|
+
mimeType,
|
|
60
|
+
imageAvailable: !reason,
|
|
61
|
+
...(reason ? { reason } : {}),
|
|
62
|
+
imageByteLimit,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
if (!includeImage)
|
|
66
|
+
return result;
|
|
67
|
+
if (reason)
|
|
68
|
+
fail(reason, '此资源不能直接返回图片;请读取元数据或在页面查看');
|
|
69
|
+
const asset = await workspace.asset(source);
|
|
70
|
+
if (asset.bytes.length > imageByteLimit)
|
|
71
|
+
fail('IMAGE_TOO_LARGE', '图片超过 2 MiB');
|
|
72
|
+
result.metadata.bytes = asset.bytes.length;
|
|
73
|
+
result.metadata.version = asset.version;
|
|
74
|
+
result.image = { type: 'image', mimeType, data: asset.bytes.toString('base64') };
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
function parseRemoteUrl(source) {
|
|
78
|
+
try {
|
|
79
|
+
return new URL(source);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
fail('RESOURCE_INVALID', '资源 URL 无效');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DebugEnvironments } from './debug-environments.js';
|
|
2
|
+
import { ProjectTeams } from './project-teams.js';
|
|
3
|
+
import { AuthorWorkspace, type WorkspaceOptions } from './workspace.js';
|
|
4
|
+
import { AuthorJobs } from './jobs.js';
|
|
5
|
+
import { type UnknownRecord } from './types.js';
|
|
6
|
+
export { createSourceProject, connectDevelopmentSdk, authorConnection } from './project.js';
|
|
7
|
+
export { ContentWorkspace } from './content-workspace.js';
|
|
8
|
+
export { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
9
|
+
export interface AuthorSessionOptions extends WorkspaceOptions {
|
|
10
|
+
execute?: boolean;
|
|
11
|
+
contextFile?: string;
|
|
12
|
+
env?: NodeJS.ProcessEnv;
|
|
13
|
+
executable?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Shared operations for the desktop, CLI and MCP adapters. */
|
|
16
|
+
export declare function openAuthorSession(directory: string, options?: AuthorSessionOptions): Promise<{
|
|
17
|
+
workspace: AuthorWorkspace;
|
|
18
|
+
jobs: AuthorJobs;
|
|
19
|
+
teams: ProjectTeams;
|
|
20
|
+
environments: DebugEnvironments;
|
|
21
|
+
describe(): Promise<{
|
|
22
|
+
protocolVersion: number;
|
|
23
|
+
root: string;
|
|
24
|
+
name: string | undefined;
|
|
25
|
+
project: import("./workspace.js").ManifestArcadia;
|
|
26
|
+
sourceRevision: string;
|
|
27
|
+
capabilities: {
|
|
28
|
+
sourceEditing: boolean;
|
|
29
|
+
structuredSaving: boolean;
|
|
30
|
+
localeEditing: boolean;
|
|
31
|
+
yamlSharing: string;
|
|
32
|
+
externalEditor: boolean;
|
|
33
|
+
kinds: readonly string[];
|
|
34
|
+
sdkApi: unknown;
|
|
35
|
+
codeExecution: boolean;
|
|
36
|
+
};
|
|
37
|
+
diagnostics: import("./workspace.js").Diagnostic[];
|
|
38
|
+
}>;
|
|
39
|
+
query(input?: UnknownRecord): Promise<{
|
|
40
|
+
total: number;
|
|
41
|
+
offset: number;
|
|
42
|
+
nextOffset: number | null;
|
|
43
|
+
items: unknown[];
|
|
44
|
+
diagnostics: Record<string, unknown>[];
|
|
45
|
+
}>;
|
|
46
|
+
call(operation: string, input?: unknown): Promise<unknown>;
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
}>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { DebugEnvironments } from './debug-environments.js';
|
|
2
|
+
import { ProjectTeams } from './project-teams.js';
|
|
3
|
+
import { AuthorWorkspace, WorkspaceError, } from './workspace.js';
|
|
4
|
+
import { readWorkbenchContext } from './workbench-context.js';
|
|
5
|
+
import { AuthorJobs } from './jobs.js';
|
|
6
|
+
import { queryContent } from './content-query.js';
|
|
7
|
+
import { authorReference } from './author-reference.js';
|
|
8
|
+
import { inspectAsset } from './asset-inspect.js';
|
|
9
|
+
import { callPreviewControl } from './preview-control.js';
|
|
10
|
+
import { isRecord } from './types.js';
|
|
11
|
+
export { createSourceProject, connectDevelopmentSdk, authorConnection } from './project.js';
|
|
12
|
+
export { ContentWorkspace } from './content-workspace.js';
|
|
13
|
+
export { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
14
|
+
/** Shared operations for the desktop, CLI and MCP adapters. */
|
|
15
|
+
export async function openAuthorSession(directory, options = {}) {
|
|
16
|
+
const workspace = await AuthorWorkspace.open(directory, options);
|
|
17
|
+
const jobs = new AuthorJobs(workspace, options);
|
|
18
|
+
await jobs.initialize();
|
|
19
|
+
return {
|
|
20
|
+
workspace,
|
|
21
|
+
jobs,
|
|
22
|
+
teams: new ProjectTeams(workspace),
|
|
23
|
+
environments: new DebugEnvironments(workspace),
|
|
24
|
+
async describe() {
|
|
25
|
+
const snapshot = await workspace.snapshot();
|
|
26
|
+
return {
|
|
27
|
+
protocolVersion: 1,
|
|
28
|
+
root: snapshot.root,
|
|
29
|
+
name: snapshot.name,
|
|
30
|
+
project: snapshot.project,
|
|
31
|
+
sourceRevision: await workspace.revision(),
|
|
32
|
+
capabilities: { ...snapshot.capabilities, codeExecution: !workspace.readOnly && jobs.execute },
|
|
33
|
+
diagnostics: snapshot.diagnostics,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
async query(input = {}) {
|
|
37
|
+
return queryContent(workspace, input);
|
|
38
|
+
},
|
|
39
|
+
async call(operation, input = {}) {
|
|
40
|
+
if (!isRecord(input))
|
|
41
|
+
throw new WorkspaceError('INPUT_INVALID', '操作参数需要对象');
|
|
42
|
+
switch (operation) {
|
|
43
|
+
case 'context':
|
|
44
|
+
return readWorkbenchContext(options.contextFile, workspace.root);
|
|
45
|
+
case 'describe':
|
|
46
|
+
return this.describe();
|
|
47
|
+
case 'query':
|
|
48
|
+
return this.query(input);
|
|
49
|
+
case 'reference':
|
|
50
|
+
return authorReference(input);
|
|
51
|
+
case 'asset-inspect':
|
|
52
|
+
return inspectAsset(workspace, input);
|
|
53
|
+
case 'snapshot':
|
|
54
|
+
return workspace.snapshot();
|
|
55
|
+
case 'read':
|
|
56
|
+
return workspace.read(field(input, 'file'));
|
|
57
|
+
case 'write':
|
|
58
|
+
if (options.readOnly)
|
|
59
|
+
throw new WorkspaceError('WRITE_DISABLED', '此会话为只读');
|
|
60
|
+
return workspace.write(input);
|
|
61
|
+
case 'save':
|
|
62
|
+
if (options.readOnly)
|
|
63
|
+
throw new WorkspaceError('WRITE_DISABLED', '此会话为只读');
|
|
64
|
+
return workspace.saveChanges(input);
|
|
65
|
+
case 'start':
|
|
66
|
+
return jobs.start(input);
|
|
67
|
+
case 'job':
|
|
68
|
+
await jobs.refresh();
|
|
69
|
+
return jobs.get(field(input, 'jobId'));
|
|
70
|
+
case 'jobs':
|
|
71
|
+
await jobs.refresh();
|
|
72
|
+
return jobs.list();
|
|
73
|
+
case 'job-query':
|
|
74
|
+
return jobs.queryJob(input);
|
|
75
|
+
case 'jobs-query':
|
|
76
|
+
return jobs.queryJobs(input);
|
|
77
|
+
case 'job-output':
|
|
78
|
+
return jobs.readJobOutput(input);
|
|
79
|
+
case 'cancel-query': {
|
|
80
|
+
const jobId = field(input, 'jobId');
|
|
81
|
+
await jobs.refresh();
|
|
82
|
+
await jobs.cancel(jobId);
|
|
83
|
+
return jobs.queryJob({ jobId });
|
|
84
|
+
}
|
|
85
|
+
case 'team-list':
|
|
86
|
+
return { items: await this.teams.list() };
|
|
87
|
+
case 'team-save':
|
|
88
|
+
return this.teams.save(input);
|
|
89
|
+
case 'team-remove': {
|
|
90
|
+
const removal = input;
|
|
91
|
+
await this.teams.remove(removal);
|
|
92
|
+
return { id: removal.id, removed: true };
|
|
93
|
+
}
|
|
94
|
+
case 'environment-list':
|
|
95
|
+
return { items: await this.environments.list() };
|
|
96
|
+
case 'environment-save':
|
|
97
|
+
return this.environments.save(input);
|
|
98
|
+
case 'battle': {
|
|
99
|
+
if (workspace.readOnly || !jobs.execute)
|
|
100
|
+
throw new WorkspaceError('EXECUTION_DISABLED', '自动化对局需要可执行的作者会话。');
|
|
101
|
+
await jobs.refresh();
|
|
102
|
+
const job = jobs.get(field(input, 'jobId'));
|
|
103
|
+
if (job.kind !== 'preview' || job.state !== 'succeeded' || !job.result?.preview?.endpoint)
|
|
104
|
+
throw new WorkspaceError('PREVIEW_NOT_ACTIVE', '此任务没有运行中的试玩候选。');
|
|
105
|
+
const { jobId: _jobId, operation: action, ...args } = input;
|
|
106
|
+
if (typeof action !== 'string')
|
|
107
|
+
throw new WorkspaceError('INPUT_INVALID', '需要战斗操作');
|
|
108
|
+
return callPreviewControl(job.result.preview.endpoint, action, args);
|
|
109
|
+
}
|
|
110
|
+
case 'cancel':
|
|
111
|
+
await jobs.refresh();
|
|
112
|
+
return jobs.cancel(field(input, 'jobId'));
|
|
113
|
+
default:
|
|
114
|
+
throw new WorkspaceError('OPERATION_INVALID', '不支持的作者操作');
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
async close() {
|
|
118
|
+
await jobs.close();
|
|
119
|
+
await workspace.close();
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function field(input, name) {
|
|
124
|
+
const value = input[name];
|
|
125
|
+
if (typeof value !== 'string')
|
|
126
|
+
throw new WorkspaceError('INPUT_INVALID', `${name} 需要字符串`);
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare const referenceTopics: readonly ['species', 'skills', 'marks', 'team', 'environment', 'descriptions', 'effects'];
|
|
2
|
+
/** Discover installed SDK contracts, without importing a content project's executable effects. */
|
|
3
|
+
export declare function authorReference({ topic }?: {
|
|
4
|
+
topic?: string;
|
|
5
|
+
}): Promise<{
|
|
6
|
+
topic: string;
|
|
7
|
+
title: string;
|
|
8
|
+
source: string;
|
|
9
|
+
stage: string;
|
|
10
|
+
schema: {
|
|
11
|
+
[x: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
examples: {
|
|
14
|
+
language: string;
|
|
15
|
+
text: string;
|
|
16
|
+
}[];
|
|
17
|
+
notes: string[];
|
|
18
|
+
tags?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
topic: string;
|
|
21
|
+
title: string;
|
|
22
|
+
source: string;
|
|
23
|
+
stage: string;
|
|
24
|
+
schema: {
|
|
25
|
+
properties: {
|
|
26
|
+
team: {
|
|
27
|
+
items: unknown;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
examples: {
|
|
32
|
+
language: string;
|
|
33
|
+
text: string;
|
|
34
|
+
}[];
|
|
35
|
+
notes: string[];
|
|
36
|
+
tags?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
stage?: undefined;
|
|
39
|
+
schema?: undefined;
|
|
40
|
+
topic: string;
|
|
41
|
+
title: string;
|
|
42
|
+
source: string;
|
|
43
|
+
examples: {
|
|
44
|
+
language: string;
|
|
45
|
+
text: string;
|
|
46
|
+
}[];
|
|
47
|
+
notes: string[];
|
|
48
|
+
tags?: undefined;
|
|
49
|
+
} | {
|
|
50
|
+
stage?: undefined;
|
|
51
|
+
schema?: undefined;
|
|
52
|
+
topic: string;
|
|
53
|
+
title: string;
|
|
54
|
+
source: string;
|
|
55
|
+
tags: string[];
|
|
56
|
+
examples: {
|
|
57
|
+
language: string;
|
|
58
|
+
text: string;
|
|
59
|
+
}[];
|
|
60
|
+
notes: string[];
|
|
61
|
+
}>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { toJsonSchemaCompat } from '@modelcontextprotocol/sdk/server/zod-json-schema-compat.js';
|
|
3
|
+
import { NativeSpeciesSchema, NativeSkillSchema, NativeMarkSchema } from '@arcadia-eternity/battle/engine';
|
|
4
|
+
import { teamEnvelopeSchema, portablePetSchema } from './project-teams.js';
|
|
5
|
+
import { EnvironmentDocumentSchema } from './debug-environments.js';
|
|
6
|
+
import { WorkspaceError } from './workspace.js';
|
|
7
|
+
import { errorCode } from './types.js';
|
|
8
|
+
export const referenceTopics = ['species', 'skills', 'marks', 'team', 'environment', 'descriptions', 'effects'];
|
|
9
|
+
const parserSchemas = {
|
|
10
|
+
species: NativeSpeciesSchema,
|
|
11
|
+
skills: NativeSkillSchema,
|
|
12
|
+
marks: NativeMarkSchema,
|
|
13
|
+
};
|
|
14
|
+
const examples = {
|
|
15
|
+
species: 'data/species/pet.yaml',
|
|
16
|
+
skills: 'data/skills/strike.yaml',
|
|
17
|
+
marks: 'data/marks/slow.yaml',
|
|
18
|
+
};
|
|
19
|
+
async function template(file) {
|
|
20
|
+
try {
|
|
21
|
+
return await readFile(new URL(`./template/${file}`, import.meta.url), 'utf8');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (errorCode(error) !== 'ENOENT')
|
|
25
|
+
throw error;
|
|
26
|
+
return readFile(new URL(`../template/${file}`, import.meta.url), 'utf8');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Discover installed SDK contracts, without importing a content project's executable effects. */
|
|
30
|
+
export async function authorReference({ topic } = {}) {
|
|
31
|
+
if (!topic || !referenceTopics.includes(topic))
|
|
32
|
+
throw new WorkspaceError('REFERENCE_UNKNOWN', '请选择有效的作者参考主题');
|
|
33
|
+
if (parserSchemas[topic]) {
|
|
34
|
+
return {
|
|
35
|
+
topic,
|
|
36
|
+
title: `${topic}: parser fields and source example`,
|
|
37
|
+
source: '@arcadia-eternity/battle/engine',
|
|
38
|
+
stage: 'linked-runtime',
|
|
39
|
+
schema: toJsonSchemaCompat(parserSchemas[topic]),
|
|
40
|
+
examples: [{ language: 'yaml', text: await template(examples[topic] ?? '') }],
|
|
41
|
+
notes: [
|
|
42
|
+
'This is the actual parser schema AFTER package linking, not a validator for unlinked source documents. JSON Schema cannot express every Zod refinement; run check and tests.',
|
|
43
|
+
'Source IDs are local stable IDs. Package linking produces namespace:id runtime IDs. Official base references retain their existing IDs.',
|
|
44
|
+
'Source relationship slots use {$ref:{projectId,kind,id}} for package content: species learnable_skills[].skill_id uses kind skill; ability/emblem use mark; skills/marks behaviors[].definitionId uses behavior. Declare dependencies and resolve actual IDs before writing.',
|
|
45
|
+
'Keep rules, data/presentations, data/resources and localized names/descriptions separate. Do not infer behavior from description text.',
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (topic === 'team') {
|
|
50
|
+
const schema = toJsonSchemaCompat(teamEnvelopeSchema);
|
|
51
|
+
schema.properties.team.items = JSON.parse(JSON.stringify(portablePetSchema));
|
|
52
|
+
return {
|
|
53
|
+
topic,
|
|
54
|
+
title: 'Portable project team',
|
|
55
|
+
source: '@arcadia-eternity/content-sdk/project-teams',
|
|
56
|
+
stage: 'source',
|
|
57
|
+
schema,
|
|
58
|
+
examples: [{ language: 'yaml', text: 'schemaVersion: 1\nid: blue\nname: 蓝队\nteam: []\n' }],
|
|
59
|
+
notes: [
|
|
60
|
+
'Save debug/teams/<id>.yaml with expectedVersion. Pets have no runtime id. Order determines the lead pet; an empty team is editable but cannot start a battle.',
|
|
61
|
+
'Saving project teams does not change local page drafts, selected teams or an already running battle. Re-read before retrying a conflict.',
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (topic === 'environment') {
|
|
66
|
+
return {
|
|
67
|
+
topic,
|
|
68
|
+
title: 'Named project environment',
|
|
69
|
+
source: '@arcadia-eternity/content-sdk/debug-environments',
|
|
70
|
+
stage: 'source',
|
|
71
|
+
schema: toJsonSchemaCompat(EnvironmentDocumentSchema),
|
|
72
|
+
examples: [
|
|
73
|
+
{
|
|
74
|
+
language: 'json',
|
|
75
|
+
text: JSON.stringify({ schemaVersion: 1, id: 'interaction', name: '双包交互', packages: {}, sources: [] }),
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
notes: [
|
|
79
|
+
'default is built in and cannot be saved as a named environment. Names must be nonblank; source package names must be unique.',
|
|
80
|
+
'packages accepts registry version constraints, never file:/link:/workspace: or filesystem paths. sources lists package names already mapped locally; it does not contain paths.',
|
|
81
|
+
'Save with expectedVersion. Updating a named environment neither selects it in the page nor changes a running candidate; prepare a new preview explicitly.',
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (topic === 'effects') {
|
|
86
|
+
return {
|
|
87
|
+
topic,
|
|
88
|
+
title: 'Native TypeScript effects',
|
|
89
|
+
source: '@arcadia-eternity/content-sdk/dist/template/src/effects/slow.effect.ts',
|
|
90
|
+
examples: [{ language: 'typescript', text: await template('src/effects/slow.effect.ts') }],
|
|
91
|
+
notes: [
|
|
92
|
+
'Import EffectModuleContext from @arcadia-eternity/content-sdk and use the host-supplied SDK. Importing an effect module must not register global state.',
|
|
93
|
+
'defineCodeEffect uses triggers/apply. ctx.trigger identifies the trigger; ctx.parent is the typed parent context. Use stable namespaced IDs and actual behavior definitions.',
|
|
94
|
+
'This installed template is the executable example. Query content, read source versions, check, and run behavior tests after edits. No Rule Graph/DSL conversion is needed.',
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
topic,
|
|
100
|
+
title: 'ICU descriptions and semantic tags',
|
|
101
|
+
source: 'docs/guides/content-presentation.md; packages/web-ui/src/i18n/richDescription.ts',
|
|
102
|
+
tags: [
|
|
103
|
+
'markName',
|
|
104
|
+
'status',
|
|
105
|
+
'guaranteedHit',
|
|
106
|
+
'damage',
|
|
107
|
+
'heal',
|
|
108
|
+
'shield',
|
|
109
|
+
'buff',
|
|
110
|
+
'debuff',
|
|
111
|
+
'rage',
|
|
112
|
+
'strong',
|
|
113
|
+
'emphasis',
|
|
114
|
+
'mark',
|
|
115
|
+
],
|
|
116
|
+
examples: [
|
|
117
|
+
{
|
|
118
|
+
language: 'text',
|
|
119
|
+
text: '造成 <damage>{power}</damage> 点伤害,并附加 <mark>example-content-pack:slow</mark>。',
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
notes: [
|
|
123
|
+
'Names are plain text. Descriptions use ICU flat variables such as {power}, plural/select, and the listed semantic tags; no Markdown, HTML attributes, dotted expressions, or legacy color codes.',
|
|
124
|
+
'Only scalar public values from the actual rendering context are available. Definition previews have no live stack and preserve {stack}; battle descriptions use the real instance stack.',
|
|
125
|
+
'markName highlights ordinary marks in cyan. status highlights the adverse/exceptional display subclass in orange. guaranteedHit describes the skill property in lime. Do not modify gameplay tags merely for color.',
|
|
126
|
+
'<mark>namespace:id</mark> is the current mark reference. Plain highlighted names are not identities. Resolve real dependency-visible targets; never guess a matching object by name.',
|
|
127
|
+
'A general cross-kind reference protocol, exhaustive variable contract and shared reference-integrity validator are not implemented. Formatting checks do not prove all references are valid.',
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { readContentSources, assembleContent } from './lib/content.js';
|
|
5
|
+
import { buildPresentation } from './lib/presentation.js';
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
if (args.length && (args.length !== 1 || args[0] !== '--check'))
|
|
8
|
+
throw new Error('Usage: build-content.ts [--check]');
|
|
9
|
+
const root = resolve('.');
|
|
10
|
+
const sources = await readContentSources(root);
|
|
11
|
+
const content = assembleContent(sources);
|
|
12
|
+
const presentation = await buildPresentation(root, sources);
|
|
13
|
+
if (!args.includes('--check')) {
|
|
14
|
+
const directory = join(root, 'dist');
|
|
15
|
+
await mkdir(directory, { recursive: true });
|
|
16
|
+
const temporary = join(directory, `content.${process.pid}.tmp`);
|
|
17
|
+
try {
|
|
18
|
+
await writeFile(temporary, JSON.stringify(content, null, 2) + '\n', { flag: 'wx' });
|
|
19
|
+
await writeFile(join(directory, 'presentation.json.tmp'), JSON.stringify(presentation, null, 2) + '\n');
|
|
20
|
+
await rename(join(directory, 'presentation.json.tmp'), join(directory, 'presentation.json'));
|
|
21
|
+
await rename(temporary, join(directory, 'content.json'));
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
await rm(temporary, { force: true });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
console.log(`${args.includes('--check') ? 'Checked' : 'Built'} ${sources.length} data files: ${Object.entries(content.data)
|
|
28
|
+
.map(([kind, records]) => `${kind}=${records.length}`)
|
|
29
|
+
.join(', ')}`);
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { siblingModulePath } from './module-path.js';
|
|
5
|
+
import { errorMessage } from './types.js';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const [command, ...args] = process.argv.slice(2);
|
|
8
|
+
const help = `arcadia-content <command>
|
|
9
|
+
check Check TypeScript and JSON/YAML content
|
|
10
|
+
build Compile TypeScript and assemble content/media/locales metadata
|
|
11
|
+
rename Change package/project/namespace identities and local references
|
|
12
|
+
demo Run the battle configured in arcadia.config.mjs
|
|
13
|
+
preview Prepare a local candidate for the full battle client; stop with Ctrl+C
|
|
14
|
+
pack Check, build and create an npm content package
|
|
15
|
+
setup Install the pinned development SDK and tool
|
|
16
|
+
workspace <directory> <operation> [--execute] Structured author operations
|
|
17
|
+
`;
|
|
18
|
+
function run(file, arguments_) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const child = spawn(file, arguments_, { stdio: 'inherit', cwd: process.cwd() });
|
|
21
|
+
child.on('error', reject);
|
|
22
|
+
child.on('exit', (code, signal) => code === 0 ? resolve() : reject(new Error(`${file} failed (${signal ?? code})`)));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function data(check = false) {
|
|
26
|
+
await run(process.execPath, [siblingModulePath('build-content'), ...(check ? ['--check'] : [])]);
|
|
27
|
+
}
|
|
28
|
+
async function types(check = false) {
|
|
29
|
+
await run(process.execPath, [
|
|
30
|
+
require.resolve('typescript/bin/tsc'),
|
|
31
|
+
'-p',
|
|
32
|
+
'tsconfig.json',
|
|
33
|
+
...(check ? ['--noEmit'] : []),
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
async function build() {
|
|
37
|
+
await data(true);
|
|
38
|
+
await types();
|
|
39
|
+
await data();
|
|
40
|
+
const { buildEffects } = await import('./effect-build.js');
|
|
41
|
+
await buildEffects(process.cwd());
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
if (!command || command === '--help' || command === '-h')
|
|
45
|
+
console.log(help);
|
|
46
|
+
else if (command === 'workspace') {
|
|
47
|
+
const { workspaceCli } = await import('./workspace-cli.js');
|
|
48
|
+
await workspaceCli(args);
|
|
49
|
+
}
|
|
50
|
+
else if (command === 'setup') {
|
|
51
|
+
const { setup } = await import('./setup.js');
|
|
52
|
+
await setup(args);
|
|
53
|
+
}
|
|
54
|
+
else if (command === 'rename')
|
|
55
|
+
await run(process.execPath, [siblingModulePath('rename'), ...args]);
|
|
56
|
+
else {
|
|
57
|
+
if (!['check', 'build', 'demo', 'preview', 'pack'].includes(command) || args.length)
|
|
58
|
+
throw new Error(`Unknown command or option.\n${help}`);
|
|
59
|
+
if (command === 'check') {
|
|
60
|
+
await data(true);
|
|
61
|
+
await types(true);
|
|
62
|
+
}
|
|
63
|
+
else if (command === 'build')
|
|
64
|
+
await build();
|
|
65
|
+
else if (command === 'demo')
|
|
66
|
+
await import('./demo.js');
|
|
67
|
+
else if (command === 'preview')
|
|
68
|
+
await (await import('./preview.js')).previewCommand();
|
|
69
|
+
else {
|
|
70
|
+
await build();
|
|
71
|
+
const { packBuiltProject } = await import('./pack-project.js');
|
|
72
|
+
const packed = await packBuiltProject();
|
|
73
|
+
console.log(`Packed ${packed.filename}`);
|
|
74
|
+
console.log(`ARCADIA_RESULT=${JSON.stringify({ filename: packed.filename, integrity: packed.integrity, shasum: packed.shasum, files: packed.files.map((file) => file.path) })}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error(errorMessage(error));
|
|
80
|
+
process.exitCode = 1;
|
|
81
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AuthorWorkspace } from './workspace.js';
|
|
2
|
+
import { type UnknownRecord } from './types.js';
|
|
3
|
+
declare const kinds: readonly ['content', 'presentations', 'resources', 'assets', 'files', 'locales', 'diagnostics'];
|
|
4
|
+
declare const scopes: readonly ['project', 'dependencies', 'all'];
|
|
5
|
+
declare const details: readonly ['summary', 'full'];
|
|
6
|
+
type QueryKind = (typeof kinds)[number];
|
|
7
|
+
type QueryScope = (typeof scopes)[number];
|
|
8
|
+
type QueryDetail = (typeof details)[number];
|
|
9
|
+
export interface QueryOptions {
|
|
10
|
+
kind: QueryKind;
|
|
11
|
+
scope: QueryScope;
|
|
12
|
+
detail: QueryDetail;
|
|
13
|
+
search: string;
|
|
14
|
+
offset: number;
|
|
15
|
+
limit: number;
|
|
16
|
+
contentKind?: string;
|
|
17
|
+
id?: string;
|
|
18
|
+
locale?: string;
|
|
19
|
+
namespace?: string;
|
|
20
|
+
packageName?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Read-only discovery over disk data. Never loads effects or changes workbench selection/drafts. */
|
|
23
|
+
export declare function queryContent(workspace: AuthorWorkspace, input?: UnknownRecord): Promise<{
|
|
24
|
+
total: number;
|
|
25
|
+
offset: number;
|
|
26
|
+
nextOffset: number | null;
|
|
27
|
+
items: unknown[];
|
|
28
|
+
diagnostics: Record<string, unknown>[];
|
|
29
|
+
}>;
|
|
30
|
+
export {};
|