@recallai/desktop-sdk 2025.7.7-f942f66dd0374c767882a285f9f4fd8ae0f428e4 → 2025.7.9-76c1703ef5aec16f4fdc217bc94d55d56b620a53
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/index.js +52 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -28,7 +28,22 @@ let lastOptions;
|
|
|
28
28
|
let remainingAutomaticRestarts = 10;
|
|
29
29
|
let unexpectedShutdown = false;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
let logBuffer = [];
|
|
32
|
+
let logIndex = 0;
|
|
33
|
+
|
|
34
|
+
function flushLogBuffer() {
|
|
35
|
+
const buf = logBuffer.slice();
|
|
36
|
+
|
|
37
|
+
logBuffer = [];
|
|
38
|
+
logIndex = 0;
|
|
39
|
+
|
|
40
|
+
for (const idx in buf) {
|
|
41
|
+
const { level, log, echo } = buf[idx];
|
|
42
|
+
doLog(level, [log], echo);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function doLog(level, log, echo = true) {
|
|
32
47
|
try {
|
|
33
48
|
const levelMap = {
|
|
34
49
|
"info": "log",
|
|
@@ -36,14 +51,25 @@ async function doLog(level, log) {
|
|
|
36
51
|
"error": "error"
|
|
37
52
|
};
|
|
38
53
|
|
|
39
|
-
|
|
54
|
+
if (echo)
|
|
55
|
+
console[levelMap[level] ?? "log"](...log);
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
let logPayload = {
|
|
42
58
|
log: log.join(" "),
|
|
43
|
-
level: level
|
|
44
|
-
|
|
59
|
+
level: level,
|
|
60
|
+
echo
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
let idx = logIndex++;
|
|
64
|
+
|
|
65
|
+
logBuffer[idx] = logPayload;
|
|
66
|
+
|
|
67
|
+
if (proc && proc.exitCode === null) {
|
|
68
|
+
await sendCommand("log", logPayload);
|
|
69
|
+
delete logBuffer[idx];
|
|
70
|
+
}
|
|
45
71
|
} catch (e) {
|
|
46
|
-
|
|
72
|
+
console.error("Failed to send log to Desktop SDK", e.stack, e.message);
|
|
47
73
|
}
|
|
48
74
|
}
|
|
49
75
|
|
|
@@ -60,6 +86,10 @@ function logError(...log) {
|
|
|
60
86
|
}
|
|
61
87
|
|
|
62
88
|
function emitEvent(type, payload) {
|
|
89
|
+
if (type !== "upload-progress" && type !== "realtime-event") {
|
|
90
|
+
doLog("info", ["Receiving event: " + type + " | " + JSON.stringify(payload)], false);
|
|
91
|
+
}
|
|
92
|
+
|
|
63
93
|
for (const listener of listeners) {
|
|
64
94
|
if (listener.type === type)
|
|
65
95
|
listener.callback(payload);
|
|
@@ -74,7 +104,10 @@ function flushPendingCommands(err) {
|
|
|
74
104
|
}
|
|
75
105
|
|
|
76
106
|
function startProcess() {
|
|
77
|
-
if (proc && proc.exitCode === null)
|
|
107
|
+
if (proc && proc.exitCode === null) {
|
|
108
|
+
logError("Desktop SDK: Trying to start process while it is already started");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
78
111
|
|
|
79
112
|
const exe_path = exe_paths.find(fs.existsSync);
|
|
80
113
|
|
|
@@ -84,8 +117,6 @@ function startProcess() {
|
|
|
84
117
|
for (const exe_path of exe_paths)
|
|
85
118
|
logError("Tried:", exe_path);
|
|
86
119
|
|
|
87
|
-
log();
|
|
88
|
-
|
|
89
120
|
return;
|
|
90
121
|
}
|
|
91
122
|
|
|
@@ -156,7 +187,7 @@ function startProcess() {
|
|
|
156
187
|
logError(`Desktop SDK: Process error: ${error.message}`);
|
|
157
188
|
});
|
|
158
189
|
|
|
159
|
-
proc.on('close', (code, signal) => {
|
|
190
|
+
proc.on('close', async (code, signal) => {
|
|
160
191
|
flushPendingCommands(new Error(`Process exited with code ${code}, signal ${signal}.`));
|
|
161
192
|
emitEvent('shutdown', { code, signal });
|
|
162
193
|
|
|
@@ -170,11 +201,12 @@ function startProcess() {
|
|
|
170
201
|
message: "The Desktop SDK server process exited unexpectedly."
|
|
171
202
|
});
|
|
172
203
|
|
|
204
|
+
proc = null;
|
|
173
205
|
unexpectedShutdown = true;
|
|
174
206
|
|
|
175
207
|
if (lastOptions.restartOnError && remainingAutomaticRestarts > 0) {
|
|
176
208
|
remainingAutomaticRestarts--;
|
|
177
|
-
|
|
209
|
+
logError(`Automatically restarting Desktop SDK due to unexpected exit! Automatic restarts left: ${remainingAutomaticRestarts}`);
|
|
178
210
|
doInit(lastOptions);
|
|
179
211
|
}
|
|
180
212
|
});
|
|
@@ -196,11 +228,16 @@ function sendCommand(command, params = {}) {
|
|
|
196
228
|
params
|
|
197
229
|
};
|
|
198
230
|
|
|
199
|
-
|
|
231
|
+
let payloadStr = JSON.stringify(payload);
|
|
232
|
+
proc.stdin.write(payloadStr + "\n");
|
|
233
|
+
|
|
234
|
+
if (command !== "log") {
|
|
235
|
+
doLog("info", ["Sending command: " + payloadStr], false);
|
|
236
|
+
}
|
|
200
237
|
});
|
|
201
238
|
}
|
|
202
239
|
|
|
203
|
-
function doInit(options) {
|
|
240
|
+
async function doInit(options) {
|
|
204
241
|
startProcess();
|
|
205
242
|
|
|
206
243
|
if (unexpectedShutdown) {
|
|
@@ -208,7 +245,8 @@ function doInit(options) {
|
|
|
208
245
|
unexpectedShutdown = false;
|
|
209
246
|
}
|
|
210
247
|
|
|
211
|
-
|
|
248
|
+
await sendCommand("init", { config: JSON.stringify(options) });
|
|
249
|
+
flushLogBuffer();
|
|
212
250
|
}
|
|
213
251
|
|
|
214
252
|
async function init(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@recallai/desktop-sdk",
|
|
3
|
-
"version": "2025.07.
|
|
3
|
+
"version": "2025.07.09-76c1703ef5aec16f4fdc217bc94d55d56b620a53",
|
|
4
4
|
"description": "Recall Desktop SDK (Alpha)",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|