Documentation
¶
Overview ¶
Package assistant is the AI assistant's threads (assistant brief D1, D7; milestone B3): a person's conversations in a workspace, with the model each uses, what the person attached and confirmed sharing, and their cumulative ceilings. A thread is its owner's only: nobody else reads it, integration managers included; they see usage, never content.
Content (titles, messages, attached snapshots, stream events) is sealed at rest with the instance's key. Models, budgets and projections come from internal/ai through Models; this package never opens a key.
Index ¶
- Constants
- func Register(h huma.API, s *Service)
- type AIThread
- type AIThreadCard
- type AIThreadConfirmation
- type AIThreadConfirmationDecision
- type AIThreadConfirmationEvent
- type AIThreadContext
- type AIThreadContextInput
- type AIThreadDeltaEvent
- type AIThreadHeartbeat
- type AIThreadInput
- type AIThreadList
- type AIThreadListItem
- type AIThreadMessage
- type AIThreadMessageEvent
- type AIThreadMessageInput
- type AIThreadServersInput
- type AIThreadSnapshotEvent
- type AIThreadStreamProblem
- type AIThreadToolEvent
- type AIThreadToolRow
- type AIThreadTurn
- type AIThreadTurnEvent
- type AIThreadUpdate
- type AIThreadUsage
- type AIThreadUsageEvent
- type HelpArticle
- type Hub
- type Models
- type PurgeResult
- type RetentionArgs
- type RetentionWorker
- type Screen
- type Servers
- type Service
- func (s *Service) AttachContext(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread uuid.UUID, ...) (AIThread, error)
- func (s *Service) CreateThread(ctx context.Context, ws *store.Workspace, p *authz.Principal, in AIThreadInput) (AIThread, error)
- func (s *Service) DecideConfirmation(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (AIThread, error)
- func (s *Service) DeleteThread(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) error
- func (s *Service) DetachContext(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (AIThread, error)
- func (s *Service) ExecuteTurn(ctx context.Context, args TurnArgs) error
- func (s *Service) Purge(ctx context.Context) (PurgeResult, error)
- func (s *Service) SendMessage(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread uuid.UUID, ...) (AIThread, error)
- func (s *Service) SetThreadServers(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread uuid.UUID, ...) (AIThread, error)
- func (s *Service) StopTurn(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (AIThread, error)
- func (s *Service) Stream(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread uuid.UUID, ...)
- func (s *Service) Sweep(ctx context.Context) (int, error)
- func (s *Service) Thread(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (AIThread, error)
- func (s *Service) Threads(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (AIThreadList, error)
- func (s *Service) UpdateThread(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (AIThread, error)
- type SweepArgs
- type SweepWorker
- type ToolSpec
- type TurnArgs
- type TurnWorker
Constants ¶
const Retention = 30 * 24 * time.Hour
Retention is how long a thread keeps its content after its last activity.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AIThread ¶
type AIThread struct {
ID uuid.UUID `json:"id"`
// Title is the person's name for the thread ("" until they give one).
Title string `json:"title"`
State string `json:"state" enum:"open,expired"`
Screen string `json:"screen,omitempty"`
// Model is the model the thread's turns use, absent once it was removed.
Model *ai.AIAssistantModel `json:"model,omitempty"`
Limits ai.AIAgentLimits `json:"limits"`
Usage AIThreadUsage `json:"usage"`
Contexts []AIThreadContext `json:"contexts"`
Messages []AIThreadMessage `json:"messages"`
// Turn is the thread's latest turn: the one answering now, or how the
// last one ended. Absent before the first message.
Turn *AIThreadTurn `json:"turn,omitempty"`
// Confirmation is the call of a writing MCP tool its turn waits on
// (the turn is "waiting"): its owner allows or denies it.
Confirmation *AIThreadConfirmation `json:"confirmation,omitempty"`
// MCPServerIDs are the MCP servers the thread may use.
MCPServerIDs []uuid.UUID `json:"mcpServerIds"`
// EventSeq is the thread's last stream event: a stream resumes after it.
EventSeq int64 `json:"eventSeq"`
CreatedAt time.Time `json:"createdAt"`
LastActivityAt time.Time `json:"lastActivityAt"`
// ExpiresAt is when the content goes, 30 days after the last activity.
ExpiresAt time.Time `json:"expiresAt"`
}
AIThread is a thread as its owner sees it.
type AIThreadCard ¶
type AIThreadCard struct {
Kind string `json:"kind" enum:"link,proposal,agent_task"`
Title string `json:"title"`
Path string `json:"path"`
ProposalID *uuid.UUID `json:"proposalId,omitempty"`
// Brief is a drafted agent task: the person starts the run and confirms
// sharing in the agent's screen.
Brief string `json:"brief,omitempty"`
}
AIThreadCard is a handoff into an existing screen: it only navigates.
type AIThreadConfirmation ¶
type AIThreadConfirmation struct {
ID uuid.UUID `json:"id"`
TurnID uuid.UUID `json:"turnId"`
ServerID *uuid.UUID `json:"serverId,omitempty"`
ServerName string `json:"serverName"`
Tool string `json:"tool" doc:"The tool's name on its server"`
ModelName string `json:"modelName" doc:"The tool's name for the model: mcp__<server>__<tool>"`
// Arguments are exactly what the call sends once allowed.
Arguments json.RawMessage `json:"arguments"`
// State: expired after a day without the owner's decision (the turn
// ended, nothing was sent).
State string `json:"state" enum:"pending,allowed,denied,calling,done,expired"`
Decision string `json:"decision,omitempty" enum:"allow,deny"`
CreatedAt time.Time `json:"createdAt"`
DecidedAt *time.Time `json:"decidedAt,omitempty"`
}
AIThreadConfirmation is a call of a writing MCP tool waiting for the thread's owner: the server, the tool and the exact arguments it will be sent with.
type AIThreadConfirmationDecision ¶
type AIThreadConfirmationDecision struct {
Decision string `json:"decision" enum:"allow,deny" doc:"allow runs this call once; deny tells the model it was refused"`
}
AIThreadConfirmationDecision is the owner's decision on one call.
type AIThreadConfirmationEvent ¶
type AIThreadConfirmationEvent struct {
Confirmation AIThreadConfirmation `json:"confirmation"`
}
AIThreadConfirmationEvent: a call waits for the owner, or was decided.
type AIThreadContext ¶
type AIThreadContext struct {
ID uuid.UUID `json:"id"`
Kind string `json:"kind" enum:"campaign,post,report,segment,automation"`
TargetID uuid.UUID `json:"targetId"`
Title string `json:"title"`
Available bool `json:"available"`
Revision int64 `json:"revision"`
}
AIThreadContext is a resource attached to a thread. Available is false when the person can no longer read it: it is then never read.
type AIThreadContextInput ¶
type AIThreadContextInput struct {
Kind string `json:"kind" enum:"campaign,report"`
ID uuid.UUID `json:"id" format:"uuid"`
SharingReviewed bool `json:"sharingReviewed" doc:"The person reviewed what is shared with the model and confirmed it"`
}
AIThreadContextInput attaches a resource to a thread. The current screen is only suggested: nothing is shared until the person attaches it and confirms sharing (SharingReviewed).
type AIThreadDeltaEvent ¶
AIThreadDeltaEvent is a piece of a turn's answer as it arrives.
type AIThreadHeartbeat ¶
AIThreadHeartbeat says the stream is alive while nothing happens.
type AIThreadInput ¶
type AIThreadInput struct {
Title string `json:"title,omitempty" maxLength:"120"`
// ModelID picks the model; empty takes the person's own pick for the
// assistant, or else the workspace's.
ModelID *uuid.UUID `json:"modelId,omitempty" format:"uuid"`
// Screen is the route key of the screen it was opened on.
Screen string `json:"screen,omitempty" maxLength:"80" pattern:"^[a-z0-9_.-]*$"`
// RequestKey makes a retry after a lost response return the same thread.
RequestKey string `json:"requestKey" pattern:"^[A-Za-z0-9_-]{1,80}$"`
}
AIThreadInput starts a thread.
type AIThreadList ¶
type AIThreadList struct {
Items []AIThreadListItem `json:"items"`
Next string `json:"next,omitempty"`
}
AIThreadList is a page of the person's threads, the most recently active first.
type AIThreadListItem ¶
type AIThreadListItem struct {
ID uuid.UUID `json:"id"`
Title string `json:"title"`
State string `json:"state" enum:"open,expired"`
ModelID *uuid.UUID `json:"modelId,omitempty"`
LastActivityAt time.Time `json:"lastActivityAt"`
ExpiresAt time.Time `json:"expiresAt"`
}
AIThreadListItem is a thread in the thread list.
type AIThreadMessage ¶
type AIThreadMessage struct {
ID uuid.UUID `json:"id"`
Role string `json:"role" enum:"user,assistant,tool,summary"`
Text string `json:"text"`
TurnID *uuid.UUID `json:"turnId,omitempty"`
// Partial: the answer stopped before it ended (its turn failed); it is
// what arrived.
Partial bool `json:"partial,omitempty"`
// Withheld: an answer or summary that used something the person can no
// longer read (a campaign or report they lost access to or that was
// deleted, an MCP server they may no longer use). Its text is left out
// and the model doesn't read it again.
Withheld bool `json:"withheld,omitempty"`
// Card is a fixed answer the app shows as a card, without a model call:
// hostrepute, for questions about reputation, blocklists or placement.
Card string `json:"card,omitempty" enum:"hostrepute"`
// Tools are a tool message's calls.
Tools []AIThreadToolRow `json:"tools,omitempty"`
CreatedAt time.Time `json:"createdAt"`
}
AIThreadMessage is one message of a thread: the person's, the assistant's, the tools a turn called (their rows), or the marker where earlier messages were summarized (summary).
type AIThreadMessageEvent ¶
type AIThreadMessageEvent struct {
Message AIThreadMessage `json:"message"`
}
AIThreadMessageEvent is a message saved in the thread: the person's, or the assistant's whole answer once it ended (it replaces the deltas).
type AIThreadMessageInput ¶
type AIThreadMessageInput struct {
Text string `json:"text" minLength:"1" maxLength:"20000"`
// RequestKey makes a retry after a lost response return the same turn.
RequestKey string `json:"requestKey" pattern:"^[A-Za-z0-9_-]{1,80}$"`
}
AIThreadMessageInput is a person's message: it starts a turn.
type AIThreadServersInput ¶
type AIThreadServersInput struct {
ServerIDs []uuid.UUID `json:"serverIds" maxItems:"20" doc:"Servers from list-ai-assistant-mcp-servers; empty: none"`
}
AIThreadServersInput is the MCP servers a thread may use.
type AIThreadSnapshotEvent ¶
type AIThreadSnapshotEvent struct {
Thread AIThread `json:"thread"`
}
AIThreadSnapshotEvent is the whole thread, sent instead of events the stream no longer has (or first, without a cursor). Its id is the last event it includes.
type AIThreadStreamProblem ¶
type AIThreadStreamProblem struct {
Status int `json:"status"`
Code string `json:"code"`
Detail string `json:"detail"`
}
AIThreadStreamProblem ends a stream the caller may not or can no longer read: the thread isn't theirs or is gone, they lost ai:use, or the assistant was switched off. A client doesn't reconnect after it.
type AIThreadToolEvent ¶
type AIThreadToolEvent struct {
TurnID uuid.UUID `json:"turnId"`
Tool AIThreadToolRow `json:"tool"`
}
AIThreadToolEvent is a tool call of a turn, once it ran.
type AIThreadToolRow ¶
type AIThreadToolRow struct {
CallID string `json:"callId"`
Name string `json:"name"`
OK bool `json:"ok"`
Code string `json:"code,omitempty"`
Ms int64 `json:"ms"`
Label string `json:"label,omitempty"`
Card *AIThreadCard `json:"card,omitempty"`
}
AIThreadToolRow is a tool call as the thread shows it: what was read or called, how long it took and, for a handoff, its card.
type AIThreadTurn ¶
type AIThreadTurn struct {
ID uuid.UUID `json:"id"`
Sequence int32 `json:"sequence"`
State string `json:"state" enum:"queued,answering,waiting,stopped,failed,done"`
Reason string `json:"reason,omitempty"`
// ModelID is the model the turn uses, fixed when it was sent.
ModelID *uuid.UUID `json:"modelId,omitempty"`
// Text is the answer so far while it answers. Withheld: it is left out
// because the thread read something the person can no longer read (the
// saved answer then says whether it used it).
Text string `json:"text,omitempty"`
Withheld bool `json:"withheld,omitempty"`
CreatedAt time.Time `json:"createdAt"`
StartedAt *time.Time `json:"startedAt,omitempty"`
EndedAt *time.Time `json:"endedAt,omitempty"`
}
AIThreadTurn is a turn's state: Queued, Answering, Waiting for you, Stopped, Failed or Done. Reason says why it stopped, failed or ended short: stopped; interrupted (the worker was lost, so its usage is unknown); not_started (no worker took it within half an hour); confirmation_expired (a call waited a day for its owner: nothing was sent); access_lost, assistant_off; the thread's model: model_gone (it was removed, with its account or alone), account_disconnected (its account was disconnected), key_rejected, tools_unchecked (its tool check isn't passed, for example after its key was replaced), personal_keys_off (it is on the owner's own key and personal keys were turned off), not_configured; a budget: cap_reached, reservation_cap, personal_cap_reached, thread_cap…; the provider: rate_limited, timeout, provider_error, too_large; refused; length (done, cut at its length); reputation (done, the HostRepute card); expired (retention removed the thread's content while it answered).
type AIThreadTurnEvent ¶
type AIThreadTurnEvent struct {
Turn AIThreadTurn `json:"turn"`
}
AIThreadTurnEvent: a turn was queued, began answering, stopped, failed or was done.
type AIThreadUpdate ¶
type AIThreadUpdate struct {
Title *string `json:"title,omitempty" maxLength:"120"`
ModelID *uuid.UUID `json:"modelId,omitempty" format:"uuid"`
}
AIThreadUpdate renames a thread or picks another model for its next turns.
type AIThreadUsage ¶
type AIThreadUsage struct {
ToolCalls int32 `json:"toolCalls"`
Tokens int64 `json:"tokens"`
CostMicros int64 `json:"costMicros"`
Requests int64 `json:"requests"`
UncertainRequests int64 `json:"uncertainRequests"`
UncertainTokens int64 `json:"uncertainTokens"`
UncertainCostMicros int64 `json:"uncertainCostMicros"`
}
AIThreadUsage is what a thread used of its ceilings, reserved included. A request whose usage the provider never reported (one stopped, or cut short) is uncertain: it counts at its reserved maximum, in Tokens and CostMicros too, until a person reconciles it.
type AIThreadUsageEvent ¶
type AIThreadUsageEvent struct {
Usage AIThreadUsage `json:"usage"`
}
AIThreadUsageEvent is the thread's usage after a request was accounted.
type HelpArticle ¶
type HelpArticle struct {
ID string `json:"id"`
Title string `json:"title"`
Text string `json:"text"`
}
HelpArticle is a help article as search_help returns it.
type Hub ¶
type Hub struct {
Pool *pgxpool.Pool
Log *slog.Logger
// PollEvery is how often streams are woken while the hub can't listen
// (1 s); IdleClose how long it keeps listening without streams (1 min).
PollEvery, IdleClose time.Duration
// contains filtered or unexported fields
}
Hub wakes this process's thread streams when their thread has new events. It listens on one connection of its own, opened when the first stream starts and closed a while after the last one ends; NOTIFY only says which thread changed, and each stream reads its events from the table after its own cursor. While the connection is down (Postgres restarted it, a proxy cut it) the hub wakes every stream every PollEvery until it listens again, so nothing waits for a notification that was lost.
type Models ¶
type Models interface {
AssistantSettings(ctx context.Context, q *store.Queries, ws uuid.UUID) (ai.AIAssistantSettings, error)
AssistantModels(ctx context.Context, ws *store.Workspace, p *authz.Principal) (ai.AIAssistantModelList, error)
ResolveAssistantModel(ctx context.Context, q *store.Queries, ws, user uuid.UUID, model *uuid.UUID) (*ai.AssistantModel, error)
AssistantModelView(ctx context.Context, q *store.Queries, ws, user uuid.UUID, model *uuid.UUID) (*ai.AIAssistantModel, error)
AssistantAttachment(ctx context.Context, q *store.Queries, ws *store.Workspace, p *authz.Principal, kind string, id uuid.UUID, snapshot bool) (ai.AssistantAttachment, error)
// A turn's request: ready, reserved under the thread's lock, sent,
// then accounted.
LockAssistantConfig(ctx context.Context, q *store.Queries, ws uuid.UUID) error
ReadyAssistant(ctx context.Context, q *store.Queries, ws *store.Workspace, m *ai.AssistantModel) error
ReserveAssistant(ctx context.Context, q *store.Queries, ws *store.Workspace, p *authz.Principal, m *ai.AssistantModel, req *llm.Request, l ai.AssistantLedger, id uuid.UUID) error
AssistantProvider(m *ai.AssistantModel) (llm.Provider, error)
AccountAssistant(ctx context.Context, q *store.Queries, r ai.AssistantRequest, res llm.Response, callErr error) (bool, error)
AfterAssistant(ctx context.Context, ws *store.Workspace, m *ai.AssistantModel, callErr error)
// The tools' reads and handoffs, each authorized as the owner now.
AssistantFeatureOn(ctx context.Context, q *store.Queries, ws uuid.UUID, feature string) (bool, error)
AssistantReadCampaign(ctx context.Context, q *store.Queries, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (ai.AssistantCampaign, error)
AssistantProposeCampaign(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread, id uuid.UUID, base int64, email ai.AIDraftEmail) (uuid.UUID, error)
AssistantSubjectIdeas(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (ai.AISubjectIdeas, error)
AssistantRewrite(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, text, action, instruction string) (ai.AIRewrite, error)
}
Models is what the assistant uses of internal/ai: the models a thread may use, the assistant's settings and what a person may attach. *ai.Service is one.
type PurgeResult ¶
type PurgeResult struct {
Events, Expired, Tombstones int64
}
PurgeResult is what a retention run removed.
type RetentionArgs ¶
type RetentionArgs struct{}
RetentionArgs is the hourly retention job.
func (RetentionArgs) InsertOpts ¶
func (RetentionArgs) InsertOpts() river.InsertOpts
InsertOpts runs it once at a time.
type RetentionWorker ¶
type RetentionWorker struct {
river.WorkerDefaults[RetentionArgs]
S *Service
}
RetentionWorker runs the retention.
func (*RetentionWorker) Work ¶
func (w *RetentionWorker) Work(ctx context.Context, _ *river.Job[RetentionArgs]) error
Work implements river.Worker.
type Screen ¶
type Screen struct {
Key, Route, Title, Purpose string
Permission authz.Permission
// Param is the route's resource id parameter ("" for none).
Param string
}
Screen is a screen of the app the assistant knows: its route in the web app (web/src/routeTree.gen.ts), the permission it needs, and what it is for. The app only shows links to these.
type Servers ¶
type Servers interface {
ThreadTools(ctx context.Context, q *store.Queries, ws *store.Workspace, owner *authz.Principal, thread uuid.UUID) ([]mcpclient.ThreadTool, error)
Current(ctx context.Context, q *store.Queries, ws *store.Workspace, owner *authz.Principal, toolID uuid.UUID, hash []byte) (store.McpTool, store.McpServer, error)
Call(ctx context.Context, ws *store.Workspace, owner *authz.Principal, thread uuid.UUID, callID string, toolID uuid.UUID, hash []byte, args json.RawMessage) (mcpclient.Result, error)
Usable(ctx context.Context, ws *store.Workspace, p *authz.Principal) (mcpclient.RemoteMCPServerList, error)
MayRead(ctx context.Context, q *store.Queries, ws *store.Workspace, owner *authz.Principal, server uuid.UUID) (bool, error)
}
Servers is what the assistant uses of internal/mcpclient, each as the owner is now. *mcpclient.Service is one.
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Audit *audit.Logger
Box *secrets.Box
AI Models
// MCP is the remote MCP servers' tools (nil: none).
MCP Servers
Log *slog.Logger
// Jobs enqueues turns (any role's client can insert).
Jobs func() *jobs.Client
// Hub wakes this process's streams; one per process.
Hub *Hub
// Now is the clock (tests); nil is the wall clock.
Now func() time.Time
// Heartbeat, WatchEvery and SlowClient tune streams and turns (tests);
// zero takes the default: a heartbeat event every 15 s, a turn's
// access and Stop checked every second while it answers, a stream cut
// once one event takes 5 s to reach its client.
Heartbeat, WatchEvery, SlowClient time.Duration
// contains filtered or unexported fields
}
Service is the assistant's threads, their turns and streams.
func (*Service) AttachContext ¶
func (s *Service) AttachContext(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread uuid.UUID, in AIThreadContextInput) (AIThread, error)
AttachContext attaches a resource the person may read to one of their threads; a report's numbers are its fixed snapshot, taken now. Attaching it again changes nothing.
func (*Service) CreateThread ¶
func (s *Service) CreateThread(ctx context.Context, ws *store.Workspace, p *authz.Principal, in AIThreadInput) (AIThread, error)
CreateThread starts a thread on a model the person may use. A retry with the same request key returns the same thread; the key reused for another request is a conflict.
func (*Service) DecideConfirmation ¶
func (s *Service) DecideConfirmation(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread, id uuid.UUID, in AIThreadConfirmationDecision) (AIThread, error)
DecideConfirmation is the owner's decision on a call waiting in one of their threads: allow runs it once, deny tells the model it was refused; the turn goes on either way. Sending the same decision again changes nothing; another decision, or one on a call whose turn ended, is a conflict. Allowing needs the tool as it was offered (not changed, blocked or removed) and a server the owner may still use.
func (*Service) DeleteThread ¶
func (s *Service) DeleteThread(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) error
DeleteThread deletes one of the person's threads and all its content at once: messages, attached resources and stream events. The activity log and the budget ledger keep its usage, without content. A person may delete their thread with the assistant switched off.
func (*Service) DetachContext ¶
func (s *Service) DetachContext(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread, id uuid.UUID) (AIThread, error)
DetachContext removes a resource from a thread: later turns no longer read it.
func (*Service) ExecuteTurn ¶
ExecuteTurn answers a turn with at most one model request. Running it twice, at once or after a lost acknowledgment, sends nothing twice.
func (*Service) Purge ¶
func (s *Service) Purge(ctx context.Context) (PurgeResult, error)
Purge applies the retention, in batches. An expiring thread is taken in the threads' lock order and skipped while someone holds it; its active turns end first (their version moves on), so a worker that checks in afterwards restores nothing.
func (*Service) SendMessage ¶
func (s *Service) SendMessage(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread uuid.UUID, in AIThreadMessageInput) (AIThread, error)
SendMessage adds the person's message to one of their threads and queues its turn on the thread's model; the answer streams on the thread's events. One turn answers at a time in a thread. A question about reputation, blocklists or placement gets the HostRepute card at once, without a model call. A retry with the same request key returns the thread; the key reused for another message is a conflict.
func (*Service) SetThreadServers ¶
func (s *Service) SetThreadServers(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread uuid.UUID, in AIThreadServersInput) (AIThread, error)
SetThreadServers picks the MCP servers one of the person's threads may use: servers they may use now. Audited as ai_assistant_thread.updated.
func (*Service) StopTurn ¶
func (s *Service) StopTurn(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread, turn uuid.UUID) (AIThread, error)
StopTurn stops one of the person's turns: no model request starts for it any more, and what an answering request writes after now is dropped (it is still accounted: the provider may charge for it). Stopping a turn that already ended changes nothing. The person may stop a turn with the assistant switched off.
func (*Service) Stream ¶
func (s *Service) Stream(ctx context.Context, ws *store.Workspace, p *authz.Principal, thread uuid.UUID, cursor string, send sse.Sender)
Stream sends a thread's events to its owner after the cursor (the last event id they read): a snapshot first when there is no cursor, or when the events after it are gone (24 hours after their turn, or lost in a crash), then each event as it commits, and a heartbeat every 15 s.
func (*Service) Sweep ¶
Sweep fails the turns no worker answers: answering without a live lease (interrupted) and queued for half an hour (not_started); and the turns whose call waited a day for its owner (confirmation_expired). It reports how many it looked at.
func (*Service) Thread ¶
func (s *Service) Thread(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (AIThread, error)
Thread returns one of the person's threads.
func (*Service) Threads ¶
func (s *Service) Threads(ctx context.Context, ws *store.Workspace, p *authz.Principal, search, cursor string, limit int) (AIThreadList, error)
Threads lists the person's threads; with search, the ones whose title has it (titles are sealed, so they are searched here, not in the database).
func (*Service) UpdateThread ¶
func (s *Service) UpdateThread(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, in AIThreadUpdate) (AIThread, error)
UpdateThread renames a thread or picks another model for its next turns. Turns pin their model when they start, so a turn answering keeps its own.
type SweepArgs ¶
type SweepArgs struct{}
SweepArgs is the minute's sweep of turns no worker answers.
func (SweepArgs) InsertOpts ¶
func (SweepArgs) InsertOpts() river.InsertOpts
InsertOpts runs it once at a time.
type SweepWorker ¶
type SweepWorker struct {
river.WorkerDefaults[SweepArgs]
S *Service
}
SweepWorker runs the sweep.
type ToolSpec ¶
type ToolSpec struct {
Name string
Description string
Parameters map[string]any
// Permission is what the owner needs; Feature the AI feature whose
// switch must be on ("" for none); Needs the kind of attached resource
// it works on ("" for none).
Permission authz.Permission
Feature string
Needs string
// Confirm: the call waits for the person to confirm that exact call
// (the turn is "waiting"): MCP tools that write outside ReputeCast; no
// tool of ReputeCast's own needs it.
Confirm bool
// contains filtered or unexported fields
}
ToolSpec is one tool.
type TurnArgs ¶
type TurnArgs struct {
WorkspaceID uuid.UUID `json:"workspaceId"`
ThreadID uuid.UUID `json:"threadId"`
TurnID uuid.UUID `json:"turnId"`
Version int64 `json:"version"`
}
TurnArgs is a turn's job: ids only, never content.
func (TurnArgs) InsertOpts ¶
func (TurnArgs) InsertOpts() river.InsertOpts
InsertOpts puts turns on their own queue: a long answer never holds up other jobs.
type TurnWorker ¶
type TurnWorker struct {
river.WorkerDefaults[TurnArgs]
S *Service
}
TurnWorker answers turns.