feat: config, OpenAI-compatible streaming provider and safe tools

This commit is contained in:
OpenClaw Dev 2026-10-25 03:10:13 +01:00
commit c1c7b0e005
13 changed files with 1031 additions and 0 deletions

53
internal/llm/llm.go Normal file
View file

@ -0,0 +1,53 @@
// Package llm defines the provider abstraction and message types.
package llm
import "context"
type Role string
const (
RoleSystem Role = "system"
RoleUser Role = "user"
RoleAssistant Role = "assistant"
RoleTool Role = "tool"
)
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Arguments string `json:"arguments"` // raw JSON
}
type Message struct {
Role Role `json:"role"`
Content string `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
Name string `json:"name,omitempty"`
}
// ToolSpec describes a callable tool using JSON Schema parameters.
type ToolSpec struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]any `json:"parameters"`
}
type Request struct {
Messages []Message
Tools []ToolSpec
}
// Response is the final assembled assistant turn.
type Response struct {
Content string
ToolCalls []ToolCall
FinishReason string
}
// DeltaFunc receives streamed text tokens. May be nil.
type DeltaFunc func(text string)
type Provider interface {
Chat(ctx context.Context, req Request, onDelta DeltaFunc) (Response, error)
}