inmemory

package
v0.36.0 Latest Latest
Warning

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

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

Documentation

Overview

Package inmemory provides the in-process reference history store. Build it with NewStore, the same shape every backend store is built with.

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() {
	ctx := context.Background()
	store, err := inmemory.NewStore(ctx, inmemory.StoreConfig{})
	if err != nil {
		panic(err)
	}
	message := chat.NewUserMessage(chat.NewTextPart("hello"))
	if _, err = store.Write(ctx, history.ConversationID("demo"), message); err != nil {
		panic(err)
	}
	messages, err := store.Read(ctx, 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. Writes validate then snapshot messages before locking; reads return deep caller-owned snapshots, and missing conversations behave as empty histories.

func NewStore added in v0.36.0

func NewStore(_ context.Context, _ StoreConfig) (*Store, error)

NewStore builds the zero-dependency reference implementation. It exists so the shared conformance suite and callers' tests have a store with no external service, not as a production store: state lives in process and is lost when it exits.

The context is unused — there is no service to reach — and taken anyway so construction has the same shape as external backend constructors.

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)

type StoreConfig added in v0.36.0

type StoreConfig struct{}

StoreConfig carries no settings: the store keeps every conversation in process and reads nothing from its caller. It exists so this reference implementation is constructed exactly like a backend store, which is what lets a call site move between them unchanged.

Jump to

Keyboard shortcuts

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