mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-07 04:12:10 +02:00
saving
This commit is contained in:
parent
9e9307a2aa
commit
e26caa0b12
123 changed files with 3478 additions and 10078 deletions
34
ts/packages/cli/src/commands/agent.ts
Normal file
34
ts/packages/cli/src/commands/agent.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* Agent CLI commands.
|
||||
*
|
||||
* Python reference: trustgraph-cli/trustgraph/cli/invoke_agent.py
|
||||
*/
|
||||
|
||||
import type { Command } from "commander";
|
||||
import { createSocket, getOpts } from "./util.js";
|
||||
|
||||
export function registerAgentCommands(program: Command): void {
|
||||
program
|
||||
.command("agent")
|
||||
.description("Ask the TrustGraph agent a question")
|
||||
.argument("<question>", "Question to ask")
|
||||
.action(async (question: string, _opts, cmd) => {
|
||||
const opts = getOpts(cmd);
|
||||
const socket = await createSocket(opts);
|
||||
|
||||
try {
|
||||
const resp = await socket.request("agent", { question }, {
|
||||
flowId: opts.flow,
|
||||
onChunk: (chunk) => {
|
||||
const c = chunk as { answer?: string };
|
||||
if (c.answer) process.stdout.write(c.answer);
|
||||
},
|
||||
});
|
||||
|
||||
const r = resp as { answer?: string };
|
||||
if (r.answer) console.log(r.answer);
|
||||
} finally {
|
||||
await socket.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue