()
| 5 | import { SessionResource, WorkflowResource, ParallelWorkflowDefinition, SequentialWorkflowDefinition, LoopWorkflowDefinition } from "@aster/client-js"; |
| 6 | |
| 7 | async function main() { |
| 8 | console.log("=".repeat(60)); |
| 9 | console.log("AsterClient Session + Workflow 演示"); |
| 10 | console.log("=".repeat(60)); |
| 11 | |
| 12 | // 创建资源实例 |
| 13 | const session = new SessionResource({ |
| 14 | baseUrl: "http://localhost:8080", |
| 15 | apiKey: process.env.ASTER_API_KEY, |
| 16 | }); |
| 17 | |
| 18 | const workflow = new WorkflowResource({ |
| 19 | baseUrl: "http://localhost:8080", |
| 20 | apiKey: process.env.ASTER_API_KEY, |
| 21 | }); |
| 22 | |
| 23 | // ======================================================================== |
| 24 | // 1. Session 管理演示 |
| 25 | // ======================================================================== |
| 26 | console.log("\n📝 1. Session 管理"); |
| 27 | console.log("-".repeat(60)); |
| 28 | |
| 29 | // 创建 Session |
| 30 | const newSession = await session.create({ |
| 31 | agentId: "agent-123", |
| 32 | templateId: "assistant", |
| 33 | userId: "user-456", |
| 34 | metadata: { |
| 35 | project: "demo", |
| 36 | environment: "development", |
| 37 | }, |
| 38 | enableCheckpoints: true, |
| 39 | checkpointInterval: 5, // 每5条消息创建一个断点 |
| 40 | }); |
| 41 | console.log("✅ 创建 Session:", newSession.id); |
| 42 | |
| 43 | // 添加消息 |
| 44 | await session.addMessage(newSession.id, { |
| 45 | role: "user", |
| 46 | content: "Hello! Can you help me with something?", |
| 47 | }); |
| 48 | console.log("✅ 添加用户消息"); |
| 49 | |
| 50 | await session.addMessage(newSession.id, { |
| 51 | role: "assistant", |
| 52 | content: "Of course! I'd be happy to help. What do you need assistance with?", |
| 53 | }); |
| 54 | console.log("✅ 添加助手消息"); |
| 55 | |
| 56 | // 获取消息列表 |
| 57 | const messages = await session.getMessages(newSession.id, { |
| 58 | page: 1, |
| 59 | pageSize: 10, |
| 60 | sort: "asc", |
| 61 | }); |
| 62 | console.log(`📋 获取消息列表: ${messages.items.length} 条消息`); |
| 63 | |
| 64 | // ======================================================================== |
no test coverage detected