From ae0b6c6e57929bf2b6bfe91eaede0639a91d262a Mon Sep 17 00:00:00 2001 From: Ricky Schema Cascade Date: Wed, 10 Jun 2026 09:13:06 +0200 Subject: [PATCH] fix(runtime): no-trigger personas narrow to AgentEvent, not BaseAgentEvent v4.0.0 regression: defineAgent's event narrowing collapsed personas that declare no concrete trigger literals (e.g. team members launched by a dispatcher) to `BaseAgentEvent<`${string}.${string}`>`, which is narrower than `AgentEvent` and rejects an `(event: AgentEvent)`/`WorkforceEvent` handler: Type '(ctx, event: WorkforceEvent) => ...' is not assignable to '(ctx, event: ProviderEventFor) => ...' ProviderEventFor now falls back to the full `AgentEvent` when the trigger `on` union is the wide `string` (nothing concrete declared), while still mapping declared literals to `BaseAgentEvent<`${P}.${O}`>` (incl. 2-segment types like slack.app_mention). Restores the pre-v4 behavior for trigger-less personas. 86 runtime tests pass; the agents repo's cloud-team member personas typecheck clean against the rebuilt runtime. Co-Authored-By: Claude Opus 4.8 --- packages/runtime/src/define-agent.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/define-agent.ts b/packages/runtime/src/define-agent.ts index f864d18d..72fd7cee 100644 --- a/packages/runtime/src/define-agent.ts +++ b/packages/runtime/src/define-agent.ts @@ -39,7 +39,15 @@ type TriggerOnUnion = OnLiteralsOf>; // for any provider event shape — including 2-segment types like // `slack.app_mention` that aren't valid `EventType`s (those collapse to `never` // under `AgentEvent<...>`). -type ProviderEventFor

= BaseAgentEvent<`${P}.${O}`>; +// +// When `O` is the wide `string` (a persona that declares no concrete trigger +// literals — e.g. team members launched by a dispatcher), fall back to the full +// `AgentEvent` so a `(event: AgentEvent)` handler stays assignable. Without this +// the wide case narrows to `BaseAgentEvent<\`${string}.${string}\`>`, which is +// narrower than `AgentEvent` and rejects an `AgentEvent`-typed handler. +type ProviderEventFor

= string extends O + ? AgentEvent + : BaseAgentEvent<`${P}.${O}`>; type TriggerProviderEvents = { [P in keyof Tr]: P extends string