diff options
| author | Dax Raad <[email protected]> | 2025-05-27 02:17:35 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-27 02:17:35 -0400 |
| commit | c040baae118787cd0573e5b674a2a225f36d898c (patch) | |
| tree | 04c4ff3d08f1243e170397fed9f5a31b0ea082cc /js/src/index.ts | |
| parent | 754cc667411cc1d652acd0a811c530dcc35f5927 (diff) | |
| download | opencode-c040baae118787cd0573e5b674a2a225f36d898c.tar.gz opencode-c040baae118787cd0573e5b674a2a225f36d898c.zip | |
Refactor LSP tools and add hover functionality
- Split diagnostics tool into separate lsp-diagnostics.ts file
- Add new lsp-hover.ts tool for LSP hover information
- Update tool exports and session integration
- Remove old diagnostics.ts file
🤖 Generated with opencode
Co-Authored-By: opencode <[email protected]>
Diffstat (limited to 'js/src/index.ts')
| -rw-r--r-- | js/src/index.ts | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/js/src/index.ts b/js/src/index.ts index b0e3ed270..7d6feed45 100644 --- a/js/src/index.ts +++ b/js/src/index.ts @@ -6,6 +6,7 @@ import { Bus } from "./bus"; import { Session } from "./session/session"; import cac from "cac"; import { Share } from "./share/share"; +import { Storage } from "./storage/storage"; const cli = cac("opencode"); @@ -41,6 +42,52 @@ cli const shareID = await Session.share(session.id); if (shareID) console.log("Share ID: https://dev.opencode.ai/share?id=" + session.id); + + let index = 0; + Bus.subscribe(Storage.Event.Write, async (payload) => { + const [root, , type, messageID] = payload.properties.key.split("/"); + if (root !== "session" && type !== "message") return; + const message = await Session.messages(session.id).then((x) => + x.find((x) => x.id === messageID), + ); + if (!message) return; + + for (; index < message.parts.length; index++) { + const part = message.parts[index]; + if (part.type === "text") continue; + if (part.type === "step-start") continue; + if ( + part.type === "tool-invocation" && + part.toolInvocation.state !== "result" + ) + break; + + if (part.type === "tool-invocation") { + console.log(`🔧 ${part.toolInvocation.toolName}`); + if ( + part.toolInvocation.state === "result" && + "result" in part.toolInvocation + ) { + const result = part.toolInvocation.result; + if (typeof result === "string") { + const lines = result.split("\n"); + const truncated = lines.slice(0, 4); + if (lines.length > 4) truncated.push("..."); + console.log(truncated.join("\n")); + } else if (result && typeof result === "object") { + const jsonStr = JSON.stringify(result, null, 2); + const lines = jsonStr.split("\n"); + const truncated = lines.slice(0, 4); + if (lines.length > 4) truncated.push("..."); + console.log(truncated.join("\n")); + } + } + continue; + } + console.log(part); + } + }); + const result = await Session.chat(session.id, { type: "text", text: message.join(" "), @@ -50,16 +97,6 @@ cli if (part.type === "text") { console.log("opencode:", part.text); } - if (part.type === "tool-invocation") { - console.log( - "tool:", - part.toolInvocation.toolName, - part.toolInvocation.args, - part.toolInvocation.state === "result" - ? part.toolInvocation.result - : "", - ); - } } }); }); |
