inmemory

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package inmemory provides a zero-value-ready in-process history store.

Example
package main

import (
	"context"
	"fmt"

	"github.com/Tangerg/scope/core/chat"
	"github.com/Tangerg/scope/core/history"
	"github.com/Tangerg/scope/core/history/inmemory"
)

func main() {
	store := new(inmemory.Store)
	message := chat.NewUserMessage(chat.NewTextPart("hello"))
	if _, err := store.Write(context.Background(), history.ConversationID("demo"), message); err != nil {
		panic(err)
	}
	messages, err := store.Read(context.Background(), history.ConversationID("demo"))
	if err != nil {
		panic(err)
	}
	fmt.Println(len(messages), messages[0].Text())
}
Output:
1 hello

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a concurrent in-process history store suitable for tests, development, and single-instance applications. Its zero value is ready to use. Writes validate then snapshot messages before locking; reads return deep caller-owned snapshots, and missing conversations behave as empty histories.

func (*Store) Clear

func (s *Store) Clear(ctx context.Context, conversationID history.ConversationID) error

func (*Store) Conversations

func (s *Store) Conversations(ctx context.Context) ([]history.ConversationID, error)

func (*Store) Read

func (s *Store) Read(ctx context.Context, conversationID history.ConversationID) ([]chat.Message, error)

func (*Store) Write

func (s *Store) Write(ctx context.Context, conversationID history.ConversationID, messages ...chat.Message) (history.WriteOutcome, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL