@pipelab/plugin-system 1.0.0-beta.28 → 1.0.0-beta.31
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/dist/index.cjs +77 -9
- package/dist/index.mjs +77 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -144828,6 +144828,58 @@ if (isDev && projectRoot) {
|
|
|
144828
144828
|
}
|
|
144829
144829
|
}
|
|
144830
144830
|
//#endregion
|
|
144831
|
+
//#region ../../packages/core-node/src/api.ts
|
|
144832
|
+
const usePluginAPI = (browserWindow) => {
|
|
144833
|
+
const { logger } = useLogger();
|
|
144834
|
+
/**
|
|
144835
|
+
* Send an order
|
|
144836
|
+
*/
|
|
144837
|
+
const send = (channel, args) => {
|
|
144838
|
+
if (!browserWindow || browserWindow.isDestroyed()) return;
|
|
144839
|
+
browserWindow.webContents.send(channel, args);
|
|
144840
|
+
};
|
|
144841
|
+
const on = (channel, listener) => {
|
|
144842
|
+
if (!browserWindow || browserWindow.isDestroyed()) return () => {};
|
|
144843
|
+
const ipcMain = browserWindow.webContents.ipc.on(channel, listener);
|
|
144844
|
+
const cancel = () => {
|
|
144845
|
+
if (browserWindow.isDestroyed()) return;
|
|
144846
|
+
ipcMain.removeListener(channel, listener);
|
|
144847
|
+
};
|
|
144848
|
+
return cancel;
|
|
144849
|
+
};
|
|
144850
|
+
/**
|
|
144851
|
+
* Send an order and wait for it's execution
|
|
144852
|
+
*/
|
|
144853
|
+
const execute = async (channel, data, listener) => {
|
|
144854
|
+
const newId = nanoid();
|
|
144855
|
+
return new Promise(async (resolve, reject) => {
|
|
144856
|
+
const message = {
|
|
144857
|
+
requestId: newId,
|
|
144858
|
+
data: (0, vue_exports.toRaw)(klona(data))
|
|
144859
|
+
};
|
|
144860
|
+
if (!browserWindow || browserWindow.isDestroyed()) return reject(/* @__PURE__ */ new Error("Browser window is destroyed"));
|
|
144861
|
+
const cancel = on(newId, async (event, data) => {
|
|
144862
|
+
if (data.type === "end") {
|
|
144863
|
+
cancel();
|
|
144864
|
+
return resolve(data.data);
|
|
144865
|
+
} else await listener?.(event, data);
|
|
144866
|
+
});
|
|
144867
|
+
try {
|
|
144868
|
+
browserWindow.webContents.send(channel, message);
|
|
144869
|
+
} catch (e) {
|
|
144870
|
+
logger().error(e);
|
|
144871
|
+
logger().error(channel, message);
|
|
144872
|
+
reject(e);
|
|
144873
|
+
}
|
|
144874
|
+
});
|
|
144875
|
+
};
|
|
144876
|
+
return {
|
|
144877
|
+
send,
|
|
144878
|
+
on,
|
|
144879
|
+
execute
|
|
144880
|
+
};
|
|
144881
|
+
};
|
|
144882
|
+
//#endregion
|
|
144831
144883
|
//#region ../plugin-core/src/pipelab.ts
|
|
144832
144884
|
const createActionRunner = (runner) => runner;
|
|
144833
144885
|
const createEventRunner = (runner) => runner;
|
|
@@ -144874,11 +144926,11 @@ const alertAction = createAction({
|
|
|
144874
144926
|
value: ""
|
|
144875
144927
|
} }
|
|
144876
144928
|
});
|
|
144877
|
-
const alertActionRunner = createActionRunner(async ({ log, inputs,
|
|
144929
|
+
const alertActionRunner = createActionRunner(async ({ log, inputs, setOutput, browserWindow }) => {
|
|
144878
144930
|
browserWindow.flashFrame(true);
|
|
144879
|
-
const _answer = await
|
|
144880
|
-
if ("
|
|
144881
|
-
else
|
|
144931
|
+
const _answer = await usePluginAPI(browserWindow).execute("dialog:alert", { message: inputs.message });
|
|
144932
|
+
if (_answer.type === "success") setOutput("answer", _answer.result.answer);
|
|
144933
|
+
else throw new Error(_answer.ipcError);
|
|
144882
144934
|
});
|
|
144883
144935
|
const promptAction = createAction({
|
|
144884
144936
|
id: "system:prompt",
|
|
@@ -144896,9 +144948,9 @@ const promptAction = createAction({
|
|
|
144896
144948
|
value: ""
|
|
144897
144949
|
} }
|
|
144898
144950
|
});
|
|
144899
|
-
const promptActionRunner = createActionRunner(async ({ log, inputs,
|
|
144951
|
+
const promptActionRunner = createActionRunner(async ({ log, inputs, setOutput, browserWindow }) => {
|
|
144900
144952
|
browserWindow.flashFrame(true);
|
|
144901
|
-
const _answer = await
|
|
144953
|
+
const _answer = await usePluginAPI(browserWindow).execute("dialog:prompt", { message: inputs.message });
|
|
144902
144954
|
log("_answer", _answer);
|
|
144903
144955
|
if (_answer.type === "success") setOutput("answer", _answer.result.answer);
|
|
144904
144956
|
else throw new Error(_answer.ipcError);
|
|
@@ -144916,9 +144968,25 @@ const sleepAction = createAction({
|
|
|
144916
144968
|
}) },
|
|
144917
144969
|
outputs: {}
|
|
144918
144970
|
});
|
|
144919
|
-
const
|
|
144920
|
-
|
|
144921
|
-
|
|
144971
|
+
const sleepActionRunner = createActionRunner(async ({ inputs, abortSignal }) => {
|
|
144972
|
+
if (abortSignal.aborted) {
|
|
144973
|
+
const abortError = /* @__PURE__ */ new Error("Aborted");
|
|
144974
|
+
abortError.name = "AbortError";
|
|
144975
|
+
throw abortError;
|
|
144976
|
+
}
|
|
144977
|
+
await new Promise((resolve, reject) => {
|
|
144978
|
+
const onAbort = () => {
|
|
144979
|
+
clearTimeout(timeout);
|
|
144980
|
+
const abortError = /* @__PURE__ */ new Error("Aborted");
|
|
144981
|
+
abortError.name = "AbortError";
|
|
144982
|
+
reject(abortError);
|
|
144983
|
+
};
|
|
144984
|
+
abortSignal.addEventListener("abort", onAbort);
|
|
144985
|
+
const timeout = setTimeout(() => {
|
|
144986
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
144987
|
+
resolve();
|
|
144988
|
+
}, inputs.duration);
|
|
144989
|
+
});
|
|
144922
144990
|
});
|
|
144923
144991
|
//#endregion
|
|
144924
144992
|
//#region src/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -144829,6 +144829,58 @@ if (isDev && projectRoot) {
|
|
|
144829
144829
|
}
|
|
144830
144830
|
}
|
|
144831
144831
|
//#endregion
|
|
144832
|
+
//#region ../../packages/core-node/src/api.ts
|
|
144833
|
+
const usePluginAPI = (browserWindow) => {
|
|
144834
|
+
const { logger } = useLogger();
|
|
144835
|
+
/**
|
|
144836
|
+
* Send an order
|
|
144837
|
+
*/
|
|
144838
|
+
const send = (channel, args) => {
|
|
144839
|
+
if (!browserWindow || browserWindow.isDestroyed()) return;
|
|
144840
|
+
browserWindow.webContents.send(channel, args);
|
|
144841
|
+
};
|
|
144842
|
+
const on = (channel, listener) => {
|
|
144843
|
+
if (!browserWindow || browserWindow.isDestroyed()) return () => {};
|
|
144844
|
+
const ipcMain = browserWindow.webContents.ipc.on(channel, listener);
|
|
144845
|
+
const cancel = () => {
|
|
144846
|
+
if (browserWindow.isDestroyed()) return;
|
|
144847
|
+
ipcMain.removeListener(channel, listener);
|
|
144848
|
+
};
|
|
144849
|
+
return cancel;
|
|
144850
|
+
};
|
|
144851
|
+
/**
|
|
144852
|
+
* Send an order and wait for it's execution
|
|
144853
|
+
*/
|
|
144854
|
+
const execute = async (channel, data, listener) => {
|
|
144855
|
+
const newId = nanoid();
|
|
144856
|
+
return new Promise(async (resolve, reject) => {
|
|
144857
|
+
const message = {
|
|
144858
|
+
requestId: newId,
|
|
144859
|
+
data: (0, vue_exports.toRaw)(klona(data))
|
|
144860
|
+
};
|
|
144861
|
+
if (!browserWindow || browserWindow.isDestroyed()) return reject(/* @__PURE__ */ new Error("Browser window is destroyed"));
|
|
144862
|
+
const cancel = on(newId, async (event, data) => {
|
|
144863
|
+
if (data.type === "end") {
|
|
144864
|
+
cancel();
|
|
144865
|
+
return resolve(data.data);
|
|
144866
|
+
} else await listener?.(event, data);
|
|
144867
|
+
});
|
|
144868
|
+
try {
|
|
144869
|
+
browserWindow.webContents.send(channel, message);
|
|
144870
|
+
} catch (e) {
|
|
144871
|
+
logger().error(e);
|
|
144872
|
+
logger().error(channel, message);
|
|
144873
|
+
reject(e);
|
|
144874
|
+
}
|
|
144875
|
+
});
|
|
144876
|
+
};
|
|
144877
|
+
return {
|
|
144878
|
+
send,
|
|
144879
|
+
on,
|
|
144880
|
+
execute
|
|
144881
|
+
};
|
|
144882
|
+
};
|
|
144883
|
+
//#endregion
|
|
144832
144884
|
//#region ../plugin-core/src/pipelab.ts
|
|
144833
144885
|
const createActionRunner = (runner) => runner;
|
|
144834
144886
|
const createEventRunner = (runner) => runner;
|
|
@@ -144875,11 +144927,11 @@ const alertAction = createAction({
|
|
|
144875
144927
|
value: ""
|
|
144876
144928
|
} }
|
|
144877
144929
|
});
|
|
144878
|
-
const alertActionRunner = createActionRunner(async ({ log, inputs,
|
|
144930
|
+
const alertActionRunner = createActionRunner(async ({ log, inputs, setOutput, browserWindow }) => {
|
|
144879
144931
|
browserWindow.flashFrame(true);
|
|
144880
|
-
const _answer = await
|
|
144881
|
-
if ("
|
|
144882
|
-
else
|
|
144932
|
+
const _answer = await usePluginAPI(browserWindow).execute("dialog:alert", { message: inputs.message });
|
|
144933
|
+
if (_answer.type === "success") setOutput("answer", _answer.result.answer);
|
|
144934
|
+
else throw new Error(_answer.ipcError);
|
|
144883
144935
|
});
|
|
144884
144936
|
const promptAction = createAction({
|
|
144885
144937
|
id: "system:prompt",
|
|
@@ -144897,9 +144949,9 @@ const promptAction = createAction({
|
|
|
144897
144949
|
value: ""
|
|
144898
144950
|
} }
|
|
144899
144951
|
});
|
|
144900
|
-
const promptActionRunner = createActionRunner(async ({ log, inputs,
|
|
144952
|
+
const promptActionRunner = createActionRunner(async ({ log, inputs, setOutput, browserWindow }) => {
|
|
144901
144953
|
browserWindow.flashFrame(true);
|
|
144902
|
-
const _answer = await
|
|
144954
|
+
const _answer = await usePluginAPI(browserWindow).execute("dialog:prompt", { message: inputs.message });
|
|
144903
144955
|
log("_answer", _answer);
|
|
144904
144956
|
if (_answer.type === "success") setOutput("answer", _answer.result.answer);
|
|
144905
144957
|
else throw new Error(_answer.ipcError);
|
|
@@ -144917,9 +144969,25 @@ const sleepAction = createAction({
|
|
|
144917
144969
|
}) },
|
|
144918
144970
|
outputs: {}
|
|
144919
144971
|
});
|
|
144920
|
-
const
|
|
144921
|
-
|
|
144922
|
-
|
|
144972
|
+
const sleepActionRunner = createActionRunner(async ({ inputs, abortSignal }) => {
|
|
144973
|
+
if (abortSignal.aborted) {
|
|
144974
|
+
const abortError = /* @__PURE__ */ new Error("Aborted");
|
|
144975
|
+
abortError.name = "AbortError";
|
|
144976
|
+
throw abortError;
|
|
144977
|
+
}
|
|
144978
|
+
await new Promise((resolve, reject) => {
|
|
144979
|
+
const onAbort = () => {
|
|
144980
|
+
clearTimeout(timeout);
|
|
144981
|
+
const abortError = /* @__PURE__ */ new Error("Aborted");
|
|
144982
|
+
abortError.name = "AbortError";
|
|
144983
|
+
reject(abortError);
|
|
144984
|
+
};
|
|
144985
|
+
abortSignal.addEventListener("abort", onAbort);
|
|
144986
|
+
const timeout = setTimeout(() => {
|
|
144987
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
144988
|
+
resolve();
|
|
144989
|
+
}, inputs.duration);
|
|
144990
|
+
});
|
|
144923
144991
|
});
|
|
144924
144992
|
//#endregion
|
|
144925
144993
|
//#region src/index.ts
|