index
@fungi.computer/mule / index
Type Aliases
Section titled “Type Aliases”MuleStreamFunction
Section titled “MuleStreamFunction”MuleStreamFunction = (
model,context,options?) =>AssistantMessageEventStream|Promise<AssistantMessageEventStream>>
Pi’s model stream function, supplied explicitly by the caller.
Parameters
Section titled “Parameters”Model<Api>
context
Section titled “context”Context
options?
Section titled “options?”SimpleStreamOptions
Returns
Section titled “Returns”AssistantMessageEventStream | Promise<AssistantMessageEventStream>
MuleIdentityKind
Section titled “MuleIdentityKind”MuleIdentityKind =
"run"|"turn"|"message"|"tool_call"|"tool_result"|"terminal"
Causal roles added around Pi’s model and tool loop.
MuleIdentity
Section titled “MuleIdentity”MuleIdentity =
object
One run-local causal identity.
Properties
Section titled “Properties”
readonlykind:MuleIdentityKind
readonlyvalue:string
parent?
Section titled “parent?”
readonlyoptionalparent?:MuleIdentity
MuleError
Section titled “MuleError”MuleError =
object
Expected failure from Mule’s model, tool, control, or listener work.
Properties
Section titled “Properties”
readonly_tag:"MuleError"
readonlyphase:"model"|"tool"|"control"|"listener"
message
Section titled “message”
readonlymessage:string
cause?
Section titled “cause?”
readonlyoptionalcause?:unknown
The underlying rejection or thrown value, when one exists.
MuleToolResult
Section titled “MuleToolResult”MuleToolResult =
object
Result produced by a tool before Mule forms Pi’s correlated result message.
Properties
Section titled “Properties”content
Section titled “content”
readonlycontent: (TextContent|ImageContent)[]
details?
Section titled “details?”
readonlyoptionaldetails?:JsonValue
usage?
Section titled “usage?”
readonlyoptionalusage?:Usage
addedToolNames?
Section titled “addedToolNames?”
readonlyoptionaladdedToolNames?:string[]
isError
Section titled “isError”
readonlyisError:boolean
terminate?
Section titled “terminate?”
readonlyoptionalterminate?:boolean
MuleToolExecutionPart
Section titled “MuleToolExecutionPart”MuleToolExecutionPart = {
type:"update";result:MuleToolResult; } | {type:"result";result:MuleToolResult; }
Progress or terminal output from one tool execution.
MuleToolRejection
Section titled “MuleToolRejection”MuleToolRejection =
object
A real parser or authorization rejection produced before tool execution.
Properties
Section titled “Properties”message
Section titled “message”
readonlymessage:string
terminate?
Section titled “terminate?”
readonlyoptionalterminate?:boolean
MuleCompletedTurn
Section titled “MuleCompletedTurn”MuleCompletedTurn =
object
Facts from a completed Pi turn supplied to the retained stop hook.
Properties
Section titled “Properties”message
Section titled “message”
readonlymessage:AssistantMessage
toolResults
Section titled “toolResults”
readonlytoolResults: readonlyToolResultMessage[]
context
Section titled “context”
readonlycontext: readonlyMessage[]
newMessages
Section titled “newMessages”
readonlynewMessages: readonlyMessage[]
MuleEvent
Section titled “MuleEvent”MuleEvent = {
type:"run_start";run:MuleIdentity; } | {type:"turn_start";run:MuleIdentity;turn:MuleIdentity; } | {type:"message_start";run:MuleIdentity;turn:MuleIdentity;message:MuleIdentity;value:Message; } | {type:"message_update";run:MuleIdentity;turn:MuleIdentity;message:MuleIdentity;value:AssistantMessage;event:AssistantMessageEvent; } | {type:"message_end";run:MuleIdentity;turn:MuleIdentity;message:MuleIdentity;value:Message; } | {type:"tool_execution_start";run:MuleIdentity;turn:MuleIdentity;toolCall:MuleIdentity;call:ToolCall; } | {type:"tool_execution_update";run:MuleIdentity;turn:MuleIdentity;toolCall:MuleIdentity;call:ToolCall;result:MuleToolResult; } | {type:"tool_execution_end";run:MuleIdentity;turn:MuleIdentity;toolCall:MuleIdentity;call:ToolCall;result:MuleToolResult; } | {type:"turn_end";run:MuleIdentity;turn:MuleIdentity;message:AssistantMessage;toolResults: readonlyToolResultMessage[]; } | {type:"run_end";run:MuleIdentity;terminal:MuleIdentity;outcome:"completed"|"cancelled"|"failed"; }
Lifecycle emitted around Pi values. Pi messages and events are not rewritten.
Union Members
Section titled “Union Members”Type Literal
Section titled “Type Literal”{ type: "run_start"; run: MuleIdentity; }
Type Literal
Section titled “Type Literal”{ type: "turn_start"; run: MuleIdentity; turn:
MuleIdentity; }
Type Literal
Section titled “Type Literal”{ type: "message_start"; run: MuleIdentity; turn:
MuleIdentity; message: MuleIdentity;
value: Message; }
Type Literal
Section titled “Type Literal”{ type: "message_update"; run: MuleIdentity; turn:
MuleIdentity; message: MuleIdentity;
value: AssistantMessage; event: AssistantMessageEvent; }
Type Literal
Section titled “Type Literal”{ type: "message_end"; run: MuleIdentity; turn:
MuleIdentity; message: MuleIdentity;
value: Message; }
Type Literal
Section titled “Type Literal”{ type: "tool_execution_start"; run: MuleIdentity;
turn: MuleIdentity; toolCall:
MuleIdentity; call: ToolCall; }
Type Literal
Section titled “Type Literal”{ type: "tool_execution_update"; run: MuleIdentity;
turn: MuleIdentity; toolCall:
MuleIdentity; call: ToolCall; result:
MuleToolResult; }
Type Literal
Section titled “Type Literal”{ type: "tool_execution_end"; run: MuleIdentity;
turn: MuleIdentity; toolCall:
MuleIdentity; call: ToolCall; result:
MuleToolResult; }
Type Literal
Section titled “Type Literal”{ type: "turn_end"; run: MuleIdentity; turn:
MuleIdentity; message: AssistantMessage; toolResults:
readonly ToolResultMessage[]; }
Type Literal
Section titled “Type Literal”{ type: "run_end"; run: MuleIdentity; terminal:
MuleIdentity; outcome: "completed" | "cancelled" |
"failed"; }
readonlytype:"run_end"
The run’s one terminal. A run interrupted after run_start ends cancelled; a
run that fails with a non-listener MuleError ends failed. A listener failure
ends the run without this event.
readonlyrun:MuleIdentity
terminal
Section titled “terminal”
readonlyterminal:MuleIdentity
outcome
Section titled “outcome”
readonlyoutcome:"completed"|"cancelled"|"failed"
MuleRunSettings
Section titled “MuleRunSettings”MuleRunSettings =
object
Run inputs that are identical on the Promise and Effect roots.
Properties
Section titled “Properties”
readonlymodel:Model<Api>>
stream?
Section titled “stream?”
readonlyoptionalstream?:MuleStreamFunction
Override Pi’s default streamSimple, primarily for explicit providers and
tests.
systemPrompt
Section titled “systemPrompt”
readonlysystemPrompt:string
messages
Section titled “messages”
readonlymessages: readonlyMessage[]
streamOptions?
Section titled “streamOptions?”
readonlyoptionalstreamOptions?:Omit<SimpleStreamOptions,"signal">>
Pi stream options. Cancellation is the run’s interruption, never a signal here.
toolExecution?
Section titled “toolExecution?”
readonlyoptionaltoolExecution?:"parallel"|"sequential"
MuleRunOutcome
Section titled “MuleRunOutcome”MuleRunOutcome =
object
Honest terminal result of one Mule invocation.
Properties
Section titled “Properties”status
Section titled “status”
readonlystatus:"completed"|"cancelled"|"failed"
readonlyrun:MuleIdentity
terminal
Section titled “terminal”
readonlyterminal:MuleIdentity
message
Section titled “message”
readonlymessage:AssistantMessage
messages
Section titled “messages”
readonlymessages: readonlyMessage[]
MulePromiseListener
Section titled “MulePromiseListener”MulePromiseListener = (
event,signal) =>Promise<void> > |void
Promise listener adapted once into Mule’s canonical Effect program.
Parameters
Section titled “Parameters”signal
Section titled “signal”AbortSignal
Returns
Section titled “Returns”Promise<void> | void
MuleToolPreparation
Section titled “MuleToolPreparation”MuleToolPreparation = {
status:"prepared";execute: (signal) =>AsyncIterable<MuleToolExecutionPart>>; } |object&MuleToolRejection
Outcome of preparing one exact Pi tool call.
Union Members
Section titled “Union Members”Type Literal
Section titled “Type Literal”{ status: "prepared"; execute: (signal) =>
AsyncIterable<MuleToolExecutionPart>; }
status
Section titled “status”
readonlystatus:"prepared"
execute
Section titled “execute”
readonlyexecute: (signal) =>AsyncIterable<MuleToolExecutionPart>>
Run the already-decoded and authorized call; abort ends it early.
Parameters
Section titled “Parameters”signal
Section titled “signal”AbortSignal
Returns
Section titled “Returns”AsyncIterable<MuleToolExecutionPart>
object & MuleToolRejection
MuleTool
Section titled “MuleTool”MuleTool =
object
Pi tool declaration paired with its Promise preparation door.
Properties
Section titled “Properties”descriptor
Section titled “descriptor”
readonlydescriptor:Tool
executionMode?
Section titled “executionMode?”
readonlyoptionalexecutionMode?:"parallel"|"sequential"
prepare
Section titled “prepare”
readonlyprepare: (call,signal) =>Promise<MuleToolPreparation>>
Decode and authorize one exact Pi tool call before it can execute.
Parameters
Section titled “Parameters”ToolCall
signal
Section titled “signal”AbortSignal
Returns
Section titled “Returns”Promise<MuleToolPreparation>
MuleRunInput
Section titled “MuleRunInput”MuleRunInput =
MuleRunSettings&object
Inputs for one complete Pi model/tool loop through the Promise facade.
Type Declaration
Section titled “Type Declaration”tools?
Section titled “tools?”
readonlyoptionaltools?: readonlyMuleTool[]
resolveApiKey?
Section titled “resolveApiKey?”
readonlyoptionalresolveApiKey?: (provider,signal) =>Promise<string|undefined>>
Resolve a fresh provider credential immediately before each Pi call.
Parameters
Section titled “Parameters”provider
Section titled “provider”string
signal
Section titled “signal”AbortSignal
Returns
Section titled “Returns”Promise<string | undefined>
getSteeringMessages?
Section titled “getSteeringMessages?”
readonlyoptionalgetSteeringMessages?: (signal) =>Promise<readonlyMessage[]>
Pull messages that should steer the active run at Pi’s safe point.
Parameters
Section titled “Parameters”signal
Section titled “signal”AbortSignal
Returns
Section titled “Returns”Promise<readonly Message[]>
getFollowUpMessages?
Section titled “getFollowUpMessages?”
readonlyoptionalgetFollowUpMessages?: (signal) =>Promise<readonlyMessage[]>
Pull messages queued until the run would otherwise finish.
Parameters
Section titled “Parameters”signal
Section titled “signal”AbortSignal
Returns
Section titled “Returns”Promise<readonly Message[]>
shouldStopAfterTurn?
Section titled “shouldStopAfterTurn?”
readonlyoptionalshouldStopAfterTurn?: (turn,signal) =>Promise<boolean>>
Request a graceful stop after the current Pi turn has fully settled.
Parameters
Section titled “Parameters”signal
Section titled “signal”AbortSignal
Returns
Section titled “Returns”Promise<boolean>
Mule =
object
Promise-facing Mule interface.
Properties
Section titled “Properties”
readonlyrun: (input,listener?,signal?) =>Promise<MuleRunOutcome>>
Run one complete Pi model/tool loop. Rejects with the MuleError that failed
the run, or with the abort reason (an AbortError when the reason is not an
Error) after the caller aborts signal.
Parameters
Section titled “Parameters”listener?
Section titled “listener?”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”Promise<MuleRunOutcome>
Variables
Section titled “Variables”
constmule:Mule
Default Promise-facing Mule interface.