Files
openfang/sdk/javascript/examples/streaming.js
T
jaberjaber23 5692c96494 Initial commit — OpenFang Agent Operating System
Open-source Agent OS built in Rust.

- 14 crates, 1,767+ tests, zero clippy warnings
- 7 autonomous Hands (Clip, Lead, Collector, Predictor, Researcher, Twitter, Browser)
- 16 security systems (WASM sandbox, Merkle audit trail, taint tracking, Ed25519 signing, SSRF protection, secret zeroization, HMAC-SHA256 mutual auth, and more)
- 30 pre-built agents across 4 performance tiers
- 40 channel adapters (Telegram, Discord, Slack, WhatsApp, Teams, and 35 more)
- 38 built-in tools + MCP client/server + A2A protocol
- 26 LLM providers with intelligent routing and cost tracking
- 60+ bundled skills with FangHub marketplace
- Tauri 2.0 native desktop app
- 140+ REST/WS/SSE API endpoints with Alpine.js dashboard
- OpenAI-compatible /v1/chat/completions endpoint
- One-command install, production-ready
2026-02-26 01:00:27 +03:00

34 lines
902 B
JavaScript

/**
* Streaming example — stream agent responses token by token.
*
* Usage:
* node streaming.js
*/
const { OpenFang } = require("../index");
async function main() {
const client = new OpenFang("http://localhost:3000");
// Create an agent
const agent = await client.agents.create({ template: "assistant" });
console.log("Agent:", agent.id);
// Stream the response
console.log("\n--- Streaming response ---");
for await (const event of client.agents.stream(agent.id, "Tell me a short story about a robot.")) {
if (event.type === "text_delta" && event.delta) {
process.stdout.write(event.delta);
} else if (event.type === "tool_call") {
console.log("\n[Tool call:", event.tool, "]");
} else if (event.type === "done") {
console.log("\n--- Done ---");
}
}
// Clean up
await client.agents.delete(agent.id);
}
main().catch(console.error);