feat(sdk): typed errors, enums, and KB model config for the CLI

Adds the client-library surface the agent-first CLI builds on:
- named server error-code constants + typed *APIError from non-2xx responses,
- MessageSearchMode / AgentMode / KBSelectionMode and model type/source
  enumerators so the CLI validates flags against the server vocabulary,
- SetKBModelConfig for binding embedding/chat models to a knowledge base.
This commit is contained in:
nullkey
2026-06-26 20:40:59 +08:00
committed by lyingbug
parent eba9fe7e78
commit 8f36ea2229
9 changed files with 203 additions and 8 deletions
+40
View File
@@ -28,6 +28,46 @@ type Agent struct {
CreatorName string `json:"creator_name,omitempty"`
}
// AgentMode is an agent's operating mode (AgentConfig.AgentMode). It mirrors
// the server constants in internal/types/custom_agent.go.
type AgentMode string
const (
// AgentModeQuickAnswer is the RAG mode for quick Q&A.
AgentModeQuickAnswer AgentMode = "quick-answer"
// AgentModeSmartReasoning is the ReAct mode for multi-step reasoning.
AgentModeSmartReasoning AgentMode = "smart-reasoning"
)
// AllAgentModes returns every agent operating mode the server recognises, in a
// stable order. Use this instead of re-typing the set so callers can't drift
// from the SDK.
func AllAgentModes() []AgentMode {
return []AgentMode{AgentModeQuickAnswer, AgentModeSmartReasoning}
}
// KBSelectionMode controls how an agent selects knowledge bases
// (AgentConfig.KBSelectionMode). It mirrors the server's documented values
// ("all" | "selected" | "none") in internal/types/custom_agent.go.
type KBSelectionMode string
const (
// KBSelectionModeAll retrieves across every knowledge base.
KBSelectionModeAll KBSelectionMode = "all"
// KBSelectionModeSelected retrieves only the agent's attached KBs
// (AgentConfig.KnowledgeBases).
KBSelectionModeSelected KBSelectionMode = "selected"
// KBSelectionModeNone disables knowledge base retrieval.
KBSelectionModeNone KBSelectionMode = "none"
)
// AllKBSelectionModes returns every KB selection mode the server recognises, in
// a stable order. Use this instead of re-typing the set so callers can't drift
// from the SDK.
func AllKBSelectionModes() []KBSelectionMode {
return []KBSelectionMode{KBSelectionModeAll, KBSelectionModeSelected, KBSelectionModeNone}
}
// AgentConfig represents the configuration for an agent.
// Field names and JSON tags mirror internal/types.CustomAgentConfig.
type AgentConfig struct {