Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
33 lines
888 B
Go
33 lines
888 B
Go
package hitl
|
|
|
|
import (
|
|
"context"
|
|
|
|
"academy/internal/types"
|
|
)
|
|
|
|
type delegationKey struct{}
|
|
|
|
// Delegation is installed by the worker, never from model arguments. Register
|
|
// durably associates a prompt with the current run before it can be answered.
|
|
type Delegation struct {
|
|
Register func(context.Context, *types.AgentPrompt) error
|
|
Check func(context.Context) error
|
|
}
|
|
|
|
// WithDelegation attaches child prompt ownership checks to the execution context.
|
|
func WithDelegation(ctx context.Context, d Delegation) context.Context {
|
|
return context.WithValue(ctx, delegationKey{}, d)
|
|
}
|
|
|
|
// CheckDelegation rejects canceled or stale child executions before prompt handling.
|
|
func CheckDelegation(ctx context.Context) error {
|
|
if err := ctx.Err(); err != nil {
|
|
return err
|
|
}
|
|
if d, ok := ctx.Value(delegationKey{}).(Delegation); ok && d.Check != nil {
|
|
return d.Check(ctx)
|
|
}
|
|
return nil
|
|
}
|