callback

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package callback is the dispatch runtime for workspace callback definitions.

The dispatcher accepts a DispatchInput (event name, conversation context, forge submit payload), renders the matching callback's payload template, and invokes the mapped tool via the registry. It is invoked from the HTTP adapter at adapter/http/callback.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBlockedError added in v0.1.9

func IsBlockedError(err error) bool

Types

type DispatchInput

type DispatchInput struct {
	// EventName is the callback id the foreground wants routed (e.g.
	// "spo_planner_submit"). Required.
	EventName string `json:"eventName"`

	// ConversationID is the conversation this dispatch is acting on. Required
	// when the callback's payload template references any conversation-scoped
	// placeholder.
	ConversationID string `json:"conversationId,omitempty"`

	// TurnID is optional — the turn that produced the dashboard where the
	// user clicked submit. Surfaced in templates as `{{.turnId}}` for use in
	// recommendation id generation and audit trails.
	TurnID string `json:"turnId,omitempty"`

	// Payload is the raw body forge posts when the user clicks submit.
	// Common shape: `{ "selectedRows": [...] }`. Surfaced in templates as
	// `{{.payload.<key>}}`; the convenience alias `{{.selectedRows}}` is
	// populated when present.
	Payload map[string]interface{} `json:"payload,omitempty"`

	// Context carries arbitrary key/value pairs the foreground wants to
	// expose to the payload template. Typical keys: agencyId, advertiserId,
	// campaignId, adOrderId, audienceId — passed from the current UI view
	// state. Keys here are flattened into the template root and MUST NOT
	// shadow reserved keys (eventName, conversationId, turnId, agentId,
	// payload, selectedRows, now, today).
	Context map[string]interface{} `json:"context,omitempty"`
}

DispatchInput is the envelope the caller (typically the HTTP handler wrapping a forge submit event) passes to Service.Dispatch.

type DispatchOutput

type DispatchOutput struct {
	// EventName echoes the request so clients can multiplex responses.
	EventName string `json:"eventName"`

	// Tool is the tool that was invoked, for audit.
	Tool string `json:"tool"`

	// Result is the tool's textual return value, verbatim. Clients should
	// parse it per the tool's documented schema.
	Result string `json:"result,omitempty"`

	// Error carries any dispatch or tool-invocation failure that should be
	// presented to the user. Network / authz errors are returned via the
	// HTTP status code instead.
	Error string `json:"error,omitempty"`

	// Blocked reports that the callback was intentionally blocked by a
	// producer-owned callback gate before any tool invocation occurred.
	Blocked bool `json:"blocked,omitempty"`
}

DispatchOutput is what Service.Dispatch returns. The HTTP adapter encodes this as JSON on the wire.

type Option

type Option func(*Service)

Option configures a Service.

func WithConversationClient

func WithConversationClient(c apiconv.Client) Option

WithConversationClient enables `.agentId` resolution from conversationId.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service dispatches foreground submit events to the mapped tool. It is constructed once at workspace bootstrap and shared across HTTP requests.

func New

func New(repo *callbackrepo.Repository, registry tooldef.Registry, opts ...Option) *Service

New builds a dispatch service. repo and registry are required; panics on nil.

func (*Service) Dispatch

func (s *Service) Dispatch(ctx context.Context, in *DispatchInput) (*DispatchOutput, error)

Dispatch resolves the callback, renders the payload, and invokes the mapped tool. Returns a DispatchOutput carrying the tool's textual result or a non-empty Error when the dispatch itself failed (not when the tool returned an application error — those flow via Result).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL