connector

package
v0.6.129 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CardActionDecisionApprove = "approve"
	CardActionDecisionReject  = "reject"
)

Variables

View Source
var ErrIgnoreMessage = errors.New("ignore message")

ErrIgnoreMessage is returned when a message should be silently dropped.

Functions

func NewGoalRunHelper added in v0.6.117

func NewGoalRunHelper(processor *Processor) automation.GoalRunHelper

NewGoalRunHelper creates a GoalRunHelper that delegates to the Processor's RunGoalMessage pipeline, giving goals the same OnProgress and OnRawEvent dispatching that regular user messages receive.

Types

type App

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

App orchestrates message processing, session management, and LLM interaction for a single bot instance.

func NewApp

func NewApp(cfg config.Config, processor *Processor) *App

NewApp creates a new App with the given config and processor.

func (*App) FlushRuntimeState

func (a *App) FlushRuntimeState() error

func (*App) FlushRuntimeStateIfDirty

func (a *App) FlushRuntimeStateIfDirty() error

func (*App) GetSessionMeta added in v0.6.127

func (a *App) GetSessionMeta(sessionKey string) automation.SessionMeta

GetSessionMeta returns the LLM configuration for the given session key.

func (*App) GetSessionThreadID added in v0.6.110

func (a *App) GetSessionThreadID(sessionKey string) string

GetSessionThreadID returns the current backend LLM thread ID for the given session key. Returns an empty string if the session has no thread yet.

func (*App) GetSessionWorkDir added in v0.6.127

func (a *App) GetSessionWorkDir(sessionKey string) string

GetSessionWorkDir returns the workspace directory for the given session key.

func (*App) IsSessionActive added in v0.6.62

func (a *App) IsSessionActive(sessionKey string) bool

IsSessionActive reports whether any session matching the given sessionKey's visibility prefix is currently processing a user message. The automation engine calls this before executing a scheduled task to skip execution when the user is actively conversing, avoiding interruption.

Thread isolation: if either the query key or an active key carries a thread-specific token (seed or thread), only sessions in the *same* thread are considered a match. This prevents a conversation in one Feishu work-thread from blocking automation tasks that target a different thread in the same group.

func (*App) LoadRuntimeState

func (a *App) LoadRuntimeState(path string) error

func (*App) RecordSessionUsage added in v0.6.127

func (a *App) RecordSessionUsage(sessionKey string, usage llm.Usage)

RecordSessionUsage records LLM token usage for the given session key.

func (*App) ReleaseSession added in v0.6.80

func (a *App) ReleaseSession(sessionKey string)

ReleaseSession removes a previously acquired automation session entry. It is a no-op if the session entry was already replaced by a newer user-message run (version != 0).

func (*App) Run

func (a *App) Run(ctx context.Context) error

func (*App) RunWithoutConnector added in v0.6.9

func (a *App) RunWithoutConnector(ctx context.Context) error

func (*App) SetAutomationRunner

func (a *App) SetAutomationRunner(runner AutomationRunner)

func (*App) SetBotOpenID added in v0.6.53

func (a *App) SetBotOpenID(openID string)

func (*App) SetCardActionHandler added in v0.6.13

func (a *App) SetCardActionHandler(handler CardActionHandler)

func (*App) SetPromptLoader

func (a *App) SetPromptLoader(loader *prompting.Loader)

func (*App) TryAcquireSession added in v0.6.80

func (a *App) TryAcquireSession(sessionKey string, cancel context.CancelCauseFunc) bool

TryAcquireSession atomically checks whether the session is inactive and, if so, registers it as active with version=0. Version 0 ensures that any real user message (version >= 1) will interrupt the task via the cancel function passed to this method (see enqueueJob).

func (*App) UpdateRuntimeConfig

func (a *App) UpdateRuntimeConfig(cfg config.Config)

type Attachment

type Attachment struct {
	SourceMessageID string
	Kind            string
	FileKey         string
	ImageKey        string
	FileName        string
	LocalPath       string
	DownloadError   string
}

Attachment represents a file or image attached to an incoming message.

type AttachmentDownloader

type AttachmentDownloader interface {
	DownloadAttachment(ctx context.Context, resourceScopeKey, sourceMessageID string, attachment *Attachment) error
}

AttachmentDownloader downloads attachments to the local filesystem.

type AutomationRunner

type AutomationRunner interface {
	Run(ctx context.Context)
}

type CardActionHandler added in v0.6.13

type CardActionHandler interface {
	HandleCardAction(ctx context.Context, req CardActionRequest) (CardActionResult, error)
}

type CardActionRequest added in v0.6.13

type CardActionRequest struct {
	Kind          string
	CampaignID    string
	PlanRound     int
	Decision      string
	ActorOpenID   string
	ActorUserID   string
	OpenMessageID string
}

type CardActionResult added in v0.6.13

type CardActionResult struct {
	Toast     string
	ToastType string
}

type ChatMemberNameResolver

type ChatMemberNameResolver interface {
	ResolveChatMemberName(ctx context.Context, chatID, openID, userID string) (string, error)
}

ChatMemberNameResolver resolves a user's display name within a specific chat.

type Job

