@pipelab/core-node 1.0.0-beta.17 → 1.0.0-beta.19

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.
@@ -1,11 +1,12 @@
1
1
  import { useAPI, HandleListenerSendFn } from "../ipc-core";
2
- import { PipelabContext } from "../context";
2
+ import { PipelabContext, CacheFolder } from "../context";
3
3
  import { useLogger } from "@pipelab/shared";
4
4
  import { getFinalPlugins, executeGraphWithHistory } from "../utils";
5
5
  import { presets } from "../presets/list";
6
6
  import { handleActionExecute } from "../handler-func";
7
7
  import { join } from "node:path";
8
- import { setupConfigFile } from "../config";
8
+ import { rm } from "node:fs/promises";
9
+ import { setupSettingsConfigFile } from "../config";
9
10
  import { AppConfig } from "@pipelab/shared";
10
11
 
11
12
  export const registerEngineHandlers = (context: PipelabContext) => {
@@ -78,32 +79,35 @@ export const registerEngineHandlers = (context: PipelabContext) => {
78
79
 
79
80
  handle("action:execute", async (event, { send, value }) => {
80
81
  const { nodeId, params, pluginId } = value;
81
- const settings = await setupConfigFile<AppConfig>("settings", { context });
82
- const config = await settings.getConfig();
83
-
84
- const cachePath = join(context.userDataPath, "cache", "actions", pluginId, nodeId);
82
+ const cachePath = context.getCachePath(CacheFolder.Actions, pluginId, nodeId);
85
83
  const cwd = await context.createTempFolder("action-execute-");
86
84
 
87
- const mainWindow: undefined = undefined;
88
- abortControllerGraph = new AbortController();
85
+ try {
86
+ const mainWindow: undefined = undefined;
87
+ abortControllerGraph = new AbortController();
89
88
 
90
- const signalPromise = new Promise((resolve, reject) => {
91
- abortControllerGraph!.signal.addEventListener("abort", async () => {
92
- await send({
93
- type: "end",
94
- data: {
95
- ipcError: "Action aborted",
96
- type: "error",
97
- },
89
+ const signalPromise = new Promise((resolve, reject) => {
90
+ abortControllerGraph!.signal.addEventListener("abort", async () => {
91
+ await send({
92
+ type: "end",
93
+ data: {
94
+ ipcError: "Action aborted",
95
+ type: "error",
96
+ },
97
+ });
98
+ return reject(new Error("Action interrupted"));
98
99
  });
99
- return reject(new Error("Action interrupted"));
100
100
  });
101
- });
102
101
 
103
- await Promise.race([
104
- signalPromise,
105
- effectiveActionExecute(nodeId, pluginId, params, mainWindow, send, cwd, cachePath),
106
- ]);
102
+ await Promise.race([
103
+ signalPromise,
104
+ effectiveActionExecute(nodeId, pluginId, params, mainWindow, send, cwd, cachePath),
105
+ ]);
106
+ } finally {
107
+ await rm(cwd, { recursive: true, force: true }).catch((err) => {
108
+ console.warn(`Failed to cleanup temp folder at ${cwd}:`, err);
109
+ });
110
+ }
107
111
  });
108
112
 
109
113
  handle("constants:get", async (_, { send }) => {
@@ -138,13 +142,13 @@ export const registerEngineHandlers = (context: PipelabContext) => {
138
142
 
139
143
  handle("graph:execute", async (event, { send, value }) => {
140
144
  const { graph, variables, projectName, projectPath, pipelineId } = value;
141
- const settings = await setupConfigFile<AppConfig>("settings", { context });
145
+ const settings = await setupSettingsConfigFile(context);
142
146
  const config = await settings.getConfig();
143
147
 
144
148
  const effectiveProjectName = projectName || "Unnamed Project";
145
149
  const effectiveProjectPath = projectPath || "";
146
150
  const effectivePipelineId = pipelineId || "unknown";
147
- const effectiveCachePath = join(context.userDataPath, "cache", effectivePipelineId);
151
+ const effectiveCachePath = context.getCachePath(CacheFolder.Pipelines, effectivePipelineId);
148
152
 
149
153
  const mainWindow: undefined = undefined;
150
154
  abortControllerGraph = new AbortController();
@@ -284,44 +284,4 @@ export const registerHistoryHandlers = (context: PipelabContext) => {
284
284
  });
285
285
  }
286
286
  });
287
-
288
- handle("build-history:configure", async (_, { send, value }) => {
289
- try {
290
- logger().info("Updating build history configuration:", value.config);
291
-
292
- const settings = await setupConfigFile<AppConfig>("settings", { context });
293
- const currentConfig = await settings.getConfig();
294
-
295
- // Deep merge the new config with the existing one
296
- const newConfig = {
297
- ...currentConfig,
298
- buildHistory: {
299
- ...currentConfig?.buildHistory,
300
- retentionPolicy: {
301
- ...currentConfig?.buildHistory?.retentionPolicy,
302
- ...value.config.retentionPolicy,
303
- },
304
- },
305
- };
306
-
307
- await settings.setConfig(newConfig);
308
-
309
- send({
310
- type: "end",
311
- data: {
312
- type: "success",
313
- result: { result: "ok" },
314
- },
315
- });
316
- } catch (error) {
317
- logger().error("Failed to configure build history:", error);
318
- send({
319
- type: "end",
320
- data: {
321
- type: "error",
322
- ipcError: error instanceof Error ? error.message : "Failed to configure build history",
323
- },
324
- });
325
- }
326
- });
327
287
  };
@@ -7,6 +7,7 @@ import { registerAgentsHandlers } from "./agents";
7
7
  import { registerAuthHandlers } from "./auth";
8
8
  import { registerSystemHandlers } from "./system";
9
9
  import { registerPluginsHandlers } from "./plugins";
10
+ import { registerMigrationHandlers } from "./migration";
10
11
  import { builtInPlugins } from "../plugins-registry";
11
12
  import { usePlugins } from "@pipelab/shared";
12
13
  import { PipelabContext } from "../context";
@@ -26,6 +27,7 @@ export const registerAllHandlers = async (options: {
26
27
  registerAuthHandlers(context);
27
28
  registerSystemHandlers(options);
28
29
  registerPluginsHandlers(context);
30
+ registerMigrationHandlers(context);
29
31
 
30
32
  const { registerPlugins } = usePlugins();
31
33
  // Execute in the background! The plugins will be dynamically registered and broadcasted to the UI.