[PR #97] [MERGED] feat: add withSnapshot API #104

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

📋 Pull Request Information

Original PR: https://github.com/run-llama/workflows-ts/pull/97
Author: @himself65
Created: 4/30/2025
Status: Merged
Merged: 5/20/2025
Merged by: @himself65

Base: mainHead: snapshot-2


📝 Commits (10+)

📊 Changes

14 files changed (+1217 additions, -56 deletions)

View changed files

.changeset/pretty-moose-share.md (+12 -0)
📝 demo/hono/app.ts (+48 -0)
demo/node/name-ask-readline.ts (+29 -0)
📝 demo/package.json (+1 -0)
demo/workflows/human-in-the-loop.ts (+73 -0)
📝 packages/core/package.json (+4 -0)
📝 packages/core/src/core/context.ts (+46 -40)
📝 packages/core/src/core/stream.ts (+3 -3)
📝 packages/core/src/core/utils.ts (+16 -10)
packages/core/src/middleware/snapshot.ts (+361 -0)
packages/core/src/middleware/snapshot/stable-hash.ts (+60 -0)
packages/core/tests/middleware/with-snapshot.spec.ts (+279 -0)
📝 packages/core/vitest.config.ts (+3 -3)
📝 pnpm-lock.yaml (+282 -0)

📄 Description

add snapshot API, for human in the loop feature. The API is designed for cross JavaScript platform, including node.js, browser, and serverless platform such as cloudflare worker and edge runtime

  • workflow.createContext(): Context
  • context.snapshot(): Promise<[requestEvent, snapshot]>
    This will stop all incoming handler, lock the context and wait until all existing handler get result.
  • workflow.resume(data, snapshot)

Recover all pending events in the queue and send request event back

Test Code sample

image


🔄 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/97 **Author:** [@himself65](https://github.com/himself65) **Created:** 4/30/2025 **Status:** ✅ Merged **Merged:** 5/20/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `main` ← **Head:** `snapshot-2` --- ### 📝 Commits (10+) - [`9eac0ba`](https://github.com/run-llama/workflows-ts/commit/9eac0ba5c3d1ae80bab5022e353dccf7fa78dd36) feat: init snapshot v2 - [`6808e4c`](https://github.com/run-llama/workflows-ts/commit/6808e4ca642f0c2d9e2945d864470274a53850f8) feat: init `snapshot` API - [`f15df4d`](https://github.com/run-llama/workflows-ts/commit/f15df4ded7a80e4466c61f213e07cae0e0d3a4d9) feat: recoverContext API - [`ec85b3a`](https://github.com/run-llama/workflows-ts/commit/ec85b3a28dfa0228ba1d23d8da8e7dc8e90643e6) chore: remove dep - [`7a3084e`](https://github.com/run-llama/workflows-ts/commit/7a3084eb44d965647a19eb38becabc48a4d969c5) fix: test - [`9c9021b`](https://github.com/run-llama/workflows-ts/commit/9c9021b618035770fcb7030fba8888f3badb3728) feat: resume - [`c524f9d`](https://github.com/run-llama/workflows-ts/commit/c524f9dd05653263bd8f8a2089209ebd85dca51b) feat: add onRequestEvent callback - [`47b604b`](https://github.com/run-llama/workflows-ts/commit/47b604b02d1c59d19c39f4c34dd51d68e2a61267) fix: naming - [`93ced6f`](https://github.com/run-llama/workflows-ts/commit/93ced6f63ec8cd7d67554ba46cdbf73b795f9b09) fix: snapshot - [`baae397`](https://github.com/run-llama/workflows-ts/commit/baae397dcc078cb124e62a7ba825e8ece65e04e6) feat: update change ### 📊 Changes **14 files changed** (+1217 additions, -56 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/pretty-moose-share.md` (+12 -0) 📝 `demo/hono/app.ts` (+48 -0) ➕ `demo/node/name-ask-readline.ts` (+29 -0) 📝 `demo/package.json` (+1 -0) ➕ `demo/workflows/human-in-the-loop.ts` (+73 -0) 📝 `packages/core/package.json` (+4 -0) 📝 `packages/core/src/core/context.ts` (+46 -40) 📝 `packages/core/src/core/stream.ts` (+3 -3) 📝 `packages/core/src/core/utils.ts` (+16 -10) ➕ `packages/core/src/middleware/snapshot.ts` (+361 -0) ➕ `packages/core/src/middleware/snapshot/stable-hash.ts` (+60 -0) ➕ `packages/core/tests/middleware/with-snapshot.spec.ts` (+279 -0) 📝 `packages/core/vitest.config.ts` (+3 -3) 📝 `pnpm-lock.yaml` (+282 -0) </details> ### 📄 Description add snapshot API, for human in the loop feature. The API is designed for cross JavaScript platform, including node.js, browser, and serverless platform such as cloudflare worker and edge runtime - `workflow.createContext(): Context` - `context.snapshot(): Promise<[requestEvent, snapshot]>` This will stop all incoming handler, lock the context and wait until all existing handler get result. - `workflow.resume(data, snapshot)` Recover all pending events in the queue and send request event back ## Test Code sample ![image](https://github.com/user-attachments/assets/bd1f511e-dbde-406b-8ba0-ac7f7627f3af) --- <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:11 -05:00
yindo closed this issue 2026-02-16 03:16:11 -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#104