semantic-atlas 0.2.0 → 0.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/.agents/skills/semantic-atlas/SKILL.md +3 -0
- package/.agents/skills/semantic-atlas/references/product-feedback.md +34 -0
- package/.agents/skills/semantic-atlas-insights/SKILL.md +55 -0
- package/README.md +229 -88
- package/README.zh-CN.md +204 -85
- package/dist/cli/argument-parser.js +9 -1
- package/dist/cli/bin.js +17 -2
- package/dist/cli/cli-application.d.ts +1 -0
- package/dist/cli/cli-application.d.ts.map +1 -1
- package/dist/cli/cli-application.js +64 -12
- package/dist/cli/insights-cli.d.ts +6 -0
- package/dist/cli/insights-cli.d.ts.map +1 -0
- package/dist/cli/insights-cli.js +236 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +94 -2
- package/dist/cli/standalone-cli.d.ts.map +1 -1
- package/dist/cli/standalone-cli.js +44 -5
- package/dist/cli/types.d.ts +2 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/web-cli.d.ts +9 -0
- package/dist/cli/web-cli.d.ts.map +1 -0
- package/dist/cli/web-cli.js +134 -0
- package/dist/contracts/cli.d.ts +63 -0
- package/dist/contracts/cli.d.ts.map +1 -1
- package/dist/contracts/cli.js +7 -0
- package/dist/contracts/insights.d.ts +2 -0
- package/dist/contracts/insights.d.ts.map +1 -0
- package/dist/contracts/insights.js +1 -0
- package/dist/contracts/public-contracts.d.ts +1 -0
- package/dist/contracts/public-contracts.d.ts.map +1 -1
- package/dist/contracts/public-contracts.js +1 -0
- package/dist/graph/graph-store.d.ts +2 -2
- package/dist/graph/graph-store.d.ts.map +1 -1
- package/dist/graph/graph-store.js +2 -2
- package/dist/insights/contracts.d.ts +266 -0
- package/dist/insights/contracts.d.ts.map +1 -0
- package/dist/insights/contracts.js +124 -0
- package/dist/insights/insights-store.d.ts +73 -0
- package/dist/insights/insights-store.d.ts.map +1 -0
- package/dist/insights/insights-store.js +246 -0
- package/dist/repository/repository-inspector.d.ts +1 -0
- package/dist/repository/repository-inspector.d.ts.map +1 -1
- package/dist/repository/repository-inspector.js +13 -0
- package/dist/setup/package-upgrader.d.ts +54 -0
- package/dist/setup/package-upgrader.d.ts.map +1 -0
- package/dist/setup/package-upgrader.js +169 -0
- package/dist/setup/skill-installer.d.ts +3 -2
- package/dist/setup/skill-installer.d.ts.map +1 -1
- package/dist/setup/skill-installer.js +67 -36
- package/dist/storage/atlas-database.d.ts +8 -1
- package/dist/storage/atlas-database.d.ts.map +1 -1
- package/dist/storage/atlas-database.js +68 -11
- package/dist/web/application/atlas-read-service.d.ts +27 -0
- package/dist/web/application/atlas-read-service.d.ts.map +1 -0
- package/dist/web/application/atlas-read-service.js +216 -0
- package/dist/web/application/primary-repository-catalog.d.ts +15 -0
- package/dist/web/application/primary-repository-catalog.d.ts.map +1 -0
- package/dist/web/application/primary-repository-catalog.js +202 -0
- package/dist/web/application/types.d.ts +41 -0
- package/dist/web/application/types.d.ts.map +1 -0
- package/dist/web/application/types.js +1 -0
- package/dist/web/server/api-router.d.ts +4 -0
- package/dist/web/server/api-router.d.ts.map +1 -0
- package/dist/web/server/api-router.js +151 -0
- package/dist/web/server/local-web-server.d.ts +12 -0
- package/dist/web/server/local-web-server.d.ts.map +1 -0
- package/dist/web/server/local-web-server.js +100 -0
- package/dist/web-client/assets/index-DneaErDj.css +1 -0
- package/dist/web-client/assets/index-cze_4vtt.js +2 -0
- package/dist/web-client/assets/index-cze_4vtt.js.map +1 -0
- package/dist/web-client/index.html +61 -0
- package/dist/world/world-graph-query.d.ts +5 -1
- package/dist/world/world-graph-query.d.ts.map +1 -1
- package/dist/world/world-graph-query.js +4 -2
- package/dist/world/world-snapshot-store.d.ts +2 -1
- package/dist/world/world-snapshot-store.d.ts.map +1 -1
- package/dist/world/world-snapshot-store.js +2 -2
- package/docs/architecture/web-viewer.md +225 -0
- package/docs/contracts/cli-v1.md +40 -4
- package/docs/contracts/http-api-v1.md +155 -0
- package/docs/contracts/insights-v1.md +84 -0
- package/docs/index.md +7 -0
- package/docs/log.md +103 -0
- package/docs/product-contract.md +45 -10
- package/package.json +7 -4
- package/schemas/cli-envelope-v1.schema.json +85 -1
- package/schemas/insights-envelope-v1.schema.json +428 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import { createRequire } from "node:module";
|
|
54
|
+
import { readdir } from "node:fs/promises";
|
|
55
|
+
import { basename, join } from "node:path";
|
|
56
|
+
import { inspectGitRepository, readCurrentBranch, } from "../../repository/repository-inspector.js";
|
|
57
|
+
import { createRepositorySnapshot } from "../../snapshots/repository-snapshot.js";
|
|
58
|
+
import { CURRENT_ATLAS_SCHEMA_VERSION, resolveExistingAtlasHome, } from "../../storage/atlas-database.js";
|
|
59
|
+
const REPOSITORY_ID_PATTERN = /^[0-9a-f]{64}$/u;
|
|
60
|
+
const require = createRequire(import.meta.url);
|
|
61
|
+
export class PrimaryRepositoryCatalog {
|
|
62
|
+
async listProjects() {
|
|
63
|
+
return (await this.discoverProjects()).map(({ summary }) => summary);
|
|
64
|
+
}
|
|
65
|
+
async findProject(repositoryId) {
|
|
66
|
+
if (!REPOSITORY_ID_PATTERN.test(repositoryId)) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return (await this.discoverProjects(repositoryId))[0];
|
|
70
|
+
}
|
|
71
|
+
async discoverProjects(requestedRepositoryId) {
|
|
72
|
+
const atlasHome = resolveExistingAtlasHome();
|
|
73
|
+
if (atlasHome === null) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
const repositoriesDirectory = join(atlasHome, "repositories");
|
|
77
|
+
let entries;
|
|
78
|
+
try {
|
|
79
|
+
entries = await readdir(repositoriesDirectory, { withFileTypes: true });
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (error.code === "ENOENT") {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
const repositoryIds = entries
|
|
88
|
+
.filter((entry) => entry.isDirectory() && REPOSITORY_ID_PATTERN.test(entry.name))
|
|
89
|
+
.map((entry) => entry.name)
|
|
90
|
+
.filter((repositoryId) => (requestedRepositoryId === undefined || repositoryId === requestedRepositoryId))
|
|
91
|
+
.sort();
|
|
92
|
+
const projects = (await Promise.all(repositoryIds.map(async (repositoryId) => (this.inspectStoredRepository(repositoriesDirectory, repositoryId))))).filter((project) => project !== undefined);
|
|
93
|
+
return projects.sort((left, right) => (left.summary.name.localeCompare(right.summary.name)
|
|
94
|
+
|| left.summary.root.localeCompare(right.summary.root)));
|
|
95
|
+
}
|
|
96
|
+
async inspectStoredRepository(repositoriesDirectory, repositoryId) {
|
|
97
|
+
const databasePath = join(repositoriesDirectory, repositoryId, "atlas.db");
|
|
98
|
+
let storedState;
|
|
99
|
+
try {
|
|
100
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
101
|
+
try {
|
|
102
|
+
const { DatabaseSync } = require("node:sqlite");
|
|
103
|
+
const database = __addDisposableResource(env_1, new DatabaseSync(databasePath, { readOnly: true }), false);
|
|
104
|
+
const schema = database.prepare(`
|
|
105
|
+
SELECT version
|
|
106
|
+
FROM atlas_schema
|
|
107
|
+
WHERE singleton = 1
|
|
108
|
+
`).get();
|
|
109
|
+
if (schema?.version !== CURRENT_ATLAS_SCHEMA_VERSION) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
storedState = database.prepare(`
|
|
113
|
+
SELECT
|
|
114
|
+
repository.repository_id,
|
|
115
|
+
repository.common_git_directory,
|
|
116
|
+
worktree.git_directory,
|
|
117
|
+
worktree.worktree_root,
|
|
118
|
+
worktree.status,
|
|
119
|
+
worktree.current_snapshot_id,
|
|
120
|
+
snapshot.payload AS snapshot_payload
|
|
121
|
+
FROM atlas_repositories AS repository
|
|
122
|
+
JOIN atlas_worktree_states AS worktree
|
|
123
|
+
ON worktree.repository_id = repository.repository_id
|
|
124
|
+
AND worktree.git_directory = repository.common_git_directory
|
|
125
|
+
LEFT JOIN atlas_repository_snapshots AS snapshot
|
|
126
|
+
ON snapshot.repository_id = worktree.repository_id
|
|
127
|
+
AND snapshot.snapshot_id = worktree.current_snapshot_id
|
|
128
|
+
WHERE repository.repository_id = ?
|
|
129
|
+
`).get(repositoryId);
|
|
130
|
+
}
|
|
131
|
+
catch (e_1) {
|
|
132
|
+
env_1.error = e_1;
|
|
133
|
+
env_1.hasError = true;
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
__disposeResources(env_1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
if (storedState === undefined) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const repository = await inspectGitRepository(storedState.worktree_root);
|
|
147
|
+
if (repository.repositoryId !== storedState.repository_id
|
|
148
|
+
|| repository.gitDirectory !== repository.commonGitDirectory
|
|
149
|
+
|| repository.gitDirectory !== storedState.git_directory
|
|
150
|
+
|| repository.commonGitDirectory !== storedState.common_git_directory) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
const branch = await readCurrentBranch(repository);
|
|
154
|
+
if (!isPrimaryBranch(branch)) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
const currentSnapshot = await createRepositorySnapshot(repository);
|
|
158
|
+
const publishedSnapshot = parsePublishedSnapshot(storedState.snapshot_payload);
|
|
159
|
+
const freshness = projectFreshness(storedState, currentSnapshot, publishedSnapshot);
|
|
160
|
+
return {
|
|
161
|
+
repository,
|
|
162
|
+
currentSnapshot,
|
|
163
|
+
summary: {
|
|
164
|
+
id: repository.repositoryId,
|
|
165
|
+
name: basename(repository.worktreeRoot),
|
|
166
|
+
root: repository.worktreeRoot,
|
|
167
|
+
branch,
|
|
168
|
+
headCommit: currentSnapshot.headCommit,
|
|
169
|
+
snapshotId: storedState.current_snapshot_id,
|
|
170
|
+
freshness,
|
|
171
|
+
status: storedState.status,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function isPrimaryBranch(branch) {
|
|
181
|
+
return branch === "main" || branch === "master";
|
|
182
|
+
}
|
|
183
|
+
function parsePublishedSnapshot(payload) {
|
|
184
|
+
if (payload === null) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
return JSON.parse(payload);
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function projectFreshness(storedState, currentSnapshot, publishedSnapshot) {
|
|
195
|
+
if (storedState.current_snapshot_id === null) {
|
|
196
|
+
return "missing";
|
|
197
|
+
}
|
|
198
|
+
if (storedState.status !== "current" || publishedSnapshot === null) {
|
|
199
|
+
return "stale";
|
|
200
|
+
}
|
|
201
|
+
return publishedSnapshot.snapshotId === currentSnapshot.snapshotId ? "current" : "stale";
|
|
202
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { BusinessGraphView, BusinessMapView, GraphSearchResult, BusinessGraphNode } from "../../graph/types.js";
|
|
2
|
+
import type { RepositoryLanguageSupport } from "../../repository/repository-language-support.js";
|
|
3
|
+
import type { StructuralIndexState } from "../../structural-backend/types.js";
|
|
4
|
+
import type { WorldSnapshotStatus } from "../../world/types.js";
|
|
5
|
+
export type WebProjectBranch = "main" | "master";
|
|
6
|
+
export type WebProjectFreshness = "current" | "stale" | "missing";
|
|
7
|
+
export interface WebProjectSummary {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly root: string;
|
|
11
|
+
readonly branch: WebProjectBranch;
|
|
12
|
+
readonly headCommit: string;
|
|
13
|
+
readonly snapshotId: string | null;
|
|
14
|
+
readonly freshness: WebProjectFreshness;
|
|
15
|
+
readonly status: WorldSnapshotStatus;
|
|
16
|
+
}
|
|
17
|
+
export interface WebProjectStatus {
|
|
18
|
+
readonly project: WebProjectSummary;
|
|
19
|
+
readonly currentRevision: {
|
|
20
|
+
readonly headCommit: string;
|
|
21
|
+
readonly changes: {
|
|
22
|
+
readonly staged: number;
|
|
23
|
+
readonly unstaged: number;
|
|
24
|
+
readonly untracked: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
readonly languages: readonly RepositoryLanguageSupport[];
|
|
28
|
+
readonly backend: Pick<StructuralIndexState, "backendVersion" | "completeness" | "extractionVersion" | "indexedAt">;
|
|
29
|
+
readonly warnings: readonly {
|
|
30
|
+
readonly code: string;
|
|
31
|
+
readonly message: string;
|
|
32
|
+
}[];
|
|
33
|
+
}
|
|
34
|
+
export interface WebBusinessSearch {
|
|
35
|
+
readonly query: string;
|
|
36
|
+
readonly limit: number;
|
|
37
|
+
readonly results: readonly GraphSearchResult<BusinessGraphNode>[];
|
|
38
|
+
}
|
|
39
|
+
export type WebBusinessMap = BusinessMapView;
|
|
40
|
+
export type WebBusinessNode = BusinessGraphView;
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/web/application/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AACjG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,CAAC;AACjD,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;CACtC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE;QACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,OAAO,EAAE;YAChB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;YACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;YAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;SAC5B,CAAC;KACH,CAAC;IACF,QAAQ,CAAC,SAAS,EAAE,SAAS,yBAAyB,EAAE,CAAC;IACzD,QAAQ,CAAC,OAAO,EAAE,IAAI,CACpB,oBAAoB,EACpB,gBAAgB,GAAG,cAAc,GAAG,mBAAmB,GAAG,WAAW,CACtE,CAAC;IACF,QAAQ,CAAC,QAAQ,EAAE,SAAS;QAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KAC1B,EAAE,CAAC;CACL;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,iBAAiB,CAAC,iBAAiB,CAAC,EAAE,CAAC;CACnE;AAED,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC;AAC7C,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { type AtlasReadOperations } from "../application/atlas-read-service.js";
|
|
3
|
+
export declare function createApiRequestHandler(service: AtlasReadOperations): (request: IncomingMessage, response: ServerResponse) => void;
|
|
4
|
+
//# sourceMappingURL=api-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-router.d.ts","sourceRoot":"","sources":["../../../src/web/server/api-router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,sCAAsC,CAAC;AAgB9C,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,mBAAmB,GAC3B,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,KAAK,IAAI,CAI9D"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { businessKeySchema } from "../../contracts/graph.js";
|
|
2
|
+
import { AtlasReadError, } from "../application/atlas-read-service.js";
|
|
3
|
+
const PROJECT_ID_PATTERN = /^[0-9a-f]{64}$/u;
|
|
4
|
+
const PROJECT_ROUTE_PATTERN = /^\/api\/v1\/projects\/([^/]+)\/(status|map|search|node)$/u;
|
|
5
|
+
class HttpApiError extends Error {
|
|
6
|
+
statusCode;
|
|
7
|
+
code;
|
|
8
|
+
constructor(statusCode, code, message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.statusCode = statusCode;
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.name = "HttpApiError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function createApiRequestHandler(service) {
|
|
16
|
+
return (request, response) => {
|
|
17
|
+
void routeApiRequest(service, request, response);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async function routeApiRequest(service, request, response) {
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
23
|
+
if (request.method !== "GET") {
|
|
24
|
+
response.setHeader("Allow", "GET");
|
|
25
|
+
throw new HttpApiError(405, "METHOD_NOT_ALLOWED", "The resource supports GET only.");
|
|
26
|
+
}
|
|
27
|
+
if (url.pathname === "/api/v1/projects") {
|
|
28
|
+
requireAllowedQuery(url, []);
|
|
29
|
+
writeJson(response, 200, { data: { projects: await service.listProjects() } });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const route = PROJECT_ROUTE_PATTERN.exec(url.pathname);
|
|
33
|
+
if (route === null) {
|
|
34
|
+
throw invalidRequest("The requested API route is invalid.");
|
|
35
|
+
}
|
|
36
|
+
const repositoryId = route[1];
|
|
37
|
+
const operation = route[2];
|
|
38
|
+
if (!PROJECT_ID_PATTERN.test(repositoryId)) {
|
|
39
|
+
throw invalidRequest("Expected an opaque Semantic Atlas project ID.");
|
|
40
|
+
}
|
|
41
|
+
if (operation === "status") {
|
|
42
|
+
requireAllowedQuery(url, []);
|
|
43
|
+
writeJson(response, 200, { data: await service.getStatus(repositoryId) });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (operation === "map") {
|
|
47
|
+
requireAllowedQuery(url, ["focus"]);
|
|
48
|
+
const focus = optionalBusinessKey(url, "focus");
|
|
49
|
+
writeJson(response, 200, {
|
|
50
|
+
data: await service.getMap(repositoryId, focus),
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (operation === "search") {
|
|
55
|
+
requireAllowedQuery(url, ["q", "limit"]);
|
|
56
|
+
const query = requiredQuery(url, "q").trim();
|
|
57
|
+
if (query.length === 0) {
|
|
58
|
+
throw invalidRequest("Search query q must not be empty.");
|
|
59
|
+
}
|
|
60
|
+
const limit = positiveIntegerQuery(url, "limit", 20, 100);
|
|
61
|
+
writeJson(response, 200, {
|
|
62
|
+
data: await service.searchBusiness(repositoryId, query, limit),
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
requireAllowedQuery(url, ["key"]);
|
|
67
|
+
const businessKey = requiredBusinessKey(url, "key");
|
|
68
|
+
writeJson(response, 200, {
|
|
69
|
+
data: await service.getBusinessNode(repositoryId, businessKey),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
writeApiError(response, error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function requiredQuery(url, name) {
|
|
77
|
+
const values = url.searchParams.getAll(name);
|
|
78
|
+
if (values.length !== 1 || values[0] === undefined) {
|
|
79
|
+
throw invalidRequest(`Query parameter ${name} is required exactly once.`);
|
|
80
|
+
}
|
|
81
|
+
return values[0];
|
|
82
|
+
}
|
|
83
|
+
function optionalBusinessKey(url, name) {
|
|
84
|
+
const values = url.searchParams.getAll(name);
|
|
85
|
+
if (values.length === 0) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
if (values.length !== 1) {
|
|
89
|
+
throw invalidRequest(`Query parameter ${name} may be provided once.`);
|
|
90
|
+
}
|
|
91
|
+
return parseBusinessKey(values[0], name);
|
|
92
|
+
}
|
|
93
|
+
function requiredBusinessKey(url, name) {
|
|
94
|
+
return parseBusinessKey(requiredQuery(url, name), name);
|
|
95
|
+
}
|
|
96
|
+
function parseBusinessKey(value, name) {
|
|
97
|
+
const parsed = businessKeySchema.safeParse(value);
|
|
98
|
+
if (!parsed.success) {
|
|
99
|
+
throw invalidRequest(`Query parameter ${name} must be a business key.`);
|
|
100
|
+
}
|
|
101
|
+
return parsed.data;
|
|
102
|
+
}
|
|
103
|
+
function positiveIntegerQuery(url, name, defaultValue, maximum) {
|
|
104
|
+
const values = url.searchParams.getAll(name);
|
|
105
|
+
if (values.length === 0) {
|
|
106
|
+
return defaultValue;
|
|
107
|
+
}
|
|
108
|
+
if (values.length !== 1) {
|
|
109
|
+
throw invalidRequest(`Query parameter ${name} may be provided once.`);
|
|
110
|
+
}
|
|
111
|
+
const value = Number(values[0]);
|
|
112
|
+
if (!Number.isInteger(value) || value < 1 || value > maximum) {
|
|
113
|
+
throw invalidRequest(`Query parameter ${name} must be an integer from 1 through ${maximum}.`);
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
function requireAllowedQuery(url, allowed) {
|
|
118
|
+
const allowedNames = new Set(allowed);
|
|
119
|
+
for (const name of url.searchParams.keys()) {
|
|
120
|
+
if (!allowedNames.has(name)) {
|
|
121
|
+
throw invalidRequest(`Query parameter ${name} is not supported by this route.`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function invalidRequest(message) {
|
|
126
|
+
return new HttpApiError(400, "INVALID_REQUEST", message);
|
|
127
|
+
}
|
|
128
|
+
function writeApiError(response, error) {
|
|
129
|
+
if (response.headersSent) {
|
|
130
|
+
response.end();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (error instanceof AtlasReadError || error instanceof HttpApiError) {
|
|
134
|
+
writeJson(response, error.statusCode, {
|
|
135
|
+
error: { code: error.code, message: error.message },
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
writeJson(response, 500, {
|
|
140
|
+
error: {
|
|
141
|
+
code: "INTERNAL_ERROR",
|
|
142
|
+
message: "Semantic Atlas could not complete the local request.",
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function writeJson(response, statusCode, contents) {
|
|
147
|
+
response.statusCode = statusCode;
|
|
148
|
+
response.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
149
|
+
response.setHeader("Cache-Control", "no-store");
|
|
150
|
+
response.end(JSON.stringify({ schemaVersion: 1, ...contents }));
|
|
151
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AtlasReadOperations } from "../application/atlas-read-service.js";
|
|
2
|
+
export interface LocalWebServerOptions {
|
|
3
|
+
readonly readService: AtlasReadOperations;
|
|
4
|
+
readonly port: number;
|
|
5
|
+
readonly assetsDirectory?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface RunningLocalWebServer {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function startLocalWebServer(options: LocalWebServerOptions): Promise<RunningLocalWebServer>;
|
|
12
|
+
//# sourceMappingURL=local-web-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-web-server.d.ts","sourceRoot":"","sources":["../../../src/web/server/local-web-server.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAGhF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,qBAAqB,CAAC,CA0BhC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createReadStream } from "node:fs";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { extname, join, normalize, relative } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { createApiRequestHandler } from "./api-router.js";
|
|
7
|
+
export async function startLocalWebServer(options) {
|
|
8
|
+
const apiHandler = createApiRequestHandler(options.readService);
|
|
9
|
+
const assetsDirectory = options.assetsDirectory ?? bundledAssetsDirectory();
|
|
10
|
+
const server = createServer((request, response) => {
|
|
11
|
+
if ((request.url ?? "").startsWith("/api/")) {
|
|
12
|
+
apiHandler(request, response);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
void serveStaticAsset(assetsDirectory, request, response);
|
|
16
|
+
});
|
|
17
|
+
await new Promise((resolve, reject) => {
|
|
18
|
+
server.once("error", reject);
|
|
19
|
+
server.listen(options.port, "127.0.0.1", resolve);
|
|
20
|
+
});
|
|
21
|
+
const address = server.address();
|
|
22
|
+
if (address === null || typeof address === "string") {
|
|
23
|
+
server.close();
|
|
24
|
+
throw new Error("Semantic Atlas Web did not receive a TCP address");
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
url: `http://127.0.0.1:${address.port}`,
|
|
28
|
+
close: () => new Promise((resolve, reject) => {
|
|
29
|
+
server.close((error) => error === undefined ? resolve() : reject(error));
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function serveStaticAsset(assetsDirectory, request, response) {
|
|
34
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
35
|
+
response.statusCode = 405;
|
|
36
|
+
response.setHeader("Allow", "GET, HEAD");
|
|
37
|
+
response.end();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let requestedPath;
|
|
41
|
+
try {
|
|
42
|
+
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
43
|
+
requestedPath = url.pathname === "/" ? "index.html" : decodeURIComponent(url.pathname.slice(1));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
response.statusCode = 400;
|
|
47
|
+
response.end("Invalid request");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const normalizedPath = normalize(requestedPath);
|
|
51
|
+
const assetPath = join(assetsDirectory, normalizedPath);
|
|
52
|
+
const pathFromAssets = relative(assetsDirectory, assetPath);
|
|
53
|
+
if (pathFromAssets.startsWith("..") || pathFromAssets === "" || pathFromAssets.includes("\0")) {
|
|
54
|
+
respondNotFound(response);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const metadata = await stat(assetPath);
|
|
59
|
+
if (!metadata.isFile()) {
|
|
60
|
+
respondNotFound(response);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
response.statusCode = 200;
|
|
64
|
+
response.setHeader("Content-Type", contentType(assetPath));
|
|
65
|
+
response.setHeader("Cache-Control", requestedPath === "index.html"
|
|
66
|
+
? "no-cache"
|
|
67
|
+
: "public, max-age=31536000, immutable");
|
|
68
|
+
if (request.method === "HEAD") {
|
|
69
|
+
response.end();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
createReadStream(assetPath).pipe(response);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error.code === "ENOENT") {
|
|
76
|
+
respondNotFound(response);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
response.statusCode = 500;
|
|
80
|
+
response.end("Semantic Atlas Web could not load this asset.");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function bundledAssetsDirectory() {
|
|
84
|
+
return fileURLToPath(new URL("../../web-client/", import.meta.url));
|
|
85
|
+
}
|
|
86
|
+
function respondNotFound(response) {
|
|
87
|
+
response.statusCode = 404;
|
|
88
|
+
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
89
|
+
response.end("Not found");
|
|
90
|
+
}
|
|
91
|
+
function contentType(path) {
|
|
92
|
+
switch (extname(path)) {
|
|
93
|
+
case ".html": return "text/html; charset=utf-8";
|
|
94
|
+
case ".css": return "text/css; charset=utf-8";
|
|
95
|
+
case ".js": return "text/javascript; charset=utf-8";
|
|
96
|
+
case ".svg": return "image/svg+xml";
|
|
97
|
+
case ".png": return "image/png";
|
|
98
|
+
default: return "application/octet-stream";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{--ink: #17231d;--ink-muted: #526158;--paper: #f3f0e8;--panel: #fffdf8;--rail: #e7e9df;--line: #d7d9cf;--line-strong: #bfc6ba;--accent: #c75d35;--accent-soft: #f3ded3;--sage: #647d6c;--sage-soft: #dfe8df;--warning: #a67420;--danger: #a64f42;--shadow: 0 18px 45px rgba(31, 45, 37, .08);font-family:Avenir Next,Gill Sans,Trebuchet MS,sans-serif;color:var(--ink);background:var(--paper);font-synthesis:none;text-rendering:optimizeLegibility}*{box-sizing:border-box}html,body{min-width:1120px;min-height:100%;margin:0}body{background:radial-gradient(circle at 72% 8%,rgba(199,93,53,.08),transparent 28rem),linear-gradient(135deg,#f5f2eb,#efeee7)}button,input{font:inherit}button{color:inherit}code,kbd{font-family:SFMono-Regular,Cascadia Code,monospace}.app-shell{display:grid;grid-template-columns:208px minmax(850px,1fr);min-height:100vh}.project-rail{position:sticky;top:0;display:flex;flex-direction:column;height:100vh;padding:22px 14px;overflow:hidden;background:var(--rail);border-right:1px solid var(--line-strong)}.rail-header{padding:0 9px 16px;border-bottom:1px solid var(--line-strong)}.rail-header h1{margin:0;font-family:Iowan Old Style,Baskerville,Georgia,serif;font-size:22px;font-weight:600;letter-spacing:-.02em}.project-list{flex:1;min-height:0;padding-top:10px;overflow-y:auto}.project-button{display:block;width:100%;padding:11px 10px;text-align:left;background:transparent;border:0;border-radius:10px;cursor:pointer;transition:background .15s ease,transform .15s ease}.project-button:hover{background:#ffffff8c}.project-button[aria-current=true]{background:var(--panel);box-shadow:0 5px 14px #23302812}.project-name{display:block;overflow:hidden;font-size:14px;font-weight:650;text-overflow:ellipsis;white-space:nowrap}.rail-empty{padding:18px 10px;color:var(--ink-muted);font-size:13px;line-height:1.55}.workspace{min-width:0}.workspace-header{position:sticky;z-index:20;top:0;display:flex;align-items:center;justify-content:space-between;min-height:58px;padding:9px 24px;background:#f3f0e8e0;border-bottom:1px solid rgba(191,198,186,.75);-webkit-backdrop-filter:blur(16px);backdrop-filter:blur(16px)}.breadcrumbs{display:flex;align-items:center;min-width:0;color:var(--ink-muted);font-size:13px}.breadcrumb-button{max-width:180px;padding:5px 7px;overflow:hidden;color:inherit;text-overflow:ellipsis;white-space:nowrap;background:transparent;border:0;border-radius:5px;cursor:pointer}.breadcrumb-button:hover{color:var(--ink);background:#ffffffb3}.breadcrumb-separator{color:#98a197}.search{position:relative;display:flex;align-items:center;width:280px;height:38px;padding:0 11px;background:var(--panel);border:1px solid var(--line);border-radius:9px;box-shadow:0 5px 16px #2330280a}.search:focus-within{border-color:var(--sage);box-shadow:0 0 0 3px #647d6c1f}.search>svg{flex:0 0 auto;width:17px;fill:none;stroke:var(--ink-muted);stroke-width:1.7}.search input{min-width:0;flex:1;height:100%;padding:0 9px;color:var(--ink);background:transparent;border:0;outline:0}.search input::placeholder{color:#879087}.search input:disabled{cursor:not-allowed}.search-results{position:absolute;top:48px;right:0;width:390px;max-height:430px;padding:7px;overflow-y:auto;background:var(--panel);border:1px solid var(--line);border-radius:11px;box-shadow:var(--shadow)}.search-result{display:block;width:100%;padding:11px 12px;text-align:left;background:transparent;border:0;border-radius:7px;cursor:pointer}.search-result:hover{background:#f1f2ec}.search-result strong{display:block;font-size:13px}.search-result span{display:block;margin-top:3px;overflow:hidden;color:var(--ink-muted);font-size:11px;text-overflow:ellipsis;white-space:nowrap}.search-message{padding:17px 13px;color:var(--ink-muted);font-size:12px}.content-layout{display:grid;grid-template-columns:minmax(660px,1fr) 310px;gap:14px;padding:16px 24px 24px}body.is-immersive-map,body.is-immersive-map .app-shell,body.is-immersive-map .workspace{height:100vh;overflow:hidden}body.is-immersive-map .project-rail,body.is-immersive-map .workspace-header,body.is-immersive-map .detail-panel{display:none}body.is-immersive-map .app-shell,body.is-immersive-map .content-layout{display:block}body.is-immersive-map .content-layout{height:100vh;padding:0}body.is-immersive-map .map-surface{height:100vh;min-height:0;border:0;border-radius:0;box-shadow:none}body.is-immersive-map .map-viewport{height:100vh}.map-surface,.detail-panel{min-height:calc(100vh - 98px);background:#fffdf8e0;border:1px solid var(--line);border-radius:14px;box-shadow:var(--shadow)}.map-surface{position:relative;min-width:0;overflow:hidden}.map-viewport{position:relative;height:clamp(560px,calc(100vh - 98px),900px);overflow:hidden;background:radial-gradient(circle at 50% 48%,rgba(199,93,53,.08),transparent 24rem),radial-gradient(circle at 20% 82%,rgba(100,125,108,.08),transparent 22rem),linear-gradient(rgba(93,110,98,.07) 1px,transparent 1px),linear-gradient(90deg,rgba(93,110,98,.07) 1px,transparent 1px),#fbfaf4;background-size:auto,auto,42px 42px,42px 42px,auto;cursor:grab;touch-action:none}.map-viewport.is-panning{cursor:grabbing}.map-world{position:absolute;top:0;left:0;transform-origin:0 0;will-change:transform}.map-world.is-animating{transition:transform .52s cubic-bezier(.2,.78,.25,1)}.map-connections{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none}.map-connections path{fill:none;vector-effect:non-scaling-stroke}.map-connections path[hidden]{display:none}.map-hierarchy-edge{stroke:#b6c0b4;stroke-width:1.4}.map-business-edge{stroke:var(--accent);stroke-width:1.5;stroke-dasharray:6 6;opacity:.78}.map-hub{position:absolute;display:grid;width:150px;height:150px;padding:24px 18px;place-content:center;text-align:center;background:var(--ink);border:8px solid rgba(255,253,248,.94);border-radius:50%;box-shadow:0 18px 36px #17231d33;transform:translate(-50%,-50%)}.map-hub-label{color:#fffdf8;font-size:14px;font-weight:750;line-height:1.15}.map-node{position:absolute;z-index:2;width:154px;transform:translate(-50%,-50%);transition:opacity .18s ease,transform .18s ease}.map-node[hidden]{display:none}.map-node-core{display:grid;width:134px;height:134px;margin:auto;padding:17px 12px 15px;place-content:center;text-align:center;background:#fffdf8f5;border:2px solid var(--node-color, var(--sage));border-radius:50%;box-shadow:0 10px 26px #1f2d2521;cursor:pointer;transition:transform .16s ease,box-shadow .16s ease,background .16s ease}.map-node-core:hover,.map-node.is-selected .map-node-core{background:#fff;box-shadow:0 16px 32px #1f2d2533;transform:scale(1.06)}.map-node.is-selected .map-node-core{outline:5px solid color-mix(in srgb,var(--node-color, var(--accent)) 18%,transparent)}.map-node[data-role=context] .map-node-core{border-style:dashed;opacity:.86}.map-node[data-validity=stale] .map-node-core{border-color:var(--warning)}.map-node[data-kind=capability]{--node-color: #c75d35}.map-node[data-kind=operation]{--node-color: #647d6c}.map-node[data-kind=interface]{--node-color: #456a82}.map-node[data-kind=scenario]{--node-color: #a67420}.map-node[data-kind=invariant]{--node-color: #a64f42}.map-node[data-kind=data]{--node-color: #4a817e}.map-node-count{display:block;margin-top:7px;color:var(--ink-muted);font-size:8px;font-weight:750;letter-spacing:.1em;text-transform:uppercase}.map-node-label{display:-webkit-box;max-height:42px;margin:0;overflow:hidden;font-size:12px;font-weight:750;line-height:1.15;-webkit-box-orient:vertical;-webkit-line-clamp:3}.map-viewport[data-zoom=overview] .map-node-count{display:none}.map-viewport[data-zoom=overview] .map-node-core{width:112px;height:112px}.map-controls{position:absolute;z-index:5;top:14px;right:14px;display:flex;overflow:hidden;background:#fffdf8ed;border:1px solid var(--line);border-radius:9px;box-shadow:0 8px 22px #1f2d251a}.map-control{min-width:39px;height:36px;padding:0 11px;background:transparent;border:0;border-right:1px solid var(--line);cursor:pointer;font-size:12px;font-weight:700}.map-control[data-action=immersive]{min-width:58px}.map-control:last-child{border-right:0}.map-control:hover{color:var(--accent);background:var(--accent-soft)}.detail-panel{align-self:start;min-width:0;max-height:calc(100vh - 98px);padding:22px;overflow-y:auto}.detail-placeholder,.welcome-state,.empty-state,.error-state{display:flex;flex-direction:column;justify-content:center;min-height:330px;padding:34px}.detail-placeholder{min-height:300px;padding:8px}.detail-placeholder h3,.welcome-state h3,.empty-state h3,.error-state h3{margin:13px 0 8px;font-family:Iowan Old Style,Baskerville,Georgia,serif;font-size:23px;font-weight:500}.detail-placeholder p:last-child,.welcome-state p:last-child,.empty-state p:last-child,.error-state p:last-child{max-width:430px;margin:0;color:var(--ink-muted);font-size:13px;line-height:1.6}.detail-heading{padding-bottom:20px;border-bottom:1px solid var(--line)}.detail-heading h3{margin:12px 0 9px;font-family:Iowan Old Style,Baskerville,Georgia,serif;font-size:25px;font-weight:500;line-height:1.12}.detail-heading>p{margin:0;color:var(--ink-muted);font-size:13px;line-height:1.6;overflow-wrap:anywhere}.detail-kind{margin:0 0 10px;color:var(--ink-muted);font-size:12px}.detail-section{padding:20px 0;border-bottom:1px solid var(--line)}.detail-section:last-child{border-bottom:0}.detail-section h4{margin:0 0 11px;color:var(--ink-muted);font-size:12px}.relation-item{position:relative;padding:7px 0 7px 13px;color:var(--ink);font-size:13px;line-height:1.45;overflow-wrap:anywhere}.relation-item:before{position:absolute;top:15px;left:1px;width:4px;height:4px;content:"";background:var(--accent);border-radius:50%}.loading-state{display:grid;min-height:420px;place-items:center;color:var(--ink-muted);font-size:12px}.loading-state:before{width:23px;height:23px;margin-right:9px;content:"";border:2px solid var(--line);border-top-color:var(--accent);border-radius:50%;animation:spin .7s linear infinite}.notice{position:fixed;z-index:50;right:28px;bottom:25px;max-width:430px;padding:12px 15px;color:#fff;background:var(--ink);border-radius:8px;box-shadow:var(--shadow);font-size:12px}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}@keyframes region-in{0%{opacity:0;transform:translateY(7px)}to{opacity:1;transform:translateY(0)}}@keyframes spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){*,*:before,*:after{scroll-behavior:auto!important;animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))o(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const a of s.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&o(a)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function o(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();function ne(t,e,n,o){const i=t.get(n);if(i!==void 0)return Promise.resolve(i);const s=e.get(n);if(s!==void 0)return s;const a=o().then(d=>(t.set(n,d),d)).finally(()=>e.delete(n));return e.set(n,a),a}const p={width:3e3,height:2200};function oe(t,e=[]){const n={x:p.width/2,y:p.height/2},o=new Map(e.map(s=>[s.key,s])),i=t.filter(({key:s})=>!o.has(s));for(;i.length>0;){const s=i.filter(({parentKey:d})=>d===void 0||o.has(d)),a=s.length>0?s:i;for(const[d,l]of re(a))ie(l,d,o,n);for(const{key:d}of a)ce(i,d)}return{center:n,nodes:t.map(({key:s})=>o.get(s))}}function ie(t,e,n,o){const i=e===void 0?void 0:n.get(e),a=[...[...n.values()].filter(c=>c.parentKey===e).sort(de),...t].sort((c,u)=>c.key.localeCompare(u.key)),d=i===void 0,l=i??{x:o.x,y:o.y,depth:0},h=d?-Math.PI/2:Math.atan2(l.y-o.y,l.x-o.x);for(const c of t){const u=a.findIndex(({key:te})=>te===c.key),y=se(h,u,a.length,d),b=l.depth+1,K=ae(b,c.role,d);n.set(c.key,{key:c.key,x:Math.round(l.x+Math.cos(y)*K.x),y:Math.round(l.y+Math.sin(y)*K.y),ring:b+(c.role==="context"?1:0),depth:b,role:c.role,parentKey:e})}}function se(t,e,n,o){if(n<=1)return t;if(o)return t+Math.PI*2*e/n;const i=Math.min(1.7,Math.max(.85,(n-1)*.46));return t-i/2+i*e/(n-1)}function ae(t,e,n){const o=n?430:320+Math.min(t,4)*28,i=e==="context"?155:0;return{x:o+i,y:Math.round((o+i)*.72)}}function re(t){const e=new Map;for(const n of t){const o=e.get(n.parentKey)??[];o.push(n),e.set(n.parentKey,o)}return e}function ce(t,e){const n=t.findIndex(o=>o.key===e);n>=0&&t.splice(n,1)}function de(t,e){return t.key.localeCompare(e.key)}const k={minScale:.2,maxScale:4.8};function le(t,e,n){const o=z(t.scale*e,k.minScale,k.maxScale),i=(n.x-t.x)/t.scale,s=(n.y-t.y)/t.scale;return{scale:o,x:n.x-i*o,y:n.y-s*o}}function pe(t,e){return{...t,x:t.x+e.x,y:t.y+e.y}}function ue(t,e,n=80){const o=Math.max(1,e.right-e.left),i=Math.max(1,e.bottom-e.top),s=z(Math.min((t.width-n*2)/o,(t.height-n*2)/i),k.minScale,k.maxScale);return{scale:s,x:(t.width-o*s)/2-e.left*s,y:(t.height-i*s)/2-e.top*s}}function P(t){return t<=1?k.minScale:z(.55*1.6**(t-1),k.minScale,k.maxScale)}function T(t,e){return t<=1||e>=P(t)}function fe(t,e,n){return T(t,n)&&T(e,n)}function z(t,e,n){return Math.min(n,Math.max(e,t))}class X extends Error{constructor(e,n){super(n),this.code=e,this.name="ApiRequestError"}code}const q=M("project-list"),S=M("breadcrumbs"),C=M("map-surface"),L=M("detail-panel"),U=M("search-form"),m=M("business-search"),g=M("search-results"),B=M("notice");let w=[],f,x,E,v,I=0,V;he();async function he(){me();try{w=(await N("/api/v1/projects")).projects,Q();const t=new URLSearchParams(location.search).get("project"),e=w.find(({id:n})=>n===t)??w.find(({freshness:n})=>n==="current")??w[0];e!==void 0?await _(e.id):je()}catch(t){Ne("项目列表暂时无法显示",R(t))}}function me(){U.addEventListener("submit",e=>e.preventDefault());let t;m.addEventListener("input",()=>{window.clearTimeout(t);const e=m.value.trim();if(e.length===0){A();return}t=window.setTimeout(()=>{Ie(e)},170)}),m.addEventListener("keydown",e=>{e.key==="Escape"&&(A(),m.blur())}),document.addEventListener("keydown",e=>{const n=e.target;if(e.key==="Escape"&&document.body.classList.contains("is-immersive-map")){e.preventDefault(),W(!1);return}e.key==="/"&&n?.tagName!=="INPUT"&&f!==void 0&&(e.preventDefault(),m.focus())}),document.addEventListener("click",e=>{U.contains(e.target)||A()}),window.addEventListener("resize",()=>x?.fit())}async function _(t){const e=w.find(({id:n})=>n===t);if(e!==void 0){f=e,x=void 0,E=void 0,v={projectId:e.id,maps:new Map,mapRequests:new Map,nodes:new Map,connections:new Map,positions:new Map,camera:void 0},m.disabled=!1,m.value="",A(),Q(),J(C,"正在加载业务地图"),G(),qe(e.id);try{const n=await O();F(n)}catch(n){Z(n)}}}async function O(t){const e=f,n=v;if(e===void 0||n===void 0)throw new Error("请先选择一个项目。");const o=t??"";return ne(n.maps,n.mapRequests,o,async()=>{const i=t===void 0?"":`?focus=${encodeURIComponent(t)}`,s=await N(`/api/v1/projects/${e.id}/map${i}`);return H(n,s),s})}function H(t,e){let n;for(const s of e.breadcrumbs)D(t,s,n===void 0?"root":"child",n,0,!0),n=s.key;const o=e.breadcrumbs.at(-1);e.focus!==null&&o?.key!==e.focus.key&&D(t,e.focus,"child",n,0,!0);for(const s of e.regions)D(t,s.node,s.role,e.focus?.key,s.childCount,s.expandable);for(const s of e.connections)t.connections.set(`${s.from.key}\0${s.to.key}`,s);const i=oe([...t.nodes.values()].map(({node:s,role:a,parentKey:d})=>({key:s.key,role:a,parentKey:d})),[...t.positions.values()]);t.positions=new Map(i.nodes.map(s=>[s.key,s]))}function D(t,e,n,o,i,s){const a=t.nodes.get(e.key),d=a!==void 0&&n==="context";t.nodes.set(e.key,{node:e,role:d?a.role:n,parentKey:d?a.parentKey:o,childCount:Math.max(a?.childCount??0,i),expandable:(a?.expandable??!1)||s})}function Q(){if(q.replaceChildren(),w.length===0){const t=r("p","rail-empty");t.textContent="暂无可查看的项目。",q.append(t);return}for(const t of w){const e=r("button","project-button");e.type="button",e.setAttribute("aria-current",String(t.id===f?.id)),e.setAttribute("aria-label",`${t.name},${t.branch} 分支`),e.addEventListener("click",()=>{_(t.id)});const n=r("span","project-name");n.textContent=t.name,e.append(n),q.append(e)}}function F(t){if(v!==void 0&&H(v,t),$e(t),C.replaceChildren(),t.regions.length===0&&t.focus===null){const e=r("div","empty-state"),n=r("h3");n.textContent=t.focus===null?"还没有可展示的业务知识":"这里没有更多业务区域";const o=r("p");o.textContent=t.focus===null?"业务知识会在日常研发过程中逐步整理。":"这个区域仍可能包含简介和相关业务。",e.append(n,o),C.append(e);return}v!==void 0&&C.append(ye(v))}function ye(t){const e=r("section","map-viewport");e.tabIndex=0,e.setAttribute("aria-label","交互式业务地图。拖拽移动,滚轮缩放。");const n=r("div","map-world");n.style.width=`${p.width}px`,n.style.height=`${p.height}px`;const o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.classList.add("map-connections"),o.setAttribute("viewBox",`0 0 ${p.width} ${p.height}`),o.setAttribute("aria-hidden","true"),be(o,t),n.append(o,ge());for(const s of t.nodes.values()){const a=t.positions.get(s.node.key);a!==void 0&&n.append(xe(s,a))}e.append(n,ve());const i=t.camera===void 0;return x=Ce(e,n,t),requestAnimationFrame(()=>{i?x?.fit():x?.refresh()}),e}function ge(){const t=r("div","map-hub");t.style.left=`${p.width/2}px`,t.style.top=`${p.height/2}px`;const e=r("span","map-hub-label");return e.textContent=f?.name??"项目",t.append(e),t}function xe(t,e){const n=r("article","map-node");n.dataset.key=t.node.key,n.dataset.depth=String(e.depth),n.dataset.role=t.role,n.dataset.kind=t.node.kind.toLowerCase().replaceAll(" ","-"),n.dataset.validity=t.node.validity,n.classList.toggle("is-selected",t.node.key===E),n.style.left=`${e.x}px`,n.style.top=`${e.y}px`;const o=r("button","map-node-core");o.type="button",o.title=t.expandable?"进入这个业务区域":"查看这个业务区域",o.setAttribute("aria-label",t.node.label),o.addEventListener("click",()=>{j(t.node.key)});const i=r("span","map-node-label");if(i.textContent=t.node.label,o.append(i),t.childCount>0){const s=r("span","map-node-count");s.textContent=`${t.childCount} 项`,o.append(s)}return n.append(o),n}function be(t,e){const n={x:p.width/2,y:p.height/2};for(const o of e.nodes.values()){if(o.role==="context")continue;const i=e.positions.get(o.node.key);if(i===void 0)continue;const s=o.parentKey===void 0?void 0:e.positions.get(o.parentKey),a=s??n;a!==void 0&&Y(t,a,i,"map-hierarchy-edge",s?.depth??1,i.depth)}for(const o of e.connections.values()){const i=e.positions.get(o.from.key),s=e.positions.get(o.to.key);i===void 0||s===void 0||Y(t,i,s,"map-business-edge",i.depth,s.depth)}}function Y(t,e,n,o,i,s){const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.classList.add(o),a.dataset.fromDepth=String(i),a.dataset.toDepth=String(s);const d={x:(e.x+n.x)/2,y:(e.y+n.y)/2},l={x:-(n.y-e.y)*.08,y:(n.x-e.x)*.08};a.setAttribute("d",`M ${e.x} ${e.y} Q ${d.x+l.x} ${d.y+l.y} ${n.x} ${n.y}`),t.append(a)}function ve(){const t=r("div","map-controls"),e=document.body.classList.contains("is-immersive-map");for(const[n,o,i]of[["zoom-out","−","缩小"],["fit","适应","适应当前地图"],["zoom-in","+","放大"],["immersive",e?"退出":"沉浸",e?"退出沉浸查看":"进入沉浸查看"]]){const s=r("button","map-control");s.type="button",s.dataset.action=n,s.textContent=o,s.title=i,n==="immersive"&&s.setAttribute("aria-pressed",String(e)),t.append(s)}return t}function Ce(t,e,n){let o=n.camera??{scale:1,x:0,y:0},i;const s=new Map([...t.querySelectorAll("[data-action]")].map(c=>[c.dataset.action,c])),a=(c=!1)=>{e.classList.toggle("is-animating",c),e.style.transform=`translate3d(${o.x}px, ${o.y}px, 0) scale(${o.scale})`,n.camera=o,t.dataset.zoom=o.scale<.75?"overview":o.scale<1.4?"region":"detail",ke(t,n,o.scale)},d=()=>{o=ue(t.getBoundingClientRect(),Ee(n)),a(!0)},l=(c,u=o.scale)=>{const y=n.positions.get(c);if(y===void 0)return;const b=t.getBoundingClientRect();o={scale:u,x:b.width/2-y.x*u,y:b.height/2-y.y*u},a(!0)},h=(c,u)=>{o=le(o,c,u),a()};return s.get("zoom-in")?.addEventListener("click",()=>{h(1.25,$(t))}),s.get("zoom-out")?.addEventListener("click",()=>{h(.8,$(t))}),s.get("fit")?.addEventListener("click",d),s.get("immersive")?.addEventListener("click",()=>{W(!document.body.classList.contains("is-immersive-map"))}),t.addEventListener("wheel",c=>{c.preventDefault();const u=t.getBoundingClientRect(),y={x:c.clientX-u.left,y:c.clientY-u.top},b=o.scale;h(Math.exp(-c.deltaY*.0015),y),o.scale>b&&Me(c.target,n,o,y)},{passive:!1}),t.addEventListener("pointerdown",c=>{c.button!==0||c.target.closest("button")||(i={pointerId:c.pointerId,x:c.clientX,y:c.clientY},t.setPointerCapture(c.pointerId),t.classList.add("is-panning"))}),t.addEventListener("pointermove",c=>{i?.pointerId===c.pointerId&&(o=pe(o,{x:c.clientX-i.x,y:c.clientY-i.y}),i={...i,x:c.clientX,y:c.clientY},a())}),t.addEventListener("pointerup",()=>{i=void 0,t.classList.remove("is-panning")}),t.addEventListener("keydown",c=>{(c.key==="+"||c.key==="=")&&(c.preventDefault(),h(1.25,$(t))),c.key==="-"&&(c.preventDefault(),h(.8,$(t))),c.key==="0"&&(c.preventDefault(),d())}),a(),{fit:d,focus:l,refresh:()=>a()}}function W(t){document.body.classList.toggle("is-immersive-map",t);const e=document.querySelector("[data-action=immersive]");e!==null&&(e.textContent=t?"退出":"沉浸",e.title=t?"退出沉浸查看":"进入沉浸查看",e.setAttribute("aria-pressed",String(t))),requestAnimationFrame(()=>{const n=v?.camera;E!==void 0&&n!==void 0?x?.focus(E,n.scale):x?.fit()})}function Me(t,e,n,o){const s=(t instanceof Element?t.closest(".map-node"):null)?.dataset.key??we(e,n,o)??E;if(s===void 0||e.maps.has(s)||e.mapRequests.has(s))return;const a=e.nodes.get(s),d=e.positions.get(s);a?.expandable===!0&&d!==void 0&&n.scale>=P(d.depth+1)&&j(s)}function we(t,e,n){let o;for(const i of t.nodes.values()){if(!i.expandable)continue;const s=t.positions.get(i.node.key);if(s===void 0)continue;const a=s.x*e.scale+e.x,d=s.y*e.scale+e.y,l=Math.hypot(n.x-a,n.y-d);l<=130&&(o===void 0||l<o.distance)&&(o={key:i.node.key,distance:l})}return o?.key}function ke(t,e,n){const o=new Map([...t.querySelectorAll(".map-node")].map(i=>[i.dataset.key,i]));for(const i of e.nodes.values()){const s=e.positions.get(i.node.key),a=o.get(i.node.key);s===void 0||a===void 0||(a.hidden=!T(s.depth,n))}t.querySelectorAll("[data-from-depth][data-to-depth]").forEach(i=>{const s=fe(Number(i.dataset.fromDepth),Number(i.dataset.toDepth),n);i.toggleAttribute("hidden",!s),i.style.display=s?"":"none"})}function Ee(t){const e=[...t.positions.values()];if(e.length===0){const n=p.width/2,o=p.height/2;return{left:n-240,top:o-160,right:n+240,bottom:o+160}}return{left:Math.min(p.width/2,...e.map(({x:n})=>n))-150,top:Math.min(p.height/2,...e.map(({y:n})=>n))-150,right:Math.max(p.width/2,...e.map(({x:n})=>n))+150,bottom:Math.max(p.height/2,...e.map(({y:n})=>n))+150}}function $(t){const e=t.getBoundingClientRect();return{x:e.width/2,y:e.height/2}}async function j(t){const e=v;if(e===void 0)return;E=t;const n=e.nodes.get(t),o=n?.expandable===!0||n===void 0?O(t):Promise.resolve(void 0),i=Se(t),s=await o;s!==void 0&&F(s),await i;const a=e.nodes.get(t),d=e.positions.get(t),l=d===void 0?e.camera?.scale:a?.expandable===!0?P(d.depth+1):Math.max(e.camera?.scale??1,P(d.depth));x?.focus(t,l)}async function Le(){try{const t=await O();F(t),x?.fit()}catch(t){Z(t)}}async function Se(t){if(f!==void 0){E=t,C.querySelectorAll(".map-node").forEach(e=>{e.classList.toggle("is-selected",e.dataset.key===t)}),J(L,"正在加载详情");try{const e=await N(`/api/v1/projects/${f.id}/node?key=${encodeURIComponent(t)}`);Ae(e)}catch(e){const n=r("div","error-state"),o=r("h3");o.textContent="详情暂时无法显示";const i=r("p");i.textContent=R(e),n.append(o,i),L.replaceChildren(n)}}}function Ae(t){const e=t.node;L.replaceChildren();const n=r("header","detail-heading"),o=r("p","detail-kind");o.textContent=`类型:${ee(e.kind)}`;const i=r("h3");i.textContent=e.label;const s=r("p");if(s.textContent=e.summary,n.append(o,i,s),L.append(n),t.relations.length===0)return;const a=Re("相关业务");t.relations.forEach(d=>{const l=r("div","relation-item"),h=r("span");h.textContent=d.node.label,l.append(h),a.append(l)}),L.append(a)}function $e(t){S.replaceChildren();const e=r("button","breadcrumb-button");e.type="button",e.textContent=f?.name??"业务地图",e.addEventListener("click",()=>{Le(),G()}),S.append(e);for(const n of t.breadcrumbs){const o=r("span","breadcrumb-separator");o.textContent="/";const i=r("button","breadcrumb-button");i.type="button",i.textContent=n.label,i.addEventListener("click",()=>{j(n.key)}),S.append(o,i)}}async function Ie(t){if(f===void 0)return;const e=++I;g.hidden=!1;const n=r("div","search-message");n.textContent="正在搜索业务知识…",g.replaceChildren(n);try{const o=await N(`/api/v1/projects/${f.id}/search?q=${encodeURIComponent(t)}&limit=12`);if(e!==I||m.value.trim()!==t)return;Pe(o.results)}catch(o){if(e!==I)return;const i=r("div","search-message");i.textContent=R(o),g.replaceChildren(i)}}function Pe(t){if(g.replaceChildren(),g.hidden=!1,t.length===0){const e=r("div","search-message");e.textContent="没有找到匹配的业务知识。",g.append(e);return}for(const e of t){const n=r("button","search-result");n.type="button";const o=r("strong");o.textContent=e.node.label;const i=r("span");i.textContent=`类型:${ee(e.node.kind)}`,n.append(o,i),n.addEventListener("click",()=>{m.value="",A(),j(e.node.key)}),g.append(n)}}function A(){I+=1,g.hidden=!0,g.replaceChildren()}function je(){m.disabled=!0;const t=r("div","empty-state"),e=r("h3");e.textContent="没有可查看的项目";const n=r("p");n.textContent="请先为主分支项目准备业务知识。",t.append(e,n),C.replaceChildren(t)}function Z(t){S.replaceChildren();const e=r("span","breadcrumb-button");e.textContent=f?.name??"业务地图",S.append(e);const n=r("div","error-state"),o=r("h3");o.textContent=t instanceof X&&t.code==="ATLAS_STATE_UNAVAILABLE"?"地图尚未准备好":"业务地图暂时无法显示";const i=r("p");i.textContent=R(t),n.append(o,i),C.replaceChildren(n)}function Ne(t,e){const n=r("div","error-state"),o=r("h3");o.textContent=t;const i=r("p");i.textContent=e,n.append(o,i),C.replaceChildren(n),Be(e)}function G(){const t=r("div","detail-placeholder"),e=r("h3");e.textContent="选择一个业务区域";const n=r("p");n.textContent="在地图上点击节点查看简介和相关业务。",t.append(e,n),L.replaceChildren(t)}function J(t,e){const n=r("div","loading-state");n.textContent=e,t.replaceChildren(n)}function Re(t){const e=r("section","detail-section"),n=r("h4");return n.textContent=t,e.append(n),e}async function N(t){const e=await fetch(t,{headers:{Accept:"application/json"}}),n=await e.json();if(!e.ok||"error"in n){const o="error"in n?n.error:{code:"INVALID_RESPONSE",message:"The local API returned an invalid response."};throw new X(o.code,o.message)}return n.data}function qe(t){const e=new URL(location.href);e.searchParams.set("project",t),history.replaceState(null,"",e)}function Be(t){window.clearTimeout(V),B.textContent=t,B.hidden=!1,V=window.setTimeout(()=>{B.hidden=!0},4500)}function ee(t){return{Capability:"能力",Scenario:"场景",Operation:"操作",Invariant:"规则",Interface:"接口",Data:"数据"}[t]??t}function R(t){return t instanceof Error?t.message:String(t)}function M(t){const e=document.getElementById(t);if(e===null)throw new Error(`Missing required interface element ${t}`);return e}function r(t,e){const n=document.createElement(t);return e!==void 0&&(n.className=e),n}
|
|
2
|
+
//# sourceMappingURL=index-cze_4vtt.js.map
|