summaryrefslogtreecommitdiffhomepage
path: root/js/src/index.ts
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-30 20:47:56 -0400
committerDax Raad <[email protected]>2025-05-30 20:48:36 -0400
commitf3da73553c45f17e04b1e77cb13eb0fca714d1bd (patch)
treea24317a19e1ab2a89da50db669dc6894f15d00d1 /js/src/index.ts
parent9a26b3058ffc1023e5c7e54b6d571c903d15888e (diff)
downloadopencode-f3da73553c45f17e04b1e77cb13eb0fca714d1bd.tar.gz
opencode-f3da73553c45f17e04b1e77cb13eb0fca714d1bd.zip
sync
Diffstat (limited to 'js/src/index.ts')
-rw-r--r--js/src/index.ts85
1 files changed, 0 insertions, 85 deletions
diff --git a/js/src/index.ts b/js/src/index.ts
deleted file mode 100644
index c86e60955..000000000
--- a/js/src/index.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-import "zod-openapi/extend";
-import { App } from "./app/app";
-import { Server } from "./server/server";
-import fs from "fs/promises";
-import path from "path";
-import { Bus } from "./bus";
-import { Session } from "./session/session";
-import cac from "cac";
-import { Share } from "./share/share";
-import { Storage } from "./storage/storage";
-import { LLM } from "./llm/llm";
-import { Message } from "./session/message";
-
-const cli = cac("opencode");
-
-cli.command("", "Start the opencode in interactive mode").action(async () => {
- await App.provide({ directory: process.cwd() }, async () => {
- await Share.init();
- Server.listen();
- });
-});
-
-cli.command("generate", "Generate OpenAPI and event specs").action(async () => {
- const specs = await Server.openapi();
- const dir = "gen";
- await fs.rmdir(dir, { recursive: true }).catch(() => {});
- await fs.mkdir(dir, { recursive: true });
- await Bun.write(
- path.join(dir, "openapi.json"),
- JSON.stringify(specs, null, 2),
- );
-});
-
-cli
- .command("run [...message]", "Run a chat message")
- .option("--session <id>", "Session ID")
- .action(async (message: string[], options) => {
- await App.provide({ directory: process.cwd() }, async () => {
- await Share.init();
- const session = options.session
- ? await Session.get(options.session)
- : await Session.create();
- console.log("Session:", session.id);
-
- Bus.subscribe(Message.Event.Updated, async (message) => {
- console.log("Thinking...");
- });
-
- const unsub = Bus.subscribe(Session.Event.Updated, async (message) => {
- if (message.properties.info.share?.url)
- console.log("Share:", message.properties.info.share.url);
- unsub();
- });
-
- const providers = await LLM.providers();
- const providerID = Object.keys(providers)[0];
- const modelID = Object.keys(providers[providerID].info.models!)[0];
- console.log("using", providerID, modelID);
- const result = await Session.chat({
- sessionID: session.id,
- providerID,
- modelID,
- parts: [
- {
- type: "text",
- text: message.join(" "),
- },
- ],
- });
-
- for (const part of result.parts) {
- if (part.type === "text") {
- console.log("opencode:", part.text);
- }
- }
- console.log({
- cost: result.metadata.assistant?.cost,
- tokens: result.metadata.assistant?.tokens,
- });
- });
- });
-
-cli.help();
-cli.version("1.0.0");
-cli.parse();