node

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package node provides the Go-native LLM and Knowledge graph nodes.

Index

Constants

View Source
const (
	VarResponse    = "response"
	VarUsage       = "usage"
	VarToolPending = "tool_pending"
	VarToolOutput  = "tool_output"
	VarToolCalls   = "__tool_calls"
)

Board variable keys used by builtin node implementations (LLM, template, etc.).

Variables

This section is empty.

Functions

func PortsForType

func PortsForType(nodeType string) (input, output []graph.Port)

PortsForType returns the graph.Port slices for a registered node type, derived from the schema's PortSchema definitions. This is the single source of truth — jsnode and other implementations should call this instead of hardcoding port definitions.

func RegisterBuiltinSchemas

func RegisterBuiltinSchemas(reg *SchemaRegistry)

func RegisterDefaultBuilder

func RegisterDefaultBuilder(nodeType string, builder NodeBuilder)

RegisterDefaultBuilder is called by node packages in init() to register their node type builders.

func RegisterDefaultSchema

func RegisterDefaultSchema(schema NodeSchema)

func RegisterFallbackBuilder

func RegisterFallbackBuilder(builder NodeBuilder)

RegisterFallbackBuilder sets the fallback builder used when no explicit builder matches.

Types

type BoardVarSpec

type BoardVarSpec struct {
	Key       string `json:"key"`
	Type      string `json:"type"`
	Desc      string `json:"desc"`
	Condition string `json:"condition,omitempty"`
}

BoardVarSpec describes a single board variable that a node reads or writes.

type BuildContext

type BuildContext struct {
	LLMResolver   llm.LLMResolver
	ToolRegistry  *tool.Registry
	ScriptRuntime script.Runtime
	ScriptFS      fs.FS
	Workspace     workspace.Workspace
	CommandRunner workspace.CommandRunner
}

BuildContext provides runtime dependencies for node construction.

type Factory

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

Factory manages NodeBuilder registration and constructs nodes from definitions.

func NewFactory

func NewFactory(opts ...FactoryOption) *Factory

NewFactory creates a new Factory, copying from the default builder registry.

func (*Factory) Build

func (f *Factory) Build(def graph.NodeDefinition) (graph.Node, error)

Build constructs a single node from its definition.

func (*Factory) Fallback

func (f *Factory) Fallback() NodeBuilder

Fallback returns the current fallback builder (may be nil).

func (*Factory) RegisterBuilder

func (f *Factory) RegisterBuilder(nodeType string, builder NodeBuilder)

RegisterBuilder registers a builder for a specific node type on this instance.

func (*Factory) SetFallback

func (f *Factory) SetFallback(builder NodeBuilder)

SetFallback sets a builder that is tried when no explicit builder matches.

func (*Factory) ValidateConsistency

func (f *Factory) ValidateConsistency(schemas *SchemaRegistry) []string

ValidateConsistency checks that every registered builder has a corresponding schema and vice versa. Returns a list of warning messages for any mismatches. Intended for startup-time diagnostics, not hot paths.

type FactoryOption

type FactoryOption func(*Factory)

FactoryOption configures a Factory.

func WithCommandRunner

func WithCommandRunner(cr workspace.CommandRunner) FactoryOption

func WithLLMResolver

func WithLLMResolver(r llm.LLMResolver) FactoryOption

func WithScriptFS

func WithScriptFS(fsys fs.FS) FactoryOption

func WithScriptRuntime

func WithScriptRuntime(rt script.Runtime) FactoryOption

func WithToolRegistry

func WithToolRegistry(tr *tool.Registry) FactoryOption

func WithWorkspace

func WithWorkspace(ws workspace.Workspace) FactoryOption

type FieldSchema

type FieldSchema struct {
	Key          string         `json:"key"`
	Label        string         `json:"label"`
	Type         string         `json:"type"`
	Required     bool           `json:"required,omitempty"`
	Placeholder  string         `json:"placeholder,omitempty"`
	DefaultValue any            `json:"default_value,omitempty"`
	Options      []SelectOption `json:"options,omitempty"`
}

FieldSchema describes a single configurable field of a node type.

type LLMConfig

type LLMConfig struct {
	SystemPrompt  string   `json:"system_prompt" yaml:"system_prompt"`
	Model         string   `json:"model,omitempty" yaml:"model,omitempty"`
	Temperature   *float64 `json:"temperature,omitempty" yaml:"temperature,omitempty"`
	MaxTokens     int64    `json:"max_tokens,omitempty" yaml:"max_tokens,omitempty"`
	OutputKey     string   `json:"output_key,omitempty" yaml:"output_key,omitempty"`
	MessagesKey   string   `json:"messages_key,omitempty" yaml:"messages_key,omitempty"`
	JSONMode      bool     `json:"json_mode,omitempty" yaml:"json_mode,omitempty"`
	Thinking      bool     `json:"thinking,omitempty" yaml:"thinking,omitempty"`
	QueryFallback bool     `json:"query_fallback,omitempty" yaml:"query_fallback,omitempty"`
	TrackSteps    bool     `json:"track_steps,omitempty" yaml:"track_steps,omitempty"`
	ToolNames     []string `json:"tool_names,omitempty" yaml:"tool_names,omitempty"`
}

