bothy-sdk
    Preparing search index...

    Class RunPatcher

    Collects live-box changes of one run and sends them throttled.

    Every setter only records the change and schedules a send; the throttle timer sends the pending changes as one patch once agent.run_update_min_interval passed since the last sent patch. RunPatcher.flush sends at once. After the end of the run every setter is a no-op.

    Index

    Constructors

    • Creates the patcher.

      Parameters

      • client: ApiClient

        The REST client (bound to the run by the caller, 07 SR9).

      • runId: string

        The run.

      • baseVersion: number

        The version of the Run that startRun or resumeRun answered.

      • options: RunPatcherOptions = {}

        Settings, clock and the onEnded callback.

      Returns RunPatcher

    Properties

    baseVersion: number

    The version the next patch builds on.

    client: ApiClient

    The REST client (bound to the run by the caller, 07 SR9).

    clock: Clock

    The time source of the throttle.

    ended: boolean = false

    true once the server said the run has ended; nothing is sent after that.

    patchesSent: number = 0

    The number of patches the server accepted (or the gateway took).

    runId: string

    The run.

    settings: SdkSettings

    agent.run_update_min_interval and sdk.retry_max_attempts.

    Methods

    • Stops the throttle timer without sending; a patch already on its way completes.

      Returns Promise<void>

      A promise that resolves when the timer has stopped.

    • Adds a step; its ID is a UUIDv7 of the adapter, the server assigns ordinal.

      Parameters

      • kind: string

        tool_call, subagent, background_job, workflow or status.

      • name: string

        The step name.

      • options: AddStepOptions = {}

        title, status, parentStepId and detail.

      Returns string

      The step ID.

    • Removes /metrics/last_api_retry.

      Returns void

    • Removes /plan.

      Returns void

    • Removes /status_line.

      Returns void

    • Sends the pending changes now (one patch), rebasing after a version conflict.

      A patch that finds the run ended stops the patcher and returns. After a transient refusal (5xx, 429, a conflict that outlasted the rebases) or a transport error the changes stay pending, values set meanwhile win; a permanent refusal (for example 400 validation_failed) drops the patch, so one bad value never blocks the later updates.

      Returns Promise<void>

      A promise that resolves when the patch was sent (or there was nothing to send).

      ProblemError for a refusal other than the end of the run, or the version conflict after sdk.retry_max_attempts rounds; TransportError when no answer arrived.

    • Marks a follow-up as absorbed by the runtime.

      Parameters

      • messageId: string

        The follow-up message.

      Returns void

      RangeError when the follow-up is already absorbed.

    • Marks a follow-up as delivered to the runtime.

      Parameters

      • messageId: string

        The follow-up message.

      Returns void

      RangeError when the follow-up is already further.

    • Handles an error frame of a run.update of this run.

      base_version_conflict loads getRun and sends the last ops again on its version; conflict (run_not_active) ends the patcher.

      Parameters

      Returns Promise<void>

      A promise that resolves when the reaction is done.

      ProblemError when getRun fails.

    • Sends raw RFC 6902 operations at once, after checking them against PATCH_PATHS.

      Parameters

      • ops: readonly {}[]

        The operations.

      Returns Promise<number>

      The new version.

      PatchPathError when an operation names a path or op outside 09 5.3 (before any request); ProblemError when the server refused.

      await patcher.sendOps([{ op: "replace", path: "/status_line", value: "Reading" }]);
      
    • Sets /cost; always an estimate (is_estimate: true).

      Parameters

      • amountMicros: number

        The amount in millionths of the currency unit.

      • currency: string

        The ISO 4217 code.

      Returns void

    • Sets /metrics/last_api_retry.

      Parameters

      • attempt: number

        The attempt number.

      • options: LastApiRetryOptions = {}

        maxRetries, retryDelayMs and error, each if known.

      Returns void

    • Sets /last_text_excerpt (the server keeps its last run.excerpt_max_chars).

      Parameters

      • text: string

        The draft text so far.

      Returns void

    • Sets /metrics/<name>.

      Parameters

      Returns void

      RangeError when name is not a metric of run_metrics.v1.

    • Sets /model.

      Parameters

      • model: string

        The model name of the runtime.

      Returns void

    • Sets /plan.

      Parameters

      • items: readonly PlanItem[]

        Plan items with id, text and status.

      Returns void

    • Sets /status_line.

      Parameters

      • text: string

        The status line.

      Returns void

    • Changes a step; an unsent add absorbs the change.

      Parameters

      • stepId: string

        The step.

      • changes: UpdateStepOptions

        status, title, detail and finishedAt; absent members stay.

      Returns void

    • Sends patches with the gateway op run.update instead of REST.

      The gateway has no success reply, so the next base is assumed as baseVersion + 1; route an error frame of a run.update of this run to RunPatcher.onGatewayError, which loads getRun after base_version_conflict and sends again.

      Parameters

      Returns void