Documentation
¶
Overview ¶
Package aictx 提供 internal/ai 各子包共享的 context 键、决策原语与 slot 协议。
本包没有任何 internal/ai/* 依赖,是 ai 体系的最底层公共类型。其他子包 (audit/policy/permission/helper/tool/runner) 都向上依赖本包。
Index ¶
- Constants
- func ArgInt(args map[string]any, key string) int
- func ArgInt64(args map[string]any, key string) int64
- func ArgString(args map[string]any, key string) string
- func GetAuditSource(ctx context.Context) string
- func GetConversationID(ctx context.Context) int64
- func GetGrantSessionID(ctx context.Context) string
- func GetPolicyLang(ctx context.Context) string
- func GetSessionID(ctx context.Context) string
- func NotifyDataChanged(resource string)
- func RecordDecision(ctx context.Context, result CheckResult)
- func SetDataChangeNotifier(n DataChangeNotifier)
- func WithAuditSource(ctx context.Context, source string) context.Context
- func WithCheckResultSlot(ctx context.Context, slot *CheckResult) context.Context
- func WithConversationID(ctx context.Context, id int64) context.Context
- func WithGrantSessionID(ctx context.Context, id string) context.Context
- func WithPolicyLang(ctx context.Context, lang string) context.Context
- func WithSessionID(ctx context.Context, id string) context.Context
- type CheckResult
- type DataChangeNotifier
- type Decision
Constants ¶
const ( SourcePolicyAllow = "policy_allow" // 命令策略白名单放行 SourcePolicyDeny = "policy_deny" // 命令策略黑名单拒绝 SourceUserAllow = "user_allow" // 用户手动允许 SourceUserDeny = "user_deny" // 用户手动拒绝 SourceGrantAllow = "grant_allow" // Grant 预批准匹配放行 SourceGrantDeny = "grant_deny" // Grant 权限申请被拒绝 )
决策来源常量
Variables ¶
This section is empty.
Functions ¶
func GetConversationID ¶
GetConversationID 获取会话 ID
func GetGrantSessionID ¶
GetGrantSessionID 获取授权会话 ID
func NotifyDataChanged ¶
func NotifyDataChanged(resource string)
NotifyDataChanged 安全广播一次变更事件,未注入通知器时静默忽略。
func RecordDecision ¶
func RecordDecision(ctx context.Context, result CheckResult)
RecordDecision 在工具 handler 中写入决策结果,供 audit middleware 读取。 没有 slot(如 opsctl 直调 handler 路径)时为 no-op。
func SetDataChangeNotifier ¶
func SetDataChangeNotifier(n DataChangeNotifier)
SetDataChangeNotifier 注入数据变更通知器(应在应用启动时调用)。
func WithAuditSource ¶
WithAuditSource 注入审计来源
func WithCheckResultSlot ¶
func WithCheckResultSlot(ctx context.Context, slot *CheckResult) context.Context
WithCheckResultSlot 把 slot 挂到 ctx 上,供后续 RecordDecision 写入。 通常由 audit middleware 在 c.Next() 之前调用。
func WithConversationID ¶
WithConversationID 注入会话 ID
func WithGrantSessionID ¶
WithGrantSessionID 注入授权会话 ID
func WithPolicyLang ¶
WithPolicyLang 设置策略消息的语言("zh-cn", "en" 等)
Types ¶
type CheckResult ¶
type CheckResult struct {
Decision Decision
Message string // 返回给 AI 的消息
HintRules []string // 拒绝时的允许规则提示
DecisionSource string // 决策来源(SourcePolicyAllow 等常量)
MatchedPattern string // 匹配的命令模式
}
CheckResult 权限检查结果
func GetCheckResult ¶
func GetCheckResult(ctx context.Context) *CheckResult
GetCheckResult 读取当前 ctx 上挂的 *CheckResult slot 值。 返回 nil 表示未挂 slot(opsctl 直调路径)。
func (CheckResult) DecisionString ¶
func (r CheckResult) DecisionString() string
DecisionString 返回决策的字符串表示(用于审计日志存储)
type DataChangeNotifier ¶
type DataChangeNotifier interface {
NotifyDataChanged(resource string)
}
DataChangeNotifier 由 app 层注入,向前端广播数据变更(资产/分组等), 触发 UI 自动刷新。