chat

package
v0.4.43-beta Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package chat implements shared persisted chat orchestration for Kodelet UIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 ApplyFragmentRestrictions

func ApplyFragmentRestrictions(ctx context.Context, llmConfig *llmtypes.Config, fragmentMetadata *fragments.Metadata)

func BuildState

func BuildState(
	ctx context.Context,
	llmConfig llmtypes.Config,
	sessionID string,
	workingDir string,
	mcpManager *tools.MCPManager,
	extensionRuntime *extensions.Runtime,
) (*tools.BasicState, error)

func ExpandCWDInput

func ExpandCWDInput(query, defaultCWD string) (string, error)

ExpandCWDInput expands user-entered working-directory text relative to a default cwd.

func ExpandSlashCommand

func ExpandSlashCommand(ctx context.Context, message string, cwd string) (string, *slashcommands.Expansion, error)

func IsNaturalDirectoryQuery

func IsNaturalDirectoryQuery(query string) bool

IsNaturalDirectoryQuery reports whether query is a bare directory name.

func NormalizeRequest

func NormalizeRequest(req ChatRequest) (string, []string, error)

func NormalizeRequestedProfile

func NormalizeRequestedProfile(profile string) string

func ResolveConfig

func ResolveConfig(ctx context.Context, conversationID, requestedProfile, requestedCWD, defaultCWDInput string) (llmtypes.Config, string, error)

func ResolveConfigForExistingConversation

func ResolveConfigForExistingConversation(record *conversationservice.GetConversationResponse) (llmtypes.Config, error)

func ResolveConfigForNewConversation

func ResolveConfigForNewConversation(requestedProfile string) (llmtypes.Config, error)

func ResolveConfiguredDefaultCWD

func ResolveConfiguredDefaultCWD(configuredCWD string) (string, error)

ResolveConfiguredDefaultCWD resolves a configured default working directory.

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 TransformSlashCommandIfNeeded

func TransformSlashCommandIfNeeded(ctx context.Context, message string, cwd string, enabled bool) (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 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"`
	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"`
	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

type ChatEventSink interface {
	Send(ChatEvent) error
}

ChatEventSink receives streamed chat events.

type ChatImageSource

type ChatImageSource struct {
	Data      string `json:"data"`
	MediaType string `json:"media_type"`
}

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"`
	Profile        string             `json:"profile,omitempty"`
	CWD            string             `json:"cwd,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 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) 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

Run executes a single persisted chat turn and streams events to the sink.

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 (ServiceStoreAdapter) Load

func (ServiceStoreAdapter) Query

func (ServiceStoreAdapter) Save

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

type UINotifyEvent struct {
	Title   string `json:"title,omitempty"`
	Message string `json:"message"`
}

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.

Jump to

Keyboard shortcuts

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