scriptling

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventParamsVarName = "__event_params"
	EventMetaVarName   = "__event"
)

Variables

View Source
var EmbeddedLibs embed.FS
View Source
var UserSecretResolver func(path string) (string, error)

UserSecretResolver reads a personal secret through the agent running in the space. The agentlink package installs it; scripts outside a space never get this library and use the embedded Python knot.secret, which refuses.

Functions

func ExpectSyncProjectAgent added in v0.42.0

func ExpectSyncProjectAgent()

ExpectSyncProjectAgent says the process will install a SyncProjectAgent shortly: the agent, which runs startup scripts as it connects, before its sync projects have started. knot.files.sync waits for it then.

func GetAILibrary

func GetAILibrary(aiClient ai.Client) *object.Library

GetAILibrary returns the knot.ai library for scriptling environments. Only Client() and get_default_model() are exposed, matching the Python standalone interface. When aiClient is nil, Client() will return an error.

func GetApiClientLibrary added in v0.23.6

func GetApiClientLibrary(client rest.RESTClient, userId string) *object.Library

GetApiClientLibrary returns the knot.apiclient Go transport library. In embedded contexts this replaces the Python apiclient.py transport stub. configure() and is_configured() are no-ops - the client is pre-configured. Tokens are never exposed to scripts.

func GetEventLibrary added in v0.28.0

func GetEventLibrary() *object.Library

func GetHealthCheckLibrary added in v0.24.0

func GetHealthCheckLibrary() *object.Library

GetHealthCheckLibrary returns the knot.healthcheck built-in library.

func GetIdentityLibrary added in v0.34.0

func GetIdentityLibrary(user object.Object) *object.Library

GetIdentityLibrary builds knot.identity: the requesting user for code that runs inside imported modules (plugin peers, lib scripts), where the dispatch globals — bound on the main program's scope — are not visible. user() returns the same User instance the `user` global holds, so module code can self-gate exactly like handler code does.

The instance is captured at registration: environments that rebind identity (pooled plugin envs per lease, server envs per execution) re-register the library with the current user.

func GetIntAsUint16

func GetIntAsUint16(args []object.Object, index int, name string) (uint16, object.Object)

GetIntAsUint16 safely extracts an integer argument at the given index and converts to uint16. Returns the uint16 value and nil error on success, or 0 and error object on failure.

func GetMCPToolsLibrary

func GetMCPToolsLibrary(client *apiclient.ApiClient, mcpParams map[string]object.Object) *object.Library

GetMCPToolsLibrary returns the MCP tools library for scriptling (used in local/remote environments) This provides only tool access functions that communicate with the server via API calls

func GetMethodsLibrary added in v0.28.0

func GetMethodsLibrary() *object.Library

