@sema-agent/core 5.6.0 → 5.8.0
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/CHANGELOG.md +55 -0
- package/dist/agents/cascade.d.ts +1 -1
- package/dist/agents/subagent.d.ts +4 -7
- package/dist/agents/subagent.js +10 -19
- package/dist/agents/teacher.js +3 -3
- package/dist/agents/team.d.ts +1 -1
- package/dist/agents/team.js +1 -1
- package/dist/agents/verify.js +1 -1
- package/dist/brain/anthropic.js +24 -35
- package/dist/brain/openai.js +22 -33
- package/dist/brain/stream-engine.d.ts +0 -2
- package/dist/brain/stream-engine.js +5 -47
- package/dist/brain/stream-shared.d.ts +0 -10
- package/dist/brain/stream-shared.js +0 -23
- package/dist/brain/terminal-cause.d.ts +0 -1
- package/dist/brain/terminal-cause.js +0 -3
- package/dist/brain/timeout.d.ts +4 -2
- package/dist/brain/timeout.js +4 -14
- package/dist/config/catalog.d.ts +3 -11
- package/dist/config/catalog.js +30 -69
- package/dist/config/defaults.d.ts +0 -3
- package/dist/config/defaults.js +0 -3
- package/dist/core/auto-compaction.d.ts +2 -11
- package/dist/core/auto-compaction.js +3 -67
- package/dist/core/checkpoint-store.d.ts +15 -10
- package/dist/core/checkpoint-store.js +13 -10
- package/dist/core/memory-engine/file-backend.js +20 -17
- package/dist/core/memory-engine/layout.d.ts +5 -0
- package/dist/core/memory-engine/layout.js +72 -47
- package/dist/core/runner/assemble-result.d.ts +2 -8
- package/dist/core/runner/assemble-result.js +15 -16
- package/dist/core/runner/prepare-task.d.ts +26 -6
- package/dist/core/runner/prepare-task.js +203 -141
- package/dist/core/runner/runtask.d.ts +0 -2
- package/dist/core/runner/runtask.js +267 -253
- package/dist/core/secret-env.d.ts +2 -0
- package/dist/core/secret-env.js +16 -4
- package/dist/core/session-policy-store.d.ts +5 -0
- package/dist/core/session-policy-store.js +3 -1
- package/dist/core/store-contracts/checkpoint-store-contract.js +2 -2
- package/dist/core/task-notification.d.ts +1 -0
- package/dist/core/task-notification.js +3 -0
- package/dist/core/task-registry-agent.d.ts +2 -0
- package/dist/core/task-registry-agent.js +33 -1
- package/dist/core/task-registry.d.ts +2 -0
- package/dist/core/task-registry.js +9 -1
- package/dist/core/tool-errors.js +10 -2
- package/dist/core/trace.d.ts +1 -8
- package/dist/core/types.d.ts +24 -30
- package/dist/core/usage-window-store.d.ts +39 -0
- package/dist/core/usage-window-store.js +115 -0
- package/dist/engine/execution-env/node-execution-env.js +0 -22
- package/dist/engine/harness/agent-harness.d.ts +0 -7
- package/dist/engine/harness/agent-harness.js +13 -53
- package/dist/engine/harness/types.d.ts +2 -15
- package/dist/engine/llm/types.d.ts +1 -2
- package/dist/engine/loop/agent-loop.d.ts +1 -1
- package/dist/engine/loop/agent-loop.js +5 -171
- package/dist/engine/loop/types.d.ts +0 -18
- package/dist/index.d.ts +10 -5
- package/dist/index.js +8 -4
- package/dist/orchestration/goal.js +1 -5
- package/dist/orchestration/run-workflow-tool.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.js +1 -2
- package/dist/orchestration/workflow-governance.d.ts +6 -6
- package/dist/orchestration/workflow-governance.js +33 -47
- package/dist/prompt-assembly/event-registry.js +2 -3
- package/dist/stores/cc/lockfile.js +9 -11
- package/dist/stores/cc/mailbox-store.js +49 -38
- package/dist/stores/file/index.d.ts +3 -0
- package/dist/stores/file/index.js +4 -0
- package/dist/stores/file/usage-window-store.d.ts +9 -0
- package/dist/stores/file/usage-window-store.js +86 -0
- package/dist/tools/fs/fs-bash.d.ts +1 -10
- package/dist/tools/fs/fs-bash.js +20 -60
- package/dist/tools/fs/index.d.ts +0 -2
- package/dist/tools/fs/index.js +1 -2
- package/package.json +1 -4
- package/dist/bin/sema-tb.d.ts +0 -31
- package/dist/bin/sema-tb.js +0 -448
- package/dist/bin/tb-env.d.ts +0 -2
- package/dist/bin/tb-env.js +0 -17
- package/dist/brain/walltime.d.ts +0 -1
- package/dist/brain/walltime.js +0 -1
- package/dist/core/runner/call-cap.d.ts +0 -67
- package/dist/core/runner/call-cap.js +0 -145
- package/dist/core/runner/cut-kill.d.ts +0 -10
- package/dist/core/runner/cut-kill.js +0 -37
package/dist/bin/tb-env.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function positiveIntFromEnv(name, env = process.env) {
|
|
2
|
-
const raw = env[name];
|
|
3
|
-
if (raw === undefined)
|
|
4
|
-
return undefined;
|
|
5
|
-
const s = raw.trim();
|
|
6
|
-
if (s === "")
|
|
7
|
-
return undefined;
|
|
8
|
-
const n = /^[0-9]+$/.test(s) ? Number(s) : NaN;
|
|
9
|
-
if (!Number.isSafeInteger(n) || n <= 0) {
|
|
10
|
-
process.stderr.write(`sema-tb: ignoring ${name}=${JSON.stringify(raw)} — expected a positive integer.\n`);
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
return n;
|
|
14
|
-
}
|
|
15
|
-
export function tbModelInput(env = process.env) {
|
|
16
|
-
return env.TB_VISION === "1" ? ["text", "image"] : ["text"];
|
|
17
|
-
}
|
package/dist/brain/walltime.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const WALLTIME_CUTOFF_MESSAGE = "walltime cutoff: the response crossed the task's soft wall-clock deadline and was cut off to preserve a write-out window";
|
package/dist/brain/walltime.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const WALLTIME_CUTOFF_MESSAGE = "walltime cutoff: the response crossed the task's soft wall-clock deadline and was cut off to preserve a write-out window";
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
export declare const CALL_CAP_PRIOR_TOK_PER_SEC = 40;
|
|
2
|
-
export declare const CALL_CAP_SAFETY = 0.5;
|
|
3
|
-
export declare const CALL_CAP_MIN_FLOOR = 1024;
|
|
4
|
-
export declare const CALL_CAP_THINKING_MIN = 2048;
|
|
5
|
-
export declare const WRITEOUT_CUSHION_MAX_MS = 75000;
|
|
6
|
-
export declare const WRITEOUT_CUSHION_MIN_MS = 10000;
|
|
7
|
-
export declare const CUSHION_LATENCY_FACTOR = 2;
|
|
8
|
-
export declare const CUSHION_BUDGET_FRACTION = 0.4;
|
|
9
|
-
export declare const FINAL_WRITEOUT_MARGIN_MS = 5000;
|
|
10
|
-
export declare const TTFT_WINDOW_FACTOR = 2;
|
|
11
|
-
export declare const TTFT_PRIOR_MS = 5000;
|
|
12
|
-
export declare const WRITEOUT_WINDOW_NO_SAMPLE_FLOOR_MS = 1000;
|
|
13
|
-
export declare const TOOL_CUT_WRITEOUT_RESERVE_MS = 5000;
|
|
14
|
-
export declare const TOOL_CUT_DEADLINE_LAG_MS = 2500;
|
|
15
|
-
export declare const TOOL_CUT_MIN_WINDOW_MS = 10000;
|
|
16
|
-
export declare const TOOL_CUT_FLOOR_GRACE_MS = 2000;
|
|
17
|
-
export declare const WALLTIME_STALL_CONNECT_MS = 30000;
|
|
18
|
-
export declare const WALLTIME_STALL_FIRST_TOKEN_MS = 120000;
|
|
19
|
-
export declare const WALLTIME_STALL_IDLE_MS = 90000;
|
|
20
|
-
export declare function writeoutCushionMs(budgetMs: number): number;
|
|
21
|
-
export interface CallCapState {
|
|
22
|
-
emaTokPerSec?: number;
|
|
23
|
-
emaCallMs?: number;
|
|
24
|
-
emaToolMs?: number;
|
|
25
|
-
peakCallMs?: number;
|
|
26
|
-
peakToolMs?: number;
|
|
27
|
-
recentCallMs?: number[];
|
|
28
|
-
recentToolMs?: number[];
|
|
29
|
-
ttftEwma?: number;
|
|
30
|
-
last?: {
|
|
31
|
-
cap: number;
|
|
32
|
-
remainingMs: number;
|
|
33
|
-
tokPerSec: number;
|
|
34
|
-
thinkingSkipped: boolean;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export interface CallCapRef {
|
|
38
|
-
state: CallCapState;
|
|
39
|
-
deadlineMs?: number;
|
|
40
|
-
finalizeMode?: boolean;
|
|
41
|
-
staticCapTokens?: number;
|
|
42
|
-
shrinks?: number;
|
|
43
|
-
cushionMs?: number;
|
|
44
|
-
budgetMs?: number;
|
|
45
|
-
toolClamps?: number;
|
|
46
|
-
toolCuts?: number;
|
|
47
|
-
pendingCutTools?: number;
|
|
48
|
-
reasoningObserved?: boolean;
|
|
49
|
-
}
|
|
50
|
-
export declare function effectiveCushionMs(ref: CallCapRef): number | undefined;
|
|
51
|
-
export declare function minLiveWriteoutWindowMs(state: CallCapState): number;
|
|
52
|
-
export declare function softExecDeadlineMs(ref: CallCapRef): number | undefined;
|
|
53
|
-
export declare function createCallCapRef(): CallCapRef;
|
|
54
|
-
export declare function toolCutDeadlineMs(ref: CallCapRef, nowMs: number): number | undefined;
|
|
55
|
-
export declare function hasRealContent(content: ReadonlyArray<{
|
|
56
|
-
type?: unknown;
|
|
57
|
-
text?: unknown;
|
|
58
|
-
thinking?: unknown;
|
|
59
|
-
}> | undefined): boolean;
|
|
60
|
-
export declare function recordCallSample(state: CallCapState, outputTokens: number, latencyMs: number, opts?: {
|
|
61
|
-
contentValid?: boolean;
|
|
62
|
-
}): void;
|
|
63
|
-
export declare function recordTtftSample(state: CallCapState, ttftMs: number): void;
|
|
64
|
-
export declare function recordToolSample(state: CallCapState, durationMs: number): void;
|
|
65
|
-
export declare function recordToolCycleSample(state: CallCapState, wallSpanMs: number): void;
|
|
66
|
-
export declare function computeCallCap(ref: CallCapRef, nowMs: number, thinkingActive: boolean): number | undefined;
|
|
67
|
-
export declare function estimateCycleMs(state: CallCapState): number;
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
const EWMA_ALPHA = 0.4;
|
|
2
|
-
export const CALL_CAP_PRIOR_TOK_PER_SEC = 40;
|
|
3
|
-
export const CALL_CAP_SAFETY = 0.5;
|
|
4
|
-
export const CALL_CAP_MIN_FLOOR = 1024;
|
|
5
|
-
export const CALL_CAP_THINKING_MIN = 2048;
|
|
6
|
-
const FINALIZE_HEADROOM = 1.5;
|
|
7
|
-
const FINALIZE_PRIOR_CYCLE_MS = 60_000;
|
|
8
|
-
const PEAK_DECAY = 0.85;
|
|
9
|
-
const CYCLE_RING_SIZE = 8;
|
|
10
|
-
const CYCLE_PERCENTILE = 0.75;
|
|
11
|
-
export const WRITEOUT_CUSHION_MAX_MS = 75_000;
|
|
12
|
-
export const WRITEOUT_CUSHION_MIN_MS = 10_000;
|
|
13
|
-
export const CUSHION_LATENCY_FACTOR = 2;
|
|
14
|
-
export const CUSHION_BUDGET_FRACTION = 0.4;
|
|
15
|
-
export const FINAL_WRITEOUT_MARGIN_MS = 5_000;
|
|
16
|
-
export const TTFT_WINDOW_FACTOR = 2;
|
|
17
|
-
export const TTFT_PRIOR_MS = 5_000;
|
|
18
|
-
export const WRITEOUT_WINDOW_NO_SAMPLE_FLOOR_MS = 1_000;
|
|
19
|
-
export const TOOL_CUT_WRITEOUT_RESERVE_MS = 5_000;
|
|
20
|
-
export const TOOL_CUT_DEADLINE_LAG_MS = 2_500;
|
|
21
|
-
export const TOOL_CUT_MIN_WINDOW_MS = 10_000;
|
|
22
|
-
export const TOOL_CUT_FLOOR_GRACE_MS = 2_000;
|
|
23
|
-
export const WALLTIME_STALL_CONNECT_MS = 30_000;
|
|
24
|
-
export const WALLTIME_STALL_FIRST_TOKEN_MS = 120_000;
|
|
25
|
-
export const WALLTIME_STALL_IDLE_MS = 90_000;
|
|
26
|
-
export function writeoutCushionMs(budgetMs) {
|
|
27
|
-
return Math.min(WRITEOUT_CUSHION_MAX_MS, Math.max(WRITEOUT_CUSHION_MIN_MS, Math.floor(budgetMs * 0.15)));
|
|
28
|
-
}
|
|
29
|
-
export function effectiveCushionMs(ref) {
|
|
30
|
-
const base = ref.cushionMs;
|
|
31
|
-
if (base === undefined)
|
|
32
|
-
return undefined;
|
|
33
|
-
const budgetCapMs = ref.budgetMs !== undefined ? Math.floor(ref.budgetMs * CUSHION_BUDGET_FRACTION) : Infinity;
|
|
34
|
-
const smallWindow = (ref.state.recentCallMs?.length ?? 0) < 3;
|
|
35
|
-
const observedRaw = Math.max(ref.state.peakCallMs ?? 0, ref.state.emaCallMs ?? 0);
|
|
36
|
-
const observedCallMs = smallWindow ? Math.min(observedRaw, FINALIZE_PRIOR_CYCLE_MS) : observedRaw;
|
|
37
|
-
const dynamic = observedCallMs > 0 ? Math.min(CUSHION_LATENCY_FACTOR * observedCallMs, budgetCapMs) : 0;
|
|
38
|
-
const ttftFloor = Math.min(FINAL_WRITEOUT_MARGIN_MS + TTFT_WINDOW_FACTOR * (ref.state.ttftEwma ?? TTFT_PRIOR_MS), budgetCapMs);
|
|
39
|
-
return Math.max(base, Math.ceil(dynamic), Math.ceil(ttftFloor));
|
|
40
|
-
}
|
|
41
|
-
export function minLiveWriteoutWindowMs(state) {
|
|
42
|
-
return state.ttftEwma !== undefined
|
|
43
|
-
? Math.ceil(TTFT_WINDOW_FACTOR * state.ttftEwma)
|
|
44
|
-
: WRITEOUT_WINDOW_NO_SAMPLE_FLOOR_MS;
|
|
45
|
-
}
|
|
46
|
-
export function softExecDeadlineMs(ref) {
|
|
47
|
-
const d = ref.deadlineMs;
|
|
48
|
-
const c = effectiveCushionMs(ref);
|
|
49
|
-
if (d === undefined || c === undefined)
|
|
50
|
-
return undefined;
|
|
51
|
-
return ref.finalizeMode ? d - FINAL_WRITEOUT_MARGIN_MS : d - c;
|
|
52
|
-
}
|
|
53
|
-
export function createCallCapRef() {
|
|
54
|
-
return { state: {} };
|
|
55
|
-
}
|
|
56
|
-
export function toolCutDeadlineMs(ref, nowMs) {
|
|
57
|
-
const soft = softExecDeadlineMs(ref);
|
|
58
|
-
if (soft === undefined)
|
|
59
|
-
return undefined;
|
|
60
|
-
const raw = Math.max(soft + TOOL_CUT_DEADLINE_LAG_MS, nowMs + TOOL_CUT_MIN_WINDOW_MS);
|
|
61
|
-
const ttftReserve = ref.state.ttftEwma !== undefined ? Math.ceil(TTFT_WINDOW_FACTOR * ref.state.ttftEwma) : 0;
|
|
62
|
-
const hardCap = ref.deadlineMs - FINAL_WRITEOUT_MARGIN_MS - Math.max(TOOL_CUT_WRITEOUT_RESERVE_MS, ttftReserve);
|
|
63
|
-
const clamped = Math.min(raw, hardCap);
|
|
64
|
-
return clamped > nowMs ? clamped : nowMs + TOOL_CUT_FLOOR_GRACE_MS;
|
|
65
|
-
}
|
|
66
|
-
export function hasRealContent(content) {
|
|
67
|
-
if (!Array.isArray(content))
|
|
68
|
-
return false;
|
|
69
|
-
return content.some((c) => (c?.type === "text" && typeof c.text === "string" && c.text.length > 0) ||
|
|
70
|
-
c?.type === "toolCall" ||
|
|
71
|
-
(c?.type === "thinking" && typeof c.thinking === "string" && (c.thinking.length > 0)));
|
|
72
|
-
}
|
|
73
|
-
export function recordCallSample(state, outputTokens, latencyMs, opts) {
|
|
74
|
-
const latencyHonest = latencyMs > 0 && (outputTokens > 0 || opts?.contentValid === true);
|
|
75
|
-
if (latencyHonest) {
|
|
76
|
-
state.emaCallMs = state.emaCallMs === undefined ? latencyMs : EWMA_ALPHA * latencyMs + (1 - EWMA_ALPHA) * state.emaCallMs;
|
|
77
|
-
state.peakCallMs = Math.max(latencyMs, (state.peakCallMs ?? 0) * PEAK_DECAY);
|
|
78
|
-
(state.recentCallMs ??= []).push(latencyMs);
|
|
79
|
-
if (state.recentCallMs.length > CYCLE_RING_SIZE)
|
|
80
|
-
state.recentCallMs.shift();
|
|
81
|
-
}
|
|
82
|
-
if (latencyMs > 0 && outputTokens > 0) {
|
|
83
|
-
const tps = (outputTokens / latencyMs) * 1000;
|
|
84
|
-
state.emaTokPerSec =
|
|
85
|
-
state.emaTokPerSec === undefined ? tps : EWMA_ALPHA * tps + (1 - EWMA_ALPHA) * state.emaTokPerSec;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export function recordTtftSample(state, ttftMs) {
|
|
89
|
-
if (Number.isFinite(ttftMs) && ttftMs >= 0) {
|
|
90
|
-
state.ttftEwma = state.ttftEwma === undefined ? ttftMs : EWMA_ALPHA * ttftMs + (1 - EWMA_ALPHA) * state.ttftEwma;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
export function recordToolSample(state, durationMs) {
|
|
94
|
-
if (durationMs > 0) {
|
|
95
|
-
state.emaToolMs = state.emaToolMs === undefined ? durationMs : EWMA_ALPHA * durationMs + (1 - EWMA_ALPHA) * state.emaToolMs;
|
|
96
|
-
state.peakToolMs = Math.max(durationMs, (state.peakToolMs ?? 0) * PEAK_DECAY);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export function recordToolCycleSample(state, wallSpanMs) {
|
|
100
|
-
if (wallSpanMs > 0) {
|
|
101
|
-
(state.recentToolMs ??= []).push(wallSpanMs);
|
|
102
|
-
if (state.recentToolMs.length > CYCLE_RING_SIZE)
|
|
103
|
-
state.recentToolMs.shift();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
export function computeCallCap(ref, nowMs, thinkingActive) {
|
|
107
|
-
const staticCapTokens = ref.staticCapTokens;
|
|
108
|
-
const deadline = ref.deadlineMs;
|
|
109
|
-
if (deadline === undefined)
|
|
110
|
-
return undefined;
|
|
111
|
-
const remainingMs = deadline - nowMs;
|
|
112
|
-
if (remainingMs <= 0)
|
|
113
|
-
return undefined;
|
|
114
|
-
const tokPerSec = ref.state.emaTokPerSec ?? CALL_CAP_PRIOR_TOK_PER_SEC;
|
|
115
|
-
const raw = Math.floor((remainingMs / 1000) * tokPerSec * CALL_CAP_SAFETY);
|
|
116
|
-
const floor = ref.finalizeMode ? CALL_CAP_THINKING_MIN : CALL_CAP_MIN_FLOOR;
|
|
117
|
-
let cap = Math.max(floor, raw);
|
|
118
|
-
let thinkingSkipped = false;
|
|
119
|
-
if (thinkingActive && cap < CALL_CAP_THINKING_MIN) {
|
|
120
|
-
if ((remainingMs / 1000) * tokPerSec >= CALL_CAP_THINKING_MIN) {
|
|
121
|
-
cap = CALL_CAP_THINKING_MIN;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
thinkingSkipped = true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (staticCapTokens !== undefined && staticCapTokens > 0 && cap >= staticCapTokens) {
|
|
128
|
-
ref.state.last = undefined;
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
|
-
ref.state.last = { cap, remainingMs, tokPerSec: Math.round(tokPerSec * 10) / 10, thinkingSkipped };
|
|
132
|
-
return cap;
|
|
133
|
-
}
|
|
134
|
-
export function estimateCycleMs(state) {
|
|
135
|
-
if (state.recentCallMs === undefined || state.recentCallMs.length === 0)
|
|
136
|
-
return Math.ceil(FINALIZE_PRIOR_CYCLE_MS * FINALIZE_HEADROOM);
|
|
137
|
-
const p75 = (ring) => {
|
|
138
|
-
if (ring === undefined || ring.length === 0)
|
|
139
|
-
return 0;
|
|
140
|
-
const sorted = [...ring].sort((a, b) => a - b);
|
|
141
|
-
return sorted[Math.max(0, Math.ceil(sorted.length * CYCLE_PERCENTILE) - 1)];
|
|
142
|
-
};
|
|
143
|
-
const clampMs = state.recentCallMs.length < 3 ? FINALIZE_PRIOR_CYCLE_MS : Number.POSITIVE_INFINITY;
|
|
144
|
-
return Math.ceil((Math.min(p75(state.recentCallMs), clampMs) + Math.min(p75(state.recentToolMs), clampMs)) * FINALIZE_HEADROOM);
|
|
145
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface ExecKillHandle {
|
|
2
|
-
pid: number;
|
|
3
|
-
kill: () => void;
|
|
4
|
-
}
|
|
5
|
-
export interface CutKillRegistry {
|
|
6
|
-
register: (toolCallId: string, handle: ExecKillHandle) => () => void;
|
|
7
|
-
killFor: (toolCallId: string) => number;
|
|
8
|
-
kills: number;
|
|
9
|
-
}
|
|
10
|
-
export declare function createCutKillRegistry(): CutKillRegistry;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export function createCutKillRegistry() {
|
|
2
|
-
const live = new Map();
|
|
3
|
-
const registry = {
|
|
4
|
-
kills: 0,
|
|
5
|
-
register: (toolCallId, handle) => {
|
|
6
|
-
let set = live.get(toolCallId);
|
|
7
|
-
if (!set) {
|
|
8
|
-
set = new Set();
|
|
9
|
-
live.set(toolCallId, set);
|
|
10
|
-
}
|
|
11
|
-
set.add(handle);
|
|
12
|
-
return () => {
|
|
13
|
-
set.delete(handle);
|
|
14
|
-
if (set.size === 0)
|
|
15
|
-
live.delete(toolCallId);
|
|
16
|
-
};
|
|
17
|
-
},
|
|
18
|
-
killFor: (toolCallId) => {
|
|
19
|
-
const set = live.get(toolCallId);
|
|
20
|
-
if (!set || set.size === 0)
|
|
21
|
-
return 0;
|
|
22
|
-
let signalled = 0;
|
|
23
|
-
for (const h of set) {
|
|
24
|
-
try {
|
|
25
|
-
h.kill();
|
|
26
|
-
signalled++;
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (signalled > 0)
|
|
32
|
-
registry.kills += 1;
|
|
33
|
-
return signalled;
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
return registry;
|
|
37
|
-
}
|