Download this file
| 1 | package assist |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | // Filter decides what a person may be offered and run (spec |
| 6 | // 2026-11-26-assistant-abilities §6.1): a provider whose whole ability is |
| 7 | // off is never asked to list (Provider false), and an operation the |
| 8 | // person can't use isn't offered, described or run (Operation false). |
| 9 | type Filter interface { |
| 10 | Provider(name string) bool |
| 11 | Operation(op Operation) bool |
| 12 | } |
| 13 | |
| 14 | type filterKey struct{} |
| 15 | |
| 16 | // WithFilter is ctx with f applied to look, describe and invoke. |
| 17 | func WithFilter(ctx context.Context, f Filter) context.Context { |
| 18 | return context.WithValue(ctx, filterKey{}, f) |
| 19 | } |
| 20 | |
| 21 | func filterFrom(ctx context.Context) Filter { |
| 22 | f, _ := ctx.Value(filterKey{}).(Filter) |
| 23 | return f |
| 24 | } |
| 25 | |