schema

package
v1.0.43 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePath

func ParsePath(args []string) []string

ParsePath normalizes the positional arguments of `lark-cli schema` into a slice of path segments. It accepts two equivalent forms:

lark-cli schema im.messages.reply  -> single arg, split on "."
lark-cli schema im messages reply  -> multiple args, used as-is
lark-cli schema "im chat.members bots" is NOT a supported form; quote
arguments individually if your shell needs it. Nested resources keep their
internal dots (e.g. "chat.members").

Returns nil for zero args (bare invocation).

Types

type Affordance

type Affordance struct {
	UseWhen       []string         `json:"use_when,omitempty"`
	DoNotUseWhen  []string         `json:"do_not_use_when,omitempty"`
	Prerequisites []string         `json:"prerequisites,omitempty"`
	Examples      []AffordanceCase `json:"examples,omitempty"`
	Related       []string         `json:"related,omitempty"`
}

Affordance is the hand-written overlay (PR-1 only defines the type, no YAML loaded).

type AffordanceCase

type AffordanceCase struct {
	Description string `json:"description"`
	Command     string `json:"command"`
}

AffordanceCase is one example entry: a one-line description plus a ready-to-run lark-cli command string.

type Envelope

type Envelope struct {
	Name         string        `json:"name"`
	Description  string        `json:"description"`
	InputSchema  *InputSchema  `json:"inputSchema"`
	OutputSchema *OutputSchema `json:"outputSchema"`
	Meta         *Meta         `json:"_meta"`
}

Envelope is the MCP Tool spec contract for a single API method command.

func AssembleAll

func AssembleAll(filter MethodFilter) []Envelope

AssembleAll assembles every embedded service into one big sorted slice. Uses embedded data only (bypasses remote overlay) so envelope output is deterministic across machines (CI vs dev vs different user brands).

func AssembleEnvelope

func AssembleEnvelope(serviceName string, resourcePath []string, methodName string, method map[string]interface{}) Envelope

AssembleEnvelope is the main entry point: takes a service / resource path / method name plus its meta_data spec, and produces a fully assembled MCP envelope. Output is fully determined by inputs (same arguments → same envelope), but assembly briefly publishes the per-method key-order context through the package-level currentMethodOrder so orderedKeys can reach it without threading it through every helper. assembleMu serializes that publish, which is why concurrent callers are still safe — they queue rather than run in parallel.

If parallelism becomes a bottleneck, replace currentMethodOrder with an assembler struct or pass *MethodKeyOrder explicitly down the call chain.

func AssembleService

func AssembleService(serviceName string, spec map[string]interface{}, filter MethodFilter) []Envelope

AssembleService assembles all methods under one service into a sorted envelope slice (sorted by Envelope.Name ascending).

type InputSchema

type InputSchema struct {
	Type       string        `json:"type"`
	Required   []string      `json:"required"`
	Properties *OrderedProps `json:"properties"`
}

InputSchema is JSON Schema Draft 2020-12 flattened.

Required is intentionally rendered (no omitempty) so the envelope shape stays stable for AI consumers — an empty []string means "no required fields" rather than "schema is missing the field".

type Meta

type Meta struct {
	EnvelopeVersion string      `json:"envelope_version"`
	Scopes          []string    `json:"scopes"`
	RequiredScopes  []string    `json:"required_scopes"`
	AccessTokens    []string    `json:"access_tokens"`
	Danger          bool        `json:"danger"`
	Risk            string      `json:"risk"`
	DocURL          string      `json:"doc_url,omitempty"`
	Affordance      *Affordance `json:"affordance,omitempty"`
}

Meta is the Lark-specific extension namespace.

type MethodFilter

type MethodFilter func(method map[string]interface{}) bool

MethodFilter is an optional predicate used by AssembleService and AssembleAll to filter methods (e.g. by access token for strict mode). Pass nil to include all methods.

type MethodKeyOrder

type MethodKeyOrder struct {
	Parameters   []string
	RequestBody  []string
	ResponseBody []string
	NestedKeys   map[string][]string
}

MethodKeyOrder records the natural meta_data.json key order for one method's parameters / requestBody / responseBody. Nested object key orders are stored under NestedKeys, keyed by dotted path from the method root (e.g. "responseBody.items.properties").

type OrderedProps

type OrderedProps struct {
	Order []string
	Map   map[string]Property
}

OrderedProps is map[string]Property with preserved key order on MarshalJSON. It is used wherever JSON output must reflect meta_data.json's natural field order rather than Go's default alphabetical map encoding.

func (*OrderedProps) MarshalJSON

func (o *OrderedProps) MarshalJSON() ([]byte, error)

MarshalJSON emits keys in Order, not alphabetical. If Order is empty but Map has entries, fall back to alphabetical key order over Map so callers that only populated Map (no explicit ordering) still see their fields.

func (*OrderedProps) UnmarshalJSON

func (o *OrderedProps) UnmarshalJSON(data []byte) error

UnmarshalJSON parses an object preserving key order via json.Decoder.Token(). Used for round-tripping in tests (and future golden update flows).

type OutputSchema

type OutputSchema struct {
	Type       string        `json:"type"`
	Properties *OrderedProps `json:"properties"`
}

OutputSchema wraps responseBody into a JSON Schema object.

type Property

type Property struct {
	Type        string        `json:"type,omitempty"`
	Description string        `json:"description,omitempty"`
	Enum        []interface{} `json:"enum,omitempty"`
	Default     interface{}   `json:"default,omitempty"`
	Example     interface{}   `json:"example,omitempty"`
	Minimum     *float64      `json:"minimum,omitempty"`
	Maximum     *float64      `json:"maximum,omitempty"`
	Format      string        `json:"format,omitempty"`
	Required    []string      `json:"required,omitempty"`
	Properties  *OrderedProps `json:"properties,omitempty"`
	Items       *Property     `json:"items,omitempty"`
}

Property is one field's JSON Schema shape, recursive.

Required is used when Property describes a nested object (e.g. the "params" / "data" sub-objects inside inputSchema): it lists which keys inside that object's Properties are mandatory. Leaf fields ignore it.

Jump to

Keyboard shortcuts

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