Documentation
¶
Overview ¶
Package chat implements shared persisted chat orchestration for Kodelet UIs.
Index ¶
- Constants
- func AddEnvironmentCommandDisplay(thread llmtypes.Thread, result agentenv.CommandResult)
- func AddExtensionCommandDisplay(thread llmtypes.Thread, result *extensions.RoutedCommandResult)
- func AddGoalDisplay(thread llmtypes.Thread, update *goals.CommandUpdate)
- func AddSlashCommandDisplay(thread llmtypes.Thread, expansion *slashcommands.Expansion)
- func ApplyCommandRestrictions(ctx context.Context, llmConfig *llmtypes.Config, result agentenv.CommandResult)
- func ApplyFragmentRestrictions(ctx context.Context, llmConfig *llmtypes.Config, ...)
- func BuildState(ctx context.Context, llmConfig llmtypes.Config, sessionID string, ...) (*tools.BasicState, error)
- func ExpandCWDInput(query, defaultCWD string) (string, error)
- func ExpandSlashCommand(ctx context.Context, message string, cwd string) (string, *slashcommands.Expansion, error)
- func IsNaturalDirectoryQuery(query string) bool
- func NormalizeEnvironmentProfile(profile string) string
- func NormalizeRequest(req ChatRequest) (string, []string, error)
- func NormalizeRequestedProfile(profile string) string
- func ResolveConfig(ctx context.Context, ...) (llmtypes.Config, string, error)
- func ResolveConfigForExistingConversation(record *conversationservice.GetConversationResponse, ...) (llmtypes.Config, error)
- func ResolveConfigForNewConversation(requestedProfile string, requestedReasoningEfforts ...string) (llmtypes.Config, error)
- func ResolveConfigWithReasoning(ctx context.Context, ...) (llmtypes.Config, string, error)
- func ResolveConfiguredDefaultCWD(configuredCWD string) (string, error)
- func ResolveExtensionCallContext(ctx context.Context, conversationID, cwd string, config llmtypes.Config) (extensions.ExtensionCallContext, error)
- func ResolveRemoteConfigWithReasoning(ctx context.Context, ...) (llmtypes.Config, error)
- func ResolveRemoteConfigWithReasoningAndEnvironmentProfile(ctx context.Context, ...) (llmtypes.Config, string, error)
- func RunDefaultChat(ctx context.Context, req ChatRequest, sink ChatEventSink, defaultCWD string, ...) (string, error)
- func TransformSlashCommand(ctx context.Context, message string, cwd string) (string, *slashcommands.Expansion, *goals.CommandUpdate, error)
- func TransformSlashCommandIfNeeded(ctx context.Context, message string, cwd string, enabled bool) (string, *slashcommands.Expansion, *goals.CommandUpdate, error)
- func TryExtensionCommand(ctx context.Context, message string, extensionRuntime *extensions.Runtime, ...) (*extensions.RoutedCommandResult, bool, error)
- type ChatClientCapabilities
- type ChatContentBlock
- type ChatEvent
- type ChatEventSink
- type ChatImageSource
- type ChatImageURLSource
- type ChatRequest
- type ChatRunner
- type ControlPlaneChatRunner
- func (r *ControlPlaneChatRunner) ChatSettings(ctx context.Context, profile string) (ControlPlaneChatSettings, error)
- func (r *ControlPlaneChatRunner) ListConversations(ctx context.Context, limit int) ([]convtypes.ConversationSummary, error)
- func (r *ControlPlaneChatRunner) LoadConversation(ctx context.Context, conversationID string) (ConversationHistory, error)
- func (r *ControlPlaneChatRunner) Run(ctx context.Context, request ChatRequest, sink ChatEventSink) (string, error)
- func (r *ControlPlaneChatRunner) SteerConversation(ctx context.Context, conversationID, message string) (bool, error)
- func (r *ControlPlaneChatRunner) StopConversation(ctx context.Context, conversationID string) error
- func (r *ControlPlaneChatRunner) StopConversationTurn(ctx context.Context, conversationID, turnID string) error
- type ControlPlaneChatSettings
- type ControlPlaneProfileOption
- type ConversationHistory
- type ConversationSource
- type DefaultChatRunner
- func (r *DefaultChatRunner) Close() error
- func (r *DefaultChatRunner) CloseConversation(conversationID string) error
- func (r *DefaultChatRunner) DefaultCWD() string
- func (r *DefaultChatRunner) ExtensionRuntimeProvider() ExtensionRuntimeProvider
- func (r *DefaultChatRunner) Run(ctx context.Context, req ChatRequest, sink ChatEventSink) (string, error)
- func (r *DefaultChatRunner) SetEnvironmentResolver(resolver EnvironmentResolver)
- type EnvironmentResolver
- type ExtensionRuntimeProvider
- type ServiceStoreAdapter
- func (s ServiceStoreAdapter) Close() error
- func (s ServiceStoreAdapter) Delete(context.Context, string) error
- func (s ServiceStoreAdapter) Load(ctx context.Context, id string) (convtypes.ConversationRecord, error)
- func (s ServiceStoreAdapter) Query(context.Context, convtypes.QueryOptions) (convtypes.QueryResult, error)
- func (s ServiceStoreAdapter) Save(context.Context, convtypes.ConversationRecord) error
- type UIConfirmEvent
- type UIInputEvent
- type UINotifyEvent
- type UISelectEvent
Constants ¶
const ( // RunnerIDMetadataKey identifies the remote runner that owns a conversation environment. RunnerIDMetadataKey = convtypes.RunnerIDMetadataKey // EnvironmentProfileMetadataKey stores the runner-owned profile independently from model policy. EnvironmentProfileMetadataKey = convtypes.RunnerEnvironmentProfileMetadataKey )
Variables ¶
This section is empty.
Functions ¶
func AddEnvironmentCommandDisplay ¶
func AddEnvironmentCommandDisplay(thread llmtypes.Thread, result agentenv.CommandResult)
AddEnvironmentCommandDisplay stores the compact display for an environment-routed command.
func AddExtensionCommandDisplay ¶
func AddExtensionCommandDisplay(thread llmtypes.Thread, result *extensions.RoutedCommandResult)
func AddGoalDisplay ¶
func AddGoalDisplay(thread llmtypes.Thread, update *goals.CommandUpdate)
func AddSlashCommandDisplay ¶
func AddSlashCommandDisplay(thread llmtypes.Thread, expansion *slashcommands.Expansion)
func ApplyCommandRestrictions ¶
func ApplyCommandRestrictions(ctx context.Context, llmConfig *llmtypes.Config, result agentenv.CommandResult)
ApplyCommandRestrictions applies model/tool restrictions returned by an environment command.
func BuildState ¶
func ExpandCWDInput ¶
ExpandCWDInput expands user-entered working-directory text relative to a default cwd.
func ExpandSlashCommand ¶
func IsNaturalDirectoryQuery ¶
IsNaturalDirectoryQuery reports whether query is a bare directory name.
func NormalizeEnvironmentProfile ¶
NormalizeEnvironmentProfile maps blank and the reserved default name to runner base configuration.
func NormalizeRequest ¶
func NormalizeRequest(req ChatRequest) (string, []string, error)
func ResolveConfig ¶
func ResolveConfigForExistingConversation ¶
func ResolveConfigForExistingConversation(record *conversationservice.GetConversationResponse, requestedReasoningEfforts ...string) (llmtypes.Config, error)
func ResolveConfiguredDefaultCWD ¶
ResolveConfiguredDefaultCWD resolves a configured default working directory.
func ResolveExtensionCallContext ¶
func ResolveExtensionCallContext(ctx context.Context, conversationID, cwd string, config llmtypes.Config) (extensions.ExtensionCallContext, error)
ResolveExtensionCallContext builds the extension context for an interactive operation, including the persisted origin of a resumed conversation.
func ResolveRemoteConfigWithReasoning ¶
func ResolveRemoteConfigWithReasoning(ctx context.Context, conversationID, requestedProfile, requestedReasoningEffort string) (llmtypes.Config, error)
ResolveRemoteConfigWithReasoning resolves only control-plane provider settings. The runner manifest supplies the authoritative workspace path and environment configuration.
func ResolveRemoteConfigWithReasoningAndEnvironmentProfile ¶
func ResolveRemoteConfigWithReasoningAndEnvironmentProfile(ctx context.Context, conversationID, requestedProfile, requestedReasoningEffort, requestedEnvironmentProfile string) (llmtypes.Config, string, error)
ResolveRemoteConfigWithReasoningAndEnvironmentProfile resolves central model policy and the independently locked runner profile.
func RunDefaultChat ¶
func RunDefaultChat(ctx context.Context, req ChatRequest, sink ChatEventSink, defaultCWD string, extensionRuntimes ExtensionRuntimeProvider) (string, error)
RunDefaultChat executes a single persisted chat turn and streams events to the sink.
func TransformSlashCommand ¶
func TransformSlashCommand(ctx context.Context, message string, cwd string) (string, *slashcommands.Expansion, *goals.CommandUpdate, error)
func TryExtensionCommand ¶
func TryExtensionCommand( ctx context.Context, message string, extensionRuntime *extensions.Runtime, llmConfig llmtypes.Config, conversationID string, workingDir string, ) (*extensions.RoutedCommandResult, bool, error)
Types ¶
type ChatClientCapabilities ¶
type ChatClientCapabilities struct {
InteractiveUI bool `json:"interactiveUI"`
PersistentSurfaces bool `json:"persistentSurfaces"`
}
ChatClientCapabilities describes UI behavior supported by the client attached to a chat run.
type ChatContentBlock ¶
type ChatContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Command string `json:"command,omitempty"`
Source *ChatImageSource `json:"source,omitempty"`
ImageURL *ChatImageURLSource `json:"image_url,omitempty"`
}
ChatContentBlock represents a typed chat content block.
func ContentBlocksForUserInput ¶
func ContentBlocksForUserInput(text string, imageInputs []string) []ChatContentBlock
type ChatEvent ¶
type ChatEvent struct {
Kind string `json:"kind"`
ConversationID string `json:"conversation_id,omitempty"`
ConversationName string `json:"conversation_name,omitempty"`
Role string `json:"role,omitempty"`
Delta string `json:"delta,omitempty"`
Content any `json:"content,omitempty"`
Usage *llmtypes.Usage `json:"usage,omitempty"`
ToolName string `json:"tool_name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
Input string `json:"input,omitempty"`
ToolOutput string `json:"tool_output,omitempty"`
ToolResult *tooltypes.StructuredToolResult `json:"tool_result,omitempty"`
UIInput *UIInputEvent `json:"ui_input,omitempty"`
UIConfirm *UIConfirmEvent `json:"ui_confirm,omitempty"`
UISelect *UISelectEvent `json:"ui_select,omitempty"`
UINotify *UINotifyEvent `json:"ui_notify,omitempty"`
Error string `json:"error,omitempty"`
}
ChatEvent is a single streaming chat event.
type ChatEventSink ¶
ChatEventSink receives streamed chat events.
type ChatImageSource ¶
ChatImageSource represents embedded image data.
func ParseDataURL ¶
func ParseDataURL(dataURL string) (*ChatImageSource, bool)
ParseDataURL parses a base64 data URL into a chat image source.
type ChatImageURLSource ¶
type ChatImageURLSource struct {
URL string `json:"url"`
}
ChatImageURLSource represents URL-based image input.
type ChatRequest ¶
type ChatRequest struct {
Message string `json:"message"`
Content []ChatContentBlock `json:"content,omitempty"`
ConversationID string `json:"conversationId,omitempty"`
TurnID string `json:"turnId,omitempty"`
RunnerID string `json:"runnerId,omitempty"`
Profile string `json:"profile,omitempty"`
EnvironmentProfile string `json:"environmentProfile,omitempty"`
ReasoningEffort string `json:"reasoningEffort,omitempty"`
CWD string `json:"cwd,omitempty"`
ClientCapabilities *ChatClientCapabilities `json:"clientCapabilities,omitempty"`
}
ChatRequest is the payload for a streamed chat turn.
type ChatRunner ¶
type ChatRunner interface {
Run(ctx context.Context, req ChatRequest, sink ChatEventSink) (string, error)
}
ChatRunner executes a single persisted chat turn.
type ControlPlaneChatRunner ¶
type ControlPlaneChatRunner struct {
// contains filtered or unexported fields
}
ControlPlaneChatRunner streams chat turns and conversation history through kodelet serve.
func NewControlPlaneChatRunner ¶
func NewControlPlaneChatRunner(server, authToken, runnerID string) (*ControlPlaneChatRunner, error)
NewControlPlaneChatRunner creates a TUI-compatible control-plane transport with an optional runner selection.
func (*ControlPlaneChatRunner) ChatSettings ¶
func (r *ControlPlaneChatRunner) ChatSettings(ctx context.Context, profile string) (ControlPlaneChatSettings, error)
ChatSettings fetches control-plane model profiles and reasoning policy.
func (*ControlPlaneChatRunner) ListConversations ¶
func (r *ControlPlaneChatRunner) ListConversations(ctx context.Context, limit int) ([]convtypes.ConversationSummary, error)
ListConversations returns control-plane conversations visible to this client.
func (*ControlPlaneChatRunner) LoadConversation ¶
func (r *ControlPlaneChatRunner) LoadConversation(ctx context.Context, conversationID string) (ConversationHistory, error)
LoadConversation returns normalized history from the control plane.
func (*ControlPlaneChatRunner) Run ¶
func (r *ControlPlaneChatRunner) Run(ctx context.Context, request ChatRequest, sink ChatEventSink) (string, error)
Run posts one chat request and forwards NDJSON events to the TUI sink.
func (*ControlPlaneChatRunner) SteerConversation ¶
func (r *ControlPlaneChatRunner) SteerConversation(ctx context.Context, conversationID, message string) (bool, error)
SteerConversation queues a steering message in the control plane that owns the active provider loop.
func (*ControlPlaneChatRunner) StopConversation ¶
func (r *ControlPlaneChatRunner) StopConversation(ctx context.Context, conversationID string) error
StopConversation requests cancellation of central and runner work before the client stream closes.
func (*ControlPlaneChatRunner) StopConversationTurn ¶
func (r *ControlPlaneChatRunner) StopConversationTurn(ctx context.Context, conversationID, turnID string) error
StopConversationTurn requests cancellation of one specific control-plane turn.
type ControlPlaneChatSettings ¶
type ControlPlaneChatSettings struct {
CurrentProfile string `json:"currentProfile,omitempty"`
Profiles []ControlPlaneProfileOption `json:"profiles"`
ReasoningEffort string `json:"reasoningEffort"`
ReasoningEffortOptions []string `json:"reasoningEffortOptions"`
DefaultCWD string `json:"defaultCWD,omitempty"`
}
ControlPlaneChatSettings contains server-owned settings for a new conversation.
type ControlPlaneProfileOption ¶
type ControlPlaneProfileOption struct {
Name string `json:"name"`
Scope string `json:"scope"`
Active bool `json:"active,omitempty"`
}
ControlPlaneProfileOption describes one model-policy profile advertised by the server.
type ConversationHistory ¶
type ConversationHistory struct {
ID string
CWD string
Title string
Provider string
Profile string
ReasoningEffort string
RunnerID string
EnvironmentProfile string
UpdatedAt time.Time
Usage llmtypes.Usage
Messages []conversationservice.StreamableMessage
}
ConversationHistory is the client-facing persisted state needed to resume a conversation.
type ConversationSource ¶
type ConversationSource interface {
ListConversations(ctx context.Context, limit int) ([]convtypes.ConversationSummary, error)
LoadConversation(ctx context.Context, conversationID string) (ConversationHistory, error)
}
ConversationSource supplies persisted conversation summaries and normalized history to a chat client.
type DefaultChatRunner ¶
type DefaultChatRunner struct {
// contains filtered or unexported fields
}
DefaultChatRunner executes chat turns using the same LLM/tool stack as the CLI.
func NewDefaultChatRunner ¶
func NewDefaultChatRunner(defaultCWD string, extensionRuntimes ...ExtensionRuntimeProvider) *DefaultChatRunner
NewDefaultChatRunner creates a default chat runner.
func (*DefaultChatRunner) Close ¶
func (r *DefaultChatRunner) Close() error
Close releases cached conversation threads and their persistent transports.
func (*DefaultChatRunner) CloseConversation ¶
func (r *DefaultChatRunner) CloseConversation(conversationID string) error
CloseConversation releases a cached thread when its conversation is removed.
func (*DefaultChatRunner) DefaultCWD ¶
func (r *DefaultChatRunner) DefaultCWD() string
DefaultCWD returns the runner's configured default working directory.
func (*DefaultChatRunner) ExtensionRuntimeProvider ¶
func (r *DefaultChatRunner) ExtensionRuntimeProvider() ExtensionRuntimeProvider
ExtensionRuntimeProvider returns the runner's configured extension runtime provider.
func (*DefaultChatRunner) Run ¶
func (r *DefaultChatRunner) Run(ctx context.Context, req ChatRequest, sink ChatEventSink) (string, error)
Run executes a single persisted chat turn and streams events to the sink.
func (*DefaultChatRunner) SetEnvironmentResolver ¶
func (r *DefaultChatRunner) SetEnvironmentResolver(resolver EnvironmentResolver)
SetEnvironmentResolver configures remote environment selection for subsequent requests.
type EnvironmentResolver ¶
type EnvironmentResolver interface {
ResolveEnvironment(ctx context.Context, req ChatRequest, conversationID string, config llmtypes.Config, resolvedCWD string) (agentenv.Environment, error)
}
EnvironmentResolver optionally selects a non-local environment for a chat request.
type ExtensionRuntimeProvider ¶
type ExtensionRuntimeProvider interface {
Runtime(ctx context.Context, cwd string) (*extensions.Runtime, error)
}
ExtensionRuntimeProvider supplies extension runtimes for chat turns.
type ServiceStoreAdapter ¶
type ServiceStoreAdapter struct {
Service conversationservice.ConversationServiceInterface
}
func (ServiceStoreAdapter) Close ¶
func (s ServiceStoreAdapter) Close() error
func (ServiceStoreAdapter) Delete ¶
func (s ServiceStoreAdapter) Delete(context.Context, string) error
func (ServiceStoreAdapter) Load ¶
func (s ServiceStoreAdapter) Load(ctx context.Context, id string) (convtypes.ConversationRecord, error)
func (ServiceStoreAdapter) Query ¶
func (s ServiceStoreAdapter) Query(context.Context, convtypes.QueryOptions) (convtypes.QueryResult, error)
func (ServiceStoreAdapter) Save ¶
func (s ServiceStoreAdapter) Save(context.Context, convtypes.ConversationRecord) error
type UIConfirmEvent ¶
type UIConfirmEvent struct {
ID string `json:"id"`
Title string `json:"title"`
Message string `json:"message,omitempty"`
ConfirmButtonText string `json:"confirmButtonText,omitempty"`
CancelButtonText string `json:"cancelButtonText,omitempty"`
}
UIConfirmEvent describes an extension-requested confirmation prompt.
type UIInputEvent ¶
type UIInputEvent struct {
ID string `json:"id"`
Title string `json:"title"`
HelpText string `json:"helpText,omitempty"`
Message string `json:"message,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
DefaultValue string `json:"defaultValue,omitempty"`
SubmitButtonText string `json:"submitButtonText,omitempty"`
CancelButtonText string `json:"cancelButtonText,omitempty"`
Required bool `json:"required,omitempty"`
Secret bool `json:"secret,omitempty"`
}
UIInputEvent describes an extension-requested input prompt.
type UINotifyEvent ¶
UINotifyEvent describes an extension-requested notification.
type UISelectEvent ¶
type UISelectEvent struct {
ID string `json:"id"`
Title string `json:"title"`
Message string `json:"message,omitempty"`
Options []string `json:"options"`
SubmitButtonText string `json:"submitButtonText,omitempty"`
CancelButtonText string `json:"cancelButtonText,omitempty"`
}
UISelectEvent describes an extension-requested single-choice prompt.