libretto 0.1.4 → 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.
Files changed (183) hide show
  1. package/README.md +213 -17
  2. package/bin/libretto.mjs +18 -0
  3. package/dist/cli/cli.js +201 -0
  4. package/dist/cli/commands/ai.js +21 -0
  5. package/dist/cli/commands/browser.js +56 -0
  6. package/dist/cli/commands/execution.js +407 -0
  7. package/dist/cli/commands/logs.js +65 -0
  8. package/dist/cli/commands/snapshot.js +99 -0
  9. package/dist/cli/core/ai-config.js +149 -0
  10. package/dist/cli/core/browser.js +687 -0
  11. package/dist/cli/core/context.js +113 -0
  12. package/dist/cli/core/pause-signals.js +29 -0
  13. package/dist/cli/core/session.js +183 -0
  14. package/dist/cli/core/snapshot-analyzer.js +492 -0
  15. package/dist/cli/core/telemetry.js +350 -0
  16. package/dist/cli/index.js +13 -0
  17. package/dist/cli/workers/run-integration-runtime.js +204 -0
  18. package/dist/cli/workers/run-integration-worker-protocol.js +0 -0
  19. package/dist/cli/workers/run-integration-worker.js +83 -0
  20. package/dist/index.cjs +127 -0
  21. package/dist/index.d.cts +22 -0
  22. package/dist/index.d.ts +22 -0
  23. package/dist/index.js +110 -0
  24. package/dist/runtime/download/download.cjs +70 -0
  25. package/dist/runtime/download/download.d.cts +35 -0
  26. package/dist/runtime/download/download.d.ts +35 -0
  27. package/dist/runtime/download/download.js +45 -0
  28. package/dist/runtime/download/index.cjs +30 -0
  29. package/dist/runtime/download/index.d.cts +3 -0
  30. package/dist/runtime/download/index.d.ts +3 -0
  31. package/dist/runtime/download/index.js +8 -0
  32. package/dist/runtime/extract/extract.cjs +87 -0
  33. package/dist/runtime/extract/extract.d.cts +23 -0
  34. package/dist/runtime/extract/extract.d.ts +23 -0
  35. package/dist/runtime/extract/extract.js +63 -0
  36. package/dist/runtime/extract/index.cjs +28 -0
  37. package/dist/runtime/extract/index.d.cts +5 -0
  38. package/dist/runtime/extract/index.d.ts +5 -0
  39. package/dist/runtime/extract/index.js +4 -0
  40. package/dist/runtime/network/index.cjs +28 -0
  41. package/dist/runtime/network/index.d.cts +4 -0
  42. package/dist/runtime/network/index.d.ts +4 -0
  43. package/dist/runtime/network/index.js +6 -0
  44. package/dist/runtime/network/network.cjs +91 -0
  45. package/dist/runtime/network/network.d.cts +28 -0
  46. package/dist/runtime/network/network.d.ts +28 -0
  47. package/dist/runtime/network/network.js +67 -0
  48. package/dist/runtime/recovery/agent.cjs +218 -0
  49. package/dist/runtime/recovery/agent.d.cts +13 -0
  50. package/dist/runtime/recovery/agent.d.ts +13 -0
  51. package/dist/runtime/recovery/agent.js +194 -0
  52. package/dist/runtime/recovery/errors.cjs +122 -0
  53. package/dist/runtime/recovery/errors.d.cts +31 -0
  54. package/dist/runtime/recovery/errors.d.ts +31 -0
  55. package/dist/runtime/recovery/errors.js +98 -0
  56. package/dist/runtime/recovery/index.cjs +34 -0
  57. package/dist/runtime/recovery/index.d.cts +7 -0
  58. package/dist/runtime/recovery/index.d.ts +7 -0
  59. package/dist/runtime/recovery/index.js +10 -0
  60. package/dist/runtime/recovery/recovery.cjs +53 -0
  61. package/dist/runtime/recovery/recovery.d.cts +12 -0
  62. package/dist/runtime/recovery/recovery.d.ts +12 -0
  63. package/dist/runtime/recovery/recovery.js +29 -0
  64. package/dist/runtime/step/index.cjs +31 -0
  65. package/dist/runtime/step/index.d.cts +7 -0
  66. package/dist/runtime/step/index.d.ts +7 -0
  67. package/dist/runtime/step/index.js +6 -0
  68. package/dist/runtime/step/runner.cjs +208 -0
  69. package/dist/runtime/step/runner.d.cts +16 -0
  70. package/dist/runtime/step/runner.d.ts +16 -0
  71. package/dist/runtime/step/runner.js +187 -0
  72. package/dist/runtime/step/step.cjs +67 -0
  73. package/dist/runtime/step/step.d.cts +23 -0
  74. package/dist/runtime/step/step.d.ts +23 -0
  75. package/dist/runtime/step/step.js +43 -0
  76. package/dist/runtime/step/types.cjs +16 -0
  77. package/dist/runtime/step/types.d.cts +72 -0
  78. package/dist/runtime/step/types.d.ts +72 -0
  79. package/dist/runtime/step/types.js +0 -0
  80. package/dist/shared/config/config.cjs +44 -0
  81. package/dist/shared/config/config.d.cts +10 -0
  82. package/dist/shared/config/config.d.ts +10 -0
  83. package/dist/shared/config/config.js +18 -0
  84. package/dist/shared/config/index.cjs +32 -0
  85. package/dist/shared/config/index.d.cts +1 -0
  86. package/dist/shared/config/index.d.ts +1 -0
  87. package/dist/shared/config/index.js +10 -0
  88. package/dist/shared/debug/index.cjs +32 -0
  89. package/dist/shared/debug/index.d.cts +2 -0
  90. package/dist/shared/debug/index.d.ts +2 -0
  91. package/dist/shared/debug/index.js +10 -0
  92. package/dist/shared/debug/pause.cjs +56 -0
  93. package/dist/shared/debug/pause.d.cts +23 -0
  94. package/dist/shared/debug/pause.d.ts +23 -0
  95. package/dist/shared/debug/pause.js +30 -0
  96. package/dist/shared/instrumentation/errors.cjs +81 -0
  97. package/dist/shared/instrumentation/errors.d.cts +12 -0
  98. package/dist/shared/instrumentation/errors.d.ts +12 -0
  99. package/dist/shared/instrumentation/errors.js +57 -0
  100. package/dist/shared/instrumentation/index.cjs +35 -0
  101. package/dist/shared/instrumentation/index.d.cts +6 -0
  102. package/dist/shared/instrumentation/index.d.ts +6 -0
  103. package/dist/shared/instrumentation/index.js +12 -0
  104. package/dist/shared/instrumentation/instrument.cjs +206 -0
  105. package/dist/shared/instrumentation/instrument.d.cts +32 -0
  106. package/dist/shared/instrumentation/instrument.d.ts +32 -0
  107. package/dist/shared/instrumentation/instrument.js +190 -0
  108. package/dist/shared/llm/client.cjs +139 -0
  109. package/dist/shared/llm/client.d.cts +6 -0
  110. package/dist/shared/llm/client.d.ts +6 -0
  111. package/dist/shared/llm/client.js +115 -0
  112. package/dist/shared/llm/index.cjs +28 -0
  113. package/dist/shared/llm/index.d.cts +3 -0
  114. package/dist/shared/llm/index.d.ts +3 -0
  115. package/dist/shared/llm/index.js +4 -0
  116. package/dist/shared/llm/types.cjs +16 -0
  117. package/dist/shared/llm/types.d.cts +34 -0
  118. package/dist/shared/llm/types.d.ts +34 -0
  119. package/dist/shared/llm/types.js +0 -0
  120. package/dist/shared/logger/index.cjs +35 -0
  121. package/dist/shared/logger/index.d.cts +2 -0
  122. package/dist/shared/logger/index.d.ts +2 -0
  123. package/dist/shared/logger/index.js +12 -0
  124. package/dist/shared/logger/logger.cjs +200 -0
  125. package/dist/shared/logger/logger.d.cts +70 -0
  126. package/dist/shared/logger/logger.d.ts +70 -0
  127. package/dist/shared/logger/logger.js +176 -0
  128. package/dist/shared/logger/sinks.cjs +160 -0
  129. package/dist/shared/logger/sinks.d.cts +9 -0
  130. package/dist/shared/logger/sinks.d.ts +9 -0
  131. package/dist/shared/logger/sinks.js +124 -0
  132. package/dist/shared/paths/paths.cjs +104 -0
  133. package/dist/shared/paths/paths.d.cts +10 -0
  134. package/dist/shared/paths/paths.d.ts +10 -0
  135. package/dist/shared/paths/paths.js +73 -0
  136. package/dist/shared/run/api.cjs +35 -0
  137. package/dist/shared/run/api.d.cts +3 -0
  138. package/dist/shared/run/api.d.ts +3 -0
  139. package/dist/shared/run/api.js +12 -0
  140. package/dist/shared/run/browser.cjs +98 -0
  141. package/dist/shared/run/browser.d.cts +22 -0
  142. package/dist/shared/run/browser.d.ts +22 -0
  143. package/dist/shared/run/browser.js +74 -0
  144. package/dist/shared/state/index.cjs +38 -0
  145. package/dist/shared/state/index.d.cts +2 -0
  146. package/dist/shared/state/index.d.ts +2 -0
  147. package/dist/shared/state/index.js +16 -0
  148. package/dist/shared/state/session-state.cjs +85 -0
  149. package/dist/shared/state/session-state.d.cts +34 -0
  150. package/dist/shared/state/session-state.d.ts +34 -0
  151. package/dist/shared/state/session-state.js +56 -0
  152. package/dist/shared/visualization/ghost-cursor.cjs +174 -0
  153. package/dist/shared/visualization/ghost-cursor.d.cts +37 -0
  154. package/dist/shared/visualization/ghost-cursor.d.ts +37 -0
  155. package/dist/shared/visualization/ghost-cursor.js +145 -0
  156. package/dist/shared/visualization/highlight.cjs +134 -0
  157. package/dist/shared/visualization/highlight.d.cts +22 -0
  158. package/dist/shared/visualization/highlight.d.ts +22 -0
  159. package/dist/shared/visualization/highlight.js +108 -0
  160. package/dist/shared/visualization/index.cjs +45 -0
  161. package/dist/shared/visualization/index.d.cts +3 -0
  162. package/dist/shared/visualization/index.d.ts +3 -0
  163. package/dist/shared/visualization/index.js +24 -0
  164. package/dist/shared/workflow/workflow.cjs +47 -0
  165. package/dist/shared/workflow/workflow.d.cts +33 -0
  166. package/dist/shared/workflow/workflow.d.ts +33 -0
  167. package/dist/shared/workflow/workflow.js +21 -0
  168. package/package.json +123 -26
  169. package/.npmignore +0 -2
  170. package/bin/libretto +0 -31
  171. package/lib/connect.js +0 -34
  172. package/lib/export.js +0 -224
  173. package/lib/import.js +0 -168
  174. package/lib/index.js +0 -8
  175. package/lib/log.js +0 -9
  176. package/lib/validate.js +0 -20
  177. package/makefile +0 -8
  178. package/src/connect.coffee +0 -25
  179. package/src/export.coffee +0 -222
  180. package/src/import.coffee +0 -171
  181. package/src/index.coffee +0 -3
  182. package/src/log.coffee +0 -3
  183. 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,3 @@
