libretto 0.4.4 → 0.5.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/README.md +106 -36
- package/dist/cli/cli.js +39 -113
- package/dist/cli/commands/ai.js +1 -1
- package/dist/cli/commands/browser.js +87 -60
- package/dist/cli/commands/execution.js +201 -88
- package/dist/cli/commands/init.js +30 -8
- package/dist/cli/commands/logs.js +5 -6
- package/dist/cli/commands/shared.js +30 -29
- package/dist/cli/commands/snapshot.js +26 -39
- package/dist/cli/core/ai-config.js +9 -2
- package/dist/cli/core/api-snapshot-analyzer.js +15 -5
- package/dist/cli/core/browser.js +141 -33
- package/dist/cli/core/context.js +7 -18
- package/dist/cli/core/session-telemetry.js +5 -2
- package/dist/cli/core/session.js +23 -10
- package/dist/cli/core/snapshot-analyzer.js +16 -33
- package/dist/cli/core/snapshot-api-config.js +2 -6
- package/dist/cli/core/telemetry.js +10 -2
- package/dist/cli/framework/simple-cli.js +45 -25
- package/dist/cli/router.js +14 -21
- package/dist/cli/workers/run-integration-runtime.js +26 -7
- package/dist/cli/workers/run-integration-worker-protocol.js +3 -1
- package/dist/cli/workers/run-integration-worker.js +1 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.js +7 -10
- package/dist/runtime/download/download.js +5 -1
- package/dist/runtime/extract/extract.js +11 -2
- package/dist/runtime/network/network.js +8 -1
- package/dist/runtime/recovery/agent.js +6 -2
- package/dist/runtime/recovery/errors.js +3 -1
- package/dist/runtime/recovery/recovery.js +3 -1
- package/dist/shared/condense-dom/condense-dom.js +6 -13
- package/dist/shared/config/config.d.ts +1 -9
- package/dist/shared/config/config.js +0 -18
- package/dist/shared/config/index.d.ts +2 -1
- package/dist/shared/config/index.js +0 -10
- package/dist/shared/debug/pause.js +9 -3
- package/dist/shared/instrumentation/instrument.js +101 -5
- package/dist/shared/llm/ai-sdk-adapter.js +3 -1
- package/dist/shared/llm/client.js +3 -1
- package/dist/shared/logger/index.js +4 -1
- package/dist/shared/paths/paths.js +2 -1
- package/dist/shared/paths/repo-root.d.ts +3 -0
- package/dist/shared/paths/repo-root.js +24 -0
- package/dist/shared/run/api.js +3 -1
- package/dist/shared/run/browser.js +7 -2
- package/dist/shared/state/session-state.d.ts +2 -1
- package/dist/shared/state/session-state.js +5 -2
- package/dist/shared/visualization/ghost-cursor.js +19 -10
- package/dist/shared/visualization/highlight.js +9 -6
- package/dist/shared/workflow/workflow.d.ts +4 -5
- package/dist/shared/workflow/workflow.js +3 -5
- package/package.json +11 -8
- package/scripts/check-skills-sync.mjs +25 -0
- package/scripts/compare-eval-summary.mjs +47 -0
- package/scripts/postinstall.mjs +26 -17
- package/scripts/prepare-release.sh +97 -0
- package/scripts/skills-libretto.mjs +103 -0
- package/scripts/summarize-evals.mjs +135 -0
- package/scripts/sync-skills.mjs +12 -0
- package/skills/libretto/SKILL.md +130 -377
- package/skills/libretto/references/auth-profiles.md +30 -0
- package/skills/libretto/{code-generation-rules.md → references/code-generation-rules.md} +27 -42
- package/skills/libretto/references/configuration-file-reference.md +53 -0
- package/skills/libretto/references/pages-and-page-targeting.md +29 -0
- package/skills/libretto/references/site-security-review.md +143 -0
- package/src/cli/cli.ts +86 -0
- package/src/cli/commands/ai.ts +35 -0
- package/src/cli/commands/browser.ts +189 -0
- package/src/cli/commands/execution.ts +822 -0
- package/src/cli/commands/init.ts +350 -0
- package/src/cli/commands/logs.ts +128 -0
- package/src/cli/commands/shared.ts +69 -0
- package/src/cli/commands/snapshot.ts +312 -0
- package/src/cli/core/ai-config.ts +264 -0
- package/src/cli/core/api-snapshot-analyzer.ts +108 -0
- package/src/cli/core/browser.ts +976 -0
- package/src/cli/core/context.ts +127 -0
- package/src/cli/core/pause-signals.ts +35 -0
- package/src/cli/core/session-telemetry.ts +564 -0
- package/src/cli/core/session.ts +223 -0
- package/src/cli/core/snapshot-analyzer.ts +855 -0
- package/src/cli/core/snapshot-api-config.ts +231 -0
- package/src/cli/core/telemetry.ts +459 -0
- package/src/cli/framework/simple-cli.ts +1340 -0
- package/src/cli/index.ts +13 -0
- package/src/cli/router.ts +20 -0
- package/src/cli/workers/run-integration-runtime.ts +338 -0
- package/src/cli/workers/run-integration-worker-protocol.ts +16 -0
- package/src/cli/workers/run-integration-worker.ts +72 -0
- package/src/index.ts +127 -0
- package/src/runtime/download/download.ts +104 -0
- package/src/runtime/download/index.ts +7 -0
- package/src/runtime/extract/extract.ts +102 -0
- package/src/runtime/extract/index.ts +1 -0
- package/src/runtime/network/index.ts +5 -0
- package/src/runtime/network/network.ts +119 -0
- package/{dist/runtime/recovery/agent.cjs → src/runtime/recovery/agent.ts} +114 -76
- package/src/runtime/recovery/errors.ts +155 -0
- package/src/runtime/recovery/index.ts +7 -0
- package/src/runtime/recovery/recovery.ts +53 -0
- package/{dist/shared/condense-dom/condense-dom.cjs → src/shared/condense-dom/condense-dom.ts} +249 -124
- package/src/shared/config/config.ts +3 -0
- package/src/shared/config/index.ts +0 -0
- package/src/shared/debug/index.ts +1 -0
- package/src/shared/debug/pause.ts +91 -0
- package/src/shared/instrumentation/errors.ts +84 -0
- package/src/shared/instrumentation/index.ts +9 -0
- package/src/shared/instrumentation/instrument.ts +406 -0
- package/src/shared/llm/ai-sdk-adapter.ts +81 -0
- package/{dist/shared/llm/client.cjs → src/shared/llm/client.ts} +86 -80
- package/src/shared/llm/index.ts +3 -0
- package/src/shared/llm/types.ts +63 -0
- package/src/shared/logger/index.ts +13 -0
- package/src/shared/logger/logger.ts +358 -0
- package/src/shared/logger/sinks.ts +148 -0
- package/src/shared/paths/paths.ts +110 -0
- package/src/shared/paths/repo-root.ts +27 -0
- package/src/shared/run/api.ts +6 -0
- package/src/shared/run/browser.ts +107 -0
- package/src/shared/state/index.ts +11 -0
- package/src/shared/state/session-state.ts +77 -0
- package/src/shared/visualization/ghost-cursor.ts +213 -0
- package/src/shared/visualization/highlight.ts +149 -0
- package/src/shared/visualization/index.ts +18 -0
- package/src/shared/workflow/workflow.ts +36 -0
- package/dist/index.cjs +0 -144
- package/dist/index.d.cts +0 -21
- package/dist/runtime/download/download.cjs +0 -70
- package/dist/runtime/download/download.d.cts +0 -35
- package/dist/runtime/download/index.cjs +0 -30
- package/dist/runtime/download/index.d.cts +0 -3
- package/dist/runtime/extract/extract.cjs +0 -88
- package/dist/runtime/extract/extract.d.cts +0 -23
- package/dist/runtime/extract/index.cjs +0 -28
- package/dist/runtime/extract/index.d.cts +0 -5
- package/dist/runtime/network/index.cjs +0 -28
- package/dist/runtime/network/index.d.cts +0 -4
- package/dist/runtime/network/network.cjs +0 -91
- package/dist/runtime/network/network.d.cts +0 -28
- package/dist/runtime/recovery/agent.d.cts +0 -13
- package/dist/runtime/recovery/errors.cjs +0 -124
- package/dist/runtime/recovery/errors.d.cts +0 -31
- package/dist/runtime/recovery/index.cjs +0 -34
- package/dist/runtime/recovery/index.d.cts +0 -7
- package/dist/runtime/recovery/recovery.cjs +0 -55
- package/dist/runtime/recovery/recovery.d.cts +0 -12
- package/dist/shared/condense-dom/condense-dom.d.cts +0 -34
- package/dist/shared/config/config.cjs +0 -44
- package/dist/shared/config/config.d.cts +0 -10
- package/dist/shared/config/index.cjs +0 -32
- package/dist/shared/config/index.d.cts +0 -1
- package/dist/shared/debug/index.cjs +0 -28
- package/dist/shared/debug/index.d.cts +0 -1
- package/dist/shared/debug/pause.cjs +0 -86
- package/dist/shared/debug/pause.d.cts +0 -12
- package/dist/shared/instrumentation/errors.cjs +0 -81
- package/dist/shared/instrumentation/errors.d.cts +0 -12
- package/dist/shared/instrumentation/index.cjs +0 -35
- package/dist/shared/instrumentation/index.d.cts +0 -6
- package/dist/shared/instrumentation/instrument.cjs +0 -206
- package/dist/shared/instrumentation/instrument.d.cts +0 -32
- package/dist/shared/llm/ai-sdk-adapter.cjs +0 -71
- package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
- package/dist/shared/llm/client.d.cts +0 -13
- package/dist/shared/llm/index.cjs +0 -31
- package/dist/shared/llm/index.d.cts +0 -5
- package/dist/shared/llm/types.cjs +0 -16
- package/dist/shared/llm/types.d.cts +0 -67
- package/dist/shared/logger/index.cjs +0 -37
- package/dist/shared/logger/index.d.cts +0 -2
- package/dist/shared/logger/logger.cjs +0 -232
- package/dist/shared/logger/logger.d.cts +0 -86
- package/dist/shared/logger/sinks.cjs +0 -160
- package/dist/shared/logger/sinks.d.cts +0 -9
- package/dist/shared/paths/paths.cjs +0 -104
- package/dist/shared/paths/paths.d.cts +0 -10
- package/dist/shared/run/api.cjs +0 -28
- package/dist/shared/run/api.d.cts +0 -2
- package/dist/shared/run/browser.cjs +0 -98
- package/dist/shared/run/browser.d.cts +0 -22
- package/dist/shared/state/index.cjs +0 -38
- package/dist/shared/state/index.d.cts +0 -2
- package/dist/shared/state/session-state.cjs +0 -92
- package/dist/shared/state/session-state.d.cts +0 -40
- package/dist/shared/visualization/ghost-cursor.cjs +0 -174
- package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
- package/dist/shared/visualization/highlight.cjs +0 -134
- package/dist/shared/visualization/highlight.d.cts +0 -22
- package/dist/shared/visualization/index.cjs +0 -45
- package/dist/shared/visualization/index.d.cts +0 -3
- package/dist/shared/workflow/workflow.cjs +0 -47
- package/dist/shared/workflow/workflow.d.cts +0 -21
- package/skills/libretto/integration-approach-selection.md +0 -174
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
|
|
3
|
-
type MessageContentPart = {
|
|
4
|
-
type: "text";
|
|
5
|
-
text: string;
|
|
6
|
-
} | {
|
|
7
|
-
type: "image";
|
|
8
|
-
image: string | Uint8Array;
|
|
9
|
-
mediaType?: string;
|
|
10
|
-
};
|
|
11
|
-
type Message = {
|
|
12
|
-
role: "user" | "assistant";
|
|
13
|
-
content: string | MessageContentPart[];
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Pluggable LLM client interface.
|
|
17
|
-
*
|
|
18
|
-
* Users provide their own implementation backed by any LLM provider
|
|
19
|
-
* (OpenAI, Anthropic, etc.). Libretto uses this interface for AI extraction,
|
|
20
|
-
* recovery agents, and error detection.
|
|
21
|
-
*
|
|
22
|
-
* **Error handling:** implementations should throw on failure rather than
|
|
23
|
-
* returning sentinel values (e.g. `null` or `undefined`). Libretto relies
|
|
24
|
-
* on exceptions to trigger retry/recovery logic.
|
|
25
|
-
*
|
|
26
|
-
* A ready-made adapter for the Vercel AI SDK is available via
|
|
27
|
-
* {@link createLLMClientFromModel} in `libretto/llm`.
|
|
28
|
-
*/
|
|
29
|
-
interface LLMClient {
|
|
30
|
-
/**
|
|
31
|
-
* Generate a structured object from a single text prompt.
|
|
32
|
-
*
|
|
33
|
-
* The underlying model **must** support structured / JSON output so that
|
|
34
|
-
* the response can be parsed and validated against the provided Zod schema.
|
|
35
|
-
*
|
|
36
|
-
* @param opts.prompt - The text prompt sent to the model.
|
|
37
|
-
* @param opts.schema - A Zod schema describing the expected response shape.
|
|
38
|
-
* @param opts.temperature - Sampling temperature (default chosen by implementation, typically 0).
|
|
39
|
-
* @returns The parsed object matching the schema.
|
|
40
|
-
* @throws On LLM or parsing failure.
|
|
41
|
-
*/
|
|
42
|
-
generateObject<T extends z.ZodType>(opts: {
|
|
43
|
-
prompt: string;
|
|
44
|
-
schema: T;
|
|
45
|
-
temperature?: number;
|
|
46
|
-
}): Promise<z.output<T>>;
|
|
47
|
-
/**
|
|
48
|
-
* Generate a structured object from a conversation-style message array.
|
|
49
|
-
*
|
|
50
|
-
* Messages may contain **image content** (base64 data URIs via
|
|
51
|
-
* {@link MessageContentPart}), so the backing model must support
|
|
52
|
-
* vision / multimodal input when images are present.
|
|
53
|
-
*
|
|
54
|
-
* @param opts.messages - Ordered list of user/assistant messages, potentially multimodal.
|
|
55
|
-
* @param opts.schema - A Zod schema describing the expected response shape.
|
|
56
|
-
* @param opts.temperature - Sampling temperature (default chosen by implementation, typically 0).
|
|
57
|
-
* @returns The parsed object matching the schema.
|
|
58
|
-
* @throws On LLM or parsing failure.
|
|
59
|
-
*/
|
|
60
|
-
generateObjectFromMessages<T extends z.ZodType>(opts: {
|
|
61
|
-
messages: Message[];
|
|
62
|
-
schema: T;
|
|
63
|
-
temperature?: number;
|
|
64
|
-
}): Promise<z.output<T>>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type { LLMClient, Message, MessageContentPart };
|
|
@@ -1,37 +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: () => import_logger.Logger,
|
|
22
|
-
createFileLogSink: () => import_sinks.createFileLogSink,
|
|
23
|
-
defaultLogger: () => import_logger.defaultLogger,
|
|
24
|
-
jsonlConsoleSink: () => import_sinks.jsonlConsoleSink,
|
|
25
|
-
prettyConsoleSink: () => import_sinks.prettyConsoleSink
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(logger_exports);
|
|
28
|
-
var import_logger = require("./logger.js");
|
|
29
|
-
var import_sinks = require("./sinks.js");
|
|
30
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
-
0 && (module.exports = {
|
|
32
|
-
Logger,
|
|
33
|
-
createFileLogSink,
|
|
34
|
-
defaultLogger,
|
|
35
|
-
jsonlConsoleSink,
|
|
36
|
-
prettyConsoleSink
|
|
37
|
-
});
|
|
@@ -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,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var sinks_exports = {};
|
|
30
|
-
__export(sinks_exports, {
|
|
31
|
-
createFileLogSink: () => createFileLogSink,
|
|
32
|
-
jsonlConsoleSink: () => jsonlConsoleSink,
|
|
33
|
-
prettyConsoleSink: () => prettyConsoleSink
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(sinks_exports);
|
|
36
|
-
var fs = __toESM(require("node:fs"), 1);
|
|
37
|
-
var path = __toESM(require("node:path"), 1);
|
|
38
|
-
function createFileLogSink({
|
|
39
|
-
filePath
|
|
40
|
-
}) {
|
|
41
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
42
|
-
const writeStream = fs.createWriteStream(filePath, { flags: "a" });
|
|
43
|
-
return {
|
|
44
|
-
write: ({ id, scope, level, event, data, options }) => {
|
|
45
|
-
if (writeStream.destroyed || writeStream.writableEnded) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const timestamp = options?.timestamp || /* @__PURE__ */ new Date();
|
|
49
|
-
const logEntry = {
|
|
50
|
-
timestamp: timestamp.toISOString(),
|
|
51
|
-
id,
|
|
52
|
-
level,
|
|
53
|
-
scope,
|
|
54
|
-
event,
|
|
55
|
-
data
|
|
56
|
-
};
|
|
57
|
-
const jsonLine = JSON.stringify(logEntry) + "\n";
|
|
58
|
-
try {
|
|
59
|
-
writeStream.write(jsonLine, (error) => {
|
|
60
|
-
if (error) {
|
|
61
|
-
console.error("Failed to write to log file:", error);
|
|
62
|
-
console[level]({ id, scope, event, data, timestamp });
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error("Failed to write to log file:", error);
|
|
67
|
-
console[level]({ id, scope, event, data, timestamp });
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
flush: () => new Promise((resolve, reject) => {
|
|
71
|
-
if (!writeStream.writable || writeStream.writableEnded || writeStream.destroyed) {
|
|
72
|
-
resolve();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
writeStream.write("", (error) => {
|
|
76
|
-
if (error) {
|
|
77
|
-
reject(error);
|
|
78
|
-
} else {
|
|
79
|
-
resolve();
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}),
|
|
83
|
-
close: () => new Promise((resolve) => {
|
|
84
|
-
if (writeStream.destroyed || writeStream.closed) {
|
|
85
|
-
resolve();
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
let settled = false;
|
|
89
|
-
const done = () => {
|
|
90
|
-
if (settled) return;
|
|
91
|
-
settled = true;
|
|
92
|
-
resolve();
|
|
93
|
-
};
|
|
94
|
-
writeStream.once("finish", done);
|
|
95
|
-
writeStream.once("close", done);
|
|
96
|
-
writeStream.once("error", done);
|
|
97
|
-
try {
|
|
98
|
-
writeStream.end();
|
|
99
|
-
} catch {
|
|
100
|
-
done();
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
const colors = {
|
|
106
|
-
reset: "\x1B[0m",
|
|
107
|
-
gray: "\x1B[90m",
|
|
108
|
-
red: "\x1B[31m",
|
|
109
|
-
yellow: "\x1B[33m",
|
|
110
|
-
blue: "\x1B[34m",
|
|
111
|
-
cyan: "\x1B[36m"
|
|
112
|
-
};
|
|
113
|
-
function formatTimestamp(date) {
|
|
114
|
-
return date.toISOString().replace("T", " ").replace("Z", "");
|
|
115
|
-
}
|
|
116
|
-
const prettyConsoleSink = {
|
|
117
|
-
write: ({ scope, level, event, data, options }) => {
|
|
118
|
-
const timestamp = `${colors.gray}${formatTimestamp(options?.timestamp || /* @__PURE__ */ new Date())}${colors.reset}`;
|
|
119
|
-
const levelColor = level === "error" ? colors.red : level === "warn" ? colors.yellow : colors.blue;
|
|
120
|
-
const coloredScope = scope ? `${colors.cyan}[${scope}]${colors.reset}` : "";
|
|
121
|
-
const logPrefix = `${timestamp} ${levelColor}${level.toUpperCase()}${colors.reset} ${coloredScope} ${event}`;
|
|
122
|
-
if (level === "error" && data.error) {
|
|
123
|
-
const { error, ...otherData } = data;
|
|
124
|
-
console.error(logPrefix);
|
|
125
|
-
if (error.stack) {
|
|
126
|
-
console.error(` ${error.stack}`);
|
|
127
|
-
} else if (error.type && error.message) {
|
|
128
|
-
console.error(` ${error.type}: ${error.message}`);
|
|
129
|
-
}
|
|
130
|
-
if (Object.keys(otherData).length > 0) {
|
|
131
|
-
console.error(JSON.stringify(otherData, null, 2));
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
console[level](logPrefix);
|
|
135
|
-
if (Object.keys(data).length > 0) {
|
|
136
|
-
console[level](JSON.stringify(data, null, 2));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const jsonlConsoleSink = {
|
|
142
|
-
write: ({ id, scope, level, event, data, options }) => {
|
|
143
|
-
const timestamp = options?.timestamp || /* @__PURE__ */ new Date();
|
|
144
|
-
const logEntry = {
|
|
145
|
-
timestamp: timestamp.toISOString(),
|
|
146
|
-
id,
|
|
147
|
-
level,
|
|
148
|
-
scope: scope || void 0,
|
|
149
|
-
event,
|
|
150
|
-
data
|
|
151
|
-
};
|
|
152
|
-
console.log(JSON.stringify(logEntry));
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
-
0 && (module.exports = {
|
|
157
|
-
createFileLogSink,
|
|
158
|
-
jsonlConsoleSink,
|
|
159
|
-
prettyConsoleSink
|
|
160
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { LoggerSink } from './logger.cjs';
|
|
2
|
-
|
|
3
|
-
declare function createFileLogSink({ filePath, }: {
|
|
4
|
-
filePath: string;
|
|
5
|
-
}): LoggerSink;
|
|
6
|
-
declare const prettyConsoleSink: LoggerSink;
|
|
7
|
-
declare const jsonlConsoleSink: LoggerSink;
|
|
8
|
-
|
|
9
|
-
export { createFileLogSink, jsonlConsoleSink, prettyConsoleSink };
|