Documentation
¶
Index ¶
- func Register(optionFns ...func(*Options)) func(*core.Core) core.Result
- type ActionConversationCleared
- type ActionConversationCreated
- type ActionConversationDeleted
- type ActionConversationUpdated
- type ActionImageQueued
- type ActionMessageAdded
- type ActionStreamFinished
- type ActionStreamStarted
- type ActionThinkingAppended
- type ActionThinkingEnded
- type ActionThinkingStarted
- type ActionTokenAppended
- type ActionToolCallStarted
- type ActionToolResultReady
- type ChatMessage
- type ChatSettings
- type Conversation
- type ConversationSummary
- type ImageAttachment
- type Message
- type Model
- type ModelEntry
- type Options
- type QueryConversationGet
- type QueryConversationList
- type QueryConversationSearch
- type QueryHistory
- type QueryModels
- type QuerySettings
- type QuerySettingsDefaults
- type Service
- func (s *Service) DeleteConversation(id string) error
- func (s *Service) HandleIPCEvents(_ *core.Core, _ core.Message) core.Result
- func (s *Service) History(conversationID string, limit int) ([]Message, error)
- func (s *Service) ListConversations() ([]Conversation, error)
- func (s *Service) LoadConversation(id string) (Conversation, error)
- func (s *Service) Models() []ModelEntry
- func (s *Service) OnStartup(_ context.Context) core.Result
- func (s *Service) SelectModel(input selectModelInput) (ChatSettings, error)
- func (s *Service) Send(ctx context.Context, input sendInput) (string, error)
- func (s *Service) StartThinking(input thinkingInput) (ThinkingState, error)
- func (s *Service) StopThinking(input thinkingInput) (ThinkingState, error)
- type StreamCallbacks
- type StreamRenderer
- type ThinkingState
- type ToolCall
- type ToolCallHandler
- type ToolExecutor
- type ToolResult
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
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 ActionStreamFinished ¶
type ActionStreamStarted ¶
type ActionThinkingAppended ¶
type ActionThinkingEnded ¶
type ActionThinkingStarted ¶
type ActionTokenAppended ¶
type ActionToolCallStarted ¶
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 ImageAttachment ¶
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 QueryConversationGet ¶
type QueryConversationList ¶
type QueryConversationList struct{}
type QueryConversationSearch ¶
type QueryConversationSearch struct {
Query string `json:"q"`
}
type QueryHistory ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) Thinking ¶
func (r *StreamRenderer) Thinking() *ThinkingState
func (*StreamRenderer) ToolCalls ¶
func (r *StreamRenderer) ToolCalls() []ToolCall
type ThinkingState ¶
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 ¶
Click to show internal directories.
Click to hide internal directories.