chat

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: EUPL-1.2 Imports: 22 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(optionFns ...func(*Options)) func(*core.Core) core.Result
Example
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
	writeSSE(w,
		`{"id":"chatcmpl-1","choices":[{"delta":{"content":"Hello from chat"}}]}`,
		`{"id":"chatcmpl-1","choices":[{"finish_reason":"stop"}]}`,
		`[DONE]`,
	)
}))
defer server.Close()

storeDir, err := coreMkdirTemp("", "chat-example-*")
if err != nil {
	panic(err)
}
defer coreRemoveAll(storeDir)

c := core.New(
	core.WithService(Register(
		func(o *Options) { o.APIURL = server.URL },
		func(o *Options) { o.StorePath = core.PathJoin(storeDir, "chat.db") },
		func(o *Options) { o.ToolExecutor = &mockToolExecutor{} },
		func(o *Options) { o.Now = func() time.Time { return time.Unix(1_700_000_000, 0).UTC() } },
	)),
	core.WithServiceLock(),
)
if !c.ServiceStartup(context.Background(), nil).OK {
	panic("chat startup failed")
}

send := c.Action("gui.chat.send").Run(context.Background(), core.NewOptions(
	core.Option{Key: "content", Value: "Hello"},
))
if !send.OK {
	panic(send.Value)
}

conversations := c.Action("gui.chat.conversations.list").Run(context.Background(), core.NewOptions())
history := c.Action("gui.chat.history").Run(context.Background(), core.NewOptions(
	core.Option{Key: "conversation_id", Value: conversations.Value.([]Conversation)[0].ID},
))

core.Println(len(history.Value.([]Message)))
core.Println(history.Value.([]Message)[1].Content)
Output:
2
Hello from chat

Types

type ActionConversationCleared

type ActionConversationCleared struct {
	ConversationID string `json:"conversation_id"`
}

type ActionConversationCreated

type ActionConversationCreated struct {
	Conversation Conversation `json:"conversation"`
}

type ActionConversationDeleted

type ActionConversationDeleted struct {
	ConversationID string `json:"conversation_id"`
}

type ActionConversationUpdated

type ActionConversationUpdated struct {
	Conversation Conversation `json:"conversation"`
}

type ActionImageQueued

type ActionImageQueued struct {
	ConversationID string          `json:"conversation_id"`
	Attachment     ImageAttachment `json:"attachment"`
}

type ActionMessageAdded

type ActionMessageAdded struct {
	ConversationID string  `json:"conversation_id"`
	Message        Message `json:"message"`
}

type ActionStreamFinished

type ActionStreamFinished struct {
	ConversationID string `json:"conversation_id"`
	MessageID      string `json:"message_id"`
	FinishReason   string `json:"finish_reason,omitempty"`
}

type ActionStreamStarted

type ActionStreamStarted struct {
	ConversationID string `json:"conversation_id"`
	MessageID      string `json:"message_id"`
	StreamID       string `json:"stream_id"`
}

type ActionThinkingAppended

type ActionThinkingAppended struct {
	ConversationID string `json:"conversation_id"`
	MessageID      string `json:"message_id"`
	Content        string `json:"content"`
}

type ActionThinkingEnded

type ActionThinkingEnded struct {
	ConversationID string `json:"conversation_id"`
	MessageID      string `json:"message_id"`
	DurationMS     int64  `json:"duration_ms"`
}

type ActionThinkingStarted

type ActionThinkingStarted struct {
	ConversationID string    `json:"conversation_id"`
	MessageID      string    `json:"message_id"`
	StartedAt      time.Time `json:"started_at"`
}

type ActionTokenAppended

type ActionTokenAppended struct {
	ConversationID string `json:"conversation_id"`
	MessageID      string `json:"message_id"`
	Content        string `json:"content"`
}

type ActionToolCallStarted

type ActionToolCallStarted struct {
	ConversationID string   `json:"conversation_id"`
	MessageID      string   `json:"message_id"`
	Call           ToolCall `json:"call"`
}

type ActionToolResultReady

type ActionToolResultReady struct {
	ConversationID string     `json:"conversation_id"`
	MessageID      string     `json:"message_id"`
	Result         ToolResult `json:"result"`
}

type ChatMessage

type ChatMessage = Message

ChatMessage aliases Message to preserve the original public IPC type name.

type ChatSettings

type ChatSettings struct {
	Temperature   float32 `json:"temperature"`
	TopP          float32 `json:"top_p"`
	TopK          int     `json:"top_k"`
	MaxTokens     int     `json:"max_tokens"`
	ContextWindow int     `json:"context_window"`
	SystemPrompt  string  `json:"system_prompt"`
	DefaultModel  string  `json:"default_model"`
}

