noteconnection 1.7.0 → 1.8.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/LICENSE +674 -21
- package/README.md +242 -62
- package/dist/src/agent_workspace.contract.parity.test.js +475 -0
- package/dist/src/agent_workspace.frontend.test.js +9989 -0
- package/dist/src/agent_workspace.locale.contract.test.js +95 -0
- package/dist/src/agent_workspace.runtime.behavior.test.js +5072 -0
- package/dist/src/copy.assets.contract.test.js +130 -0
- package/dist/src/core/PathBridge.js +28 -3
- package/dist/src/export/WorkspaceExportBundle.js +1130 -0
- package/dist/src/export/WorkspaceExportBundle.test.js +1480 -0
- package/dist/src/export/index.js +18 -0
- package/dist/src/export/types.js +2 -0
- package/dist/src/fixrisk.issue.verifier.contract.test.js +3 -1
- package/dist/src/foundation.ann.runtime.contract.test.js +81 -0
- package/dist/src/foundation.release.evidence.contract.test.js +406 -0
- package/dist/src/foundation.sqlite.runtime.contract.test.js +82 -0
- package/dist/src/frontend/README.md +242 -62
- package/dist/src/frontend/agent_workspace.js +5353 -0
- package/dist/src/frontend/agent_workspace_runtime.js +4434 -0
- package/dist/src/frontend/analysis.js +31 -4
- package/dist/src/frontend/app.js +2178 -62
- package/dist/src/frontend/focus_mode_interactions.js +33 -0
- package/dist/src/frontend/godot_future_path_renderer.js +540 -0
- package/dist/src/frontend/godot_tree_interactions.js +178 -0
- package/dist/src/frontend/graph_state.mjs +105 -0
- package/dist/src/frontend/hosted_future_path_runtime.js +157 -0
- package/dist/src/frontend/i18n.mjs +186 -0
- package/dist/src/frontend/index.html +641 -266
- package/dist/src/frontend/layout_gpu.js +12 -4
- package/dist/src/frontend/locales/en.json +721 -5
- package/dist/src/frontend/locales/zh.json +721 -5
- package/dist/src/frontend/main.mjs +60 -0
- package/dist/src/frontend/markdown_runtime.js +827 -0
- package/dist/src/frontend/notemd.css +49 -0
- package/dist/src/frontend/notemd.html +7 -1
- package/dist/src/frontend/notemd.js +64 -0
- package/dist/src/frontend/path.html +107 -0
- package/dist/src/frontend/path_app.js +2108 -130
- package/dist/src/frontend/path_layout.mjs +143 -0
- package/dist/src/frontend/path_mermaid_utils.mjs +108 -0
- package/dist/src/frontend/path_modules_bridge.js +486 -0
- package/dist/src/frontend/path_state.mjs +118 -0
- package/dist/src/frontend/path_styles.css +146 -0
- package/dist/src/frontend/path_worker_bridge.mjs +85 -0
- package/dist/src/frontend/reader.js +393 -33
- package/dist/src/frontend/runtime_bridge.js +67 -54
- package/dist/src/frontend/runtime_bridge.mjs +279 -0
- package/dist/src/frontend/settings.js +130 -12
- package/dist/src/frontend/source_manager.js +190 -21
- package/dist/src/frontend/styles.css +2720 -72
- package/dist/src/frontend/workbench_state.mjs +101 -0
- package/dist/src/frontend/workspace_panes.js +10168 -0
- package/dist/src/frontend.locale.contract.test.js +62 -0
- package/dist/src/godot.sidecar.bootstrap.contract.test.js +244 -0
- package/dist/src/indexing/IndexLifecycle.js +195 -0
- package/dist/src/indexing/IndexLifecycle.test.js +49 -0
- package/dist/src/indexing/SegmentBuilder.js +64 -0
- package/dist/src/indexing/UnitBuilder.js +48 -0
- package/dist/src/indexing/types.js +2 -0
- package/dist/src/knowledge.api.contract.test.js +170 -0
- package/dist/src/learning/KnowledgeLearningPlatform.js +10386 -0
- package/dist/src/learning/KnowledgeLearningPlatform.persistence.test.js +327 -0
- package/dist/src/learning/KnowledgeLearningPlatform.program-f.test.js +99 -0
- package/dist/src/learning/KnowledgeLearningPlatform.test.js +2971 -0
- package/dist/src/learning/KnowledgeWorkspaceConversationRegression.js +2974 -0
- package/dist/src/learning/KnowledgeWorkspaceConversationRegression.test.js +3928 -0
- package/dist/src/learning/answerReleaseReview.js +4319 -0
- package/dist/src/learning/answerReleaseReview.test.js +2888 -0
- package/dist/src/learning/api.js +2 -0
- package/dist/src/learning/conversationComposer.js +1480 -0
- package/dist/src/learning/conversationComposer.test.js +1817 -0
- package/dist/src/learning/domains/ConversationManager.js +53 -0
- package/dist/src/learning/domains/KnowledgeIngestor.js +238 -0
- package/dist/src/learning/domains/KnowledgeQuerier.js +187 -0
- package/dist/src/learning/domains/MasteryEngine.js +387 -0
- package/dist/src/learning/domains/MemoryPolicyManager.js +408 -0
- package/dist/src/learning/domains/QualityEvaluator.js +307 -0
- package/dist/src/learning/domains/TutorRouter.js +313 -0
- package/dist/src/learning/domains/index.js +33 -0
- package/dist/src/learning/domains/types.js +7 -0
- package/dist/src/learning/errors.js +29 -0
- package/dist/src/learning/evidenceContextAssembler.js +1176 -0
- package/dist/src/learning/evidenceContextAssembler.test.js +6332 -0
- package/dist/src/learning/graphContextAssembler.js +870 -0
- package/dist/src/learning/graphContextAssembler.test.js +1033 -0
- package/dist/src/learning/index.js +28 -0
- package/dist/src/learning/queryBackend.js +1898 -0
- package/dist/src/learning/queryBackend.test.js +955 -0
- package/dist/src/learning/ragContextPack.js +257 -0
- package/dist/src/learning/ragContextPack.test.js +160 -0
- package/dist/src/learning/ragPublicText.js +38 -0
- package/dist/src/learning/ragSufficiencyJudge.js +161 -0
- package/dist/src/learning/ragSufficiencyJudge.test.js +177 -0
- package/dist/src/learning/ragSufficiencyProviderJudge.js +227 -0
- package/dist/src/learning/ragSufficiencyProviderJudge.test.js +156 -0
- package/dist/src/learning/requestNormalization.js +198 -0
- package/dist/src/learning/runtimeCapability.js +4677 -0
- package/dist/src/learning/runtimeCapability.test.js +3635 -0
- package/dist/src/learning/store.js +1240 -0
- package/dist/src/learning/store.test.js +1126 -0
- package/dist/src/learning/tutorAdapter.js +2 -0
- package/dist/src/learning/types.js +2 -0
- package/dist/src/learning/vectorAccelerationAdapter.js +942 -0
- package/dist/src/learning/vectorAccelerationAdapter.test.js +382 -0
- package/dist/src/lfs.asset.policy.contract.test.js +153 -0
- package/dist/src/license.policy.contract.test.js +66 -0
- package/dist/src/memory/MemoryGovernance.js +74 -0
- package/dist/src/memory/MemoryGovernance.test.js +46 -0
- package/dist/src/memory/types.js +2 -0
- package/dist/src/mermaid.frontend.guard.contract.test.js +77 -0
- package/dist/src/middleware/auth.js +17 -0
- package/dist/src/middleware/body-parser.js +45 -0
- package/dist/src/middleware/cors.js +44 -0
- package/dist/src/middleware/index.js +21 -0
- package/dist/src/middleware/request-trace.js +96 -0
- package/dist/src/notemd/AppConfigToml.js +6 -4
- package/dist/src/notemd/MermaidProcessor.js +400 -50
- package/dist/src/notemd/NotemdService.js +498 -13
- package/dist/src/notemd/PromptManager.js +15 -0
- package/dist/src/notemd/cli/commands.js +357 -0
- package/dist/src/notemd/cli/dispatcher.js +225 -0
- package/dist/src/notemd/cli/index.js +169 -0
- package/dist/src/notemd/cli/parser.js +68 -0
- package/dist/src/notemd/cli/types.js +2 -0
- package/dist/src/notemd/constants.js +43 -0
- package/dist/src/notemd/diagram/diagramGenerationService.js +78 -0
- package/dist/src/notemd/diagram/diagramSpec.js +79 -0
- package/dist/src/notemd/diagram/diagramSpecResponseParser.js +131 -0
- package/dist/src/notemd/diagram/intent.js +95 -0
- package/dist/src/notemd/diagram/planner.js +71 -0
- package/dist/src/notemd/diagram/prompts/diagramSpecPrompt.js +42 -0
- package/dist/src/notemd/diagram/types.js +18 -0
- package/dist/src/notemd/index.js +26 -0
- package/dist/src/notemd/operations/capabilityManifest.js +23 -0
- package/dist/src/notemd/operations/cliContracts.js +17 -0
- package/dist/src/notemd/operations/configProfileCommands.js +85 -0
- package/dist/src/notemd/operations/registry.contract.test.js +95 -0
- package/dist/src/notemd/operations/registry.js +991 -0
- package/dist/src/notemd/operations/types.js +2 -0
- package/dist/src/notemd/providerDiagnostics.js +220 -0
- package/dist/src/notemd/providerProfiles.js +42 -0
- package/dist/src/notemd/providerTemplates.js +231 -0
- package/dist/src/notemd/search/DuckDuckGoProvider.js +39 -0
- package/dist/src/notemd/search/SearchManager.js +13 -0
- package/dist/src/notemd/search/SearchProvider.js +2 -0
- package/dist/src/notemd/search/TavilyProvider.js +44 -0
- package/dist/src/notemd.agent.manifest.test.js +85 -0
- package/dist/src/notemd.api.contract.test.js +14 -1
- package/dist/src/notemd.app_config_toml.test.js +2 -1
- package/dist/src/notemd.batch.workflow.test.js +117 -0
- package/dist/src/notemd.cli.e2e.test.js +136 -0
- package/dist/src/notemd.core.test.js +51 -0
- package/dist/src/notemd.diagram.pipeline.test.js +233 -0
- package/dist/src/notemd.providerTemplates.test.js +34 -0
- package/dist/src/notemd.server.integration.test.js +143 -35
- package/dist/src/notemd.workflow.pipeline.test.js +162 -0
- package/dist/src/pathbridge.handshake.contract.test.js +16 -2
- package/dist/src/pathmode.background.contract.test.js +69 -0
- package/dist/src/pathmode.settings.api.contract.test.js +9 -0
- package/dist/src/pkg.sidecar.contract.test.js +9 -3
- package/dist/src/platform/ExportProfile.js +58 -0
- package/dist/src/platform/PlatformCapabilities.js +45 -0
- package/dist/src/platform/PlatformCapabilities.test.js +30 -0
- package/dist/src/platform/RenderMaterializer.js +33 -0
- package/dist/src/platform/RenderMaterializer.test.js +32 -0
- package/dist/src/query_backend.external_http.integration.test.js +410 -0
- package/dist/src/reader_renderer.js +404 -3
- package/dist/src/reader_renderer.test.js +87 -0
- package/dist/src/release.godot.mirror.contract.test.js +73 -0
- package/dist/src/resources/ResourceRegistry.js +223 -0
- package/dist/src/resources/ResourceRegistry.test.js +61 -0
- package/dist/src/resources/types.js +2 -0
- package/dist/src/routes/agentWorkspaceDiagnostics.js +173 -0
- package/dist/src/routes/data.js +267 -0
- package/dist/src/routes/diagnostics.js +51 -0
- package/dist/src/routes/index.js +23 -0
- package/dist/src/routes/knowledge.js +968 -0
- package/dist/src/routes/markdown.js +287 -0
- package/dist/src/routes/notemd.js +565 -0
- package/dist/src/routes/registry.contract.test.js +130 -0
- package/dist/src/routes/render.js +285 -0
- package/dist/src/routes/runtimeRunbookRouteOps.js +149 -0
- package/dist/src/routes/runtimeRunbookRouteOps.test.js +194 -0
- package/dist/src/routes/settings.js +6 -0
- package/dist/src/routes/staticFiles.js +94 -0
- package/dist/src/routes/types.js +2 -0
- package/dist/src/runtime.transport.adapter.contract.test.js +81 -0
- package/dist/src/server.js +11090 -1549
- package/dist/src/server.migration.test.js +193 -21
- package/dist/src/server.port.fallback.contract.test.js +63 -0
- package/dist/src/session/SessionStateStore.js +81 -0
- package/dist/src/session/SessionStateStore.test.js +58 -0
- package/dist/src/session/types.js +2 -0
- package/dist/src/settings.runtime.contract.test.js +50 -0
- package/dist/src/shared/types.contract.test.js +107 -0
- package/dist/src/shared/types.js +22 -0
- package/dist/src/sidecar.replacement.boundary.contract.test.js +128 -0
- package/dist/src/sidecar.supply.readiness.contract.test.js +144 -0
- package/dist/src/source_manager.loadflow.test.js +46 -0
- package/dist/src/startup.layout.snapshot.contract.test.js +57 -0
- package/dist/src/tauri.frontend.build.contract.test.js +60 -0
- package/dist/src/tauri.sidecar.cleanup.contract.test.js +21 -0
- package/dist/src/utils/RuntimePaths.js +4 -13
- package/dist/src/utils/platform.js +153 -0
- package/dist/src/workflows/WorkflowArtifactStore.js +96 -0
- package/dist/src/workflows/WorkflowArtifactStore.test.js +80 -0
- package/dist/src/workflows/types.js +2 -0
- package/dist/src/workspace/WorkspaceRegistry.js +122 -0
- package/dist/src/workspace/WorkspaceRegistry.test.js +29 -0
- package/dist/src/workspace/types.js +2 -0
- package/package.json +53 -10
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
function getNestedStringValue(record, dottedKey) {
|
|
39
|
+
const value = dottedKey.split('.').reduce((current, segment) => {
|
|
40
|
+
if (!current || typeof current !== 'object' || !(segment in current)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return current[segment];
|
|
44
|
+
}, record);
|
|
45
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : null;
|
|
46
|
+
}
|
|
47
|
+
describe('frontend locale contract', () => {
|
|
48
|
+
const repoRoot = path.resolve(__dirname, '..');
|
|
49
|
+
const enLocale = JSON.parse(fs.readFileSync(path.join(repoRoot, 'src', 'frontend', 'locales', 'en.json'), 'utf8'));
|
|
50
|
+
const zhLocale = JSON.parse(fs.readFileSync(path.join(repoRoot, 'src', 'frontend', 'locales', 'zh.json'), 'utf8'));
|
|
51
|
+
const requiredKeys = [
|
|
52
|
+
'analysis_title',
|
|
53
|
+
'node_details',
|
|
54
|
+
'reader_loading',
|
|
55
|
+
'reader_outline_title',
|
|
56
|
+
'reader_outline_empty',
|
|
57
|
+
];
|
|
58
|
+
test('required reader and analysis keys resolve in both locales', () => {
|
|
59
|
+
const missing = requiredKeys.filter((key) => (!getNestedStringValue(enLocale, key) || !getNestedStringValue(zhLocale, key)));
|
|
60
|
+
expect(missing).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const crypto = __importStar(require("crypto"));
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const os = __importStar(require("os"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const url_1 = require("url");
|
|
41
|
+
class TempDir {
|
|
42
|
+
constructor(prefix) {
|
|
43
|
+
this.path = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), `${prefix}-`));
|
|
44
|
+
}
|
|
45
|
+
child(relative) {
|
|
46
|
+
return path.join(this.path, relative);
|
|
47
|
+
}
|
|
48
|
+
mkdir(relative) {
|
|
49
|
+
const target = this.child(relative);
|
|
50
|
+
fs.mkdirSync(target, { recursive: true });
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
cleanup() {
|
|
54
|
+
fs.rmSync(this.path, { recursive: true, force: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function sha256File(filePath) {
|
|
58
|
+
return crypto.createHash('sha256').update(fs.readFileSync(filePath)).digest('hex');
|
|
59
|
+
}
|
|
60
|
+
describe('godot sidecar bootstrap contracts', () => {
|
|
61
|
+
const repoRoot = path.resolve(__dirname, '..');
|
|
62
|
+
const sidecarUtilsPath = path.join(repoRoot, 'scripts', 'tauri-sidecar-utils.js');
|
|
63
|
+
let sidecarUtils;
|
|
64
|
+
let temp;
|
|
65
|
+
beforeAll(() => {
|
|
66
|
+
sidecarUtils = require(sidecarUtilsPath);
|
|
67
|
+
});
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
temp = new TempDir('noteconnection-godot-bootstrap');
|
|
70
|
+
});
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
if (temp) {
|
|
73
|
+
temp.cleanup();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
test('downloads and caches a host godot binary when a pinned file URL is configured', async () => {
|
|
77
|
+
const fakeRepoRoot = temp.mkdir('repo');
|
|
78
|
+
const downloadRoot = temp.mkdir('downloads');
|
|
79
|
+
const cacheRoot = temp.mkdir('cache');
|
|
80
|
+
const sourceBinaryPath = path.join(downloadRoot, 'godot-linux-x64');
|
|
81
|
+
const sourceBinary = Buffer.alloc(sidecarUtils.MIN_GODOT_BINARY_BYTES + 64, 7);
|
|
82
|
+
fs.writeFileSync(sourceBinaryPath, sourceBinary);
|
|
83
|
+
const result = await sidecarUtils.prepareGodotSidecar({
|
|
84
|
+
repoRoot: fakeRepoRoot,
|
|
85
|
+
platform: 'linux',
|
|
86
|
+
arch: 'x64',
|
|
87
|
+
env: {
|
|
88
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_URL: (0, url_1.pathToFileURL)(sourceBinaryPath).href,
|
|
89
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_SHA256: sha256File(sourceBinaryPath),
|
|
90
|
+
NOTE_CONNECTION_GODOT_CACHE_DIR: cacheRoot,
|
|
91
|
+
},
|
|
92
|
+
logger: console,
|
|
93
|
+
});
|
|
94
|
+
expect(result.outcome).toBe('prepared');
|
|
95
|
+
expect(result.sourceKind).toBe('download');
|
|
96
|
+
expect(fs.existsSync(result.targetPath)).toBe(true);
|
|
97
|
+
expect(fs.existsSync(result.cachePath)).toBe(true);
|
|
98
|
+
expect(fs.readFileSync(result.targetPath)).toEqual(sourceBinary);
|
|
99
|
+
expect(fs.readFileSync(result.cachePath)).toEqual(sourceBinary);
|
|
100
|
+
});
|
|
101
|
+
test('accepts GitHub Releases URLs as pinned bootstrap sources without provider-specific branching', () => {
|
|
102
|
+
const fakeRepoRoot = temp.mkdir('repo');
|
|
103
|
+
const cacheRoot = temp.mkdir('cache');
|
|
104
|
+
const githubReleaseUrl = 'https://github.com/Jacobinwwey/NoteConnection/releases/download/v1.7.0/godot-x86_64-unknown-linux-gnu';
|
|
105
|
+
const context = sidecarUtils.resolveGodotBootstrapContext({
|
|
106
|
+
repoRoot: fakeRepoRoot,
|
|
107
|
+
platform: 'linux',
|
|
108
|
+
arch: 'x64',
|
|
109
|
+
env: {
|
|
110
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_URL: githubReleaseUrl,
|
|
111
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_SHA256: 'abc123',
|
|
112
|
+
NOTE_CONNECTION_GODOT_CACHE_DIR: cacheRoot,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
expect(context).not.toBeNull();
|
|
116
|
+
expect(context?.downloadUrl).toBe(githubReleaseUrl);
|
|
117
|
+
expect(context?.expectedSha256).toBe('abc123');
|
|
118
|
+
expect(context?.cachePath).toBe(path.join(cacheRoot, 'godot-x86_64-unknown-linux-gnu'));
|
|
119
|
+
expect(context?.targetPath).toBe(path.join(fakeRepoRoot, 'src-tauri', 'bin', 'godot-x86_64-unknown-linux-gnu'));
|
|
120
|
+
});
|
|
121
|
+
test('accepts generic object-storage mirror URLs through the same bootstrap contract', () => {
|
|
122
|
+
const fakeRepoRoot = temp.mkdir('repo');
|
|
123
|
+
const cacheRoot = temp.mkdir('cache');
|
|
124
|
+
const objectStorageUrl = 'https://mirror.example.invalid/noteconnection/godot/godot-x86_64-unknown-linux-gnu';
|
|
125
|
+
const context = sidecarUtils.resolveGodotBootstrapContext({
|
|
126
|
+
repoRoot: fakeRepoRoot,
|
|
127
|
+
platform: 'linux',
|
|
128
|
+
arch: 'x64',
|
|
129
|
+
env: {
|
|
130
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_URL: objectStorageUrl,
|
|
131
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_SHA256: 'def456',
|
|
132
|
+
NOTE_CONNECTION_GODOT_CACHE_DIR: cacheRoot,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
expect(context).not.toBeNull();
|
|
136
|
+
expect(context?.downloadUrl).toBe(objectStorageUrl);
|
|
137
|
+
expect(context?.expectedSha256).toBe('def456');
|
|
138
|
+
expect(context?.cachePath).toBe(path.join(cacheRoot, 'godot-x86_64-unknown-linux-gnu'));
|
|
139
|
+
});
|
|
140
|
+
test('reuses cached godot binary when the original download source is gone', async () => {
|
|
141
|
+
const fakeRepoRoot = temp.mkdir('repo');
|
|
142
|
+
const downloadRoot = temp.mkdir('downloads');
|
|
143
|
+
const cacheRoot = temp.mkdir('cache');
|
|
144
|
+
const sourceBinaryPath = path.join(downloadRoot, 'godot-linux-x64');
|
|
145
|
+
fs.writeFileSync(sourceBinaryPath, Buffer.alloc(sidecarUtils.MIN_GODOT_BINARY_BYTES + 32, 3));
|
|
146
|
+
const env = {
|
|
147
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_URL: (0, url_1.pathToFileURL)(sourceBinaryPath).href,
|
|
148
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_SHA256: sha256File(sourceBinaryPath),
|
|
149
|
+
NOTE_CONNECTION_GODOT_CACHE_DIR: cacheRoot,
|
|
150
|
+
};
|
|
151
|
+
const first = await sidecarUtils.prepareGodotSidecar({
|
|
152
|
+
repoRoot: fakeRepoRoot,
|
|
153
|
+
platform: 'linux',
|
|
154
|
+
arch: 'x64',
|
|
155
|
+
env,
|
|
156
|
+
logger: console,
|
|
157
|
+
});
|
|
158
|
+
expect(first.sourceKind).toBe('download');
|
|
159
|
+
fs.rmSync(sourceBinaryPath, { force: true });
|
|
160
|
+
fs.rmSync(first.targetPath, { force: true });
|
|
161
|
+
const second = await sidecarUtils.prepareGodotSidecar({
|
|
162
|
+
repoRoot: fakeRepoRoot,
|
|
163
|
+
platform: 'linux',
|
|
164
|
+
arch: 'x64',
|
|
165
|
+
env,
|
|
166
|
+
logger: console,
|
|
167
|
+
});
|
|
168
|
+
expect(second.outcome).toBe('prepared');
|
|
169
|
+
expect(second.sourceKind).toBe('cache');
|
|
170
|
+
expect(fs.existsSync(second.targetPath)).toBe(true);
|
|
171
|
+
});
|
|
172
|
+
test('rejects downloaded godot binaries when sha256 does not match the pinned value', async () => {
|
|
173
|
+
const fakeRepoRoot = temp.mkdir('repo');
|
|
174
|
+
const downloadRoot = temp.mkdir('downloads');
|
|
175
|
+
const cacheRoot = temp.mkdir('cache');
|
|
176
|
+
const sourceBinaryPath = path.join(downloadRoot, 'godot-linux-x64');
|
|
177
|
+
fs.writeFileSync(sourceBinaryPath, Buffer.alloc(sidecarUtils.MIN_GODOT_BINARY_BYTES + 16, 9));
|
|
178
|
+
await expect(sidecarUtils.prepareGodotSidecar({
|
|
179
|
+
repoRoot: fakeRepoRoot,
|
|
180
|
+
platform: 'linux',
|
|
181
|
+
arch: 'x64',
|
|
182
|
+
env: {
|
|
183
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_URL: (0, url_1.pathToFileURL)(sourceBinaryPath).href,
|
|
184
|
+
NOTE_CONNECTION_GODOT_DOWNLOAD_SHA256: 'deadbeef',
|
|
185
|
+
NOTE_CONNECTION_GODOT_CACHE_DIR: cacheRoot,
|
|
186
|
+
},
|
|
187
|
+
logger: console,
|
|
188
|
+
})).rejects.toThrow(/sha256/i);
|
|
189
|
+
});
|
|
190
|
+
test('does not require a linux host godot binary by default when validating sidecars', () => {
|
|
191
|
+
const fakeRepoRoot = temp.mkdir('repo');
|
|
192
|
+
const binDir = temp.mkdir(path.join('repo', 'src-tauri', 'bin'));
|
|
193
|
+
fs.writeFileSync(path.join(binDir, 'server-x86_64-unknown-linux-gnu'), 'server');
|
|
194
|
+
fs.writeFileSync(path.join(binDir, 'markdown-worker-x86_64-unknown-linux-gnu'), 'worker');
|
|
195
|
+
const result = sidecarUtils.validateTauriSidecars({
|
|
196
|
+
repoRoot: fakeRepoRoot,
|
|
197
|
+
platform: 'linux',
|
|
198
|
+
arch: 'x64',
|
|
199
|
+
});
|
|
200
|
+
expect(sidecarUtils.resolveHostGodotBinaryName({ platform: 'linux', arch: 'x64' })).toBe('godot-x86_64-unknown-linux-gnu');
|
|
201
|
+
expect(result.invalid).toEqual([]);
|
|
202
|
+
});
|
|
203
|
+
test('requires the windows host godot binary together with server and markdown worker sidecars', () => {
|
|
204
|
+
const fakeRepoRoot = temp.mkdir('repo');
|
|
205
|
+
const binDir = temp.mkdir(path.join('repo', 'src-tauri', 'bin'));
|
|
206
|
+
fs.writeFileSync(path.join(binDir, 'server-x86_64-pc-windows-msvc.exe'), 'server');
|
|
207
|
+
fs.writeFileSync(path.join(binDir, 'markdown-worker-x86_64-pc-windows-msvc.exe'), 'worker');
|
|
208
|
+
const missingGodot = sidecarUtils.validateTauriSidecars({
|
|
209
|
+
repoRoot: fakeRepoRoot,
|
|
210
|
+
platform: 'win32',
|
|
211
|
+
arch: 'x64',
|
|
212
|
+
});
|
|
213
|
+
expect(missingGodot.invalid).toEqual([
|
|
214
|
+
expect.stringContaining('godot-x86_64-pc-windows-msvc.exe'),
|
|
215
|
+
]);
|
|
216
|
+
fs.writeFileSync(path.join(binDir, 'godot-x86_64-pc-windows-msvc.exe'), Buffer.alloc(sidecarUtils.MIN_GODOT_BINARY_BYTES + 8, 5));
|
|
217
|
+
const ready = sidecarUtils.validateTauriSidecars({
|
|
218
|
+
repoRoot: fakeRepoRoot,
|
|
219
|
+
platform: 'win32',
|
|
220
|
+
arch: 'x64',
|
|
221
|
+
});
|
|
222
|
+
expect(ready.invalid).toEqual([]);
|
|
223
|
+
});
|
|
224
|
+
test('treats git-lfs pointer placeholders as invalid server and markdown-worker sidecars', () => {
|
|
225
|
+
const fakeRepoRoot = temp.mkdir('repo');
|
|
226
|
+
const binDir = temp.mkdir(path.join('repo', 'src-tauri', 'bin'));
|
|
227
|
+
const lfsPointer = [
|
|
228
|
+
'version https://git-lfs.github.com/spec/v1',
|
|
229
|
+
'oid sha256:deadbeef',
|
|
230
|
+
'size 12345678',
|
|
231
|
+
].join('\n');
|
|
232
|
+
fs.writeFileSync(path.join(binDir, 'server-x86_64-unknown-linux-gnu'), lfsPointer);
|
|
233
|
+
fs.writeFileSync(path.join(binDir, 'markdown-worker-x86_64-unknown-linux-gnu'), lfsPointer);
|
|
234
|
+
const result = sidecarUtils.validateTauriSidecars({
|
|
235
|
+
repoRoot: fakeRepoRoot,
|
|
236
|
+
platform: 'linux',
|
|
237
|
+
arch: 'x64',
|
|
238
|
+
});
|
|
239
|
+
expect(result.invalid).toEqual([
|
|
240
|
+
expect.stringContaining('server-x86_64-unknown-linux-gnu'),
|
|
241
|
+
expect.stringContaining('markdown-worker-x86_64-unknown-linux-gnu'),
|
|
242
|
+
]);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexLifecycle = void 0;
|
|
4
|
+
const SegmentBuilder_1 = require("./SegmentBuilder");
|
|
5
|
+
const UnitBuilder_1 = require("./UnitBuilder");
|
|
6
|
+
class IndexLifecycle {
|
|
7
|
+
constructor(nextId, computeHash) {
|
|
8
|
+
this.nextId = nextId;
|
|
9
|
+
this.computeHash = computeHash;
|
|
10
|
+
this.units = new Map();
|
|
11
|
+
this.segments = new Map();
|
|
12
|
+
this.unitIdsByDocumentId = new Map();
|
|
13
|
+
this.segmentIdsByAtomId = new Map();
|
|
14
|
+
this.unitBuilder = new UnitBuilder_1.UnitBuilder(computeHash);
|
|
15
|
+
this.segmentBuilder = new SegmentBuilder_1.SegmentBuilder(computeHash);
|
|
16
|
+
}
|
|
17
|
+
syncDocumentIndex(input) {
|
|
18
|
+
this.retireDocumentIndex(input.documentId);
|
|
19
|
+
const unitDrafts = this.unitBuilder.buildDocumentAndAtomUnits({
|
|
20
|
+
documentId: input.documentId,
|
|
21
|
+
sourcePath: input.sourcePath,
|
|
22
|
+
language: input.language,
|
|
23
|
+
workspaceId: input.workspaceId,
|
|
24
|
+
corpusId: input.corpusId,
|
|
25
|
+
title: input.title,
|
|
26
|
+
content: input.content,
|
|
27
|
+
}, input.atoms);
|
|
28
|
+
const createdUnits = [];
|
|
29
|
+
const createdSegments = [];
|
|
30
|
+
unitDrafts.forEach((draft) => {
|
|
31
|
+
const unitId = this.nextId('idx_unit');
|
|
32
|
+
const builtSegments = this.segmentBuilder.buildSegments(draft.content);
|
|
33
|
+
const segmentIds = [];
|
|
34
|
+
builtSegments.forEach((segmentDraft) => {
|
|
35
|
+
const segmentId = this.nextId('idx_segment');
|
|
36
|
+
const segment = {
|
|
37
|
+
segmentId,
|
|
38
|
+
unitId,
|
|
39
|
+
resourceId: input.resourceId,
|
|
40
|
+
projectionId: input.projectionId,
|
|
41
|
+
documentId: draft.documentId,
|
|
42
|
+
atomId: draft.atomId,
|
|
43
|
+
workspaceId: draft.workspaceId,
|
|
44
|
+
corpusId: draft.corpusId,
|
|
45
|
+
modality: 'text',
|
|
46
|
+
segmentIndex: segmentDraft.segmentIndex,
|
|
47
|
+
content: segmentDraft.content,
|
|
48
|
+
contentHash: segmentDraft.contentHash,
|
|
49
|
+
tokenCount: segmentDraft.tokenCount,
|
|
50
|
+
state: 'indexed',
|
|
51
|
+
error: null,
|
|
52
|
+
representationVersion: 'noteconnection-index-segment-v1',
|
|
53
|
+
createdAt: input.indexedAt,
|
|
54
|
+
updatedAt: input.indexedAt,
|
|
55
|
+
};
|
|
56
|
+
this.segments.set(segmentId, segment);
|
|
57
|
+
createdSegments.push(segment);
|
|
58
|
+
segmentIds.push(segmentId);
|
|
59
|
+
});
|
|
60
|
+
const unit = {
|
|
61
|
+
unitId,
|
|
62
|
+
resourceId: input.resourceId,
|
|
63
|
+
projectionId: input.projectionId,
|
|
64
|
+
documentId: draft.documentId,
|
|
65
|
+
atomId: draft.atomId,
|
|
66
|
+
workspaceId: draft.workspaceId,
|
|
67
|
+
corpusId: draft.corpusId,
|
|
68
|
+
sourcePath: draft.sourcePath,
|
|
69
|
+
language: draft.language,
|
|
70
|
+
title: draft.title,
|
|
71
|
+
content: draft.content,
|
|
72
|
+
unitKind: draft.unitKind,
|
|
73
|
+
unitIndex: draft.unitIndex,
|
|
74
|
+
contentHash: draft.contentHash,
|
|
75
|
+
state: 'indexed',
|
|
76
|
+
error: null,
|
|
77
|
+
segmentIds,
|
|
78
|
+
createdAt: input.indexedAt,
|
|
79
|
+
updatedAt: input.indexedAt,
|
|
80
|
+
};
|
|
81
|
+
this.units.set(unitId, unit);
|
|
82
|
+
createdUnits.push(unit);
|
|
83
|
+
const existingUnitIds = this.unitIdsByDocumentId.get(input.documentId) || [];
|
|
84
|
+
existingUnitIds.push(unitId);
|
|
85
|
+
this.unitIdsByDocumentId.set(input.documentId, existingUnitIds);
|
|
86
|
+
if (draft.atomId) {
|
|
87
|
+
this.segmentIdsByAtomId.set(draft.atomId, [...segmentIds]);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
units: createdUnits,
|
|
92
|
+
segments: createdSegments,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
retireDocumentIndex(documentId) {
|
|
96
|
+
const unitIds = this.unitIdsByDocumentId.get(String(documentId || '').trim()) || [];
|
|
97
|
+
unitIds.forEach((unitId) => {
|
|
98
|
+
const unit = this.units.get(unitId);
|
|
99
|
+
if (!unit) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (unit.atomId) {
|
|
103
|
+
this.segmentIdsByAtomId.delete(unit.atomId);
|
|
104
|
+
}
|
|
105
|
+
unit.segmentIds.forEach((segmentId) => {
|
|
106
|
+
this.segments.delete(segmentId);
|
|
107
|
+
});
|
|
108
|
+
this.units.delete(unitId);
|
|
109
|
+
});
|
|
110
|
+
this.unitIdsByDocumentId.delete(String(documentId || '').trim());
|
|
111
|
+
}
|
|
112
|
+
listSegmentsForAtom(atomId) {
|
|
113
|
+
const segmentIds = this.segmentIdsByAtomId.get(String(atomId || '').trim()) || [];
|
|
114
|
+
return segmentIds
|
|
115
|
+
.map((segmentId) => this.segments.get(segmentId))
|
|
116
|
+
.filter((segment) => Boolean(segment));
|
|
117
|
+
}
|
|
118
|
+
listUnitsByProjectionIds(projectionIds) {
|
|
119
|
+
const allowedProjectionIds = new Set(projectionIds
|
|
120
|
+
.map((projectionId) => String(projectionId || '').trim())
|
|
121
|
+
.filter(Boolean));
|
|
122
|
+
if (allowedProjectionIds.size <= 0) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
return Array.from(this.units.values())
|
|
126
|
+
.filter((unit) => allowedProjectionIds.has(unit.projectionId))
|
|
127
|
+
.sort((left, right) => left.unitId.localeCompare(right.unitId));
|
|
128
|
+
}
|
|
129
|
+
listSegmentsByUnitIds(unitIds) {
|
|
130
|
+
const allowedUnitIds = new Set(unitIds
|
|
131
|
+
.map((unitId) => String(unitId || '').trim())
|
|
132
|
+
.filter(Boolean));
|
|
133
|
+
if (allowedUnitIds.size <= 0) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
return Array.from(this.segments.values())
|
|
137
|
+
.filter((segment) => allowedUnitIds.has(segment.unitId))
|
|
138
|
+
.sort((left, right) => left.segmentId.localeCompare(right.segmentId));
|
|
139
|
+
}
|
|
140
|
+
hasIndexedSegmentsForAtom(atomId) {
|
|
141
|
+
return this.listSegmentsForAtom(atomId).some((segment) => segment.state === 'indexed');
|
|
142
|
+
}
|
|
143
|
+
buildSummary() {
|
|
144
|
+
const states = {
|
|
145
|
+
pending: 0,
|
|
146
|
+
indexing: 0,
|
|
147
|
+
indexed: 0,
|
|
148
|
+
failed: 0,
|
|
149
|
+
disabled: 0,
|
|
150
|
+
};
|
|
151
|
+
this.units.forEach((unit) => {
|
|
152
|
+
states[unit.state] += 1;
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
totalUnits: this.units.size,
|
|
156
|
+
totalSegments: this.segments.size,
|
|
157
|
+
states,
|
|
158
|
+
activeDocuments: this.unitIdsByDocumentId.size,
|
|
159
|
+
activeAtomUnits: Array.from(this.units.values()).filter((unit) => unit.atomId !== null).length,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
buildSnapshot() {
|
|
163
|
+
return {
|
|
164
|
+
units: Array.from(this.units.values()).map((unit) => ({
|
|
165
|
+
...unit,
|
|
166
|
+
segmentIds: [...unit.segmentIds],
|
|
167
|
+
})),
|
|
168
|
+
segments: Array.from(this.segments.values()).map((segment) => ({ ...segment })),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
restoreFromSnapshot(snapshot) {
|
|
172
|
+
this.units.clear();
|
|
173
|
+
this.segments.clear();
|
|
174
|
+
this.unitIdsByDocumentId.clear();
|
|
175
|
+
this.segmentIdsByAtomId.clear();
|
|
176
|
+
(snapshot?.segments || []).forEach((segment) => {
|
|
177
|
+
this.segments.set(segment.segmentId, { ...segment });
|
|
178
|
+
});
|
|
179
|
+
(snapshot?.units || []).forEach((unit) => {
|
|
180
|
+
this.units.set(unit.unitId, {
|
|
181
|
+
...unit,
|
|
182
|
+
segmentIds: [...unit.segmentIds],
|
|
183
|
+
});
|
|
184
|
+
if (unit.documentId) {
|
|
185
|
+
const existingUnitIds = this.unitIdsByDocumentId.get(unit.documentId) || [];
|
|
186
|
+
existingUnitIds.push(unit.unitId);
|
|
187
|
+
this.unitIdsByDocumentId.set(unit.documentId, existingUnitIds);
|
|
188
|
+
}
|
|
189
|
+
if (unit.atomId) {
|
|
190
|
+
this.segmentIdsByAtomId.set(unit.atomId, [...unit.segmentIds]);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.IndexLifecycle = IndexLifecycle;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const IndexLifecycle_1 = require("./IndexLifecycle");
|
|
4
|
+
describe('IndexLifecycle', () => {
|
|
5
|
+
test('indexes document and atom units, then retires them by document', () => {
|
|
6
|
+
let idCounter = 0;
|
|
7
|
+
const lifecycle = new IndexLifecycle_1.IndexLifecycle((prefix = 'index') => `${prefix}_${++idCounter}`, (value) => `hash_${value.length}`);
|
|
8
|
+
const atom = {
|
|
9
|
+
id: 'atom_1',
|
|
10
|
+
stableKey: 'doc_a::intro',
|
|
11
|
+
documentId: 'doc_a',
|
|
12
|
+
sourcePath: 'Knowledge_Base/optics/doc_a.md',
|
|
13
|
+
title: 'Intro',
|
|
14
|
+
content: 'Absorption affects transmitted intensity.',
|
|
15
|
+
representationType: 'text',
|
|
16
|
+
keywords: ['absorption', 'intensity'],
|
|
17
|
+
evidenceSpanIds: ['evidence_1'],
|
|
18
|
+
createdAt: '2026-05-26T00:00:00.000Z',
|
|
19
|
+
updatedAt: '2026-05-26T00:00:00.000Z',
|
|
20
|
+
metadata: {
|
|
21
|
+
sectionPath: ['Intro'],
|
|
22
|
+
version: 1,
|
|
23
|
+
sourceHash: 'hash_doc_a',
|
|
24
|
+
language: 'en',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const indexed = lifecycle.syncDocumentIndex({
|
|
28
|
+
resourceId: 'resource_1',
|
|
29
|
+
projectionId: 'projection_1',
|
|
30
|
+
documentId: 'doc_a',
|
|
31
|
+
sourcePath: 'Knowledge_Base/optics/doc_a.md',
|
|
32
|
+
language: 'en',
|
|
33
|
+
workspaceId: 'optics',
|
|
34
|
+
corpusId: 'optics',
|
|
35
|
+
title: 'doc_a',
|
|
36
|
+
content: '# Intro\nAbsorption affects transmitted intensity.',
|
|
37
|
+
atoms: [atom],
|
|
38
|
+
indexedAt: '2026-05-26T00:00:00.000Z',
|
|
39
|
+
});
|
|
40
|
+
expect(indexed.units.length).toBeGreaterThan(0);
|
|
41
|
+
expect(indexed.segments.length).toBeGreaterThan(0);
|
|
42
|
+
expect(lifecycle.hasIndexedSegmentsForAtom('atom_1')).toBe(true);
|
|
43
|
+
expect(lifecycle.listUnitsByProjectionIds(['projection_1']).length).toBe(indexed.units.length);
|
|
44
|
+
expect(lifecycle.listSegmentsByUnitIds(indexed.units.map((unit) => unit.unitId)).length).toBe(indexed.segments.length);
|
|
45
|
+
lifecycle.retireDocumentIndex('doc_a');
|
|
46
|
+
expect(lifecycle.hasIndexedSegmentsForAtom('atom_1')).toBe(false);
|
|
47
|
+
expect(lifecycle.buildSummary().totalUnits).toBe(0);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SegmentBuilder = void 0;
|
|
4
|
+
class SegmentBuilder {
|
|
5
|
+
constructor(computeHash) {
|
|
6
|
+
this.computeHash = computeHash;
|
|
7
|
+
}
|
|
8
|
+
buildSegments(content, options = {}) {
|
|
9
|
+
const normalizedContent = String(content || '').trim();
|
|
10
|
+
if (!normalizedContent) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const maxSegmentChars = Math.max(120, Math.floor(Number(options.maxSegmentChars) || 420));
|
|
14
|
+
const paragraphs = normalizedContent
|
|
15
|
+
.split(/\n{2,}/)
|
|
16
|
+
.map((paragraph) => paragraph.trim())
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
const segments = [];
|
|
19
|
+
let current = '';
|
|
20
|
+
const flush = () => {
|
|
21
|
+
const value = current.trim();
|
|
22
|
+
if (!value) {
|
|
23
|
+
current = '';
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
segments.push({
|
|
27
|
+
content: value,
|
|
28
|
+
segmentIndex: segments.length,
|
|
29
|
+
tokenCount: value.split(/\s+/).filter(Boolean).length,
|
|
30
|
+
contentHash: this.computeHash(value),
|
|
31
|
+
});
|
|
32
|
+
current = '';
|
|
33
|
+
};
|
|
34
|
+
paragraphs.forEach((paragraph) => {
|
|
35
|
+
const candidate = current ? `${current}\n\n${paragraph}` : paragraph;
|
|
36
|
+
if (candidate.length > maxSegmentChars && current) {
|
|
37
|
+
flush();
|
|
38
|
+
}
|
|
39
|
+
if (paragraph.length > maxSegmentChars) {
|
|
40
|
+
const tokens = paragraph.split(/\s+/).filter(Boolean);
|
|
41
|
+
let buffer = '';
|
|
42
|
+
tokens.forEach((token) => {
|
|
43
|
+
const tokenCandidate = buffer ? `${buffer} ${token}` : token;
|
|
44
|
+
if (tokenCandidate.length > maxSegmentChars && buffer) {
|
|
45
|
+
current = buffer;
|
|
46
|
+
flush();
|
|
47
|
+
buffer = token;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
buffer = tokenCandidate;
|
|
51
|
+
});
|
|
52
|
+
if (buffer) {
|
|
53
|
+
current = buffer;
|
|
54
|
+
flush();
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
current = current ? `${current}\n\n${paragraph}` : paragraph;
|
|
59
|
+
});
|
|
60
|
+
flush();
|
|
61
|
+
return segments;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.SegmentBuilder = SegmentBuilder;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnitBuilder = void 0;
|
|
4
|
+
class UnitBuilder {
|
|
5
|
+
constructor(computeHash) {
|
|
6
|
+
this.computeHash = computeHash;
|
|
7
|
+
}
|
|
8
|
+
buildDocumentAndAtomUnits(document, atoms) {
|
|
9
|
+
const units = [];
|
|
10
|
+
const normalizedDocumentContent = String(document.content || '').trim();
|
|
11
|
+
if (normalizedDocumentContent) {
|
|
12
|
+
units.push({
|
|
13
|
+
documentId: document.documentId,
|
|
14
|
+
atomId: null,
|
|
15
|
+
sourcePath: document.sourcePath,
|
|
16
|
+
language: document.language,
|
|
17
|
+
workspaceId: document.workspaceId,
|
|
18
|
+
corpusId: document.corpusId,
|
|
19
|
+
title: document.title,
|
|
20
|
+
content: normalizedDocumentContent,
|
|
21
|
+
unitKind: 'knowledge_document',
|
|
22
|
+
unitIndex: 0,
|
|
23
|
+
contentHash: this.computeHash(normalizedDocumentContent),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
atoms.forEach((atom, index) => {
|
|
27
|
+
const normalizedContent = String(atom.content || '').trim();
|
|
28
|
+
if (!normalizedContent) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
units.push({
|
|
32
|
+
documentId: atom.documentId,
|
|
33
|
+
atomId: atom.id,
|
|
34
|
+
sourcePath: atom.sourcePath,
|
|
35
|
+
language: String(atom.metadata?.language || document.language || 'unknown').trim() || 'unknown',
|
|
36
|
+
workspaceId: document.workspaceId,
|
|
37
|
+
corpusId: document.corpusId,
|
|
38
|
+
title: atom.title,
|
|
39
|
+
content: normalizedContent,
|
|
40
|
+
unitKind: 'knowledge_atom',
|
|
41
|
+
unitIndex: index + 1,
|
|
42
|
+
contentHash: this.computeHash(normalizedContent),
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return units;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.UnitBuilder = UnitBuilder;
|