nekit

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

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

View Source
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)
)
View Source
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)
)
View Source
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.

View Source
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

ChatSimple is the preset for non-technical users. It grows as technical features are added.

Functions

func AskOptions

func AskOptions(input AskInput, answer common.Answer[AskOutput]) api.ChatAsk

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

func IslandRegisterAll(l neui.Library) error

IslandRegisterAll registers every layout and widget and adds IslandStyle to the head.

func IslandRegisterButton

func IslandRegisterButton(l neui.Library) error

IslandRegisterButton registers the control button and adds IslandStyle to the head.

func IslandRegisterForm

func IslandRegisterForm(l neui.Library) error

IslandRegisterForm registers the control form and adds IslandStyle to the head.

func IslandRegisterLayout

func IslandRegisterLayout(l neui.Library) error

IslandRegisterLayout registers the layouts column, row and grid and adds IslandStyle to the head.

func IslandRegisterMarkdown

func IslandRegisterMarkdown(l neui.Library) error

IslandRegisterMarkdown registers the view markdown and adds IslandStyle to the head.

func IslandRegisterTable

func IslandRegisterTable(l neui.Library) error

IslandRegisterTable registers the control table and adds IslandStyle to the head.

func IslandRegisterWidgets

func IslandRegisterWidgets(l neui.Library) error

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

func IslandStyle() gox.Elem

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

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

type AskInput = chat.AskInput

AskInput is what the agent sends to the ask tool: a question and the answers to offer.

type AskOption

type AskOption = chat.AskOption

AskOption is one answer the user can pick in an AskOptions question.

type AskOutput

type AskOutput = chat.AskOutput

AskOutput is the user's answer as the agent receives it. At least one of Picked and Typed is set.

type Chat

type Chat = chat.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

type ChatFeature = params.Feature

ChatFeature is a part of the chat UI that can be hidden from the user.

type ChatLayout

type ChatLayout = css.Layout

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 ChatSide

type ChatSide = css.Side

ChatSide is the page edge the chat sits at.

type ChatTheme

type ChatTheme = css.Theme

ChatTheme overrides colours of the built-in palette for one face, dark or light; set it as Chat.ThemeDark or Chat.ThemeLight.

type DiskUploads

type DiskUploads = *disk.Store

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

type IslandButtonParams = button.Params

IslandButtonParams is what a script passes to ui.button.

type IslandButtonPatch

type IslandButtonPatch = button.Patch

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

type IslandFormParams = form.Params

IslandFormParams is what a script passes to ui.form.

type IslandFormPatch

type IslandFormPatch = form.Patch

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

type IslandMarkdownParams = markdown.Params

IslandMarkdownParams is what a script passes to ui.markdown.

type IslandMarkdownPatch

type IslandMarkdownPatch = markdown.Patch

IslandMarkdownPatch is what a script passes to update a markdown view.

type IslandRowParams

type IslandRowParams = layout.RowParams

IslandRowParams is what a script passes to ui.row.

type IslandTableParams

type IslandTableParams = table.Params

IslandTableParams is what a script passes to ui.table.

type IslandTablePatch

type IslandTablePatch = table.Patch

IslandTablePatch is what a script passes to update a table.

type IslandTableSubmit

type IslandTableSubmit = table.Submit

IslandTableSubmit is what a table hands the script waiting in ui.draw().

type S3Uploads

type S3Uploads = *s3.Store

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.

func NewS3Uploads

func NewS3Uploads(client *minio.Client, bucket, prefix string) S3Uploads

NewS3Uploads stores files in bucket under prefix, "" for the bucket root. Build client with minio.New for your endpoint and credentials; the bucket must exist. Each upload buffers up to 16 MiB in memory.

type SQLiteMessages

type SQLiteMessages = *sqlite.Store

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.
s3

Jump to

Keyboard shortcuts

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