libretto 0.1.5 → 0.2.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/README.md +213 -17
- package/bin/libretto.mjs +18 -0
- package/dist/cli/cli.js +201 -0
- package/dist/cli/commands/ai.js +21 -0
- package/dist/cli/commands/browser.js +56 -0
- package/dist/cli/commands/execution.js +407 -0
- package/dist/cli/commands/logs.js +65 -0
- package/dist/cli/commands/snapshot.js +99 -0
- package/dist/cli/core/ai-config.js +149 -0
- package/dist/cli/core/browser.js +687 -0
- package/dist/cli/core/context.js +113 -0
- package/dist/cli/core/pause-signals.js +29 -0
- package/dist/cli/core/session.js +183 -0
- package/dist/cli/core/snapshot-analyzer.js +492 -0
- package/dist/cli/core/telemetry.js +350 -0
- package/dist/cli/index.js +13 -0
- package/dist/cli/workers/run-integration-runtime.js +204 -0
- package/dist/cli/workers/run-integration-worker-protocol.js +0 -0
- package/dist/cli/workers/run-integration-worker.js +83 -0
- package/dist/index.cjs +127 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +110 -0
- package/dist/runtime/download/download.cjs +70 -0
- package/dist/runtime/download/download.d.cts +35 -0
- package/dist/runtime/download/download.d.ts +35 -0
- package/dist/runtime/download/download.js +45 -0
- package/dist/runtime/download/index.cjs +30 -0
- package/dist/runtime/download/index.d.cts +3 -0
- package/dist/runtime/download/index.d.ts +3 -0
- package/dist/runtime/download/index.js +8 -0
- package/dist/runtime/extract/extract.cjs +87 -0
- package/dist/runtime/extract/extract.d.cts +23 -0
- package/dist/runtime/extract/extract.d.ts +23 -0
- package/dist/runtime/extract/extract.js +63 -0
- package/dist/runtime/extract/index.cjs +28 -0
- package/dist/runtime/extract/index.d.cts +5 -0
- package/dist/runtime/extract/index.d.ts +5 -0
- package/dist/runtime/extract/index.js +4 -0
- package/dist/runtime/network/index.cjs +28 -0
- package/dist/runtime/network/index.d.cts +4 -0
- package/dist/runtime/network/index.d.ts +4 -0
- package/dist/runtime/network/index.js +6 -0
- package/dist/runtime/network/network.cjs +91 -0
- package/dist/runtime/network/network.d.cts +28 -0
- package/dist/runtime/network/network.d.ts +28 -0
- package/dist/runtime/network/network.js +67 -0
- package/dist/runtime/recovery/agent.cjs +218 -0
- package/dist/runtime/recovery/agent.d.cts +13 -0
- package/dist/runtime/recovery/agent.d.ts +13 -0
- package/dist/runtime/recovery/agent.js +194 -0
- package/dist/runtime/recovery/errors.cjs +122 -0
- package/dist/runtime/recovery/errors.d.cts +31 -0
- package/dist/runtime/recovery/errors.d.ts +31 -0
- package/dist/runtime/recovery/errors.js +98 -0
- package/dist/runtime/recovery/index.cjs +34 -0
- package/dist/runtime/recovery/index.d.cts +7 -0
- package/dist/runtime/recovery/index.d.ts +7 -0
- package/dist/runtime/recovery/index.js +10 -0
- package/dist/runtime/recovery/recovery.cjs +53 -0
- package/dist/runtime/recovery/recovery.d.cts +12 -0
- package/dist/runtime/recovery/recovery.d.ts +12 -0
- package/dist/runtime/recovery/recovery.js +29 -0
- package/dist/runtime/step/index.cjs +31 -0
- package/dist/runtime/step/index.d.cts +7 -0
- package/dist/runtime/step/index.d.ts +7 -0
- package/dist/runtime/step/index.js +6 -0
- package/dist/runtime/step/runner.cjs +208 -0
- package/dist/runtime/step/runner.d.cts +16 -0
- package/dist/runtime/step/runner.d.ts +16 -0
- package/dist/runtime/step/runner.js +187 -0
- package/dist/runtime/step/step.cjs +67 -0
- package/dist/runtime/step/step.d.cts +23 -0
- package/dist/runtime/step/step.d.ts +23 -0
- package/dist/runtime/step/step.js +43 -0
- package/dist/runtime/step/types.cjs +16 -0
- package/dist/runtime/step/types.d.cts +72 -0
- package/dist/runtime/step/types.d.ts +72 -0
- package/dist/runtime/step/types.js +0 -0
- package/dist/shared/config/config.cjs +44 -0
- package/dist/shared/config/config.d.cts +10 -0
- package/dist/shared/config/config.d.ts +10 -0
- package/dist/shared/config/config.js +18 -0
- package/dist/shared/config/index.cjs +32 -0
- package/dist/shared/config/index.d.cts +1 -0
- package/dist/shared/config/index.d.ts +1 -0
- package/dist/shared/config/index.js +10 -0
- package/dist/shared/debug/index.cjs +32 -0
- package/dist/shared/debug/index.d.cts +2 -0
- package/dist/shared/debug/index.d.ts +2 -0
- package/dist/shared/debug/index.js +10 -0
- package/dist/shared/debug/pause.cjs +56 -0
- package/dist/shared/debug/pause.d.cts +23 -0
- package/dist/shared/debug/pause.d.ts +23 -0
- package/dist/shared/debug/pause.js +30 -0
- package/dist/shared/instrumentation/errors.cjs +81 -0
- package/dist/shared/instrumentation/errors.d.cts +12 -0
- package/dist/shared/instrumentation/errors.d.ts +12 -0
- package/dist/shared/instrumentation/errors.js +57 -0
- package/dist/shared/instrumentation/index.cjs +35 -0
- package/dist/shared/instrumentation/index.d.cts +6 -0
- package/dist/shared/instrumentation/index.d.ts +6 -0
- package/dist/shared/instrumentation/index.js +12 -0
- package/dist/shared/instrumentation/instrument.cjs +206 -0
- package/dist/shared/instrumentation/instrument.d.cts +32 -0
- package/dist/shared/instrumentation/instrument.d.ts +32 -0
- package/dist/shared/instrumentation/instrument.js +190 -0
- package/dist/shared/llm/client.cjs +139 -0
- package/dist/shared/llm/client.d.cts +6 -0
- package/dist/shared/llm/client.d.ts +6 -0
- package/dist/shared/llm/client.js +115 -0
- package/dist/shared/llm/index.cjs +28 -0
- package/dist/shared/llm/index.d.cts +3 -0
- package/dist/shared/llm/index.d.ts +3 -0
- package/dist/shared/llm/index.js +4 -0
- package/dist/shared/llm/types.cjs +16 -0
- package/dist/shared/llm/types.d.cts +34 -0
- package/dist/shared/llm/types.d.ts +34 -0
- package/dist/shared/llm/types.js +0 -0
- package/dist/shared/logger/index.cjs +35 -0
- package/dist/shared/logger/index.d.cts +2 -0
- package/dist/shared/logger/index.d.ts +2 -0
- package/dist/shared/logger/index.js +12 -0
- package/dist/shared/logger/logger.cjs +200 -0
- package/dist/shared/logger/logger.d.cts +70 -0
- package/dist/shared/logger/logger.d.ts +70 -0
- package/dist/shared/logger/logger.js +176 -0
- package/dist/shared/logger/sinks.cjs +160 -0
- package/dist/shared/logger/sinks.d.cts +9 -0
- package/dist/shared/logger/sinks.d.ts +9 -0
- package/dist/shared/logger/sinks.js +124 -0
- package/dist/shared/paths/paths.cjs +104 -0
- package/dist/shared/paths/paths.d.cts +10 -0
- package/dist/shared/paths/paths.d.ts +10 -0
- package/dist/shared/paths/paths.js +73 -0
- package/dist/shared/run/api.cjs +35 -0
- package/dist/shared/run/api.d.cts +3 -0
- package/dist/shared/run/api.d.ts +3 -0
- package/dist/shared/run/api.js +12 -0
- package/dist/shared/run/browser.cjs +98 -0
- package/dist/shared/run/browser.d.cts +22 -0
- package/dist/shared/run/browser.d.ts +22 -0
- package/dist/shared/run/browser.js +74 -0
- package/dist/shared/state/index.cjs +38 -0
- package/dist/shared/state/index.d.cts +2 -0
- package/dist/shared/state/index.d.ts +2 -0
- package/dist/shared/state/index.js +16 -0
- package/dist/shared/state/session-state.cjs +85 -0
- package/dist/shared/state/session-state.d.cts +34 -0
- package/dist/shared/state/session-state.d.ts +34 -0
- package/dist/shared/state/session-state.js +56 -0
- package/dist/shared/visualization/ghost-cursor.cjs +174 -0
- package/dist/shared/visualization/ghost-cursor.d.cts +37 -0
- package/dist/shared/visualization/ghost-cursor.d.ts +37 -0
- package/dist/shared/visualization/ghost-cursor.js +145 -0
- package/dist/shared/visualization/highlight.cjs +134 -0
- package/dist/shared/visualization/highlight.d.cts +22 -0
- package/dist/shared/visualization/highlight.d.ts +22 -0
- package/dist/shared/visualization/highlight.js +108 -0
- package/dist/shared/visualization/index.cjs +45 -0
- package/dist/shared/visualization/index.d.cts +3 -0
- package/dist/shared/visualization/index.d.ts +3 -0
- package/dist/shared/visualization/index.js +24 -0
- package/dist/shared/workflow/workflow.cjs +47 -0
- package/dist/shared/workflow/workflow.d.cts +33 -0
- package/dist/shared/workflow/workflow.d.ts +33 -0
- package/dist/shared/workflow/workflow.js +21 -0
- package/package.json +123 -26
- package/.npmignore +0 -2
- package/bin/libretto +0 -31
- package/lib/connect.js +0 -34
- package/lib/export.js +0 -224
- package/lib/import.js +0 -166
- package/lib/index.js +0 -8
- package/lib/log.js +0 -9
- package/lib/validate.js +0 -20
- package/makefile +0 -8
- package/src/connect.coffee +0 -25
- package/src/export.coffee +0 -222
- package/src/import.coffee +0 -166
- package/src/index.coffee +0 -3
- package/src/log.coffee +0 -3
- package/src/validate.coffee +0 -10
|
@@ -0,0 +1,35 @@
|
|
|
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 api_exports = {};
|
|
20
|
+
__export(api_exports, {
|
|
21
|
+
DebugPauseSignal: () => import_pause.DebugPauseSignal,
|
|
22
|
+
debugPause: () => import_pause.debugPause,
|
|
23
|
+
isDebugPauseSignal: () => import_pause.isDebugPauseSignal,
|
|
24
|
+
launchBrowser: () => import_browser.launchBrowser
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(api_exports);
|
|
27
|
+
var import_browser = require("./browser.js");
|
|
28
|
+
var import_pause = require("../debug/pause.js");
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
DebugPauseSignal,
|
|
32
|
+
debugPause,
|
|
33
|
+
isDebugPauseSignal,
|
|
34
|
+
launchBrowser
|
|
35
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
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 browser_exports = {};
|
|
20
|
+
__export(browser_exports, {
|
|
21
|
+
launchBrowser: () => launchBrowser
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(browser_exports);
|
|
24
|
+
var import_playwright = require("playwright");
|
|
25
|
+
var import_node_net = require("node:net");
|
|
26
|
+
var import_node_fs = require("node:fs");
|
|
27
|
+
var import_paths = require("../paths/paths.js");
|
|
28
|
+
var import_session_state = require("../state/session-state.js");
|
|
29
|
+
async function pickFreePort() {
|
|
30
|
+
return await new Promise((resolve, reject) => {
|
|
31
|
+
const server = (0, import_node_net.createServer)();
|
|
32
|
+
server.unref();
|
|
33
|
+
server.on("error", reject);
|
|
34
|
+
server.listen(0, "127.0.0.1", () => {
|
|
35
|
+
const addr = server.address();
|
|
36
|
+
if (addr && typeof addr === "object") {
|
|
37
|
+
server.close(() => resolve(addr.port));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
server.close(() => reject(new Error("Failed to resolve debug port")));
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function launchBrowser({
|
|
45
|
+
sessionName,
|
|
46
|
+
headless = false,
|
|
47
|
+
viewport = { width: 1366, height: 768 },
|
|
48
|
+
storageStatePath
|
|
49
|
+
}) {
|
|
50
|
+
const debugPort = await pickFreePort();
|
|
51
|
+
const browser = await import_playwright.chromium.launch({
|
|
52
|
+
headless,
|
|
53
|
+
args: [
|
|
54
|
+
"--disable-blink-features=AutomationControlled",
|
|
55
|
+
`--remote-debugging-port=${debugPort}`,
|
|
56
|
+
"--no-focus-on-check"
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
const context = await browser.newContext({
|
|
60
|
+
viewport,
|
|
61
|
+
...storageStatePath ? { storageState: storageStatePath } : {}
|
|
62
|
+
});
|
|
63
|
+
const page = await context.newPage();
|
|
64
|
+
page.setDefaultTimeout(3e4);
|
|
65
|
+
page.setDefaultNavigationTimeout(45e3);
|
|
66
|
+
const metadataPath = (0, import_paths.ensureLibrettoSessionStatePath)(sessionName);
|
|
67
|
+
const existingStateRaw = (0, import_node_fs.existsSync)(metadataPath) ? JSON.parse((0, import_node_fs.readFileSync)(metadataPath, "utf-8")) : void 0;
|
|
68
|
+
const parsedExistingState = import_session_state.SessionStateFileSchema.safeParse(existingStateRaw);
|
|
69
|
+
(0, import_node_fs.writeFileSync)(
|
|
70
|
+
metadataPath,
|
|
71
|
+
JSON.stringify(
|
|
72
|
+
{
|
|
73
|
+
version: parsedExistingState.success ? parsedExistingState.data.version : import_session_state.SESSION_STATE_VERSION,
|
|
74
|
+
session: sessionName,
|
|
75
|
+
port: debugPort,
|
|
76
|
+
pid: process.pid,
|
|
77
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
78
|
+
status: "active"
|
|
79
|
+
},
|
|
80
|
+
null,
|
|
81
|
+
2
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
return {
|
|
85
|
+
browser,
|
|
86
|
+
context,
|
|
87
|
+
page,
|
|
88
|
+
debugPort,
|
|
89
|
+
metadataPath,
|
|
90
|
+
close: async () => {
|
|
91
|
+
await browser.close();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
launchBrowser
|
|
98
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Browser, BrowserContext, Page } from 'playwright';
|
|
2
|
+
|
|
3
|
+
type LaunchBrowserArgs = {
|
|
4
|
+
sessionName: string;
|
|
5
|
+
headless?: boolean;
|
|
6
|
+
viewport?: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
storageStatePath?: string;
|
|
11
|
+
};
|
|
12
|
+
type BrowserSession = {
|
|
13
|
+
browser: Browser;
|
|
14
|
+
context: BrowserContext;
|
|
15
|
+
page: Page;
|
|
16
|
+
debugPort: number;
|
|
17
|
+
metadataPath: string;
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
declare function launchBrowser({ sessionName, headless, viewport, storageStatePath, }: LaunchBrowserArgs): Promise<BrowserSession>;
|
|
21
|
+
|
|
22
|
+
export { type BrowserSession, type LaunchBrowserArgs, launchBrowser };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Browser, BrowserContext, Page } from 'playwright';
|
|
2
|
+
|
|
3
|
+
type LaunchBrowserArgs = {
|
|
4
|
+
sessionName: string;
|
|
5
|
+
headless?: boolean;
|
|
6
|
+
viewport?: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
storageStatePath?: string;
|
|
11
|
+
};
|
|
12
|
+
type BrowserSession = {
|
|
13
|
+
browser: Browser;
|
|
14
|
+
context: BrowserContext;
|
|
15
|
+
page: Page;
|
|
16
|
+
debugPort: number;
|
|
17
|
+
metadataPath: string;
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
declare function launchBrowser({ sessionName, headless, viewport, storageStatePath, }: LaunchBrowserArgs): Promise<BrowserSession>;
|
|
21
|
+
|
|
22
|
+
export { type BrowserSession, type LaunchBrowserArgs, launchBrowser };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { chromium } from "playwright";
|
|
2
|
+
import { createServer } from "node:net";
|
|
3
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { ensureLibrettoSessionStatePath } from "../paths/paths.js";
|
|
5
|
+
import { SESSION_STATE_VERSION, SessionStateFileSchema } from "../state/session-state.js";
|
|
6
|
+
async function pickFreePort() {
|
|
7
|
+
return await new Promise((resolve, reject) => {
|
|
8
|
+
const server = createServer();
|
|
9
|
+
server.unref();
|
|
10
|
+
server.on("error", reject);
|
|
11
|
+
server.listen(0, "127.0.0.1", () => {
|
|
12
|
+
const addr = server.address();
|
|
13
|
+
if (addr && typeof addr === "object") {
|
|
14
|
+
server.close(() => resolve(addr.port));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
server.close(() => reject(new Error("Failed to resolve debug port")));
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function launchBrowser({
|
|
22
|
+
sessionName,
|
|
23
|
+
headless = false,
|
|
24
|
+
viewport = { width: 1366, height: 768 },
|
|
25
|
+
storageStatePath
|
|
26
|
+
}) {
|
|
27
|
+
const debugPort = await pickFreePort();
|
|
28
|
+
const browser = await chromium.launch({
|
|
29
|
+
headless,
|
|
30
|
+
args: [
|
|
31
|
+
"--disable-blink-features=AutomationControlled",
|
|
32
|
+
`--remote-debugging-port=${debugPort}`,
|
|
33
|
+
"--no-focus-on-check"
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
const context = await browser.newContext({
|
|
37
|
+
viewport,
|
|
38
|
+
...storageStatePath ? { storageState: storageStatePath } : {}
|
|
39
|
+
});
|
|
40
|
+
const page = await context.newPage();
|
|
41
|
+
page.setDefaultTimeout(3e4);
|
|
42
|
+
page.setDefaultNavigationTimeout(45e3);
|
|
43
|
+
const metadataPath = ensureLibrettoSessionStatePath(sessionName);
|
|
44
|
+
const existingStateRaw = existsSync(metadataPath) ? JSON.parse(readFileSync(metadataPath, "utf-8")) : void 0;
|
|
45
|
+
const parsedExistingState = SessionStateFileSchema.safeParse(existingStateRaw);
|
|
46
|
+
writeFileSync(
|
|
47
|
+
metadataPath,
|
|
48
|
+
JSON.stringify(
|
|
49
|
+
{
|
|
50
|
+
version: parsedExistingState.success ? parsedExistingState.data.version : SESSION_STATE_VERSION,
|
|
51
|
+
session: sessionName,
|
|
52
|
+
port: debugPort,
|
|
53
|
+
pid: process.pid,
|
|
54
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
55
|
+
status: "active"
|
|
56
|
+
},
|
|
57
|
+
null,
|
|
58
|
+
2
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
return {
|
|
62
|
+
browser,
|
|
63
|
+
context,
|
|
64
|
+
page,
|
|
65
|
+
debugPort,
|
|
66
|
+
metadataPath,
|
|
67
|
+
close: async () => {
|
|
68
|
+
await browser.close();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
launchBrowser
|
|
74
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
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 state_exports = {};
|
|
20
|
+
__export(state_exports, {
|
|
21
|
+
SESSION_STATE_VERSION: () => import_session_state.SESSION_STATE_VERSION,
|
|
22
|
+
SessionStateFileSchema: () => import_session_state.SessionStateFileSchema,
|
|
23
|
+
SessionStatusSchema: () => import_session_state.SessionStatusSchema,
|
|
24
|
+
parseSessionStateContent: () => import_session_state.parseSessionStateContent,
|
|
25
|
+
parseSessionStateData: () => import_session_state.parseSessionStateData,
|
|
26
|
+
serializeSessionState: () => import_session_state.serializeSessionState
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(state_exports);
|
|
29
|
+
var import_session_state = require("./session-state.js");
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
SESSION_STATE_VERSION,
|
|
33
|
+
SessionStateFileSchema,
|
|
34
|
+
SessionStatusSchema,
|
|
35
|
+
parseSessionStateContent,
|
|
36
|
+
parseSessionStateData,
|
|
37
|
+
serializeSessionState
|
|
38
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SESSION_STATE_VERSION,
|
|
3
|
+
SessionStatusSchema,
|
|
4
|
+
SessionStateFileSchema,
|
|
5
|
+
parseSessionStateData,
|
|
6
|
+
parseSessionStateContent,
|
|
7
|
+
serializeSessionState
|
|
8
|
+
} from "./session-state.js";
|
|
9
|
+
export {
|
|
10
|
+
SESSION_STATE_VERSION,
|
|
11
|
+
SessionStateFileSchema,
|
|
12
|
+
SessionStatusSchema,
|
|
13
|
+
parseSessionStateContent,
|
|
14
|
+
parseSessionStateData,
|
|
15
|
+
serializeSessionState
|
|
16
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
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 session_state_exports = {};
|
|
20
|
+
__export(session_state_exports, {
|
|
21
|
+
SESSION_STATE_VERSION: () => SESSION_STATE_VERSION,
|
|
22
|
+
SessionStateFileSchema: () => SessionStateFileSchema,
|
|
23
|
+
SessionStatusSchema: () => SessionStatusSchema,
|
|
24
|
+
parseSessionStateContent: () => parseSessionStateContent,
|
|
25
|
+
parseSessionStateData: () => parseSessionStateData,
|
|
26
|
+
serializeSessionState: () => serializeSessionState
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(session_state_exports);
|
|
29
|
+
var import_zod = require("zod");
|
|
30
|
+
const SESSION_STATE_VERSION = 1;
|
|
31
|
+
const SessionStatusSchema = import_zod.z.enum([
|
|
32
|
+
"active",
|
|
33
|
+
"paused",
|
|
34
|
+
"completed",
|
|
35
|
+
"failed",
|
|
36
|
+
"exited"
|
|
37
|
+
]);
|
|
38
|
+
const SessionStateFileSchema = import_zod.z.object({
|
|
39
|
+
version: import_zod.z.literal(SESSION_STATE_VERSION),
|
|
40
|
+
port: import_zod.z.number().int().min(0).max(65535),
|
|
41
|
+
pid: import_zod.z.number().int(),
|
|
42
|
+
session: import_zod.z.string().min(1),
|
|
43
|
+
startedAt: import_zod.z.string().datetime({ offset: true }),
|
|
44
|
+
status: SessionStatusSchema.optional()
|
|
45
|
+
});
|
|
46
|
+
function formatIssues(error) {
|
|
47
|
+
return error.issues.map((issue) => {
|
|
48
|
+
const path = issue.path.join(".") || "root";
|
|
49
|
+
return `${path}: ${issue.message}`;
|
|
50
|
+
}).join("; ");
|
|
51
|
+
}
|
|
52
|
+
function parseSessionStateData(rawState, source) {
|
|
53
|
+
const parsed = SessionStateFileSchema.safeParse(rawState);
|
|
54
|
+
if (!parsed.success) {
|
|
55
|
+
throw new Error(`Session state at ${source} is invalid: ${formatIssues(parsed.error)}`);
|
|
56
|
+
}
|
|
57
|
+
const { version: _version, ...state } = parsed.data;
|
|
58
|
+
return state;
|
|
59
|
+
}
|
|
60
|
+
function parseSessionStateContent(content, source) {
|
|
61
|
+
let rawState;
|
|
62
|
+
try {
|
|
63
|
+
rawState = JSON.parse(content);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Session state at ${source} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return parseSessionStateData(rawState, source);
|
|
70
|
+
}
|
|
71
|
+
function serializeSessionState(state) {
|
|
72
|
+
return SessionStateFileSchema.parse({
|
|
73
|
+
version: SESSION_STATE_VERSION,
|
|
74
|
+
...state
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
SESSION_STATE_VERSION,
|
|
80
|
+
SessionStateFileSchema,
|
|
81
|
+
SessionStatusSchema,
|
|
82
|
+
parseSessionStateContent,
|
|
83
|
+
parseSessionStateData,
|
|
84
|
+
serializeSessionState
|
|
85
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const SESSION_STATE_VERSION = 1;
|
|
4
|
+
declare const SessionStatusSchema: z.ZodEnum<["active", "paused", "completed", "failed", "exited"]>;
|
|
5
|
+
declare const SessionStateFileSchema: z.ZodObject<{
|
|
6
|
+
version: z.ZodLiteral<1>;
|
|
7
|
+
port: z.ZodNumber;
|
|
8
|
+
pid: z.ZodNumber;
|
|
9
|
+
session: z.ZodString;
|
|
10
|
+
startedAt: z.ZodString;
|
|
11
|
+
status: z.ZodOptional<z.ZodEnum<["active", "paused", "completed", "failed", "exited"]>>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
version: 1;
|
|
14
|
+
port: number;
|
|
15
|
+
pid: number;
|
|
16
|
+
session: string;
|
|
17
|
+
startedAt: string;
|
|
18
|
+
status?: "completed" | "failed" | "paused" | "active" | "exited" | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
version: 1;
|
|
21
|
+
port: number;
|
|
22
|
+
pid: number;
|
|
23
|
+
session: string;
|
|
24
|
+
startedAt: string;
|
|
25
|
+
status?: "completed" | "failed" | "paused" | "active" | "exited" | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
type SessionStatus = z.infer<typeof SessionStatusSchema>;
|
|
28
|
+
type SessionStateFile = z.infer<typeof SessionStateFileSchema>;
|
|
29
|
+
type SessionState = Omit<SessionStateFile, "version">;
|
|
30
|
+
declare function parseSessionStateData(rawState: unknown, source: string): SessionState;
|
|
31
|
+
declare function parseSessionStateContent(content: string, source: string): SessionState;
|
|
32
|
+
declare function serializeSessionState(state: SessionState): SessionStateFile;
|
|
33
|
+
|
|
34
|
+
export { SESSION_STATE_VERSION, type SessionState, type SessionStateFile, SessionStateFileSchema, type SessionStatus, SessionStatusSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const SESSION_STATE_VERSION = 1;
|
|
4
|
+
declare const SessionStatusSchema: z.ZodEnum<["active", "paused", "completed", "failed", "exited"]>;
|
|
5
|
+
declare const SessionStateFileSchema: z.ZodObject<{
|
|
6
|
+
version: z.ZodLiteral<1>;
|
|
7
|
+
port: z.ZodNumber;
|
|
8
|
+
pid: z.ZodNumber;
|
|
9
|
+
session: z.ZodString;
|
|
10
|
+
startedAt: z.ZodString;
|
|
11
|
+
status: z.ZodOptional<z.ZodEnum<["active", "paused", "completed", "failed", "exited"]>>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
version: 1;
|
|
14
|
+
port: number;
|
|
15
|
+
pid: number;
|
|
16
|
+
session: string;
|
|
17
|
+
startedAt: string;
|
|
18
|
+
status?: "completed" | "failed" | "paused" | "active" | "exited" | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
version: 1;
|
|
21
|
+
port: number;
|
|
22
|
+
pid: number;
|
|
23
|
+
session: string;
|
|
24
|
+
startedAt: string;
|
|
25
|
+
status?: "completed" | "failed" | "paused" | "active" | "exited" | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
type SessionStatus = z.infer<typeof SessionStatusSchema>;
|
|
28
|
+
type SessionStateFile = z.infer<typeof SessionStateFileSchema>;
|
|
29
|
+
type SessionState = Omit<SessionStateFile, "version">;
|
|
30
|
+
declare function parseSessionStateData(rawState: unknown, source: string): SessionState;
|
|
31
|
+
declare function parseSessionStateContent(content: string, source: string): SessionState;
|
|
32
|
+
declare function serializeSessionState(state: SessionState): SessionStateFile;
|
|
33
|
+
|
|
34
|
+
export { SESSION_STATE_VERSION, type SessionState, type SessionStateFile, SessionStateFileSchema, type SessionStatus, SessionStatusSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const SESSION_STATE_VERSION = 1;
|
|
3
|
+
const SessionStatusSchema = z.enum([
|
|
4
|
+
"active",
|
|
5
|
+
"paused",
|
|
6
|
+
"completed",
|
|
7
|
+
"failed",
|
|
8
|
+
"exited"
|
|
9
|
+
]);
|
|
10
|
+
const SessionStateFileSchema = z.object({
|
|
11
|
+
version: z.literal(SESSION_STATE_VERSION),
|
|
12
|
+
port: z.number().int().min(0).max(65535),
|
|
13
|
+
pid: z.number().int(),
|
|
14
|
+
session: z.string().min(1),
|
|
15
|
+
startedAt: z.string().datetime({ offset: true }),
|
|
16
|
+
status: SessionStatusSchema.optional()
|
|
17
|
+
});
|
|
18
|
+
function formatIssues(error) {
|
|
19
|
+
return error.issues.map((issue) => {
|
|
20
|
+
const path = issue.path.join(".") || "root";
|
|
21
|
+
return `${path}: ${issue.message}`;
|
|
22
|
+
}).join("; ");
|
|
23
|
+
}
|
|
24
|
+
function parseSessionStateData(rawState, source) {
|
|
25
|
+
const parsed = SessionStateFileSchema.safeParse(rawState);
|
|
26
|
+
if (!parsed.success) {
|
|
27
|
+
throw new Error(`Session state at ${source} is invalid: ${formatIssues(parsed.error)}`);
|
|
28
|
+
}
|
|
29
|
+
const { version: _version, ...state } = parsed.data;
|
|
30
|
+
return state;
|
|
31
|
+
}
|
|
32
|
+
function parseSessionStateContent(content, source) {
|
|
33
|
+
let rawState;
|
|
34
|
+
try {
|
|
35
|
+
rawState = JSON.parse(content);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Session state at ${source} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return parseSessionStateData(rawState, source);
|
|
42
|
+
}
|
|
43
|
+
function serializeSessionState(state) {
|
|
44
|
+
return SessionStateFileSchema.parse({
|
|
45
|
+
version: SESSION_STATE_VERSION,
|
|
46
|
+
...state
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
SESSION_STATE_VERSION,
|
|
51
|
+
SessionStateFileSchema,
|
|
52
|
+
SessionStatusSchema,
|
|
53
|
+
parseSessionStateContent,
|
|
54
|
+
parseSessionStateData,
|
|
55
|
+
serializeSessionState
|
|
56
|
+
};
|