agentfootprint 9.7.0 → 9.9.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/dist/adapters/identity/vault.js +336 -0
- package/dist/adapters/identity/vault.js.map +1 -0
- package/dist/adapters/observability/audit.js +2 -28
- package/dist/adapters/observability/audit.js.map +1 -1
- package/dist/adapters/observability/file.js +307 -0
- package/dist/adapters/observability/file.js.map +1 -0
- package/dist/adapters/observability/githubBugReporter.js +461 -0
- package/dist/adapters/observability/githubBugReporter.js.map +1 -0
- package/dist/adapters/observability/githubDeviceSignIn.js +263 -0
- package/dist/adapters/observability/githubDeviceSignIn.js.map +1 -0
- package/dist/esm/adapters/identity/vault.d.ts +146 -0
- package/dist/esm/adapters/identity/vault.js +332 -0
- package/dist/esm/adapters/identity/vault.js.map +1 -0
- package/dist/esm/adapters/observability/audit.js +1 -27
- package/dist/esm/adapters/observability/audit.js.map +1 -1
- package/dist/esm/adapters/observability/file.d.ts +145 -0
- package/dist/esm/adapters/observability/file.js +303 -0
- package/dist/esm/adapters/observability/file.js.map +1 -0
- package/dist/esm/adapters/observability/githubBugReporter.d.ts +154 -0
- package/dist/esm/adapters/observability/githubBugReporter.js +457 -0
- package/dist/esm/adapters/observability/githubBugReporter.js.map +1 -0
- package/dist/esm/adapters/observability/githubDeviceSignIn.d.ts +131 -0
- package/dist/esm/adapters/observability/githubDeviceSignIn.js +259 -0
- package/dist/esm/adapters/observability/githubDeviceSignIn.js.map +1 -0
- package/dist/esm/identity.d.ts +1 -0
- package/dist/esm/identity.js +4 -0
- package/dist/esm/identity.js.map +1 -1
- package/dist/esm/lib/bug-report/build.d.ts +103 -0
- package/dist/esm/lib/bug-report/build.js +648 -0
- package/dist/esm/lib/bug-report/build.js.map +1 -0
- package/dist/esm/lib/bug-report/index.d.ts +14 -0
- package/dist/esm/lib/bug-report/index.js +13 -0
- package/dist/esm/lib/bug-report/index.js.map +1 -0
- package/dist/esm/lib/bug-report/transcript.d.ts +61 -0
- package/dist/esm/lib/bug-report/transcript.js +124 -0
- package/dist/esm/lib/bug-report/transcript.js.map +1 -0
- package/dist/esm/lib/bug-report/types.d.ts +206 -0
- package/dist/esm/lib/bug-report/types.js +12 -0
- package/dist/esm/lib/bug-report/types.js.map +1 -0
- package/dist/esm/lib/bug-report/zip.d.ts +71 -0
- package/dist/esm/lib/bug-report/zip.js +202 -0
- package/dist/esm/lib/bug-report/zip.js.map +1 -0
- package/dist/esm/lib/libraryVersion.d.ts +23 -0
- package/dist/esm/lib/libraryVersion.js +46 -0
- package/dist/esm/lib/libraryVersion.js.map +1 -0
- package/dist/esm/lib/trace-toolpack/openRecording.d.ts +17 -0
- package/dist/esm/lib/trace-toolpack/openRecording.js +8 -2
- package/dist/esm/lib/trace-toolpack/openRecording.js.map +1 -1
- package/dist/esm/observability-providers.d.ts +6 -1
- package/dist/esm/observability-providers.js +16 -1
- package/dist/esm/observability-providers.js.map +1 -1
- package/dist/esm/observe.d.ts +1 -0
- package/dist/esm/observe.js +6 -0
- package/dist/esm/observe.js.map +1 -1
- package/dist/identity.js +6 -1
- package/dist/identity.js.map +1 -1
- package/dist/lib/bug-report/build.js +656 -0
- package/dist/lib/bug-report/build.js.map +1 -0
- package/dist/lib/bug-report/index.js +18 -0
- package/dist/lib/bug-report/index.js.map +1 -0
- package/dist/lib/bug-report/transcript.js +128 -0
- package/dist/lib/bug-report/transcript.js.map +1 -0
- package/dist/lib/bug-report/types.js +13 -0
- package/dist/lib/bug-report/types.js.map +1 -0
- package/dist/lib/bug-report/zip.js +207 -0
- package/dist/lib/bug-report/zip.js.map +1 -0
- package/dist/lib/libraryVersion.js +51 -0
- package/dist/lib/libraryVersion.js.map +1 -0
- package/dist/lib/trace-toolpack/openRecording.js +9 -2
- package/dist/lib/trace-toolpack/openRecording.js.map +1 -1
- package/dist/observability-providers.js +20 -2
- package/dist/observability-providers.js.map +1 -1
- package/dist/observe.js +14 -6
- package/dist/observe.js.map +1 -1
- package/dist/types/adapters/identity/vault.d.ts +147 -0
- package/dist/types/adapters/identity/vault.d.ts.map +1 -0
- package/dist/types/adapters/observability/audit.d.ts.map +1 -1
- package/dist/types/adapters/observability/file.d.ts +146 -0
- package/dist/types/adapters/observability/file.d.ts.map +1 -0
- package/dist/types/adapters/observability/githubBugReporter.d.ts +155 -0
- package/dist/types/adapters/observability/githubBugReporter.d.ts.map +1 -0
- package/dist/types/adapters/observability/githubDeviceSignIn.d.ts +132 -0
- package/dist/types/adapters/observability/githubDeviceSignIn.d.ts.map +1 -0
- package/dist/types/identity.d.ts +1 -0
- package/dist/types/identity.d.ts.map +1 -1
- package/dist/types/lib/bug-report/build.d.ts +104 -0
- package/dist/types/lib/bug-report/build.d.ts.map +1 -0
- package/dist/types/lib/bug-report/index.d.ts +15 -0
- package/dist/types/lib/bug-report/index.d.ts.map +1 -0
- package/dist/types/lib/bug-report/transcript.d.ts +62 -0
- package/dist/types/lib/bug-report/transcript.d.ts.map +1 -0
- package/dist/types/lib/bug-report/types.d.ts +207 -0
- package/dist/types/lib/bug-report/types.d.ts.map +1 -0
- package/dist/types/lib/bug-report/zip.d.ts +72 -0
- package/dist/types/lib/bug-report/zip.d.ts.map +1 -0
- package/dist/types/lib/libraryVersion.d.ts +24 -0
- package/dist/types/lib/libraryVersion.d.ts.map +1 -0
- package/dist/types/lib/trace-toolpack/openRecording.d.ts +17 -0
- package/dist/types/lib/trace-toolpack/openRecording.d.ts.map +1 -1
- package/dist/types/observability-providers.d.ts +6 -1
- package/dist/types/observability-providers.d.ts.map +1 -1
- package/dist/types/observe.d.ts +1 -0
- package/dist/types/observe.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* fileObservability — the typed event stream, one JSON line per event, in a
|
|
4
|
+
* local file.
|
|
5
|
+
*
|
|
6
|
+
* The sink for the shop that has no collector. Every other adapter in this
|
|
7
|
+
* folder ships somewhere: CloudWatch, X-Ray, an OTLP endpoint. A great many
|
|
8
|
+
* on-premises deployments have none of those — they have a directory, a log
|
|
9
|
+
* shipper (Filebeat, Fluent Bit, Vector, `promtail`, `journald`, or a person
|
|
10
|
+
* with `grep`), and a rule that nothing leaves the network. NDJSON on disk is
|
|
11
|
+
* the format all of those already read, so the sink is the file.
|
|
12
|
+
*
|
|
13
|
+
* Zero dependencies: `node:fs`, lazily required at construction so merely
|
|
14
|
+
* importing `agentfootprint/observe` stays browser-safe (this factory is
|
|
15
|
+
* Node-only; calling it in a browser throws by name).
|
|
16
|
+
*
|
|
17
|
+
* ## The line
|
|
18
|
+
*
|
|
19
|
+
* One `JSON.stringify(event)` per line, newline-terminated, appended in
|
|
20
|
+
* dispatch order — the SAME envelope `cloudwatchObservability` puts in a log
|
|
21
|
+
* event, so a query written against one reads the other:
|
|
22
|
+
*
|
|
23
|
+
* ```jsonl
|
|
24
|
+
* {"type":"agentfootprint.agent.turn_start","payload":{…},"meta":{"runId":"…","sessionId":"…"}}
|
|
25
|
+
* {"type":"agentfootprint.stream.tool_end","payload":{…},"meta":{…}}
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Nothing is summarized, bounded or redacted on the way out. **A payload that
|
|
29
|
+
* must not be on that disk must not reach this strategy** — narrow it with
|
|
30
|
+
* `eventTypes` / `tier` / `sampleRate`, or apply a footprintjs
|
|
31
|
+
* `RedactionPolicy` upstream, exactly as with every other sink. (For a bounded
|
|
32
|
+
* record by construction, `auditExport({ payloadMode: 'bounded' })` is the
|
|
33
|
+
* adapter that does that job.)
|
|
34
|
+
*
|
|
35
|
+
* ## Buffered, not synchronous
|
|
36
|
+
*
|
|
37
|
+
* `exportEvent` is sync and never touches the disk: it serializes, buffers, and
|
|
38
|
+
* returns. Batches are appended asynchronously on a size trigger
|
|
39
|
+
* (`maxBufferEvents` / `maxBufferBytes`), on a timer (`flushIntervalMs`), and on
|
|
40
|
+
* `flush()`. A hard kill therefore loses at most the buffer — the price of not
|
|
41
|
+
* making telemetry a term in agent-loop latency. Call `flush()` (or
|
|
42
|
+
* `agent.shutdown()`, which does) at process end; see the 8.12.0 lifecycle laws
|
|
43
|
+
* on {@link BaseStrategy.flush}.
|
|
44
|
+
*
|
|
45
|
+
* ## Rotation is ONE generation, and that is deliberate
|
|
46
|
+
*
|
|
47
|
+
* With `maxBytes` set, a batch that would push the file past the ceiling first
|
|
48
|
+
* renames it to `<path>.1` — **replacing any previous `.1`** — and starts a
|
|
49
|
+
* fresh file. That is the whole policy. There is no `.2`, no compression, no
|
|
50
|
+
* time-based schedule, no cross-process coordination (two processes writing one
|
|
51
|
+
* file each keep their own byte count and will both rotate it). It exists so an
|
|
52
|
+
* unattended agent cannot fill a disk, and for nothing else: **retention is a
|
|
53
|
+
* log-management daemon's job**, and `logrotate` with `copytruncate`, Fluent Bit,
|
|
54
|
+
* or a systemd timer will do it properly. Omit `maxBytes` — the default — and
|
|
55
|
+
* this adapter never renames anything, which is the right choice when a real
|
|
56
|
+
* rotator already owns the file.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { fileObservability } from 'agentfootprint/observe';
|
|
61
|
+
*
|
|
62
|
+
* const telemetry = agent.enable.observability({
|
|
63
|
+
* strategy: fileObservability({
|
|
64
|
+
* path: '/var/log/agentfootprint/events.ndjson',
|
|
65
|
+
* maxBytes: 64 * 1024 * 1024, // safety ceiling; logrotate owns retention
|
|
66
|
+
* }),
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // … run …
|
|
70
|
+
* await agent.shutdown(); // flushes + stops everything enabled
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
74
|
+
exports.fileObservability = void 0;
|
|
75
|
+
const lazyRequire_js_1 = require("../../lib/lazyRequire.js");
|
|
76
|
+
const deliveryErrors_js_1 = require("./deliveryErrors.js");
|
|
77
|
+
// ─── Public factory ──────────────────────────────────────────────────
|
|
78
|
+
/**
|
|
79
|
+
* NDJSON-to-a-local-file observability strategy. See
|
|
80
|
+
* {@link FileObservabilityOptions} for the per-option contract, and this
|
|
81
|
+
* module's docstring for the rotation policy and what is NOT bounded.
|
|
82
|
+
*/
|
|
83
|
+
function fileObservability(opts) {
|
|
84
|
+
const strategyName = 'file';
|
|
85
|
+
if (!opts.path || typeof opts.path !== 'string' || opts.path.trim() === '') {
|
|
86
|
+
throw new TypeError(`[${strategyName}Observability] \`path\` is required — the file this sink writes. ` +
|
|
87
|
+
`Pass one, e.g. '/var/log/agentfootprint/events.ndjson'. There is no default: ` +
|
|
88
|
+
`where a run's telemetry lands on your disk is not a decision this library makes.`);
|
|
89
|
+
}
|
|
90
|
+
if (opts.maxBytes !== undefined && !(opts.maxBytes > 0)) {
|
|
91
|
+
throw new TypeError(`[${strategyName}Observability] \`maxBytes\` must be a positive number of bytes ` +
|
|
92
|
+
`(got ${String(opts.maxBytes)}). Omit it for no rotation at all, which is the ` +
|
|
93
|
+
`right choice when logrotate or a log shipper already owns '${opts.path}'.`);
|
|
94
|
+
}
|
|
95
|
+
const path = opts.path;
|
|
96
|
+
const rotatedPath = `${path}.1`;
|
|
97
|
+
const maxBufferEvents = opts.maxBufferEvents ?? 100;
|
|
98
|
+
const maxBufferBytes = opts.maxBufferBytes ?? 65_536;
|
|
99
|
+
const flushIntervalMs = opts.flushIntervalMs ?? 1000;
|
|
100
|
+
const fs = opts._fs ?? createNodeFileSink(strategyName);
|
|
101
|
+
// Claim the file NOW. Two things this buys, both worth the syscall:
|
|
102
|
+
// 1. an unwritable path (no directory, no permission, a directory where a
|
|
103
|
+
// file should be, a read-only mount) is refused at construction, where
|
|
104
|
+
// the caller can still read the message;
|
|
105
|
+
// 2. `statSync` below gives the rotation counter a true starting size, so a
|
|
106
|
+
// restart appends to an existing file rather than believing it is empty.
|
|
107
|
+
let bytesOnDisk = 0;
|
|
108
|
+
try {
|
|
109
|
+
const dir = parentDir(path);
|
|
110
|
+
if (dir)
|
|
111
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
112
|
+
fs.appendFileSync(path, '');
|
|
113
|
+
bytesOnDisk = fs.statSync(path).size;
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
throw new Error(`[${strategyName}Observability] cannot write '${path}': ${errorMessage(err)}. ` +
|
|
117
|
+
`The parent directory is created for you; a failure here means the path is a ` +
|
|
118
|
+
`directory, the mount is read-only, or the process user lacks permission. ` +
|
|
119
|
+
`Fix the path or the permission — this sink refuses to start rather than ` +
|
|
120
|
+
`silently drop every event.`);
|
|
121
|
+
}
|
|
122
|
+
// Buffered lines — drained by `flush()` / size trigger / timer.
|
|
123
|
+
const buffer = [];
|
|
124
|
+
let bufferBytes = 0;
|
|
125
|
+
let lastFlushPromise = Promise.resolve();
|
|
126
|
+
let timer;
|
|
127
|
+
let stopped = false;
|
|
128
|
+
// The fallback when the consumer wires nothing. Rate-limited; a
|
|
129
|
+
// consumer-supplied sink is not.
|
|
130
|
+
const consoleSink = (0, deliveryErrors_js_1.rateLimitedConsoleSink)(strategyName);
|
|
131
|
+
function scheduleTimedFlush() {
|
|
132
|
+
if (timer || flushIntervalMs <= 0 || stopped)
|
|
133
|
+
return;
|
|
134
|
+
timer = setTimeout(() => {
|
|
135
|
+
timer = undefined;
|
|
136
|
+
void doFlush();
|
|
137
|
+
}, flushIntervalMs);
|
|
138
|
+
// Never hold the process open for telemetry. `unref` exists on Node's
|
|
139
|
+
// Timeout and not on the browser's number — feature-detected, so a
|
|
140
|
+
// non-Node runtime with an injected `_fs` still works.
|
|
141
|
+
timer.unref?.();
|
|
142
|
+
}
|
|
143
|
+
/** Route a delivery failure through whatever `_onError` IS RIGHT NOW —
|
|
144
|
+
* reading it at call time, so a consumer who assigns `_onError` after
|
|
145
|
+
* construction still receives them (the 8.11.0 fix). */
|
|
146
|
+
function reportFailure(err) {
|
|
147
|
+
strategy._onError?.(err);
|
|
148
|
+
}
|
|
149
|
+
/** ONE generation. A file already at or over the ceiling is renamed to
|
|
150
|
+
* `<path>.1` (replacing any previous `.1`) and the counter resets. A batch
|
|
151
|
+
* bigger than the whole ceiling is still written — truncating a run's
|
|
152
|
+
* telemetry to fit a dial nobody set for that purpose would be worse. */
|
|
153
|
+
async function rotateIfNeeded(incomingBytes) {
|
|
154
|
+
const ceiling = opts.maxBytes;
|
|
155
|
+
if (ceiling === undefined)
|
|
156
|
+
return;
|
|
157
|
+
if (bytesOnDisk === 0)
|
|
158
|
+
return;
|
|
159
|
+
if (bytesOnDisk + incomingBytes <= ceiling)
|
|
160
|
+
return;
|
|
161
|
+
await fs.rename(path, rotatedPath);
|
|
162
|
+
bytesOnDisk = 0;
|
|
163
|
+
}
|
|
164
|
+
async function doFlush() {
|
|
165
|
+
// `stopped` is deliberately NOT a guard here — same stance as the AWS
|
|
166
|
+
// adapters since 8.11.1. `stop()` stops this strategy ACCEPTING events; it
|
|
167
|
+
// does not authorise throwing away events already accepted, and a `flush()`
|
|
168
|
+
// that cannot make progress after a `stop()` is how shutdown spins forever.
|
|
169
|
+
if (buffer.length === 0)
|
|
170
|
+
return;
|
|
171
|
+
// Snapshot + clear so events emitted during the in-flight write accumulate
|
|
172
|
+
// into the next batch.
|
|
173
|
+
const batch = buffer.splice(0);
|
|
174
|
+
const batchBytes = bufferBytes;
|
|
175
|
+
bufferBytes = 0;
|
|
176
|
+
const data = `${batch.join('\n')}\n`;
|
|
177
|
+
try {
|
|
178
|
+
await rotateIfNeeded(batchBytes);
|
|
179
|
+
await fs.appendFile(path, data);
|
|
180
|
+
bytesOnDisk += byteLength(data);
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
reportFailure(new Error(`${batch.length} event(s) dropped writing to '${path}': ${errorMessage(err)}`));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function enqueue(event) {
|
|
187
|
+
if (stopped)
|
|
188
|
+
return;
|
|
189
|
+
// The hot path must not throw (port law). `JSON.stringify` can — a cycle, a
|
|
190
|
+
// BigInt, a throwing getter — and an event that cannot be serialized is a
|
|
191
|
+
// reportable fact, not a reason to break the agent loop.
|
|
192
|
+
let line;
|
|
193
|
+
try {
|
|
194
|
+
line = JSON.stringify(event);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
reportFailure(new Error(`event '${event?.type ?? 'unknown'}' could not be serialized: ` + errorMessage(err)));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
// `JSON.stringify` returns undefined for an undefined input — nothing to
|
|
201
|
+
// write, and a bare "undefined" line would corrupt the NDJSON stream.
|
|
202
|
+
if (line === undefined)
|
|
203
|
+
return;
|
|
204
|
+
buffer.push(line);
|
|
205
|
+
bufferBytes += byteLength(line) + 1; // + the newline this line will carry
|
|
206
|
+
if (buffer.length >= maxBufferEvents || bufferBytes >= maxBufferBytes) {
|
|
207
|
+
// Size trigger. Chain onto the last write rather than racing it — the
|
|
208
|
+
// file's line order IS the dispatch order, and that is the only thing an
|
|
209
|
+
// offline reader can rely on.
|
|
210
|
+
lastFlushPromise = lastFlushPromise.then(doFlush, doFlush);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
scheduleTimedFlush();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const strategy = {
|
|
217
|
+
name: strategyName,
|
|
218
|
+
capabilities: { events: true, logs: true },
|
|
219
|
+
...(opts.eventTypes && { relevantEventTypes: opts.eventTypes }),
|
|
220
|
+
exportEvent: enqueue,
|
|
221
|
+
/**
|
|
222
|
+
* Write what is buffered. Called for you on shutdown (8.12.0) — by the
|
|
223
|
+
* handle `enable.observability()` returns, by `agent.shutdown()`, and by a
|
|
224
|
+
* `standingAgent` closing. Safe at any time, including after `stop()`.
|
|
225
|
+
*/
|
|
226
|
+
async flush() {
|
|
227
|
+
// BOUNDED BY CONSTRUCTION — every pass must remove at least one buffered
|
|
228
|
+
// line; a pass that removes none ends the drain instead of retrying. The
|
|
229
|
+
// shape the CloudWatch adapter arrived at in 8.11.1, for the same reason:
|
|
230
|
+
// a drain that cannot finish must return, never spin.
|
|
231
|
+
for (;;) {
|
|
232
|
+
const pending = buffer.length;
|
|
233
|
+
lastFlushPromise = lastFlushPromise.then(doFlush, doFlush);
|
|
234
|
+
await lastFlushPromise;
|
|
235
|
+
if (buffer.length === 0)
|
|
236
|
+
return;
|
|
237
|
+
if (buffer.length >= pending)
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
/** Clear the timer and stop accepting events. Terminal: there is no
|
|
242
|
+
* restart. What it does NOT do is discard the buffer — `flush()` after
|
|
243
|
+
* `stop()` still writes it. */
|
|
244
|
+
stop() {
|
|
245
|
+
stopped = true;
|
|
246
|
+
if (timer) {
|
|
247
|
+
clearTimeout(timer);
|
|
248
|
+
timer = undefined;
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
/** Where failures go. Two callers: the dispatch layer (when `exportEvent`
|
|
252
|
+
* itself throws) and this adapter's own write path. */
|
|
253
|
+
_onError(err, event) {
|
|
254
|
+
(opts.onError ?? consoleSink)(err, event);
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
return strategy;
|
|
258
|
+
}
|
|
259
|
+
exports.fileObservability = fileObservability;
|
|
260
|
+
// ─── node:fs binding (lazy) ──────────────────────────────────────────
|
|
261
|
+
/**
|
|
262
|
+
* Bind {@link FileSinkFs} to `node:fs`. Lazily required so that importing
|
|
263
|
+
* `agentfootprint/observe` in a browser bundle never resolves `node:fs` — only
|
|
264
|
+
* CALLING this factory does, and a runtime without it is refused by name.
|
|
265
|
+
*/
|
|
266
|
+
function createNodeFileSink(strategyName) {
|
|
267
|
+
let mod;
|
|
268
|
+
try {
|
|
269
|
+
mod = (0, lazyRequire_js_1.lazyRequire)('node:fs');
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
throw new Error(`[${strategyName}Observability] needs \`node:fs\`, and this runtime has none. ` +
|
|
273
|
+
`It is a Node-only sink by definition — a browser has no local file to append to. ` +
|
|
274
|
+
`In a browser, ship events over your own transport, or pass \`_fs\` to write ` +
|
|
275
|
+
`somewhere you control.`);
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
mkdirSync: (dir, options) => void mod.mkdirSync(dir, options),
|
|
279
|
+
appendFileSync: (file, data) => mod.appendFileSync(file, data),
|
|
280
|
+
statSync: (file) => mod.statSync(file),
|
|
281
|
+
appendFile: (file, data) => mod.promises.appendFile(file, data),
|
|
282
|
+
rename: (from, to) => mod.promises.rename(from, to),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
// ─── Small helpers ───────────────────────────────────────────────────
|
|
286
|
+
function errorMessage(err) {
|
|
287
|
+
return err instanceof Error ? err.message : String(err);
|
|
288
|
+
}
|
|
289
|
+
/** UTF-8 byte length. `Buffer` where there is one, `TextEncoder` otherwise —
|
|
290
|
+
* the byte count decides rotation, so a multi-byte prompt must not be counted
|
|
291
|
+
* as its character length. */
|
|
292
|
+
function byteLength(s) {
|
|
293
|
+
const B = globalThis.Buffer;
|
|
294
|
+
if (B)
|
|
295
|
+
return B.byteLength(s, 'utf8');
|
|
296
|
+
return new TextEncoder().encode(s).length;
|
|
297
|
+
}
|
|
298
|
+
/** The directory part of a path, POSIX or Windows separators, or `''` for a
|
|
299
|
+
* bare filename (nothing to create). Done by hand rather than through
|
|
300
|
+
* `node:path` so the module has exactly one Node import, behind one seam. */
|
|
301
|
+
function parentDir(file) {
|
|
302
|
+
const idx = Math.max(file.lastIndexOf('/'), file.lastIndexOf('\\'));
|
|
303
|
+
if (idx <= 0)
|
|
304
|
+
return '';
|
|
305
|
+
return file.slice(0, idx);
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/adapters/observability/file.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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