@xopcai/xopc 0.0.283 → 0.0.284
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-iPtG94qr.js → activity-store-CwbIMGLY.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DQ74xqLi.js → agent-avatar-dicebear-DjiOld-S.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-defaults-settings-panel-SElFkQd6.js → agent-defaults-settings-panel-D9qP10BK.js} +1 -1
- package/dist/gateway/static/root/assets/{agents-DYazUaZ6.js → agents-D-bkOuAl.js} +1 -1
- package/dist/gateway/static/root/assets/{api-KMJzMqvZ.js → api-3lphBVuY.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-B42TpqIb.js → app-management-settings-panel-B2nwCXxE.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-D9Lfe7Sk.js → appearance-settings-BXO4Ej88.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-BzrodN8C.js → apps-page-BKwBBwJN.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-BdmQwj4x.js → archive-plugin-6ZRqNjla.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-B4S0_nji.js → attachment-load-CmPZalcW.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-B3TmHNjQ.js → automations-page-Bc3WbK5n.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-workspace--A4I0jMu.js → automations-workspace-B2-f9qZu.js} +1 -1
- package/dist/gateway/static/root/assets/{binary-plugins-B3cXF_DP.js → binary-plugins-OWR6cxpc.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-05zyBXBe.js → block-editor-Ca-tDQXm.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automation-inputs-BTIufVbM.js → browser-automation-inputs-Dxy2_p3U.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-DRBA9nwe.js → browser-automations-page-CibQIxpi.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-DDTXUNWK.js → browser-settings-page-Dtn4rMeq.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-Ll5UeXq5.js → capabilities-settings-panel-DiwtR9MD.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-BzL15bkU.js → channels-settings-pTdR1q1K.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-status-swr-DMYQNs-J.js → channels-status-swr-Bh-G9mdZ.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-Dx5KQyo5.js → chat-terminal-dock-lbzbSpV3.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-RPw1AOMb.js → connectors-page-BSQ7Hs2w.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-CkDROZoe.js → date-picker-tYvbTfZT.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-Bl8HcvzL.js → dependency-picker-B8yo7-7V.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-BcknAjbW.js → desktop-pet-BUGkGB4-.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-BuCpXQPm.js → desktop-pet-settings-DNeVGZNp.js} +1 -1
- package/dist/gateway/static/root/assets/{device-pairing-wizard-D0_tCX49.js → device-pairing-wizard-CYkT7ecp.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-qRpb2FFa.js → extension-debug-page-CiK0QI2p.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-C7gs9wu4.js → extension-page-CirPNHJd.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-CyJP1CMZ.js → extension-settings-page-Baua1_Le.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-Cpmyrr6j.js → gateway-config-swr-Co4hHe0i.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-DOeeTdWE.js → gateway-settings-CzpSYWex.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-DoiPeb65.js → gateway-startup-retry-DBPNJG-e.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-CV6Dolcn.js → heartbeat-settings-DTM_kYpE.js} +1 -1
- package/dist/gateway/static/root/assets/{home-page-Djw1H_Go.js → home-page-CSSJvdd6.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-CqjHWl2T.js → image-generation-api-D0rMTumD.js} +1 -1
- package/dist/gateway/static/root/assets/imports-page-XqVVYbAp.js +1 -0
- package/dist/gateway/static/root/assets/{index-CHgOG1aR.js → index-C9aQA4Dr.js} +9 -9
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-B3XqA41D.js → keyboard-shortcuts-settings-CMUaF61L.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-BPqgyYJq.js → local-app-workbench-page-CZSgTYuI.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-BcIVYp0J.js → local-apps-page-CHxyT09t.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-1urrBBCQ.js → locale-store-DO6JJ1l2.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-BHax3XlS.js → logs-page-z5ktnEzX.js} +1 -1
- package/dist/gateway/static/root/assets/{management-settings-DNFCdgzR.js → management-settings-jXbA2S54.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-BZmcFIWa.js → markdown-view-CKInRsDh.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-BDxNhoBC.js → media-plugins-BaPkSvW7.js} +1 -1
- package/dist/gateway/static/root/assets/messages-BgZRsCkG.js +3 -0
- package/dist/gateway/static/root/assets/{note-detail-panel-Cs46LFXO.js → note-detail-panel-DSaZfkna.js} +3 -3
- package/dist/gateway/static/root/assets/{notes-page-BUkcn_0t.js → notes-page-CePEyv_C.js} +1 -1
- package/dist/gateway/static/root/assets/{page-tabs-agH3a2PI.js → page-tabs-CdYemUOu.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-XEZ7zDOP.js → preview-open-alternatives-DzgF1yYO.js} +1 -1
- package/dist/gateway/static/root/assets/{proactive-page-Bn484J9v.js → proactive-page-Cy2Gm2f8.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-lXAbj85Z.js → product-open-page-iQ-eW6Aj.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-LcH21ixD.js → project-detail-page-BliwYpns.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-DelBiwyB.js → projects-page-Dm-BqnQn.js} +1 -1
- package/dist/gateway/static/root/assets/{registry-api-CxQstD00.js → registry-api-DMNudT60.js} +1 -1
- package/dist/gateway/static/root/assets/{remote-access-hub-3BjFYXCf.js → remote-access-hub-C_XuQ9XR.js} +1 -1
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-DErKZlVJ.js → runtime-tools-settings-panel-u_wVepf7.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-DhCmJQVJ.js → schema-form-YdZj2xdI.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-CVFirgVd.js → sessions-page-Drt1aS2G.js} +1 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BAUd06_9.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-Dg6chotg.js → settings-form-section-Bw6xKOX5.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-LyuN5N3M.js → settings-page-CV8kVdnE.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-CrXhTzHr.js → setup-status-panel-BHI9e5Tw.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-CZvmf4Ob.js → share-preview-page-BHwjHlrV.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-DyM_D8hM.js → shares-settings-DOAOjZBQ.js} +1 -1
- package/dist/gateway/static/root/assets/skill-reload-api-DU0VQpHj.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-DRKdb6O5.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page.utils-Eu0WVHTS.js → skills-page.utils-DYfaLtts.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-DQKkM7B2.js → system-settings-panel-CWrWpKV-.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-B18NcZQJ.js → task-detail-page-DiPgMmBM.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-Dc5s20V3.js → theme-store-CDc7Wqy5.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-TKQpPVd6.js → tunnel-api-Bmsy-5Fs.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-CkVlrFk1.js → use-autosave-D-FRib85.js} +1 -1
- package/dist/gateway/static/root/assets/{user-model-page-ul-zr58b.js → user-model-page-DxRaRdA0.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-B12fFN-L.js → voice-api-key-field-iQ7EBzII.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-Mk78BrpP.js → voice-config-api-DNMWA2tx.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-CT9Zy36i.js → work-discovery-overlay-BesuhDlH.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-BwefQliE.js → workflow-run-setup-panel-Du81FoCy.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-BY_AWs7S.js → workflows-page-CZikdgNw.js} +1 -1
- package/dist/gateway/static/root/index.html +9 -9
- package/dist/package.js +1 -1
- package/dist/src/cli/command-loaders.js +1 -0
- package/dist/src/cli/command-manifest.js +4 -0
- package/dist/src/cli/commands/agent.js +2 -2
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
- package/dist/src/cli/commands/import.d.ts +2 -0
- package/dist/src/cli/commands/import.js +30 -0
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/commands/onboard.js +1 -1
- package/dist/src/cli/commands/platform.js +1 -1
- package/dist/src/cli/commands/profile.js +1 -1
- package/dist/src/cli/commands/tunnel.js +1 -1
- package/dist/src/cli/commands/update.js +1 -1
- package/dist/src/cli/extension-cli-register.js +1 -1
- package/dist/src/config/index.js +1 -1
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/gateway/hono/routes/imports.d.ts +3 -0
- package/dist/src/gateway/hono/routes/imports.js +44 -0
- package/dist/src/gateway/hono/routes/lazy-bundles.js +8 -0
- package/dist/src/gateway/run-loop.js +1 -1
- package/dist/src/gateway/service.js +2 -0
- package/dist/src/heartbeat/index.js +1 -1
- package/dist/src/imports/compatibility.d.ts +7 -0
- package/dist/src/imports/compatibility.js +174 -0
- package/dist/src/imports/contextImport.d.ts +3 -0
- package/dist/src/imports/contextImport.js +56 -0
- package/dist/src/imports/files.d.ts +13 -0
- package/dist/src/imports/files.js +77 -0
- package/dist/src/imports/importService.d.ts +45 -0
- package/dist/src/imports/importService.js +417 -0
- package/dist/src/imports/planner.d.ts +11 -0
- package/dist/src/imports/planner.js +98 -0
- package/dist/src/imports/productImport.d.ts +10 -0
- package/dist/src/imports/productImport.js +148 -0
- package/dist/src/imports/runtime.d.ts +5 -0
- package/dist/src/imports/runtime.js +56 -0
- package/dist/src/imports/scanner.d.ts +14 -0
- package/dist/src/imports/scanner.js +159 -0
- package/dist/src/imports/secrets.d.ts +2 -0
- package/dist/src/imports/secrets.js +9 -0
- package/dist/src/imports/sources.d.ts +37 -0
- package/dist/src/imports/sources.js +75 -0
- package/dist/src/imports/types.d.ts +91 -0
- package/dist/src/imports/types.js +11 -0
- package/dist/src/knowledge-memory/repository.js +4 -2
- package/dist/src/storage/sqlite/import-repository.d.ts +19 -0
- package/dist/src/storage/sqlite/import-repository.js +35 -0
- package/dist/src/storage/sqlite/migrations/174_capability_imports.sql +11 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/package.json +4 -3
- package/dist/gateway/static/root/assets/messages-DYFcjtmG.js +0 -3
- package/dist/gateway/static/root/assets/settings-advanced-gate-DyfBpqkY.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-Bys58-15.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-sWNvFo6D.js +0 -2
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { resolveStateDir } from "../config/paths-state.js";
|
|
2
|
+
import { init_paths } from "../config/paths.js";
|
|
3
|
+
import { ProjectService } from "../projects/project-service.js";
|
|
4
|
+
import { ImportError } from "./types.js";
|
|
5
|
+
import { importContextDocument } from "./contextImport.js";
|
|
6
|
+
import { ImportRepository } from "../storage/sqlite/import-repository.js";
|
|
7
|
+
import { detectImportSources } from "./sources.js";
|
|
8
|
+
import { resolveImportTarget } from "./runtime.js";
|
|
9
|
+
import { isAbsolute, join, parse } from "node:path";
|
|
10
|
+
import { mkdirSync, realpathSync, statSync } from "node:fs";
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
12
|
+
import lockfile from "proper-lockfile";
|
|
13
|
+
//#region src/imports/productImport.ts
|
|
14
|
+
init_paths();
|
|
15
|
+
function listImportSources(owner) {
|
|
16
|
+
const runs = new ImportRepository(owner).latestRuns();
|
|
17
|
+
return detectImportSources().map((source) => ({
|
|
18
|
+
...source,
|
|
19
|
+
lastImport: runs.find((r) => r.source === source.id)
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
/** One product action. Destination services retain their existing scope and trust policies. */
|
|
23
|
+
async function importProduct(service, source, requestId = randomUUID(), owner = "gateway-owner") {
|
|
24
|
+
const root = join(resolveStateDir(), "imports", "product-import");
|
|
25
|
+
mkdirSync(root, {
|
|
26
|
+
recursive: true,
|
|
27
|
+
mode: 448
|
|
28
|
+
});
|
|
29
|
+
const release = await lockfile.lock(root, {
|
|
30
|
+
realpath: false,
|
|
31
|
+
retries: {
|
|
32
|
+
retries: 10,
|
|
33
|
+
minTimeout: 100,
|
|
34
|
+
maxTimeout: 500
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const repo = new ImportRepository(owner);
|
|
38
|
+
try {
|
|
39
|
+
try {
|
|
40
|
+
const previous = repo.get("run", requestId);
|
|
41
|
+
if (previous.source !== source) throw new ImportError("conflict", "Request belongs to another product", 409);
|
|
42
|
+
return previous;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (!(error instanceof ImportError) || error.code !== "not_found") throw error;
|
|
45
|
+
}
|
|
46
|
+
if (!detectImportSources().some((s) => s.id === source && s.detected)) throw new ImportError("source_not_found", "This app is no longer available on the xopc device", 404);
|
|
47
|
+
const result = {
|
|
48
|
+
id: requestId,
|
|
49
|
+
source,
|
|
50
|
+
createdAt: Date.now(),
|
|
51
|
+
skills: 0,
|
|
52
|
+
context: 0,
|
|
53
|
+
projects: 0,
|
|
54
|
+
skipped: 0,
|
|
55
|
+
issues: []
|
|
56
|
+
};
|
|
57
|
+
const budget = {
|
|
58
|
+
bytes: 0,
|
|
59
|
+
files: 0
|
|
60
|
+
};
|
|
61
|
+
const scan = service.scan({
|
|
62
|
+
source,
|
|
63
|
+
budget
|
|
64
|
+
});
|
|
65
|
+
const saveContext = (items, projectId) => {
|
|
66
|
+
for (const item of items.filter((c) => c.kind === "rule" && c.scope === (projectId ? "project" : "user"))) {
|
|
67
|
+
if (!item.content || item.compatibility !== "compatible") {
|
|
68
|
+
result.issues.push({
|
|
69
|
+
name: item.name,
|
|
70
|
+
reason: item.findings.join("; ")
|
|
71
|
+
});
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const status = importContextDocument(item, projectId);
|
|
76
|
+
if (status === "created") result.context++;
|
|
77
|
+
else if (status === "unchanged") result.skipped++;
|
|
78
|
+
else result.issues.push({
|
|
79
|
+
name: item.name,
|
|
80
|
+
reason: "Existing context was kept. The source document has changed."
|
|
81
|
+
});
|
|
82
|
+
} catch {
|
|
83
|
+
result.issues.push({
|
|
84
|
+
name: item.name,
|
|
85
|
+
reason: "Unable to save this context document. Try again."
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const importScope = async (scopeScan, projectId) => {
|
|
91
|
+
const scoped = {
|
|
92
|
+
...scopeScan,
|
|
93
|
+
candidates: scopeScan.candidates.filter((c) => c.scope === (projectId ? "project" : "user"))
|
|
94
|
+
};
|
|
95
|
+
result.issues.push(...scopeScan.diagnostics.map((reason) => ({
|
|
96
|
+
name: source,
|
|
97
|
+
reason
|
|
98
|
+
})));
|
|
99
|
+
saveContext(scoped.candidates, projectId);
|
|
100
|
+
for (const item of scoped.candidates.filter((c) => c.kind === "mcp")) result.issues.push({
|
|
101
|
+
name: item.name,
|
|
102
|
+
reason: "Reconnect this tool in Connections; credentials and executable settings are not transferred."
|
|
103
|
+
});
|
|
104
|
+
try {
|
|
105
|
+
const skills = await service.importSkills(scoped, resolveImportTarget(projectId));
|
|
106
|
+
result.skills += skills.imported;
|
|
107
|
+
result.skipped += skills.skipped;
|
|
108
|
+
result.issues.push(...skills.issues);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
result.issues.push({
|
|
111
|
+
name: projectId ? "Project skills" : "Skills",
|
|
112
|
+
reason: error instanceof ImportError ? error.message : "Unable to import skills. Try again."
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
await importScope(scan);
|
|
117
|
+
const projects = new ProjectService();
|
|
118
|
+
const seen = /* @__PURE__ */ new Set();
|
|
119
|
+
for (const path of scan.projectRoots ?? []) try {
|
|
120
|
+
if (!isAbsolute(path) || parse(path).root === path || !statSync(path).isDirectory()) throw new Error("Invalid project");
|
|
121
|
+
const workspaceRoot = realpathSync(path);
|
|
122
|
+
if (seen.has(workspaceRoot)) continue;
|
|
123
|
+
seen.add(workspaceRoot);
|
|
124
|
+
let project = projects.findByWorkspaceRoot(workspaceRoot);
|
|
125
|
+
if (!project) {
|
|
126
|
+
project = projects.create({ workspaceRoot });
|
|
127
|
+
result.projects++;
|
|
128
|
+
} else result.skipped++;
|
|
129
|
+
await importScope(service.scan({
|
|
130
|
+
source,
|
|
131
|
+
projectRoot: workspaceRoot,
|
|
132
|
+
projectOnly: true,
|
|
133
|
+
budget
|
|
134
|
+
}), project.id);
|
|
135
|
+
} catch {
|
|
136
|
+
result.issues.push({
|
|
137
|
+
name: path,
|
|
138
|
+
reason: "Project unavailable; existing content was kept."
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
repo.save("run", result);
|
|
142
|
+
return result;
|
|
143
|
+
} finally {
|
|
144
|
+
await release();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
export { importProduct, listImportSources };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ImportService } from './importService.js';
|
|
2
|
+
import { type ImportTarget } from './types.js';
|
|
3
|
+
export declare function resolveImportTarget(projectId?: string): ImportTarget;
|
|
4
|
+
export declare function createRuntimeImportService(owner: string, refreshSkills?: () => void | Promise<void>, checkTrust?: (root: string) => boolean): ImportService;
|
|
5
|
+
export declare function recoverCapabilityImports(): Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { resolveStateDir } from "../config/paths-state.js";
|
|
2
|
+
import { init_paths, resolveBundledSkillsDir, resolveSkillsDir } from "../config/paths.js";
|
|
3
|
+
import { ProjectService } from "../projects/project-service.js";
|
|
4
|
+
import { resolveWorkspaceSkillsDir } from "../agent/skills/workspace-skills-dir.js";
|
|
5
|
+
import { loadSkills } from "../agent/skills/index.js";
|
|
6
|
+
import { ProjectTrustStore } from "../project-trust/trust-store.js";
|
|
7
|
+
import { ImportError } from "./types.js";
|
|
8
|
+
import { ImportRepository } from "../storage/sqlite/import-repository.js";
|
|
9
|
+
import { canonicalTarget } from "./planner.js";
|
|
10
|
+
import { ImportService } from "./importService.js";
|
|
11
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
12
|
+
//#region src/imports/runtime.ts
|
|
13
|
+
init_paths();
|
|
14
|
+
function resolveImportTarget(projectId) {
|
|
15
|
+
if (!projectId) return { root: canonicalTarget(resolveSkillsDir()) };
|
|
16
|
+
const project = new ProjectService().get(projectId);
|
|
17
|
+
if (!project?.workspaceRoot || !existsSync(project.workspaceRoot)) throw new ImportError("invalid_project", "Project needs an existing workspace");
|
|
18
|
+
return {
|
|
19
|
+
projectId,
|
|
20
|
+
root: canonicalTarget(resolveWorkspaceSkillsDir(project.workspaceRoot))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function createRuntimeImportService(owner, refreshSkills, checkTrust) {
|
|
24
|
+
return new ImportService({
|
|
25
|
+
owner,
|
|
26
|
+
stateDir: resolveStateDir(),
|
|
27
|
+
refreshSkills,
|
|
28
|
+
isConnected(candidate) {
|
|
29
|
+
if (!candidate.shared) return false;
|
|
30
|
+
const workspaceDir = (candidate.scope === "project" ? new ProjectService().resolveForWorkspacePath(candidate.location)?.project : void 0)?.workspaceRoot;
|
|
31
|
+
return loadSkills({
|
|
32
|
+
workspaceDir,
|
|
33
|
+
workspaceTrust: workspaceDir && (checkTrust ? checkTrust(workspaceDir) : new ProjectTrustStore().get(workspaceDir) === true) ? "trusted" : "untrusted"
|
|
34
|
+
}).skills.some((s) => realpathSync(s.baseDir) === candidate.location);
|
|
35
|
+
},
|
|
36
|
+
validateTarget(target) {
|
|
37
|
+
if (resolveImportTarget(target.projectId).root !== target.root) throw new ImportError("scope_mismatch", "Project target changed; preview again", 409);
|
|
38
|
+
if (target.projectId) {
|
|
39
|
+
const project = new ProjectService().get(target.projectId);
|
|
40
|
+
if (!(checkTrust ? checkTrust(project.workspaceRoot) : new ProjectTrustStore().get(project.workspaceRoot) === true)) throw new ImportError("workspace_untrusted", "Trust this project in project settings before importing", 403);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
reservedNames(target) {
|
|
44
|
+
return loadSkills({
|
|
45
|
+
workspaceDir: target.projectId ? new ProjectService().get(target.projectId)?.workspaceRoot : void 0,
|
|
46
|
+
workspaceTrust: "trusted",
|
|
47
|
+
builtinDir: resolveBundledSkillsDir() ?? void 0
|
|
48
|
+
}).skills.map((s) => s.name);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function recoverCapabilityImports() {
|
|
53
|
+
for (const owner of ImportRepository.owners()) await createRuntimeImportService(owner).recoverAndClean();
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { createRuntimeImportService, recoverCapabilityImports, resolveImportTarget };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ImportScan, type ImportSource } from './types.js';
|
|
2
|
+
export { IMPORT_SOURCES } from './sources.js';
|
|
3
|
+
export interface ScanInput {
|
|
4
|
+
source: ImportSource;
|
|
5
|
+
root?: string;
|
|
6
|
+
projectRoot?: string;
|
|
7
|
+
home?: string;
|
|
8
|
+
projectOnly?: boolean;
|
|
9
|
+
budget?: {
|
|
10
|
+
bytes: number;
|
|
11
|
+
files: number;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare function scanLocal(input: ScanInput): ImportScan;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { containsSecret } from "./secrets.js";
|
|
2
|
+
import { ImportError } from "./types.js";
|
|
3
|
+
import { IMPORT_LIMITS, digest, readRegularFile, readTree } from "./files.js";
|
|
4
|
+
import { inspectMcp, inspectSkill } from "./compatibility.js";
|
|
5
|
+
import { IMPORT_SOURCES, sourceLayout } from "./sources.js";
|
|
6
|
+
import { basename, join } from "node:path";
|
|
7
|
+
import { existsSync, readdirSync, realpathSync } from "node:fs";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { parse as parse$1 } from "smol-toml";
|
|
10
|
+
//#region src/imports/scanner.ts
|
|
11
|
+
function scanResult(source) {
|
|
12
|
+
if (!IMPORT_SOURCES.some((s) => s.id === source)) throw new ImportError("unsupported_source", "Unsupported source");
|
|
13
|
+
return {
|
|
14
|
+
id: randomUUID(),
|
|
15
|
+
createdAt: Date.now(),
|
|
16
|
+
source,
|
|
17
|
+
candidates: [],
|
|
18
|
+
diagnostics: []
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function base(source, scope, location, shared = false) {
|
|
22
|
+
return {
|
|
23
|
+
id: randomUUID(),
|
|
24
|
+
source,
|
|
25
|
+
scope,
|
|
26
|
+
location,
|
|
27
|
+
shared
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function appendMcp(scan, raw, scope, location) {
|
|
31
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
|
|
32
|
+
for (const [name, config] of Object.entries(raw)) scan.candidates.push(inspectMcp(base(scan.source, scope, location), name, config));
|
|
33
|
+
}
|
|
34
|
+
function scanLocal(input) {
|
|
35
|
+
const scan = scanResult(input.source);
|
|
36
|
+
const { home, root, layout } = sourceLayout(input.source, input.home, input.root);
|
|
37
|
+
const scopes = (input.projectOnly ? [] : layout.skills).map((s) => ({
|
|
38
|
+
path: join(s.base === "home" ? home : root, s.path),
|
|
39
|
+
scope: "user",
|
|
40
|
+
shared: s.shared
|
|
41
|
+
}));
|
|
42
|
+
if (input.projectRoot) scopes.push({
|
|
43
|
+
path: join(input.projectRoot, layout.projectSkills),
|
|
44
|
+
scope: "project",
|
|
45
|
+
shared: layout.skills.some((s) => s.shared)
|
|
46
|
+
});
|
|
47
|
+
const seen = /* @__PURE__ */ new Set();
|
|
48
|
+
const budget = input.budget ?? {
|
|
49
|
+
bytes: 0,
|
|
50
|
+
files: 0
|
|
51
|
+
};
|
|
52
|
+
const consume = (bytes, files) => {
|
|
53
|
+
budget.bytes += bytes;
|
|
54
|
+
budget.files += files;
|
|
55
|
+
if (budget.bytes > IMPORT_LIMITS.total || budget.files > IMPORT_LIMITS.count) throw new ImportError("limit_exceeded", "Import exceeds batch limits", 413);
|
|
56
|
+
};
|
|
57
|
+
for (const scope of scopes) {
|
|
58
|
+
if (!existsSync(scope.path)) continue;
|
|
59
|
+
let entries;
|
|
60
|
+
try {
|
|
61
|
+
entries = readdirSync(scope.path, { withFileTypes: true });
|
|
62
|
+
} catch {
|
|
63
|
+
scan.diagnostics.push("Unable to read skills directory");
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
68
|
+
const location = join(scope.path, entry.name);
|
|
69
|
+
if (!existsSync(join(location, "SKILL.md"))) continue;
|
|
70
|
+
try {
|
|
71
|
+
const real = realpathSync(location);
|
|
72
|
+
if (seen.has(real)) continue;
|
|
73
|
+
seen.add(real);
|
|
74
|
+
const files = readTree(location);
|
|
75
|
+
consume(files.reduce((n, f) => n + Buffer.byteLength(f.data, "base64"), 0), files.length);
|
|
76
|
+
scan.candidates.push(inspectSkill(base(input.source, scope.scope, real, scope.shared), files));
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof ImportError && error.code === "limit_exceeded") throw error;
|
|
79
|
+
scan.diagnostics.push(`${entry.name}: ${error instanceof ImportError ? error.message : "Unable to read skill"}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const configs = [{
|
|
84
|
+
path: join(root, layout.config.path),
|
|
85
|
+
scope: "user"
|
|
86
|
+
}];
|
|
87
|
+
if (input.projectRoot) configs.push({
|
|
88
|
+
path: join(input.projectRoot, layout.projectConfig),
|
|
89
|
+
scope: "project"
|
|
90
|
+
});
|
|
91
|
+
for (const config of configs) {
|
|
92
|
+
if (!existsSync(config.path)) continue;
|
|
93
|
+
try {
|
|
94
|
+
const text = readRegularFile(config.path, 1024 * 1024).toString("utf8");
|
|
95
|
+
const parsed = layout.config.format === "toml" ? parse$1(text) : JSON.parse(text);
|
|
96
|
+
if (!input.projectOnly || config.scope === "project") appendMcp(scan, parsed[layout.config.mcpKey], config.scope, config.path);
|
|
97
|
+
const projects = parsed.projects;
|
|
98
|
+
if (config.scope === "user" && projects && typeof projects === "object" && !Array.isArray(projects)) {
|
|
99
|
+
const paths = Object.keys(projects);
|
|
100
|
+
scan.projectRoots = paths.slice(0, 100);
|
|
101
|
+
if (paths.length > 100) scan.diagnostics.push("Only the first 100 projects were imported.");
|
|
102
|
+
if (input.projectRoot) {
|
|
103
|
+
const project = projects[input.projectRoot];
|
|
104
|
+
appendMcp(scan, project?.[layout.config.mcpKey], "project", config.path);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
scan.diagnostics.push(`${basename(config.path)}: invalid or unreadable configuration`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const addDocument = (path, scope) => {
|
|
112
|
+
if (!existsSync(path)) return;
|
|
113
|
+
try {
|
|
114
|
+
const content = readRegularFile(path, 128 * 1024).toString("utf8").trim();
|
|
115
|
+
if (!content) return;
|
|
116
|
+
consume(Buffer.byteLength(content), 1);
|
|
117
|
+
const blocked = containsSecret(content);
|
|
118
|
+
scan.candidates.push({
|
|
119
|
+
...base(input.source, scope, realpathSync(path)),
|
|
120
|
+
kind: "rule",
|
|
121
|
+
name: basename(path),
|
|
122
|
+
description: "",
|
|
123
|
+
hash: digest(content),
|
|
124
|
+
files: [],
|
|
125
|
+
compatibility: blocked ? "blocked" : "compatible",
|
|
126
|
+
findings: blocked ? ["Document contains probable credentials"] : [],
|
|
127
|
+
requiredEnv: [],
|
|
128
|
+
content: blocked ? void 0 : content
|
|
129
|
+
});
|
|
130
|
+
} catch {
|
|
131
|
+
scan.diagnostics.push(`${basename(path)}: unable to read context document`);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const addInstructions = (directory, groups, scope) => {
|
|
135
|
+
for (const names of groups) {
|
|
136
|
+
const path = names.map((name) => join(directory, name)).find(existsSync);
|
|
137
|
+
if (path) addDocument(path, scope);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const addRules = (directory, scope) => {
|
|
141
|
+
if (!existsSync(directory)) return;
|
|
142
|
+
try {
|
|
143
|
+
for (const entry of readdirSync(directory, { withFileTypes: true }).slice(0, 100)) if (entry.isFile() && entry.name.endsWith(".md")) addDocument(join(directory, entry.name), scope);
|
|
144
|
+
} catch {
|
|
145
|
+
scan.diagnostics.push("Unable to read rules directory");
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
if (!input.projectOnly) {
|
|
149
|
+
addInstructions(root, layout.instructions, "user");
|
|
150
|
+
if (layout.rules) addRules(join(root, layout.rules), "user");
|
|
151
|
+
}
|
|
152
|
+
if (input.projectRoot) {
|
|
153
|
+
addInstructions(input.projectRoot, layout.projectInstructions, "project");
|
|
154
|
+
if (layout.projectRules) addRules(join(input.projectRoot, layout.projectRules), "project");
|
|
155
|
+
}
|
|
156
|
+
return scan;
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
export { IMPORT_SOURCES, scanLocal };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/imports/secrets.ts
|
|
2
|
+
function containsSecret(text) {
|
|
3
|
+
return /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\b(?:sk-[a-zA-Z0-9_-]{20,}|gh[pousr]_[a-zA-Z0-9]{20,}|AKIA[A-Z0-9]{16})\b/i.test(text) || /(?:api[_-]?key|access[_-]?token|client[_-]?secret|password|authorization)\s*[=:]\s*["']?(?!\$|<|\{|process\.env|os\.environ)[a-zA-Z0-9_+/.-]{12,}/i.test(text);
|
|
4
|
+
}
|
|
5
|
+
function isCredentialPath(path) {
|
|
6
|
+
return /(^|\/)(\.env(?:\..*)?|auth\.json|credentials[^/]*|id_rsa|id_ed25519)$/i.test(path);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { containsSecret, isCredentialPath };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ImportSource } from './types.js';
|
|
2
|
+
interface SourceLayout {
|
|
3
|
+
id: ImportSource;
|
|
4
|
+
name: string;
|
|
5
|
+
directory: string;
|
|
6
|
+
environment: string;
|
|
7
|
+
skills: Array<{
|
|
8
|
+
base: 'home' | 'root';
|
|
9
|
+
path: string;
|
|
10
|
+
shared: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
projectSkills: string;
|
|
13
|
+
instructions: string[][];
|
|
14
|
+
projectInstructions: string[][];
|
|
15
|
+
rules?: string;
|
|
16
|
+
projectRules?: string;
|
|
17
|
+
config: {
|
|
18
|
+
path: string;
|
|
19
|
+
format: 'json' | 'toml';
|
|
20
|
+
mcpKey: string;
|
|
21
|
+
};
|
|
22
|
+
projectConfig: string;
|
|
23
|
+
}
|
|
24
|
+
/** Product differences live here; readers and destination writers are shared. */
|
|
25
|
+
export declare const IMPORT_SOURCES: readonly SourceLayout[];
|
|
26
|
+
export declare function sourceLayout(source: ImportSource, home?: string, root?: string): {
|
|
27
|
+
layout: SourceLayout;
|
|
28
|
+
home: string;
|
|
29
|
+
root: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function detectImportSources(): {
|
|
32
|
+
id: ImportSource;
|
|
33
|
+
name: string;
|
|
34
|
+
detected: boolean;
|
|
35
|
+
}[];
|
|
36
|
+
export declare function isImportSource(value: string): value is ImportSource;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ImportError } from "./types.js";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
//#region src/imports/sources.ts
|
|
6
|
+
/** Product differences live here; readers and destination writers are shared. */
|
|
7
|
+
const IMPORT_SOURCES = [{
|
|
8
|
+
id: "codex",
|
|
9
|
+
name: "Codex",
|
|
10
|
+
directory: ".codex",
|
|
11
|
+
environment: "CODEX_HOME",
|
|
12
|
+
skills: [{
|
|
13
|
+
base: "home",
|
|
14
|
+
path: ".agents/skills",
|
|
15
|
+
shared: true
|
|
16
|
+
}],
|
|
17
|
+
projectSkills: ".agents/skills",
|
|
18
|
+
instructions: [["AGENTS.override.md", "AGENTS.md"]],
|
|
19
|
+
projectInstructions: [["AGENTS.override.md", "AGENTS.md"]],
|
|
20
|
+
config: {
|
|
21
|
+
path: "config.toml",
|
|
22
|
+
format: "toml",
|
|
23
|
+
mcpKey: "mcp_servers"
|
|
24
|
+
},
|
|
25
|
+
projectConfig: ".codex/config.toml"
|
|
26
|
+
}, {
|
|
27
|
+
id: "claude-code",
|
|
28
|
+
name: "Claude Code",
|
|
29
|
+
directory: ".claude",
|
|
30
|
+
environment: "CLAUDE_CONFIG_DIR",
|
|
31
|
+
skills: [{
|
|
32
|
+
base: "root",
|
|
33
|
+
path: "skills",
|
|
34
|
+
shared: false
|
|
35
|
+
}],
|
|
36
|
+
projectSkills: ".claude/skills",
|
|
37
|
+
instructions: [["CLAUDE.md"]],
|
|
38
|
+
projectInstructions: [
|
|
39
|
+
["CLAUDE.md"],
|
|
40
|
+
[".claude/CLAUDE.md"],
|
|
41
|
+
["CLAUDE.local.md"]
|
|
42
|
+
],
|
|
43
|
+
rules: "rules",
|
|
44
|
+
projectRules: ".claude/rules",
|
|
45
|
+
config: {
|
|
46
|
+
path: "../.claude.json",
|
|
47
|
+
format: "json",
|
|
48
|
+
mcpKey: "mcpServers"
|
|
49
|
+
},
|
|
50
|
+
projectConfig: ".mcp.json"
|
|
51
|
+
}];
|
|
52
|
+
function sourceLayout(source, home, root) {
|
|
53
|
+
const layout = IMPORT_SOURCES.find((s) => s.id === source);
|
|
54
|
+
if (!layout) throw new ImportError("unsupported_source", "Unsupported source");
|
|
55
|
+
return {
|
|
56
|
+
layout,
|
|
57
|
+
home: home ?? homedir(),
|
|
58
|
+
root: root ?? (home ? void 0 : process.env[layout.environment]) ?? join(home ?? homedir(), layout.directory)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function detectImportSources() {
|
|
62
|
+
return IMPORT_SOURCES.map((s) => {
|
|
63
|
+
const { root } = sourceLayout(s.id);
|
|
64
|
+
return {
|
|
65
|
+
id: s.id,
|
|
66
|
+
name: s.name,
|
|
67
|
+
detected: existsSync(root) || existsSync(join(root, s.config.path))
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function isImportSource(value) {
|
|
72
|
+
return IMPORT_SOURCES.some((source) => source.id === value);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { IMPORT_SOURCES, detectImportSources, isImportSource, sourceLayout };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export type ImportSource = 'codex' | 'claude-code';
|
|
2
|
+
export type ImportScope = 'user' | 'project';
|
|
3
|
+
export type Compatibility = 'compatible' | 'needs_setup' | 'blocked' | 'unsupported';
|
|
4
|
+
export interface ImportFile {
|
|
5
|
+
path: string;
|
|
6
|
+
data: string;
|
|
7
|
+
executable: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ImportCandidate {
|
|
10
|
+
id: string;
|
|
11
|
+
source: ImportSource;
|
|
12
|
+
kind: 'skill' | 'mcp' | 'rule';
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
scope: ImportScope;
|
|
16
|
+
location: string;
|
|
17
|
+
hash: string;
|
|
18
|
+
compatibility: Compatibility;
|
|
19
|
+
findings: string[];
|
|
20
|
+
files: ImportFile[];
|
|
21
|
+
content?: string;
|
|
22
|
+
mcp?: Record<string, unknown>;
|
|
23
|
+
requiredEnv: string[];
|
|
24
|
+
shared: boolean;
|
|
25
|
+
connected?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface ImportScan {
|
|
28
|
+
id: string;
|
|
29
|
+
createdAt: number;
|
|
30
|
+
source: ImportSource;
|
|
31
|
+
candidates: ImportCandidate[];
|
|
32
|
+
diagnostics: string[];
|
|
33
|
+
projectRoots?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface ImportTarget {
|
|
36
|
+
projectId?: string;
|
|
37
|
+
root: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ImportAction {
|
|
40
|
+
candidateId: string;
|
|
41
|
+
operation: 'skip' | 'create' | 'rename' | 'replace';
|
|
42
|
+
name: string;
|
|
43
|
+
beforeHash: string | null;
|
|
44
|
+
}
|
|
45
|
+
export interface ImportPlan {
|
|
46
|
+
id: string;
|
|
47
|
+
scanId: string;
|
|
48
|
+
createdAt: number;
|
|
49
|
+
expiresAt: number;
|
|
50
|
+
target: ImportTarget;
|
|
51
|
+
targetRevision: string;
|
|
52
|
+
actions: ImportAction[];
|
|
53
|
+
}
|
|
54
|
+
export interface ImportJobItem {
|
|
55
|
+
action: ImportAction;
|
|
56
|
+
status: 'staged' | 'skipped' | 'publishing' | 'active' | 'rolling_back' | 'rolled_back' | 'failed';
|
|
57
|
+
error?: string;
|
|
58
|
+
afterHash?: string;
|
|
59
|
+
backupPath?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ImportJob {
|
|
62
|
+
id: string;
|
|
63
|
+
plan: ImportPlan;
|
|
64
|
+
createdAt: number;
|
|
65
|
+
expiresAt: number;
|
|
66
|
+
items: ImportJobItem[];
|
|
67
|
+
}
|
|
68
|
+
export declare class ImportError extends Error {
|
|
69
|
+
readonly code: string;
|
|
70
|
+
readonly status: 400 | 403 | 404 | 409 | 413;
|
|
71
|
+
constructor(code: string, message: string, status?: 400 | 403 | 404 | 409 | 413);
|
|
72
|
+
}
|
|
73
|
+
export interface ProductImportResult {
|
|
74
|
+
id: string;
|
|
75
|
+
source: ImportSource;
|
|
76
|
+
createdAt: number;
|
|
77
|
+
skills: number;
|
|
78
|
+
context: number;
|
|
79
|
+
projects: number;
|
|
80
|
+
skipped: number;
|
|
81
|
+
issues: Array<{
|
|
82
|
+
name: string;
|
|
83
|
+
reason: string;
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
export interface DetectedImportSource {
|
|
87
|
+
id: ImportSource;
|
|
88
|
+
name: string;
|
|
89
|
+
detected: boolean;
|
|
90
|
+
lastImport?: ProductImportResult;
|
|
91
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/imports/types.ts
|
|
2
|
+
var ImportError = class extends Error {
|
|
3
|
+
constructor(code, message, status = 400) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.name = "ImportError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { ImportError };
|
|
@@ -142,7 +142,9 @@ function searchKnowledgeItems(input) {
|
|
|
142
142
|
const visible = visibilityClause(input.context);
|
|
143
143
|
const sourceParts = [];
|
|
144
144
|
const sourceValues = [];
|
|
145
|
-
|
|
145
|
+
const importedSource = "COALESCE(json_extract(k.source_json, '$.kind'), '') = 'product_import'";
|
|
146
|
+
if (input.sources?.includes("connector")) sourceParts.push(`(k.record_class = 'source_index' AND NOT (${importedSource}))`);
|
|
147
|
+
if (input.sources?.includes("workspace")) sourceParts.push(`(k.record_class = 'source_index' AND ${importedSource})`);
|
|
146
148
|
const memoryScopes = input.sources?.filter((source) => source !== "connector") ?? [];
|
|
147
149
|
if (memoryScopes.length) {
|
|
148
150
|
sourceParts.push(`(k.record_class = 'memory' AND k.scope_type IN (${memoryScopes.map(() => "?").join(", ")}))`);
|
|
@@ -163,7 +165,7 @@ function searchKnowledgeItems(input) {
|
|
|
163
165
|
ORDER BY rank ASC, k.importance DESC, k.updated_at DESC LIMIT ?`).all(fts, principalId, asOf, asOf, asOf, ...input.recordClass ? [input.recordClass] : [], ...sourceValues, ...visible.values, limit).map(fromRow);
|
|
164
166
|
}
|
|
165
167
|
function knowledgeSourceAllowed(item, sources) {
|
|
166
|
-
if (item.recordClass === "source_index") return sources.includes("connector");
|
|
168
|
+
if (item.recordClass === "source_index") return sources.includes(item.source.kind === "product_import" ? "workspace" : "connector");
|
|
167
169
|
return item.scope.type === "session" ? sources.includes("session") : item.scope.type === "workspace" ? sources.includes("workspace") : item.scope.type === "project" ? sources.includes("project") : false;
|
|
168
170
|
}
|
|
169
171
|
//#endregion
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ImportJob, ImportPlan, ImportScan, ProductImportResult } from '../../imports/types.js';
|
|
2
|
+
type Records = {
|
|
3
|
+
scan: ImportScan;
|
|
4
|
+
plan: ImportPlan;
|
|
5
|
+
job: ImportJob;
|
|
6
|
+
run: ProductImportResult;
|
|
7
|
+
};
|
|
8
|
+
export declare class ImportRepository {
|
|
9
|
+
readonly owner: string;
|
|
10
|
+
constructor(owner: string);
|
|
11
|
+
get<K extends keyof Records>(kind: K, id: string): Records[K];
|
|
12
|
+
save<K extends keyof Records>(kind: K, value: Records[K], key?: string): void;
|
|
13
|
+
byKey(key: string): ImportJob | undefined;
|
|
14
|
+
latestRuns(): ProductImportResult[];
|
|
15
|
+
static owners(): string[];
|
|
16
|
+
scansBefore(time: number): ImportScan[];
|
|
17
|
+
jobs(limit?: number): ImportJob[];
|
|
18
|
+
}
|
|
19
|
+
export {};
|