func DefaultSettings

func DefaultSettings() ChatSettings

type Conversation

type Conversation struct {
	ID        string        `json:"id"`
	Title     string        `json:"title"`
	Model     string        `json:"model"`
	CreatedAt time.Time     `json:"created_at"`
	UpdatedAt time.Time     `json:"updated_at"`
	Messages  []Message     `json:"messages"`
	Settings  *ChatSettings `json:"settings,omitempty"`
}

func (Conversation) Summary

func (c Conversation) Summary() ConversationSummary

type ConversationSummary

type ConversationSummary struct {
	ID           string    `json:"id"`
	Title        string    `json:"title"`
	Model        string    `json:"model"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	MessageCount int       `json:"message_count"`
}

type ImageAttachment

type ImageAttachment struct {
	Filename string `json:"filename"`
	MimeType string `json:"mime_type"`
	Data     string `json:"data"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
}

type Message

type Message struct {
	ID           string            `json:"id"`
	Role         string            `json:"role"`
	Content      string            `json:"content"`
	CreatedAt    time.Time         `json:"created_at"`
	Model        string            `json:"model,omitempty"`
	Attachments  []ImageAttachment `json:"attachments,omitempty"`
	Thinking     *ThinkingState    `json:"thinking,omitempty"`
	ToolCalls    []ToolCall        `json:"tool_calls,omitempty"`
	ToolResults  []ToolResult      `json:"tool_results,omitempty"`
	ToolCallID   string            `json:"tool_call_id,omitempty"`
	FinishReason string            `json:"finish_reason,omitempty"`
}

Message is the persisted chat transcript entry used by the MVP IPC surface.

type Model

type Model struct {
	Name           string `json:"name"`
	Size           int64  `json:"size"` // Size mirrors SizeBytes for legacy clients that read the original field.
	Status         string `json:"status"`
	Architecture   string `json:"architecture,omitempty"`
	QuantBits      int    `json:"quant_bits,omitempty"`
	SizeBytes      int64  `json:"size_bytes,omitempty"` // SizeBytes is the exact model size in bytes.
	Loaded         bool   `json:"loaded,omitempty"`
	Backend        string `json:"backend,omitempty"`
	SupportsVision bool   `json:"supports_vision,omitempty"`
}

Model is the transport shape exposed by gui.chat.models.

type ModelEntry

type ModelEntry = Model

ModelEntry aliases Model for backwards-compatible model list APIs.

type Options

type Options struct {
	APIURL       string
	StorePath    string
	HTTPClient   *http.Client
	ModelRoots   []string
	ToolExecutor ToolExecutor
	Now          func() time.Time
}

type QueryConversationGet

type QueryConversationGet struct {
	ConversationID string `json:"conversation_id,omitempty"`
	ID             string `json:"id,omitempty"`
}

type QueryConversationList

type QueryConversationList struct{}

type QueryConversationSearch

type QueryConversationSearch struct {
	Query string `json:"q"`
}

type QueryHistory

type QueryHistory struct {
	ConversationID string `json:"conversation_id,omitempty"`
	ID             string `json:"id,omitempty"`
}

type QueryModels

type QueryModels struct{}

type QuerySettings

type QuerySettings struct{}

type QuerySettingsDefaults

type QuerySettingsDefaults struct{}

type Service

type Service struct {
	*core.ServiceRuntime[Options]
	// contains filtered or unexported fields
}

func (*Service) DeleteConversation

