Initial commit on Forgejo
Fresh repository history for elektrine/tarakan-client hosted at https://git.elektrine.com/elektrine/tarakan-client.
This commit is contained in:
commit
58b29a7f84
70 changed files with 12994 additions and 0 deletions
37
internal/session/session.go
Normal file
37
internal/session/session.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package session
|
||||
|
||||
import "time"
|
||||
|
||||
type Role string
|
||||
|
||||
const (
|
||||
RoleSystem Role = "system"
|
||||
RoleUser Role = "user"
|
||||
RoleAgent Role = "agent"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Role Role `json:"role"`
|
||||
Content string `json:"content"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type Transcript struct {
|
||||
messages []Message
|
||||
}
|
||||
|
||||
func (t *Transcript) Append(role Role, content string) {
|
||||
t.messages = append(t.messages, Message{
|
||||
Role: role,
|
||||
Content: content,
|
||||
CreatedAt: time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
func (t *Transcript) Clear() {
|
||||
t.messages = nil
|
||||
}
|
||||
|
||||
func (t Transcript) Messages() []Message {
|
||||
return append([]Message(nil), t.messages...)
|
||||
}
|
||||
23
internal/session/session_test.go
Normal file
23
internal/session/session_test.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package session
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTranscriptAppendAndClear(t *testing.T) {
|
||||
var transcript Transcript
|
||||
transcript.Append(RoleUser, "scan authentication")
|
||||
|
||||
messages := transcript.Messages()
|
||||
if len(messages) != 1 || messages[0].Content != "scan authentication" {
|
||||
t.Fatalf("unexpected messages: %#v", messages)
|
||||
}
|
||||
|
||||
messages[0].Content = "changed"
|
||||
if transcript.Messages()[0].Content != "scan authentication" {
|
||||
t.Fatal("Messages returned the transcript's backing slice")
|
||||
}
|
||||
|
||||
transcript.Clear()
|
||||
if len(transcript.Messages()) != 0 {
|
||||
t.Fatal("Clear did not empty transcript")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue