@storyteller-platform/ghost-story 0.0.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/LICENSE.md +611 -0
- package/README.md +18 -0
- package/dist/api/APIOptions.cjs +16 -0
- package/dist/api/APIOptions.d.cts +18 -0
- package/dist/api/APIOptions.d.ts +18 -0
- package/dist/api/APIOptions.js +0 -0
- package/dist/api/Recognition.cjs +263 -0
- package/dist/api/Recognition.d.cts +77 -0
- package/dist/api/Recognition.d.ts +77 -0
- package/dist/api/Recognition.js +233 -0
- package/dist/api/VoiceActivityDetection.cjs +77 -0
- package/dist/api/VoiceActivityDetection.d.cts +24 -0
- package/dist/api/VoiceActivityDetection.d.ts +24 -0
- package/dist/api/VoiceActivityDetection.js +43 -0
- package/dist/audio/AudioConverter.cjs +331 -0
- package/dist/audio/AudioConverter.d.cts +53 -0
- package/dist/audio/AudioConverter.d.ts +53 -0
- package/dist/audio/AudioConverter.js +310 -0
- package/dist/audio/AudioFormat.cjs +151 -0
- package/dist/audio/AudioFormat.d.cts +25 -0
- package/dist/audio/AudioFormat.d.ts +25 -0
- package/dist/audio/AudioFormat.js +123 -0
- package/dist/audio/AudioSource.cjs +119 -0
- package/dist/audio/AudioSource.d.cts +33 -0
- package/dist/audio/AudioSource.d.ts +33 -0
- package/dist/audio/AudioSource.js +88 -0
- package/dist/audio/index.cjs +74 -0
- package/dist/audio/index.d.cts +6 -0
- package/dist/audio/index.d.ts +6 -0
- package/dist/audio/index.js +54 -0
- package/dist/cli/bin.cjs +277 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +275 -0
- package/dist/cli/config.cjs +347 -0
- package/dist/cli/config.d.cts +33 -0
- package/dist/cli/config.d.ts +33 -0
- package/dist/cli/config.js +285 -0
- package/dist/cli/install.cjs +334 -0
- package/dist/cli/install.d.cts +62 -0
- package/dist/cli/install.d.ts +62 -0
- package/dist/cli/install.js +316 -0
- package/dist/cli/whisper-server.cjs +172 -0
- package/dist/cli/whisper-server.d.cts +24 -0
- package/dist/cli/whisper-server.d.ts +24 -0
- package/dist/cli/whisper-server.js +152 -0
- package/dist/config.cjs +60 -0
- package/dist/config.d.cts +12 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +32 -0
- package/dist/convert.cjs +88 -0
- package/dist/convert.d.cts +12 -0
- package/dist/convert.d.ts +12 -0
- package/dist/convert.js +63 -0
- package/dist/encodings/Ascii.cjs +75 -0
- package/dist/encodings/Ascii.d.cts +13 -0
- package/dist/encodings/Ascii.d.ts +13 -0
- package/dist/encodings/Ascii.js +48 -0
- package/dist/encodings/Base64.cjs +155 -0
- package/dist/encodings/Base64.d.cts +5 -0
- package/dist/encodings/Base64.d.ts +5 -0
- package/dist/encodings/Base64.js +129 -0
- package/dist/encodings/TextEncodingsCommon.cjs +16 -0
- package/dist/encodings/TextEncodingsCommon.d.cts +6 -0
- package/dist/encodings/TextEncodingsCommon.d.ts +6 -0
- package/dist/encodings/TextEncodingsCommon.js +0 -0
- package/dist/index.cjs +153 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +140 -0
- package/dist/recognition/AmazonTranscribeSTT.cjs +188 -0
- package/dist/recognition/AmazonTranscribeSTT.d.cts +21 -0
- package/dist/recognition/AmazonTranscribeSTT.d.ts +21 -0
- package/dist/recognition/AmazonTranscribeSTT.js +160 -0
- package/dist/recognition/AzureCognitiveServicesSTT.cjs +124 -0
- package/dist/recognition/AzureCognitiveServicesSTT.d.cts +21 -0
- package/dist/recognition/AzureCognitiveServicesSTT.d.ts +21 -0
- package/dist/recognition/AzureCognitiveServicesSTT.js +95 -0
- package/dist/recognition/DeepgramSTT.cjs +172 -0
- package/dist/recognition/DeepgramSTT.d.cts +23 -0
- package/dist/recognition/DeepgramSTT.d.ts +23 -0
- package/dist/recognition/DeepgramSTT.js +153 -0
- package/dist/recognition/GoogleCloudSTT.cjs +125 -0
- package/dist/recognition/GoogleCloudSTT.d.cts +35 -0
- package/dist/recognition/GoogleCloudSTT.d.ts +35 -0
- package/dist/recognition/GoogleCloudSTT.js +107 -0
- package/dist/recognition/OpenAICloudSTT.cjs +180 -0
- package/dist/recognition/OpenAICloudSTT.d.cts +29 -0
- package/dist/recognition/OpenAICloudSTT.d.ts +29 -0
- package/dist/recognition/OpenAICloudSTT.js +150 -0
- package/dist/recognition/WhisperCppSTT.cjs +296 -0
- package/dist/recognition/WhisperCppSTT.d.cts +40 -0
- package/dist/recognition/WhisperCppSTT.d.ts +40 -0
- package/dist/recognition/WhisperCppSTT.js +275 -0
- package/dist/recognition/WhisperServerSTT.cjs +119 -0
- package/dist/recognition/WhisperServerSTT.d.cts +24 -0
- package/dist/recognition/WhisperServerSTT.d.ts +24 -0
- package/dist/recognition/WhisperServerSTT.js +105 -0
- package/dist/utilities/FileSystem.cjs +54 -0
- package/dist/utilities/FileSystem.d.cts +3 -0
- package/dist/utilities/FileSystem.d.ts +3 -0
- package/dist/utilities/FileSystem.js +20 -0
- package/dist/utilities/Locale.cjs +46 -0
- package/dist/utilities/Locale.d.cts +9 -0
- package/dist/utilities/Locale.d.ts +9 -0
- package/dist/utilities/Locale.js +20 -0
- package/dist/utilities/ObjectUtilities.cjs +41 -0
- package/dist/utilities/ObjectUtilities.d.cts +3 -0
- package/dist/utilities/ObjectUtilities.d.ts +3 -0
- package/dist/utilities/ObjectUtilities.js +7 -0
- package/dist/utilities/Timeline.cjs +120 -0
- package/dist/utilities/Timeline.d.cts +23 -0
- package/dist/utilities/Timeline.d.ts +23 -0
- package/dist/utilities/Timeline.js +94 -0
- package/dist/utilities/Timing.cjs +287 -0
- package/dist/utilities/Timing.d.cts +64 -0
- package/dist/utilities/Timing.d.ts +64 -0
- package/dist/utilities/Timing.js +256 -0
- package/dist/utilities/WhisperTimeline.cjs +344 -0
- package/dist/utilities/WhisperTimeline.d.cts +86 -0
- package/dist/utilities/WhisperTimeline.d.ts +86 -0
- package/dist/utilities/WhisperTimeline.js +313 -0
- package/dist/vad/ActiveGate.cjs +357 -0
- package/dist/vad/ActiveGate.d.cts +53 -0
- package/dist/vad/ActiveGate.d.ts +53 -0
- package/dist/vad/ActiveGate.js +329 -0
- package/dist/vad/ActiveGateOg.cjs +1366 -0
- package/dist/vad/ActiveGateOg.d.cts +33 -0
- package/dist/vad/ActiveGateOg.d.ts +33 -0
- package/dist/vad/ActiveGateOg.js +1341 -0
- package/dist/vad/Silero.cjs +174 -0
- package/dist/vad/Silero.d.cts +25 -0
- package/dist/vad/Silero.d.ts +25 -0
- package/dist/vad/Silero.js +153 -0
- package/package.json +125 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Timing_exports = {};
|
|
20
|
+
__export(Timing_exports, {
|
|
21
|
+
Timing: () => Timing,
|
|
22
|
+
TimingAggregator: () => TimingAggregator,
|
|
23
|
+
createAggregator: () => createAggregator,
|
|
24
|
+
createTiming: () => createTiming,
|
|
25
|
+
formatDuration: () => formatDuration,
|
|
26
|
+
formatPercentage: () => formatPercentage,
|
|
27
|
+
formatSingleReport: () => formatSingleReport,
|
|
28
|
+
printSingleReport: () => printSingleReport
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(Timing_exports);
|
|
31
|
+
class Timing {
|
|
32
|
+
spans = [];
|
|
33
|
+
activeSpans = /* @__PURE__ */ new Map();
|
|
34
|
+
startTime = 0;
|
|
35
|
+
metadata = {};
|
|
36
|
+
constructor() {
|
|
37
|
+
this.startTime = performance.now();
|
|
38
|
+
}
|
|
39
|
+
time(name, fn) {
|
|
40
|
+
const start = performance.now();
|
|
41
|
+
try {
|
|
42
|
+
return fn();
|
|
43
|
+
} finally {
|
|
44
|
+
const end = performance.now();
|
|
45
|
+
this.spans.push({
|
|
46
|
+
name,
|
|
47
|
+
startTime: start - this.startTime,
|
|
48
|
+
endTime: end - this.startTime,
|
|
49
|
+
duration: end - start
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async timeAsync(name, fn) {
|
|
54
|
+
const start = performance.now();
|
|
55
|
+
try {
|
|
56
|
+
return await fn();
|
|
57
|
+
} finally {
|
|
58
|
+
const end = performance.now();
|
|
59
|
+
this.spans.push({
|
|
60
|
+
name,
|
|
61
|
+
startTime: start - this.startTime,
|
|
62
|
+
endTime: end - this.startTime,
|
|
63
|
+
duration: end - start
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
start(name) {
|
|
68
|
+
const start = performance.now();
|
|
69
|
+
this.activeSpans.set(name, start);
|
|
70
|
+
return () => {
|
|
71
|
+
this.end(name);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
end(name) {
|
|
75
|
+
const start = this.activeSpans.get(name);
|
|
76
|
+
if (start === void 0) return;
|
|
77
|
+
const end = performance.now();
|
|
78
|
+
this.activeSpans.delete(name);
|
|
79
|
+
this.spans.push({
|
|
80
|
+
name,
|
|
81
|
+
startTime: start - this.startTime,
|
|
82
|
+
endTime: end - this.startTime,
|
|
83
|
+
duration: end - start
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
setMetadata(key, value) {
|
|
87
|
+
this.metadata[key] = value;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
addMetadata(data) {
|
|
91
|
+
Object.assign(this.metadata, data);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
getElapsedMs() {
|
|
95
|
+
return performance.now() - this.startTime;
|
|
96
|
+
}
|
|
97
|
+
summary() {
|
|
98
|
+
const wallClockMs = performance.now() - this.startTime;
|
|
99
|
+
const totalMs = this.spans.reduce((sum, s) => sum + s.duration, 0);
|
|
100
|
+
const phaseMap = /* @__PURE__ */ new Map();
|
|
101
|
+
for (const span of this.spans) {
|
|
102
|
+
phaseMap.set(span.name, (phaseMap.get(span.name) ?? 0) + span.duration);
|
|
103
|
+
}
|
|
104
|
+
const phases = [...phaseMap.entries()].map(
|
|
105
|
+
([name, duration]) => ({
|
|
106
|
+
name,
|
|
107
|
+
duration,
|
|
108
|
+
percentage: totalMs > 0 ? duration / totalMs * 100 : 0
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
return {
|
|
112
|
+
totalMs,
|
|
113
|
+
wallClockMs,
|
|
114
|
+
phases,
|
|
115
|
+
spans: [...this.spans],
|
|
116
|
+
metadata: { ...this.metadata }
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function createTiming() {
|
|
121
|
+
return new Timing();
|
|
122
|
+
}
|
|
123
|
+
function formatDuration(ms) {
|
|
124
|
+
if (ms < 1e3) {
|
|
125
|
+
return `${ms.toFixed(0)}ms`;
|
|
126
|
+
}
|
|
127
|
+
if (ms < 6e4) {
|
|
128
|
+
return `${(ms / 1e3).toFixed(2)}s`;
|
|
129
|
+
}
|
|
130
|
+
const minutes = Math.floor(ms / 6e4);
|
|
131
|
+
const seconds = (ms % 6e4 / 1e3).toFixed(1);
|
|
132
|
+
return `${minutes}m ${seconds}s`;
|
|
133
|
+
}
|
|
134
|
+
function formatPercentage(pct) {
|
|
135
|
+
return `${pct.toFixed(1)}%`;
|
|
136
|
+
}
|
|
137
|
+
class TimingAggregator {
|
|
138
|
+
summaries = [];
|
|
139
|
+
metadata = {};
|
|
140
|
+
aggregatorStartTime = performance.now();
|
|
141
|
+
add(summary) {
|
|
142
|
+
this.summaries.push(summary);
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
setMetadata(key, value) {
|
|
146
|
+
this.metadata[key] = value;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
getStats() {
|
|
150
|
+
if (this.summaries.length === 0) {
|
|
151
|
+
return {
|
|
152
|
+
count: 0,
|
|
153
|
+
totalMs: 0,
|
|
154
|
+
wallClockMs: 0,
|
|
155
|
+
avgMs: 0,
|
|
156
|
+
minMs: 0,
|
|
157
|
+
maxMs: 0,
|
|
158
|
+
phaseStats: /* @__PURE__ */ new Map()
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const wallClockTotals = this.summaries.map((s) => s.wallClockMs);
|
|
162
|
+
const totalMs = wallClockTotals.reduce((a, b) => a + b, 0);
|
|
163
|
+
const wallClockMs = performance.now() - this.aggregatorStartTime;
|
|
164
|
+
const avgMs = totalMs / this.summaries.length;
|
|
165
|
+
const minMs = Math.min(...wallClockTotals);
|
|
166
|
+
const maxMs = Math.max(...wallClockTotals);
|
|
167
|
+
const phaseStats = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const summary of this.summaries) {
|
|
169
|
+
for (const phase of summary.phases) {
|
|
170
|
+
const existing = phaseStats.get(phase.name);
|
|
171
|
+
if (existing) {
|
|
172
|
+
existing.totalMs += phase.duration;
|
|
173
|
+
} else {
|
|
174
|
+
phaseStats.set(phase.name, {
|
|
175
|
+
totalMs: phase.duration,
|
|
176
|
+
avgMs: 0,
|
|
177
|
+
percentage: 0
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const phaseTotalMs = [...phaseStats.values()].reduce(
|
|
183
|
+
(sum, p) => sum + p.totalMs,
|
|
184
|
+
0
|
|
185
|
+
);
|
|
186
|
+
for (const [, stats] of phaseStats) {
|
|
187
|
+
stats.avgMs = stats.totalMs / this.summaries.length;
|
|
188
|
+
stats.percentage = phaseTotalMs > 0 ? stats.totalMs / phaseTotalMs * 100 : 0;
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
count: this.summaries.length,
|
|
192
|
+
totalMs,
|
|
193
|
+
wallClockMs,
|
|
194
|
+
avgMs,
|
|
195
|
+
minMs,
|
|
196
|
+
maxMs,
|
|
197
|
+
phaseStats
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
formatReport(title) {
|
|
201
|
+
const stats = this.getStats();
|
|
202
|
+
const lines = [];
|
|
203
|
+
const divider = "-".repeat(60);
|
|
204
|
+
lines.push(divider);
|
|
205
|
+
lines.push(title ?? "Timing Report");
|
|
206
|
+
lines.push(divider);
|
|
207
|
+
for (const [key, value] of Object.entries(this.metadata)) {
|
|
208
|
+
lines.push(` ${key}: ${value}`);
|
|
209
|
+
}
|
|
210
|
+
if (Object.keys(this.metadata).length > 0) {
|
|
211
|
+
lines.push("");
|
|
212
|
+
}
|
|
213
|
+
lines.push(` Files processed: ${stats.count}`);
|
|
214
|
+
lines.push(` Wall clock time: ${formatDuration(stats.wallClockMs)}`);
|
|
215
|
+
lines.push(` Combined time: ${formatDuration(stats.totalMs)}`);
|
|
216
|
+
lines.push(` Average per file: ${formatDuration(stats.avgMs)}`);
|
|
217
|
+
lines.push(` Fastest: ${formatDuration(stats.minMs)}`);
|
|
218
|
+
lines.push(` Slowest: ${formatDuration(stats.maxMs)}`);
|
|
219
|
+
if (stats.phaseStats.size > 0) {
|
|
220
|
+
lines.push("");
|
|
221
|
+
lines.push(" Time by phase:");
|
|
222
|
+
const sortedPhases = [...stats.phaseStats.entries()].sort(
|
|
223
|
+
(a, b) => b[1].totalMs - a[1].totalMs
|
|
224
|
+
);
|
|
225
|
+
for (const [name, phaseData] of sortedPhases) {
|
|
226
|
+
const pct = formatPercentage(phaseData.percentage);
|
|
227
|
+
const avg = formatDuration(phaseData.avgMs);
|
|
228
|
+
const total = formatDuration(phaseData.totalMs);
|
|
229
|
+
lines.push(
|
|
230
|
+
` ${name.padEnd(20)} ${pct.padStart(6)} avg: ${avg.padStart(8)} total: ${total}`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
lines.push(divider);
|
|
235
|
+
return lines.join("\n");
|
|
236
|
+
}
|
|
237
|
+
print(title) {
|
|
238
|
+
console.log(this.formatReport(title));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function createAggregator() {
|
|
242
|
+
return new TimingAggregator();
|
|
243
|
+
}
|
|
244
|
+
function formatSingleReport(summary, title) {
|
|
245
|
+
const lines = [];
|
|
246
|
+
const divider = "-".repeat(50);
|
|
247
|
+
lines.push(divider);
|
|
248
|
+
lines.push(title ?? "Timing");
|
|
249
|
+
lines.push(divider);
|
|
250
|
+
for (const [key, value] of Object.entries(summary.metadata)) {
|
|
251
|
+
lines.push(` ${key}: ${value}`);
|
|
252
|
+
}
|
|
253
|
+
if (Object.keys(summary.metadata).length > 0) {
|
|
254
|
+
lines.push("");
|
|
255
|
+
}
|
|
256
|
+
lines.push(` Wall clock: ${formatDuration(summary.wallClockMs)}`);
|
|
257
|
+
lines.push(` Active time: ${formatDuration(summary.totalMs)}`);
|
|
258
|
+
if (summary.phases.length > 0) {
|
|
259
|
+
lines.push("");
|
|
260
|
+
const sortedPhases = [...summary.phases].sort(
|
|
261
|
+
(a, b) => b.duration - a.duration
|
|
262
|
+
);
|
|
263
|
+
for (const phase of sortedPhases) {
|
|
264
|
+
const pct = formatPercentage(phase.percentage);
|
|
265
|
+
const dur = formatDuration(phase.duration);
|
|
266
|
+
lines.push(
|
|
267
|
+
` ${phase.name.padEnd(20)} ${pct.padStart(6)} ${dur.padStart(10)}`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
lines.push(divider);
|
|
272
|
+
return lines.join("\n");
|
|
273
|
+
}
|
|
274
|
+
function printSingleReport(summary, title) {
|
|
275
|
+
console.log(formatSingleReport(summary, title));
|
|
276
|
+
}
|
|
277
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
278
|
+
0 && (module.exports = {
|
|
279
|
+
Timing,
|
|
280
|
+
TimingAggregator,
|
|
281
|
+
createAggregator,
|
|
282
|
+
createTiming,
|
|
283
|
+
formatDuration,
|
|
284
|
+
formatPercentage,
|
|
285
|
+
formatSingleReport,
|
|
286
|
+
printSingleReport
|
|
287
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
interface TimingSpan {
|
|
2
|
+
name: string;
|
|
3
|
+
startTime: number;
|
|
4
|
+
endTime: number;
|
|
5
|
+
duration: number;
|
|
6
|
+
}
|
|
7
|
+
interface PhaseTiming {
|
|
8
|
+
name: string;
|
|
9
|
+
duration: number;
|
|
10
|
+
percentage: number;
|
|
11
|
+
}
|
|
12
|
+
interface TimingSummary {
|
|
13
|
+
totalMs: number;
|
|
14
|
+
wallClockMs: number;
|
|
15
|
+
phases: PhaseTiming[];
|
|
16
|
+
spans: TimingSpan[];
|
|
17
|
+
metadata: Record<string, string | number | boolean>;
|
|
18
|
+
}
|
|
19
|
+
declare class Timing {
|
|
20
|
+
private spans;
|
|
21
|
+
private activeSpans;
|
|
22
|
+
private startTime;
|
|
23
|
+
private metadata;
|
|
24
|
+
constructor();
|
|
25
|
+
time<T>(name: string, fn: () => T): T;
|
|
26
|
+
timeAsync<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
27
|
+
start(name: string): () => void;
|
|
28
|
+
end(name: string): void;
|
|
29
|
+
setMetadata(key: string, value: string | number | boolean): this;
|
|
30
|
+
addMetadata(data: Record<string, string | number | boolean>): this;
|
|
31
|
+
getElapsedMs(): number;
|
|
32
|
+
summary(): TimingSummary;
|
|
33
|
+
}
|
|
34
|
+
declare function createTiming(): Timing;
|
|
35
|
+
declare function formatDuration(ms: number): string;
|
|
36
|
+
declare function formatPercentage(pct: number): string;
|
|
37
|
+
interface AggregatedStats {
|
|
38
|
+
count: number;
|
|
39
|
+
totalMs: number;
|
|
40
|
+
wallClockMs: number;
|
|
41
|
+
avgMs: number;
|
|
42
|
+
minMs: number;
|
|
43
|
+
maxMs: number;
|
|
44
|
+
phaseStats: Map<string, {
|
|
45
|
+
totalMs: number;
|
|
46
|
+
avgMs: number;
|
|
47
|
+
percentage: number;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
declare class TimingAggregator {
|
|
51
|
+
private summaries;
|
|
52
|
+
private metadata;
|
|
53
|
+
private aggregatorStartTime;
|
|
54
|
+
add(summary: TimingSummary): this;
|
|
55
|
+
setMetadata(key: string, value: string | number | boolean): this;
|
|
56
|
+
getStats(): AggregatedStats;
|
|
57
|
+
formatReport(title?: string): string;
|
|
58
|
+
print(title?: string): void;
|
|
59
|
+
}
|
|
60
|
+
declare function createAggregator(): TimingAggregator;
|
|
61
|
+
declare function formatSingleReport(summary: TimingSummary, title?: string): string;
|
|
62
|
+
declare function printSingleReport(summary: TimingSummary, title?: string): void;
|
|
63
|
+
|
|
64
|
+
export { type AggregatedStats, type PhaseTiming, Timing, TimingAggregator, type TimingSpan, type TimingSummary, createAggregator, createTiming, formatDuration, formatPercentage, formatSingleReport, printSingleReport };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
interface TimingSpan {
|
|
2
|
+
name: string;
|
|
3
|
+
startTime: number;
|
|
4
|
+
endTime: number;
|
|
5
|
+
duration: number;
|
|
6
|
+
}
|
|
7
|
+
interface PhaseTiming {
|
|
8
|
+
name: string;
|
|
9
|
+
duration: number;
|
|
10
|
+
percentage: number;
|
|
11
|
+
}
|
|
12
|
+
interface TimingSummary {
|
|
13
|
+
totalMs: number;
|
|
14
|
+
wallClockMs: number;
|
|
15
|
+
phases: PhaseTiming[];
|
|
16
|
+
spans: TimingSpan[];
|
|
17
|
+
metadata: Record<string, string | number | boolean>;
|
|
18
|
+
}
|
|
19
|
+
declare class Timing {
|
|
20
|
+
private spans;
|
|
21
|
+
private activeSpans;
|
|
22
|
+
private startTime;
|
|
23
|
+
private metadata;
|
|
24
|
+
constructor();
|
|
25
|
+
time<T>(name: string, fn: () => T): T;
|
|
26
|
+
timeAsync<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
27
|
+
start(name: string): () => void;
|
|
28
|
+
end(name: string): void;
|
|
29
|
+
setMetadata(key: string, value: string | number | boolean): this;
|
|
30
|
+
addMetadata(data: Record<string, string | number | boolean>): this;
|
|
31
|
+
getElapsedMs(): number;
|
|
32
|
+
summary(): TimingSummary;
|
|
33
|
+
}
|
|
34
|
+
declare function createTiming(): Timing;
|
|
35
|
+
declare function formatDuration(ms: number): string;
|
|
36
|
+
declare function formatPercentage(pct: number): string;
|
|
37
|
+
interface AggregatedStats {
|
|
38
|
+
count: number;
|
|
39
|
+
totalMs: number;
|
|
40
|
+
wallClockMs: number;
|
|
41
|
+
avgMs: number;
|
|
42
|
+
minMs: number;
|
|
43
|
+
maxMs: number;
|
|
44
|
+
phaseStats: Map<string, {
|
|
45
|
+
totalMs: number;
|
|
46
|
+
avgMs: number;
|
|
47
|
+
percentage: number;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
declare class TimingAggregator {
|
|
51
|
+
private summaries;
|
|
52
|
+
private metadata;
|
|
53
|
+
private aggregatorStartTime;
|
|
54
|
+
add(summary: TimingSummary): this;
|
|
55
|
+
setMetadata(key: string, value: string | number | boolean): this;
|
|
56
|
+
getStats(): AggregatedStats;
|
|
57
|
+
formatReport(title?: string): string;
|
|
58
|
+
print(title?: string): void;
|
|
59
|
+
}
|
|
60
|
+
declare function createAggregator(): TimingAggregator;
|
|
61
|
+
declare function formatSingleReport(summary: TimingSummary, title?: string): string;
|
|
62
|
+
declare function printSingleReport(summary: TimingSummary, title?: string): void;
|
|
63
|
+
|
|
64
|
+
export { type AggregatedStats, type PhaseTiming, Timing, TimingAggregator, type TimingSpan, type TimingSummary, createAggregator, createTiming, formatDuration, formatPercentage, formatSingleReport, printSingleReport };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
class Timing {
|
|
2
|
+
spans = [];
|
|
3
|
+
activeSpans = /* @__PURE__ */ new Map();
|
|
4
|
+
startTime = 0;
|
|
5
|
+
metadata = {};
|
|
6
|
+
constructor() {
|
|
7
|
+
this.startTime = performance.now();
|
|
8
|
+
}
|
|
9
|
+
time(name, fn) {
|
|
10
|
+
const start = performance.now();
|
|
11
|
+
try {
|
|
12
|
+
return fn();
|
|
13
|
+
} finally {
|
|
14
|
+
const end = performance.now();
|
|
15
|
+
this.spans.push({
|
|
16
|
+
name,
|
|
17
|
+
startTime: start - this.startTime,
|
|
18
|
+
endTime: end - this.startTime,
|
|
19
|
+
duration: end - start
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async timeAsync(name, fn) {
|
|
24
|
+
const start = performance.now();
|
|
25
|
+
try {
|
|
26
|
+
return await fn();
|
|
27
|
+
} finally {
|
|
28
|
+
const end = performance.now();
|
|
29
|
+
this.spans.push({
|
|
30
|
+
name,
|
|
31
|
+
startTime: start - this.startTime,
|
|
32
|
+
endTime: end - this.startTime,
|
|
33
|
+
duration: end - start
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
start(name) {
|
|
38
|
+
const start = performance.now();
|
|
39
|
+
this.activeSpans.set(name, start);
|
|
40
|
+
return () => {
|
|
41
|
+
this.end(name);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
end(name) {
|
|
45
|
+
const start = this.activeSpans.get(name);
|
|
46
|
+
if (start === void 0) return;
|
|
47
|
+
const end = performance.now();
|
|
48
|
+
this.activeSpans.delete(name);
|
|
49
|
+
this.spans.push({
|
|
50
|
+
name,
|
|
51
|
+
startTime: start - this.startTime,
|
|
52
|
+
endTime: end - this.startTime,
|
|
53
|
+
duration: end - start
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
setMetadata(key, value) {
|
|
57
|
+
this.metadata[key] = value;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
addMetadata(data) {
|
|
61
|
+
Object.assign(this.metadata, data);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
getElapsedMs() {
|
|
65
|
+
return performance.now() - this.startTime;
|
|
66
|
+
}
|
|
67
|
+
summary() {
|
|
68
|
+
const wallClockMs = performance.now() - this.startTime;
|
|
69
|
+
const totalMs = this.spans.reduce((sum, s) => sum + s.duration, 0);
|
|
70
|
+
const phaseMap = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const span of this.spans) {
|
|
72
|
+
phaseMap.set(span.name, (phaseMap.get(span.name) ?? 0) + span.duration);
|
|
73
|
+
}
|
|
74
|
+
const phases = [...phaseMap.entries()].map(
|
|
75
|
+
([name, duration]) => ({
|
|
76
|
+
name,
|
|
77
|
+
duration,
|
|
78
|
+
percentage: totalMs > 0 ? duration / totalMs * 100 : 0
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
return {
|
|
82
|
+
totalMs,
|
|
83
|
+
wallClockMs,
|
|
84
|
+
phases,
|
|
85
|
+
spans: [...this.spans],
|
|
86
|
+
metadata: { ...this.metadata }
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function createTiming() {
|
|
91
|
+
return new Timing();
|
|
92
|
+
}
|
|
93
|
+
function formatDuration(ms) {
|
|
94
|
+
if (ms < 1e3) {
|
|
95
|
+
return `${ms.toFixed(0)}ms`;
|
|
96
|
+
}
|
|
97
|
+
if (ms < 6e4) {
|
|
98
|
+
return `${(ms / 1e3).toFixed(2)}s`;
|
|
99
|
+
}
|
|
100
|
+
const minutes = Math.floor(ms / 6e4);
|
|
101
|
+
const seconds = (ms % 6e4 / 1e3).toFixed(1);
|
|
102
|
+
return `${minutes}m ${seconds}s`;
|
|
103
|
+
}
|
|
104
|
+
function formatPercentage(pct) {
|
|
105
|
+
return `${pct.toFixed(1)}%`;
|
|
106
|
+
}
|
|
107
|
+
class TimingAggregator {
|
|
108
|
+
summaries = [];
|
|
109
|
+
metadata = {};
|
|
110
|
+
aggregatorStartTime = performance.now();
|
|
111
|
+
add(summary) {
|
|
112
|
+
this.summaries.push(summary);
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
setMetadata(key, value) {
|
|
116
|
+
this.metadata[key] = value;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
getStats() {
|
|
120
|
+
if (this.summaries.length === 0) {
|
|
121
|
+
return {
|
|
122
|
+
count: 0,
|
|
123
|
+
totalMs: 0,
|
|
124
|
+
wallClockMs: 0,
|
|
125
|
+
avgMs: 0,
|
|
126
|
+
minMs: 0,
|
|
127
|
+
maxMs: 0,
|
|
128
|
+
phaseStats: /* @__PURE__ */ new Map()
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const wallClockTotals = this.summaries.map((s) => s.wallClockMs);
|
|
132
|
+
const totalMs = wallClockTotals.reduce((a, b) => a + b, 0);
|
|
133
|
+
const wallClockMs = performance.now() - this.aggregatorStartTime;
|
|
134
|
+
const avgMs = totalMs / this.summaries.length;
|
|
135
|
+
const minMs = Math.min(...wallClockTotals);
|
|
136
|
+
const maxMs = Math.max(...wallClockTotals);
|
|
137
|
+
const phaseStats = /* @__PURE__ */ new Map();
|
|
138
|
+
for (const summary of this.summaries) {
|
|
139
|
+
for (const phase of summary.phases) {
|
|
140
|
+
const existing = phaseStats.get(phase.name);
|
|
141
|
+
if (existing) {
|
|
142
|
+
existing.totalMs += phase.duration;
|
|
143
|
+
} else {
|
|
144
|
+
phaseStats.set(phase.name, {
|
|
145
|
+
totalMs: phase.duration,
|
|
146
|
+
avgMs: 0,
|
|
147
|
+
percentage: 0
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const phaseTotalMs = [...phaseStats.values()].reduce(
|
|
153
|
+
(sum, p) => sum + p.totalMs,
|
|
154
|
+
0
|
|
155
|
+
);
|
|
156
|
+
for (const [, stats] of phaseStats) {
|
|
157
|
+
stats.avgMs = stats.totalMs / this.summaries.length;
|
|
158
|
+
stats.percentage = phaseTotalMs > 0 ? stats.totalMs / phaseTotalMs * 100 : 0;
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
count: this.summaries.length,
|
|
162
|
+
totalMs,
|
|
163
|
+
wallClockMs,
|
|
164
|
+
avgMs,
|
|
165
|
+
minMs,
|
|
166
|
+
maxMs,
|
|
167
|
+
phaseStats
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
formatReport(title) {
|
|
171
|
+
const stats = this.getStats();
|
|
172
|
+
const lines = [];
|
|
173
|
+
const divider = "-".repeat(60);
|
|
174
|
+
lines.push(divider);
|
|
175
|
+
lines.push(title ?? "Timing Report");
|
|
176
|
+
lines.push(divider);
|
|
177
|
+
for (const [key, value] of Object.entries(this.metadata)) {
|
|
178
|
+
lines.push(` ${key}: ${value}`);
|
|
179
|
+
}
|
|
180
|
+
if (Object.keys(this.metadata).length > 0) {
|
|
181
|
+
lines.push("");
|
|
182
|
+
}
|
|
183
|
+
lines.push(` Files processed: ${stats.count}`);
|
|
184
|
+
lines.push(` Wall clock time: ${formatDuration(stats.wallClockMs)}`);
|
|
185
|
+
lines.push(` Combined time: ${formatDuration(stats.totalMs)}`);
|
|
186
|
+
lines.push(` Average per file: ${formatDuration(stats.avgMs)}`);
|
|
187
|
+
lines.push(` Fastest: ${formatDuration(stats.minMs)}`);
|
|
188
|
+
lines.push(` Slowest: ${formatDuration(stats.maxMs)}`);
|
|
189
|
+
if (stats.phaseStats.size > 0) {
|
|
190
|
+
lines.push("");
|
|
191
|
+
lines.push(" Time by phase:");
|
|
192
|
+
const sortedPhases = [...stats.phaseStats.entries()].sort(
|
|
193
|
+
(a, b) => b[1].totalMs - a[1].totalMs
|
|
194
|
+
);
|
|
195
|
+
for (const [name, phaseData] of sortedPhases) {
|
|
196
|
+
const pct = formatPercentage(phaseData.percentage);
|
|
197
|
+
const avg = formatDuration(phaseData.avgMs);
|
|
198
|
+
const total = formatDuration(phaseData.totalMs);
|
|
199
|
+
lines.push(
|
|
200
|
+
` ${name.padEnd(20)} ${pct.padStart(6)} avg: ${avg.padStart(8)} total: ${total}`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
lines.push(divider);
|
|
205
|
+
return lines.join("\n");
|
|
206
|
+
}
|
|
207
|
+
print(title) {
|
|
208
|
+
console.log(this.formatReport(title));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function createAggregator() {
|
|
212
|
+
return new TimingAggregator();
|
|
213
|
+
}
|
|
214
|
+
function formatSingleReport(summary, title) {
|
|
215
|
+
const lines = [];
|
|
216
|
+
const divider = "-".repeat(50);
|
|
217
|
+
lines.push(divider);
|
|
218
|
+
lines.push(title ?? "Timing");
|
|
219
|
+
lines.push(divider);
|
|
220
|
+
for (const [key, value] of Object.entries(summary.metadata)) {
|
|
221
|
+
lines.push(` ${key}: ${value}`);
|
|
222
|
+
}
|
|
223
|
+
if (Object.keys(summary.metadata).length > 0) {
|
|
224
|
+
lines.push("");
|
|
225
|
+
}
|
|
226
|
+
lines.push(` Wall clock: ${formatDuration(summary.wallClockMs)}`);
|
|
227
|
+
lines.push(` Active time: ${formatDuration(summary.totalMs)}`);
|
|
228
|
+
if (summary.phases.length > 0) {
|
|
229
|
+
lines.push("");
|
|
230
|
+
const sortedPhases = [...summary.phases].sort(
|
|
231
|
+
(a, b) => b.duration - a.duration
|
|
232
|
+
);
|
|
233
|
+
for (const phase of sortedPhases) {
|
|
234
|
+
const pct = formatPercentage(phase.percentage);
|
|
235
|
+
const dur = formatDuration(phase.duration);
|
|
236
|
+
lines.push(
|
|
237
|
+
` ${phase.name.padEnd(20)} ${pct.padStart(6)} ${dur.padStart(10)}`
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
lines.push(divider);
|
|
242
|
+
return lines.join("\n");
|
|
243
|
+
}
|
|
244
|
+
function printSingleReport(summary, title) {
|
|
245
|
+
console.log(formatSingleReport(summary, title));
|
|
246
|
+
}
|
|
247
|
+
export {
|
|
248
|
+
Timing,
|
|
249
|
+
TimingAggregator,
|
|
250
|
+
createAggregator,
|
|
251
|
+
createTiming,
|
|
252
|
+
formatDuration,
|
|
253
|
+
formatPercentage,
|
|
254
|
+
formatSingleReport,
|
|
255
|
+
printSingleReport
|
|
256
|
+
};
|