1
+ export { BrowserSession, LaunchBrowserArgs, launchBrowser } from './browser.cjs';
2
+ export { DebugPauseContext, DebugPauseDetails, DebugPauseSignal, debugPause, isDebugPauseSignal } from '../debug/pause.cjs';
3
+ import 'playwright';
@@ -0,0 +1,3 @@
1
+ export { BrowserSession, LaunchBrowserArgs, launchBrowser } from './browser.js';
2
+ export { DebugPauseContext, DebugPauseDetails, DebugPauseSignal, debugPause, isDebugPauseSignal } from '../debug/pause.js';
3
+ import 'playwright';
@@ -0,0 +1,12 @@
1
+ import { launchBrowser } from "./browser.js";
2
+ import {
3
+ debugPause,
4
+ DebugPauseSignal,
5
+ isDebugPauseSignal
6
+ } from "../debug/pause.js";
7
+ export {
8
+ DebugPauseSignal,
9
+ debugPause,
10
+ isDebugPauseSignal,
11
+ launchBrowser
12
+ };
@@ -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,2 @@
1
+ export { SESSION_STATE_VERSION, SessionState, SessionStateFile, SessionStateFileSchema, SessionStatus, SessionStatusSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState } from './session-state.cjs';
2
+ import 'zod';
@@ -0,0 +1,2 @@
1
+ export { SESSION_STATE_VERSION, SessionState, SessionStateFile, SessionStateFileSchema, SessionStatus, SessionStatusSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState } from './session-state.js';
2
+ import 'zod';
@@ -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
+ };