Documentation
¶
Overview ¶
Package hooks is the host of the agent's lifecycle hook points: the points defined once, the callbacks plugins and the user's shell hooks set on them, and how a firing runs them, in order, each bounded by its time limit, the policy of its point deciding what a failure means
Index ¶
- Constants
- func Answers(point string) []string
- func BoardTaskOf(ctx context.Context) string
- func CallOf(ctx context.Context) string
- func Chars(list []*sessionsv1.Message) int
- func Example(point string) (map[string]any, bool)
- func Fields(event Event) []string
- func Messages(list []*sessionsv1.Message) []map[string]any
- func Optional(text string) *string
- func Parameters(request *provider.Request) map[string]any
- func Payload(event Event) map[string]any
- func Points() []string
- func RequestView(cfg *config.Config, request *provider.Request) any
- func ResponseView(cfg *config.Config, model string, response *provider.Response) any
- func Sanitize(cfg *config.Config, value any) any
- func Spill(cfg *config.Config, text, session, source string) string
- func StopReason(cause string) string
- func System(list []*sessionsv1.Message) string
- func WithBoardTask(ctx context.Context, task string) context.Context
- func WithCall(ctx context.Context, id string) context.Context
- func WithTurn(ctx context.Context, turn Turn) context.Context
- type APIError
- type APIRequest
- type APIResponse
- type Admitted
- type Answered
- type Approval
- type Approved
- type Arriving
- type Ask
- type AuxRequest
- type AuxResponse
- type Auxiliary
- type Benched
- type Board
- type BoardDispatched
- type BoardTaskBlocked
- type BoardTaskClaimed
- type BoardTaskCompleted
- type BoardTaskUpdated
- type BoardWorkerExited
- type BoardWorkerSpawned
- type BoardWorkerStale
- type Call
- type ChatSource
- type Classification
- type Classify
- type Command
- type Compacted
- type Consenter
- type Consumed
- type Cost
- type Deleted
- type Delta
- type Directive
- type Dispatched
- type Ended
- type Event
- type Failure
- type Finalized
- type Firer
- type GatewayStarted
- type Hook
- type Hooks
- func (h *Hooks) Accept(ctx context.Context, cfg *config.Config) error
- func (h *Hooks) Classify(ctx context.Context, cfg *config.Config, failure Classify, ...) *Classification
- func (h *Hooks) Close() error
- func (h *Hooks) Finalize(ctx context.Context, cfg *config.Config, finalized Finalized) []string
- func (h *Hooks) Fire(ctx context.Context, cfg *config.Config, event Event) []Result
- func (h *Hooks) Fired(point string) []Site
- func (h *Hooks) Has(cfg *config.Config, point string) bool
- func (h *Hooks) Holds(cfg *config.Config) bool
- func (h *Hooks) PostAdmission(ctx context.Context, cfg *config.Config, message Admitted) Consumed
- func (h *Hooks) PreCommand(ctx context.Context, cfg *config.Config, command Command) Verdict
- func (h *Hooks) PreDispatch(ctx context.Context, cfg *config.Config, message Arriving) Dispatched
- func (h *Hooks) PreLLMCall(ctx context.Context, cfg *config.Config, prompt Prompt) (string, string)
- func (h *Hooks) PreToolCall(ctx context.Context, cfg *config.Config, call ToolCall) Directive
- func (h *Hooks) PreVerify(ctx context.Context, cfg *config.Config, verify Verify) string
- func (h *Hooks) Register(registrant Registrant)
- func (h *Hooks) Stream(ctx context.Context, cfg *config.Config, event Event) bool
- func (h *Hooks) StreamsReasoning(cfg *config.Config) bool
- func (h *Hooks) Transcribe(ctx context.Context, cfg *config.Config, audio Transcription) (model, language, prompt string)
- func (h *Hooks) TransformReply(ctx context.Context, cfg *config.Config, reply Reply, held bool) (string, bool)
- func (h *Hooks) TransformResult(ctx context.Context, cfg *config.Config, result ToolResult) (string, bool)
- func (h *Hooks) TransformTerminal(ctx context.Context, cfg *config.Config, output TerminalOutput) string
- type HumanAnswered
- type HumanInput
- type Interim
- type JobIncident
- type Login
- type LoopStopped
- type Outcome
- type Panic
- type PlatformEvent
- type Point
- type Prompt
- type Registrant
- type Registry
- type Reply
- type Request
- type Reset
- type Result
- type RoomActivity
- type SessionMoved
- type SessionStarted
- type Site
- type Sites
- type Skill
- type Started
- type Step
- type Stream
- type SubagentProgressed
- type SubagentStarted
- type SubagentStopped
- type TerminalOutput
- type ToolCall
- type ToolDone
- type ToolResult
- type Transcription
- type Turn
- type TurnEnded
- type Usage
- type Verdict
- type Verify
Constants ¶
const ( Skip = "skip" Allow = "allow" )
Answers a hook of a message of a chat app gives beside Rewrite and Handled: the message is dropped, or let on as it is
const ( // The app and the command line SurfaceApp = "cli" // A chat of a chat app SurfaceChats = "gateway" )
Where a slash command was typed, as pre_command names it
const ( PreToolCall = "pre_tool_call" PostToolCall = "post_tool_call" TransformTerminalOutput = "transform_terminal_output" TransformToolResult = "transform_tool_result" TransformLLMOutput = "transform_llm_output" PreLLMCall = "pre_llm_call" PostLLMCall = "post_llm_call" StreamStart = "on_stream_start" StreamDelta = "on_stream_delta" StreamEnd = "on_stream_end" InterimMessage = "on_interim_message" PreVerify = "pre_verify" PreAPIRequest = "pre_api_request" PostAPIRequest = "post_api_request" APIRequestError = "api_request_error" PreAuxiliaryCall = "pre_auxiliary_call" PostAuxiliaryCall = "post_auxiliary_call" TransformAPIErrorClassification = "transform_api_error_classification" SessionStart = "on_session_start" SessionEnd = "on_session_end" SessionFinalize = "on_session_finalize" SessionReset = "on_session_reset" SessionMove = "on_session_move" SessionDelete = "on_session_delete" SkillLifecycle = "on_skill_lifecycle" SubagentStart = "subagent_start" SubagentProgress = "subagent_progress" SubagentStop = "subagent_stop" PreGatewayDispatch = "pre_gateway_dispatch" PostGatewayAdmission = "post_gateway_admission" AgentLoopStopped = "agent_loop_stopped" PreApprovalRequest = "pre_approval_request" PostApprovalResponse = "post_approval_response" HumanInputRequest = "on_human_input_request" HumanInputResolved = "on_human_input_resolved" RoomMemberActivity = "on_room_member_activity" PreTranscription = "pre_transcription" KanbanTaskClaimed = "kanban_task_claimed" KanbanTaskCompleted = "kanban_task_completed" KanbanTaskBlocked = "kanban_task_blocked" KanbanWorkerSpawned = "on_kanban_worker_spawned" KanbanWorkerExited = "on_kanban_worker_exited" KanbanWorkerStaleClaim = "on_kanban_worker_stale_claim" KanbanTaskUpdated = "on_kanban_task_updated" KanbanDispatchTick = "on_kanban_dispatch_tick" GatewayPlatformEvent = "gateway_platform_event" GatewayStartup = "on_gateway_startup" PreCommand = "pre_command" PostCompaction = "post_compaction" LoginExhausted = "on_login_exhausted" CronIncident = "on_cron_incident" )
Hook points, by the names hooks are set on
const ( Block = "block" Modify = "modify" Approve = "approve" Continue = "continue" Handled = "handled" Rewrite = "rewrite" )
Directives a callback answers with; a pre_command callback may also answer that it handled the command itself, or turn it into another
const ( // A person stopped it: /stop, the stop key of a window, the stop of a chat app or of an editor StopAsked = "stop_command" // A message sent while it ran stopped it to be answered next, as the session's settings have a message do StopInterrupted = "interrupt_message" // The window or the chat left the session for a new one StopNewSession = "new_command" // The session was closed while it ran StopClosed = "session_closed" // icebath was paused, which stops every reply StopPaused = "pause" // icebath stopped StopShutdown = "shutdown" // The run that asked for the reply was cancelled, such as a scheduled job removed or one past the time it may take StopRunCancelled = "run_cancelled" // It asked for an approval or an answer in a run nobody watches StopUnattended = "unattended" // It was cancelled by what started it, for no cause it named StopCancelled = "cancelled" )
Why a reply was stopped from outside before it ended, as agent_loop_stopped names it in invalidation_reason
const Schema = "icebath.observer.v1"
Schema of the payloads observers read, which every firing but a gateway platform event names
Variables ¶
This section is empty.
Functions ¶
func Answers ¶
What a hook's answer may do at the point, each a line a person reads with the JSON a command prints for it; none for a point that only tells of what happened
func BoardTaskOf ¶
Board task the context carries, empty outside a worker's turns
func Chars ¶
func Chars(list []*sessionsv1.Message) int
Characters of the text of the messages, which a rough count of their tokens divides by four
func Example ¶
The payload a hook of the point receives, as plain JSON data made from the example of its event, every field the event has with a value of the kind it holds; false for a name that is no point
func Messages ¶
func Messages(list []*sessionsv1.Message) []map[string]any
Messages of a conversation as hooks read them: role, content, the tool calls an answer made and the call a result is of
func Parameters ¶
What a request asks the model with as hooks read it: the most tokens, the temperature, the reasoning effort, the shape of the reply and the tools offered as it sets them, and the fields it puts at the top of its body, those that name a credential left out
func Payload ¶
Event as plain JSON data, the way a hook outside icebath reads it: its fields by name, with the version of the observer schema every event but a gateway platform event names; nil for an event that cannot be written
func RequestView ¶
The request as hooks are handed it: the body sent, secrets masked and cut to hooks.payload_max_chars
func ResponseView ¶
The reply as hooks are handed it: the model, why it stopped, the assistant's message and the tokens, secrets masked and cut to hooks.payload_max_chars
func Sanitize ¶
View of a request or response as hooks are handed it: plain JSON data, credentials masked, texts, lists and nesting bounded, tighter bounds tried when it runs past hooks.payload_max_chars and a preview of it past that
func Spill ¶
Text a hook hands the turn, saved to a file of the session's under the hook output folder when it is longer than the profile allows and a preview naming the file kept in its place: so many characters of its start and end, source naming what gave it
func StopReason ¶
Why a reply stopped, in words, for the cause it stopped for; the cause itself for one icebath does not know
func System ¶
func System(list []*sessionsv1.Message) string
Text of the first system message, empty when there is none
func WithBoardTask ¶
Context carrying the board task a worker works on, which every firing inside its turns names
Types ¶
type APIError ¶
type APIError struct {
Request
Duration float64 `json:"api_duration"`
Finished float64 `json:"ended_at"`
Status *int `json:"status_code"`
Retries int `json:"retry_count"`
// Retries the request may take, whether this failure is one to retry, and why it failed as the agent reads it
MaxRetries int `json:"max_retries"`
Retryable bool `json:"retryable"`
Reason *string `json:"reason"`
Error Failure `json:"error"`
Body any `json:"request"`
}
A model request that failed
type APIRequest ¶
type APIRequest struct {
Request
Message string `json:"user_message"`
History []map[string]any `json:"conversation_history"`
Retries int `json:"retry_count"`
Messages []map[string]any `json:"request_messages"`
System string `json:"system_prompt"`
// Messages, tools, rough tokens and characters of the request
MessageCount int `json:"message_count"`
ToolCount int `json:"tool_count"`
Tokens int `json:"approx_input_tokens"`
Chars int `json:"request_char_count"`
// Most tokens the reply may take, nil for the provider's limit
MaxTokens *int `json:"max_tokens"`
Trace []any `json:"middleware_trace"`
// The request as it is sent, secrets masked and cut to hooks.payload_max_chars
Body any `json:"request"`
// What the request asks the model with as it sets them, such as temperature, max_tokens, reasoning_effort and response_format, and the
// fields it puts at the top of the body
Parameters map[string]any `json:"model_parameters"`
// The messages as they are sent, the images and videos they carry among them, for the callbacks of this process alone
Sent []*sessionsv1.Message `json:"-"`
}
A model request about to be sent
func (APIRequest) Point ¶
func (APIRequest) Point() string
type APIResponse ¶
type APIResponse struct {
Request
// Seconds it took, and when it ended and its first piece came, in seconds since the epoch
Duration float64 `json:"api_duration"`
Finished float64 `json:"ended_at"`
FirstAt *float64 `json:"first_chunk_at"`
Finish *string `json:"finish_reason"`
Messages int `json:"message_count"`
Answering string `json:"response_model"`
// The reply as it came, secrets masked and cut to hooks.payload_max_chars
Body any `json:"response"`
Usage *Usage `json:"usage"`
// Tokens the model takes in at once, nil when not known
Window *int `json:"context_length"`
Assistant map[string]any `json:"assistant_message"`
Chars int `json:"assistant_content_chars"`
ToolCalls int `json:"assistant_tool_call_count"`
// What the reference models of a mixture of agents answered, nil for a request of one model
References any `json:"moa_references"`
// What the call cost by the prices of the model that answered it, nil when the provider said nothing of the tokens it took
Cost *Cost `json:"cost"`
}
A model request that was answered
func (APIResponse) Point ¶
func (APIResponse) Point() string
type Admitted ¶
type Admitted struct {
// Key of the chat and the session it talks to
SessionKey string `json:"session_key"`
Session string `json:"session_id"`
Platform string `json:"platform"`
Message string `json:"message_id"`
Text string `json:"text"`
Source ChatSource `json:"source"`
}
A message of a chat app let in, about to start a reply of the session its chat talks to, which a hook may take over
type Answered ¶
type Answered struct {
Session string `json:"session_id"`
Task string `json:"task_id"`
Turn string `json:"turn_id"`
Message string `json:"user_message"`
Response string `json:"assistant_response"`
History []map[string]any `json:"conversation_history"`
Model string `json:"model"`
// Provider the model that answered last is of
Provider string `json:"provider"`
Platform string `json:"platform"`
// Lease a consented user plugin redeems to ask a side question of the turn, nil while no such plugin is loaded
Token *string `json:"side_question_token"`
}
A turn that answered
type Approval ¶
type Approval struct {
Command string `json:"command"`
Description string `json:"description"`
Key string `json:"pattern_key"`
Keys []string `json:"pattern_keys"`
SessionKey string `json:"session_key"`
// Where it is asked: the chat, smart for the helper model's review, transport:<name> for an approval transport
Surface string `json:"surface"`
// Request a transport is handed and its digest, for an approval through one
RequestID string `json:"request_id,omitempty"`
Digest string `json:"request_digest,omitempty"`
// It waits on an identical prompt already asked
Coalesced bool `json:"coalesced,omitempty"`
Session string `json:"session_id"`
Turn string `json:"turn_id"`
Call string `json:"tool_call_id"`
}
An approval about to be asked
type Approved ¶
type Approved struct {
Approval
// once, session, always, deny, timeout, cancelled, smart_approve, smart_deny or transport_<failure>
Choice string `json:"choice"`
Cancelled string `json:"cancelled,omitempty"`
// Who decided it when the user did not, aux_llm for the smart reviewer and transport:<name> for a transport in place of the chat
DecidedBy string `json:"decided_by,omitempty"`
// Who answered through a transport, the transport and the person it says answered; empty for the person in the chat or the app
By string `json:"answered_by,omitempty"`
}
An approval that was answered, refused or not answered in time
type Arriving ¶
type Arriving struct {
Platform string `json:"platform"`
Profile string `json:"profile_name"`
Text string `json:"text"`
Message string `json:"message_id"`
// text, command or voice, as what it carries says
Kind string `json:"message_type"`
// Kinds of the files it carries, such as image or voice, in their order
Media []string `json:"media_types"`
// Message it answers and what that said, empty for none
ReplyTo string `json:"reply_to_message_id,omitempty"`
ReplyText string `json:"reply_to_text,omitempty"`
// It names the bot or answers one of its messages
Mentioned bool `json:"mentioned"`
Source ChatSource `json:"source"`
}
A message of a chat app about to be handled, before who wrote it is let in, which a hook may drop or reword
type Ask ¶
Approval a hook asks for: what the user is told, and the name the answer is remembered under, the tool's name when empty
type AuxRequest ¶
type AuxRequest struct {
Auxiliary
Sent []map[string]any `json:"request_messages"`
System string `json:"system_prompt"`
Tools int `json:"tool_count"`
Tokens int `json:"approx_input_tokens"`
Chars int `json:"request_char_count"`
MaxTokens *int `json:"max_tokens"`
Body any `json:"request"`
}
A helper model's request about to be sent
func (AuxRequest) Point ¶
func (AuxRequest) Point() string
type AuxResponse ¶
type AuxResponse struct {
Auxiliary
Finished float64 `json:"ended_at"`
Duration float64 `json:"api_duration"`
// What failed, kind and message, and its kind; nil for an answer
Error *string `json:"error"`
ErrorType *string `json:"error_type"`
Finish *string `json:"finish_reason"`
Answering *string `json:"response_model"`
Usage *Usage `json:"usage"`
Body any `json:"response"`
Chars int `json:"assistant_content_chars"`
ToolCalls int `json:"assistant_tool_call_count"`
// What the call cost by the prices of the model that answered it, nil for a failure or a reply that told no tokens
Cost *Cost `json:"cost"`
}
A helper model's request that was answered or failed
func (AuxResponse) Point ¶
func (AuxResponse) Point() string
type Auxiliary ¶
type Auxiliary struct {
Session string `json:"session_id"`
Task string `json:"task_id"`
Turn string `json:"turn_id"`
Platform string `json:"platform"`
// Task of the helper model, such as title_generation
Job string `json:"aux_task"`
ID string `json:"api_request_id"`
Retries int `json:"retry_count"`
Count int `json:"api_call_count"`
Model string `json:"model"`
Provider string `json:"provider"`
// Address of the provider as the settings it was read from write it, every ${NAME} kept
BaseURL string `json:"base_url"`
Mode string `json:"api_mode"`
Streamed bool `json:"streaming"`
Started float64 `json:"started_at"`
Messages int `json:"message_count"`
}
A request of a helper model's task, one per attempt of a route
type Benched ¶
type Benched struct {
Provider string `json:"provider"`
Login Login `json:"login"`
Resets *int64 `json:"resets_at"`
Reason string `json:"reason"`
Ready []Login `json:"ready"`
}
An account of a provider benched as it reached a limit or its sign-in was refused: the provider, the account, when the limit lifts as the provider said (seconds since the epoch, nil when it said nothing), why, and the other accounts of the provider ready to take its place
type Board ¶
type Board struct {
Board string `json:"board"`
Task string `json:"task_id"`
Profile string `json:"profile_name"`
}
Board and task a firing of the shared task board is about, and the profile whose hooks run it
type BoardDispatched ¶
type BoardDispatched struct {
Board string `json:"board"`
Profile string `json:"profile_name"`
DryRun bool `json:"dry_run"`
Outcome string `json:"outcome"`
Result map[string]any `json:"result"`
}
A pass of the board's dispatcher, and what it did
func (BoardDispatched) Point ¶
func (BoardDispatched) Point() string
type BoardTaskBlocked ¶
type BoardTaskBlocked struct {
Board
Assignee string `json:"assignee"`
Run int64 `json:"run_id"`
Reason string `json:"reason"`
}
A task of the board blocked
func (BoardTaskBlocked) Point ¶
func (BoardTaskBlocked) Point() string
type BoardTaskClaimed ¶
A task of the board taken by a worker
func (BoardTaskClaimed) Point ¶
func (BoardTaskClaimed) Point() string
type BoardTaskCompleted ¶
type BoardTaskCompleted struct {
Board
Assignee string `json:"assignee"`
Run int64 `json:"run_id"`
Summary string `json:"summary"`
}
A task of the board marked done
func (BoardTaskCompleted) Point ¶
func (BoardTaskCompleted) Point() string
type BoardTaskUpdated ¶
type BoardTaskUpdated struct {
Board
Assignee string `json:"assignee"`
Run int64 `json:"run_id"`
Changed []string `json:"changed_fields"`
}
A task of the board changed: given to another profile, held to another model, or edited
func (BoardTaskUpdated) Point ¶
func (BoardTaskUpdated) Point() string
type BoardWorkerExited ¶
type BoardWorkerExited struct {
Board
Assignee string `json:"assignee"`
Run int64 `json:"run_id"`
Session string `json:"session_id"`
Kind string `json:"exit_kind"`
Outcome string `json:"outcome"`
Retry string `json:"retry_status"`
}
A worker of the board that ended without handing its task back, and what became of the task
func (BoardWorkerExited) Point ¶
func (BoardWorkerExited) Point() string
type BoardWorkerSpawned ¶
type BoardWorkerSpawned struct {
Board
Assignee string `json:"assignee"`
Run int64 `json:"run_id"`
Session string `json:"session_id"`
Workspace string `json:"workspace_path"`
}
A worker of the board started on a task, in its session and workspace
func (BoardWorkerSpawned) Point ¶
func (BoardWorkerSpawned) Point() string
type BoardWorkerStale ¶
type BoardWorkerStale struct {
Board
Assignee string `json:"assignee"`
Run int64 `json:"run_id"`
Session string `json:"session_id"`
Stale bool `json:"heartbeat_stale"`
Retry string `json:"retry_status"`
}
A task of the board whose worker went away or stopped making progress, put back to be started again
func (BoardWorkerStale) Point ¶
func (BoardWorkerStale) Point() string
type Call ¶
type Call struct {
Tool string `json:"tool_name"`
Args map[string]any `json:"args"`
Task string `json:"task_id"`
Session string `json:"session_id"`
ID string `json:"tool_call_id"`
Turn string `json:"turn_id"`
Request string `json:"api_request_id"`
}
Tool call a point fires for
type ChatSource ¶
type ChatSource struct {
Platform string `json:"platform"`
Chat string `json:"chat_id"`
ChatName string `json:"chat_name"`
// dm, group or channel
ChatType string `json:"chat_type"`
User string `json:"user_id"`
UserName string `json:"user_name"`
// Thread or topic inside the chat and what it is called, empty outside one
Thread string `json:"thread_id"`
Topic string `json:"chat_topic"`
// Server or workspace the chat lies in, empty on an app with none
Scope string `json:"scope_id,omitempty"`
// Profile that answers the chat
Profile string `json:"profile"`
// The writer is another bot
Bot bool `json:"is_bot,omitempty"`
}
The chat a message of a chat app came from and who wrote it there, by the names of the source of a session
type Classification ¶
type Classification struct {
// Why it failed, one of the reasons the agent knows
Reason string
// What the agent does about it, each nil to leave it to the agent
Retryable, Compress, Rotate, Fallback *bool
// What the user is told, at most 500 characters
Message string
Context map[string]any
}
How a plugin classified a failed request
type Classify ¶
type Classify struct {
Provider string `json:"provider"`
Model string `json:"model"`
Status *int `json:"status_code"`
Type string `json:"error_type"`
Code string `json:"error_code"`
Message string `json:"error_message"`
Body map[string]any `json:"error_body"`
Error string `json:"error"`
Tokens int `json:"approx_tokens"`
Window int `json:"context_length"`
Count int `json:"num_messages"`
}
A failed model request, which a plugin may classify in place of the agent
type Command ¶
type Command struct {
// Where it was typed: cli for the app and the command line, gateway for a chat of a chat app
Surface string `json:"surface"`
Name string `json:"command"`
// Name it was typed as
Alias string `json:"alias_used"`
Args string `json:"args_raw"`
SessionKey *string `json:"session_key"`
Platform *string `json:"platform"`
}
A slash command about to run
type Compacted ¶
type Compacted struct {
Session string `json:"session_id"`
// Session it came from when the conversation went on in a new one, empty when it did not
Old string `json:"old_session_id"`
// summarize, micro_summarize, prune_tool_results or provider_native
Kind string `json:"kind"`
Reason string `json:"reason"`
Before *int `json:"before_tokens"`
After *int `json:"after_tokens"`
// Messages it folded away
Removed *int `json:"messages_removed"`
// Summaries the session's context took so far, this one counted; nil for a compaction that is no summary
Count *int `json:"compression_count"`
}
A compaction of a session's context that was stored
type Consenter ¶
Registrant whose hooks need the user's consent before they run, such as the user's shell hooks: given it for every hook the profile's settings set, as a launch with --accept-hooks gives it
type Consumed ¶
type Consumed struct {
// A hook handled the message itself, so no reply of the session starts
Handled bool
// What the chat is told in its place, empty for nothing
Reply string
}
What the post_gateway_admission hooks made of a message
type Cost ¶
type Cost struct {
// USD of the whole call, nil when its price is not known
Total *float64 `json:"total_usd"`
// USD of each part the price prices: input, output, cache_read, cache_write and request
Parts map[string]float64 `json:"parts,omitempty"`
// estimated, included or unknown, and where the price came from
Status string `json:"status"`
Source string `json:"source"`
}
What a model call cost by the prices of its model
type Deleted ¶
type Deleted struct {
Session string `json:"session_id"`
// delete, prune, archive or empty_sweep
Reason string `json:"reason"`
Profile *string `json:"profile"`
// Every session it took out, when more than one
IDs []string `json:"deleted_ids,omitempty"`
}
Sessions taken out of the store
type Delta ¶
type Delta struct {
Stream
Text string `json:"delta"`
// text or reasoning
Kind string `json:"kind"`
}
A piece of a streaming reply: its text, or its reasoning when hooks.stream_reasoning lets hooks see it
type Directive ¶
type Directive struct {
// Why a hook blocked it, empty when none did
Block string
// Approval of the user a hook asks for before it runs, nil when none does
Approve *Ask
// Arguments the hooks rewrote it to, nil when none did
Args map[string]any
}
What the pre_tool_call hooks made of a call
type Dispatched ¶
type Dispatched struct {
// The message is dropped, and why the hook said it was
Skip bool
Reason string
// Text the message is reworded to, Rewritten saying a hook did
Text string
Rewritten bool
}
What the pre_gateway_dispatch hooks made of a message
type Ended ¶
type Ended struct {
Stream
Text string `json:"final_text"`
Finished bool `json:"finished"`
// Why it ended early, nil when it did not
Error *string `json:"error"`
}
A reply that ended streaming
type Event ¶
type Event interface {
// Name of the point it fires
Point() string
}
What hooks a firing hands to its point's callbacks, one of the payload types of this package
type Finalized ¶
type Finalized struct {
Session string `json:"session_id"`
Platform string `json:"platform"`
// Why it closed: shutdown, new_session, or as the session store ends it
Reason string `json:"reason"`
// For a session a window left for a new one, the two of them
Old *string `json:"old_session_id,omitempty"`
New *string `json:"new_session_id,omitempty"`
}
A session closed for good, whose hooks may have something to tell the user
type Firer ¶
type Firer interface {
Fires() []Site
}
Registrant of a feature that fires points: the moments of its own it tells the hooks of, which the hooks screen and Doctor read, so a hook set on a point nothing in this build fires is said never to run
type GatewayStarted ¶
type GatewayStarted struct {
Platforms []string `json:"platforms"`
Profile string `json:"profile_name"`
}
The chat apps of a profile starting, as the service that keeps their connections starts: the apps the profile turned on and set up, by name, each connecting
func (GatewayStarted) Point ¶
func (GatewayStarted) Point() string
type Hook ¶
type Hook struct {
Point string
// What it is, as the log names it, such as shell_hook[pre_tool_call:./guard.sh]; one name for one callback, which its time limit and
// failures are tracked by
Name string
// Plugin that set it, as the log names it when it hangs
Owner string
// On transform_llm_output: the reply is held back from the screen while it streams, only what the hook makes of it shown
Hold bool
Run func(ctx context.Context, event Event) (*Result, error)
}
One callback set on a point
type Hooks ¶
type Hooks struct {
Registry
// contains filtered or unexported fields
}
What runs the hooks: the callbacks set on a point, their time limits and failures as they ran so far
func (*Hooks) Accept ¶
Takes consent for every hook the profile's settings set, as a launch with --accept-hooks gives it
func (*Hooks) Classify ¶
func (h *Hooks) Classify(ctx context.Context, cfg *config.Config, failure Classify, known func(reason string) bool) *Classification
Runs the transform_api_error_classification hooks: the first classification whose reason the agent knows, in registration order, its message cut to 500 characters; nil when none gave one
func (*Hooks) Close ¶
Lets every stream observer see the events it has waiting, each stopped after its last, within two seconds in all, then lets the registrants that keep work going past a firing finish it, as icebath exits
func (*Hooks) Finalize ¶
Runs the on_session_finalize hooks: what they have to tell the user, each trimmed, blank ones left out
func (*Hooks) Fire ¶
Runs every callback of the event's point in turn and gives what they answered, in order
func (*Hooks) Fired ¶
Places the point is fired from in this build, none for a point nothing here fires, so a hook set on it never runs
func (*Hooks) Has ¶
Whether a callback is set on the point for the profile, so a caller builds a costly payload only when something reads it
func (*Hooks) Holds ¶
Whether a callback rewrites the replies of the profile with the stream held back until it did
func (*Hooks) PostAdmission ¶
Runs the post_gateway_admission hooks on a message let in: the first that says it handled the message takes it over, with what the chat is told; a hook that fails or runs out of time is passed over, so the message goes on to the session
func (*Hooks) PreCommand ¶
Runs the pre_command hooks: the first, in the order they were set, that refuses the command, handles it itself or turns it into another command decides; a rewrite that names no command decides nothing
func (*Hooks) PreDispatch ¶
Runs the pre_gateway_dispatch hooks on a message: the first, in the order they were set, that drops it, rewords it or lets it on decides; a rewrite that holds no text decides nothing, and a hook that fails is passed over
func (*Hooks) PreLLMCall ¶
Runs the pre_llm_call hooks: why the first that blocked the turn did, and the context the others gave, each saved to a file and previewed when it is long, joined by blank lines
func (*Hooks) PreToolCall ¶
Runs the pre_tool_call hooks: the first block that says why wins, else the first approval asked for; the arguments every modify gives are laid over the call's in turn
func (*Hooks) PreVerify ¶
Runs the pre_verify hooks: the message of the first that keeps the turn going, empty to let it end
func (*Hooks) Register ¶
func (h *Hooks) Register(registrant Registrant)
Adds a registrant; a registry nested in the host reaches it through Host
func (*Hooks) Stream ¶
Queues the event for every callback of its point, each run on a worker of its own in the order the events came; whether one took it
func (*Hooks) StreamsReasoning ¶
Whether a reasoning piece of a reply is one for the hooks: hooks.stream_reasoning lets them see it and a callback watches the pieces
func (*Hooks) Transcribe ¶
func (h *Hooks) Transcribe(ctx context.Context, cfg *config.Config, audio Transcription) (model, language, prompt string)
Runs the pre_transcription hooks: the model, language and prompt they set, each the last hook's that set it, what none set kept; the file is never theirs to change
func (*Hooks) TransformReply ¶
func (h *Hooks) TransformReply(ctx context.Context, cfg *config.Config, reply Reply, held bool) (string, bool)
Runs the transform_llm_output hooks: the first rewrite that holds text, and whether there was one; a reply held back from the screen is withheld when every hook failed to rewrite it
func (*Hooks) TransformResult ¶
func (h *Hooks) TransformResult(ctx context.Context, cfg *config.Config, result ToolResult) (string, bool)
Runs the transform_tool_result hooks: the result the first that replaces it gives, false when none does
func (*Hooks) TransformTerminal ¶
func (h *Hooks) TransformTerminal(ctx context.Context, cfg *config.Config, output TerminalOutput) string
Runs the transform_terminal_output hooks: the output the first that replaces it gives, else the output as it was
type HumanAnswered ¶
type HumanAnswered struct {
HumanInput
Outcome string `json:"outcome"`
}
What became of asking the user
func (HumanAnswered) Point ¶
func (HumanAnswered) Point() string
type HumanInput ¶
type HumanInput struct {
// approval, clarify, sudo, or extension for questions an extension asks
Kind string `json:"kind"`
ID string `json:"request_id"`
Session string `json:"session_id"`
SessionKey string `json:"session_key"`
Platform string `json:"platform"`
// What the user is asked, secrets masked
Prompt string `json:"prompt"`
Turn string `json:"turn_id"`
Call string `json:"tool_call_id"`
}
The user asked for something, an approval, an answer or a password
func (HumanInput) Point ¶
func (HumanInput) Point() string
type Interim ¶
type Interim struct {
Stream
Text string `json:"text"`
// The user saw it stream already
Streamed bool `json:"already_streamed"`
}
Text the agent said while it went on working, such as before its tool calls
type JobIncident ¶
type JobIncident struct {
Profile string `json:"profile_name"`
Job string `json:"job_id"`
Name string `json:"job_name"`
ID string `json:"incident_id"`
// detected, alerted, resolved or closed
State string `json:"state"`
// Kind of failure: rate_limit, timeout, auth, delivery, config, script, agent or unknown
Kind string `json:"failure_type"`
// Error of its last failure, its secrets masked
Error string `json:"error"`
Failures int `json:"failures"`
First float64 `json:"first_seen_at"`
Last float64 `json:"last_seen_at"`
}
An incident of a scheduled job that keeps failing as it opens, is told, closes as a run went well, or a person acknowledges it
func (JobIncident) Point ¶
func (JobIncident) Point() string
type LoopStopped ¶
type LoopStopped struct {
// Key of the chat the session talks to, the session itself where no chat does
SessionKey string `json:"session_key"`
Session string `json:"session_id"`
Platform string `json:"platform"`
// Turn and task that were stopped, empty for a reply stopped before its turn began
Turn string `json:"turn_id"`
Task string `json:"task_id"`
// Why it stopped, in words, and as one of the causes, such as stop_command
Reason string `json:"reason"`
Invalidation string `json:"invalidation_reason"`
}
A reply of a session stopped from outside before it ended, with why; what the person sent meanwhile is answered next
func (LoopStopped) Point ¶
func (LoopStopped) Point() string
type Outcome ¶
type Outcome struct {
Call
Result string `json:"result"`
// Milliseconds it took
Duration int64 `json:"duration_ms"`
// ok, error or blocked
Status string `json:"status"`
// tool_error or plugin_block, and what went wrong; nil for a call that went well
ErrorType *string `json:"error_type"`
ErrorMessage *string `json:"error_message"`
}
What came of a tool call
type PlatformEvent ¶
type PlatformEvent struct {
Platform string `json:"platform"`
Kind string `json:"event_type"`
Payload map[string]any `json:"payload"`
}
Something a chat app tells of beside the messages people write, such as a reaction set on a message, from someone the profile lets in there: the app, what kind of thing happened, and what the app told of it
func (PlatformEvent) Point ¶
func (PlatformEvent) Point() string
type Point ¶
type Point struct {
Name string
// Callbacks are cut off past hooks.callback_timeout and left to finish on their own
Bounded bool
// A callback that fails or runs out of time blocks what the point guards
FailClosed bool
// Fired for each call of a tool, so a hook may name the tools it is for
Tool bool
// What it guards can be blocked by a hook's answer
Blocking bool
// A shell command has no way to give the answer the point takes
NoShell bool
}
How the callbacks of one point are run
type Prompt ¶
type Prompt struct {
Session string `json:"session_id"`
Task string `json:"task_id"`
Turn string `json:"turn_id"`
// What the user sent
Message string `json:"user_message"`
// The conversation, the message last
History []map[string]any `json:"conversation_history"`
First bool `json:"is_first_turn"`
Model string `json:"model"`
// Surface the session is shown on
Platform string `json:"platform"`
// Session of the agent that delegated, nil for a session of its own
Parent *string `json:"parent_session_id"`
// Who sent it on a messaging platform, nil elsewhere
Sender *string `json:"sender_id"`
// What the sender is called there, and whether the sender is another bot
SenderName string `json:"sender_name,omitempty"`
SenderBot bool `json:"sender_is_bot,omitempty"`
}
A user message about to start a turn, which a hook may refuse or give context to
type Registrant ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Accept ¶
Takes consent for every hook of the profile from every registrant that asks for it
func (*Registry) Close ¶
Lets the registrants that keep work going past a firing finish it, such as posts of events still queued, last registered first, as icebath exits
func (*Registry) Register ¶
func (r *Registry) Register(registrant Registrant)
type Reply ¶
type Reply struct {
Text string `json:"response_text"`
Session string `json:"session_id"`
Model string `json:"model"`
Platform string `json:"platform"`
Turn string `json:"turn_id"`
}
The reply a turn ends with, which a hook may rewrite
type Request ¶
type Request struct {
Task string `json:"task_id"`
Turn string `json:"turn_id"`
ID string `json:"api_request_id"`
Session string `json:"session_id"`
Platform string `json:"platform"`
Model string `json:"model"`
Provider string `json:"provider"`
// Address of the provider as the settings it was read from write it, every ${NAME} kept
BaseURL string `json:"base_url"`
Mode string `json:"api_mode"`
// Model calls of the turn, this one counted
Count int `json:"api_call_count"`
// When it was sent, in seconds since the epoch
Started float64 `json:"started_at"`
}
The model request a point fires for
type Reset ¶
type Reset struct {
Session *string `json:"session_id"`
Reason string `json:"reason"`
Platform string `json:"platform"`
Old *string `json:"old_session_id"`
New *string `json:"new_session_id"`
}
A window that left its session for a new one
type Result ¶
type Result struct {
// block, modify, approve or continue; empty for none
Action string
// Why it blocked, what approval it asks for, what the agent is sent back with, or what the user is told
Message string
// Arguments a modify puts over those of the call
Args map[string]any
// Name the answer to an approve is remembered under, the tool's name when empty
Rule string
// Text the turn's message carries to the model, for pre_llm_call
Context string
// Text in place of what a transform point was given; nil leaves it
Replace *string
// Fields a hook sets over those of the event, for the points that take them, such as the model, language and prompt of pre_transcription,
// or the command and args a rewrite of pre_command turns the command into
Set map[string]string
// How a failed request is to be treated, for transform_api_error_classification
Class *Classification
}
What a callback hands back, nil for nothing
type RoomActivity ¶
type RoomActivity struct {
Room string `json:"room_id"`
Thread string `json:"thread_id"`
Member string `json:"member_id"`
Turn string `json:"turn_id"`
Task string `json:"task_id"`
Generation int64 `json:"execution_generation"`
// tool.started, tool.progress, tool.completed, message.delta, message.interim, reasoning.delta, request.opened, turn.notice or
// turn.error
Kind string `json:"kind"`
// Count of the events of this try so far, from 1
Seq int64 `json:"seq"`
// What was said, asked or told: the text of a delta or of what the member said between its steps, what a tool was called with or
// gave back, what an approval would run or a question asks, the notice, or why the reply failed
Text string `json:"text,omitempty"`
// Tool the event is of, by its name, for the events of tools
Tool string `json:"tool,omitempty"`
}
Something a member of a room does while it answers
func (RoomActivity) Point ¶
func (RoomActivity) Point() string
type SessionMoved ¶
type SessionMoved struct {
Session string `json:"session_id"`
From string `json:"from"`
To string `json:"cwd"`
// Git branch and repository root of the folder it works in now, and the project the folder lies in, by its id and name; empty for none
Branch string `json:"git_branch,omitempty"`
Root string `json:"git_root,omitempty"`
Project string `json:"project_id,omitempty"`
Title string `json:"project,omitempty"`
}
A session that moved to work in another folder: by a person's /cd, into a project or a worktree, or at an extension's request
func (SessionMoved) Point ¶
func (SessionMoved) Point() string
type SessionStarted ¶
type SessionStarted struct {
Session string `json:"session_id"`
Model string `json:"model"`
Platform string `json:"platform"`
}
A session that starts, its prompt built for the first time
func (SessionStarted) Point ¶
func (SessionStarted) Point() string
type Site ¶
type Site struct {
Point string
// Feature that fires it, such as the chat apps or the task board
By string
// When it fires, such as "as a message of a chat app arrives, before who wrote it is let in"
When string
}
A place a point is fired from: the point, the feature whose moment it is, and that moment, as a person reads them
type Sites ¶
type Sites []Site
The moments a feature fires points at, as a registrant of their own that sets no callback
type Skill ¶
type Skill struct {
// loaded, viewed, patched, created, installed, archived and the like
Action string `json:"action"`
Name string `json:"skill_name"`
// Where it comes from: bundled, installed, agent_created, external, local or unknown
Provenance string `json:"provenance"`
Task string `json:"task_id"`
Session string `json:"session_id"`
Uses any `json:"use_count"`
Reused any `json:"reused"`
Patched any `json:"reuse_after_patch"`
}
A change of a skill's state its usage records
type Step ¶
type Step struct {
Tool string `json:"tool_name"`
// Names of its arguments and the paths and addresses it acted on
Input map[string]any `json:"tool_input"`
In int `json:"input_bytes"`
Out *int `json:"output_bytes"`
Status string `json:"status"`
}
A tool call of a subagent, as its stop tells it
type Stream ¶
type Stream struct {
Turn string `json:"turn_id"`
// Model calls of the turn so far
Iteration int `json:"iteration"`
Session string `json:"session_id"`
Model string `json:"model"`
Provider string `json:"provider"`
Surface string `json:"surface"`
}
Where a reply streams, which every stream event names
type SubagentProgressed ¶
type SubagentProgressed struct {
Parent *string `json:"parent_session_id"`
ChildSession *string `json:"child_session_id"`
ChildAgent string `json:"child_subagent_id"`
// Title of the tool, and what the call works on as the chat names it beside the title
Tool string `json:"tool_name"`
Subject string `json:"subject"`
// Tool calls it started so far
Calls int `json:"tool_calls"`
}
A subagent at work: one of its tool calls starting
func (SubagentProgressed) Point ¶
func (SubagentProgressed) Point() string
type SubagentStarted ¶
type SubagentStarted struct {
Parent *string `json:"parent_session_id"`
ParentTurn string `json:"parent_turn_id"`
ParentAgent *string `json:"parent_subagent_id"`
ChildSession *string `json:"child_session_id"`
ChildAgent string `json:"child_subagent_id"`
Role string `json:"child_role"`
Goal string `json:"child_goal"`
}
A subagent the agent delegated a task to, about to start
func (SubagentStarted) Point ¶
func (SubagentStarted) Point() string
type SubagentStopped ¶
type SubagentStopped struct {
Parent *string `json:"parent_session_id"`
ParentTurn string `json:"parent_turn_id"`
ChildSession *string `json:"child_session_id"`
ChildAgent string `json:"child_subagent_id"`
Role *string `json:"child_role"`
// Task the subagent was handed, as its start told it
Goal string `json:"child_goal"`
Summary *string `json:"child_summary"`
Status string `json:"child_status"`
Steps []Step `json:"tool_call_history"`
Duration int64 `json:"duration_ms"`
}
A subagent that finished its task: completed, or failed, timed out or stopped (interrupted), as its status says
func (SubagentStopped) Point ¶
func (SubagentStopped) Point() string
type TerminalOutput ¶
type TerminalOutput struct {
Command string `json:"command"`
Output string `json:"output"`
// Exit code, nil while a background process still runs
ReturnCode *int `json:"returncode"`
Task string `json:"task_id"`
// Backend the command ran on, empty for a background process
Backend string `json:"env_type"`
ID string `json:"tool_call_id"`
}
Output of a terminal command, which a hook may replace before it is cut to fit and the model reads it
func (TerminalOutput) Point ¶
func (TerminalOutput) Point() string
type ToolCall ¶
A tool call about to run, which a hook may block, rewrite or hold for the user's approval
type ToolResult ¶
type ToolResult struct {
Outcome
}
The result of a finished tool call, which a hook may replace before the model reads it
func (ToolResult) Point ¶
func (ToolResult) Point() string
type Transcription ¶
type Transcription struct {
File string `json:"file_path"`
Provider string `json:"provider"`
Model *string `json:"model"`
Language *string `json:"language"`
Prompt *string `json:"prompt"`
Source *string `json:"source"`
}
Audio about to be transcribed, whose model, language and prompt a hook may set
func (Transcription) Point ¶
func (Transcription) Point() string
type Turn ¶
type Turn struct {
Session string
Task string
ID string
Request string
Platform string
Cwd string
// Task of the helper model the model request is for, such as title_generation; empty for a request of the agent's own
Helper string
}
Turn a firing happens in: the session and the task it runs as, the turn and the model request it is at, the surface it is shown on and the folder it works in. The agent puts it on the context of each turn, so whatever fires inside the turn names it
type TurnEnded ¶
type TurnEnded struct {
Session string `json:"session_id"`
Task string `json:"task_id"`
Turn string `json:"turn_id"`
Completed bool `json:"completed"`
Failed bool `json:"failed"`
Interrupted bool `json:"interrupted"`
// How it ended, such as text_response(stop)
Reason string `json:"turn_exit_reason"`
Model string `json:"model"`
Platform string `json:"platform"`
}
A turn of a session that ended, however it ended
type Usage ¶
type Usage struct {
Input int64 `json:"input_tokens"`
Output int64 `json:"output_tokens"`
CacheRead int64 `json:"cache_read_tokens"`
CacheWrite int64 `json:"cache_write_tokens"`
Reasoning int64 `json:"reasoning_tokens"`
Requests int64 `json:"request_count"`
Prompt int64 `json:"prompt_tokens"`
Total int64 `json:"total_tokens"`
}
Tokens a model call took
type Verdict ¶
type Verdict struct {
// Block, Handled or Rewrite; empty to let the command run as it was typed
Action string
// What the person is told: why it was refused or what the hook did instead, empty when the hook said nothing
Message string
// Command, without its slash, and the words after it, that a rewrite turns the command into
Command, Args string
}
What the pre_command hooks made of a slash command
type Verify ¶
type Verify struct {
Session string `json:"session_id"`
Platform string `json:"platform"`
Model string `json:"model"`
// The session works on code
Coding bool `json:"coding"`
// Times hooks sent this turn back so far
Attempt int `json:"attempt"`
Final string `json:"final_response"`
// Files the turn's writes landed in
Changed []string `json:"changed_paths"`
}
A turn that changed code about to end, which a hook may send back to check its work