libretto 0.2.7 → 0.3.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/LICENSE +21 -0
- package/package.json +21 -15
- package/skill/SKILL.md +20 -18
- package/skill/code-generation-rules.md +3 -3
- package/skill/integration-approach-selection.md +3 -3
- package/dist/cli/cli.js +0 -209
- package/dist/cli/commands/ai.js +0 -21
- package/dist/cli/commands/browser.js +0 -82
- package/dist/cli/commands/execution.js +0 -461
- package/dist/cli/commands/init.js +0 -95
- package/dist/cli/commands/logs.js +0 -93
- package/dist/cli/commands/snapshot.js +0 -106
- package/dist/cli/core/ai-config.js +0 -149
- package/dist/cli/core/browser.js +0 -648
- package/dist/cli/core/context.js +0 -118
- package/dist/cli/core/pause-signals.js +0 -29
- package/dist/cli/core/session-telemetry.js +0 -491
- package/dist/cli/core/session.js +0 -183
- package/dist/cli/core/snapshot-analyzer.js +0 -492
- package/dist/cli/core/telemetry.js +0 -362
- package/dist/cli/index.js +0 -13
- package/dist/cli/workers/run-integration-runtime.js +0 -227
- package/dist/cli/workers/run-integration-worker-protocol.js +0 -12
- package/dist/cli/workers/run-integration-worker.js +0 -66
- package/dist/index.cjs +0 -116
- package/dist/index.d.cts +0 -21
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -97
- package/dist/runtime/download/download.cjs +0 -70
- package/dist/runtime/download/download.d.cts +0 -35
- package/dist/runtime/download/download.d.ts +0 -35
- package/dist/runtime/download/download.js +0 -45
- package/dist/runtime/download/index.cjs +0 -30
- package/dist/runtime/download/index.d.cts +0 -3
- package/dist/runtime/download/index.d.ts +0 -3
- package/dist/runtime/download/index.js +0 -8
- package/dist/runtime/extract/extract.cjs +0 -88
- package/dist/runtime/extract/extract.d.cts +0 -23
- package/dist/runtime/extract/extract.d.ts +0 -23
- package/dist/runtime/extract/extract.js +0 -64
- package/dist/runtime/extract/index.cjs +0 -28
- package/dist/runtime/extract/index.d.cts +0 -5
- package/dist/runtime/extract/index.d.ts +0 -5
- package/dist/runtime/extract/index.js +0 -4
- package/dist/runtime/network/index.cjs +0 -28
- package/dist/runtime/network/index.d.cts +0 -4
- package/dist/runtime/network/index.d.ts +0 -4
- package/dist/runtime/network/index.js +0 -6
- package/dist/runtime/network/network.cjs +0 -91
- package/dist/runtime/network/network.d.cts +0 -28
- package/dist/runtime/network/network.d.ts +0 -28
- package/dist/runtime/network/network.js +0 -67
- package/dist/runtime/recovery/agent.cjs +0 -223
- package/dist/runtime/recovery/agent.d.cts +0 -13
- package/dist/runtime/recovery/agent.d.ts +0 -13
- package/dist/runtime/recovery/agent.js +0 -199
- package/dist/runtime/recovery/errors.cjs +0 -124
- package/dist/runtime/recovery/errors.d.cts +0 -31
- package/dist/runtime/recovery/errors.d.ts +0 -31
- package/dist/runtime/recovery/errors.js +0 -100
- package/dist/runtime/recovery/index.cjs +0 -34
- package/dist/runtime/recovery/index.d.cts +0 -7
- package/dist/runtime/recovery/index.d.ts +0 -7
- package/dist/runtime/recovery/index.js +0 -10
- package/dist/runtime/recovery/recovery.cjs +0 -55
- package/dist/runtime/recovery/recovery.d.cts +0 -12
- package/dist/runtime/recovery/recovery.d.ts +0 -12
- package/dist/runtime/recovery/recovery.js +0 -31
- package/dist/shared/config/config.cjs +0 -44
- package/dist/shared/config/config.d.cts +0 -10
- package/dist/shared/config/config.d.ts +0 -10
- package/dist/shared/config/config.js +0 -18
- package/dist/shared/config/index.cjs +0 -32
- package/dist/shared/config/index.d.cts +0 -1
- package/dist/shared/config/index.d.ts +0 -1
- package/dist/shared/config/index.js +0 -10
- package/dist/shared/debug/index.cjs +0 -30
- package/dist/shared/debug/index.d.cts +0 -1
- package/dist/shared/debug/index.d.ts +0 -1
- package/dist/shared/debug/index.js +0 -5
- package/dist/shared/debug/pause.cjs +0 -90
- package/dist/shared/debug/pause.d.cts +0 -16
- package/dist/shared/debug/pause.d.ts +0 -16
- package/dist/shared/debug/pause.js +0 -55
- package/dist/shared/instrumentation/errors.cjs +0 -81
- package/dist/shared/instrumentation/errors.d.cts +0 -12
- package/dist/shared/instrumentation/errors.d.ts +0 -12
- package/dist/shared/instrumentation/errors.js +0 -57
- package/dist/shared/instrumentation/index.cjs +0 -35
- package/dist/shared/instrumentation/index.d.cts +0 -6
- package/dist/shared/instrumentation/index.d.ts +0 -6
- package/dist/shared/instrumentation/index.js +0 -12
- package/dist/shared/instrumentation/instrument.cjs +0 -206
- package/dist/shared/instrumentation/instrument.d.cts +0 -32
- package/dist/shared/instrumentation/instrument.d.ts +0 -32
- package/dist/shared/instrumentation/instrument.js +0 -190
- package/dist/shared/llm/ai-sdk-adapter.cjs +0 -67
- package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
- package/dist/shared/llm/ai-sdk-adapter.d.ts +0 -22
- package/dist/shared/llm/ai-sdk-adapter.js +0 -43
- package/dist/shared/llm/client.cjs +0 -139
- package/dist/shared/llm/client.d.cts +0 -6
- package/dist/shared/llm/client.d.ts +0 -6
- package/dist/shared/llm/client.js +0 -115
- package/dist/shared/llm/index.cjs +0 -31
- package/dist/shared/llm/index.d.cts +0 -5
- package/dist/shared/llm/index.d.ts +0 -5
- package/dist/shared/llm/index.js +0 -6
- package/dist/shared/llm/types.cjs +0 -16
- package/dist/shared/llm/types.d.cts +0 -66
- package/dist/shared/llm/types.d.ts +0 -66
- package/dist/shared/llm/types.js +0 -0
- package/dist/shared/logger/index.cjs +0 -37
- package/dist/shared/logger/index.d.cts +0 -2
- package/dist/shared/logger/index.d.ts +0 -2
- package/dist/shared/logger/index.js +0 -13
- package/dist/shared/logger/logger.cjs +0 -232
- package/dist/shared/logger/logger.d.cts +0 -86
- package/dist/shared/logger/logger.d.ts +0 -86
- package/dist/shared/logger/logger.js +0 -207
- package/dist/shared/logger/sinks.cjs +0 -160
- package/dist/shared/logger/sinks.d.cts +0 -9
- package/dist/shared/logger/sinks.d.ts +0 -9
- package/dist/shared/logger/sinks.js +0 -124
- package/dist/shared/paths/paths.cjs +0 -104
- package/dist/shared/paths/paths.d.cts +0 -10
- package/dist/shared/paths/paths.d.ts +0 -10
- package/dist/shared/paths/paths.js +0 -73
- package/dist/shared/run/api.cjs +0 -28
- package/dist/shared/run/api.d.cts +0 -2
- package/dist/shared/run/api.d.ts +0 -2
- package/dist/shared/run/api.js +0 -4
- package/dist/shared/run/browser.cjs +0 -98
- package/dist/shared/run/browser.d.cts +0 -22
- package/dist/shared/run/browser.d.ts +0 -22
- package/dist/shared/run/browser.js +0 -74
- package/dist/shared/state/index.cjs +0 -38
- package/dist/shared/state/index.d.cts +0 -2
- package/dist/shared/state/index.d.ts +0 -2
- package/dist/shared/state/index.js +0 -16
- package/dist/shared/state/session-state.cjs +0 -85
- package/dist/shared/state/session-state.d.cts +0 -34
- package/dist/shared/state/session-state.d.ts +0 -34
- package/dist/shared/state/session-state.js +0 -56
- package/dist/shared/visualization/ghost-cursor.cjs +0 -174
- package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
- package/dist/shared/visualization/ghost-cursor.d.ts +0 -37
- package/dist/shared/visualization/ghost-cursor.js +0 -145
- package/dist/shared/visualization/highlight.cjs +0 -134
- package/dist/shared/visualization/highlight.d.cts +0 -22
- package/dist/shared/visualization/highlight.d.ts +0 -22
- package/dist/shared/visualization/highlight.js +0 -108
- package/dist/shared/visualization/index.cjs +0 -45
- package/dist/shared/visualization/index.d.cts +0 -3
- package/dist/shared/visualization/index.d.ts +0 -3
- package/dist/shared/visualization/index.js +0 -24
- package/dist/shared/workflow/workflow.cjs +0 -47
- package/dist/shared/workflow/workflow.d.cts +0 -21
- package/dist/shared/workflow/workflow.d.ts +0 -21
- package/dist/shared/workflow/workflow.js +0 -21
|
@@ -1,232 +0,0 @@
|
|
|
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 logger_exports = {};
|
|
20
|
-
__export(logger_exports, {
|
|
21
|
-
Logger: () => Logger,
|
|
22
|
-
defaultLogger: () => defaultLogger
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(logger_exports);
|
|
25
|
-
function generateId() {
|
|
26
|
-
return Math.random().toString(36).substring(2, 15);
|
|
27
|
-
}
|
|
28
|
-
const defaultLogger = {
|
|
29
|
-
info(event, data) {
|
|
30
|
-
console.log(`[INFO] ${event}`, data ?? "");
|
|
31
|
-
},
|
|
32
|
-
warn(event, data) {
|
|
33
|
-
console.warn(`[WARN] ${event}`, data ?? "");
|
|
34
|
-
},
|
|
35
|
-
error(event, data) {
|
|
36
|
-
console.error(`[ERROR] ${event}`, data ?? "");
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const sinkLifecycleState = /* @__PURE__ */ new WeakMap();
|
|
40
|
-
function getSinkLifecycleState(sink) {
|
|
41
|
-
const existingState = sinkLifecycleState.get(sink);
|
|
42
|
-
if (existingState) {
|
|
43
|
-
return existingState;
|
|
44
|
-
}
|
|
45
|
-
const initialState = { closed: false };
|
|
46
|
-
sinkLifecycleState.set(sink, initialState);
|
|
47
|
-
return initialState;
|
|
48
|
-
}
|
|
49
|
-
function isSinkClosedOrClosing(sink) {
|
|
50
|
-
const state = sinkLifecycleState.get(sink);
|
|
51
|
-
return Boolean(state?.closed || state?.closing);
|
|
52
|
-
}
|
|
53
|
-
async function closeSinkOnce(sink) {
|
|
54
|
-
if (!sink.close) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const state = getSinkLifecycleState(sink);
|
|
58
|
-
if (state.closed) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (state.closing) {
|
|
62
|
-
return state.closing;
|
|
63
|
-
}
|
|
64
|
-
state.closing = (async () => {
|
|
65
|
-
try {
|
|
66
|
-
await sink.close?.();
|
|
67
|
-
} catch {
|
|
68
|
-
} finally {
|
|
69
|
-
state.closed = true;
|
|
70
|
-
state.closing = void 0;
|
|
71
|
-
}
|
|
72
|
-
})();
|
|
73
|
-
return state.closing;
|
|
74
|
-
}
|
|
75
|
-
function isObject(value) {
|
|
76
|
-
return typeof value === "object" && value !== null;
|
|
77
|
-
}
|
|
78
|
-
function removeUndefined(data) {
|
|
79
|
-
if (typeof data === "object" && data !== null) {
|
|
80
|
-
return Object.fromEntries(
|
|
81
|
-
Object.entries(data).filter(([_, value]) => value !== void 0)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return data;
|
|
85
|
-
}
|
|
86
|
-
class Logger {
|
|
87
|
-
constructor(scopes = [], sinks = [], scopeData = {}) {
|
|
88
|
-
this.scopes = scopes;
|
|
89
|
-
this.sinks = sinks;
|
|
90
|
-
this.scopeData = scopeData;
|
|
91
|
-
this.prefix = scopes.join(".");
|
|
92
|
-
}
|
|
93
|
-
prefix;
|
|
94
|
-
entry(entry) {
|
|
95
|
-
this.sinks.forEach((sink) => {
|
|
96
|
-
if (isSinkClosedOrClosing(sink)) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
sink.write({
|
|
100
|
-
id: generateId(),
|
|
101
|
-
scope: this.prefix,
|
|
102
|
-
level: entry.level,
|
|
103
|
-
event: entry.event,
|
|
104
|
-
data: removeUndefined({ ...this.scopeData, ...entry.data }),
|
|
105
|
-
options: entry.options
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
log(event, data, options) {
|
|
110
|
-
this.entry({ level: "log", event, data, options });
|
|
111
|
-
}
|
|
112
|
-
error(event, dataOrError, options) {
|
|
113
|
-
const data = dataOrError instanceof Error ? {
|
|
114
|
-
error: {
|
|
115
|
-
type: dataOrError.constructor.name,
|
|
116
|
-
message: dataOrError.message,
|
|
117
|
-
stack: dataOrError.stack || null
|
|
118
|
-
}
|
|
119
|
-
} : isObject(dataOrError) && dataOrError.error instanceof Error ? {
|
|
120
|
-
...dataOrError,
|
|
121
|
-
error: {
|
|
122
|
-
type: dataOrError.error.constructor.name,
|
|
123
|
-
message: dataOrError.error.message,
|
|
124
|
-
stack: dataOrError.error.stack || null
|
|
125
|
-
}
|
|
126
|
-
} : isObject(dataOrError) ? dataOrError : dataOrError !== void 0 ? { error: dataOrError } : void 0;
|
|
127
|
-
this.entry({
|
|
128
|
-
level: "error",
|
|
129
|
-
event,
|
|
130
|
-
data,
|
|
131
|
-
options
|
|
132
|
-
});
|
|
133
|
-
if (dataOrError instanceof Error) {
|
|
134
|
-
return dataOrError;
|
|
135
|
-
}
|
|
136
|
-
if (isObject(dataOrError) && dataOrError.error instanceof Error) {
|
|
137
|
-
return dataOrError.error;
|
|
138
|
-
}
|
|
139
|
-
let message = event;
|
|
140
|
-
if (data !== void 0) {
|
|
141
|
-
try {
|
|
142
|
-
message += "\n" + JSON.stringify(data, void 0, 2);
|
|
143
|
-
} catch {
|
|
144
|
-
message += "\n[Unserializable error data]";
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return new Error(message);
|
|
148
|
-
}
|
|
149
|
-
warn(event, dataOrError, options) {
|
|
150
|
-
const data = dataOrError instanceof Error ? {
|
|
151
|
-
error: {
|
|
152
|
-
type: dataOrError.constructor.name,
|
|
153
|
-
message: dataOrError.message,
|
|
154
|
-
stack: dataOrError.stack || null
|
|
155
|
-
}
|
|
156
|
-
} : isObject(dataOrError) && dataOrError.error instanceof Error ? {
|
|
157
|
-
...dataOrError,
|
|
158
|
-
error: {
|
|
159
|
-
type: dataOrError.error.constructor.name,
|
|
160
|
-
message: dataOrError.error.message,
|
|
161
|
-
stack: dataOrError.error.stack || null
|
|
162
|
-
}
|
|
163
|
-
} : isObject(dataOrError) ? dataOrError : dataOrError !== void 0 ? { error: dataOrError } : void 0;
|
|
164
|
-
this.entry({
|
|
165
|
-
level: "warn",
|
|
166
|
-
event,
|
|
167
|
-
data,
|
|
168
|
-
options
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
info(event, dataOrError, options) {
|
|
172
|
-
const data = dataOrError instanceof Error ? {
|
|
173
|
-
error: {
|
|
174
|
-
type: dataOrError.constructor.name,
|
|
175
|
-
message: dataOrError.message,
|
|
176
|
-
stack: dataOrError.stack || null
|
|
177
|
-
}
|
|
178
|
-
} : isObject(dataOrError) && dataOrError.error instanceof Error ? {
|
|
179
|
-
...dataOrError,
|
|
180
|
-
error: {
|
|
181
|
-
type: dataOrError.error.constructor.name,
|
|
182
|
-
message: dataOrError.error.message,
|
|
183
|
-
stack: dataOrError.error.stack || null
|
|
184
|
-
}
|
|
185
|
-
} : isObject(dataOrError) ? dataOrError : dataOrError !== void 0 ? { error: dataOrError } : void 0;
|
|
186
|
-
this.entry({
|
|
187
|
-
level: "info",
|
|
188
|
-
event,
|
|
189
|
-
data,
|
|
190
|
-
options
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
withScope(scope, context = {}) {
|
|
194
|
-
return new Logger([...this.scopes, scope], this.sinks, {
|
|
195
|
-
...this.scopeData,
|
|
196
|
-
...context
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
withContext(context) {
|
|
200
|
-
return new Logger(this.scopes, this.sinks, {
|
|
201
|
-
...this.scopeData,
|
|
202
|
-
...context
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
withSink(sink) {
|
|
206
|
-
return new Logger(this.scopes, [...this.sinks, sink]);
|
|
207
|
-
}
|
|
208
|
-
async flush() {
|
|
209
|
-
for (let i = this.sinks.length - 1; i >= 0; i--) {
|
|
210
|
-
const sink = this.sinks[i];
|
|
211
|
-
if (!sink) continue;
|
|
212
|
-
if (isSinkClosedOrClosing(sink)) continue;
|
|
213
|
-
try {
|
|
214
|
-
await sink.flush?.();
|
|
215
|
-
} catch {
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
async close() {
|
|
220
|
-
await this.flush();
|
|
221
|
-
for (let i = this.sinks.length - 1; i >= 0; i--) {
|
|
222
|
-
const sink = this.sinks[i];
|
|
223
|
-
if (!sink) continue;
|
|
224
|
-
await closeSinkOnce(sink);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
-
0 && (module.exports = {
|
|
230
|
-
Logger,
|
|
231
|
-
defaultLogger
|
|
232
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
type LogOptions = {
|
|
2
|
-
timestamp?: Date;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* Minimal logger interface accepted by public-facing runtime functions.
|
|
6
|
-
* Any logger with info/warn/error methods satisfies this — no need to
|
|
7
|
-
* implement withScope, withContext, flush, etc.
|
|
8
|
-
*/
|
|
9
|
-
type MinimalLogger = {
|
|
10
|
-
info: (event: string, data?: any) => void;
|
|
11
|
-
warn: (event: string, data?: any) => void;
|
|
12
|
-
error: (event: string, data?: any) => any;
|
|
13
|
-
};
|
|
14
|
-
/** Default console logger used when callers omit the logger option. */
|
|
15
|
-
declare const defaultLogger: MinimalLogger;
|
|
16
|
-
type LoggerApi = {
|
|
17
|
-
log: (event: string, data?: Record<string, any>, options?: LogOptions) => void;
|
|
18
|
-
/**
|
|
19
|
-
* Logs an error and returns an Error object that can be thrown
|
|
20
|
-
*
|
|
21
|
-
* either pass in an Error directly as data or as { error: Error, ...other_data }
|
|
22
|
-
*/
|
|
23
|
-
error: (event: string, data?: Error | ({
|
|
24
|
-
error: Error;
|
|
25
|
-
} & Record<string, any>) | unknown, options?: LogOptions) => Error;
|
|
26
|
-
warn: (event: string, data?: Error | ({
|
|
27
|
-
error: Error;
|
|
28
|
-
} & Record<string, any>) | unknown, options?: LogOptions) => void;
|
|
29
|
-
info: (event: string, data?: Error | ({
|
|
30
|
-
error: Error;
|
|
31
|
-
} & Record<string, any>) | unknown, options?: LogOptions) => void;
|
|
32
|
-
/**
|
|
33
|
-
* Context passed in will be attached to all entries in this scope.
|
|
34
|
-
*/
|
|
35
|
-
withScope: (scope: string, context?: Record<string, any>) => LoggerApi;
|
|
36
|
-
/**
|
|
37
|
-
* Context passed in will be attached to all entries.
|
|
38
|
-
*/
|
|
39
|
-
withContext: (context: Record<string, any>) => LoggerApi;
|
|
40
|
-
/**
|
|
41
|
-
* Flushes all sinks in reverse order (most recently added first).
|
|
42
|
-
*/
|
|
43
|
-
flush: () => Promise<void>;
|
|
44
|
-
};
|
|
45
|
-
type LoggerSink = {
|
|
46
|
-
write: (args: {
|
|
47
|
-
id: string;
|
|
48
|
-
scope: string;
|
|
49
|
-
level: "log" | "error" | "warn" | "info";
|
|
50
|
-
event: string;
|
|
51
|
-
data: Record<string, any>;
|
|
52
|
-
options?: LogOptions;
|
|
53
|
-
}) => void;
|
|
54
|
-
flush?: () => Promise<void>;
|
|
55
|
-
close?: () => Promise<void>;
|
|
56
|
-
};
|
|
57
|
-
declare class Logger implements LoggerApi {
|
|
58
|
-
private readonly scopes;
|
|
59
|
-
private readonly sinks;
|
|
60
|
-
private readonly scopeData;
|
|
61
|
-
private readonly prefix;
|
|
62
|
-
constructor(scopes?: string[], sinks?: LoggerSink[], scopeData?: Record<string, any>);
|
|
63
|
-
entry(entry: {
|
|
64
|
-
level: "log" | "error" | "warn" | "info";
|
|
65
|
-
event: string;
|
|
66
|
-
data?: Record<string, any>;
|
|
67
|
-
options?: LogOptions;
|
|
68
|
-
}): void;
|
|
69
|
-
log(event: string, data?: Record<string, any>, options?: LogOptions): void;
|
|
70
|
-
error(event: string, dataOrError?: Error | ({
|
|
71
|
-
error: Error;
|
|
72
|
-
} & Record<string, any>) | unknown, options?: LogOptions): Error;
|
|
73
|
-
warn(event: string, dataOrError?: Error | ({
|
|
74
|
-
error: Error;
|
|
75
|
-
} & Record<string, any>) | unknown, options?: LogOptions): void;
|
|
76
|
-
info(event: string, dataOrError?: Error | ({
|
|
77
|
-
error: Error;
|
|
78
|
-
} & Record<string, any>) | unknown, options?: LogOptions): void;
|
|
79
|
-
withScope(scope: string, context?: Record<string, any>): LoggerApi;
|
|
80
|
-
withContext(context: Record<string, any>): LoggerApi;
|
|
81
|
-
withSink(sink: LoggerSink): Logger;
|
|
82
|
-
flush(): Promise<void>;
|
|
83
|
-
close(): Promise<void>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { type LogOptions, Logger, type LoggerApi, type LoggerSink, type MinimalLogger, defaultLogger };
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
type LogOptions = {
|
|
2
|
-
timestamp?: Date;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* Minimal logger interface accepted by public-facing runtime functions.
|
|
6
|
-
* Any logger with info/warn/error methods satisfies this — no need to
|
|
7
|
-
* implement withScope, withContext, flush, etc.
|
|
8
|
-
*/
|
|
9
|
-
type MinimalLogger = {
|
|
10
|
-
info: (event: string, data?: any) => void;
|
|
11
|
-
warn: (event: string, data?: any) => void;
|
|
12
|
-
error: (event: string, data?: any) => any;
|
|
13
|
-
};
|
|
14
|
-
/** Default console logger used when callers omit the logger option. */
|
|
15
|
-
declare const defaultLogger: MinimalLogger;
|
|
16
|
-
type LoggerApi = {
|
|
17
|
-
log: (event: string, data?: Record<string, any>, options?: LogOptions) => void;
|
|
18
|
-
/**
|
|
19
|
-
* Logs an error and returns an Error object that can be thrown
|
|
20
|
-
*
|
|
21
|
-
* either pass in an Error directly as data or as { error: Error, ...other_data }
|
|
22
|
-
*/
|
|
23
|
-
error: (event: string, data?: Error | ({
|
|
24
|
-
error: Error;
|
|
25
|
-
} & Record<string, any>) | unknown, options?: LogOptions) => Error;
|
|
26
|
-
warn: (event: string, data?: Error | ({
|
|
27
|
-
error: Error;
|
|
28
|
-
} & Record<string, any>) | unknown, options?: LogOptions) => void;
|
|
29
|
-
info: (event: string, data?: Error | ({
|
|
30
|
-
error: Error;
|
|
31
|
-
} & Record<string, any>) | unknown, options?: LogOptions) => void;
|
|
32
|
-
/**
|
|
33
|
-
* Context passed in will be attached to all entries in this scope.
|
|
34
|
-
*/
|
|
35
|
-
withScope: (scope: string, context?: Record<string, any>) => LoggerApi;
|
|
36
|
-
/**
|
|
37
|
-
* Context passed in will be attached to all entries.
|
|
38
|
-
*/
|
|
39
|
-
withContext: (context: Record<string, any>) => LoggerApi;
|
|
40
|
-
/**
|
|
41
|
-
* Flushes all sinks in reverse order (most recently added first).
|
|
42
|
-
*/
|
|
43
|
-
flush: () => Promise<void>;
|
|
44
|
-
};
|
|
45
|
-
type LoggerSink = {
|
|
46
|
-
write: (args: {
|
|
47
|
-
id: string;
|
|
48
|
-
scope: string;
|
|
49
|
-
level: "log" | "error" | "warn" | "info";
|
|
50
|
-
event: string;
|
|
51
|
-
data: Record<string, any>;
|
|
52
|
-
options?: LogOptions;
|
|
53
|
-
}) => void;
|
|
54
|
-
flush?: () => Promise<void>;
|
|
55
|
-
close?: () => Promise<void>;
|
|
56
|
-
};
|
|
57
|
-
declare class Logger implements LoggerApi {
|
|
58
|
-
private readonly scopes;
|
|
59
|
-
private readonly sinks;
|
|
60
|
-
private readonly scopeData;
|
|
61
|
-
private readonly prefix;
|
|
62
|
-
constructor(scopes?: string[], sinks?: LoggerSink[], scopeData?: Record<string, any>);
|
|
63
|
-
entry(entry: {
|
|
64
|
-
level: "log" | "error" | "warn" | "info";
|
|
65
|
-
event: string;
|
|
66
|
-
data?: Record<string, any>;
|
|
67
|
-
options?: LogOptions;
|
|
68
|
-
}): void;
|
|
69
|
-
log(event: string, data?: Record<string, any>, options?: LogOptions): void;
|
|
70
|
-
error(event: string, dataOrError?: Error | ({
|
|
71
|
-
error: Error;
|
|
72
|
-
} & Record<string, any>) | unknown, options?: LogOptions): Error;
|
|
73
|
-
warn(event: string, dataOrError?: Error | ({
|
|
74
|
-
error: Error;
|
|
75
|
-
} & Record<string, any>) | unknown, options?: LogOptions): void;
|
|
76
|
-
info(event: string, dataOrError?: Error | ({
|
|
77
|
-
error: Error;
|
|
78
|
-
} & Record<string, any>) | unknown, options?: LogOptions): void;
|
|
79
|
-
withScope(scope: string, context?: Record<string, any>): LoggerApi;
|
|
80
|
-
withContext(context: Record<string, any>): LoggerApi;
|
|
81
|
-
withSink(sink: LoggerSink): Logger;
|
|
82
|
-
flush(): Promise<void>;
|
|
83
|
-
close(): Promise<void>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { type LogOptions, Logger, type LoggerApi, type LoggerSink, type MinimalLogger, defaultLogger };
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
function generateId() {
|
|
2
|
-
return Math.random().toString(36).substring(2, 15);
|
|
3
|
-
}
|
|
4
|
-
const defaultLogger = {
|
|
5
|
-
info(event, data) {
|
|
6
|
-
console.log(`[INFO] ${event}`, data ?? "");
|
|
7
|
-
},
|
|
8
|
-
warn(event, data) {
|
|
9
|
-
console.warn(`[WARN] ${event}`, data ?? "");
|
|
10
|
-
},
|
|
11
|
-
error(event, data) {
|
|
12
|
-
console.error(`[ERROR] ${event}`, data ?? "");
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const sinkLifecycleState = /* @__PURE__ */ new WeakMap();
|
|
16
|
-
function getSinkLifecycleState(sink) {
|
|
17
|
-
const existingState = sinkLifecycleState.get(sink);
|
|
18
|
-
if (existingState) {
|
|
19
|
-
return existingState;
|
|
20
|
-
}
|
|
21
|
-
const initialState = { closed: false };
|
|
22
|
-
sinkLifecycleState.set(sink, initialState);
|
|
23
|
-
return initialState;
|
|
24
|
-
}
|
|
25
|
-
function isSinkClosedOrClosing(sink) {
|
|
26
|
-
const state = sinkLifecycleState.get(sink);
|
|
27
|
-
return Boolean(state?.closed || state?.closing);
|
|
28
|
-
}
|
|
29
|
-
async function closeSinkOnce(sink) {
|
|
30
|
-
if (!sink.close) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const state = getSinkLifecycleState(sink);
|
|
34
|
-
if (state.closed) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (state.closing) {
|
|
38
|
-
return state.closing;
|
|
39
|
-
}
|
|
40
|
-
state.closing = (async () => {
|
|
41
|
-
try {
|
|
42
|
-
await sink.close?.();
|
|
43
|
-
} catch {
|
|
44
|
-
} finally {
|
|
45
|
-
state.closed = true;
|
|
46
|
-
state.closing = void 0;
|
|
47
|
-
}
|
|
48
|
-
})();
|
|
49
|
-
return state.closing;
|
|
50
|
-
}
|
|
51
|
-
function isObject(value) {
|
|
52
|
-
return typeof value === "object" && value !== null;
|
|
53
|
-
}
|
|
54
|
-
function removeUndefined(data) {
|
|
55
|
-
if (typeof data === "object" && data !== null) {
|
|
56
|
-
return Object.fromEntries(
|
|
57
|
-
Object.entries(data).filter(([_, value]) => value !== void 0)
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
return data;
|
|
61
|
-
}
|
|
62
|
-
class Logger {
|
|
63
|
-
constructor(scopes = [], sinks = [], scopeData = {}) {
|
|
64
|
-
this.scopes = scopes;
|
|
65
|
-
this.sinks = sinks;
|
|
66
|
-
this.scopeData = scopeData;
|
|
67
|
-
this.prefix = scopes.join(".");
|
|
68
|
-
}
|
|
69
|
-
prefix;
|
|
70
|
-
entry(entry) {
|
|
71
|
-
this.sinks.forEach((sink) => {
|
|
72
|
-
if (isSinkClosedOrClosing(sink)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
sink.write({
|
|
76
|
-
id: generateId(),
|
|
77
|
-
scope: this.prefix,
|
|
78
|
-
level: entry.level,
|
|
79
|
-
event: entry.event,
|
|
80
|
-
data: removeUndefined({ ...this.scopeData, ...entry.data }),
|
|
81
|
-
options: entry.options
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
log(event, data, options) {
|
|
86
|
-
this.entry({ level: "log", event, data, options });
|
|
87
|
-
}
|
|
88
|
-
error(event, dataOrError, options) {
|
|
89
|
-
const data = dataOrError instanceof Error ? {
|
|
90
|
-
error: {
|
|
91
|
-
type: dataOrError.constructor.name,
|
|
92
|
-
message: dataOrError.message,
|
|
93
|
-
stack: dataOrError.stack || null
|
|
94
|
-
}
|
|
95
|
-
} : isObject(dataOrError) && dataOrError.error instanceof Error ? {
|
|
96
|
-
...dataOrError,
|
|
97
|
-
error: {
|
|
98
|
-
type: dataOrError.error.constructor.name,
|
|
99
|
-
message: dataOrError.error.message,
|
|
100
|
-
stack: dataOrError.error.stack || null
|
|
101
|
-
}
|
|
102
|
-
} : isObject(dataOrError) ? dataOrError : dataOrError !== void 0 ? { error: dataOrError } : void 0;
|
|
103
|
-
this.entry({
|
|
104
|
-
level: "error",
|
|
105
|
-
event,
|
|
106
|
-
data,
|
|
107
|
-
options
|
|
108
|
-
});
|
|
109
|
-
if (dataOrError instanceof Error) {
|
|
110
|
-
return dataOrError;
|
|
111
|
-
}
|
|
112
|
-
if (isObject(dataOrError) && dataOrError.error instanceof Error) {
|
|
113
|
-
return dataOrError.error;
|
|
114
|
-
}
|
|
115
|
-
let message = event;
|
|
116
|
-
if (data !== void 0) {
|
|
117
|
-
try {
|
|
118
|
-
message += "\n" + JSON.stringify(data, void 0, 2);
|
|
119
|
-
} catch {
|
|
120
|
-
message += "\n[Unserializable error data]";
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return new Error(message);
|
|
124
|
-
}
|
|
125
|
-
warn(event, dataOrError, options) {
|
|
126
|
-
const data = dataOrError instanceof Error ? {
|
|
127
|
-
error: {
|
|
128
|
-
type: dataOrError.constructor.name,
|
|
129
|
-
message: dataOrError.message,
|
|
130
|
-
stack: dataOrError.stack || null
|
|
131
|
-
}
|
|
132
|
-
} : isObject(dataOrError) && dataOrError.error instanceof Error ? {
|
|
133
|
-
...dataOrError,
|
|
134
|
-
error: {
|
|
135
|
-
type: dataOrError.error.constructor.name,
|
|
136
|
-
message: dataOrError.error.message,
|
|
137
|
-
stack: dataOrError.error.stack || null
|
|
138
|
-
}
|
|
139
|
-
} : isObject(dataOrError) ? dataOrError : dataOrError !== void 0 ? { error: dataOrError } : void 0;
|
|
140
|
-
this.entry({
|
|
141
|
-
level: "warn",
|
|
142
|
-
event,
|
|
143
|
-
data,
|
|
144
|
-
options
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
info(event, dataOrError, options) {
|
|
148
|
-
const data = dataOrError instanceof Error ? {
|
|
149
|
-
error: {
|
|
150
|
-
type: dataOrError.constructor.name,
|
|
151
|
-
message: dataOrError.message,
|
|
152
|
-
stack: dataOrError.stack || null
|
|
153
|
-
}
|
|
154
|
-
} : isObject(dataOrError) && dataOrError.error instanceof Error ? {
|
|
155
|
-
...dataOrError,
|
|
156
|
-
error: {
|
|
157
|
-
type: dataOrError.error.constructor.name,
|
|
158
|
-
message: dataOrError.error.message,
|
|
159
|
-
stack: dataOrError.error.stack || null
|
|
160
|
-
}
|
|
161
|
-
} : isObject(dataOrError) ? dataOrError : dataOrError !== void 0 ? { error: dataOrError } : void 0;
|
|
162
|
-
this.entry({
|
|
163
|
-
level: "info",
|
|
164
|
-
event,
|
|
165
|
-
data,
|
|
166
|
-
options
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
withScope(scope, context = {}) {
|
|
170
|
-
return new Logger([...this.scopes, scope], this.sinks, {
|
|
171
|
-
...this.scopeData,
|
|
172
|
-
...context
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
withContext(context) {
|
|
176
|
-
return new Logger(this.scopes, this.sinks, {
|
|
177
|
-
...this.scopeData,
|
|
178
|
-
...context
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
withSink(sink) {
|
|
182
|
-
return new Logger(this.scopes, [...this.sinks, sink]);
|
|
183
|
-
}
|
|
184
|
-
async flush() {
|
|
185
|
-
for (let i = this.sinks.length - 1; i >= 0; i--) {
|
|
186
|
-
const sink = this.sinks[i];
|
|
187
|
-
if (!sink) continue;
|
|
188
|
-
if (isSinkClosedOrClosing(sink)) continue;
|
|
189
|
-
try {
|
|
190
|
-
await sink.flush?.();
|
|
191
|
-
} catch {
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async close() {
|
|
196
|
-
await this.flush();
|
|
197
|
-
for (let i = this.sinks.length - 1; i >= 0; i--) {
|
|
198
|
-
const sink = this.sinks[i];
|
|
199
|
-
if (!sink) continue;
|
|
200
|
-
await closeSinkOnce(sink);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
export {
|
|
205
|
-
Logger,
|
|
206
|
-
defaultLogger
|
|
207
|
-
};
|