declare module 'agent-guest' { import * as golemAgent200Common from 'golem:agent/common@2.0.0'; import * as golemApi150Host from 'golem:api/host@1.5.0'; import * as golemCore200Types from 'golem:core/types@2.0.0'; import * as golemTool010Common from 'golem:tool/common@0.1.0'; import * as golemTool010Streams from 'golem:tool/streams@0.1.0'; import * as golemTool010Underlying from 'golem:tool/underlying@0.1.0'; /** * Interface exported by a component that provides tools. The component * declares which tools it exposes, supplies their metadata, and accepts * invocations against a chosen leaf command of any tool. * Tools are stateless from the host's perspective: each invocation is * independent. State accumulated by the underlying agent (file-system * writes, config-store updates, etc.) persists per the agent's normal * rules and is independent of the tool calling convention. */ export namespace golemTool010Guest { /** * Enumerate the tools this component exposes. The returned metadata * is complete (full command tree and schema graph). * @throws ToolError */ export function discoverTools(): Tool[]; /** * Look up a single tool by name. * @throws ToolError */ export function getTool(name: string): Tool; /** * Invoke a command of a tool. * `command-path` selects the command body to execute. An empty list * targets the root command's body; non-empty lists walk the * `subcommands` field, each segment matching a `command-node.name` * or alias. * `input` is a self-contained `typed-schema-value` whose root must * structurally match the selected body's input schema — a record with * one field per positional, option, flag, and inherited global declared * on or above the body, each field typed by the matching type node in * the body's schema. * `stdin` is supplied when the selected body declared a stdin * `stream-spec`. Clean EOF is underlying stream closure. A final failed * item reports recoverable source failure, abandonment, resource * exhaustion, or cancellation before closure. Dropping the reader closes * further consumption. * `stdout` is supplied when the selected body declared a stdout * `stream-spec`. The implementation writes while this function is still * running and explicitly finishes or fails the endpoint. Dropping an open * writer abandons it. The first selected terminal is immutable. * `stderr` follows the same independent attachment contract as `stdout`. * `principal` carries the caller's authenticated identity for * authorization and audit, identical in semantics to the parameter * of the same name in `golem:agent/guest.invoke`. * @throws ToolError */ export function invoke(toolName: string, commandPath: string[], input: TypedSchemaValue, stdin: AsyncIterable | undefined, stdout: ToolOutputWriter | undefined, stderr: ToolOutputWriter | undefined, principal: Principal): Promise; export type Tool = golemTool010Common.Tool; export type ToolError = golemTool010Common.ToolError; export type InvocationResult = golemTool010Common.InvocationResult; export type ByteStreamItem = golemTool010Streams.ByteStreamItem; export type ToolOutputWriter = golemTool010Streams.ToolOutputWriter; export type TypedSchemaValue = golemCore200Types.TypedSchemaValue; export type Principal = golemAgent200Common.Principal; export type Result = { tag: 'ok', val: T } | { tag: 'err', val: E }; } /** * Interface exported by components that provide tool middleware. */ export namespace toolMiddlewareGuest { /** * Enumerate every middleware definition exported by this component. * @throws ToolError */ export function discoverToolMiddlewares(): ToolMiddleware[]; /** * Look up one middleware definition by canonical name. * @throws ToolError */ export function getToolMiddleware(name: string): ToolMiddleware; /** * Invoke one middleware layer around its runtime-bound next inner layer. * @throws ToolError */ export function invokeToolMiddleware(middlewareName: string, toolName: string, toolMetadata: Tool, parameters: TypedSchemaValue, commandPath: string[], input: TypedSchemaValue, stdin: AsyncIterable | undefined, stdout: ToolOutputWriter | undefined, stderr: ToolOutputWriter | undefined, principal: Principal, wrapped: UnderlyingTool): Promise; export type InvocationResult = golemTool010Common.InvocationResult; export type Tool = golemTool010Common.Tool; export type ToolError = golemTool010Common.ToolError; export type ToolMiddleware = golemTool010Common.ToolMiddleware; export type ByteStreamItem = golemTool010Streams.ByteStreamItem; export type ToolOutputWriter = golemTool010Streams.ToolOutputWriter; export type UnderlyingTool = golemTool010Underlying.UnderlyingTool; export type Principal = golemAgent200Common.Principal; export type TypedSchemaValue = golemCore200Types.TypedSchemaValue; export type Result = { tag: 'ok', val: T } | { tag: 'err', val: E }; } /** * Interface providing user-defined snapshotting capability. This can be used to perform manual update of agents * when the new component incompatible with the old one. */ export namespace saveSnapshot { /** * Saves the component's state into a user-defined snapshot */ export function save(): Promise; export type Snapshot = golemApi150Host.Snapshot; } /** * Interface providing user-defined snapshotting capability. This can be used to perform manual update of agents * when the new component incompatible with the old one. */ export namespace loadSnapshot { /** * Tries to load a user-defined snapshot, setting up the agent's state based on it. * The function can return with a failure to indicate that the update is not possible. * @throws string */ export function load(snapshot: Snapshot): Promise; export type Snapshot = golemApi150Host.Snapshot; export type Result = { tag: 'ok', val: T } | { tag: 'err', val: E }; } export namespace golemAgent200Guest { /** * Initializes the agent of a given type with the given constructor parameters. * If called a second time, it fails. * `input` is a value tree whose root encodes the constructor's parameter * list (one record field per declared `named-field`, in declaration order). * The guest interprets it against its own constructor `input-schema`. * @throws AgentError */ export function initialize(agentType: string, input: SchemaValueTree, principal: Principal): Promise; /** * Invokes an agent. If create was not called before, it fails. * `input` is a value tree whose root encodes the method's parameter list. * Streams are represented recursively by `stream-value` nodes. The result * is `none` when the method's `output-schema` is `unit`, and `some(value)` * for a `single` output. * @throws AgentError */ export function invoke(methodName: string, input: SchemaValueTree, principal: Principal): Promise; /** * Gets the agent type. If create was not called before, it fails */ export function getDefinition(): AgentType; /** * Gets the agent types defined by this component * @throws AgentError */ export function discoverAgentTypes(): AgentType[]; export type SchemaValueTree = golemCore200Types.SchemaValueTree; export type AgentError = golemAgent200Common.AgentError; export type AgentType = golemAgent200Common.AgentType; export type Principal = golemAgent200Common.Principal; export type Result = { tag: 'ok', val: T } | { tag: 'err', val: E }; } }