- Created agent.ts to export necessary components from the plugin source. - Implemented index.ts to initialize Opencode client and list projects and sessions. - Added functionality to prompt a session with specific tool instructions.
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { createOpencode, createOpencodeClient } from '@opencode-ai/sdk'
|
|
import util from 'node:util'
|
|
const showMore = (obj: any) => {
|
|
return util.inspect(obj, { showHidden: false, depth: null, colors: true })
|
|
}
|
|
|
|
// const client = await createOpencode({
|
|
// })
|
|
const client = await createOpencodeClient({
|
|
baseUrl: "http://localhost:4096",
|
|
})
|
|
// const sessions = await client.session.list()
|
|
|
|
// console.log('session', sessions)
|
|
|
|
// const sessions = await client.session.list({
|
|
// query: {
|
|
// directory: '/home/ubuntu/kevisual'
|
|
// }
|
|
// })
|
|
|
|
// console.log('session', sessions)
|
|
|
|
const project = await client.project.list()
|
|
console.log('project', project)
|
|
const first = project.data?.[0]
|
|
if (first) {
|
|
const sessions = await client.session.list()
|
|
console.log('session', sessions)
|
|
const session = sessions.data?.[0]
|
|
if (session) {
|
|
const id = session.id;
|
|
const res = await client.session.prompt({
|
|
path: { id: session.id },
|
|
body: {
|
|
// noReply: true,
|
|
tools: {
|
|
greet: false,
|
|
},
|
|
// parts: [{ type: "text", text: "执行Greet工具" }],
|
|
// parts: [{ type: "text", text: "name是 xiong" }],
|
|
parts: [
|
|
{ type: "text", text: "执行Greet工具" },
|
|
{ type: "text", text: "name是 xiong" }],
|
|
},
|
|
})
|
|
console.log('res', showMore(res))
|
|
}
|
|
} |