contracts

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package contracts holds this server's tool input and output contracts — the typed Go structs that are the source of truth for the tool schemas (Dockyard P1 — contract-first, RFC §6). The JSON Schema and TypeScript alongside these structs are GENERATED by `dockyard generate`; never hand-edit a generated file. Change a contract here, then regenerate.

The analytics-widgets template ships three contract pairs: one per widget tool. Each output carries a `Kind` field so the App's single dispatcher can route `structuredContent` to the right renderer (chart / table / metric card) without sniffing the shape.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChartData

type ChartData struct {
	// Series is the chart's named series; at least one is expected. An
	// empty Series drives the App's empty state.
	Series []ChartSeries `json:"series"`
	// Categories are the shared-axis category labels (e.g. months on a
	// bar chart's x-axis). Optional for chart types that do not use them
	// (pie, radar, scatter).
	Categories []string `json:"categories,omitempty"`
}

ChartData is the chart payload: named series plus optional category labels.

type ChartSeries

type ChartSeries struct {
	// Name is the series label rendered in the legend.
	Name string `json:"name"`
	// Values is the series' numeric values. For scatter and radar the
	// app expects paired values; for the rest, one value per category.
	Values []float64 `json:"values"`
}

ChartSeries is one named series.

type ChartType

type ChartType string

ChartType is one of the V1 chart types the App renderer supports. The list intentionally mirrors Apache ECharts' built-in series types (decision D-125 — ECharts is the V1 renderer).

type CreateChartInput

type CreateChartInput struct {
	// Type is the chart kind: bar | line | area | pie | scatter | radar.
	Type ChartType `json:"type"`
	// Data is the chart payload: one or more named series, plus optional
	// category labels for the shared axis.
	Data ChartData `json:"data"`
	// Title is an optional chart title rendered above the chart.
	Title string `json:"title,omitempty"`
	// Options is an optional passthrough of ECharts option overrides. The
	// App merges them over the sensible defaults Dockyard derives from
	// Type + Data, so a developer can override colors, axis ticks, legend
	// placement, etc. Renderer-agnostic in framing — the field is opaque
	// in the contract — but its V1 keys mirror the ECharts schema.
	Options map[string]any `json:"options,omitempty"`
	// Theme is the per-call theme override. "auto" (default) honours the
	// host theme propagated via `hostContext.styles.variables`.
	Theme ThemeMode `json:"theme,omitempty"`
}

CreateChartInput is the model-facing input contract for create_chart.

type CreateChartOutput

type CreateChartOutput struct {
	// Kind is always "chart" for a create_chart output. The dispatcher
	// reads it to route to the chart renderer.
	Kind string `json:"kind"`
	// Type is the chart kind, passed through from the input.
	Type ChartType `json:"type"`
	// Data is the chart payload, passed through.
	Data ChartData `json:"data"`
	// Title is the chart title, passed through (empty when not set).
	Title string `json:"title,omitempty"`
	// Options is the ECharts option override, passed through.
	Options map[string]any `json:"options,omitempty"`
	// Theme is the resolved theme: never "auto" — the handler resolves
	// "auto" against the host context.
	Theme ThemeMode `json:"theme"`
	// State is the UI state the App enters: "ready" | "empty" |
	// "error" | "permission" | "loading". Fixtures drive each value to
	// exercise the four-state PageState in the inspector switcher.
	State WidgetState `json:"state"`
	// Message is the human-readable message rendered in the non-ready
	// states (e.g. "No revenue this period.", "Not authorized to view
	// this chart.", "Loading…"). Empty in the ready state.
	Message string `json:"message,omitempty"`
}

CreateChartOutput is the structured payload the App renders. It carries the input back through Data + Options (the App is a pure View — the model decides what to chart; the App renders what arrives) and adds a `Kind` discriminator the dispatcher reads.

type CreateMetricCardInput

type CreateMetricCardInput struct {
	// Label is the metric name (e.g. "Customer health").
	Label string `json:"label"`
	// Value is the metric's primary value. JSON-numeric or string; the
	// renderer prints it verbatim. Required.
	Value any `json:"value"`
	// Unit is the optional value suffix ("$", "%", "ms", …).
	Unit string `json:"unit,omitempty"`
	// Delta is the optional period-over-period change.
	Delta *MetricDelta `json:"delta,omitempty"`
	// Series is the optional sparkline series — when present the App
	// renders the shared web/ui Sparkline next to the value.
	Series []float64 `json:"series,omitempty"`
	// Breakdowns are optional sub-rows (top contributors / segments). An
	// empty Breakdowns is rendered as "no breakdown for this metric".
	Breakdowns []MetricBreakdown `json:"breakdowns,omitempty"`
	// Theme is the per-call theme override.
	Theme ThemeMode `json:"theme,omitempty"`
}

CreateMetricCardInput is the model-facing input contract for create_metric_card.

type CreateMetricCardOutput