type Job struct {
	ReceiveID            string
	ReceiveIDType        string
	ChatType             string
	BotID                string
	BotName              string
	BotOpenID            string
	BotUserID            string
	SoulPath             string
	SenderName           string
	SenderOpenID         string
	SenderUserID         string
	SenderUnionID        string
	MentionedUsers       []MentionedUser
	SourceMessageID      string
	ReplyParentMessageID string
	ThreadID             string
	RootID               string
	MessageType          string
	Text                 string
	Attachments          []Attachment
	RawContent           string
	EventID              string
	ReceivedAt           time.Time
	ResourceScopeKey     string
	SessionKey           string
	SessionVersion       uint64
	Scene                string
	ResponseMode         string
	CreateFeishuThread   bool
	LLMProvider          string
	LLMModel             string
	LLMProfile           string
	LLMReasoningEffort   string
	LLMVariant           string
	LLMPersonality       string
	LLMPromptPrefix      string
	NoReplyToken         string
	SoulDoc              soulDocument
	DisableAck           bool
	WorkflowPhase        string
}

Job is a unit of work dispatched to the connector's processing pipeline.

func BuildJob

func BuildJob(event *larkim.P2MessageReceiveV1) (*Job, error)

type JobProcessState

type JobProcessState string
const (
	JobProcessCompleted         JobProcessState = "completed"
	JobProcessRetryAfterRestart JobProcessState = "retry_after_restart"
)

type MentionedUser

type MentionedUser struct {
	Key     string
	Name    string
	OpenID  string
	UserID  string
	UnionID string
}

MentionedUser holds information about a user @-mentioned in a message.

type Processor

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

Processor handles job execution, prompt building, session state, and reply dispatch for incoming connector messages.

func NewProcessor

func NewProcessor(
	backend llm.Backend,
	sender Sender,
	failureMessage string,
	thinkingMessage string,
) *Processor

NewProcessor creates a Processor with the required dependencies.

func (*Processor) FlushSessionState

func (p *Processor) FlushSessionState() error

func (*Processor) FlushSessionStateIfDirty

func (p *Processor) FlushSessionStateIfDirty() error

func (*Processor) LoadSessionState

func (p *Processor) LoadSessionState(path string) error

func (*Processor) ProcessJob

func (p *Processor) ProcessJob(ctx context.Context, job Job) bool

func (*Processor) ProcessJobState

func (p *Processor) ProcessJobState(ctx context.Context, job Job) JobProcessState

func (*Processor) RunGoalMessage added in v0.6.117

func (p *Processor) RunGoalMessage(
	ctx context.Context,
	threadID string,
	userText string,
	scene string,
	env map[string]string,
	workspaceDir string,
	meta automation.SessionMeta,
	onProgress llm.ProgressFunc,
) (llm.RunResult, error)

RunGoalMessage runs a goal prompt through the same LLM pipeline used for regular user messages, with full OnRawEvent (reasoning, tool_use, tool_call) debug logging. It returns the complete RunResult including GoalDone so the goal engine can decide whether to continue iteration or mark complete.

func (*Processor) SetBuiltinHelpConfig added in v0.3.12

func (p *Processor) SetBuiltinHelpConfig(cfg config.Config)

func (*Processor) SetHeartbeatShowShellCommands added in v0.6.92

func (p *Processor) SetHeartbeatShowShellCommands(show bool)

func (*Processor) SetImmediateFeedback

func (p *Processor) SetImmediateFeedback(mode, emojiType string)

func (*Processor) SetLLMBackend

func (p *Processor) SetLLMBackend(backend llm.Backend)

func (*Processor) SetPromptLoader

func (p *Processor) SetPromptLoader(loader *prompting.Loader)

func (*Processor) SetReplyMessages

func (p *Processor) SetReplyMessages(failureMessage, thinkingMessage string)

func (*Processor) SetRuntimeAPI

func (p *Processor) SetRuntimeAPI(baseURL, token, runtimeBin string)

func (*Processor) SetSceneIdentityHints added in v0.6.110

func (p *Processor) SetSceneIdentityHints(chatDisable, workDisable bool)

func (*Processor) SetStatusIdentity added in v0.5.27

func (p *Processor) SetStatusIdentity(botID, botName string)

func (*Processor) SetStatusStores added in v0.5.25

func (p *Processor) SetStatusStores(automationStore *automation.Store)

func (*Processor) SetStatusUsageSources added in v0.5.27

func (p *Processor) SetStatusUsageSources(sources []StatusUsageSource)

func (*Processor) SetWorkspaceDir added in v0.6.68

func (p *Processor) SetWorkspaceDir(workspaceDir string)

func (*Processor) TrySteerJob added in v0.6.83

func (p *Processor) TrySteerJob(ctx context.Context, job Job) (bool, error)

func (*Processor) UpdateRuntimeConfig added in v0.5.27

func (p *Processor) UpdateRuntimeConfig(update ProcessorRuntimeUpdate) error

type ProcessorRuntimeUpdate added in v0.5.27

type ProcessorRuntimeUpdate struct {
	Backend                llm.Backend
	FailureMessage         string
	ThinkingMessage        string
	ImmediateFeedbackMode  string
	ImmediateFeedbackEmoji string
}

type ReplyContextProvider

type ReplyContextProvider interface {
	GetMessageText(ctx context.Context, messageID string) (string, error)
}

ReplyContextProvider provides the text of a previously sent reply message.

type Sender

type StatusUsageSource added in v0.5.27

type StatusUsageSource struct {
	BotID            string
	BotName          string
	SessionStatePath string
}

StatusUsageSource provides token usage data for status display.

type UserNameResolver

type UserNameResolver interface {
	ResolveUserName(ctx context.Context, openID, userID string) (string, error)
}

UserNameResolver resolves a user's display name.

Jump to

Keyboard shortcuts

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