chat

package
v0.37.0 Latest Latest
Warning

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

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

Documentation

Overview

Package chat implements DataTug Chat: an ADK agent produces DTQL, DataTug executes it into structured results, and session-owned RecordSets persist those results independently of the model provider's memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultChatStorePath added in v0.37.0

func DefaultChatStorePath(projectDir string) (string, error)

DefaultChatStorePath keeps snapshots outside the project repository. The hash distinguishes projects without exposing their path in a filename.

func FormatSchemaContext

func FormatSchemaContext(schema *api.CatalogSchema) string

FormatSchemaContext converts DataTug's stored schema into a compact prompt fragment. It is deterministic so model and snapshot tests stay stable.

func FormatValue

func FormatValue(value any) string

FormatValue applies basic terminal-safe value formatting.

Types

type ADKConversation

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

ADKConversation uses an ephemeral ADK session for each turn. DataTug's durable ChatSession, not ADK memory, owns conversation history.

func NewADKConversation

func NewADKConversation(llm model.LLM, executor DTQLExecutor, sourceURL, schemaContext string, options ...Option) (*ADKConversation, error)

NewADKConversation builds the constrained chat agent. schemaContext is a compact description derived from DataTug's stored dbmodel.

func (*ADKConversation) Ask

func (c *ADKConversation) Ask(ctx context.Context, prompt string) (Turn, error)

Ask runs one chat turn and returns model text separately from every structured query result captured by the tool callback.

func (*ADKConversation) AskWithContext added in v0.37.0

func (c *ADKConversation) AskWithContext(ctx context.Context, prompt, priorContext string) (Turn, error)

AskWithContext reconstructs a fresh provider turn from DataTug-owned context. No prior provider session is needed after a restart or switch.

type ChatMessage added in v0.37.0

type ChatMessage struct {
	ID          string
	Role        string
	Kind        string
	Text        string
	QueryID     string
	RecordSetID string
	CreatedAt   time.Time
}

type ChatScope added in v0.37.0

type ChatScope struct {
	Environment       string
	Database          string
	AccessFingerprint string
}

ChatScope prevents a cached, policy-redacted result from being reopened under another database or principal/policy configuration.

type ChatSession added in v0.37.0

type ChatSession struct {
	ID         string
	Title      string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Messages   []ChatMessage
	Queries    []ExecutedQuery
	RecordSets map[string]RecordSet
}

type ContextualConversation added in v0.37.0

type ContextualConversation interface {
	AskWithContext(context.Context, string, string) (Turn, error)
}

ContextualConversation runs a stateless provider turn with context rebuilt from DataTug-owned state. The provider's session is never authoritative.

type Conversation

type Conversation interface {
	Ask(context.Context, string) (Turn, error)
}

Conversation is the UI-facing chat seam and is trivial to fake in tests.

type DTQLExecutor

type DTQLExecutor interface {
	RunDTQL(context.Context, string, []byte, map[string]any) (secureread.Result, error)
}

DTQLExecutor is the existing DataTug query boundary used by Chat.

type ExecutedQuery added in v0.37.0

type ExecutedQuery struct {
	ID              string
	OriginMessageID string
	Title           string
	DTQL            string
	Source          string
	Parameters      map[string]any
	ExecutedAt      time.Time
	Error           string
}

type GridColumn

type GridColumn struct {
	Name    string
	Numeric bool
}

GridColumn is the UI-ready description of a structured result column.

type GridModel

type GridModel struct {
	Columns []GridColumn
	Rows    [][]string
	// RawRows preserves the structured source values alongside formatted cells
	// for future typed interactions without leaking database types into the UI
	// component adapter.
	RawRows [][]any
	// contains filtered or unexported fields
}

GridModel is the terminal-grid boundary. Values are formatted only here, after query execution has produced a structured secureread.Result.

func NewGridModel

func NewGridModel(result secureread.Result) GridModel

NewGridModel converts a structured query result into display cells while preserving explicit result-column order.

func (*GridModel) Sort

func (m *GridModel) Sort(column int)

Sort toggles ascending/descending ordering for one visible column.

type Option

type Option func(*conversationConfig) error

Option configures the constrained ADK conversation.

func WithThinkingLevel

func WithThinkingLevel(level string) Option

WithThinkingLevel maps the CLI's provider-neutral effort onto ADK's portable thinking budget. pi-go also receives the original level so providers with their own effort controls can apply it directly.

type QueryResult

type QueryResult struct {
	// Title is presentation metadata supplied by the same structured tool
	// action as DTQL. It is never included in, or interpreted as, executable
	// query text.
	Title       string
	DTQL        string
	QueryID     string
	RecordSetID string
	Result      secureread.Result
	Err         error
}

QueryResult records one structured tool execution for the UI.

type RecordSet added in v0.37.0

type RecordSet struct {
	ID              string
	SessionID       string
	QueryID         string
	OriginMessageID string
	Title           string
	DTQL            string
	Source          string
	Environment     string
	Database        string
	Parameters      map[string]any
	CreatedAt       time.Time
	Result          secureread.Result
}