GetMethodsLibrary returns the knot.methods library, which exposes the Server class. The schema submodule is attached as a Dict constant so that `from knot.methods import schema` and `knot.methods.schema` both resolve to the same set of builder functions (mirroring the pattern scriptling's own runtime library uses for submodules like runtime.kv).

func GetMethodsSchemaLibrary added in v0.28.0

func GetMethodsSchemaLibrary() *object.Library

GetMethodsSchemaLibrary builds the knot.methods.schema library. Each function returns a JSON Schema fragment as a scriptling dict. Common constraints (description, default, enum) are accepted as keyword arguments alongside type-specific constraints (min_length, minimum, ...). Unknown kwargs are rejected. The extra={} kwarg is an escape hatch for less-common JSON Schema keywords; explicit kwargs win over keys in extra on conflict.

func GetSecretLibrary added in v0.39.0

func GetSecretLibrary() *object.Library

GetSecretLibrary returns the knot.secret library for scripts running in a space. It shadows the embedded Python module: personal secrets are only read over the agent link, never through the REST API.

func GetSyncLibrary added in v0.42.0

func GetSyncLibrary(inSpace bool) *object.Library

GetSyncLibrary returns knot.files.sync, which starts, stops and reports on the sync projects a space's agent runs. inSpace is false for scripts that run elsewhere, where every function refuses.

func JSONSizeAtLeast added in v0.45.0

func JSONSizeAtLeast(obj object.Object, limit int) int

JSONSizeAtLeast returns a lower bound on the size of obj encoded as JSON, giving up once it passes limit (the result is then over limit): strings count their bytes and quotes, containers their brackets and separators, and every other value one byte. A value shared by several containers counts once per reference, as it would encode. A container that holds itself stops counting once the limit is passed, as each level adds at least two bytes.

func RegisterMethodLibraries added in v0.28.0

func RegisterMethodLibraries(env *scriptling.Scriptling)

RegisterMethodLibraries registers knot.methods and knot.methods.schema on a scriptling env. The agent-side envs (service.NewAgentScriptlingEnv: the agent daemon and `knot run-script` inside a space) register them directly; server-side envs (MCP tools, AI-written scripts, event sinks, plugins) do not, so scripts there cannot import knot.methods. Registering the libraries is independent of methodsRegistrar: the libraries give scripts a way to call Server(...).register(), and methodsRegistrar (installed by the agent daemon, or by `knot run-script`, which forwards to the daemon) is what register() actually invokes; without it register() raises.

func SetMethodsRegistrar added in v0.28.0

func SetMethodsRegistrar(registrar func(*methods.Registration) error)

SetMethodsRegistrar installs the agent-side registrar. Called by the agent (or by knot run-script) before evaluating user scripts that use knot.methods.

func SetMethodsUnregisterAll added in v0.28.0

func SetMethodsUnregisterAll(fn func() error)

func SetSyncProjectAgent added in v0.42.0

func SetSyncProjectAgent(a SyncProjectAgent)

SetSyncProjectAgent installs what knot.files.sync manages sync projects through; nil takes it away, as the agent stops.

Types

type HealthCheckResult added in v0.24.0

type HealthCheckResult struct {
	Healthy bool `json:"healthy" msgpack:"healthy"`
}

HealthCheckResult holds the result of a health check execution.

func ParseHealthCheckResult added in v0.24.0

func ParseHealthCheckResult(msg string) (*HealthCheckResult, bool)

ParseHealthCheckResult extracts a HealthCheckResult from a script exception message.

type MCPLibrary

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

MCPLibrary is the exported type for accessing the result

func GetMCPLibraryInstance

func GetMCPLibraryInstance(client *apiclient.ApiClient, mcpParams map[string]object.Object) *MCPLibrary

GetMCPLibraryInstance creates a new MCP library instance that can be used to retrieve results

func (*MCPLibrary) GetLibrary

func (m *MCPLibrary) GetLibrary() *object.Library

GetLibrary returns the scriptling library

func (*MCPLibrary) GetResult

func (m *MCPLibrary) GetResult() *string

GetResult returns the stored result from mcp.return_* functions

type RequestPrechecker added in v0.45.0

type RequestPrechecker interface {
	PrecheckRequest(method, path string) error
}

RequestPrechecker is a client that refuses some calls on their method and path alone (the AI script client). The transport asks it before it converts a request's body, headers or query parameters, so a call that will be refused costs nothing to build.

type SyncProjectAgent added in v0.42.0

type SyncProjectAgent interface {
	// Start runs a project from its TOML, named name when it gives no
	// name, and returns its name.
	Start(content, name string) (string, error)
	Stop(name string) error
	List() ([]syncproject.ProjectStatus, error)
}

SyncProjectAgent runs a space's sync projects: the agent's own manager for scripts the agent runs, its command socket for knot run-script.

Directories

Path Synopsis
Package pluginfetch implements the knot plugin's fetcher: the source of truth for knot:// scheme sources served to the scriptling CLI.
Package pluginfetch implements the knot plugin's fetcher: the source of truth for knot:// scheme sources served to the scriptling CLI.

Jump to

Keyboard shortcuts

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