BatchAi.h header
#include <ew/app/BatchAi.h>
Namespace ew::app
BatchItem struct
struct ew::app::BatchItem
One target of a batch AI command: a stable id, a human-readable label (for the results view), and the input text the command runs on.
Members
QString ew::app::ai::agent::BatchItem::id
A stable id (e.g. a content id) identifying the target.
QString ew::app::ai::agent::BatchItem::label
A human-readable label shown in the results.
QString ew::app::ai::agent::BatchItem::input
The text the command runs on.
BatchResult struct
struct ew::app::BatchResult
The outcome of running a command on one BatchItem.
Members
QString ew::app::ai::agent::BatchResult::id
The originating item's id.
QString ew::app::ai::agent::BatchResult::label
The originating item's label.
bool ew::app::ai::agent::BatchResult::ok = false
True when the model produced output; false when the call errored.
QString ew::app::ai::agent::BatchResult::output
The model's output (when ok).
QString ew::app::ai::agent::BatchResult::error
A human-readable error (when not ok).
TokenUsage ew::app::ai::agent::BatchResult::usage {}
The tokens the model reported for this item's call (zero when unreported).
bool operator==(const BatchResult &, const BatchResult &)=default
Results compare equal when every field matches.
ChainResult struct
struct ew::app::ChainResult
The outcome of running a chain of commands over one starting text.
Members
bool ew::app::ai::agent::ChainResult::ok = false
True when every command succeeded; false when a step errored.
QString ew::app::ai::agent::ChainResult::finalOutput
The last command's output (when ok).
std::vector<QString> ew::app::ai::agent::ChainResult::steps
Each command's output, in order, for transparency (empty past the failing step).
QString ew::app::ai::agent::ChainResult::error
A human-readable error (when a step failed).
TokenUsage ew::app::ai::agent::ChainResult::usage {}
The tokens summed across every step that ran (zero when unreported).
bool ew::app::ai::agent::ChainResult::cancelled = false
True when the run stopped because the caller cancelled it. **Distinct from error on purpose:** a writer who pressed Cancel did not hit a failure and must not be shown one. steps still holds everything that completed first.
Functions
std::vector< BatchResult > ew::app::ai::agent::runBatchCommand(app::ai::AiProvider &provider, const PromptCommand &command, const std::vector< BatchItem > &items, const core::foundation::OperationContext &operation={})
Runs command on each of items independently through provider, collecting one BatchResult per item in the same order. Each item's input is applied via the command's instruction (an AiPrompts rewrite request). Blocking (it drives the provider once per item), so call it off the GUI thread with a value copy of items so a background task owns its data.
operation reports one step per item (the item's label as the activity) and is polled for cancellation BEFORE each call, so nothing is spent after the user asks to stop.
CANCELLING YIELDS PARTIAL RESULTS, and that is deliberate: the items already run cost real provider calls, and discarding them would make Cancel more expensive than waiting. Fewer results than items is exactly how a caller detects it – every item that runs produces one result, so the count is unambiguous and no separate flag is needed.
ChainResult ew::app::ai::agent::runCommandChain(app::ai::AiProvider &provider, const std::vector< PromptCommand > &commands, const QString &initialText, const core::foundation::OperationContext &operation={})
Runs commands in order over initialText, feeding each command's output as the next command's input, and stopping at the first error. Returns the final output plus each step's output. Blocking; call off the GUI thread.
operation reports one step per command (the command's name as the activity) and is polled for cancellation BEFORE each call; cancelling sets ChainResult::cancelled and keeps the steps that already ran, rather than throwing away work the provider was already paid for.