casebound

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package casebound contains the agent runtime for case-bound channels — Slack channels that already have an associated Case. The agent runs the gollem ReAct loop with the full action mutator tool set, replying as a thread message. Slack-side concerns (posting, fetching conversation, trace UI) live in the host orchestrator at pkg/usecase/agent.go; this package is Slack-independent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConversationMessage

type ConversationMessage struct {
	UserID    string
	UserName  string
	Text      string
	Timestamp string
}

ConversationMessage is the Slack-independent shape passed to RunTurn for the conversation snapshot. The host (pkg/usecase) converts its pkg/service/slack.ConversationMessage into this type so casebound never imports the Slack service.

type Handler

type Handler interface {
	// TraceAppend records a milestone line that must stay visible (it is
	// appended to the host's progress history).
	TraceAppend(ctx context.Context, line string)
	// TraceReplace overwrites the single transient activity line in place,
	// so per-tool chatter ("Searching…", "Fetching…") does not accumulate.
	TraceReplace(ctx context.Context, line string)
}

Handler is the host-side interface casebound calls during a turn for the progressive trace UI. It is intentionally minimal: the host handles all Slack posting, conversation fetching, and final reply itself. The runtime distinguishes two kinds of progress so the host can render them differently: milestones that accumulate vs. ephemeral per-tool activity that overwrites.

type HandlerFunc

type HandlerFunc func(ctx context.Context, line string)

HandlerFunc is a convenience wrapper for callers that only care about the milestone history. The supplied closure receives every milestone via TraceAppend; TraceReplace is a no-op (transient activity is discarded).

func (HandlerFunc) TraceAppend

func (f HandlerFunc) TraceAppend(ctx context.Context, line string)

TraceAppend satisfies Handler.

func (HandlerFunc) TraceReplace

func (f HandlerFunc) TraceReplace(context.Context, string)

TraceReplace satisfies Handler. The single-func wrapper has no place to put a transient line, so it is dropped.

type HandlerFuncs

type HandlerFuncs struct {
	TraceAppendFn  func(ctx context.Context, line string)
	TraceReplaceFn func(ctx context.Context, line string)
}

HandlerFuncs is a struct-of-funcs adapter for hosts that render milestones and transient activity differently. Nil entries are treated as no-ops.

func (HandlerFuncs) TraceAppend

func (h HandlerFuncs) TraceAppend(ctx context.Context, line string)

TraceAppend satisfies Handler.

func (HandlerFuncs) TraceReplace

func (h HandlerFuncs) TraceReplace(ctx context.Context, line string)

TraceReplace satisfies Handler.

type Result

type Result struct {
	// Status is one of the constants below.
	Status Status
	// FinalText is the agent's final reply (only when Status==StatusCompleted).
	FinalText string
	// BusyOwner exposes the live owner's session when Status==StatusBusy.
	BusyOwner *model.Session
}

Result is the outcome of RunTurn. Status discriminates the three terminal shapes the host needs to act on.

type Status

type Status int

Status values returned by RunTurn.

const (
	// StatusCompleted indicates the turn ran end-to-end and FinalText is set.
	StatusCompleted Status = iota
	// StatusBusy indicates another turn was already running on this session;
	// the host should post a busy notification and drop the trigger.
	StatusBusy
	// StatusIdempotent indicates the trigger duplicates a turn already in
	// flight; the host should drop silently with no Slack post.
	StatusIdempotent
)

type TurnRequest

type TurnRequest struct {
	// Session is the active turn's Session, with TurnOwnerID etc. already
	// populated by the upstream lock acquire. The runtime updates
	// LastMentionTS / LastAction at the end of the turn and persists.
	Session *model.Session

	// Mention metadata (channel / thread / user / mention text) that drives
	// the prompt body and trace metadata.
	ChannelID   string
	ThreadTS    string
	MentionTS   string
	MentionText string
	BotUserID   string

	// Resolved domain state.
	Workspace     *model.WorkspaceEntry
	Case          *model.Case
	Actions       []*model.Action
	CurrentAction *model.Action

	// Pre-fetched conversation context. SystemMessages is non-empty only
	// for fresh sessions (Session.LastMentionTS == ""). DeltaMessages is
	// the unprocessed-since-last-mention slice for continuing sessions.
	SystemMessages []ConversationMessage
	DeltaMessages  []ConversationMessage

	// TriggerTS is the Slack TS used both as the trace ID and as the lock
	// trigger key (to detect duplicate event delivery).
	TriggerTS string

	// Handler receives progressive trace updates while gollem runs.
	Handler Handler
}

TurnRequest collects the inputs the host has already resolved before handing control to the casebound runtime. The casebound runtime never touches the Slack service directly; everything Slack-related is either pre-built (system / delta messages) or delegated via Handler.

type UseCase

type UseCase struct {
	// contains filtered or unexported fields
}

UseCase runs a single case-bound agent turn (a Slack mention in a Case channel). It owns the gollem invocation, system prompt assembly, and session lock lifecycle; the Slack-side host is responsible for fetching the conversation, posting trace updates, and posting the final reply.

func New

func New(deps *agent.CommonDeps) (*UseCase, error)

New builds a casebound UseCase wired against the shared agent deps.

func (*UseCase) RunTurn

func (uc *UseCase) RunTurn(ctx context.Context, req TurnRequest) (*Result, error)

RunTurn executes one case-bound mention turn. It acquires the per-thread turn lock (Phase A, §5.3), runs the gollem ReAct loop, persists the updated Session.LastMentionTS, and returns the gollem final text for the host to post to Slack.

Jump to

Keyboard shortcuts

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