feat!: v0.4.0 — hook redesign + built-in response cache#10
Merged
Conversation
added 4 commits
May 12, 2026 01:46
BREAKING: BeforeCallHook now returns (context.Context, *CallResult, error) - non-nil error → abort - non-nil result → short-circuit (skips upstream + ResultTransform; AfterCall fires) - non-nil ctx → propagated through chain and all downstream steps BREAKING: AfterCallHook gains duration time.Duration final parameter; fires on all code paths including rejections, cache hits, and short-circuits. BREAKING: ResultTransformHook now receives *CallResult and mutates in place; can sanitize both Text and image Parts. New: built-in bounded LRU response cache (256 entries, 30s TTL, default ON) - Cache interface + KeyFunc for external backends (Redis etc.) - WithCache, WithCacheTTL, WithCacheSize, WithoutCache, WithCacheKey options - WithCacheScope(ctx, scope) / CacheScope(ctx) / IsCacheHit(ctx) - Per-tool TTL via ToolInfo.Custom["cache_ttl"] - (*CallResult).Clone() deep-copy method New: RejectReason enum + OnRejectedCallFunc + WithOnRejectedCall option New: OnConnectFunc + WithOnConnect option Migrated: policy/ DenyDestructive, RequireRoles, RateLimit, AuditLog Updated: examples/policy, examples/redact
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BeforeCallHooknow returns(context.Context, *CallResult, error)— enables context propagation and short-circuit from BeforeAfterCallHookgainsduration time.Durationfinal param; fires on all code paths (rejections, cache hits, short-circuits)ResultTransformHookreceives*CallResultand mutates in place (text + image parts)CacheinterfaceRejectReasonenum +OnRejectedCallFunc+WithOnRejectedCallfor rejected-call observabilityOnConnectFunc+WithOnConnectfires once per server after successful connect(*CallResult).Clone()deep-copy methodpolicy/andexamples/migrated to new signaturesTest plan
go test -race ./...)go vet ./...cleanpolicy/,examples/*compile and tests pass