Skip to content

[Go SDK] triggers package + WithTriggers option + OnEvent/OnSchedule sugar #513

@santoshkumarradha

Description

@santoshkumarradha

Summary

Add the public trigger types, factories, and registration plumbing to the Go SDK, including the WithTriggers reasoner option and app.OnEvent() / app.OnSchedule() sugar helpers.

Part of the epic #508. The CP-side scaffolding (types.TriggerBinding, ReasonerDefinition.Triggers, ReasonerDefinition.AcceptsWebhook) and the auto-set accepts_webhook=true rule already landed in #506.

Scope

New Files

File Purpose
sdk/go/triggers/triggers.go Context, Binding, EventOpts, ScheduleOpts, Event(...), Schedule(...) factories. Field-for-field equivalent of agentfield/triggers.py

Modified Files

File Change
sdk/go/agent/agent.go WithTriggers(...Binding) reasoner option — appends to Reasoner.Triggers. WithAcceptsWebhook(string) option — sets Reasoner.AcceptsWebhook explicitly when needed
sdk/go/agent/agent.go (sugar) app.OnEvent(opts EventOpts, name string, handler HandlerFunc) and app.OnSchedule(expression string, name string, handler HandlerFunc) — pure forwards to RegisterReasoner with a pre-built trigger binding

Interface

package triggers

type Context struct {
    TriggerID, Source, EventType, EventID, IdempotencyKey, VCID string
    ReceivedAt time.Time
}

type Transform func(rawEvent map[string]any) any

type EventOpts struct {
    Source    string
    Types     []string
    SecretEnv string
    Config    json.RawMessage
    Transform Transform
}

type ScheduleOpts struct {
    Expression string
    Timezone   string
    Config     json.RawMessage
}

type Binding struct { /* wraps types.TriggerBinding plus the (non-serialisable) Transform */ }

func Event(opts EventOpts) Binding
func Schedule(opts ScheduleOpts) Binding
agent.WithTriggers(triggers.Event(triggers.EventOpts{
    Source:    "stripe",
    Types:     []string{"payment_intent.succeeded"},
    SecretEnv: "STRIPE_WEBHOOK_SECRET",
}))

Acceptance

  • go build -tags "embedded sqlite_fts5" ./... clean
  • go vet ./... clean
  • RegisterReasoner with WithTriggers(...) populates Reasoner.Triggers and round-trips through registerNode payload (already plumbed in Feat universal plugin based triggers #506)
  • app.OnEvent / app.OnSchedule produce the same registration shape as the long-form path
  • code_origin derived from runtime.Caller so the UI's Drift Card has a path

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
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions