@pi-unipi/core 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils.ts +26 -0
package/package.json
CHANGED
package/utils.ts
CHANGED
|
@@ -240,3 +240,29 @@ export function emitEvent(
|
|
|
240
240
|
return false;
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Wrap an awaitable blocking-UI operation with herdr `blocked` state reporting.
|
|
246
|
+
*
|
|
247
|
+
* Emits `herdr:blocked` active (with a label) before awaiting `fn`, and
|
|
248
|
+
* inactive (with matching label) afterwards — including on throw. This lets
|
|
249
|
+
* the herdr integration surface `blocked` agent status for ask_user and other
|
|
250
|
+
* stop-and-continue UIs instead of `working`.
|
|
251
|
+
*
|
|
252
|
+
* The label should match what's shown to the user so herdr's sidebar reads
|
|
253
|
+
* meaningfully (e.g. "ask_user", "helper viewer").
|
|
254
|
+
*/
|
|
255
|
+
export async function withHerdrBlocked<T>(
|
|
256
|
+
pi: { events: { emit: (name: string, payload: unknown) => void } },
|
|
257
|
+
label: string,
|
|
258
|
+
fn: () => Promise<T>,
|
|
259
|
+
): Promise<T> {
|
|
260
|
+
const event = (active: boolean) =>
|
|
261
|
+
emitEvent(pi, "herdr:blocked", { active, label });
|
|
262
|
+
event(true);
|
|
263
|
+
try {
|
|
264
|
+
return await fn();
|
|
265
|
+
} finally {
|
|
266
|
+
event(false);
|
|
267
|
+
}
|
|
268
|
+
}
|