opencode/js/src/index.ts

30 lines
673 B
TypeScript
Raw Normal View History

2025-05-18 09:31:42 +08:00
import { App } from "./app";
import process from "node:process";
import { RPC } from "./server/server";
import { Session } from "./session/session";
2025-05-18 14:43:01 +08:00
import { Identifier } from "./id/id";
2025-05-18 09:31:42 +08:00
const app = await App.create({
directory: process.cwd(),
});
App.provide(app, async () => {
2025-05-18 14:43:01 +08:00
const sessionID = await Session.list()
[Symbol.asyncIterator]()
.next()
.then((v) => v.value ?? Session.create().then((s) => s.id));
await Session.chat(sessionID, {
role: "user",
2025-05-18 14:50:38 +08:00
id: Identifier.ascending("message"),
2025-05-18 14:43:01 +08:00
parts: [
{
type: "text",
text: "Hey how are you? try to use tools",
},
],
});
2025-05-18 09:31:42 +08:00
const rpc = RPC.listen();
});