Skip to content

[Go SDK] Dispatch envelope unwrap + Context injection #514

@santoshkumarradha

Description

@santoshkumarradha

Summary

Wire the dispatch-side envelope unwrap and *triggers.Context injection into the Go SDK's reasoner request handler, so a webhook delivery from the control plane lands on a typed handler with a populated context.

Part of the epic #508. Depends on the trigger types from the sibling issue.

Scope

Modified Files

File Change
sdk/go/agent/agent.go (handler dispatch) Recognise the dispatcher's envelope shape {event, _meta}. Peel event (running the binding's Transform if registered). Build a *triggers.Context from _meta. Call the handler with the (transformed) payload and the context. Direct calls (no _meta) call the handler with the raw input unchanged

Behaviour

Generic handler signature, supported via Go 1.21+ generics:

func handlePayment(ctx context.Context, in Payment, tc *triggers.Context) (any, error) {
    if tc != nil {
        // dispatched via a trigger
    }
    return ..., nil
}

tc == nil for direct calls; non-nil when the request body is the dispatcher envelope.

Acceptance

  • Direct POST /reasoners/<name> with a flat input still works — tc is nil
  • POST with {event, _meta} envelope shape calls the handler with the transformed payload and a non-nil *triggers.Context
  • Transform runs before the handler when an envelope is detected, is skipped on direct calls
  • Unit tests cover both shapes (envelope + direct) for the same handler — same fixture files used by the test-helpers issue

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-friendlyWell-documented task suitable for AI-assisted developmentarea:sdkCross-SDK (Python + Go + TS) parity workenhancementNew feature or requesthelp wantedExtra attention is neededsdk:goGo SDK related

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions