Files
openfang/sdk/javascript/examples/basic.js
iven 92e5def702
Some checks failed
CI / Check / macos-latest (push) Has been cancelled
CI / Check / ubuntu-latest (push) Has been cancelled
CI / Check / windows-latest (push) Has been cancelled
CI / Test / macos-latest (push) Has been cancelled
CI / Test / ubuntu-latest (push) Has been cancelled
CI / Test / windows-latest (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Security Audit (push) Has been cancelled
CI / Secrets Scan (push) Has been cancelled
CI / Install Script Smoke Test (push) Has been cancelled
初始化提交
2026-03-01 16:24:24 +08:00

35 lines
885 B
JavaScript

/**
* Basic example — create an agent and chat with it.
*
* Usage:
* node basic.js
*/
const { OpenFang } = require("../index");
async function main() {
const client = new OpenFang("http://localhost:3000");
// Check server health
const health = await client.health();
console.log("Server:", health);
// List existing agents
const agents = await client.agents.list();
console.log("Agents:", agents.length);
// Create a new agent from the "assistant" template
const agent = await client.agents.create({ template: "assistant" });
console.log("Created agent:", agent.id);
// Send a message and get the full response
const reply = await client.agents.message(agent.id, "What can you help me with?");
console.log("Reply:", reply);
// Clean up
await client.agents.delete(agent.id);
console.log("Agent deleted.");
}
main().catch(console.error);