Documentation
¶
Overview ¶
Package application orchestrates agent turns, including context assembly, persistence, memory, compaction, approvals, and runtime invocation.
Index ¶
- Constants
- Variables
- func SubagentRunHandleFromContext(ctx context.Context) (sessionruntime.RunHandle, bool)
- type ACPMode
- type ACPModeRequest
- type ACPModeState
- type ACPSessionExecutionInfo
- type AssistantOutput
- type ChatAttachment
- type ChatRequest
- type ChatResponse
- type CommittedToolApprovalResponse
- type CommittedUserInputResponse
- type ContentPart
- type EditLatestMessageInput
- type EmailChatGateway
- type InjectMessage
- type InjectedMessageRecord
- type ModelMessage
- type OutboundAssetRef
- type PlatformIdentity
- type PlatformIdentitySource
- type RequestedSkillContext
- type ResolveRunConfigResult
- type RetryLatestMessageInput
- type Runner
- type ScheduleGateway
- type Service
- func (s *Service) ACPSessionExecutionInfo(ctx context.Context, sessionID string) (ACPSessionExecutionInfo, error)
- func (s *Service) AbortRuntimeRun(ctx context.Context, botID, sessionID, runID, controlID string) (bool, error)
- func (s *Service) AdmitSubagentRun(ctx context.Context, botID, threadID, invocationID string, submission []byte) (context.Context, tools.SubagentAdmission, func(tools.SubagentTerminal), error)
- func (s *Service) AdvancePlainTextUserInput(ctx context.Context, input userinput.AdvanceTextInput) (userinput.AdvanceTextResult, error)
- func (s *Service) ApplyUserMessageHookAndPersistUserTurn(ctx context.Context, req ChatRequest) (ChatRequest, messagepkg.Message, error)
- func (s *Service) Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
- func (s *Service) CommitToolApprovalResponse(ctx context.Context, input ToolApprovalResponseInput) (CommittedToolApprovalResponse, error)
- func (s *Service) CommitUserInputResponse(ctx context.Context, input UserInputResponseInput) (CommittedUserInputResponse, error)
- func (s *Service) ConfigureACPMode(ctx context.Context, input ACPModeRequest) (ACPModeState, error)
- func (s *Service) ContinueCommittedToolApprovalResponse(ctx context.Context, committed CommittedToolApprovalResponse, ...) error
- func (s *Service) ContinueCommittedUserInputResponse(ctx context.Context, committed CommittedUserInputResponse, ...) error
- func (s *Service) DeferSessionCompaction(botID, sessionID, runID string) func()
- func (s *Service) EditLatestMessageWS(ctx context.Context, input EditLatestMessageInput, ...) error
- func (s *Service) EnsureTerminalContextLifecycle(ctx context.Context, runID, botID, sessionID string, cause error)
- func (s *Service) InlineImageAttachments(ctx context.Context, botID string, refs []timeline.ImageAttachmentRef) []sdk.ImagePart
- func (s *Service) LinkOutboundAssets(ctx context.Context, botID, sessionID string, assets []messagepkg.AssetRef)
- func (s *Service) PendingRuntimeDecision(ctx context.Context, runID string) (sessionruntime.DecisionTarget, bool, error)
- func (s *Service) Pipeline() *timeline.Pipeline
- func (s *Service) PrepareEditLatestTurnOperation(ctx context.Context, sessionID, turnID string) (string, error)
- func (s *Service) PrepareRetryLatestTurnOperation(ctx context.Context, sessionID, turnID string) (string, error)
- func (s *Service) ResolveRunConfig(ctx context.Context, ...) (ResolveRunConfigResult, error)
- func (s *Service) ResolveRuntimeDecision(ctx context.Context, commandType, decisionID string) (sessionruntime.DecisionTarget, error)
- func (s *Service) ResolveTurnIDForMessage(ctx context.Context, sessionID, messageID string) (string, error)
- func (s *Service) RespondToolApproval(ctx context.Context, input turn.ToolApprovalResponse, ...) error
- func (s *Service) RespondUserInput(ctx context.Context, input turn.UserInputResponse, ...) error
- func (s *Service) RetryLatestMessageWS(ctx context.Context, input RetryLatestMessageInput, ...) error
- func (s *Service) SetACPSessionPool(pool acpPrompter)
- func (s *Service) SetAllowedTeam(teamID string)
- func (s *Service) SetBackgroundManager(m *background.Manager)
- func (s *Service) SetBotPermissionChecker(checker botPermissionChecker)
- func (s *Service) SetCompactionService(service *compaction.Service)
- func (s *Service) SetContextAbsoluteMaxTokens(v int)
- func (s *Service) SetEventPublisher(p messageevent.Publisher)
- func (s *Service) SetGatewayAssetLoader(loader gatewayAssetLoader)
- func (s *Service) SetHookService(service *hooks.Service)
- func (s *Service) SetMemoryRegistry(registry *memprovider.Registry)
- func (s *Service) SetPipeline(p *timeline.Pipeline)
- func (s *Service) SetPlatformIdentitySource(source PlatformIdentitySource)
- func (s *Service) SetSessionRuntime(manager *sessionruntime.Manager)
- func (s *Service) SetSessionService(service SessionService)
- func (s *Service) SetSkillLoader(sl SkillLoader)
- func (s *Service) SetToolApprovalService(service *toolapproval.Service)
- func (s *Service) SetUserInputService(service *userinput.Service)
- func (s *Service) SetWorkdirResolver(resolver sessionWorkdirResolver)
- func (s *Service) SetWorkspaceTargetResolver(resolver workspaceTargetResolver)
- func (s *Service) StartTurn(ctx context.Context, cmd turn.StartTurnCommand) (turn.RunHandle, error)
- func (s *Service) StoreRound(ctx context.Context, ...) error
- func (s *Service) StreamChat(ctx context.Context, req ChatRequest) (<-chan StreamChunk, <-chan error)
- func (s *Service) StreamChatWS(ctx context.Context, req ChatRequest, eventCh chan<- WSStreamEvent, ...) error
- func (s *Service) SubagentRunObserver(ctx context.Context) native.SpawnRunObserver
- func (s *Service) SubagentStepCommit(ctx context.Context, botID, sessionID, modelID, turnRequestMessageID string, ...) (func(context.Context, int, *sdk.StepResult) error, ...)
- func (s *Service) TriggerSchedule(ctx context.Context, botID string, payload schedule.TriggerPayload, ...) (triggerResult schedule.TriggerResult, err error)
- func (s *Service) ValidateWorkspaceTarget(ctx context.Context, botID, targetID string) error
- type SessionService
- type SkillActivation
- type SkillActivationSkill
- type SkillEntry
- type SkillLoader
- type StreamChunk
- type ToolApprovalResponseInput
- type ToolCall
- type ToolCallFunction
- type UserInputResponseInput
- type WSStreamEvent
- type WorkspaceTarget
Constants ¶
const UserMessageKindSkillActivation = turn.UserMessageKindSkillActivation
Variables ¶
var ( ErrACPModeSessionRequired = errors.New("ACP session is required for permission mode") ErrACPModeUnsupported = errors.New("ACP agent does not expose session modes") )
var ErrWorkspaceTargetACPUnsupported = errors.New("workspace_target_id is not supported for ACP sessions")
var ErrWorkspaceTargetWorkdirConflict = errors.New(
"this session is bound to a workdir; its workspace target cannot be changed")
ErrWorkspaceTargetWorkdirConflict is returned when a request tries to move a workdir-bound session onto a different workspace target. The binding is immutable: the workdir's directory only exists on the workdir's target, so honoring the switch would produce a session whose working directory does not exist.
Functions ¶
func SubagentRunHandleFromContext ¶
func SubagentRunHandleFromContext(ctx context.Context) (sessionruntime.RunHandle, bool)
SubagentRunHandleFromContext returns the run handle AdmitSubagentRun stored on the context, if the context belongs to an admitted subagent run.
Types ¶
type ACPModeRequest ¶
type ACPModeState ¶
type ACPSessionExecutionInfo ¶
type AssistantOutput ¶
type AssistantOutput = turn.AssistantOutput
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type ChatAttachment ¶
type ChatAttachment = turn.Attachment
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type ChatRequest ¶
type ChatRequest struct {
BotID string `json:"-"`
ChatID string `json:"-"`
ThreadID string `json:"-"`
// RunID is the server-minted identity of this turn's run. Downstream state
// that must agree on "which turn is this" — the compaction barrier, the ACP
// session, interactive tool headers — keys on it.
RunID string `json:"-"`
// TurnID and TurnPosition are the turn admission already allocated for this
// run. They travel with the request so the persisted user turn lands under
// the id the client was handed at run_accepted, instead of the history layer
// minting a second one (SR-TURN-001). Empty means no admission decided the
// turn — channel inbound and schedules — and history allocates it.
TurnID string `json:"-"`
TurnPosition *int64 `json:"-"`
Token string `json:"-"`
UserID string `json:"-"`
SourceChannelIdentityID string `json:"-"`
DisplayName string `json:"-"`
RouteID string `json:"-"`
ChatToken string `json:"-"`
ExternalMessageID string `json:"-"`
ReplyTarget string `json:"-"`
ConversationType string `json:"-"`
ConversationName string `json:"-"`
SourceReplyToMessageID string `json:"-"`
ReplySender string `json:"-"`
ReplyPreview string `json:"-"`
ReplyAttachments []turn.Attachment `json:"-"`
MentionsBot bool `json:"-"`
RepliesToBot bool `json:"-"`
ForwardMessageID string `json:"-"`
ForwardFromUserID string `json:"-"`
ForwardFromConversationID string `json:"-"`
ForwardSender string `json:"-"`
ForwardDate int64 `json:"-"`
UserMessagePersisted bool `json:"-"`
PersistedUserMessageID string `json:"-"`
ReusePersistedUserMessage bool `json:"-"`
EventID string `json:"-"`
RawQuery string `json:"-"`
ModelQuery string `json:"-"`
UserMessageKind string `json:"-"`
UserVisibleText string `json:"-"`
SkillActivation *turn.SkillActivation `json:"-"`
ToolHTTPURL string `json:"-"`
SessionType string `json:"-"`
RuntimeType string `json:"-"`
SkipMemoryExtraction bool `json:"-"`
SkipHistoryTurn bool `json:"-"`
SkipTitleGeneration bool `json:"-"`
ForceFreshRuntime bool `json:"-"`
// AgentCommand is the exact agent-command selector the Web admission layer
// matched against a live ACP runtime. The session pool re-validates it
// against the final session at prompt time; it never crosses the turn
// transport (Web admission runs in-process).
AgentCommand string `json:"-"`
HistoryCutoffBeforeMessageID string `json:"-"`
RequiredHistoryMessageID string `json:"-"`
WorkspaceTarget *WorkspaceTarget `json:"-"`
// OutboundAssetCollector returns asset refs accumulated during outbound
// streaming. It is never serialized across the turn transport.
OutboundAssetCollector func() []turn.OutboundAssetRef `json:"-"`
// InjectCh receives user messages between tool rounds. Remote transports
// use turn.RunHandle.Inject instead.
InjectCh <-chan turn.InjectMessage `json:"-"`
Query string `json:"query"`
Model string `json:"model,omitempty"`
Provider string `json:"provider,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
WorkspaceTargetID string `json:"workspace_target_id,omitempty"`
Channels []string `json:"channels,omitempty"`
CurrentChannel string `json:"current_channel,omitempty"`
Messages []turn.ModelMessage `json:"messages,omitempty"`
Attachments []turn.Attachment `json:"attachments,omitempty"`
RequestedSkills []turn.RequestedSkillContext `json:"-"`
}
ChatRequest is the application-layer input used while orchestrating a chat turn. Transport callers should prefer turn.StartTurnCommand; the additional channel and function fields below are strictly in-process runtime state.
type ChatResponse ¶
type ChatResponse struct {
Messages []turn.ModelMessage `json:"messages"`
Model string `json:"model,omitempty"`
Provider string `json:"provider,omitempty"`
}
ChatResponse is the output of a non-streaming application call.
type CommittedToolApprovalResponse ¶
type CommittedToolApprovalResponse struct {
// contains filtered or unexported fields
}
type CommittedUserInputResponse ¶
type CommittedUserInputResponse struct {
// contains filtered or unexported fields
}
CommittedUserInputResponse is the durable half of an ask_user response. Keeping it separate from the continuation lets the runtime acknowledge the user's click as soon as the decision commits, without imposing the command acknowledgement deadline on the following model call.
type ContentPart ¶
type ContentPart = turn.ContentPart
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type EditLatestMessageInput ¶
type EditLatestMessageInput struct {
BotID string
SessionID string
RunID string
TurnID string
TurnPosition *int64
// TargetTurnID names the round being replaced. See RetryLatestMessageInput.
TargetTurnID string
Text string
Attachments []ChatAttachment
ActorChannelIdentityID string
ActorUserID string
ChatToken string
Model string
ReasoningEffort string
WorkspaceTargetID string
ToolHTTPURL string
}
type EmailChatGateway ¶
type EmailChatGateway struct {
// contains filtered or unexported fields
}
EmailChatGateway implements email.ChatTriggerer by delegating to the Service.
func NewEmailChatGateway ¶
func (*EmailChatGateway) TriggerBotChat ¶
func (g *EmailChatGateway) TriggerBotChat(ctx context.Context, botID, content string) error
type InjectMessage ¶
type InjectMessage = turn.InjectMessage
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type InjectedMessageRecord ¶
InjectedMessageRecord records where an injected message belongs in the persisted model-message sequence.
type ModelMessage ¶
type ModelMessage = turn.ModelMessage
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type OutboundAssetRef ¶
type OutboundAssetRef = turn.OutboundAssetRef
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type PlatformIdentity ¶
type PlatformIdentity struct {
ID string
Platform string
ExternalIdentity string
SelfIdentity map[string]any
}
PlatformIdentity is the Agent-owned projection of a connected platform account used while assembling the system prompt.
type PlatformIdentitySource ¶
type PlatformIdentitySource interface {
ListPlatformIdentities(ctx context.Context, botID string) ([]PlatformIdentity, error)
}
PlatformIdentitySource supplies connected platform identities without exposing Channel configuration types to the application layer.
type RequestedSkillContext ¶
type RequestedSkillContext = turn.RequestedSkillContext
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type ResolveRunConfigResult ¶
type ResolveRunConfigResult struct {
RunConfig native.RunConfig
ModelID string // database UUID of the selected model
RuntimeType string
ContextBudgetMaxTokens int
}
ResolveRunConfigResult holds a fully resolved run configuration for one agent request, together with the selected model and session runtime. Produced by application.Service.ResolveRunConfig and consumed by the turn runtime adapters.
type RetryLatestMessageInput ¶
type RetryLatestMessageInput struct {
BotID string
SessionID string
RunID string
TurnID string
TurnPosition *int64
// TargetTurnID names the round being replaced. It is distinct from TurnID,
// which names the new turn this operation admits.
TargetTurnID string
ActorChannelIdentityID string
ActorUserID string
ChatToken string
Model string
ReasoningEffort string
WorkspaceTargetID string
ToolHTTPURL string
}
type Runner ¶
type Runner interface {
Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
StreamChat(ctx context.Context, req ChatRequest) (<-chan StreamChunk, <-chan error)
TriggerSchedule(ctx context.Context, botID string, payload schedule.TriggerPayload, token string) (schedule.TriggerResult, error)
}
Runner defines conversation execution behavior for sync, stream, and scheduled flows.
type ScheduleGateway ¶
type ScheduleGateway struct {
// contains filtered or unexported fields
}
ScheduleGateway adapts schedule trigger calls to the chat Service.
func NewScheduleGateway ¶
func NewScheduleGateway(service *Service) *ScheduleGateway
NewScheduleGateway creates a ScheduleGateway backed by the given Service.
func (*ScheduleGateway) TriggerSchedule ¶
func (g *ScheduleGateway) TriggerSchedule(ctx context.Context, botID string, payload schedule.TriggerPayload, token string) (schedule.TriggerResult, error)
TriggerSchedule delegates a schedule trigger to the chat Service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service orchestrates chat with the internal agent.
func NewService ¶
func NewService( log *slog.Logger, modelsService *models.Service, queries dbstore.Queries, messageService messagepkg.Service, settingsService *settings.Service, accountService *accounts.Service, a *native.Agent, clockLocation *time.Location, timeout time.Duration, ) *Service
NewService creates an application service backed by the native agent.
func (*Service) ACPSessionExecutionInfo ¶
func (*Service) AbortRuntimeRun ¶
func (s *Service) AbortRuntimeRun( ctx context.Context, botID, sessionID, runID, controlID string, ) (bool, error)
AbortRuntimeRun routes an abort through the durable runtime and then reconciles its lifecycle asynchronously. The acknowledgement remains owned by AbortControl; audit persistence failures are counted and logged only.
func (*Service) AdmitSubagentRun ¶
func (s *Service) AdmitSubagentRun( ctx context.Context, botID, threadID, invocationID string, submission []byte, ) (context.Context, tools.SubagentAdmission, func(tools.SubagentTerminal), error)
AdmitSubagentRun puts a spawned agent's turn through the same durable admission every other turn takes, and answers in the vocabulary of the turn port so the tool layer never sees a runtime type.
The slot a subagent takes is its own thread's, not its parent's: a parent may have several agents working at once, and each of those threads still runs one turn at a time. Busy therefore means *this agent* is already working — a fact the parent model can act on — rather than a failure to report.
func (*Service) AdvancePlainTextUserInput ¶
func (s *Service) AdvancePlainTextUserInput(ctx context.Context, input userinput.AdvanceTextInput) (userinput.AdvanceTextResult, error)
func (*Service) ApplyUserMessageHookAndPersistUserTurn ¶
func (s *Service) ApplyUserMessageHookAndPersistUserTurn(ctx context.Context, req ChatRequest) (ChatRequest, messagepkg.Message, error)
ApplyUserMessageHookAndPersistUserTurn applies the normal user-message hook before writing a user turn ahead of agent execution. Web skill activations use this so a denied hook cannot leave a persisted user-only special turn.
func (*Service) Chat ¶
func (s *Service) Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
Chat sends a synchronous chat request and stores the result.
func (*Service) CommitToolApprovalResponse ¶
func (s *Service) CommitToolApprovalResponse(ctx context.Context, input ToolApprovalResponseInput) (CommittedToolApprovalResponse, error)
func (*Service) CommitUserInputResponse ¶
func (s *Service) CommitUserInputResponse(ctx context.Context, input UserInputResponseInput) (CommittedUserInputResponse, error)
func (*Service) ConfigureACPMode ¶
func (s *Service) ConfigureACPMode(ctx context.Context, input ACPModeRequest) (ACPModeState, error)
ConfigureACPMode exposes the Agent's session modes without interpreting their IDs. An empty ModeID reads state; a non-empty ID is sent unchanged to session/set_mode and affects only the live ACP session.
func (*Service) ContinueCommittedToolApprovalResponse ¶
func (s *Service) ContinueCommittedToolApprovalResponse(ctx context.Context, committed CommittedToolApprovalResponse, eventCh chan<- WSStreamEvent) error
func (*Service) ContinueCommittedUserInputResponse ¶
func (s *Service) ContinueCommittedUserInputResponse(ctx context.Context, committed CommittedUserInputResponse, eventCh chan<- WSStreamEvent) error
func (*Service) DeferSessionCompaction ¶
func (*Service) EditLatestMessageWS ¶
func (s *Service) EditLatestMessageWS(ctx context.Context, input EditLatestMessageInput, eventCh chan<- WSStreamEvent, abortCh <-chan struct{}) error
func (*Service) EnsureTerminalContextLifecycle ¶
func (s *Service) EnsureTerminalContextLifecycle( ctx context.Context, runID, botID, sessionID string, cause error, )
EnsureTerminalContextLifecycle records a content-light fallback for runs that fail before native context assembly creates a snapshot. A terminal writer with an authoritative holder always wins this read-before-create race.
func (*Service) InlineImageAttachments ¶
func (s *Service) InlineImageAttachments(ctx context.Context, botID string, refs []timeline.ImageAttachmentRef) []sdk.ImagePart
InlineImageAttachments resolves image content hashes to sdk.ImagePart values using the configured asset loader. Intended for the discuss driver to inline images from new RC segments before calling the LLM.
func (*Service) LinkOutboundAssets ¶
func (s *Service) LinkOutboundAssets(ctx context.Context, botID, sessionID string, assets []messagepkg.AssetRef)
LinkOutboundAssets links bot-generated assets to the assistant message that produced them. Assets carrying a `tool_call_id` metadata entry are anchored to the assistant message containing that tool call, so a history rebuild keeps the live ordering (e.g. a generated image stays above the closing text). Assets without one fall back to the latest assistant message. When sessionID is provided, the search is scoped to that session; otherwise it falls back to a bot-wide search. Used by the WebSocket path where attachment ingestion happens after message persistence.
func (*Service) PendingRuntimeDecision ¶
func (s *Service) PendingRuntimeDecision(ctx context.Context, runID string) (sessionruntime.DecisionTarget, bool, error)
PendingRuntimeDecision resolves the one durable decision that parked runID. It is used only by expired-owner recovery, where preserving the exact row is required before advancing the run's fencing token.
func (*Service) PrepareEditLatestTurnOperation ¶
func (s *Service) PrepareEditLatestTurnOperation(ctx context.Context, sessionID, turnID string) (string, error)
PrepareEditLatestTurnOperation validates the replacement target before Session Runtime publishes it to subscribers and returns the exact persisted user message where the old turn begins.
func (*Service) PrepareRetryLatestTurnOperation ¶
func (s *Service) PrepareRetryLatestTurnOperation(ctx context.Context, sessionID, turnID string) (string, error)
PrepareRetryLatestTurnOperation validates the replacement target before Session Runtime publishes it to subscribers and returns the exact persisted message where the old assistant tail begins.
func (*Service) ResolveRunConfig ¶
func (s *Service) ResolveRunConfig(ctx context.Context, botID, sessionID, channelIdentityID, currentPlatform, replyTarget, conversationType, chatToken string) (ResolveRunConfigResult, error)
ResolveRunConfig builds a complete RunConfig (model, system prompt, tools, identity) for a bot+session without loading messages or requiring a query. The caller is responsible for filling RunConfig.Messages. Used by discuss turns to reuse the service's model, tools, and prompt pipeline.
func (*Service) ResolveRuntimeDecision ¶
func (s *Service) ResolveRuntimeDecision(ctx context.Context, commandType, decisionID string) (sessionruntime.DecisionTarget, error)
ResolveRuntimeDecision reads the authoritative decision row before any live owner lookup. Terminal rows are returned too: the router needs to distinguish a known, already-decided request from an unfenced ACP/MCP request.
func (*Service) ResolveTurnIDForMessage ¶
func (s *Service) ResolveTurnIDForMessage(ctx context.Context, sessionID, messageID string) (string, error)
ResolveTurnIDForMessage maps a stored message id onto the round that contains it. It backs the compatibility shim for the pre-turn `message_id` spelling and has no other caller: a client holds a turn id from admission onward and names the round directly, while needing a stored message id is exactly what used to force it to wait for the round to persist.
Remove it, and the shim, once the compatibility window for `message_id` closes. (Not marked Deprecated in the godoc sense — the shim is its intended caller, so flagging that call adds noise rather than signal.)
func (*Service) RespondToolApproval ¶
func (s *Service) RespondToolApproval(ctx context.Context, input turn.ToolApprovalResponse, eventCh chan<- json.RawMessage) error
RespondToolApproval resumes a turn deferred on tool approval.
func (*Service) RespondUserInput ¶
func (s *Service) RespondUserInput(ctx context.Context, input turn.UserInputResponse, eventCh chan<- json.RawMessage) error
RespondUserInput resumes a turn deferred on ask_user.
func (*Service) RetryLatestMessageWS ¶
func (s *Service) RetryLatestMessageWS(ctx context.Context, input RetryLatestMessageInput, eventCh chan<- WSStreamEvent, abortCh <-chan struct{}) error
func (*Service) SetACPSessionPool ¶
func (s *Service) SetACPSessionPool(pool acpPrompter)
func (*Service) SetAllowedTeam ¶
SetAllowedTeam restricts the service to a single team. The in-process runtime's database pool is session-bound to one team GUC, so commands for any other team must fail closed (turn.ErrTeamNotServed) instead of silently operating on the bound team's data. The composition root injects the self-hosted singleton team; a hosted multi-team runtime replaces this with request-scoped team binding.
func (*Service) SetBackgroundManager ¶
func (s *Service) SetBackgroundManager(m *background.Manager)
SetBackgroundManager configures the background task manager used for task summaries and background status tooling.
func (*Service) SetBotPermissionChecker ¶
func (s *Service) SetBotPermissionChecker(checker botPermissionChecker)
func (*Service) SetCompactionService ¶
func (s *Service) SetCompactionService(service *compaction.Service)
SetCompactionService configures the compaction service for context compaction.
func (*Service) SetContextAbsoluteMaxTokens ¶
SetContextAbsoluteMaxTokens sets the server-wide context admission cap (CM-ADM-001). Zero keeps the shared default; the cap is never disabled.
func (*Service) SetEventPublisher ¶
func (s *Service) SetEventPublisher(p messageevent.Publisher)
SetEventPublisher configures the event publisher for broadcasting events such as session title updates.
func (*Service) SetGatewayAssetLoader ¶
func (s *Service) SetGatewayAssetLoader(loader gatewayAssetLoader)
SetGatewayAssetLoader configures optional asset loading used to inline attachments before calling the agent gateway.
func (*Service) SetHookService ¶
func (*Service) SetMemoryRegistry ¶
func (s *Service) SetMemoryRegistry(registry *memprovider.Registry)
SetMemoryRegistry sets the provider registry for memory operations.
func (*Service) SetPipeline ¶
SetPipeline configures the DCP pipeline for RC-based context assembly. When set, resolve() will use RC from the pipeline instead of loading history from bot_history_messages for sessions that have pipeline data.
func (*Service) SetPlatformIdentitySource ¶
func (s *Service) SetPlatformIdentitySource(source PlatformIdentitySource)
SetPlatformIdentitySource configures the neutral source used to load platform identity metadata for system prompt generation.
func (*Service) SetSessionRuntime ¶
func (s *Service) SetSessionRuntime(manager *sessionruntime.Manager)
SetSessionRuntime injects the durable admission gate. Setter injection rather than a constructor argument because the manager and this service are wired into the same fx graph and each is reachable from the other's dependencies.
func (*Service) SetSessionService ¶
func (s *Service) SetSessionService(service SessionService)
SetSessionService configures the session service used for auto title generation.
func (*Service) SetSkillLoader ¶
func (s *Service) SetSkillLoader(sl SkillLoader)
SetSkillLoader sets the skill loader used to populate usable skills in gateway requests.
func (*Service) SetToolApprovalService ¶
func (s *Service) SetToolApprovalService(service *toolapproval.Service)
func (*Service) SetUserInputService ¶
func (*Service) SetWorkdirResolver ¶
func (s *Service) SetWorkdirResolver(resolver sessionWorkdirResolver)
SetWorkdirResolver configures resolution of session workdir bindings.
func (*Service) SetWorkspaceTargetResolver ¶
func (s *Service) SetWorkspaceTargetResolver(resolver workspaceTargetResolver)
SetWorkspaceTargetResolver configures request-scoped Computer resolution.
func (*Service) StartTurn ¶
StartTurn validates the command, admits it durably, starts the underlying stream, and returns a handle whose Events/Errs mirror the application stream.
func (*Service) StoreRound ¶
func (s *Service) StoreRound(ctx context.Context, botID, sessionID, channelIdentityID, currentPlatform string, sdkMessages []sdk.Message, modelID string) error
StoreRound persists SDK messages as a complete round (assistant + tool output) into bot_history_messages with full metadata, usage tracking, and memory extraction. Used by the discuss driver so it shares the same persistence quality as chat mode.
func (*Service) StreamChat ¶
func (s *Service) StreamChat(ctx context.Context, req ChatRequest) (<-chan StreamChunk, <-chan error)
StreamChat runs a streaming chat via the internal agent.
func (*Service) StreamChatWS ¶
func (s *Service) StreamChatWS( ctx context.Context, req ChatRequest, eventCh chan<- WSStreamEvent, abortCh <-chan struct{}, ) error
StreamChatWS resolves the agent context and streams agent events. Events are sent on eventCh. When abortCh is closed, the context is cancelled.
func (*Service) SubagentRunObserver ¶
func (s *Service) SubagentRunObserver(ctx context.Context) native.SpawnRunObserver
SubagentRunObserver returns a per-event publisher that feeds one spawned agent run's stream into the session runtime, or nil when there is nothing to publish to — no runtime configured, or a context without an admitted handle.
The returned function mirrors forwardWSStreamEvents' publishing discipline: events are published on a context that survives the run's cancellation (an aborted run's final events are exactly the ones a subscriber must see), and a lost ownership stops publishing outright because every later event would fail identically.
func (*Service) SubagentStepCommit ¶
func (s *Service) SubagentStepCommit( ctx context.Context, botID, sessionID, modelID, turnRequestMessageID string, contextLifecycle *contextfrag.LifecycleHolder, onPersisted func(), ) ( func(context.Context, int, *sdk.StepResult) error, func(context.Context, int, *sdk.StepResult) error, )
SubagentStepCommit returns the per-step persistence callback for one spawned agent run, or nil when incremental persistence is unavailable — no admitted handle on the context, no fence, no persisted request row to bind steps to, or a message service that cannot write fenced steps. A nil return means the spawn path keeps its terminal-snapshot persistence, so this is a capability probe as much as a constructor.
The callbacks persist exactly what the legacy terminal path persists — every non-user message of the step, marshalled whole — only earlier: each complete step or safe interrupted checkpoint lands in one fenced transaction instead of the whole run landing at the end. onPersisted fires after either kind of durable write; the spawn provider uses it to stop retrying an attempt whose output is already part of history.
func (*Service) TriggerSchedule ¶
func (s *Service) TriggerSchedule(ctx context.Context, botID string, payload schedule.TriggerPayload, token string) (triggerResult schedule.TriggerResult, err error)
TriggerSchedule executes a scheduled command via the internal agent.
type SessionService ¶
type SessionService interface {
Get(ctx context.Context, sessionID string) (session.Thread, error)
UpdateTitle(ctx context.Context, sessionID, title string) (session.Thread, error)
UpdateMetadata(ctx context.Context, sessionID string, metadata map[string]any) (session.Thread, error)
}
SessionService is the interface the application service uses for session metadata updates.
type SkillActivation ¶
type SkillActivation = turn.SkillActivation
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type SkillActivationSkill ¶
type SkillActivationSkill = turn.SkillActivationSkill
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type SkillEntry ¶
type SkillEntry struct {
Name string
Description string
Content string
Path string
Metadata map[string]any
}
SkillEntry represents a skill loaded from the container.
type SkillLoader ¶
type SkillLoader interface {
LoadSkills(ctx context.Context, botID string) ([]SkillEntry, error)
}
SkillLoader loads skills for a given bot from its container.
type StreamChunk ¶
type StreamChunk = json.RawMessage
StreamChunk is one raw event emitted by the application stream.
type ToolApprovalResponseInput ¶
type ToolApprovalResponseInput struct {
ControlID string
BotID string
ThreadID string
ActorChannelIdentityID string
ActorUserID string
ApprovalID string
ExplicitID string
ReplyExternalMessageID string
Decision string
// OptionID names the agent-provided permission option the decider picked;
// empty means the plain binary decision.
OptionID string
Reason string
ChatToken string
SuppressActivePromptAttach bool
}
type ToolCall ¶
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type ToolCallFunction ¶
type ToolCallFunction = turn.ToolCallFunction
The canonical turn value objects are re-exported inside application so the orchestration code can use them without maintaining a second DTO family.
type UserInputResponseInput ¶
type UserInputResponseInput struct {
ControlID string
BotID string
ThreadID string
ActorChannelIdentityID string
ActorUserID string
UserInputID string
ExplicitID string
ReplyExternalMessageID string
Answers []userinput.QuestionAnswer
TextAnswer string
Canceled bool
Reason string
ChatToken string
SuppressActivePromptAttach bool
}
type WSStreamEvent ¶
type WSStreamEvent = json.RawMessage
WSStreamEvent represents a raw JSON event forwarded from the agent.
type WorkspaceTarget ¶
type WorkspaceTarget struct {
TargetID string `json:"target_id"`
Kind string `json:"kind"`
Name string `json:"name"`
}
WorkspaceTarget is the immutable execution-location snapshot resolved for one application request.
Source Files
¶
- acp_context.go
- capability_policy.go
- context_frag.go
- contract.go
- discuss_admission.go
- email_gateway.go
- gateway_prune.go
- hook_system_sections.go
- hooks.go
- idle_timeout.go
- memory_query.go
- platform_identity.go
- reasoning_timing.go
- requested_skills.go
- resolve_result.go
- runtime_decision.go
- schedule_gateway.go
- service.go
- service_acp.go
- service_acp_active_prompt.go
- service_acp_mode.go
- service_attachments.go
- service_compaction.go
- service_compaction_barrier.go
- service_continuation.go
- service_history.go
- service_history_compaction.go
- service_history_compaction_merge.go
- service_history_messages.go
- service_history_prepare.go
- service_identity.go
- service_memory.go
- service_messages.go
- service_model_selection.go
- service_retry_edit.go
- service_run_lifecycle.go
- service_runtime_abort.go
- service_session_workdir.go
- service_settings.go
- service_store.go
- service_stream.go
- service_timezone.go
- service_title.go
- service_tool_approval.go
- service_trigger.go
- service_user_input.go
- service_user_persist.go
- service_util.go
- service_workspace_target.go
- step_commit.go
- subagent_run_context.go
- subagent_step_commit.go
- subagent_thread.go
- tool_closure.go
- turn_admission.go
- turn_convert.go
- turn_discuss.go
- turn_service.go
- types.go