Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateText ¶
Types ¶
type FantasyRunner ¶
type FantasyRunner struct {
// contains filtered or unexported fields
}
func NewFantasyRunner ¶
func NewFantasyRunner(toolFactory FantasyToolFactory) *FantasyRunner
type FantasyToolFactory ¶
FantasyRunner adapts Fantasy to the application's AI SDK UI compatible stream protocol. PocketBase and application-domain services stay outside this package and are supplied through an actor-scoped tool factory.
type Message ¶
type Message struct {
ID string `json:"id"`
Role string `json:"role"`
Metadata map[string]any `json:"metadata,omitempty"`
Parts []Part `json:"parts"`
}
Message is the provider-neutral, AI SDK UI compatible message shape used by the chat package and persisted by the application.
type ModelConfig ¶
type Part ¶
Part is a finalized UI message part. Keeping this as a JSON object lets the Go backend preserve AI SDK additions without coupling persistence to a provider-specific block model.
type Request ¶
type Request struct {
SystemPrompt string
Messages []Message
Model ModelConfig
ActorID string
}
type StreamChunk ¶
type StreamChunk struct {
Type string `json:"type"`
ID string `json:"id,omitempty"`
Delta string `json:"delta,omitempty"`
MessageID string `json:"messageId,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
InputTextDelta string `json:"inputTextDelta,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
ErrorText string `json:"errorText,omitempty"`
Reason string `json:"reason,omitempty"`
Dynamic bool `json:"dynamic,omitempty"`
ProviderExecuted bool `json:"providerExecuted,omitempty"`
SourceID string `json:"sourceId,omitempty"`
URL string `json:"url,omitempty"`
Title string `json:"title,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Filename string `json:"filename,omitempty"`
FinishReason string `json:"finishReason,omitempty"`
MessageMetadata map[string]any `json:"messageMetadata,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
StreamChunk mirrors the AI SDK UI Message Stream v1 JSON protocol. Only fields relevant to the current chat implementation are represented.
func (StreamChunk) MarshalJSON ¶
func (c StreamChunk) MarshalJSON() ([]byte, error)
MarshalJSON guarantees that nil metadata is omitted while arbitrary input and output values remain regular JSON values.
func (StreamChunk) ValidForWire ¶
func (c StreamChunk) ValidForWire() bool
ValidForWire reports whether the chunk satisfies the AI SDK UI Message Stream v1 required-field contract for its type. The AI SDK frontend parses the SSE stream with a strict Zod discriminated union: a single part missing a required field (e.g. a "reasoning-delta" without "delta") aborts the whole stream. Source libraries may emit empty/no-op deltas that, combined with the omitempty tags above, serialize to such invalid parts. This check is the single chokepoint that guarantees no structurally-invalid part ever reaches the browser, regardless of what the upstream library or callbacks produce.
Note: the persisted message (built by the reducer) is unaffected — the reducer sees every chunk and tolerates empty deltas — so dropping a chunk here only suppresses its (invalid) wire representation, never the saved state.