@homescriptone/opencode-viewer-extender 0.0.0-stage → 1.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 +21 -0
- package/README.md +153 -2
- package/bin/cli.js +2 -0
- package/bin/cli.ts +73 -0
- package/package.json +49 -4
- package/public/index.html +23 -0
- package/public/plugin-api.js +260 -0
- package/public/plugins/bulk-select.js +95 -0
- package/public/plugins/example.js +75 -0
- package/public/script.js +1877 -0
- package/public/styles.css +1174 -0
- package/server/database.ts +482 -0
- package/server/launch.ts +545 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Example OCV plugin (API v2).
|
|
2
|
+
// Drop any .js file into public/plugins/ and it is auto-loaded at startup.
|
|
3
|
+
//
|
|
4
|
+
// A plugin calls OCV.define({ id, name, description, setup(api), teardown? }).
|
|
5
|
+
// setup() registers features and returns nothing; every register* call returns
|
|
6
|
+
// an unregister function, and disabled plugins are torn down automatically.
|
|
7
|
+
//
|
|
8
|
+
// api registration hooks:
|
|
9
|
+
// api.registerPartRenderer(type, renderer) renderer(part, helpers) -> HTML
|
|
10
|
+
// api.registerExportFormat({ id, label, extension, mime, build })
|
|
11
|
+
// api.registerSessionAction({ id, label, handler })
|
|
12
|
+
// api.registerBulkAction({ id, label, danger?, handler })
|
|
13
|
+
//
|
|
14
|
+
// api.host exposes host data/actions:
|
|
15
|
+
// host.getProjects(), host.getSessions(), host.getSelection()
|
|
16
|
+
// host.api.getProjectSessions(id), host.api.getSessionDetail(id)
|
|
17
|
+
// host.api.deleteProject(id), host.api.deleteSession(id)
|
|
18
|
+
// host.download(name, content, mime), host.createZip(entries), host.refresh()
|
|
19
|
+
|
|
20
|
+
OCV.define({
|
|
21
|
+
id: "example",
|
|
22
|
+
name: "Example plugin",
|
|
23
|
+
description: "Demonstrates the plugin hooks: snapshot renderer, text export, copy session ID.",
|
|
24
|
+
|
|
25
|
+
setup(api) {
|
|
26
|
+
// 1. Custom part renderer: surface "snapshot" parts (hidden by default).
|
|
27
|
+
api.registerPartRenderer("snapshot", function (part, helpers) {
|
|
28
|
+
const hash = String(part.hash ?? part.snapshot ?? "").slice(0, 12);
|
|
29
|
+
if (!hash) return "";
|
|
30
|
+
return `<div class="part part-snapshot"><span class="tiny-muted">snapshot</span> <code>${helpers.escapeHtml(hash)}</code></div>`;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// 2. Custom export format: plain text transcript.
|
|
34
|
+
api.registerExportFormat({
|
|
35
|
+
id: "example-txt",
|
|
36
|
+
label: "Plain text (.txt) — example",
|
|
37
|
+
extension: "txt",
|
|
38
|
+
mime: "text/plain",
|
|
39
|
+
build(ctx) {
|
|
40
|
+
const lines = [];
|
|
41
|
+
lines.push(ctx.session?.title || "Session");
|
|
42
|
+
lines.push("");
|
|
43
|
+
for (const message of ctx.messages ?? []) {
|
|
44
|
+
if (message._type === "subagent") {
|
|
45
|
+
lines.push(`[subagent] ${message.title || message.id}`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
lines.push(`## ${message.role || "unknown"}`);
|
|
49
|
+
for (const part of message.parts ?? []) {
|
|
50
|
+
if (typeof part.text === "string" && part.text.trim()) lines.push(part.text.trim());
|
|
51
|
+
else if (part.type === "tool") lines.push(`[tool: ${part.tool ?? "unknown"}]`);
|
|
52
|
+
}
|
|
53
|
+
lines.push("");
|
|
54
|
+
}
|
|
55
|
+
return lines.join("\n");
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// 3. Custom session action: copy the session id.
|
|
60
|
+
api.registerSessionAction({
|
|
61
|
+
id: "example-copy-id",
|
|
62
|
+
label: "Copy session ID",
|
|
63
|
+
handler(ctx) {
|
|
64
|
+
if (ctx.session?.id && navigator.clipboard) {
|
|
65
|
+
navigator.clipboard.writeText(String(ctx.session.id));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
teardown() {
|
|
72
|
+
// registrations returned by api.register* are removed automatically;
|
|
73
|
+
// release any listeners/timers here if needed.
|
|
74
|
+
}
|
|
75
|
+
});
|