mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
refactor(pkg/kit): replace fantasy type aliases with concrete LLM* structs
Remove charm.land/fantasy from the public API surface of pkg/kit by
replacing the four type aliases with concrete Kit-owned structs:
- LLMMessage {Role LLMMessageRole, Content string}
- LLMUsage {InputTokens, OutputTokens, TotalTokens, ...}
- LLMResponse {Content, FinishReason, Usage}
- LLMFilePart {Filename, Data []byte, MediaType}
Add LLMMessageRole type with user/assistant/system/tool constants.
Introduce pkg/kit/llm_convert.go as the single boundary layer where
Kit types convert to/from fantasy types internally. All callers in
pkg/kit, pkg/kit/compaction.go, pkg/kit/extensions_bridge.go, and
internal/app/app.go cross through this layer.
ContextPrepareHook.Messages and ContextPrepareResult.Messages change
from []fantasy.Message to []LLMMessage. extensions_bridge.go drops
its fantasy and strings imports entirely.
internal/app/app_test.go switches &fantasy.Usage{} to &kit.LLMUsage{}.
Add seven new tests in types_test.go covering concrete construction,
role constants, JSON snake_case tags, and round-trip conversion.
This commit is contained in:
+12
-6
@@ -120,15 +120,17 @@ result, err := host.PromptResult(ctx, "Analyze this file")
|
||||
// result.StopReason — "stop", "length", "tool-calls", "error", etc.
|
||||
// result.SessionID — session UUID
|
||||
// result.TotalUsage — aggregate tokens across all steps (*kit.LLMUsage)
|
||||
// result.FinalUsage — tokens from last API call only
|
||||
// LLMUsage{InputTokens, OutputTokens, TotalTokens, ...}
|
||||
// result.FinalUsage — tokens from last API call only (*kit.LLMUsage)
|
||||
// result.Messages — full updated conversation ([]kit.LLMMessage)
|
||||
// LLMMessage{Role kit.LLMMessageRole, Content string}
|
||||
```
|
||||
|
||||
### Multimodal with file attachments
|
||||
|
||||
```go
|
||||
files := []kit.LLMFilePart{{
|
||||
Name: "screenshot.png",
|
||||
Filename: "screenshot.png",
|
||||
MediaType: "image/png",
|
||||
Data: imageBytes,
|
||||
}}
|
||||
@@ -640,15 +642,19 @@ kit.Config, kit.MCPServerConfig
|
||||
// Provider types
|
||||
kit.ProviderConfig, kit.ProviderResult, kit.ModelInfo, kit.ModelCost, kit.ModelLimit
|
||||
|
||||
// LLM types (re-exported from the underlying LLM library)
|
||||
kit.LLMMessage, kit.LLMUsage, kit.LLMResponse, kit.LLMFilePart
|
||||
// LLM types — concrete Kit-owned structs (no external library dependency)
|
||||
kit.LLMMessage // {Role LLMMessageRole, Content string}
|
||||
kit.LLMMessageRole // "user" | "assistant" | "system" | "tool"
|
||||
kit.LLMUsage // {InputTokens, OutputTokens, TotalTokens, ReasoningTokens, ...}
|
||||
kit.LLMResponse // {Content, FinishReason, Usage}
|
||||
kit.LLMFilePart // {Filename, Data []byte, MediaType}
|
||||
|
||||
// Compaction types
|
||||
kit.CompactionResult, kit.CompactionOptions
|
||||
|
||||
// Conversion helpers
|
||||
msgs := kit.ConvertToLLMMessages(&msg) // SDK message → LLM messages
|
||||
msg := kit.ConvertFromLLMMessage(fMsg) // LLM message → SDK message
|
||||
msgs := kit.ConvertToLLMMessages(&msg) // SDK Message → []LLMMessage
|
||||
msg := kit.ConvertFromLLMMessage(lMsg) // LLMMessage → SDK Message
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user