export * as Tool from "./tool.js" import { Effect, JsonSchema, Schema } from "effect" import type { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec" import type { Agent } from "./agent.js" import type { Session } from "./session.js" import type { SessionMessage } from "./session-message.js" export type Metadata = Readonly> export const CallID = Schema.String.pipe(Schema.brand("Tool.CallID")) export type CallID = typeof CallID.Type export interface Context { readonly sessionID: Session.ID readonly agent: Agent.ID readonly messageID: SessionMessage.ID readonly callID: CallID readonly progress: (update: Metadata) => Effect.Effect } interface BaseOptions { readonly namespace?: string readonly permission?: string } export type Options = BaseOptions & ( | { readonly codemode?: true readonly pinned?: boolean } | { readonly codemode: boolean readonly pinned?: never } ) export type ValueSchema = | Schema.Codec | (StandardSchemaV1 & StandardJSONSchemaV1) | JsonSchema.JsonSchema type InputValue = 0 extends 1 & S ? any : S extends Schema.Codec ? A : S extends StandardSchemaV1 ? A : unknown type OutputValue = S extends undefined ? never : S extends Schema.Codec ? A : S extends StandardSchemaV1 ? A : any export class Error extends Schema.TaggedErrorClass()("Tool.Error", { message: Schema.String, error: Schema.optional(Schema.Defect()), metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)), }) {} export interface TextContent extends Schema.Schema.Type {} export const TextContent = Schema.Struct({ type: Schema.Literal("text"), text: Schema.String, }).annotate({ identifier: "Tool.TextContent" }) export interface FileContent extends Schema.Schema.Type {} export const FileContent = Schema.Struct({ type: Schema.Literal("file"), uri: Schema.String, mime: Schema.String, name: Schema.optional(Schema.String), }).annotate({ identifier: "Tool.FileContent" }) export const Content = Schema.Union([TextContent, FileContent]) .pipe(Schema.toTaggedUnion("type")) .annotate({ identifier: "Tool.Content" }) export type Content = Schema.Schema.Type export interface Result | undefined = ValueSchema | undefined> { readonly output?: OutputValue readonly content?: string | ReadonlyArray readonly metadata?: Metadata } export type Info< Input extends ValueSchema = ValueSchema, Output extends ValueSchema | undefined = ValueSchema | undefined, > = { readonly name: string readonly input: Input readonly description: string readonly execute: (input: InputValue, context: Context) => Effect.Effect, Error> readonly output?: Output readonly options?: Options }