mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 18:54:21 +01:00
toolz
This commit is contained in:
27
js/example/cli.ts
Normal file
27
js/example/cli.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { hc } from "hono/client";
|
||||
import type { Server } from "../src/server/server";
|
||||
|
||||
const message = process.argv.slice(2).join(" ");
|
||||
console.log(message);
|
||||
|
||||
const client = hc<Server.App>(`http://localhost:16713`);
|
||||
const session = await client.session_create.$post().then((res) => res.json());
|
||||
const result = await client.session_chat
|
||||
.$post({
|
||||
json: {
|
||||
sessionID: session.id,
|
||||
parts: [
|
||||
{
|
||||
type: "text",
|
||||
text: message,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
.then((res) => res.json());
|
||||
|
||||
for (const part of result.parts) {
|
||||
if (part.type === "text") {
|
||||
console.log(part.text);
|
||||
}
|
||||
}
|
||||
@@ -78,13 +78,19 @@ function App() {
|
||||
<>
|
||||
<Text>{session.title}</Text>
|
||||
{
|
||||
Object.values(state.session.message[session.id]).map(message => {
|
||||
return Object.values(message.parts).map((part, index) => {
|
||||
if (part.type === "text") {
|
||||
return <Text key={`${message.id}-${index}`}>{message.role}: {part.text}</Text>
|
||||
}
|
||||
Object.values(state.session.message[session.id])
|
||||
.filter(message => message.role !== "system")
|
||||
.map(message => {
|
||||
return Object.values(message.parts)
|
||||
.map((part, index) => {
|
||||
if (part.type === "text") {
|
||||
return <Text key={`${message.id}-${index}`}>{message.role}: {part.text}</Text>
|
||||
}
|
||||
if (part.type === "tool-invocation") {
|
||||
return <Text key={`${message.id}-${index}`}>{message.role}: {part.toolInvocation.toolName} {JSON.stringify(part.toolInvocation.args)}</Text>
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
<Box gap={1} >
|
||||
<Text>Input:</Text>
|
||||
Reference in New Issue
Block a user