[PR #130] [MERGED] Add workflow.handle([or(ev1, ev2)], ...) support #132

Closed
opened 2026-02-16 03:16:15 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/run-llama/workflows-ts/pull/130
Author: @logan-markewich
Created: 7/20/2025
Status: Merged
Merged: 7/22/2025
Merged by: @logan-markewich

Base: mainHead: logan/add_handle_any


📝 Commits (10+)

📊 Changes

4 files changed (+166 additions, -0 deletions)

View changed files

.changeset/big-pandas-stay.md (+5 -0)
📝 packages/core/src/core/event.ts (+73 -0)
📝 packages/core/src/core/index.ts (+2 -0)
📝 packages/core/tests/core/context-api.spec.ts (+86 -0)

📄 Description

Currently .handle([...]) accepts one or more events in the handler array. However, this means that the workflow step handler is only triggered when ALL events are present.

Instead, its often useful to trigger on any event type in the handler array, especially when writing loops.

workflow.handleAny() is an attempt at this. I wont feel bad if you hate it, its 80% written by claude

import { createWorkflow, workflowEvent, or } from "@llamaindex/workflow-core";

const workflow = createWorkflow();

const firstEvent = workflowEvent<any>();
const loopEvent = workflowEvent<any>();

// ✅ This now works!
workflow.handle([or(firstEvent, loopEvent)], async (firstEventData?, loopEventData?) => {
    console.log("Second handler started");
    
    if (firstEventData) {
        console.log("Got first event:", firstEventData.data);
    }
    if (loopEventData) {
        console.log("Got loop event:", loopEventData.data);
    }
    ....
});

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/run-llama/workflows-ts/pull/130 **Author:** [@logan-markewich](https://github.com/logan-markewich) **Created:** 7/20/2025 **Status:** ✅ Merged **Merged:** 7/22/2025 **Merged by:** [@logan-markewich](https://github.com/logan-markewich) **Base:** `main` ← **Head:** `logan/add_handle_any` --- ### 📝 Commits (10+) - [`cf6c71d`](https://github.com/run-llama/workflows-ts/commit/cf6c71dc6c7ad9a0a222c35b3db7af30517e8eb8) attempt at .handleAny - [`9b249d7`](https://github.com/run-llama/workflows-ts/commit/9b249d700d1fb3952612327ac52c903c833aaf10) Use or() syntax - [`81f9186`](https://github.com/run-llama/workflows-ts/commit/81f9186f138f2888f53d7f20fae6394cc4c857fb) Use or() syntax - [`536336c`](https://github.com/run-llama/workflows-ts/commit/536336cc5cff08064d109873e3dcf32dcf29d01d) clean import - [`c5c3bac`](https://github.com/run-llama/workflows-ts/commit/c5c3bacf19d1338e6bac93efa7f8052979b29788) fix types - [`ead891c`](https://github.com/run-llama/workflows-ts/commit/ead891c5ffa34abf13f056edb9ee3442ce8ffff2) simplify further - [`56d2ce6`](https://github.com/run-llama/workflows-ts/commit/56d2ce6e12114f1da4828be524b1e71669a964b2) clean up old code - [`6a6745d`](https://github.com/run-llama/workflows-ts/commit/6a6745d17427df9346161d71f5f16af209b5ca23) revert workflow changes - [`66a4196`](https://github.com/run-llama/workflows-ts/commit/66a4196ae3d272674302bb3fd00035c432cefcbe) remove unused import - [`593cb62`](https://github.com/run-llama/workflows-ts/commit/593cb6258d8840e54165b039888ddad6c57bdf6c) changeset ### 📊 Changes **4 files changed** (+166 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/big-pandas-stay.md` (+5 -0) 📝 `packages/core/src/core/event.ts` (+73 -0) 📝 `packages/core/src/core/index.ts` (+2 -0) 📝 `packages/core/tests/core/context-api.spec.ts` (+86 -0) </details> ### 📄 Description Currently `.handle([...])` accepts one or more events in the handler array. However, this means that the workflow step handler is only triggered when ALL events are present. Instead, its often useful to trigger on any event type in the handler array, especially when writing loops. `workflow.handleAny()` is an attempt at this. I wont feel bad if you hate it, its 80% written by claude ``` import { createWorkflow, workflowEvent, or } from "@llamaindex/workflow-core"; const workflow = createWorkflow(); const firstEvent = workflowEvent<any>(); const loopEvent = workflowEvent<any>(); // ✅ This now works! workflow.handle([or(firstEvent, loopEvent)], async (firstEventData?, loopEventData?) => { console.log("Second handler started"); if (firstEventData) { console.log("Got first event:", firstEventData.data); } if (loopEventData) { console.log("Got loop event:", loopEventData.data); } .... }); ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 03:16:15 -05:00
yindo closed this issue 2026-02-16 03:16:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/workflows-ts#132