@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.
Files changed (38) hide show
  1. package/LICENSE +661 -0
  2. package/LICENSE-MIT +24 -0
  3. package/NOTICE.md +14 -0
  4. package/README.md +207 -2
  5. package/dist/gui-experimental.cjs +64 -0
  6. package/dist/integration.mjs +1986 -0
  7. package/docs/screenshots/code-indexes.png +0 -0
  8. package/package.json +61 -4
  9. package/scripts/prepare-runtime.mjs +298 -0
  10. package/src/binding.ts +33 -0
  11. package/src/bmad-artifact-preview.tsx +111 -0
  12. package/src/embedding-settings.tsx +191 -0
  13. package/src/gui.tsx +388 -0
  14. package/src/index.ts +484 -0
  15. package/src/integration.d.ts +75 -0
  16. package/src/rpc.ts +195 -0
  17. package/src/rule-document.ts +44 -0
  18. package/src/rules-contract.ts +77 -0
  19. package/src/rules.ts +237 -0
  20. package/src/runtime.ts +436 -0
  21. package/vendor/TENCENT-LICENSE +27 -0
  22. package/vendor/integration/native/config.ts +253 -0
  23. package/vendor/integration/native/embedding.ts +270 -0
  24. package/vendor/integration/native/index.ts +265 -0
  25. package/vendor/integration/project/index.ts +151 -0
  26. package/vendor/integration/project/knowledge.ts +283 -0
  27. package/vendor/integration/server.ts +154 -0
  28. package/vendor/integration/tencentChatRules.ts +84 -0
  29. package/vendor/integration/tencentGenerationContext.ts +4 -0
  30. package/vendor/integration/tencentKnowledgeClient.ts +512 -0
  31. package/vendor/integration/tencentMemoryClient.ts +391 -0
  32. package/vendor/integration/tencentUserQuestion.ts +51 -0
  33. package/vendor/locks/MemoryCore.json +4776 -0
  34. package/vendor/locks/MemoryKnowledge.json +3761 -0
  35. package/vendor/locks/MemoryPanel.json +467 -0
  36. package/vendor/locks/web.json +6418 -0
  37. package/vendor/provenance.json +21 -0
  38. package/vendor/runner.mjs +12 -0
