(
&self,
specs: Vec<AgentStepSpecObject>,
budget_tokens: Option<i64>,
)
| 3269 | /// outcomes array, unchanged. |
| 3270 | #[napi(ts_return_type = "Promise<Array<StepOutcomeObject> | WorkflowParallelResult>")] |
| 3271 | pub async fn parallel( |
| 3272 | &self, |
| 3273 | specs: Vec<AgentStepSpecObject>, |
| 3274 | budget_tokens: Option<i64>, |
| 3275 | ) -> napi::Result<Either<Vec<StepOutcomeObject>, WorkflowParallelResult>> { |
| 3276 | let session = self.inner.clone(); |
| 3277 | let rust_specs: Vec<RustAgentStepSpec> = specs.into_iter().map(Into::into).collect(); |
| 3278 | |
| 3279 | // No budget → unchanged behavior: the plain outcomes array. |
| 3280 | let Some(budget) = budget_tokens else { |
| 3281 | let outcomes = get_runtime() |
| 3282 | .spawn(async move { |
| 3283 | let executor = session.agent_executor(); |
| 3284 | execute_steps_parallel(executor, rust_specs, None).await |
| 3285 | }) |
| 3286 | .await |
| 3287 | .map_err(|e| napi::Error::from_reason(format!("Task join error: {e}")))?; |
| 3288 | return Ok(Either::A( |
| 3289 | outcomes.into_iter().map(StepOutcomeObject::from).collect(), |
| 3290 | )); |
| 3291 | }; |
| 3292 | |
| 3293 | // Budget → shared ledger across the fan-out; return outcomes + snapshot. |
| 3294 | let limit = budget.max(0) as u64; |
| 3295 | let (outcomes, snapshot) = get_runtime() |
| 3296 | .spawn(async move { |
| 3297 | let wf = session.workflow_with_token_budget(Some(limit)); |
| 3298 | let outcomes = wf.parallel(rust_specs).await; |
| 3299 | (outcomes, wf.budget_snapshot()) |
| 3300 | }) |
| 3301 | .await |
| 3302 | .map_err(|e| napi::Error::from_reason(format!("Task join error: {e}")))?; |
| 3303 | Ok(Either::B(WorkflowParallelResult { |
| 3304 | outcomes: outcomes.into_iter().map(StepOutcomeObject::from).collect(), |
| 3305 | budget: snapshot |
| 3306 | .map(|b| WorkflowBudgetObject { |
| 3307 | consumed_tokens: b.consumed_tokens as i64, |
| 3308 | limit_tokens: b.limit_tokens.map(|l| l as i64), |
| 3309 | }) |
| 3310 | .unwrap_or(WorkflowBudgetObject { |
| 3311 | consumed_tokens: 0, |
| 3312 | limit_tokens: Some(limit as i64), |
| 3313 | }), |
| 3314 | })) |
| 3315 | } |
| 3316 | |
| 3317 | /// Like `parallel`, but resumable: progress is journaled under |
| 3318 | /// `workflowId` via the session's `sessionStore`, so an interrupted run |
no test coverage detected