func (s *Service) DeleteConversation(id string) error
Example
subject := new(Service)
result := core.Try(func() any {
	got0 := subject.DeleteConversation("agent")
	return core.Sprintf("%T", got0)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) HandleIPCEvents

func (s *Service) HandleIPCEvents(_ *core.Core, _ core.Message) core.Result
Example
subject := new(Service)
result := core.Try(func() any {
	got0 := subject.HandleIPCEvents(nil, nil)
	return core.Sprintf("%T", got0)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) History

func (s *Service) History(conversationID string, limit int) ([]Message, error)
Example
subject := new(Service)
result := core.Try(func() any {
	got0, got1 := subject.History("agent", 1)
	return core.Sprintf("%T,%T", got0, got1)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) ListConversations

func (s *Service) ListConversations() ([]Conversation, error)
Example
subject := new(Service)
result := core.Try(func() any {
	got0, got1 := subject.ListConversations()
	return core.Sprintf("%T,%T", got0, got1)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) LoadConversation

func (s *Service) LoadConversation(id string) (Conversation, error)
Example
subject := new(Service)
result := core.Try(func() any {
	got0, got1 := subject.LoadConversation("agent")
	return core.Sprintf("%T,%T", got0, got1)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) Models

func (s *Service) Models() []ModelEntry
Example
subject := new(Service)
result := core.Try(func() any {
	got0 := subject.Models()
	return core.Sprintf("%T", got0)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) OnStartup

func (s *Service) OnStartup(_ context.Context) core.Result
Example

AX7 generated examples exercise each public call path with stable output.

subject := new(Service)
result := core.Try(func() any {
	got0 := subject.OnStartup(core.Background())
	return core.Sprintf("%T", got0)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) SelectModel

func (s *Service) SelectModel(input selectModelInput) (ChatSettings, error)
Example
subject := new(Service)
result := core.Try(func() any {
	got0, got1 := subject.SelectModel(*new(selectModelInput))
	return core.Sprintf("%T,%T", got0, got1)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) Send

func (s *Service) Send(ctx context.Context, input sendInput) (string, error)
Example
subject := new(Service)
result := core.Try(func() any {
	got0, got1 := subject.Send(core.Background(), *new(sendInput))
	return core.Sprintf("%T,%T", got0, got1)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) StartThinking

func (s *Service) StartThinking(input thinkingInput) (ThinkingState, error)
Example
subject := new(Service)
result := core.Try(func() any {
	got0, got1 := subject.StartThinking(*new(thinkingInput))
	return core.Sprintf("%T,%T", got0, got1)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

func (*Service) StopThinking

func (s *Service) StopThinking(input thinkingInput) (ThinkingState, error)
Example
subject := new(Service)
result := core.Try(func() any {
	got0, got1 := subject.StopThinking(*new(thinkingInput))
	return core.Sprintf("%T,%T", got0, got1)
})
core.Println(core.Sprintf("%T", result))
Output:
core.Result

type StreamCallbacks

type StreamCallbacks struct {
	OnStart          func(streamID string)
	OnToken          func(content string)
	OnThinkingStart  func(state ThinkingState)
	OnThinkingAppend func(content string)
	OnThinkingEnd    func(state ThinkingState)
	OnToolCall       func(call ToolCall)
	OnFinish         func(reason string)
}

type StreamRenderer

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

func NewStreamRenderer

func NewStreamRenderer(callbacks StreamCallbacks) *StreamRenderer

func (*StreamRenderer) Message

func (r *StreamRenderer) Message(messageID, model string, createdAt time.Time) ChatMessage

func (*StreamRenderer) Render

func (r *StreamRenderer) Render(reader io.Reader) error

func (*StreamRenderer) Thinking

func (r *StreamRenderer) Thinking() *ThinkingState

func (*StreamRenderer) ToolCalls

func (r *StreamRenderer) ToolCalls() []ToolCall

type ThinkingState

type ThinkingState struct {
	Active     bool      `json:"active"`
	Content    string    `json:"content"`
	StartedAt  time.Time `json:"started_at,omitempty"`
	EndedAt    time.Time `json:"ended_at,omitempty"`
	DurationMS int64     `json:"duration_ms,omitempty"`
}

type ToolCall

type ToolCall struct {
	ID        string         `json:"id"`
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments"`
}

type ToolCallHandler

type ToolCallHandler interface {
	OnToolCall(ctx context.Context, call ToolCall) (result any, err error)
	BuildToolManifest() string
}

ToolCallHandler intercepts model-emitted tool calls and renders the tool manifest that is injected into the system prompt.

func NewToolCallHandler

func NewToolCallHandler(executor ToolExecutor) ToolCallHandler
Example
handler := NewToolCallHandler(exampleToolExecutor{})
result, err := handler.OnToolCall(context.Background(), ToolCall{
	ID:        "call-1",
	Name:      "layout_suggest",
	Arguments: map[string]any{"window_count": 2},
})

core.Println(err == nil)
core.Println(result)
core.Println(core.Contains(handler.BuildToolManifest(), "layout_suggest"))
Output:
true
{"mode":"left-right"}
true

type ToolExecutor

type ToolExecutor interface {
	Manifest() []guimcp.ToolDescriptor
	ManifestText() string
	CallTool(ctx context.Context, name string, arguments map[string]any) (string, error)
}

ToolExecutor is the chat-facing subset of the GUI MCP subsystem.

type ToolResult

type ToolResult struct {
	ToolCallID string `json:"tool_call_id"`
	Content    string `json:"content"`
}

Jump to

Keyboard shortcuts

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