Documentation
¶
Overview ¶
Package chatruntime runs hosted chat using explicit models, persistence, capability dispatch, and an isolated JavaScript executor. It has no dependency on the SDK root or an Airlock server.
Index ¶
- Constants
- func JavaScriptTool(ctx context.Context, catalog []capability.Definition, backend Backend, ...) (js tool.Tool, close func() error, err error)
- func JavaScriptTools(ctx context.Context, catalog []capability.Definition, backend Backend, ...) (tool.Set, func() error, error)
- func NewScriptFileTool(backend ScriptBackend, factory ExecutorFactory, prelude string, ...) tool.Tool
- func NewScriptTool(backend ScriptBackend, factory ExecutorFactory, prelude string, ...) tool.Tool
- func RenderPrompt(instructions string, catalog []capability.Definition, direct bool) (string, error)
- func RenderTypeScript(catalog []capability.Definition) (string, error)
- func Run(ctx context.Context, in Input) (result *sol.RunResult, err error)
- func ScriptFileToolInfo() tool.Tool
- func ScriptToolInfo() tool.Tool
- type Backend
- type ExecutorFactory
- type Input
- type Invocation
- type ScriptBackend
Constants ¶
const MaxScriptBytes = 256 << 10
Variables ¶
This section is empty.
Functions ¶
func JavaScriptTool ¶
func JavaScriptTool(ctx context.Context, catalog []capability.Definition, backend Backend, factory ExecutorFactory) (js tool.Tool, close func() error, err error)
JavaScriptTool builds synchronous run_js for an application-owned run. The host preauthorizes the catalog and enforces policy in Backend; there is no interactive confirmation. Call close on every exit, including parking. The factory allocates lazily; only catalog capabilities become JavaScript bindings.
func JavaScriptTools ¶ added in v0.8.1
func JavaScriptTools(ctx context.Context, catalog []capability.Definition, backend Backend, factory ExecutorFactory) (tool.Set, func() error, error)
JavaScriptTools builds run_js and, when file reads are authorized, run_js_file over one lazily allocated realm. Close it on every attempt exit.
func NewScriptFileTool ¶ added in v0.8.1
func NewScriptFileTool(backend ScriptBackend, factory ExecutorFactory, prelude string, autoConfirm bool) tool.Tool
NewScriptFileTool uses live inspected file-read authority and the same isolated execution contract as NewScriptTool, with structured arguments.
func NewScriptTool ¶ added in v0.8.1
func NewScriptTool(backend ScriptBackend, factory ExecutorFactory, prelude string, autoConfirm bool) tool.Tool
NewScriptTool exposes the shared run_js contract without owning a model loop. Chat and MCP adapters can both use it. Every call gets a fresh realm, so inspection in one script makes its bindings available in the next script. Approval applies to the whole script before allocation or execution.
func RenderPrompt ¶
func RenderPrompt(instructions string, catalog []capability.Definition, direct bool) (string, error)
RenderPrompt uses exactly the catalog passed to Run, without discovering or independently filtering capabilities. Instructions are host-composed text.
func RenderTypeScript ¶
func RenderTypeScript(catalog []capability.Definition) (string, error)
RenderTypeScript describes asynchronous bindings from the canonical schemas.
func Run ¶
Run executes serial model tool calls. Async capability callbacks within a script are bounded by the supplied jsexec implementation. Session state lives only for this uninterrupted run; suspension or completion destroys the realm.
func ScriptFileToolInfo ¶ added in v0.8.1
ScriptFileToolInfo describes saved JS execution without allocating a realm.
func ScriptToolInfo ¶ added in v0.8.1
ScriptToolInfo returns the provider-facing contract without an executor. MCP discovery can describe run_js before allocating any execution context.
Types ¶
type ExecutorFactory ¶
type ExecutorFactory func(context.Context, []capability.Definition) (jsexec.Session, error)
ExecutorFactory allocates a fresh realm with exactly these authorized bindings. Each binding takes one JSON object argument matching Definition.InputSchema. The executor calls Invoker with Definition.Path.ID() and a positional array. Run calls the factory only after approval and closes the session on every exit.
func ExecutorFromTransport ¶ added in v0.8.1
func ExecutorFromTransport(open func(context.Context) (io.ReadWriteCloser, error), limits jsexec.Limits, user *jsexec.User) (ExecutorFactory, error)
ExecutorFromTransport creates isolated sessions using a host-owned transport. Opening is lazy. The host supplies authorized capabilities and owns the actual executor process; this factory does not provision containers or runtime state.
type Input ¶
type Input struct {
Message string
Instructions string
Model stream.Model
ModelLimits session.ModelLimits
SessionStore session.SessionStore
Capabilities []capability.Definition
Backend Backend
ExecutorFactory ExecutorFactory
Sink eventstream.Sink
MaxSteps int
Temperature *float64
DirectTools bool
AutoConfirm bool
Redactor func(string) string
ForceCompact bool
// JavaScriptPrelude defines host-authored convenience bindings inside each
// script. It carries no credentials and is not supplied by model input.
JavaScriptPrelude string
// Resume accepts only a permission checkpoint produced by this runtime.
// Approval is required when Resume is set; false explicitly denies the call.
Resume *sol.SuspensionContext
Approved *bool
}
Input is scoped to one run. The host owns authorization, run completion, checkpoint persistence, and conversation serialization across replicas. Capabilities must be the broker-authorized subset of capability.Catalog.
type Invocation ¶
type Invocation struct {
CapabilityID string
ToolCallID string
Input json.RawMessage
}
Invocation carries canonical identity and the enclosing model tool call ID. Backend implementations bind authenticated run attribution independently of the script, authorize each call, and return redacted output and references.
type ScriptBackend ¶ added in v0.8.1
type ScriptBackend interface {
Backend
Catalog(context.Context) ([]capability.Definition, error)
}
ScriptBackend resolves the current run's inspected capabilities before each script. Catalog membership is an exposure ceiling, not execution authority; Invoke must independently authorize every operation against live state.