Documentation
¶
Overview ¶
Package nekit is the ready-made chat widget for neui. Render it on a doors page:
~nekit.Chat{Disable: nekit.ChatSimple}
It shows a disabled chat until neui.Enable succeeds for the page's session, and again after neui.Disable. Chat.Disable hides parts of the UI, with ChatSimple as the preset for non-technical users, and ThemeDark and ThemeLight recolour it. ModuleAsk adds a tool that lets the agent ask the user to pick from a list inside the chat.
Package nekit is the ready-made widget set for neui islands: layouts, markdown, forms, tables and buttons. Register them on Island.Library:
Library: nekit.IslandRegisterAll
NewSQLiteMessages keeps the threads of all users in one SQLite database that the host opens with a driver of its choice, and User gives each session its user's part:
import _ "modernc.org/sqlite"
db, err := sql.Open("sqlite", "neui.db")
store, err := nekit.NewSQLiteMessages(db)
neui.Enable(ctx, neui.OptionMessageStorage(store.User(userID)))
Index ¶
- Constants
- Variables
- func AskOptions(input AskInput, answer common.Answer[AskOutput]) api.ChatAsk
- func IslandColumn(p IslandColumnParams, children []gox.Comp) gox.Comp
- func IslandGrid(p IslandGridParams, children []gox.Comp) gox.Comp
- func IslandRegisterAll(l neui.Library) error
- func IslandRegisterButton(l neui.Library) error
- func IslandRegisterForm(l neui.Library) error
- func IslandRegisterLayout(l neui.Library) error
- func IslandRegisterMarkdown(l neui.Library) error
- func IslandRegisterTable(l neui.Library) error
- func IslandRegisterWidgets(l neui.Library) error
- func IslandRow(p IslandRowParams, children []gox.Comp) gox.Comp
- func IslandStyle() gox.Elem
- func ModuleAsk() common.ModuleFactory
- func NewIslandButton(ctx context.Context, p IslandButtonParams, ...) (api.Widget[IslandButtonPatch], error)
- func NewIslandForm(ctx context.Context, p IslandFormParams, ...) (api.Widget[IslandFormPatch], error)
- func NewIslandMarkdown(ctx context.Context, p IslandMarkdownParams) (api.Widget[IslandMarkdownPatch], error)
- func NewIslandTable(ctx context.Context, p IslandTableParams, ...) (api.Widget[IslandTablePatch], error)
- type AskInput
- type AskOption
- type AskOutput
- type Chat
- type ChatFeature
- type ChatLayout
- type ChatSide
- type ChatTheme
- type DiskUploads
- type IslandButtonParams
- type IslandButtonPatch
- type IslandColumnParams
- type IslandFormParams
- type IslandFormPatch
- type IslandGridParams
- type IslandMarkdownParams
- type IslandMarkdownPatch
- type IslandRowParams
- type IslandTableParams
- type IslandTablePatch
- type IslandTableSubmit
- type S3Uploads
- type SQLiteMessages
Constants ¶
const ( // ChatRight puts the chat at the right edge, the default. ChatRight = ChatSide(css.Right) // ChatLeft puts the chat at the left edge. ChatLeft = ChatSide(css.Left) )
const ( // ChatTokens hides the context gauge, token counts and the Compact now button; a plain "compacting" chip still shows while compaction runs. ChatTokens = ChatFeature(params.Tokens) // ChatThinking hides reasoning and summary blocks and the Reasoning stat. ChatThinking = ChatFeature(params.Thinking) // ChatTools hides tool call blocks and pinned record counts. ChatTools = ChatFeature(params.Tools) // ChatTasks hides the background task chip and popover; the run chip shows "working" while only tasks run. ChatTasks = ChatFeature(params.Tasks) // ChatEdit hides the edit-and-resend button on user messages. ChatEdit = ChatFeature(params.Edit) // ChatRetry hides the retry button on failed rounds. ChatRetry = ChatFeature(params.Retry) // ChatAttachments hides the attach button and tray; large pastes stay in the draft as text. ChatAttachments = ChatFeature(params.Attachments) // // ChatFiles hides the files popover in the top bar. // ChatFiles = ChatFeature(params.Files) // ChatSidebar hides the chat list sidebar and its menu button. ChatSidebar = ChatFeature(params.Sidebar) // ChatThreadEdit hides rename, clone and delete in the chat list. ChatThreadEdit = ChatFeature(params.ThreadEdit) // ChatMessageSearch limits search to chat names; message contents are not searched. ChatMessageSearch = ChatFeature(params.MessageSearch) // ChatGreeting hides the greeting a new chat shows before its first message. ChatGreeting = ChatFeature(params.Greeting) // ChatDock hides the dock button, so the chat only floats. ChatDock = ChatFeature(params.Dock) )
const ( IslandColumnDesc = layout.ColumnDesc IslandRowDesc = layout.RowDesc IslandGridDesc = layout.GridDesc )
IslandColumnDesc, IslandRowDesc and IslandGridDesc describe IslandColumn, IslandRow and IslandGrid to the agent, for Library.Layout.
const ( IslandMarkdownDesc = markdown.Desc IslandFormDesc = form.Desc IslandTableDesc = table.Desc )
IslandMarkdownDesc, IslandFormDesc and IslandTableDesc describe the markdown view and the form and table controls to the agent, for Library.View and Library.Control. Button needs no description beyond its schema.
Variables ¶
var ChatSimple = []ChatFeature{ChatTokens, ChatThinking, ChatTools, ChatTasks}
ChatSimple is the preset for non-technical users. It grows as technical features are added.
Functions ¶
func AskOptions ¶
AskOptions is the Ask handler behind ModuleAsk. It builds the form and send button for input. When the user sends with Enter or the button, it submits an AskOutput to answer, but only if at least one option is picked or own text is selected, and the own text is within 256 KiB. Use it to add the same question to a module of your own with neui.Module.Ask.
func IslandColumn ¶
func IslandColumn(p IslandColumnParams, children []gox.Comp) gox.Comp
IslandColumn stacks children top to bottom, for Library.Layout.
func IslandGrid ¶
func IslandGrid(p IslandGridParams, children []gox.Comp) gox.Comp
IslandGrid places children in equal-width cells, for Library.Layout.
func IslandRegisterAll ¶
IslandRegisterAll registers every layout and widget and adds IslandStyle to the head.
func IslandRegisterButton ¶
IslandRegisterButton registers the control button and adds IslandStyle to the head.
func IslandRegisterForm ¶
IslandRegisterForm registers the control form and adds IslandStyle to the head.
func IslandRegisterLayout ¶
IslandRegisterLayout registers the layouts column, row and grid and adds IslandStyle to the head.
func IslandRegisterMarkdown ¶
IslandRegisterMarkdown registers the view markdown and adds IslandStyle to the head.
func IslandRegisterTable ¶
IslandRegisterTable registers the control table and adds IslandStyle to the head.
func IslandRegisterWidgets ¶
IslandRegisterWidgets registers the widgets markdown, form, table and button and adds IslandStyle to the head.
func IslandRow ¶
func IslandRow(p IslandRowParams, children []gox.Comp) gox.Comp
IslandRow places children side by side, for Library.Layout.
func IslandStyle ¶
IslandStyle is the stylesheet of the layouts and widgets. Every IslandRegister function adds it to Library.Head, and it renders once per island app. Spacing and grid cell widths read --neisland-gap-sm, -md, -lg and --neisland-item-sm, -md, -lg, so a host can override them in CSS; a fill column wraps onto the next line rather than get narrower than --neisland-item-md.
func ModuleAsk ¶
func ModuleAsk() common.ModuleFactory
ModuleAsk is the built-in module that lets the agent ask the user to pick from a list, rendered in the chat by Chat. Register it with neui.WithModules or neui.OptionModules:
neui.Enable(ctx, neui.OptionModules(nekit.ModuleAsk()))
func NewIslandButton ¶
func NewIslandButton(ctx context.Context, p IslandButtonParams, submit func(ctx context.Context, value string) bool) (api.Widget[IslandButtonPatch], error)
NewIslandButton builds a button control, for Library.Control.
func NewIslandForm ¶
func NewIslandForm(ctx context.Context, p IslandFormParams, submit func(ctx context.Context, s map[string]any) bool) (api.Widget[IslandFormPatch], error)
NewIslandForm builds a form control, for Library.Control.
func NewIslandMarkdown ¶
func NewIslandMarkdown(ctx context.Context, p IslandMarkdownParams) (api.Widget[IslandMarkdownPatch], error)
NewIslandMarkdown builds a markdown view, for Library.View.
func NewIslandTable ¶
func NewIslandTable(ctx context.Context, p IslandTableParams, submit func(ctx context.Context, s IslandTableSubmit) bool) (api.Widget[IslandTablePatch], error)
NewIslandTable builds a table control, for Library.Control.
Types ¶
type AskInput ¶
AskInput is what the agent sends to the ask tool: a question and the answers to offer.
type AskOutput ¶
AskOutput is the user's answer as the agent receives it. At least one of Picked and Typed is set.
type Chat ¶
Chat is the ready-made chat widget: the chat list sidebar, the thread, the composer and its popovers. Render it on a page as ~nekit.Chat{}; the zero value is a complete chat. It fills its container, so give that container a height.
type ChatFeature ¶
ChatFeature is a part of the chat UI that can be hidden from the user.
type ChatLayout ¶
ChatLayout sets where the chat sits and how big it is; set it as Chat.Layout. Lengths are CSS lengths such as "30rem" (px, rem, em, vw, vh or %); an empty or invalid one keeps the default. On screens under 40rem wide the open chat fills the screen.
type ChatTheme ¶
ChatTheme overrides colours of the built-in palette for one face, dark or light; set it as Chat.ThemeDark or Chat.ThemeLight.
type DiskUploads ¶
DiskUploads keeps uploaded files in a directory on the local disk, where they survive restarts. Plug it in with neui.WithUploadStorage or neui.OptionUploadStorage.
func NewDiskUploads ¶
func NewDiskUploads(path string) (DiskUploads, error)
NewDiskUploads stores files under path, creating it if missing; it fails when path is not a writable directory. Open a directory from one process only: opening discards unfinished uploads.
type IslandButtonParams ¶
IslandButtonParams is what a script passes to ui.button.
type IslandButtonPatch ¶
IslandButtonPatch is what a script passes to update a button.
type IslandColumnParams ¶
type IslandColumnParams = layout.ColumnParams
IslandColumnParams is what a script passes to ui.column.
type IslandFormParams ¶
IslandFormParams is what a script passes to ui.form.
type IslandFormPatch ¶
IslandFormPatch is the form's update: it takes none.
type IslandGridParams ¶
type IslandGridParams = layout.GridParams
IslandGridParams is what a script passes to ui.grid.
type IslandMarkdownParams ¶
IslandMarkdownParams is what a script passes to ui.markdown.
type IslandMarkdownPatch ¶
IslandMarkdownPatch is what a script passes to update a markdown view.
type IslandRowParams ¶
IslandRowParams is what a script passes to ui.row.
type IslandTableParams ¶
IslandTableParams is what a script passes to ui.table.
type IslandTablePatch ¶
IslandTablePatch is what a script passes to update a table.
type IslandTableSubmit ¶
IslandTableSubmit is what a table hands the script waiting in ui.draw().
type S3Uploads ¶
S3Uploads keeps uploaded files in an S3-compatible bucket. Plug it in with neui.WithUploadStorage or neui.OptionUploadStorage. The service must support conditional writes (If-None-Match), as AWS S3 and MinIO do.
type SQLiteMessages ¶
SQLiteMessages keeps every user's threads in one SQLite database. Give each session its user's part with User. Uploaded files are not stored here; set neui.OptionUploadStorage for them.
func NewSQLiteMessages ¶
func NewSQLiteMessages(db *sql.DB) (SQLiteMessages, error)
NewSQLiteMessages creates or migrates neui's tables in db and turns on WAL; it refuses a database written by a newer neui. Import a driver, open db and close it after the app stops. Give neui a database file of its own: the schema version is kept in PRAGMA user_version.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
chat/css
Package css holds the nechat stylesheet and its theme overrides.
|
Package css holds the nechat stylesheet and its theme overrides. |
|
chat/params
Package params carries nekit chat settings through the widget's components.
|
Package params carries nekit chat settings through the widget's components. |