Documentation
¶
Overview ¶
Package common holds shared platform helpers for inbound routing, slash commands, and outbound delivery.
Index ¶
- Constants
- Variables
- func AllowList(allowFrom, userID string) bool
- func AttachFSRel(name string) string
- func FormatAskUserPrompt(question string, options []string) string
- func FormatHelp(commands agentkit.Commands) string
- func FormatPermissionRequest(payload permission.RequestPayload) string
- func FormatUnknownCommand(name string) string
- func InboundFromContent(agentID agentkit.AgentID, route session.SessionRouteInput, ...) agentkit.MessageEvent
- func InboundMessage(agentID agentkit.AgentID, sessionID agentkit.SessionID, ...) agentkit.MessageEvent
- func IsImageAttachment(mimeType, filename string) bool
- func IsOldMessage(msgTime time.Time) bool
- func IsSlashCommand(text string) bool
- func MarkdownToSlackMrkdwn(md string) string
- func ModelMessageText(msg agentkit.ModelMessage) string
- func NormalizeSlackAPIURL(raw string) (string, error)
- func ParsePermissionCallback(data string) (requestID string, index int, ok bool)
- func ParseSlashCommand(line string) (name, args string, ok bool)
- func PermissionActionValue(index int) string
- func PermissionCallbackData(requestID string, index int) string
- func PermissionConversationFromExtra(extra map[string]string) string
- func PermissionDecisionValue(decision string) string
- func PermissionReplyEvent(agentID agentkit.AgentID, sessionID agentkit.SessionID, ...) agentkit.MessageEvent
- func PermissionReplyEventWithConversation(agentID agentkit.AgentID, sessionID agentkit.SessionID, ...) agentkit.MessageEvent
- func PermissionReplyFromAction(actionVal, userID string, extra map[string]string) (permission.Reply, bool)
- func ReadMediaPart(part agentkit.ContentPart) (data []byte, fileName string, err error)
- func RedactToken(text, token string) string
- func ResolveDomain(raw, defaultDomain string) (string, error)
- func UploadWorkRel() string
- func WarnAllowFromEmpty(platform, allowFrom string)
- func WithDeliveryRoute(event agentkit.MessageEvent, route agentkit.RouteRef) agentkit.MessageEvent
- func WithDeliverySession(event agentkit.MessageEvent, platformID string, delivery agentkit.SessionID) agentkit.MessageEvent
- func WithInboundRoute(event agentkit.MessageEvent, route session.SessionRouteInput) agentkit.MessageEvent
- type AgentRoutingConfig
- type AudioAttachment
- type ButtonOption
- type Card
- type CardActionLayout
- type CardActions
- type CardBuilder
- func (b *CardBuilder) Build() *Card
- func (b *CardBuilder) ListItemBtnExtra(desc, btnText, btnType, btnValue string, extra map[string]string) *CardBuilder
- func (b *CardBuilder) Markdown(content string) *CardBuilder
- func (b *CardBuilder) Note(text string) *CardBuilder
- func (b *CardBuilder) Title(title, color string) *CardBuilder
- type CardButton
- type CardDivider
- type CardElement
- type CardHeader
- type CardListItem
- type CardMarkdown
- type CardNote
- type CardSelect
- type CardSelectOption
- type ChatMessage
- type DeliveryRoute
- type DeliveryRouteInput
- type FileAttachment
- type ImageAttachment
- type InboundOpts
- type Inbox
- type InteractionOptions
- func (s *InteractionOptions) Clear(sessionID agentkit.SessionID)
- func (s *InteractionOptions) Reply(sessionID agentkit.SessionID, requestID, userID string, index int) (permission.Reply, bool)
- func (s *InteractionOptions) Set(sessionID agentkit.SessionID, requestID string, replies []permission.Reply)
- type MediaSender
- type MessageDedup
- type Outbound
- type ProgressCardEntry
- type ProgressCardEntryKind
- type ProgressCardPayload
- type ProgressCardState
- type SlashContext
- type SlashOutcome
- type SlashOutcomeKind
- type TextSender
Constants ¶
const (
// ProgressCardPayloadPrefix marks a structured payload for card-style progress.
ProgressCardPayloadPrefix = "__cc_connect_progress_card_v1__:"
)
Variables ¶
var ( ResolveDeliveryRoute = rtdelivery.ResolveRoute NormalizeDeliverySessionID = rtdelivery.NormalizeSessionID IsSlackChannelID = rtdelivery.IsSlackChannelID )
var ProcessStartTime = time.Now()
ProcessStartTime is set once at process startup. Platforms discard messages created before this time to avoid replay after restart.
Functions ¶
func AllowList ¶
AllowList returns true when userID is permitted by comma-separated allow_from. Empty or "*" means allow all.
func AttachFSRel ¶ added in v0.2.0
AttachFSRel is the path the model should pass to fs tools for an inbound file.
func FormatAskUserPrompt ¶
FormatAskUserPrompt formats ask_user question and numbered options for display.
func FormatHelp ¶
FormatHelp renders a plain-text command list for IM platforms.
func FormatPermissionRequest ¶
func FormatPermissionRequest(payload permission.RequestPayload) string
FormatPermissionRequest formats a permission request as assistant-visible text.
func FormatUnknownCommand ¶
FormatUnknownCommand matches cc-connect's unknown slash forwarding notice.
func InboundFromContent ¶
func InboundFromContent(agentID agentkit.AgentID, route session.SessionRouteInput, userID, content, extraContent string, images []ImageAttachment, files []FileAttachment, audio *AudioAttachment, filePaths []string, opts *InboundOpts) agentkit.MessageEvent
InboundFromContent builds a MessageEvent from text and optional rtmedia. extraContent is prepended (e.g. quoted reply context). Non-image files are saved under the tenant work dir and referenced in the prompt for the read tool.
func InboundMessage ¶
func IsImageAttachment ¶ added in v0.1.12
IsImageAttachment reports whether an inbound attachment should be sent to the model as vision input instead of a read-tool file path.
func IsOldMessage ¶
IsOldMessage returns true if msgTime is before process start (with grace).
func IsSlashCommand ¶
IsSlashCommand reports whether text starts with a slash command.
func MarkdownToSlackMrkdwn ¶
MarkdownToSlackMrkdwn converts standard Markdown to Slack mrkdwn format.
func ModelMessageText ¶
func ModelMessageText(msg agentkit.ModelMessage) string
ModelMessageText joins non-empty text parts from a model message.
func NormalizeSlackAPIURL ¶
NormalizeSlackAPIURL returns a slack-go compatible Web API base URL (trailing slash). Bare host URLs are normalized to end with /api/ like cc-connect.
func ParsePermissionCallback ¶
ParsePermissionCallback decodes Telegram callback_data.
func ParseSlashCommand ¶
ParseSlashCommand splits "/name args" into name and args.
func PermissionActionValue ¶
PermissionActionValue is the short action token stored in card button values.
func PermissionCallbackData ¶
PermissionCallbackData builds Telegram callback_data (perm:<requestID>:<index>).
func PermissionConversationFromExtra ¶ added in v0.2.2
PermissionConversationFromExtra reads the Loop conversation id echoed on card buttons.
func PermissionDecisionValue ¶
PermissionDecisionValue is the action token stored in allow/deny card buttons.
func PermissionReplyEvent ¶
func PermissionReplyEvent(agentID agentkit.AgentID, sessionID agentkit.SessionID, platformID, userID string, reply permission.Reply) agentkit.MessageEvent
func PermissionReplyEventWithConversation ¶ added in v0.2.2
func PermissionReplyEventWithConversation(agentID agentkit.AgentID, sessionID agentkit.SessionID, platformID, userID, conversation string, reply permission.Reply) agentkit.MessageEvent
func PermissionReplyFromAction ¶
func PermissionReplyFromAction(actionVal, userID string, extra map[string]string) (permission.Reply, bool)
PermissionReplyFromAction extracts a typed permission reply from card callback payloads.
func ReadMediaPart ¶ added in v0.1.6
func ReadMediaPart(part agentkit.ContentPart) (data []byte, fileName string, err error)
ReadMediaPart loads bytes for an outbound image or document content part. tool/send stores the resolved workspace path in URL.
func RedactToken ¶
RedactToken replaces a secret token in text with [REDACTED].
func ResolveDomain ¶
ResolveDomain returns trimmed raw when set, otherwise defaultDomain. Empty raw after trim uses defaultDomain without validation.
func UploadWorkRel ¶ added in v0.1.6
func UploadWorkRel() string
UploadWorkRel is the tenant-root-relative upload directory.
func WarnAllowFromEmpty ¶
func WarnAllowFromEmpty(platform, allowFrom string)
WarnAllowFromEmpty logs when allow_from is unset (permit-all).
func WithDeliveryRoute ¶ added in v0.2.1
func WithDeliveryRoute(event agentkit.MessageEvent, route agentkit.RouteRef) agentkit.MessageEvent
WithDeliveryRoute attaches the platform return address to an inbound event. Runner SyncMessageEvent copies the resolved envelope onto the inbound event.
func WithDeliverySession ¶ added in v0.2.1
func WithDeliverySession(event agentkit.MessageEvent, platformID string, delivery agentkit.SessionID) agentkit.MessageEvent
WithDeliverySession builds a session-kind route from platform and delivery ids. Prefer WithInboundRoute when channel, thread, or ReplyTo are known.
func WithInboundRoute ¶ added in v0.2.1
func WithInboundRoute(event agentkit.MessageEvent, route session.SessionRouteInput) agentkit.MessageEvent
WithInboundRoute attaches a structured session route to an inbound event.
Types ¶
type AgentRoutingConfig ¶
type AgentRoutingConfig struct {
AgentID agentkit.AgentID `json:"agentId"`
// SessionScope mirrors runner.config.sessionScope for platform-local slash
// commands (/new active-session mapping). Empty defaults to channel.
SessionScope string `json:"sessionScope"`
}
AgentRoutingConfig optionally pins inbound messages to a Loop agent. Empty agentId uses loop.defaultAgent.
func (AgentRoutingConfig) ResolveAgentID ¶
func (c AgentRoutingConfig) ResolveAgentID() agentkit.AgentID
type AudioAttachment ¶
AudioAttachment is an inbound voice message.
type ButtonOption ¶
type Card ¶
type Card struct {
Header *CardHeader
Elements []CardElement
Static bool // true after user answered; renderers must not emit interactive controls
}
Card is a platform-agnostic rich message (Slack Block Kit, Feishu interactive card, etc.).
func ConfirmedAllowDenyCard ¶ added in v0.1.12
ConfirmedAllowDenyCard updates an allow/deny card after the user decides.
func ConfirmedCardFromReply ¶ added in v0.1.12
func ConfirmedCardFromReply(reply permission.Reply, extra map[string]string) *Card
ConfirmedCardFromReply builds a non-interactive card after the user responds.
func ConfirmedPermissionCard ¶
ConfirmedPermissionCard updates the card after the user picks an option.
func PermissionCardFromPayload ¶
func PermissionCardFromPayload(payload permission.RequestPayload) *Card
PermissionCardFromPayload builds a card from Loop permission/request payload.
func (*Card) CollectButtons ¶
func (c *Card) CollectButtons() [][]ButtonOption
CollectButtons flattens list-item buttons for Telegram inline keyboards.
func (*Card) FallbackText ¶
type CardActionLayout ¶
type CardActionLayout string
const ( CardActionLayoutRow CardActionLayout = "row" CardActionLayoutEqualColumns CardActionLayout = "equal_columns" )
type CardActions ¶
type CardActions struct {
Buttons []CardButton
Layout CardActionLayout
}
type CardBuilder ¶
type CardBuilder struct {
// contains filtered or unexported fields
}
func NewCard ¶
func NewCard() *CardBuilder
func (*CardBuilder) Build ¶
func (b *CardBuilder) Build() *Card
func (*CardBuilder) ListItemBtnExtra ¶
func (b *CardBuilder) ListItemBtnExtra(desc, btnText, btnType, btnValue string, extra map[string]string) *CardBuilder
func (*CardBuilder) Markdown ¶
func (b *CardBuilder) Markdown(content string) *CardBuilder
func (*CardBuilder) Note ¶
func (b *CardBuilder) Note(text string) *CardBuilder
func (*CardBuilder) Title ¶
func (b *CardBuilder) Title(title, color string) *CardBuilder
type CardButton ¶
type CardDivider ¶
type CardDivider struct{}
type CardElement ¶
type CardElement interface {
// contains filtered or unexported methods
}
type CardHeader ¶
type CardListItem ¶
type CardMarkdown ¶
type CardMarkdown struct{ Content string }
type CardSelect ¶
type CardSelect struct {
Placeholder string
Options []CardSelectOption
InitValue string
}
type CardSelectOption ¶
type ChatMessage ¶
ChatMessage is a user-facing message derived from session events for IM / history UIs.
func MessageFromEvent ¶
func MessageFromEvent(ev agentkit.SessionEvent) *ChatMessage
MessageFromEvent maps one session event to a chat message when applicable.
func MessagesFromEvents ¶
func MessagesFromEvents(events []agentkit.SessionEvent) []ChatMessage
MessagesFromEvents derives chat-visible messages from session events.
func MessagesFromSession ¶
MessagesFromSession reads all session events and derives chat-visible messages.
type DeliveryRoute ¶ added in v0.1.22
type DeliveryRouteInput ¶ added in v0.1.22
type DeliveryRouteInput = delivery.RouteInput
type FileAttachment ¶
FileAttachment is an inbound file from an IM platform.
type ImageAttachment ¶
type ImageAttachment struct {
MimeType string
Data []byte
FileName string
// WorkPath is tenant-root-relative (e.g. work/upload/foo.png).
WorkPath string
}
ImageAttachment is an inbound image from an IM platform.
type InboundOpts ¶ added in v0.1.6
type InboundOpts struct {
// Workspace resolves upload paths; when set, inbound files land under the
// same tenant root as session/store and tool/fs-workspace.
Workspace workspace.Service
}
InboundOpts configures optional inbound media handling.
func InboundOptsFor ¶ added in v0.1.6
func InboundOptsFor(ws workspace.Service) *InboundOpts
InboundOptsFor builds inbound media options from an optional workspace.
type Inbox ¶
type Inbox struct {
// contains filtered or unexported fields
}
Inbox bridges async platform events into blocking Receive.
type InteractionOptions ¶
type InteractionOptions struct {
// contains filtered or unexported fields
}
InteractionOptions remembers option labels for platforms with short callback payloads (Telegram).
func (*InteractionOptions) Clear ¶
func (s *InteractionOptions) Clear(sessionID agentkit.SessionID)
func (*InteractionOptions) Reply ¶
func (s *InteractionOptions) Reply(sessionID agentkit.SessionID, requestID, userID string, index int) (permission.Reply, bool)
func (*InteractionOptions) Set ¶
func (s *InteractionOptions) Set(sessionID agentkit.SessionID, requestID string, replies []permission.Reply)
type MediaSender ¶ added in v0.1.6
type MediaSender func(ctx context.Context, sessionID agentkit.SessionID, part agentkit.ContentPart) error
MediaSender delivers a non-text assistant content part (image or document).
type MessageDedup ¶
type MessageDedup struct {
// contains filtered or unexported fields
}
MessageDedup tracks recently seen message IDs to prevent duplicate processing.
func (*MessageDedup) IsDuplicate ¶
func (d *MessageDedup) IsDuplicate(msgID string) bool
IsDuplicate returns true if msgID was already seen within the TTL window.
type Outbound ¶
type Outbound struct {
// contains filtered or unexported fields
}
Outbound handles agentkit outbound events with per-session text buffering.
func NewOutbound ¶
func NewOutbound(send TextSender, media MediaSender) *Outbound
type ProgressCardEntry ¶
type ProgressCardEntryKind ¶
type ProgressCardEntryKind string
const ( ProgressEntryInfo ProgressCardEntryKind = "info" ProgressEntryThinking ProgressCardEntryKind = "thinking" ProgressEntryToolUse ProgressCardEntryKind = "tool_use" ProgressEntryToolResult ProgressCardEntryKind = "tool_result" ProgressEntryError ProgressCardEntryKind = "error" )
type ProgressCardPayload ¶
type ProgressCardPayload struct {
Version int `json:"version,omitempty"`
Agent string `json:"agent,omitempty"`
Lang string `json:"lang,omitempty"`
State ProgressCardState `json:"state,omitempty"`
Entries []string `json:"entries,omitempty"`
Items []ProgressCardEntry `json:"items,omitempty"`
Truncated bool `json:"truncated"`
}
ProgressCardPayload carries structured progress entries for platforms that render custom progress cards.
func ParseProgressCardPayload ¶
func ParseProgressCardPayload(content string) (*ProgressCardPayload, bool)
ParseProgressCardPayload decodes a structured progress payload.
type ProgressCardState ¶
type ProgressCardState string
const ( ProgressCardStateRunning ProgressCardState = "running" ProgressCardStateCompleted ProgressCardState = "completed" ProgressCardStateFailed ProgressCardState = "failed" )
type SlashContext ¶ added in v0.1.6
type SlashContext struct {
Route agentkit.RouteRef
SessionScope session.SessionScope
UserID string
Metadata map[string]any
}
SlashContext carries delivery routing and sessionScope for slash commands.
type SlashOutcome ¶
type SlashOutcome struct {
Kind SlashOutcomeKind
Reply string
}
SlashOutcome is the result of ProcessSlash.
func ProcessSlash ¶
func ProcessSlash(ctx context.Context, commands agentkit.Commands, slash SlashContext, text string) (SlashOutcome, error)
ProcessSlash resolves slash commands via the injected commands registry. Non-slash input returns SlashNotCommand.
type SlashOutcomeKind ¶
type SlashOutcomeKind int
SlashOutcomeKind describes how an inbound slash command was resolved.
const ( // SlashNotCommand means the text is not a slash command. SlashNotCommand SlashOutcomeKind = iota // SlashHandled means the platform should reply locally and not enqueue a turn. SlashHandled // SlashForward means the command is unknown; notify the user then forward to the agent. SlashForward )