RecordSet is a session-owned, immutable result snapshot. Re-execution must insert another ID, never update one of these rows.

type SessionChat added in v0.37.0

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

SessionChat composes durable state with the existing AI -> DTQL pipeline. Its lock prevents a session switch while a turn is being saved/executed.

func NewSessionChat added in v0.37.0

func NewSessionChat(ctx context.Context, store *SessionStore, agent ContextualConversation, source string) (*SessionChat, error)

func (*SessionChat) Ask added in v0.37.0

func (c *SessionChat) Ask(ctx context.Context, prompt string) (Turn, error)

Ask persists the user message before invoking the model. The tool callback commits each successful query snapshot immediately; final text follows.

func (*SessionChat) Clear added in v0.37.0

func (c *SessionChat) Clear(ctx context.Context) (ChatSession, error)

func (*SessionChat) Create added in v0.37.0

func (c *SessionChat) Create(ctx context.Context) (ChatSession, error)

func (*SessionChat) Delete added in v0.37.0

func (c *SessionChat) Delete(ctx context.Context) (ChatSession, error)

func (*SessionChat) List added in v0.37.0

func (c *SessionChat) List(ctx context.Context) ([]ChatSession, error)

func (*SessionChat) Rename added in v0.37.0

func (c *SessionChat) Rename(ctx context.Context, title string) (ChatSession, error)

func (*SessionChat) Snapshot added in v0.37.0

func (c *SessionChat) Snapshot(ctx context.Context) (ChatSession, error)

func (*SessionChat) Switch added in v0.37.0

func (c *SessionChat) Switch(ctx context.Context, prefix string) (ChatSession, error)

type SessionStore added in v0.37.0

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

func OpenSessionStore added in v0.37.0

func OpenSessionStore(path string, scope ChatScope) (*SessionStore, error)

func (*SessionStore) Activate added in v0.37.0

func (s *SessionStore) Activate(ctx context.Context, id string) error

Activate makes the selected session the one reopened by the next CLI run.

func (*SessionStore) AppendQuery added in v0.37.0

func (s *SessionStore) AppendQuery(ctx context.Context, sessionID, originID, source string, query QueryResult) (QueryResult, error)

AppendQuery commits a successful execution at the tool boundary, before the model's final response. Each invocation gets a new immutable snapshot, including repeated executions of identical DTQL.

func (*SessionStore) AppendTurn added in v0.37.0

func (s *SessionStore) AppendTurn(ctx context.Context, sessionID, originID, source string, turn Turn) (Turn, error)

func (*SessionStore) AppendUser added in v0.37.0

func (s *SessionStore) AppendUser(ctx context.Context, sessionID, prompt string) (ChatMessage, error)

func (*SessionStore) Clear added in v0.37.0

func (s *SessionStore) Clear(ctx context.Context, id string) error

func (*SessionStore) Close added in v0.37.0

func (s *SessionStore) Close() error

func (*SessionStore) Create added in v0.37.0

func (s *SessionStore) Create(ctx context.Context, title string) (ChatSession, error)

func (*SessionStore) Delete added in v0.37.0

func (s *SessionStore) Delete(ctx context.Context, id string) error

func (*SessionStore) LatestOrCreate added in v0.37.0

func (s *SessionStore) LatestOrCreate(ctx context.Context) (ChatSession, error)

func (*SessionStore) List added in v0.37.0

func (s *SessionStore) List(ctx context.Context) ([]ChatSession, error)

func (*SessionStore) Load added in v0.37.0

func (s *SessionStore) Load(ctx context.Context, id string) (ChatSession, error)

func (*SessionStore) Rename added in v0.37.0

func (s *SessionStore) Rename(ctx context.Context, id, title string) error

type Turn

type Turn struct {
	Text    string
	Queries []QueryResult
}

Turn is one completed agent turn. Text is model prose; Queries remain structured and are never reconstructed from Text.

type UI

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

UI is the Bubble Tea chat model: a scrollable history viewport, inline bubble-table components, and a fixed bottom input.

func NewSessionUI added in v0.37.0

func NewSessionUI(ctx context.Context, sessions *SessionChat, modelName string) (*UI, error)

NewSessionUI restores the selected durable session before the terminal starts. Historical grids are built from stored RecordSets, never re-executed.

func NewUI

func NewUI(ctx context.Context, conversation Conversation, modelName string) *UI

NewUI creates the terminal chat model without starting a real terminal.

func (*UI) Init

func (u *UI) Init() tea.Cmd

func (*UI) Run

func (u *UI) Run() error

Run starts the Bubble Tea program and blocks until it exits.

func (*UI) Update

func (u *UI) Update(message tea.Msg) (tea.Model, tea.Cmd)

func (*UI) View

func (u *UI) View() tea.View

Jump to

Keyboard shortcuts

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