chat

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package chat installs the in-app Kiln chat panel. The panel is a small vanilla-JS UI mounted under /kiln/* on Live's auxiliary router so it survives world rebuilds. It speaks to the host via:

GET  /kiln/chat              the panel HTML
GET  /kiln/chat/panel.js     the panel runtime
GET  /kiln/chat/panel.css    the panel stylesheet
GET  /kiln/world             current Session as JSON
POST /kiln/chat/message      shortcut for tools.Chat
POST /kiln/tool/{name}       generic tool dispatch
GET  /.kiln/events           live SSE stream of session events

The panel itself does not need world IR coverage — it's the host's own surface, not something the agent edits. Kiln-built apps still drive the panel by issuing tool calls; the panel is just the eyes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HostHTML

func HostHTML() string

HostHTML is the empty-state shell. Returned to any unmatched HTML request so the floating widget is always reachable. The embedded HTML uses placeholders we substitute at serve time:

__KILN_BASE__   the server's scheme+host (per-request when possible)
__KILN_LEAD__   the welcome paragraph (adapts to current world)
the runtime <script> tag (hashed for cache-busting)

HostHTML hard-codes localhost:8765 + the empty-world lead so non- request callers (chat tests, snapshots) still produce a complete page. For live serving with a Live runtime, prefer HostHTMLForLive.

func HostHTMLForLive

func HostHTMLForLive(l *live.Live) func(*http.Request) string

HostHTMLForLive is HostHTMLForRequest with the lead paragraph computed from the Live runtime's current world: empty world → the default copy; non-empty → a per-noun summary so visitors see what the agent has built without opening the panel.

func HostHTMLForRequest

func HostHTMLForRequest(r *http.Request) string

HostHTMLForRequest is HostHTML with __KILN_BASE__ substituted from the actual incoming request's scheme + host. Lead text stays the empty-world message — for world-aware lead use HostHTMLForLive.

func MountPanel

func MountPanel(r *router.Router, l *live.Live, tools *protocol.Tools, agentState AgentStateFn)

MountPanel registers the kiln chat panel as a core-ui/widget on r. The widget is a framework-managed FloatingPanel; kiln contributes:

  • slot HTML for header / log / input (rendered server-side from session)
  • a 2s /state poll that keeps the chat_html/agent/world signals fresh
  • RPC handlers for chat send, reset, approve/reject, agent control

agentState is read by the gear modal's agent_list_html signal at mount time so the user sees the actual adapter list (claude-code, omp, claude-code, pi, codex, ...) instead of a Loading… placeholder. nil → no list.

All bespoke kiln widget plumbing (vanilla JS DOM, hand-rolled CSS, per-route HTTP handlers) is replaced by this single declaration.

func WidgetTag

func WidgetTag() string

WidgetTag returns the script tag to embed the floating panel on a page. Delegates to widget.RuntimeTag so the URL gets a content-hash cache-bust query param — fresh build invalidates any cached runtime in the browser.

Types

type AgentStateFn

type AgentStateFn func() any

AgentStateFn returns the JSON-shaped agent state consumed by the gear modal. Shape: { current: {name, display}, available: [{name, display, installed}, ...], in_flight: bool }. Concretely supplied by cmd/kiln (which owns the AdapterStore); kept as a callback so the chat package doesn't depend on cmd/kiln. Pass nil to render an empty modal (development / tests without an adapter registry).

type Server

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

Server hosts the in-app Kiln surfaces: the floating widget assets, the world-state JSON endpoint, the tool dispatcher, and the SSE bus.

func New

func New(l *live.Live, t *protocol.Tools) *Server

New constructs a chat Server.

func (*Server) Mount

func (s *Server) Mount(r *router.Router)

Mount registers the panel routes onto r. The host fallback page is NOT mounted here — kiln/render installs it as the rebuilt app's NotFound handler so every URL not otherwise claimed shows the widget.

Jump to

Keyboard shortcuts

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