@recallai/desktop-sdk 2025.7.6-f3a26148a54df7a5d577a9fe3b49203ebb24ff0d → 2025.7.7-3c1cd321bde07a26823d214e97385d2710d9b350

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 (2) hide show
  1. package/index.js +35 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -28,6 +28,19 @@ let lastOptions;
28
28
  let remainingAutomaticRestarts = 10;
29
29
  let unexpectedShutdown = false;
30
30
 
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
+ doLog(buf[idx].level, [buf[idx].log]);
42
+ }
43
+
31
44
  async function doLog(level, log) {
32
45
  try {
33
46
  const levelMap = {
@@ -38,12 +51,21 @@ async function doLog(level, log) {
38
51
 
39
52
  console[levelMap[level]](...log);
40
53
 
41
- await sendCommand("log", {
54
+ let logPayload = {
42
55
  log: log.join(" "),
43
56
  level: level
44
- });
57
+ };
58
+
59
+ let idx = logIndex++;
60
+
61
+ logBuffer[idx] = logPayload;
62
+
63
+ if (proc && proc.exitCode === null) {
64
+ await sendCommand("log", logPayload);
65
+ delete logBuffer[idx];
66
+ }
45
67
  } catch (e) {
46
- //console.error("Log failed:", e.message, e.stack);
68
+ console.error("Failed to send log to Desktop SDK", e.stack, e.message);
47
69
  }
48
70
  }
49
71
 
@@ -74,7 +96,10 @@ function flushPendingCommands(err) {
74
96
  }
75
97
 
76
98
  function startProcess() {
77
- if (proc && proc.exitCode === null) return;
99
+ if (proc && proc.exitCode === null) {
100
+ logError("Desktop SDK: Trying to start process while it is already started");
101
+ return;
102
+ }
78
103
 
79
104
  const exe_path = exe_paths.find(fs.existsSync);
80
105
 
@@ -84,8 +109,6 @@ function startProcess() {
84
109
  for (const exe_path of exe_paths)
85
110
  logError("Tried:", exe_path);
86
111
 
87
- log();
88
-
89
112
  return;
90
113
  }
91
114
 
@@ -156,7 +179,7 @@ function startProcess() {
156
179
  logError(`Desktop SDK: Process error: ${error.message}`);
157
180
  });
158
181
 
159
- proc.on('close', (code, signal) => {
182
+ proc.on('close', async (code, signal) => {
160
183
  flushPendingCommands(new Error(`Process exited with code ${code}, signal ${signal}.`));
161
184
  emitEvent('shutdown', { code, signal });
162
185
 
@@ -170,11 +193,12 @@ function startProcess() {
170
193
  message: "The Desktop SDK server process exited unexpectedly."
171
194
  });
172
195
 
196
+ proc = null;
173
197
  unexpectedShutdown = true;
174
198
 
175
199
  if (lastOptions.restartOnError && remainingAutomaticRestarts > 0) {
176
200
  remainingAutomaticRestarts--;
177
- console.error("Automatically restarting Desktop SDK due to unexpected exit!");
201
+ logError(`Automatically restarting Desktop SDK due to unexpected exit! Automatic restarts left: ${remainingAutomaticRestarts}`);
178
202
  doInit(lastOptions);
179
203
  }
180
204
  });
@@ -200,7 +224,7 @@ function sendCommand(command, params = {}) {
200
224
  });
201
225
  }
202
226
 
203
- function doInit(options) {
227
+ async function doInit(options) {
204
228
  startProcess();
205
229
 
206
230
  if (unexpectedShutdown) {
@@ -208,7 +232,8 @@ function doInit(options) {
208
232
  unexpectedShutdown = false;
209
233
  }
210
234
 
211
- return sendCommand("init", { config: JSON.stringify(options) });
235
+ await sendCommand("init", { config: JSON.stringify(options) });
236
+ flushLogBuffer();
212
237
  }
213
238
 
214
239
  async function init(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recallai/desktop-sdk",
3
- "version": "2025.07.06-f3a26148a54df7a5d577a9fe3b49203ebb24ff0d",
3
+ "version": "2025.07.07-3c1cd321bde07a26823d214e97385d2710d9b350",
4
4
  "description": "Recall Desktop SDK (Alpha)",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",