///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
import { InvocationMetadata, Datetime as Datetime$1, CancelableScheduledInvocationReceipt, ScheduledInvocationReceipt, CancellationToken, RegisteredAgentType } from 'golem:agent/host@2.0.0';
import { ByteStreamItem, RegisteredTool } from 'golem:tool/host@0.1.0';
import { Doc, Constraint, StreamSpec, CommandNode, CommandBody } from 'golem:tool/common@0.1.0';
import { Secret, QuotaToken, SchemaValueStream, SchemaValueTree, PermissionCard, Uuid as Uuid$1, TypeId, NumericRestrictions, MetadataEnvelope, TextRestrictions, BinaryRestrictions, PathSpec, UrlRestrictions, QuantitySpec, DiscriminatorRule, SecretSpec, QuotaTokenSpec, PermissionCardSpec, Datetime, QuantityValue, ComponentId as ComponentId$1 } from 'golem:core/types@2.0.0';
import { AgentMethod as AgentMethod$1 } from 'golem:agent/common@2.0.0';
import { PermissionError as PermissionError$1 } from 'golem:permissions/types@0.1.0';
declare const SECRET_INTERNAL: unique symbol;
type SecretInternal = typeof SECRET_INTERNAL;
declare class GuestSecretHandle {
constructor(key: SecretInternal, raw: Secret, onTake?: () => void, tracked?: boolean);
toJSON(): never;
}
declare const QUOTA_INTERNAL: unique symbol;
/** The type of the {@link QUOTA_INTERNAL} capability key. */
type QuotaInternal = typeof QUOTA_INTERNAL;
declare class GuestQuotaTokenHandle {
constructor(key: QuotaInternal, raw: QuotaToken, tracked?: boolean);
/**
* Quota-token handles are unforgeable capabilities, not data: serializing one
* (e.g. via `JSON.stringify`) is always an error. Transfer them only by
* passing the owning `QuotaToken` through a WIT `schema-value-tree`.
*/
toJSON(): never;
}
type GuestSchemaValueStream = {
kind: 'wrapped';
value: SchemaValueStream;
} | {
kind: 'native';
value: AsyncIterable;
};
declare const PERMISSION_CARD_INTERNAL: unique symbol;
/** The type of the {@link PERMISSION_CARD_INTERNAL} capability key. */
type PermissionCardInternal = typeof PERMISSION_CARD_INTERNAL;
/** Guest-side take-once carrier for an owned, opaque permission-card resource. */
declare class GuestPermissionCardHandle {
constructor(key: PermissionCardInternal, raw: PermissionCard, tracked?: boolean, lifted?: boolean);
toJSON(): never;
}
/**
* Rich UUID class that is structurally compatible with the WIT binding type
* `{ highBits: bigint; lowBits: bigint }` from `golem:core/types@2.0.0`.
*/
declare class Uuid {
readonly highBits: bigint;
readonly lowBits: bigint;
constructor(highBits: bigint, lowBits: bigint);
/**
* Formats the UUID as a standard hyphenated string.
*/
toString(): string;
/**
* Parses a UUID string.
*/
static parse(value: string): Uuid;
/**
* Generates a random UUID.
*/
static generate(): Uuid;
/**
* Wraps a raw WIT UUID object in a Uuid instance.
* If the value is already a Uuid, it is returned directly.
*/
static from(value: Uuid$1): Uuid;
}
/** A schema type node: a structural body plus its metadata envelope. */
interface SchemaType {
readonly body: SchemaTypeBody;
readonly metadata: MetadataEnvelope;
}
type SchemaTypeBody = {
tag: 'ref';
id: TypeId;
} | {
tag: 'bool';
} | {
tag: 's8';
restrictions?: NumericRestrictions;
} | {
tag: 's16';
restrictions?: NumericRestrictions;
} | {
tag: 's32';
restrictions?: NumericRestrictions;
} | {
tag: 's64';
restrictions?: NumericRestrictions;
} | {
tag: 'u8';
restrictions?: NumericRestrictions;
} | {
tag: 'u16';
restrictions?: NumericRestrictions;
} | {
tag: 'u32';
restrictions?: NumericRestrictions;
} | {
tag: 'u64';
restrictions?: NumericRestrictions;
} | {
tag: 'f32';
restrictions?: NumericRestrictions;
} | {
tag: 'f64';
restrictions?: NumericRestrictions;
} | {
tag: 'char';
} | {
tag: 'string';
} | {
tag: 'uuid';
} | {
tag: 'record';
fields: NamedFieldType[];
} | {
tag: 'variant';
cases: VariantCaseType[];
} | {
tag: 'enum';
cases: string[];
} | {
tag: 'flags';
names: string[];
} | {
tag: 'tuple';
elements: SchemaType[];
} | {
tag: 'list';
element: SchemaType;
} | {
tag: 'fixed-list';
element: SchemaType;
length: number;
} | {
tag: 'map';
key: SchemaType;
value: SchemaType;
} | {
tag: 'option';
element: SchemaType;
} | {
tag: 'result';
ok?: SchemaType;
err?: SchemaType;
} | {
tag: 'text';
restrictions: TextRestrictions;
} | {
tag: 'binary';
restrictions: BinaryRestrictions;
} | {
tag: 'path';
spec: PathSpec;
} | {
tag: 'url';
restrictions: UrlRestrictions;
} | {
tag: 'datetime';
} | {
tag: 'duration';
} | {
tag: 'quantity';
spec: QuantitySpec;
} | {
tag: 'union';
branches: UnionBranch[];
} | {
tag: 'secret';
spec: Omit;
inner: SchemaType;
} | {
tag: 'quota-token';
spec: QuotaTokenSpec;
} | {
tag: 'permission-card';
spec: PermissionCardSpec;
} | {
tag: 'future';
element?: SchemaType;
} | {
tag: 'stream';
element?: SchemaType;
};
interface NamedFieldType {
name: string;
body: SchemaType;
metadata: MetadataEnvelope;
}
interface VariantCaseType {
name: string;
payload?: SchemaType;
metadata: MetadataEnvelope;
}
interface UnionBranch {
/** Logical branch name (carried in `union` values). */
tag: string;
body: SchemaType;
discriminator: DiscriminatorRule;
metadata: MetadataEnvelope;
}
interface SchemaTypeDef {
/** Optional human-readable qualified name (display only). */
readonly name?: string;
readonly body: SchemaType;
}
/**
* A self-contained schema graph: a registry of named definitions (keyed by
* stable `type-id`) plus a root type. `ref` bodies reference entries in `defs`.
*/
interface SchemaGraph {
readonly defs: ReadonlyMap;
readonly root: SchemaType;
}
type SchemaValue = {
tag: 'bool';
value: boolean;
} | {
tag: 's8';
value: number;
} | {
tag: 's16';
value: number;
} | {
tag: 's32';
value: number;
} | {
tag: 's64';
value: bigint;
} | {
tag: 'u8';
value: number;
} | {
tag: 'u16';
value: number;
} | {
tag: 'u32';
value: number;
} | {
tag: 'u64';
value: bigint;
} | {
tag: 'f32';
value: number;
} | {
tag: 'f64';
value: number;
} | {
tag: 'char';
value: string;
} | {
tag: 'string';
value: string;
} | {
tag: 'uuid';
value: Uuid;
} | {
tag: 'record';
fields: SchemaValue[];
} | {
tag: 'variant';
caseIndex: number;
payload?: SchemaValue;
} | {
tag: 'enum';
caseIndex: number;
} | {
tag: 'flags';
flags: boolean[];
} | {
tag: 'tuple';
elements: SchemaValue[];
} | {
tag: 'list';
elements: SchemaValue[];
} | {
tag: 'fixed-list';
elements: SchemaValue[];
} | {
tag: 'map';
entries: SchemaMapEntry[];
} | {
tag: 'option';
value?: SchemaValue;
} | {
tag: 'result';
result: SchemaResult;
} | {
tag: 'text';
text: string;
language?: string;
} | {
tag: 'binary';
bytes: Uint8Array;
mimeType?: string;
} | {
tag: 'path';
value: string;
} | {
tag: 'url';
value: string;
} | {
tag: 'datetime';
value: Datetime;
} | {
tag: 'duration';
nanoseconds: bigint;
} | {
tag: 'quantity';
value: QuantityValue;
} | {
tag: 'union';
unionTag: string;
body: SchemaValue;
} | {
tag: 'secret';
handle: GuestSecretHandle;
} | {
tag: 'quota-token';
handle: GuestQuotaTokenHandle;
} | {
tag: 'stream';
handle: SchemaValueStreamHandle;
} | {
tag: 'permission-card';
handle: GuestPermissionCardHandle;
};
interface SchemaMapEntry {
key: SchemaValue;
value: SchemaValue;
}
interface SchemaValueStreamHandle {
peek(): GuestSchemaValueStream | undefined;
take(): GuestSchemaValueStream | undefined;
close(): Promise;
}
type SchemaResult = {
tag: 'ok';
value?: SchemaValue;
} | {
tag: 'err';
value?: SchemaValue;
};
interface TypedSchemaValue {
graph: SchemaGraph;
value: SchemaValue;
}
/** Values substituted for fields omitted from a record's canonical JSON object. */
type RecordFieldDefaults = ReadonlyMap;
type JsonValue = null | boolean | number | string | JsonValue[] | {
readonly [key: string]: JsonValue;
};
interface SchemaIssue {
readonly message: string;
readonly path: readonly (string | number)[];
}
type SchemaValidationResult = {
readonly success: true;
readonly value: T;
} | {
readonly success: false;
readonly issues: readonly SchemaIssue[];
};
declare class SchemaRef {
readonly graph: SchemaGraph;
readonly root: SchemaType;
private readonly fieldDefaults?;
constructor(graph: SchemaGraph, root?: SchemaType);
/**
* @internal Build a view over definitions already owned and frozen by the SDK.
*
* `fieldDefaults` applies only to the JSON surface of an inline root record: canonical JSON
* may omit those fields, and the rendered JSON Schema does not require them. Packed values
* always contain every field of the record.
*/
static fromImmutableGraph(graph: SchemaGraph, root: SchemaType, fieldDefaults?: RecordFieldDefaults): SchemaRef;
validateJson(value: JsonValue): SchemaValidationResult;
validateValue(value: SchemaValue): SchemaValidationResult;
/** Pack canonical JSON and validate it against the complete schema. */
packJson(value: JsonValue): SchemaValue;
unpackJson(value: SchemaValue): JsonValue;
toJsonSchema(options?: {
includeDraftMarker?: boolean;
}): JsonValue;
}
declare class ComponentId {
readonly uuid: Uuid;
constructor(uuid: Uuid);
toString(): string;
static from(value: ComponentId$1): ComponentId;
}
type ToolInputStream = ReadableStream;
type SettledToolResult = {
readonly status: 'fulfilled';
readonly value: Result;
} | {
readonly status: 'rejected';
readonly reason: unknown;
};
interface CollectedToolInvocation {
readonly result: SettledToolResult;
readonly stdout: SettledToolResult;
readonly stderr: SettledToolResult;
}
interface StartedToolInvocation {
readonly stdout?: ReadableStream;
readonly stderr?: ReadableStream;
readonly result: Promise;
cancel(): void;
/** Stop result delivery without cancelling the invocation or either output. */
detachResult(): void;
collect(): Promise>;
}
interface ToolInvocationResult {
readonly result?: TypedSchemaValue;
}
interface ToolClientRuntime {
start(commandPath: readonly string[], input: TypedSchemaValue, stdin: ToolInputStream | undefined, stdout: boolean, stderr: boolean): {
stdout?: AsyncIterable;
stderr?: AsyncIterable;
settledResult: Promise>;
cancel(): void;
};
}
/** A declared tool argument with its selected value schema. */
interface ToolArgument {
readonly kind: 'positional' | 'tail' | 'option' | 'flag';
readonly name: string;
readonly aliases: readonly string[];
readonly short?: string;
readonly required: boolean;
readonly default?: SchemaValue;
readonly optionalCarrier?: true;
readonly schema: SchemaRef;
}
/** An invalid structured result returned by a remote tool. */
declare class ToolRemoteOutputError extends Error {
constructor(message: string);
}
/** A declared custom tool error decoded using discovered metadata. */
interface ReflectedToolFailure {
readonly name: string;
readonly value?: JsonValue;
}
/** One callable command in an immutable discovered tool snapshot. */
declare class ToolCommand {
readonly toolName: string;
private readonly runtime;
readonly path: readonly string[];
readonly name: string;
readonly aliases: readonly string[];
readonly doc: Doc;
readonly inputSchema?: SchemaRef;
readonly arguments: readonly ToolArgument[];
readonly constraints: readonly Constraint[];
readonly stdin?: StreamSpec;
readonly stdout?: StreamSpec;
readonly stderr?: StreamSpec;
readonly result?: SchemaRef;
readonly errors: readonly {
readonly name: string;
readonly payload?: SchemaRef;
}[];
readonly children: readonly ToolCommand[];
private readonly wireInputGraph?;
private readonly omittedDefaults;
constructor(toolName: string, node: CommandNode, body: CommandBody | undefined, path: readonly string[], inherited: readonly ToolArgument[], graph: SchemaGraph, typeAt: (index: number) => SchemaType, children: readonly ToolCommand[], runtime: ToolClientRuntime);
/**
* Validate and pack canonical JSON input before opening a tool RPC. Omitted scalar options,
* positionals and flags take their declared defaults.
*/
packJson(input: JsonValue): SchemaValue;
/** Validate canonical JSON and command constraints without dispatching. */
validateJson(input: JsonValue): ReturnType;
private validateConstraints;
private inputValue;
private decodeResult;
private unpackResult;
/** Start a cancelable invocation with a schema-native input. */
startValue(input: SchemaValue, stdin?: ToolInputStream): StartedToolInvocation;
/** Start a cancelable invocation with canonical JSON input. */
startJson(input: JsonValue, stdin?: ToolInputStream): StartedToolInvocation;
/** Await a structured schema-native result. */
invokeValue(input: SchemaValue, stdin?: ToolInputStream): Promise;
/** Await a structured canonical JSON result. */
invokeJson(input: JsonValue, stdin?: ToolInputStream): Promise;
/** Admit a fire-and-forget invocation without output attachments. */
triggerValue(input: SchemaValue, stdin?: ToolInputStream): void;
/** Admit a fire-and-forget invocation from canonical JSON. */
triggerJson(input: JsonValue, stdin?: ToolInputStream): void;
private mapFailure;
}
/** An immutable snapshot of one accessible tool registration. */
declare class ToolType {
readonly name: string;
readonly lookupName: string;
readonly version: string;
readonly implementedBy: ComponentId;
readonly commands: readonly ToolCommand[];
readonly client: ReflectedToolClient;
constructor(registered: RegisteredTool, runtime?: ToolClientRuntime);
/** Resolve names and aliases to a canonical command handle. */
command(path: readonly string[]): ToolCommand | undefined;
}
/** Strict callable lookup for a discovered tool. */
interface ReflectedToolClient {
command(path: readonly string[]): ToolCommand;
}
/** List the current accessible tools. */
declare function getAllToolTypes(): ToolType[];
/** Look up one accessible tool; missing and inaccessible are indistinguishable. */
declare function getToolType(name: string): ToolType | undefined;
/** A fully dynamic client that sends caller-owned packed values. */
declare class DynamicToolClient {
readonly name: string;
private readonly runtime;
constructor(name: string, runtime?: ToolClientRuntime);
start(path: readonly string[], input: TypedSchemaValue, stdin?: ToolInputStream, stdout?: boolean, stderr?: boolean): StartedToolInvocation;
invoke(path: readonly string[], input: TypedSchemaValue, stdin?: ToolInputStream): Promise;
trigger(path: readonly string[], input: TypedSchemaValue, stdin?: ToolInputStream): void;
}
interface DynamicInvocation {
readonly metadata: InvocationMetadata;
readonly value?: T;
}
interface DynamicAgentClientSurface {
readonly agentId: ParsedAgentId;
method(name: string): DynamicAgentMethodSurface;
}
interface DynamicAgentMethodSurface {
readonly name: string;
/** Invoke and await. A `scopeCard` is borrowed for the call. */
invokeValue(input: SchemaValue, signal?: AbortSignal, scopeCard?: ScopeCard): Promise>;
triggerValue(input: SchemaValue): InvocationMetadata;
scheduleValue(at: Datetime$1, input: SchemaValue): CancelableScheduledInvocationReceipt;
}
declare class DynamicAgentClient implements DynamicAgentClientSurface {
readonly agentId: ParsedAgentId;
private readonly remote;
constructor(agentId: ParsedAgentId);
method(name: string): DynamicAgentMethod;
}
declare class DynamicAgentMethod implements DynamicAgentMethodSurface {
readonly name: string;
private readonly remote;
constructor(name: string, remote: RemoteAgentHandle);
invokeValue(input: SchemaValue, signal?: AbortSignal, scopeCard?: ScopeCard): Promise>;
triggerValue(input: SchemaValue): InvocationMetadata;
scheduleValue(at: Datetime$1, input: SchemaValue): CancelableScheduledInvocationReceipt;
}
/** @internal Protocol implemented by typed client definitions and reflected agent types. */
declare const bindAgentClient: "__golemBindAgentClient";
/** Options for a client bound to an existing agent identity. */
interface AgentClientBindOptions {
/** The default scope card for every awaited call of the bound client. */
readonly scopeCard?: ScopeCard;
}
/** @internal A value that can bind itself to an existing agent identity. */
interface AgentClientBinding {
[bindAgentClient](agentId: ParsedAgentId, config?: Config, options?: AgentClientBindOptions): Client;
}
/** Explicit parts used to construct a {@link ParsedAgentId}. */
interface ParsedAgentIdCreateOptions {
readonly typeName: string;
readonly constructorValue: SchemaValue;
readonly phantomId?: Uuid;
}
/** Semantic parts of a {@link ParsedAgentId}. */
interface ParsedAgentIdParts {
readonly typeName: string;
readonly constructorValue: SchemaValue;
readonly phantomId?: Uuid;
}
/**
* Parsed environment-scoped agent identity string.
*
* A ParsedAgentId wraps the environment-scoped string representation of an agent ID and can parse it
* into its constituent parts: agent type name, constructor parameters, and optional phantom ID.
*
* Constructor parameters are carried as the schema-native {@link SchemaValue} (the recursive
* in-memory value); the embedded type graph the host returns is discarded because the SDK
* re-derives parameter types from the agent's registered runtime metadata.
*/
declare class ParsedAgentId {
readonly value: string;
parsedCache: [string, SchemaValue, Uuid | undefined] | undefined;
private wireCache;
constructor(agentId: string);
/**
* Constructs a ParsedAgentId from an agent type name, constructor value, and optional phantom ID.
* Prefer a definition's `agentId(...)` when a typed definition is available.
*/
static create(options: ParsedAgentIdCreateOptions): ParsedAgentId;
/**
* Returns the parsed agent ID.
* @returns a tuple of the agent type name, parameters and an optional phantom ID
*/
parsed(): [string, SchemaValue, Uuid | undefined];
/** @internal Identity decoding for generated invocation and snapshot dispatch. */
parsedWire(): [string, SchemaValueTree, Uuid | undefined];
/** Return the semantic parts of this environment-scoped identity. */
parts(): ParsedAgentIdParts;
/**
* Bind a method-only, full, or reflected client to this identity. Config overrides apply only
* if this creates the worker. `options.scopeCard` is the client's default scope card.
*/
client(binding: AgentClientBinding, config?: Config, options?: AgentClientBindOptions): Client;
/** Invoke this identity with schema values and no discovery or typed client definition. */
dynamicClient(): DynamicAgentClientSurface;
}
declare const prototype: {
/**
* Returns `true` if the result is successful, `false` otherwise
* @example.
* Result.ok(123).isOk() // true
* @example
* Result.err('error').isOk() // false
*/
readonly isOk: typeof isOk;
/**
* Returns `true` if the result is an error, `false` otherwise
* @example
* Result.err('error').isOk() // false
* @example.
* Result.ok(123).isOk() // true
*/
readonly isErr: typeof isErr;
/**
* Returns the successful value of the result or throws the error value.
* This should be used when returning from a component function that expects to receive a result.
* @example Returns the payload of a successful result.
* Result.ok(123).unwrapForWit() // 123
* @example Throws the payload of a failed result.
* Result.err('error').unwrapForWit() // throws 'error'
*/
readonly unwrapForWit: typeof unwrapForWit;
/**
* Returns `this.value` if `this` is a successful result, otherwise throws a TypeError.
* @example Returns the payload of a successful result.
* Result.ok(123).unwrap() // 123
* @example Throws a TypeError for a failed result.
* Result.err('error').unwrap() // throws TypeError
*/
readonly unwrap: typeof unwrap;
/**
*
* Returns `this.error` if `this` is a failed result, otherwise throws a TypeError.
* @example Throw a TypeError for a successful result.
* Result.ok(123).unwrapErr() // throws TypeError
* @example Returns the payload of a failed result
* Result.err('error').unwrap() // 'error'
*/
readonly unwrapErr: typeof unwrapErr;
/**
* Returns the payload of the result.
* @example Returns the payload of a successful result.
* Result.ok(123).toUnion() // 123
* @example Returns the payload of a failed result.
* Result.err('error').toUnion() // 'error'
*/
readonly toUnion: typeof toUnion;
/**
* Return the result of applying one of the given functions to the payload.
* @example
* Result.ok(123).match((x) => x * 2, (x: string) => x + '!') // 246
* Result.err('error').match((x: number) => x * 2, (x) => x + '!') // 'error!'
*/
readonly match: typeof match;
/**
* Creates a Result value by modifying the payload of the successful result using the given function.
* @example
* Result.ok(123).map((x) => x * 2) // Result.ok(246)
* Result.err('error').map((x: number) => x * 2) // Result.err('error')
*/
readonly map: typeof map;
/**
* Creates a Result value by modifying the payload of the failed result using the given function.
* @example
* Result.ok(123).mapError((x: string) => x + '!') // Result.ok(123)
* Result.err('error').mapError((x) => x + '!') // Result.err('error!')
*/
readonly mapError: typeof mapError;
/**
* Calls the given function with the payload of the result and returns the result unchanged.
*/
readonly tap: typeof tap;
/**
* Maps the payload of the successful result and flattens the nested Result type.
* @example
* Result.ok(123).flatMap((x) => Result.ok(x * 2)) // Result.ok(246)
* Result.ok(123).flatMap((x) => Result.err('error')) // Result.err('error')
* Result.err('error').flatMap((x: number) => Result.ok(x * 2)) // Result.err('error')
* Result.err('error').flatMap((x) => Result.err('failure')) // Result.err('error')
*/
readonly flatMap: typeof flatMap;
/**
* Flattens the nested Result type.
* @example
* Result.ok(Result.ok(123)).flatten() // Result.ok(123)
* Result.ok(Result.err('error')).flatten() // Result.err('error')
* Result.err('error').flatten() // Result.err('error')
*/
readonly flatten: typeof flatten;
/**
* Perform a safe cast of the error type to the given class. If the payload of the failed result is not instance of constructor, throws TypeError.
* @example
* const result: Result = Result.tryCatch(() => {
* if (Math.random() >= 0) {
* throw new Error('error')
* } else {
* return 123
* }
* }).assertErrorInstanceOf(Error)
*/
readonly assertErrorInstanceOf: typeof assertErrorInstanceOf;
};
/** Type representing success or failure. */
type Result = Result.Ok | Result.Err;
declare namespace Result {
/**
* The type of a successful result.
* @example
* const success: Result.ok = Result.ok(123)
*/
type Ok = typeof prototype & {
readonly tag: 'ok';
readonly val: T;
};
/**
* A failed result.
* @example
* const failure: Result.err = Result.err('error')
*/
type Err = typeof prototype & {
readonly tag: 'err';
readonly val: E;
};
/**
* Create a successful result.
*/
function ok(value: T): Result.Ok;
/**
* Create an error result.
*/
function err(error: E): Err;
/**
* Create a result from a function that may throw an error.
*/
function tryCatch(f: () => T): Result;
function fromNullish(value: null): Result.Err;
function fromNullish(value: undefined): Result.Err;
function fromNullish(value: null | undefined): Result.Err;
function fromNullish(value: T): Result.Ok;
function fromNullish(value: T | null): Result;
function fromNullish(value: T | undefined): Result;
function fromNullish(value: T | null | undefined): Result;
function all(results: readonly Result.Ok[]): Result.Ok;
function all(results: readonly Result[]): Result;
}
declare function isOk(this: Result): this is Result.Ok;
declare function isErr(this: Result): this is Result.Err;
declare function unwrapForWit(this: Result.Ok): T;
declare function unwrapForWit(this: Result.Err): never;
declare function unwrapForWit(this: Result): T;
declare function unwrap(this: Result.Ok): T;
declare function unwrap(this: Result.Err): never;
declare function unwrap(this: Result): T;
declare function unwrapErr(this: Result.Ok): never;
declare function unwrapErr(this: Result.Err): E;
declare function unwrapErr(this: Result): E;
declare function toUnion(this: Result.Ok): T;
declare function toUnion(this: Result.Err): E;
declare function toUnion(this: Result): T | E;
declare function match(this: Result.Ok, f: (value: T) => T2, g: (error: E) => E2): T2;
declare function match(this: Result.Err, f: (value: T) => T2, g: (error: E) => E2): E2;
declare function match(this: Result, f: (value: T) => T2, g: (error: E) => E2): T2 | E2;
declare function map(this: Result.Ok, f: (value: T) => T2): Result.Ok;
declare function map(this: Result.Err, f: (value: T) => T2): Result.Err;
declare function map(this: Result, f: (value: T) => T2): Result;
declare function mapError(this: Result.Ok, f: (error: E) => E2): Result.Ok;
declare function mapError(this: Result.Err, f: (error: E) => E2): Result.Err;
declare function mapError(this: Result, f: (error: E) => E2): Result;
declare function tap(this: Result.Err, f: (error: E) => void): Result.Err;
declare function tap(this: Result.Ok, f: (value: T) => void): Result.Ok;
declare function tap(this: Result, f: (value: T) => void): Result;
declare function flatMap(this: Result.Ok, f: (value: T) => Result.Ok): Result.Ok;
declare function flatMap(this: Result.Ok, f: (value: T) => Result.Err): Result.Err;
declare function flatMap(this: Result.Ok, f: (value: T) => Result): Result;
declare function flatMap(this: Result.Err, f: (value: T) => Result<_T2, E2>): Result.Err;
declare function flatMap(this: Result, f: (value: T) => Result.Ok): Result;
declare function flatMap(this: Result, f: (value: T) => Result.Err): Result.Err;
declare function flatMap(this: Result, f: (value: T) => Result): Result;
declare function flatten(this: Result.Err): Result.Err;
declare function flatten(this: Result.Ok>): Result.Err;
declare function flatten(this: Result.Ok>): Result.Ok;
declare function flatten(this: Result.Ok>): Result;
declare function flatten(this: Result, E>): Result;
declare function flatten(this: Result, E2>): Result.Err;
declare function flatten(this: Result, E2>): Result;
declare function assertErrorInstanceOf unknown>(this: Result.Ok, constructor: C): Result.Ok;
declare function assertErrorInstanceOf unknown>(this: Result.Err, constructor: C): Result.Err>;
declare function assertErrorInstanceOf unknown>(this: Result, constructor: C): Result>;
/**
* One grant pattern: `class(owner) @ recipient : verb : resource-id`.
*
* Plain data. A grant never carries authority by itself; derive inputs are
* requests that the host validates against the parent card or the wallet.
*/
interface PatternGrant {
readonly class: string;
readonly owner: string;
readonly recipient: string;
readonly verb: string;
readonly resourceId: string;
}
/** The four grant lists of a card's bound lattice. */
interface CardView {
readonly lowerPositive: readonly PatternGrant[];
readonly lowerNegative: readonly PatternGrant[];
readonly upperPositive: readonly PatternGrant[];
readonly upperNegative: readonly PatternGrant[];
}
/** An instant: seconds and nanoseconds since the Unix epoch (UTC). */
interface Timestamp {
readonly seconds: bigint;
readonly nanoseconds: number;
}
declare const CARD_ID_INTERNAL: unique symbol;
/**
* An opaque permission-card identifier.
*
* Card IDs are host-private: a `CardId` has no public constructor and exposes
* no UUID or string form. Printing or serializing one gives a redacted
* placeholder. The SDK interns identifiers, so two `CardId` values for the same
* card are the same object; compare them with `===` or {@link CardId.equals},
* and use them as `Map` / `Set` keys.
*/
declare class CardId {
/** @internal */
constructor(key: typeof CARD_ID_INTERNAL, value: string);
equals(other: CardId): boolean;
toString(): string;
toJSON(): string;
}
/** The case names of the WIT `permission-error` variant. */
type PermissionErrorKind = PermissionError$1['tag'];
/** An expected failure of a permission-card operation, reported by the host. */
declare class PermissionError extends Error {
readonly kind: PermissionErrorKind;
readonly details: string;
readonly _tag = "PermissionError";
constructor(kind: PermissionErrorKind, details: string);
}
/**
* An invocation-local card from {@link deriveScope}, or the scope card lent to
* the current invocation, listed by {@link wallet}.
*
* Attach a scope card to an awaited RPC call (the `scopeCard` call or client
* option): the callee holds its authority until that invocation ends, and the
* call borrows the card. A scope card is valid only during the invocation that
* derived it; keeping it, or a client whose default is it, for a later
* invocation makes awaited calls fail with `denied`.
*
* A scope card cannot be revoked, installed, used as the parent of a
* persistent card, sent as an RPC argument or result, or serialized. It can be
* a parent in another {@link deriveScope}.
*/
declare class ScopeCard {
private readonly scopeCardBrand;
/** @internal */
constructor(key: PermissionCardInternal, raw: PermissionCard);
/** The scope card's identifier. */
id(): CardId;
/** The identifiers of the scope card's root cards. */
parents(): CardId[];
/**
* The earliest expiry of the root cards of this scope card, or `undefined`
* when no root card expires. The scope card stops authorizing then.
*/
expiresAt(): Timestamp | undefined;
/** The scope card's grant lattice. Requires `card:inspect` authority. */
inspect(): Result;
/** Drop this agent's handle to the scope card. Every later use throws. */
release(): void;
/** `true` after the scope card was released. */
isMoved(): boolean;
toJSON(): never;
}
type RemoteAgentError = {
readonly tag: 'invalid-input';
readonly details: string;
} | {
readonly tag: 'invalid-method';
readonly details: string;
} | {
readonly tag: 'invalid-type';
readonly details: string;
} | {
readonly tag: 'invalid-agent-id';
readonly details: string;
} | {
readonly tag: 'custom-error';
readonly value: Value;
};
type RemoteCallErrorCause = {
readonly tag: 'protocol-error';
readonly details: string;
} | {
readonly tag: 'denied';
readonly details: string;
} | {
readonly tag: 'not-found';
readonly details: string;
} | {
readonly tag: 'remote-internal-error';
readonly details: string;
} | {
readonly tag: 'remote-agent-error';
readonly error: RemoteAgentError;
};
declare class RemoteCallError extends Error {
readonly _tag = "RemoteCallError";
readonly cause: RemoteCallErrorCause;
constructor(context: string, cause: RemoteCallErrorCause);
}
declare function isRemoteCallError(error: unknown): error is RemoteCallError;
declare class RemoteOutputError extends Error {
readonly _tag = "RemoteOutputError";
constructor(message: string, options?: ErrorOptions);
}
interface RemoteInvocationResult {
metadata: InvocationMetadata;
value?: Value;
}
interface AgentConfigEntry {
readonly path: readonly string[];
readonly value: TypedSchemaValue;
}
interface RemoteAgentHandle {
readonly agentId: string;
/**
* Invoke `method` and await its result. A `scopeCard` is borrowed for the
* call: the callee holds its authority until the invocation ends, and the
* caller keeps the card.
*/
invokeAndAwait(method: string, params: Value, signal?: AbortSignal, scopeCard?: ScopeCard): Promise;
invokeAndAwaitWithMetadata(method: string, params: Value, signal?: AbortSignal, scopeCard?: ScopeCard): Promise>;
invoke(method: string, params: Value): void;
invokeWithMetadata(method: string, params: Value): InvocationMetadata;
schedule(at: Datetime$1, method: string, params: Value): void;
scheduleWithMetadata(at: Datetime$1, method: string, params: Value): ScheduledInvocationReceipt;
scheduleCancelable(at: Datetime$1, method: string, params: Value): CancellationToken;
scheduleCancelableWithMetadata(at: Datetime$1, method: string, params: Value): CancelableScheduledInvocationReceipt;
}
interface ReflectedInvocation {
readonly metadata: InvocationMetadata;
readonly value?: T;
}
/** Canonical JSON values for declared local configuration paths. */
interface ReflectedConfigJsonEntry {
readonly path: readonly string[];
readonly value: JsonValue;
}
declare class AgentMethod {
readonly name: string;
readonly description: string;
readonly promptHint?: string;
readonly input: SchemaRef;
readonly output?: SchemaRef;
constructor(raw: AgentMethod$1, graph: ReflectedGraph);
}
declare class AgentType {
readonly name: string;
readonly description: string;
readonly sourceLanguage: string;
readonly mode: 'durable' | 'ephemeral';
readonly implementedBy: ComponentId;
readonly constructorInput: SchemaRef;
readonly methods: readonly AgentMethod[];
readonly config: readonly {
readonly path: readonly string[];
readonly source: 'local' | 'secret';
readonly schema: SchemaRef;
}[];
readonly client: ReflectedAgentClientFactory;
constructor(registered: RegisteredAgentType);
method(name: string): AgentMethod | undefined;
/** Construct an agent identity from canonical JSON constructor input. */
agentId(input: JsonValue, phantomId?: Uuid): ParsedAgentId;
/** Construct an agent identity from an already packed constructor value. */
agentIdValue(input: SchemaValue, phantomId?: Uuid): ParsedAgentId;
[bindAgentClient](agentId: ParsedAgentId, config?: readonly AgentConfigEntry[], options?: AgentClientBindOptions): ReflectedAgentClient;
/** Pack canonical JSON overrides for declared local config fields. */
packConfigJson(entries: readonly ReflectedConfigJsonEntry[]): AgentConfigEntry[];
/** Validate schema-native overrides before opening an RPC. */
validateConfigValues(entries: readonly AgentConfigEntry[]): AgentConfigEntry[];
private configDeclaration;
}
interface ReflectedPhantomClient {
readonly agentId: ParsedAgentId;
readonly phantomId: Uuid;
readonly client: ReflectedAgentClient;
}
declare class ReflectedAgentClientFactory {
private readonly agentType;
constructor(agentType: AgentType);
get(input: JsonValue, config?: readonly ReflectedConfigJsonEntry[]): ReflectedAgentClient;
getValue(input: SchemaValue, config?: readonly AgentConfigEntry[]): ReflectedAgentClient;
getPhantom(input: JsonValue, phantomId: Uuid, config?: readonly ReflectedConfigJsonEntry[]): ReflectedAgentClient;
getPhantomValue(input: SchemaValue, phantomId: Uuid, config?: readonly AgentConfigEntry[]): ReflectedAgentClient;
newPhantom(input: JsonValue, config?: readonly ReflectedConfigJsonEntry[]): ReflectedPhantomClient | ReflectedAgentClient;
newPhantomValue(input: SchemaValue, config?: readonly AgentConfigEntry[]): ReflectedPhantomClient | ReflectedAgentClient;
private create;
private requireMode;
}
declare class ReflectedAgentClient {
private readonly agentType;
private readonly remote;
private readonly scopeCard?;
constructor(agentType: AgentType, remote: RemoteAgentHandle, scopeCard?: ScopeCard | undefined);
method(name: string): ReflectedAgentMethod;
}
/**
* One method of a reflected agent. The awaited calls borrow `scopeCard` when it
* is given, and otherwise the client's default scope card; `null` sends none.
*/
declare class ReflectedAgentMethod {
readonly definition: AgentMethod;
private readonly remote;
private readonly defaultScopeCard?;
constructor(definition: AgentMethod, remote: RemoteAgentHandle, defaultScopeCard?: ScopeCard | undefined);
invoke(input: JsonValue, signal?: AbortSignal, scopeCard?: ScopeCard | null): Promise>;
invokeJson(input: JsonValue, signal?: AbortSignal, scopeCard?: ScopeCard | null): Promise>;
invokeValue(input: SchemaValue, signal?: AbortSignal, scopeCard?: ScopeCard | null): Promise>;
trigger(input: JsonValue): InvocationMetadata;
triggerValue(input: SchemaValue): InvocationMetadata;
schedule(at: Datetime$1, input: JsonValue): CancelableScheduledInvocationReceipt;
scheduleValue(at: Datetime$1, input: SchemaValue): CancelableScheduledInvocationReceipt;
}
declare function getAllAgentTypes(): readonly AgentType[];
/**
* Look up a deployed agent type by name.
*
* This is an optional discovery operation: it returns `undefined` for routers or types not visible in
* the current environment. Once returned, each schema operation is strict and throws for malformed
* JSON or schema values.
*/
declare function getAgentType(name: string): AgentType | undefined;
/**
* Look up the current deployed schema for a full environment-scoped identity.
*
* Returns `undefined` for routers, or when the agent does not exist, its ID is malformed, its type is missing, or
* the caller lacks `View` permission. Use {@link ParsedAgentId.parsed} when strict identity parsing is
* required independently of discovery.
*/
declare function getAgentTypeByAgentId(agentId: ParsedAgentId): AgentType | undefined;
interface ReflectedGraph {
readonly graph: SchemaGraph;
readonly types: readonly SchemaType[];
}
export { AgentMethod, AgentType, ComponentId, DynamicAgentClient, DynamicAgentMethod, DynamicToolClient, ReflectedAgentClient, ReflectedAgentClientFactory, ReflectedAgentMethod, RemoteCallError, RemoteOutputError, ToolCommand, ToolRemoteOutputError, ToolType, getAgentType, getAgentTypeByAgentId, getAllAgentTypes, getAllToolTypes, getToolType, isRemoteCallError };
export type { DynamicAgentClientSurface, DynamicAgentMethodSurface, DynamicInvocation, ReflectedConfigJsonEntry, ReflectedInvocation, ReflectedPhantomClient, ReflectedToolClient, ReflectedToolFailure, RemoteAgentError, RemoteCallErrorCause, ToolArgument };