AiToolkit.ts overview
Since v1.0.0
Exports Grouped by Category
Constructors
make
Constructs a new AiToolkit
from the specified tools.
Signature
declare const make: <const Tools extends ReadonlyArray<AiTool.Any>>(...tools: Tools) => AiToolkit<Tools[number]>
Since v1.0.0
Merging
merge
Merges this toolkit with one or more other toolkits.
Signature
declare const merge: <const Toolkits extends ReadonlyArray<Any>>(
...toolkits: Toolkits
) => AiToolkit<Tools<Toolkits[number]>>
Since v1.0.0
Models
AiToolkit (interface)
An AiToolkit
represents a set of tools that a large language model can use to augment its response.
Signature
export interface AiToolkit<in out Tools extends AiTool.Any>
extends Effect.Effect<ToHandler<Tools>, never, AiTool.ToHandler<Tools>>,
Inspectable,
Pipeable {
new (_: never): {}
readonly [TypeId]: TypeId
/**
* A map containing the tools that are part of this toolkit.
*/
readonly tools: AiTool.ByName<Tools>
/**
* Converts this toolkit into a `Context` object containing the handlers for
* all tools in the toolkit.
*/
toContext<Handlers extends HandlersFrom<Tools>, EX = never, RX = never>(
build: Handlers | Effect.Effect<Handlers, EX, RX>
): Effect.Effect<Context.Context<AiTool.ToHandler<Tools>>, EX, RX>
/**
* Converts this toolkit into a `Layer` containing the handlers for all tools
* in the toolkit.
*/
toLayer<Handlers extends HandlersFrom<Tools>, EX = never, RX = never>(
build: Handlers | Effect.Effect<Handlers, EX, RX>
): Layer.Layer<AiTool.ToHandler<Tools>, EX, Exclude<RX, Scope.Scope>>
of<Handlers extends HandlersFrom<Tools>>(handlers: Handlers): Handlers
}
Since v1.0.0
Any (interface)
Signature
export interface Any {
readonly [TypeId]: TypeId
readonly tools: Record<string, AiTool.Any>
}
Since v1.0.0
ToHandler (interface)
Represents an AiToolkit
which has been augmented with a handler function for resolving tool call requests.
Signature
export interface ToHandler<in out Tool extends AiTool.Any> {
readonly tools: ReadonlyArray<Tool>
readonly handle: (toolName: AiTool.Name<Tool>, toolParams: AiTool.Parameters<Tool>) => AiTool.HandlerEffect<Tool>
}
Since v1.0.0
Type Ids
TypeId
Signature
declare const TypeId: unique symbol
Since v1.0.0
TypeId (type alias)
Signature
type TypeId = typeof TypeId
Since v1.0.0
Utility Types
HandlersFrom (type alias)
A utility mapped type which associates tool names with their handlers.
Signature
type HandlersFrom<Tools> = {
[Tool in Tools as Tool["name"]]: (params: AiTool.Parameters<Tool>) => AiTool.HandlerEffect<Tool>
}
Since v1.0.0
Tools (type alias)
A utility type which returns the tools in an AiToolkit
.
Signature
type Tools<Toolkit> = Toolkit extends AiToolkit<infer Tool> ? (string extends Tool["name"] ? never : Tool) : never
Since v1.0.0