package/src/gui.tsx ADDED
@@ -0,0 +1,388 @@
1
+ import {
2
+ Command,
3
+ MenuItem,
4
+ Panel,
5
+ Plugin,
6
+ SettingsPage,
7
+ usePlugin,
8
+ type Context,
9
+ } from "@opencode/plugin/gui";
10
+ import type { MountedSession } from "@opencode/plugin/gui";
11
+ import { createResource, createSignal, For, Show } from "solid-js";
12
+ import { TencentMemory } from "./rpc.js";
13
+ import { EmbeddingSettings } from "./embedding-settings.js";
14
+ import { registerBmadArtifacts } from "./bmad-artifact-preview.js";
15
+
16
+ const tab = {
17
+ id: "memory",
18
+ title: "Tencent Memory",
19
+ closable: "compact" as const,
20
+ };
21
+
22
+ async function loadStatus(ctx: Context) {
23
+ return ctx.client.rpc(TencentMemory).status({});
24
+ }
25
+
26
+ const statusCache = new WeakMap<
27
+ Context,
28
+ Awaited<ReturnType<typeof loadStatus>>
29
+ >();
30
+
31
+ function Tabs(props: {
32
+ active: string;
33
+ select: (tab: string) => void;
34
+ items: Array<{ id: string; title: string }>;
35
+ }) {
36
+ return (
37
+ <div
38
+ role="tablist"
39
+ style={{ display: "flex", gap: "16px", padding: "0 16px" }}
40
+ >
41
+ <For each={props.items}>
42
+ {(item) => (
43
+ <button
44
+ type="button"
45
+ role="tab"
46
+ aria-selected={props.active === item.id}
47
+ onClick={() => props.select(item.id)}
48
+ style={{
49
+ padding: "12px 4px",
50
+ border: "0",
51
+ "border-bottom":
52
+ props.active === item.id
53
+ ? "2px solid currentColor"
54
+ : "2px solid transparent",
55
+ background: "transparent",
56
+ color: "inherit",
57
+ cursor: "pointer",
58
+ font: "inherit",
59
+ }}
60
+ >
61
+ {item.title}
62
+ </button>
63
+ )}
64
+ </For>
65
+ </div>
66
+ );
67
+ }
68
+
69
+ function HubFrame(props: { session?: MountedSession }) {
70
+ const ctx = usePlugin();
71
+ const [panel] = createResource(
72
+ () => props.session?.directory ?? "global",
73
+ () =>
74
+ (props.session?.server.client ?? ctx.client)
75
+ .rpc(TencentMemory)
76
+ .panel(
77
+ {},
78
+ props.session
79
+ ? { location: { directory: props.session.directory } }
80
+ : undefined,
81
+ ),
82
+ );
83
+ return (
84
+ <div style={{ display: "flex", flex: "1", "min-height": "0" }}>
85
+ <Show when={panel.error}>
86
+ <p role="alert">Tencent Memory is unavailable. Reload OpenCode.</p>
87
+ </Show>
88
+ <Show when={panel()}>
89
+ {(data) => (
90
+ <iframe
91
+ title="Tencent Memory Hub"
92
+ src={data().url}
93
+ style={{ flex: "1", width: "100%", height: "100%", border: "0" }}
94
+ />
95
+ )}
96
+ </Show>
97
+ </div>
98
+ );
99
+ }
100
+
101
+ function GlobalMemory() {
102
+ const ctx = usePlugin();
103
+ const ui = ctx.ui;
104
+ const [active, setActive] = createSignal("hub");
105
+ const [status, { refetch }] = createResource(
106
+ async () => {
107
+ const result = await loadStatus(ctx);
108
+ statusCache.set(ctx, result);
109
+ return result;
110
+ },
111
+ { initialValue: statusCache.get(ctx) },
112
+ );
113
+ return (
114
+ <div
115
+ style={{
116
+ display: "flex",
117
+ "flex-direction": "column",
118
+ height: "100dvh",
119
+ "min-height": "650px",
120
+ }}
121
+ >
122
+ <h2 style={{ margin: "16px 20px 4px" }}>Tencent Memory</h2>
123
+ <Tabs
124
+ active={active()}
125
+ select={setActive}
126
+ items={[
127
+ { id: "hub", title: "Memory Hub" },
128
+ { id: "settings", title: "Settings" },
129
+ ]}
130
+ />
131
+ <div
132
+ role="tabpanel"
133
+ aria-label="Memory Hub"
134
+ aria-hidden={active() !== "hub"}
135
+ style={{
136
+ display: active() === "hub" ? "flex" : "none",
137
+ flex: "1",
138
+ "min-height": "0",
139
+ }}
140
+ >
141
+ <HubFrame />
142
+ </div>
143
+ <div
144
+ role="tabpanel"
145
+ aria-label="Settings"
146
+ aria-hidden={active() !== "settings"}
147
+ style={{
148
+ display: active() === "settings" ? "block" : "none",
149
+ flex: "1",
150
+ "min-height": "0",
151
+ overflow: "auto",
152
+ }}
153
+ >
154
+ <ui.SettingsLayout
155
+ title="Runtime Settings"
156
+ description="The local TencentDB service and its embedding configuration."
157
+ actions={
158
+ <ui.Button onClick={() => void refetch()}>Refresh</ui.Button>
159
+ }
160
+ >
161
+ <Show when={status.error}>
162
+ <p role="alert">Could not load Tencent Memory settings.</p>
163
+ </Show>
164
+ <Show when={status()}>
165
+ {(data) => (
166
+ <ui.SettingsSection title="Runtime">
167
+ <ui.SettingsRow
168
+ title="Status"
169
+ description={
170
+ data().ready ? "Running" : (data().error ?? "Unavailable")
171
+ }
172
+ />
173
+ <ui.SettingsRow
174
+ title="Memory tools"
175
+ description={String(data().tools)}
176
+ />
177
+ <ui.SettingsRow
178
+ title="Data directory"
179
+ description={data().dataDir}
180
+ />
181
+ </ui.SettingsSection>
182
+ )}
183
+ </Show>
184
+ <EmbeddingSettings />
185
+ </ui.SettingsLayout>
186
+ </div>
187
+ </div>
188
+ );
189
+ }
190
+
191
+ function CodeIndexes(props: { session: MountedSession }) {
192
+ const ctx = usePlugin();
193
+ const ui = ctx.ui;
194
+ const rpc = () => props.session.server.client.rpc(TencentMemory);
195
+ const options = () => ({ location: { directory: props.session.directory } });
196
+ const [catalog, { refetch }] = createResource(
197
+ () => props.session.directory,
198
+ () => rpc().repositories({}, options()),
199
+ );
200
+ const [busy, setBusy] = createSignal(false);
201
+ const [notice, setNotice] = createSignal("");
202
+
203
+ async function index(repository?: string) {
204
+ setBusy(true);
205
+ setNotice("");
206
+ try {
207
+ const result = await rpc().index({ repository }, options());
208
+ const accepted = result.results.filter((item) => item.accepted).length;
209
+ const failed = result.results.length - accepted;
210
+ setNotice(
211
+ `${accepted} index job${accepted === 1 ? "" : "s"} started${failed ? `, ${failed} failed` : ""}. Refresh to check completion.`,
212
+ );
213
+ await refetch();
214
+ } catch (error) {
215
+ setNotice(error instanceof Error ? error.message : String(error));
216
+ } finally {
217
+ setBusy(false);
218
+ }
219
+ }
220
+
221
+ return (
222
+ <div
223
+ role="tabpanel"
224
+ aria-label="Code Indexes"
225
+ style={{ flex: "1", "min-height": "0", overflow: "auto" }}
226
+ >
227
+ <ui.SettingsLayout
228
+ title="Code Indexes"
229
+ description="Git repositories are discovered automatically under this project. Index each repository separately."
230
+ actions={
231
+ <div style={{ display: "flex", gap: "8px" }}>
232
+ <ui.Button
233
+ onClick={() => void refetch()}
234
+ disabled={busy()}
235
+ busy={catalog.loading}
236
+ >
237
+ Refresh
238
+ </ui.Button>
239
+ <ui.Button
240
+ variant="contrast"
241
+ onClick={() => void index()}
242
+ disabled={busy() || !catalog()?.repositories.length}
243
+ >
244
+ Index all
245
+ </ui.Button>
246
+ </div>
247
+ }
248
+ >
249
+ <Show when={catalog.error}>
250
+ <p role="alert">{String(catalog.error)}</p>
251
+ </Show>
252
+ <Show when={notice()}>
253
+ <p role="status">{notice()}</p>
254
+ </Show>
255
+ <Show when={catalog()}>
256
+ {(data) => (
257
+ <ui.SettingsSection
258
+ title={`${data().repositories.length} discovered ${data().repositories.length === 1 ? "repository" : "repositories"}`}
259
+ footer={data().workspace}
260
+ >
261
+ <Show when={!data().repositories.length}>
262
+ <p>
263
+ No Git repositories found within three folder levels of this
264
+ project.
265
+ </p>
266
+ </Show>
267
+ <For each={data().repositories}>
268
+ {(repo) => (
269
+ <ui.SettingsRow
270
+ title={`${repo.name} · ${repo.status}`}
271
+ description={`${repo.path}${repo.indexed_at ? ` · indexed ${repo.indexed_at}` : ""}${repo.stats ? ` · ${repo.stats.files} files` : ""}${repo.error ? ` · ${repo.error}` : ""}`}
272
+ >
273
+ <ui.Button
274
+ onClick={() => void index(repo.path)}
275
+ disabled={
276
+ busy() ||
277
+ repo.status === "pending" ||
278
+ repo.status === "processing" ||
279
+ repo.status === "unavailable"
280
+ }
281
+ >
282
+ {repo.status === "ready" ? "Refresh index" : "Index"}
283
+ </ui.Button>
284
+ </ui.SettingsRow>
285
+ )}
286
+ </For>
287
+ <For each={data().errors}>
288
+ {(error) => (
289
+ <p role="alert">
290
+ {error.path}: {error.error}
291
+ </p>
292
+ )}
293
+ </For>
294
+ </ui.SettingsSection>
295
+ )}
296
+ </Show>
297
+ </ui.SettingsLayout>
298
+ </div>
299
+ );
300
+ }
301
+
302
+ function ProjectMemory(props: { session: MountedSession }) {
303
+ const [active, setActive] = createSignal("hub");
304
+ return (
305
+ <div
306
+ style={{
307
+ display: "flex",
308
+ "flex-direction": "column",
309
+ width: "100%",
310
+ height: "100%",
311
+ "min-height": "0",
312
+ }}
313
+ >
314
+ <Tabs
315
+ active={active()}
316
+ select={setActive}
317
+ items={[
318
+ { id: "hub", title: "Memory Hub" },
319
+ { id: "indexes", title: "Code Indexes" },
320
+ ]}
321
+ />
322
+ <div
323
+ role="tabpanel"
324
+ aria-label="Memory Hub"
325
+ aria-hidden={active() !== "hub"}
326
+ style={{
327
+ display: active() === "hub" ? "flex" : "none",
328
+ flex: "1",
329
+ "min-height": "0",
330
+ }}
331
+ >
332
+ <HubFrame session={props.session} />
333
+ </div>
334
+ <div
335
+ style={{
336
+ display: active() === "indexes" ? "flex" : "none",
337
+ flex: "1",
338
+ "min-height": "0",
339
+ }}
340
+ aria-hidden={active() !== "indexes"}
341
+ >
342
+ <CodeIndexes session={props.session} />
343
+ </div>
344
+ </div>
345
+ );
346
+ }
347
+
348
+ export default Plugin.define({
349
+ setup(ctx) {
350
+ registerBmadArtifacts(ctx);
351
+ const open = () => {
352
+ const session = ctx.sessions.current();
353
+ if (session?.server.local)
354
+ ctx.layout.open(`${ctx.id}:${tab.id}`, session);
355
+ };
356
+ ctx.add(SettingsPage, {
357
+ id: "memory",
358
+ title: "Tencent Memory",
359
+ icon: "brain",
360
+ render: () => <GlobalMemory />,
361
+ });
362
+ ctx.add(Command, {
363
+ id: "settings",
364
+ title: "Open Tencent Memory",
365
+ run: () => ctx.layout.settings("memory"),
366
+ });
367
+ ctx.add(MenuItem, (): MenuItem | undefined => {
368
+ const session = ctx.sessions.current();
369
+ if (!session?.server.local) return undefined;
370
+ return {
371
+ menu: "session.panel",
372
+ id: tab.id,
373
+ title: tab.title,
374
+ icon: "brain",
375
+ run: open,
376
+ opened: ctx.layout.state(`${ctx.id}:${tab.id}`, session) !== "closed",
377
+ };
378
+ });
379
+ ctx.add(Panel, {
380
+ id: tab.id,
381
+ region: "side",
382
+ width: 700,
383
+ list: ({ open, session }) =>
384
+ session.server.local && open.includes(tab.id) ? [tab] : [],
385
+ render: (input) => <ProjectMemory session={input.session} />,
386
+ });
387
+ },
388
+ });