| 77 | } |
| 78 | |
| 79 | func Chat(t testing.TB, db database.Store, seed database.Chat) database.Chat { |
| 80 | t.Helper() |
| 81 | |
| 82 | var labels pqtype.NullRawMessage |
| 83 | if seed.Labels != nil { |
| 84 | raw, err := json.Marshal(seed.Labels) |
| 85 | require.NoError(t, err, "marshal chat labels") |
| 86 | labels = pqtype.NullRawMessage{RawMessage: raw, Valid: true} |
| 87 | } |
| 88 | |
| 89 | chat, err := db.InsertChat(genCtx, database.InsertChatParams{ |
| 90 | OrganizationID: takeFirst(seed.OrganizationID, uuid.New()), |
| 91 | OwnerID: takeFirst(seed.OwnerID, uuid.New()), |
| 92 | WorkspaceID: seed.WorkspaceID, |
| 93 | BuildID: seed.BuildID, |
| 94 | AgentID: seed.AgentID, |
| 95 | ParentChatID: seed.ParentChatID, |
| 96 | RootChatID: seed.RootChatID, |
| 97 | LastModelConfigID: takeFirst(seed.LastModelConfigID, uuid.New()), |
| 98 | Title: takeFirst(seed.Title, testutil.GetRandomName(t)), |
| 99 | Mode: seed.Mode, |
| 100 | PlanMode: seed.PlanMode, |
| 101 | Status: takeFirst(seed.Status, database.ChatStatusWaiting), |
| 102 | MCPServerIDs: seed.MCPServerIDs, |
| 103 | Labels: labels, |
| 104 | DynamicTools: seed.DynamicTools, |
| 105 | ClientType: takeFirst(seed.ClientType, database.ChatClientTypeUi), |
| 106 | }) |
| 107 | require.NoError(t, err, "insert chat") |
| 108 | return chat |
| 109 | } |
| 110 | |
| 111 | func ChatMessage(t testing.TB, db database.Store, seed database.ChatMessage) database.ChatMessage { |
| 112 | t.Helper() |