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