()
| 6 | import { AsterClient } from "@aster/client-js"; |
| 7 | |
| 8 | async function main() { |
| 9 | console.log("=".repeat(70)); |
| 10 | console.log("AsterClient 完整功能演示"); |
| 11 | console.log("=".repeat(70)); |
| 12 | |
| 13 | // ======================================================================== |
| 14 | // 1. 初始化客户端 |
| 15 | // ======================================================================== |
| 16 | console.log("\n🚀 1. 初始化 AsterClient 客户端"); |
| 17 | console.log("-".repeat(70)); |
| 18 | |
| 19 | const client = new AsterClient({ |
| 20 | baseUrl: "http://localhost:8080", |
| 21 | apiKey: process.env.ASTER_API_KEY, |
| 22 | timeout: 30000, |
| 23 | retry: { |
| 24 | maxRetries: 3, |
| 25 | retryDelay: 1000, |
| 26 | }, |
| 27 | }); |
| 28 | |
| 29 | console.log("✅ 客户端已初始化"); |
| 30 | console.log(" Base URL:", "http://localhost:8080"); |
| 31 | |
| 32 | // 健康检查 |
| 33 | try { |
| 34 | const health = await client.healthCheck(); |
| 35 | console.log("💚 健康检查:", health.status); |
| 36 | console.log(" 组件状态:"); |
| 37 | Object.entries(health.components).forEach(([name, status]) => { |
| 38 | const icon = status.status === "healthy" ? "✅" : "⚠️"; |
| 39 | console.log(` ${icon} ${name}: ${status.status}`); |
| 40 | }); |
| 41 | } catch (error: any) { |
| 42 | console.log("⚠️ 健康检查失败:", error.message); |
| 43 | } |
| 44 | |
| 45 | // ======================================================================== |
| 46 | // 2. Memory 系统 |
| 47 | // ======================================================================== |
| 48 | console.log("\n🧠 2. Memory 系统"); |
| 49 | console.log("-".repeat(70)); |
| 50 | |
| 51 | // Working Memory |
| 52 | await client.memory.working.set( |
| 53 | "user_preference", |
| 54 | { |
| 55 | theme: "dark", |
| 56 | language: "zh-CN", |
| 57 | notifications: true, |
| 58 | }, |
| 59 | { |
| 60 | scope: "resource", // 全局级别(跨会话) |
| 61 | ttl: 3600, |
| 62 | }, |
| 63 | ); |
| 64 | console.log("✅ Working Memory 已设置"); |
| 65 |
no test coverage detected