aichat

module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0

README

aichat

Shared AI provider layer and Bubble Tea chat kit for Sneat, DataTug and future products. Apache-2.0.

Package What it owns
ai Chat request, normalised streaming event model, LLMProvider, tool calling (Tool/ToolCall/ToolResult) and reasoning
ai/agent Tool-calling agent Loop over an ai.LLMProvider: executes Handlers, feeds results back, itself an ai.LLMProvider
ai/decision Decision schema (evolvable), Provider, the first-decider-wins Chain
ai/session Entity refs, focus/selection/sidebar, pending/previous action
ai/cloudproto Product-neutral wire protocol + SSE codec for an AI cloud boundary (e.g. api.sneat.cloud)
ai/openaicompat LLMProvider over the OpenAI Chat Completions streaming API (plain net/http)
ai/openairesponses LLMProvider over OpenAI's Responses API (plain net/http, item-based input/output, same Config shape as ai/openaicompat)
ai/anthropic LLMProvider over the Anthropic Messages streaming API (plain net/http, prompt caching)
ai/cloud LLMProvider client for the ai/cloudproto cloud boundary; Decider() returns its separate decision.Provider role, plus Usage
ai/decision/rules Deterministic, table-driven decision.Provider — no regex/NLP engine
ai/decision/llmdecider decision.Provider backed by one structured LLM inference; the product-neutral "Jev" implementation
ai/ctxmgr Context Manager: token-budgeted, cache-stable ai.ContextBlock selection
ai/aiconfig Product config (cloud/byok, decision chain) and Build wiring
ai/diag Per-turn diagnostics record (diag.Turn) and Debug-level logging
ai/internal/retry Unexported retry-before-first-byte helper (+ Retry-After honouring) shared by the HTTP adapters
ai/internal/sse Unexported SSE line-scanner (LF/CRLF/bare-CR) shared by every SSE reader in the module
tui Messages shared across the tui/* packages (e.g. AddToSidebarMsg)
tui/grid Sortable/filterable result-grid transcript block (table/card/inspector views), extracted from DataTug chat's GridModel/gridState
tui/transcript Scrolling chat history: plain messages, streamed text, rich Block entries
tui/focus The Shift+Arrow focus ring shared by every chatshell (input / transcript stops / sidebar)
tui/sidebar The right-hand working-context panel: pinned session.EntityRefs
tui/stream Pumps an ai.LLMProvider stream into Bubble Tea messages without buffering
tui/chatshell The reusable chat screen composing the packages above; a product plugs in a Handler, and optionally a SidePanel (replaces the sidebar), Overlays (modal dialogs), GlobalKeys, product-rendered top/status bars, and mouse support (WithMouse/SetMouseEnabled: wheel-scrolls the transcript)

Products own scopes, intents, prompts, actions and controls. This module owns only what every product needs to talk to models and render chat the same way.

See docs/tui.md for the tui/* keyboard map and sidebar reference.

Directories

Path Synopsis
ai
Package ai is the product-neutral AI contract shared by Sneat, DataTug and future products: chat requests, the normalised streaming event model, and the LLMProvider interface every adapter (the ai/cloud client, OpenAI-compatible, Anthropic) implements.
Package ai is the product-neutral AI contract shared by Sneat, DataTug and future products: chat requests, the normalised streaming event model, and the LLMProvider interface every adapter (the ai/cloud client, OpenAI-compatible, Anthropic) implements.
agent
Package agent implements a tool-calling agent loop over ai.LLMProvider: it streams a model's response, executes any tool calls the model asked for via caller-supplied Handlers, feeds the results back, and repeats until the model stops calling tools or a configured limit is hit.
Package agent implements a tool-calling agent loop over ai.LLMProvider: it streams a model's response, executes any tool calls the model asked for via caller-supplied Handlers, feeds the results back, and repeats until the model stops calling tools or a configured limit is hit.
aiconfig
Package aiconfig loads and applies the product-level configuration for which LLM and decision providers a product wires up: cloud or BYOK (bring your own key, connecting directly to the provider, never via the cloud), and which deciders run before/instead of the cloud's decision service.
Package aiconfig loads and applies the product-level configuration for which LLM and decision providers a product wires up: cloud or BYOK (bring your own key, connecting directly to the provider, never via the cloud), and which deciders run before/instead of the cloud's decision service.
anthropic
Package anthropic is an ai.LLMProvider for the Anthropic Messages API, implemented directly over net/http -- no vendor SDK.
Package anthropic is an ai.LLMProvider for the Anthropic Messages API, implemented directly over net/http -- no vendor SDK.
cloud
Package cloud is the client for the cloudproto protocol (see ai/cloudproto): it implements ai.LLMProvider (chat) and exposes a separate decision.Provider via Decider(), plus a Usage lookup.
Package cloud is the client for the cloudproto protocol (see ai/cloudproto): it implements ai.LLMProvider (chat) and exposes a separate decision.Provider via Decider(), plus a Usage lookup.
cloudproto
Package cloudproto is the small, product-neutral wire protocol between clients and an AI cloud boundary.
Package cloudproto is the small, product-neutral wire protocol between clients and an AI cloud boundary.
ctxmgr
Package ctxmgr selects which ai.ContextBlock values go into a ChatRequest, balancing two goals: keep the LLM within a token budget, and keep the provider-cached prefix (the leading static blocks a provider such as Anthropic prompt-caches) as stable as possible across turns so caching actually pays off.
Package ctxmgr selects which ai.ContextBlock values go into a ChatRequest, balancing two goals: keep the LLM within a token budget, and keep the provider-cached prefix (the leading static blocks a provider such as Anthropic prompt-caches) as stable as possible across turns so caching actually pays off.
decision
Package decision defines the DecisionProvider contract and the Chain that runs providers in order until one decides.
Package decision defines the DecisionProvider contract and the Chain that runs providers in order until one decides.
decision/llmdecider
Package llmdecider is a decision.Provider that makes ONE structured inference against an ai.LLMProvider to produce a decision.Decision.
Package llmdecider is a decision.Provider that makes ONE structured inference against an ai.LLMProvider to produce a decision.Decision.
decision/rules
Package rules is a deterministic, table-driven decision.Provider.
Package rules is a deterministic, table-driven decision.Provider.
diag
Package diag is the shared diagnostics record for one conversational turn: which path handled it, what the decision chain did, which LLM answered, timing and usage.
Package diag is the shared diagnostics record for one conversational turn: which path handled it, what the decision chain did, which LLM answered, timing and usage.
internal/retry
Package retry is a tiny internal helper shared by the LLMProvider HTTP adapters (ai/openaicompat, ai/anthropic, ai/cloud).
Package retry is a tiny internal helper shared by the LLMProvider HTTP adapters (ai/openaicompat, ai/anthropic, ai/cloud).
internal/sse
Package sse is a tiny internal helper shared by every SSE reader in this module (ai/openaicompat, ai/anthropic, ai/cloudproto): a bufio.SplitFunc that behaves like bufio.ScanLines but also accepts a bare '\r' (old Mac-style line endings), which some SSE producers/proxies still emit.
Package sse is a tiny internal helper shared by every SSE reader in this module (ai/openaicompat, ai/anthropic, ai/cloudproto): a bufio.SplitFunc that behaves like bufio.ScanLines but also accepts a bare '\r' (old Mac-style line endings), which some SSE producers/proxies still emit.
openaicompat
Package openaicompat is an ai.LLMProvider for the OpenAI Chat Completions streaming API (and any API-compatible endpoint), implemented directly over net/http -- no vendor SDK.
Package openaicompat is an ai.LLMProvider for the OpenAI Chat Completions streaming API (and any API-compatible endpoint), implemented directly over net/http -- no vendor SDK.
openairesponses
Package openairesponses is an ai.LLMProvider over OpenAI's Responses API (POST {base}/responses, stream:true), implemented directly over net/http -- no vendor SDK.
Package openairesponses is an ai.LLMProvider over OpenAI's Responses API (POST {base}/responses, stream:true), implemented directly over net/http -- no vendor SDK.
session
Package session holds the product-neutral conversational working state that helps resolve requests such as "move it to Friday": the focused entity, the current selection, sidebar pins, and the pending and previous actions.
Package session holds the product-neutral conversational working state that helps resolve requests such as "move it to Friday": the focused entity, the current selection, sidebar pins, and the pending and previous actions.
tui
Package tui holds the small set of messages shared across the strongo/aichat Bubble Tea chat kit's sub-packages (tui/grid, tui/transcript, tui/focus, tui/sidebar, tui/stream, tui/chatshell) so a leaf component (e.g.
Package tui holds the small set of messages shared across the strongo/aichat Bubble Tea chat kit's sub-packages (tui/grid, tui/transcript, tui/focus, tui/sidebar, tui/stream, tui/chatshell) so a leaf component (e.g.
chatshell
Package chatshell composes tui/transcript, tui/sidebar, tui/focus and tui/stream into the reusable chat screen every aichat product runs: history + composer + sidebar + top/status bars, with a split pane when the terminal is wide enough (>= 104 columns, matching DataTug's splitEnabled).
Package chatshell composes tui/transcript, tui/sidebar, tui/focus and tui/stream into the reusable chat screen every aichat product runs: history + composer + sidebar + top/status bars, with a split pane when the terminal is wide enough (>= 104 columns, matching DataTug's splitEnabled).
focus
Package focus is a small, pure focus-ring state machine shared by every chatshell screen.
Package focus is a small, pure focus-ring state machine shared by every chatshell screen.
grid
Package grid is a product-neutral result-grid transcript block: a bubble-table-backed table with sort, per-cell column selection, a scrollbar, style presets, and slots for a product's own secondary views (charts, a current-row card, raw responses, ...) and split-pane layout.
Package grid is a product-neutral result-grid transcript block: a bubble-table-backed table with sort, per-cell column selection, a scrollbar, style presets, and slots for a product's own secondary views (charts, a current-row card, raw responses, ...) and split-pane layout.
sidebar
Package sidebar is the right-hand working-context panel shared by every aichat chatshell: an ordered list of session.EntityRef, rendered by a product-supplied renderer, with a cursor, remove ("x"/Delete), open (Enter) and a resizable split width — generalised from DataTug chat's F6 workspace dock and Ctrl+←/→ split handling (ui.go splitEnabled/ resizeChatPane, workspace_ui.go).
Package sidebar is the right-hand working-context panel shared by every aichat chatshell: an ordered list of session.EntityRef, rendered by a product-supplied renderer, with a cursor, remove ("x"/Delete), open (Enter) and a resizable split width — generalised from DataTug chat's F6 workspace dock and Ctrl+←/→ split handling (ui.go splitEnabled/ resizeChatPane, workspace_ui.go).
stream
Package stream pumps an ai.LLMProvider's iter.Seq2[ai.Event, error] into Bubble Tea messages without buffering the response: each event arrives as an EventMsg carrying the tea.Cmd that re-arms the pump for the next event (the "channel re-arm" pattern DataTug chat used for HTTP/LLM streaming).
Package stream pumps an ai.LLMProvider's iter.Seq2[ai.Event, error] into Bubble Tea messages without buffering the response: each event arrives as an EventMsg carrying the tea.Cmd that re-arms the pump for the next event (the "channel re-arm" pattern DataTug chat used for HTTP/LLM streaming).
transcript
Package transcript renders the scrolling chat history shared by every aichat product: plain user/assistant messages, streamed assistant text and rich Block entries (e.g.
Package transcript renders the scrolling chat history shared by every aichat product: plain user/assistant messages, streamed assistant text and rich Block entries (e.g.

Jump to

Keyboard shortcuts

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