LLMConfig configures an LLM graph node. Fields like SystemPrompt, OutputKey, MessagesKey, QueryFallback, and TrackSteps are graph-level board I/O concerns; the pure LLM call parameters are forwarded to llm.RoundConfig via the roundConfig() method.

func ConfigFromMap

func ConfigFromMap(m map[string]any, isDeferred func(string) bool) (LLMConfig, error)

ConfigFromMap parses an LLMConfig from a generic map via JSON round-trip. isDeferred is passed through to CoerceMapForStruct; see its documentation.

type LLMNode

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

LLMNode is a Go-native graph node that calls an LLM, handles tool calls, and manages message history.

func NewLLMNode

func NewLLMNode(id string, resolver llm.LLMResolver, toolReg *tool.Registry, config LLMConfig) *LLMNode

NewLLMNode creates a new LLM node.

func (*LLMNode) Config

func (n *LLMNode) Config() map[string]any

Config returns the raw config map for variable resolution by the executor.

func (*LLMNode) ExecuteBoard

func (n *LLMNode) ExecuteBoard(ctx graph.ExecutionContext, board *graph.Board) error

func (*LLMNode) ID

func (n *LLMNode) ID() string

func (*LLMNode) InputPorts

func (n *LLMNode) InputPorts() []graph.Port

func (*LLMNode) OutputPorts

func (n *LLMNode) OutputPorts() []graph.Port

func (*LLMNode) SetConfig

func (n *LLMNode) SetConfig(c map[string]any)

SetConfig updates the raw config and re-parses the typed LLMConfig so that resolved ${board.xxx} variables take effect (e.g. system_prompt).

func (*LLMNode) Type

func (n *LLMNode) Type() string

type NodeBuilder

type NodeBuilder func(def graph.NodeDefinition, bctx *BuildContext) (graph.Node, error)

NodeBuilder creates a graph.Node from its definition and build-time dependencies.

type NodeSchema

type NodeSchema struct {
	Type        string        `json:"type"`
	Label       string        `json:"label"`
	Icon        string        `json:"icon"`
	Color       string        `json:"color"`
	Category    string        `json:"category"`
	Description string        `json:"description"`
	Fields      []FieldSchema `json:"fields"`
	InputPorts  []PortSchema  `json:"input_ports,omitempty"`
	OutputPorts []PortSchema  `json:"output_ports,omitempty"`
	Deprecated  bool          `json:"deprecated,omitempty"`
	Runtime     *RuntimeSpec  `json:"runtime,omitempty"`
}

NodeSchema describes a node type for dynamic frontend rendering.

type PortSchema

type PortSchema struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Required    bool   `json:"required,omitempty"`
	Description string `json:"description,omitempty"`
}

PortSchema describes a typed port for frontend rendering.

type RuntimeSpec

type RuntimeSpec struct {
	BoardWrites []BoardVarSpec `json:"board_writes,omitempty"`
	BoardReads  []BoardVarSpec `json:"board_reads,omitempty"`
	EdgeVars    []BoardVarSpec `json:"edge_vars,omitempty"`
	Notes       []string       `json:"notes,omitempty"`
}

RuntimeSpec describes the runtime behavior of a node type — what board variables it reads/writes, what condition variables it produces for downstream edges, and important behavioral notes. This information is returned by the schema(action=node_usage) tool to help the Builder understand how to correctly wire nodes together.

type SchemaRegistry

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

SchemaRegistry is a thread-safe registry mapping node type strings to their schemas.

func NewSchemaRegistry

func NewSchemaRegistry() *SchemaRegistry

func (*SchemaRegistry) All

func (r *SchemaRegistry) All() []NodeSchema

func (*SchemaRegistry) Get

func (r *SchemaRegistry) Get(nodeType string) (NodeSchema, bool)

func (*SchemaRegistry) Len

func (r *SchemaRegistry) Len() int

func (*SchemaRegistry) Register

func (r *SchemaRegistry) Register(schema NodeSchema)

func (*SchemaRegistry) RegisterMany

func (r *SchemaRegistry) RegisterMany(schemas []NodeSchema)

func (*SchemaRegistry) Unregister

func (r *SchemaRegistry) Unregister(nodeType string)

Unregister removes a node schema by type name.

type SelectOption

type SelectOption struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

SelectOption is a label-value pair for dropdown fields.

Directories

Path Synopsis
Package scripts embeds all built-in JS node scripts via embed.FS.
Package scripts embeds all built-in JS node scripts via embed.FS.

Jump to

Keyboard shortcuts

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