MCPcopy Create free account
hub / github.com/astercloud/aster / main

Function main

examples/session-sqlite/main.go:17–190  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func main() {
18 ctx := context.Background()
19
20 fmt.Println("🗄️ SQLite Session Store 示例")
21 fmt.Println("================================")
22
23 // 1. 创建临时目录存储数据库
24 tmpDir, err := os.MkdirTemp("", "aster-sqlite-demo")
25 if err != nil {
26 log.Fatalf("创建临时目录失败: %v", err)
27 }
28 defer func() { _ = os.RemoveAll(tmpDir) }()
29
30 dbPath := filepath.Join(tmpDir, "sessions.db")
31 fmt.Printf("\n📁 数据库路径: %s\n", dbPath)
32
33 // 2. 创建 SQLite Session 服务
34 fmt.Println("\n✓ 创建 SQLite Session 服务...")
35 service, err := sqlite.New(dbPath)
36 if err != nil {
37 log.Fatalf("创建 SQLite 服务失败: %v", err)
38 }
39 defer func() { _ = service.Close() }()
40
41 // 3. 创建会话
42 fmt.Println("\n✓ 创建会话...")
43 sess, err := service.Create(ctx, &session.CreateRequest{
44 AppName: "desktop-app",
45 UserID: "user-001",
46 AgentID: "agent-001",
47 Metadata: map[string]any{
48 "platform": "macos",
49 "version": "1.0.0",
50 },
51 })
52 if err != nil {
53 log.Fatalf("创建会话失败: %v", err)
54 }
55
56 sessionID := sess.ID()
57 fmt.Printf(" 会话 ID: %s\n", sessionID)
58
59 // 4. 添加事件/消息
60 fmt.Println("\n✓ 添加消息...")
61 messages := []struct {
62 author string
63 content string
64 reasoning string
65 }{
66 {"user", "你好,请帮我分析这段代码。", ""},
67 {"assistant", "好的,我来帮你分析代码。首先让我看一下...", "用户请求代码分析,需要先理解代码内容"},
68 {"user", "代码在 main.go 文件中", ""},
69 }
70
71 for _, msg := range messages {
72 event := session.NewEvent("inv-001")
73 event.Author = msg.author
74 event.Content = types.Message{

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
NewEventFunction · 0.92
RoleTypeAlias · 0.92
PrintfMethod · 0.80
truncateFunction · 0.70
CloseMethod · 0.65
CreateMethod · 0.65
IDMethod · 0.65
AppendEventMethod · 0.65
GetEventsMethod · 0.65
ListMethod · 0.65
AgentIDMethod · 0.65

Tested by

no test coverage detected