type CreateMetricCardOutput struct {
	// Kind is always "metric_card" — dispatcher reads it.
	Kind string `json:"kind"`
	// Label, Value, Unit, Delta, Series, Breakdowns are passed through.
	Label      string            `json:"label"`
	Value      any               `json:"value"`
	Unit       string            `json:"unit,omitempty"`
	Delta      *MetricDelta      `json:"delta,omitempty"`
	Series     []float64         `json:"series,omitempty"`
	Breakdowns []MetricBreakdown `json:"breakdowns,omitempty"`
	// Theme is the resolved theme.
	Theme ThemeMode `json:"theme"`
	// State is the UI state ("ready" | "empty" | "error" | "permission"
	// | "loading").
	State WidgetState `json:"state"`
	// Message is the human-readable message for non-ready states.
	Message string `json:"message,omitempty"`
}

CreateMetricCardOutput is the structured payload the App renders.

type CreateTableInput

type CreateTableInput struct {
	// Columns is the table's column definitions.
	Columns []TableColumn `json:"columns"`
	// Rows is the table's row set. An empty Rows drives the empty state.
	Rows []map[string]any `json:"rows"`
	// Sort is the requested sort. Optional — the App's DataTable allows
	// client-side re-sort.
	Sort *TableSort `json:"sort,omitempty"`
	// Theme is the per-call theme override. "auto" honours the host.
	Theme ThemeMode `json:"theme,omitempty"`
}

CreateTableInput is the model-facing input contract for create_table.

type CreateTableOutput

type CreateTableOutput struct {
	// Kind is always "table" — dispatcher reads it.
	Kind string `json:"kind"`
	// Columns is the column set, passed through.
	Columns []TableColumn `json:"columns"`
	// Rows is the row set, passed through.
	Rows []map[string]any `json:"rows"`
	// Sort is the resolved sort.
	Sort *TableSort `json:"sort,omitempty"`
	// Theme is the resolved theme (never "auto").
	Theme ThemeMode `json:"theme"`
	// State is the UI state ("ready" | "empty" | "error" | "permission"
	// | "loading").
	State WidgetState `json:"state"`
	// Message is the human-readable message for non-ready states.
	Message string `json:"message,omitempty"`
}

CreateTableOutput is the structured payload the App renders.

type MetricBreakdown

type MetricBreakdown struct {
	// Label is the breakdown row's name.
	Label string `json:"label"`
	// Value is the breakdown row's value (printed verbatim).
	Value any `json:"value"`
	// Share is the optional percentage share of the total (0..1). When
	// present the App renders it as a small percentage chip.
	Share float64 `json:"share,omitempty"`
}

MetricBreakdown is one sub-row of the card.

type MetricDelta

type MetricDelta struct {
	// Value is the delta text rendered next to the value (e.g. "+12%",
	// "-3").
	Value string `json:"value"`
	// Tone colors the delta: "ok" (green-ish) | "warn" (amber) | "error"
	// (red).
	Tone MetricDeltaTone `json:"tone"`
}

MetricDelta is the period-over-period delta block on the card.

type MetricDeltaTone

type MetricDeltaTone string

MetricDeltaTone is the semantic tone of a metric's delta — drives the chip / text color on the rendered card.

type TableColumn

type TableColumn struct {
	// Key is the row map key whose value lands in this column.
	Key string `json:"key"`
	// Label is the human-facing column header.
	Label string `json:"label"`
	// Type is the column's value type ("string", "number", "currency",
	// "percent", "date", "status"). The renderer formats accordingly.
	Type TableColumnType `json:"type"`
	// Sortable opts the column into client-side sorting.
	Sortable bool `json:"sortable,omitempty"`
}

TableColumn declares one column of the table.

type TableColumnType

type TableColumnType string

TableColumnType is the column's value type — what the renderer formats.

type TableSort

type TableSort struct {
	// Column is the column Key the table is sorted by.
	Column string `json:"column"`
	// Dir is "asc" or "desc".
	Dir string `json:"dir"`
}

TableSort is an input-side sort directive.

type ThemeMode

type ThemeMode string

ThemeMode is the per-call theme override. "auto" honours the host's theme (the bridge propagates `hostContext.styles.variables`); the other two pin the rendered widget to a specific palette.

const (
	ThemeAuto  ThemeMode = "auto"
	ThemeLight ThemeMode = "light"
	ThemeDark  ThemeMode = "dark"
)

The three valid ThemeMode values. The default ("auto" / unset) honours the host theme propagated through `hostContext.styles.variables`.

type WidgetState

type WidgetState string

WidgetState is the state the App enters when rendering a widget. The values map 1:1 onto the four-state PageState in web/ui (CLAUDE.md §20).

const (
	WidgetStateReady      WidgetState = "ready"
	WidgetStateEmpty      WidgetState = "empty"
	WidgetStateError      WidgetState = "error"
	WidgetStatePermission WidgetState = "permission"
	WidgetStateLoading    WidgetState = "loading"
)

The five valid WidgetState values. The four "non-ready" states drive the inspector's fixture switcher (Phase 23): each fixture nails a distinct UI state so the rendered widget exercises every PageState branch.

Jump to

Keyboard shortcuts

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