@morozinc/opencode-tencentdb-plugin 0.0.0-stage → 0.1.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 +661 -0
- package/LICENSE-MIT +24 -0
- package/NOTICE.md +14 -0
- package/README.md +207 -2
- package/dist/gui-experimental.cjs +64 -0
- package/dist/integration.mjs +1986 -0
- package/docs/screenshots/code-indexes.png +0 -0
- package/package.json +61 -4
- package/scripts/prepare-runtime.mjs +298 -0
- package/src/binding.ts +33 -0
- package/src/bmad-artifact-preview.tsx +111 -0
- package/src/embedding-settings.tsx +191 -0
- package/src/gui.tsx +388 -0
- package/src/index.ts +484 -0
- package/src/integration.d.ts +75 -0
- package/src/rpc.ts +195 -0
- package/src/rule-document.ts +44 -0
- package/src/rules-contract.ts +77 -0
- package/src/rules.ts +237 -0
- package/src/runtime.ts +436 -0
- package/vendor/TENCENT-LICENSE +27 -0
- package/vendor/integration/native/config.ts +253 -0
- package/vendor/integration/native/embedding.ts +270 -0
- package/vendor/integration/native/index.ts +265 -0
- package/vendor/integration/project/index.ts +151 -0
- package/vendor/integration/project/knowledge.ts +283 -0
- package/vendor/integration/server.ts +154 -0
- package/vendor/integration/tencentChatRules.ts +84 -0
- package/vendor/integration/tencentGenerationContext.ts +4 -0
- package/vendor/integration/tencentKnowledgeClient.ts +512 -0
- package/vendor/integration/tencentMemoryClient.ts +391 -0
- package/vendor/integration/tencentUserQuestion.ts +51 -0
- package/vendor/locks/MemoryCore.json +4776 -0
- package/vendor/locks/MemoryKnowledge.json +3761 -0
- package/vendor/locks/MemoryPanel.json +467 -0
- package/vendor/locks/web.json +6418 -0
- package/vendor/provenance.json +21 -0
- package/vendor/runner.mjs +12 -0
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morozinc/opencode-tencentdb-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Independent TencentDB memory lifecycle, scoped tools and panel for OpenCode V2.",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"repository": "git+https://github.com/ShiftHackZ/opencode-tencentdb-plugin.git",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"opencode",
|
|
9
|
+
"opencode-plugin",
|
|
10
|
+
"tencentdb",
|
|
11
|
+
"memory"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"registry": "https://registry.npmjs.org/"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"bin": {
|
|
19
|
+
"opencode-tencentdb-prepare": "./scripts/prepare-runtime.mjs"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./src/index.ts",
|
|
23
|
+
"./gui-experimental": "./dist/gui-experimental.cjs",
|
|
24
|
+
"./rpc": "./src/rpc.ts"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"dist",
|
|
29
|
+
"vendor",
|
|
30
|
+
"scripts/prepare-runtime.mjs",
|
|
31
|
+
"docs/screenshots",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"LICENSE-MIT",
|
|
34
|
+
"NOTICE.md",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "node scripts/build.mjs && vite build",
|
|
39
|
+
"check": "tsc --noEmit",
|
|
40
|
+
"check:rules": "node --import tsx scripts/check-rules-contracts.ts",
|
|
41
|
+
"test": "node --import tsx --test tests/*.test.ts",
|
|
42
|
+
"prepare:runtime": "node scripts/prepare-runtime.mjs",
|
|
43
|
+
"prepack": "npm run check && npm run build"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@opencode/plugin": "2.4.3",
|
|
47
|
+
"@modelcontextprotocol/sdk": "1.29.0",
|
|
48
|
+
"zod": "4.4.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^22.0.0",
|
|
52
|
+
"esbuild": "^0.27.0",
|
|
53
|
+
"solid-js": "^1.9.0",
|
|
54
|
+
"tsx": "^4.21.0",
|
|
55
|
+
"typescript": "^5.9.0",
|
|
56
|
+
"vite": "^7.0.0",
|
|
57
|
+
"vite-plugin-solid": "^2.11.0",
|
|
58
|
+
"prettier": "^3.7.0"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=22.20.0"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { existsSync, rmSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
// Build dependencies are pinned snapshots. No app installation, profile or running service is consulted.
|
|
10
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
11
|
+
const provenance = JSON.parse(
|
|
12
|
+
await fs.readFile(path.join(root, "vendor/provenance.json"), "utf8"),
|
|
13
|
+
);
|
|
14
|
+
const arg = (name) => {
|
|
15
|
+
const i = process.argv.indexOf(name);
|
|
16
|
+
return i < 0 ? undefined : process.argv[i + 1];
|
|
17
|
+
};
|
|
18
|
+
const runtimeRoot = arg("--runtime-root");
|
|
19
|
+
if (
|
|
20
|
+
process.argv.includes("--runtime-root") &&
|
|
21
|
+
(!runtimeRoot || runtimeRoot.startsWith("--"))
|
|
22
|
+
)
|
|
23
|
+
throw new Error("--runtime-root requires a directory.");
|
|
24
|
+
const output = runtimeRoot
|
|
25
|
+
? path.resolve(runtimeRoot)
|
|
26
|
+
: path.join(root, "runtime");
|
|
27
|
+
const platform = `${process.platform}-${process.arch}`;
|
|
28
|
+
const destination = path.join(output, platform);
|
|
29
|
+
const version = "22.20.0";
|
|
30
|
+
const manifest = {
|
|
31
|
+
node: version,
|
|
32
|
+
platform: process.platform,
|
|
33
|
+
arch: process.arch,
|
|
34
|
+
format: 1,
|
|
35
|
+
source: provenance.tencent,
|
|
36
|
+
};
|
|
37
|
+
if (runtimeRoot && existsSync(destination)) {
|
|
38
|
+
const existing = await fs
|
|
39
|
+
.readFile(path.join(destination, "runtime.json"), "utf8")
|
|
40
|
+
.catch(() => "");
|
|
41
|
+
if (existing !== JSON.stringify(manifest))
|
|
42
|
+
throw new Error(
|
|
43
|
+
"The runtime directory is incomplete or contains a different revision. Choose a new --runtime-root.",
|
|
44
|
+
);
|
|
45
|
+
console.log(
|
|
46
|
+
`TencentDB runtime already prepared. Set runtimeDir to: ${destination}`,
|
|
47
|
+
);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
await fs.mkdir(output, { recursive: true });
|
|
51
|
+
const target = runtimeRoot
|
|
52
|
+
? await fs.mkdtemp(path.join(output, `.${platform}-`))
|
|
53
|
+
: destination;
|
|
54
|
+
const cache = runtimeRoot
|
|
55
|
+
? path.join(target, ".build-cache")
|
|
56
|
+
: path.join(output, "cache");
|
|
57
|
+
const runtimeManifest = path.join(target, "runtime.json");
|
|
58
|
+
if (runtimeRoot)
|
|
59
|
+
process.on("exit", () => rmSync(target, { recursive: true, force: true }));
|
|
60
|
+
const nodeName = process.platform === "win32" ? "node.exe" : "node";
|
|
61
|
+
const node = path.join(target, "bin", nodeName);
|
|
62
|
+
const run = (command, args, cwd) =>
|
|
63
|
+
execFileSync(command, args, {
|
|
64
|
+
cwd,
|
|
65
|
+
stdio: "inherit",
|
|
66
|
+
env: {
|
|
67
|
+
...process.env,
|
|
68
|
+
PATH: `${path.dirname(node)}${path.delimiter}${process.env.PATH}`,
|
|
69
|
+
NODE_OPTIONS: "",
|
|
70
|
+
ELECTRON_RUN_AS_NODE: "",
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
async function download(url, destination) {
|
|
74
|
+
if (existsSync(destination)) return;
|
|
75
|
+
const response = await fetch(url);
|
|
76
|
+
if (!response.ok)
|
|
77
|
+
throw new Error(`Runtime download failed: HTTP ${response.status}`);
|
|
78
|
+
await fs.writeFile(
|
|
79
|
+
`${destination}.partial`,
|
|
80
|
+
Buffer.from(await response.arrayBuffer()),
|
|
81
|
+
);
|
|
82
|
+
await fs.rename(`${destination}.partial`, destination);
|
|
83
|
+
}
|
|
84
|
+
await fs.mkdir(path.join(target, "bin"), { recursive: true });
|
|
85
|
+
await fs.mkdir(cache, { recursive: true });
|
|
86
|
+
const archive =
|
|
87
|
+
process.platform === "win32"
|
|
88
|
+
? `win-${process.arch}/node.exe`
|
|
89
|
+
: `node-v${version}-${process.platform}-${process.arch}.tar.gz`;
|
|
90
|
+
const nodeDownload = path.join(
|
|
91
|
+
cache,
|
|
92
|
+
`${process.platform}-${process.arch}-node`,
|
|
93
|
+
);
|
|
94
|
+
await download(`https://nodejs.org/dist/v${version}/${archive}`, nodeDownload);
|
|
95
|
+
const sums = await (
|
|
96
|
+
await fetch(`https://nodejs.org/dist/v${version}/SHASUMS256.txt`)
|
|
97
|
+
).text();
|
|
98
|
+
const expected = sums
|
|
99
|
+
.split("\n")
|
|
100
|
+
.find((line) => line.trim().endsWith(` ${archive}`))
|
|
101
|
+
?.split(/\s+/)[0];
|
|
102
|
+
if (
|
|
103
|
+
!expected ||
|
|
104
|
+
createHash("sha256")
|
|
105
|
+
.update(await fs.readFile(nodeDownload))
|
|
106
|
+
.digest("hex") !== expected
|
|
107
|
+
)
|
|
108
|
+
throw new Error("Node runtime checksum mismatch.");
|
|
109
|
+
if (!existsSync(node)) {
|
|
110
|
+
if (process.platform === "win32") await fs.copyFile(nodeDownload, node);
|
|
111
|
+
else {
|
|
112
|
+
run("tar", [
|
|
113
|
+
"-xzf",
|
|
114
|
+
nodeDownload,
|
|
115
|
+
"-C",
|
|
116
|
+
cache,
|
|
117
|
+
`node-v${version}-${process.platform}-${process.arch}/bin/node`,
|
|
118
|
+
]);
|
|
119
|
+
await fs.copyFile(
|
|
120
|
+
path.join(
|
|
121
|
+
cache,
|
|
122
|
+
`node-v${version}-${process.platform}-${process.arch}/bin/node`,
|
|
123
|
+
),
|
|
124
|
+
node,
|
|
125
|
+
);
|
|
126
|
+
await fs.chmod(node, 0o755);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let source = arg("--source");
|
|
130
|
+
if (source) {
|
|
131
|
+
source = path.resolve(source);
|
|
132
|
+
const actual = execFileSync("git", ["-C", source, "rev-parse", "HEAD"], {
|
|
133
|
+
encoding: "utf8",
|
|
134
|
+
}).trim();
|
|
135
|
+
if (actual !== provenance.tencent.revision)
|
|
136
|
+
throw new Error("Tencent checkout does not match the pinned revision.");
|
|
137
|
+
if (
|
|
138
|
+
execFileSync(
|
|
139
|
+
"git",
|
|
140
|
+
["-C", source, "status", "--porcelain", "--untracked-files=all"],
|
|
141
|
+
{ encoding: "utf8" },
|
|
142
|
+
).trim()
|
|
143
|
+
)
|
|
144
|
+
throw new Error(
|
|
145
|
+
"Tencent checkout has tracked modifications; use a clean pinned checkout.",
|
|
146
|
+
);
|
|
147
|
+
} else {
|
|
148
|
+
source = path.join(cache, "source");
|
|
149
|
+
if (!existsSync(path.join(source, "MemoryCore/package.json"))) {
|
|
150
|
+
const repo = provenance.tencent.repository.replace(
|
|
151
|
+
"https://github.com/",
|
|
152
|
+
"",
|
|
153
|
+
);
|
|
154
|
+
const file = path.join(cache, "source.tar.gz");
|
|
155
|
+
await download(
|
|
156
|
+
`https://codeload.github.com/${repo}/tar.gz/${provenance.tencent.revision}`,
|
|
157
|
+
file,
|
|
158
|
+
);
|
|
159
|
+
const entries = execFileSync("tar", ["-tzf", file], { encoding: "utf8" })
|
|
160
|
+
.trim()
|
|
161
|
+
.split("\n");
|
|
162
|
+
if (
|
|
163
|
+
entries.some(
|
|
164
|
+
(entry) => entry.startsWith("/") || entry.split("/").includes(".."),
|
|
165
|
+
)
|
|
166
|
+
)
|
|
167
|
+
throw new Error("Unsafe source archive.");
|
|
168
|
+
await fs.mkdir(source, { recursive: true });
|
|
169
|
+
run("tar", ["-xzf", file, "--strip-components=1", "-C", source]);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const npmCommand = execFileSync(
|
|
173
|
+
process.platform === "win32" ? "where.exe" : "which",
|
|
174
|
+
[process.platform === "win32" ? "npm.cmd" : "npm"],
|
|
175
|
+
{ encoding: "utf8" },
|
|
176
|
+
)
|
|
177
|
+
.trim()
|
|
178
|
+
.split(/\r?\n/)[0];
|
|
179
|
+
const npm =
|
|
180
|
+
process.platform === "win32"
|
|
181
|
+
? path.join(path.dirname(npmCommand), "node_modules/npm/bin/npm-cli.js")
|
|
182
|
+
: await fs.realpath(npmCommand);
|
|
183
|
+
for (const name of ["MemoryCore", "MemoryKnowledge", "MemoryPanel"]) {
|
|
184
|
+
const src = path.join(source, name),
|
|
185
|
+
dest = path.join(target, name);
|
|
186
|
+
await fs.mkdir(dest, { recursive: true });
|
|
187
|
+
const pkg = JSON.parse(
|
|
188
|
+
await fs.readFile(path.join(src, "package.json"), "utf8"),
|
|
189
|
+
);
|
|
190
|
+
delete pkg.devDependencies;
|
|
191
|
+
delete pkg.peerDependencies;
|
|
192
|
+
delete pkg.peerDependenciesMeta;
|
|
193
|
+
delete pkg.scripts;
|
|
194
|
+
pkg.dependencies.tsx = "^4.21.0";
|
|
195
|
+
const serviceManifest = JSON.stringify(pkg, null, 2);
|
|
196
|
+
const lock = await fs.readFile(
|
|
197
|
+
path.join(root, "vendor/locks", `${name}.json`),
|
|
198
|
+
"utf8",
|
|
199
|
+
);
|
|
200
|
+
const fingerprint = createHash("sha256")
|
|
201
|
+
.update(serviceManifest)
|
|
202
|
+
.update(lock)
|
|
203
|
+
.digest("hex");
|
|
204
|
+
const stamp = path.join(dest, ".dependency-manifest");
|
|
205
|
+
const dependencyCache = arg("--dependency-cache");
|
|
206
|
+
const cached = dependencyCache && path.join(dependencyCache, name);
|
|
207
|
+
if (
|
|
208
|
+
!existsSync(path.join(dest, "node_modules")) &&
|
|
209
|
+
cached &&
|
|
210
|
+
(await fs
|
|
211
|
+
.readFile(path.join(cached, ".dependency-manifest"), "utf8")
|
|
212
|
+
.catch(() => "")) === fingerprint
|
|
213
|
+
) {
|
|
214
|
+
await fs.cp(
|
|
215
|
+
path.join(cached, "node_modules"),
|
|
216
|
+
path.join(dest, "node_modules"),
|
|
217
|
+
{ recursive: true, verbatimSymlinks: true },
|
|
218
|
+
);
|
|
219
|
+
await fs.writeFile(stamp, fingerprint);
|
|
220
|
+
}
|
|
221
|
+
await fs.writeFile(path.join(dest, "package.json"), serviceManifest);
|
|
222
|
+
await fs.writeFile(path.join(dest, "package-lock.json"), lock);
|
|
223
|
+
if (
|
|
224
|
+
(await fs.readFile(stamp, "utf8").catch(() => "")) !== fingerprint ||
|
|
225
|
+
!existsSync(path.join(dest, "node_modules"))
|
|
226
|
+
) {
|
|
227
|
+
run(
|
|
228
|
+
node,
|
|
229
|
+
[
|
|
230
|
+
npm,
|
|
231
|
+
"ci",
|
|
232
|
+
"--omit=dev",
|
|
233
|
+
"--legacy-peer-deps",
|
|
234
|
+
"--no-audit",
|
|
235
|
+
"--no-fund",
|
|
236
|
+
],
|
|
237
|
+
dest,
|
|
238
|
+
);
|
|
239
|
+
await fs.writeFile(stamp, fingerprint);
|
|
240
|
+
}
|
|
241
|
+
for (const entry of [
|
|
242
|
+
"src",
|
|
243
|
+
"index.ts",
|
|
244
|
+
"openapi.yaml",
|
|
245
|
+
"templates",
|
|
246
|
+
"prompts",
|
|
247
|
+
]) {
|
|
248
|
+
if (!existsSync(path.join(src, entry))) continue;
|
|
249
|
+
await fs.rm(path.join(dest, entry), { force: true, recursive: true });
|
|
250
|
+
await fs.cp(path.join(src, entry), path.join(dest, entry), {
|
|
251
|
+
recursive: true,
|
|
252
|
+
verbatimSymlinks: true,
|
|
253
|
+
filter: (file) => !/(?:__tests__|\.test\.[cm]?ts$)/.test(file),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const web = path.join(target, "MemoryPanel/web");
|
|
258
|
+
await fs.mkdir(web, { recursive: true });
|
|
259
|
+
await fs.cp(path.join(source, "MemoryPanel/web"), web, {
|
|
260
|
+
recursive: true,
|
|
261
|
+
verbatimSymlinks: true,
|
|
262
|
+
filter: (file) =>
|
|
263
|
+
!file
|
|
264
|
+
.split(path.sep)
|
|
265
|
+
.some((part) => ["node_modules", "dist"].includes(part)),
|
|
266
|
+
});
|
|
267
|
+
await fs.copyFile(
|
|
268
|
+
path.join(root, "vendor/locks/web.json"),
|
|
269
|
+
path.join(web, "package-lock.json"),
|
|
270
|
+
);
|
|
271
|
+
run(node, [npm, "ci", "--no-audit", "--no-fund"], web);
|
|
272
|
+
run(node, [npm, "run", "build"], web);
|
|
273
|
+
await fs.rm(path.join(web, "node_modules"), { recursive: true, force: true });
|
|
274
|
+
if (runtimeRoot) await fs.rm(cache, { recursive: true, force: true });
|
|
275
|
+
// fs.cp otherwise rewrites relative links to their old absolute source paths.
|
|
276
|
+
const realTarget = await fs.realpath(target);
|
|
277
|
+
async function checkLinks(directory) {
|
|
278
|
+
for (const entry of await fs.readdir(directory, { withFileTypes: true })) {
|
|
279
|
+
const file = path.join(directory, entry.name);
|
|
280
|
+
if (entry.isSymbolicLink()) {
|
|
281
|
+
const destination = await fs.realpath(file);
|
|
282
|
+
if (
|
|
283
|
+
destination !== realTarget &&
|
|
284
|
+
!destination.startsWith(realTarget + path.sep)
|
|
285
|
+
)
|
|
286
|
+
throw new Error(`Runtime has an outside symlink: ${file}`);
|
|
287
|
+
} else if (entry.isDirectory()) await checkLinks(file);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
await checkLinks(target);
|
|
291
|
+
await fs.copyFile(
|
|
292
|
+
path.join(root, "vendor/runner.mjs"),
|
|
293
|
+
path.join(target, "runner.mjs"),
|
|
294
|
+
);
|
|
295
|
+
await fs.writeFile(`${runtimeManifest}.partial`, JSON.stringify(manifest));
|
|
296
|
+
await fs.rename(`${runtimeManifest}.partial`, runtimeManifest);
|
|
297
|
+
if (runtimeRoot) await fs.rename(target, destination);
|
|
298
|
+
console.log(`TencentDB runtime prepared. Set runtimeDir to: ${destination}`);
|
package/src/binding.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
|
|
3
|
+
export type Project = {
|
|
4
|
+
project_id: string | null;
|
|
5
|
+
name: string;
|
|
6
|
+
workspace: string;
|
|
7
|
+
roots: string[];
|
|
8
|
+
};
|
|
9
|
+
export type Binding = {
|
|
10
|
+
project: Project;
|
|
11
|
+
generation(): Promise<{
|
|
12
|
+
base_url: string;
|
|
13
|
+
model: string;
|
|
14
|
+
callback_token: string;
|
|
15
|
+
}>;
|
|
16
|
+
host(
|
|
17
|
+
route: string,
|
|
18
|
+
mutation?: unknown,
|
|
19
|
+
questions?: unknown[],
|
|
20
|
+
signal?: AbortSignal,
|
|
21
|
+
): Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
const bindings = new AsyncLocalStorage<Binding>();
|
|
24
|
+
export function binding(): Binding {
|
|
25
|
+
const current = bindings.getStore();
|
|
26
|
+
if (!current)
|
|
27
|
+
throw new Error(
|
|
28
|
+
"Tencent memory requires an OpenCode-bound project/session.",
|
|
29
|
+
);
|
|
30
|
+
return current;
|
|
31
|
+
}
|
|
32
|
+
export const runWithBinding = <T>(value: Binding, action: () => T): T =>
|
|
33
|
+
bindings.run(value, action);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LinkHandler,
|
|
3
|
+
Panel,
|
|
4
|
+
usePlugin,
|
|
5
|
+
type Context,
|
|
6
|
+
type PanelProps,
|
|
7
|
+
type PanelTab,
|
|
8
|
+
type SessionRef,
|
|
9
|
+
} from "@opencode/plugin/gui";
|
|
10
|
+
import { createResource, Show } from "solid-js";
|
|
11
|
+
import { bmadArtifactPath, TencentMemory } from "./rpc.js";
|
|
12
|
+
|
|
13
|
+
function readArtifact(session: SessionRef, path: string) {
|
|
14
|
+
return session.server.client
|
|
15
|
+
.rpc(TencentMemory)
|
|
16
|
+
.readBmadArtifact(
|
|
17
|
+
{ path },
|
|
18
|
+
{ location: { directory: session.location?.directory } },
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function ArtifactPreview(props: PanelProps) {
|
|
23
|
+
const { ui } = usePlugin();
|
|
24
|
+
const [artifact, { refetch }] = createResource(
|
|
25
|
+
() => ({ session: props.session, path: props.tab.id }),
|
|
26
|
+
({ session, path }) => readArtifact(session, path).catch(() => null),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div style={{ height: "100%", overflow: "auto", padding: "16px" }}>
|
|
31
|
+
<header
|
|
32
|
+
style={{
|
|
33
|
+
display: "flex",
|
|
34
|
+
"justify-content": "space-between",
|
|
35
|
+
gap: "8px",
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<p>TencentDB · BMAD artifact</p>
|
|
39
|
+
<ui.Button disabled={artifact.loading} onClick={() => void refetch()}>
|
|
40
|
+
Refresh
|
|
41
|
+
</ui.Button>
|
|
42
|
+
</header>
|
|
43
|
+
<Show when={artifact.loading}>
|
|
44
|
+
<p role="status">Loading artifact…</p>
|
|
45
|
+
</Show>
|
|
46
|
+
<Show when={artifact() === null}>
|
|
47
|
+
<p role="alert">Could not load this BMAD artifact from TencentDB.</p>
|
|
48
|
+
</Show>
|
|
49
|
+
<Show when={artifact()}>
|
|
50
|
+
{(document) => <ui.Markdown text={document().content} />}
|
|
51
|
+
</Show>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function registerBmadArtifacts(ctx: Context) {
|
|
57
|
+
const tabs = new Map<string, PanelTab>();
|
|
58
|
+
|
|
59
|
+
ctx.add(LinkHandler, {
|
|
60
|
+
priority: 10,
|
|
61
|
+
match: (link) =>
|
|
62
|
+
link.session?.server.local === true &&
|
|
63
|
+
!link.exact &&
|
|
64
|
+
bmadArtifactPath.safeParse(link.href).success,
|
|
65
|
+
exists: async ({ href, session }) => {
|
|
66
|
+
if (!session) return false;
|
|
67
|
+
return readArtifact(session, href).then(
|
|
68
|
+
() => true,
|
|
69
|
+
() => false,
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
open: ({ href, session, background }) => {
|
|
73
|
+
if (session)
|
|
74
|
+
ctx.layout.open(`${ctx.id}:${href}`, session, { background });
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
ctx.add(Panel, {
|
|
79
|
+
id: "bmad-artifacts",
|
|
80
|
+
region: "side",
|
|
81
|
+
mobile: {
|
|
82
|
+
title: "BMAD Artifact",
|
|
83
|
+
kind: "menu",
|
|
84
|
+
order: 50,
|
|
85
|
+
icon: "file-document",
|
|
86
|
+
},
|
|
87
|
+
list: ({ session, open }) =>
|
|
88
|
+
session.server.local
|
|
89
|
+
? open
|
|
90
|
+
.filter((id) => bmadArtifactPath.safeParse(id).success)
|
|
91
|
+
.map((id) => {
|
|
92
|
+
const existing = tabs.get(id);
|
|
93
|
+
if (existing) return existing;
|
|
94
|
+
const tab = {
|
|
95
|
+
id,
|
|
96
|
+
title: id.slice(id.lastIndexOf("/") + 1),
|
|
97
|
+
closable: "compact" as const,
|
|
98
|
+
};
|
|
99
|
+
tabs.set(id, tab);
|
|
100
|
+
return tab;
|
|
101
|
+
})
|
|
102
|
+
: [],
|
|
103
|
+
render: (props) => (
|
|
104
|
+
<ArtifactPreview
|
|
105
|
+
session={props.session}
|
|
106
|
+
tab={props.tab}
|
|
107
|
+
screen={props.screen}
|
|
108
|
+
/>
|
|
109
|
+
),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { usePlugin } from "@opencode/plugin/gui";
|
|
2
|
+
import {
|
|
3
|
+
createEffect,
|
|
4
|
+
createResource,
|
|
5
|
+
createSignal,
|
|
6
|
+
onCleanup,
|
|
7
|
+
Show,
|
|
8
|
+
} from "solid-js";
|
|
9
|
+
import { TencentMemory } from "./rpc.js";
|
|
10
|
+
|
|
11
|
+
export function EmbeddingSettings() {
|
|
12
|
+
const ctx = usePlugin();
|
|
13
|
+
const ui = ctx.ui;
|
|
14
|
+
const rpc = () => ctx.client.rpc(TencentMemory);
|
|
15
|
+
const [status, { refetch }] = createResource(() => rpc().embeddingStatus({}));
|
|
16
|
+
const [baseUrl, setBaseUrl] = createSignal("");
|
|
17
|
+
const [model, setModel] = createSignal("");
|
|
18
|
+
const [apiKey, setApiKey] = createSignal("");
|
|
19
|
+
const [checked, setChecked] = createSignal("");
|
|
20
|
+
const [notice, setNotice] = createSignal("");
|
|
21
|
+
const [busy, setBusy] = createSignal(false);
|
|
22
|
+
let initialized = false;
|
|
23
|
+
|
|
24
|
+
createEffect(() => {
|
|
25
|
+
const current = status()?.current;
|
|
26
|
+
if (current && !initialized) {
|
|
27
|
+
setBaseUrl(current.baseUrl);
|
|
28
|
+
setModel(current.model);
|
|
29
|
+
initialized = true;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
createEffect(() => {
|
|
33
|
+
if (!["checking", "reindexing"].includes(status()?.phase ?? "")) return;
|
|
34
|
+
const timer = setInterval(() => void refetch(), 1000);
|
|
35
|
+
onCleanup(() => clearInterval(timer));
|
|
36
|
+
});
|
|
37
|
+
createEffect(() => {
|
|
38
|
+
if (status()?.phase === "complete") {
|
|
39
|
+
const current = status()?.current;
|
|
40
|
+
if (current) {
|
|
41
|
+
setBaseUrl(current.baseUrl);
|
|
42
|
+
setModel(current.model);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const fingerprint = () => JSON.stringify([baseUrl(), model(), apiKey()]);
|
|
48
|
+
const input = () => ({
|
|
49
|
+
baseUrl: baseUrl().trim(),
|
|
50
|
+
model: model().trim(),
|
|
51
|
+
apiKey: apiKey().trim() || undefined,
|
|
52
|
+
});
|
|
53
|
+
const changing = () =>
|
|
54
|
+
["checking", "reindexing"].includes(status()?.phase ?? "");
|
|
55
|
+
const ready = () =>
|
|
56
|
+
!!baseUrl().trim() && !!model().trim() && !busy() && !changing();
|
|
57
|
+
|
|
58
|
+
async function check() {
|
|
59
|
+
setBusy(true);
|
|
60
|
+
setNotice("");
|
|
61
|
+
setChecked("");
|
|
62
|
+
try {
|
|
63
|
+
const result = await rpc().probeEmbedding(input());
|
|
64
|
+
setChecked(fingerprint());
|
|
65
|
+
setNotice(`Connection works · ${result.dimensions} dimensions.`);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
setNotice(error instanceof Error ? error.message : String(error));
|
|
68
|
+
} finally {
|
|
69
|
+
setBusy(false);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function apply() {
|
|
74
|
+
if (checked() !== fingerprint()) return;
|
|
75
|
+
const confirmed = await ctx.dialogs.confirm({
|
|
76
|
+
title: "Change embedding model?",
|
|
77
|
+
description:
|
|
78
|
+
"Tencent Memory will pause while it rebuilds the vector index. A backup of the previous index and settings is kept for recovery.",
|
|
79
|
+
confirm: "Rebuild index",
|
|
80
|
+
});
|
|
81
|
+
if (!confirmed) return;
|
|
82
|
+
setBusy(true);
|
|
83
|
+
setNotice("");
|
|
84
|
+
try {
|
|
85
|
+
await rpc().applyEmbedding(input());
|
|
86
|
+
setApiKey("");
|
|
87
|
+
setChecked("");
|
|
88
|
+
await refetch();
|
|
89
|
+
} catch (error) {
|
|
90
|
+
setNotice(error instanceof Error ? error.message : String(error));
|
|
91
|
+
} finally {
|
|
92
|
+
setBusy(false);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<ui.SettingsSection
|
|
98
|
+
title="Embedding"
|
|
99
|
+
footer="Changing the model rebuilds the vector index. Existing memory stays in place and the previous index is backed up."
|
|
100
|
+
>
|
|
101
|
+
<Show when={status.error}>
|
|
102
|
+
<p role="alert">Could not load embedding settings.</p>
|
|
103
|
+
</Show>
|
|
104
|
+
<Show when={status()?.current}>
|
|
105
|
+
{(current) => (
|
|
106
|
+
<ui.SettingsRow
|
|
107
|
+
title="Current model"
|
|
108
|
+
description={`${current().model} · ${current().dimensions} dimensions`}
|
|
109
|
+
/>
|
|
110
|
+
)}
|
|
111
|
+
</Show>
|
|
112
|
+
<ui.SettingsRow
|
|
113
|
+
title="Endpoint"
|
|
114
|
+
description="OpenAI compatible /v1 endpoint"
|
|
115
|
+
>
|
|
116
|
+
<ui.TextInput
|
|
117
|
+
label="Embedding endpoint"
|
|
118
|
+
value={baseUrl()}
|
|
119
|
+
onInput={setBaseUrl}
|
|
120
|
+
disabled={changing()}
|
|
121
|
+
/>
|
|
122
|
+
</ui.SettingsRow>
|
|
123
|
+
<ui.SettingsRow title="Model">
|
|
124
|
+
<ui.TextInput
|
|
125
|
+
label="Embedding model"
|
|
126
|
+
value={model()}
|
|
127
|
+
onInput={setModel}
|
|
128
|
+
disabled={changing()}
|
|
129
|
+
/>
|
|
130
|
+
</ui.SettingsRow>
|
|
131
|
+
<ui.SettingsRow
|
|
132
|
+
title="API key"
|
|
133
|
+
description="Leave blank to keep the current key for the same endpoint."
|
|
134
|
+
>
|
|
135
|
+
<ui.TextInput
|
|
136
|
+
label="Embedding API key"
|
|
137
|
+
type="password"
|
|
138
|
+
value={apiKey()}
|
|
139
|
+
onInput={setApiKey}
|
|
140
|
+
disabled={changing()}
|
|
141
|
+
/>
|
|
142
|
+
</ui.SettingsRow>
|
|
143
|
+
<ui.SettingsRow title="Verify and apply">
|
|
144
|
+
<div style={{ display: "flex", gap: "8px", "flex-wrap": "wrap" }}>
|
|
145
|
+
<ui.Button
|
|
146
|
+
onClick={() => {
|
|
147
|
+
setBaseUrl("http://127.0.0.1:11434/v1");
|
|
148
|
+
setApiKey("");
|
|
149
|
+
}}
|
|
150
|
+
disabled={changing()}
|
|
151
|
+
>
|
|
152
|
+
Ollama endpoint
|
|
153
|
+
</ui.Button>
|
|
154
|
+
<ui.Button
|
|
155
|
+
onClick={() => void check()}
|
|
156
|
+
disabled={!ready()}
|
|
157
|
+
busy={busy()}
|
|
158
|
+
>
|
|
159
|
+
Check connection
|
|
160
|
+
</ui.Button>
|
|
161
|
+
<ui.Button
|
|
162
|
+
variant="contrast"
|
|
163
|
+
onClick={() => void apply()}
|
|
164
|
+
disabled={!ready() || checked() !== fingerprint()}
|
|
165
|
+
>
|
|
166
|
+
Rebuild index
|
|
167
|
+
</ui.Button>
|
|
168
|
+
</div>
|
|
169
|
+
</ui.SettingsRow>
|
|
170
|
+
<Show when={changing()}>
|
|
171
|
+
<p role="status" style={{ padding: "0 16px" }}>
|
|
172
|
+
Rebuilding embeddings: {status()?.phase} · {status()?.done}/
|
|
173
|
+
{status()?.total} {status()?.layer ?? ""}
|
|
174
|
+
</p>
|
|
175
|
+
</Show>
|
|
176
|
+
<Show when={status()?.phase === "complete"}>
|
|
177
|
+
<p role="status" style={{ padding: "0 16px" }}>
|
|
178
|
+
Embedding index rebuilt.
|
|
179
|
+
</p>
|
|
180
|
+
</Show>
|
|
181
|
+
<Show when={status()?.error || notice()}>
|
|
182
|
+
<p
|
|
183
|
+
role={status()?.error ? "alert" : "status"}
|
|
184
|
+
style={{ padding: "0 16px" }}
|
|
185
|
+
>
|
|
186
|
+
{status()?.error || notice()}
|
|
187
|
+
</p>
|
|
188
|
+
</Show>
|
|
189
|
+
</ui.SettingsSection>
|
|
190
|
+
);
|
|
191
|
+
}
|