@pi-unipi/core 2.20.1 → 2.20.2
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 +36 -0
package/package.json
CHANGED
package/utils.ts
CHANGED
|
@@ -304,6 +304,42 @@ export async function withHerdrBlocked<T>(
|
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Claim herdr `working` state for a long-lived "the agent will auto-resume" wait
|
|
309
|
+
* (bg task wake, fusion sidekick handoff) — the states where pi has already
|
|
310
|
+
* settled but background work holds a pending wake.
|
|
311
|
+
*
|
|
312
|
+
* Key-scoped and level-based, not a wrapper: each key claims exactly once and
|
|
313
|
+
* emits `herdr:working` {active:true,label} on claim, {active:false,label} on
|
|
314
|
+
* clear — the same refcounted protocol `herdr:blocked` uses, so the herdr pi
|
|
315
|
+
* integration can keep the pane `working` after agent_settled.
|
|
316
|
+
*
|
|
317
|
+
* - label !== null && no previous claim → emit active
|
|
318
|
+
* - label !== null && same label → no emit (still claimed)
|
|
319
|
+
* - label !== null && different label → emit inactive(previous) then active
|
|
320
|
+
* - label === null && claimed → emit inactive, drop claim
|
|
321
|
+
* - label === null && not claimed → no emit
|
|
322
|
+
*/
|
|
323
|
+
const herdrWorkingClaims = new Map<string, string>();
|
|
324
|
+
|
|
325
|
+
export function setHerdrWorking(
|
|
326
|
+
pi: { events: { emit: (name: string, payload: unknown) => void } },
|
|
327
|
+
key: string,
|
|
328
|
+
label: string | null,
|
|
329
|
+
): void {
|
|
330
|
+
const previous = herdrWorkingClaims.get(key);
|
|
331
|
+
if (label === null) {
|
|
332
|
+
if (previous === undefined) return;
|
|
333
|
+
herdrWorkingClaims.delete(key);
|
|
334
|
+
emitEvent(pi, "herdr:working", { active: false, label: previous });
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (previous === label) return;
|
|
338
|
+
if (previous !== undefined) emitEvent(pi, "herdr:working", { active: false, label: previous });
|
|
339
|
+
herdrWorkingClaims.set(key, label);
|
|
340
|
+
emitEvent(pi, "herdr:working", { active: true, label });
|
|
341
|
+
}
|
|
342
|
+
|
|
307
343
|
/** Format a token count for display (e.g. 1234 → "1.2k", 1500000 → "1.5M"). */
|
|
308
344
|
export function formatTokens(n: number): string {
|
|
309
345
|
if (n < 1000) return String(n);
|