kai

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextLogger

func ContextLogger(ctx context.Context) *slog.Logger

ContextLogger exposes the slog logger stored in the provided context, if any.

func JoinSessionPath

func JoinSessionPath(baseURL, sessionID string, segments ...string) (string, error)

JoinSessionPath constructs /sessions/{id} paths safely.

Types

type ChatContext

type ChatContext struct {
	Type ContextType `json:"type"`
	ID   string      `json:"id"`
}

ChatContext represents an entity reference shared with the Kai agent.

type ChatEvent

type ChatEvent struct {
	Event string `json:"event"          yaml:"event"`
	Data  any    `json:"data,omitempty" yaml:"data,omitempty"`
}

ChatEvent represents a single server-sent event emitted by the Kai agent API.

type ContextType

type ContextType string

ContextType enumerates the supported Kai context entity types.

const (
	ContextTypeControlPlane         ContextType = "control_plane"
	ContextTypeDataPlane            ContextType = "data_plane"
	ContextTypeRoute                ContextType = "route"
	ContextTypePlugin               ContextType = "plugin"
	ContextTypeService              ContextType = "service"
	ContextTypeConsumer             ContextType = "consumer"
	ContextTypeActiveTracingSession ContextType = "active_tracing_session"
)

type CreateSessionPayload

type CreateSessionPayload struct {
	Name string `json:"name"`
}

type Result

type Result struct {
	Prompt   string      `json:"prompt"   yaml:"prompt"`
	Response string      `json:"response" yaml:"response"`
	Events   []ChatEvent `json:"events"   yaml:"events"`
}

Result captures the aggregated chat response and all underlying events.

func Chat

func Chat(ctx context.Context, client *http.Client, baseURL, token, prompt string) (*Result, error)

Chat executes a stateless prompt against the Kai agent.

type SessionHistory

type SessionHistory struct {
	ID        string               `json:"id"`
	Name      string               `json:"name"`
	CreatedAt time.Time            `json:"created_at"`
	History   []SessionHistoryItem `json:"history"`
}

func GetSessionHistory

func GetSessionHistory(
	ctx context.Context,
	client *http.Client,
	baseURL, token, sessionID string,
) (*SessionHistory, error)

GetSessionHistory retrieves full chat history for a session.

type SessionHistoryItem

type SessionHistoryItem struct {
	ID        string                 `json:"id"`
	TriggerID string                 `json:"trigger_id"`
	Role      string                 `json:"role"`
	Message   string                 `json:"message"`
	Timestamp time.Time              `json:"timestamp"`
	Context   []map[string]any       `json:"context"`
	Tool      *SessionHistoryToolRef `json:"tool_details"`
}

type SessionHistoryToolRef

type SessionHistoryToolRef struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type SessionLimitError

type SessionLimitError struct {
	Detail string
	Raw    string
}

SessionLimitError indicates the server refused to create a session because the maximum was reached.

func (*SessionLimitError) Error

func (e *SessionLimitError) Error() string

type SessionList

type SessionList []SessionMetadata

func ListSessions

func ListSessions(ctx context.Context, client *http.Client, baseURL, token string) (SessionList, error)

ListSessions retrieves available sessions for the current user.

type SessionMetadata

type SessionMetadata struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
}

func CreateSession

func CreateSession(ctx context.Context, client *http.Client, baseURL, token, name string) (*SessionMetadata, error)

CreateSession creates a new chat session and returns metadata.

type Stream

type Stream struct {
	Events <-chan ChatEvent
	// contains filtered or unexported fields
}

Stream represents an active chat stream returning events incrementally.

func AnalyzeTaskStream

func AnalyzeTaskStream(
	ctx context.Context,
	client *http.Client,
	baseURL, token, sessionID, taskID string,
) (*Stream, error)

func ChatStream

func ChatStream(ctx context.Context, client *http.Client, baseURL, token, prompt string) (*Stream, error)

ChatStream executes the chat request and streams events to the caller.

func ChatStreamSession

func ChatStreamSession(
	ctx context.Context,
	client *http.Client,
	baseURL, token, sessionID, prompt string,
	contextEntities []ChatContext,
) (*Stream, error)

ChatStreamSession streams chat tied to an existing session.

func (*Stream) Err

func (s *Stream) Err() error

Err blocks until the underlying stream completes and returns the terminal error, if any.

type TaskAction

type TaskAction string
const (
	TaskActionStart TaskAction = "start"
	TaskActionStop  TaskAction = "stop"
)

type TaskDetails

type TaskDetails struct {
	ID                  string         `json:"id"`
	SessionID           string         `json:"session_id"`
	TriggerID           string         `json:"trigger_id"`
	Type                string         `json:"type"`
	Context             []ChatContext  `json:"context"`
	ToolCallMetadata    map[string]any `json:"tool_call_metadata"`
	Status              string         `json:"status"`
	CreatedAt           time.Time      `json:"created_at"`
	ExpiresAt           time.Time      `json:"expires_at"`
	ConfirmationMessage string         `json:"confirmation_message"`
}

func ListActiveTasks

func ListActiveTasks(
	ctx context.Context,
	client *http.Client,
	baseURL, token, sessionID string,
) ([]TaskDetails, error)

func UpdateTask

func UpdateTask(
	ctx context.Context,
	client *http.Client,
	baseURL, token, sessionID, taskID string,
	action TaskAction,
) (*TaskDetails, error)

type TaskStatusEvent

type TaskStatusEvent struct {
	Status  string
	Message string
}

type TaskStatusStream

type TaskStatusStream struct {
	Events <-chan TaskStatusEvent
	// contains filtered or unexported fields
}

func StreamTaskStatus

func StreamTaskStatus(
	ctx context.Context,
	client *http.Client,
	baseURL, token, sessionID, taskID string,
) (*TaskStatusStream, error)

func (*TaskStatusStream) Err

func (s *TaskStatusStream) Err() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL