@lightcone-ai/daemon 0.6.1 → 0.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightcone-ai/daemon",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -81,15 +81,16 @@ export class AgentManager {
81
81
 
82
82
  if (config.mysqlAccess) {
83
83
  const mysqlServerPath = new URL('../../mcp-servers/mysql/index.js', import.meta.url).pathname;
84
+ const agentEnv = config.envVars ?? {};
84
85
  mcpServers['mysql'] = {
85
86
  command: 'node',
86
87
  args: [mysqlServerPath],
87
88
  env: {
88
- DB_HOST: process.env.DB_HOST ?? '',
89
+ DB_HOST: process.env.DB_HOST ?? '',
89
90
  DB_PORT: process.env.DB_PORT ?? '3306',
90
91
  DB_USER: process.env.DB_USER ?? '',
91
92
  DB_PASSWORD: process.env.DB_PASSWORD ?? '',
92
- DB_NAME: process.env.DB_NAME ?? '',
93
+ DB_NAME: agentEnv.MYSQL_DB ?? process.env.DB_NAME ?? '',
93
94
  },
94
95
  };
95
96
  }
@@ -154,6 +155,9 @@ export class AgentManager {
154
155
 
155
156
  connection.send({ type: 'agent:status', agentId, channelId, status: 'active' });
156
157
  connection.send({ type: 'agent:activity', agentId, channelId, activity: 'online', detail: '', entries: [] });
158
+
159
+ // Flush any messages that arrived while the agent was starting
160
+ this._flushPending(key, connection);
157
161
  }
158
162
 
159
163
  _stopAgent(agentId, channelId, connection) {
@@ -165,12 +169,29 @@ export class AgentManager {
165
169
  // exit handler will report status
166
170
  }
167
171
 
168
- _deliverMessage({ agentId, channelId, seq, message }, connection) {
172
+ _deliverMessage(msg, connection) {
173
+ const { agentId, channelId, seq, message } = msg;
169
174
  const key = this._key(agentId, channelId);
170
175
  connection.send({ type: 'agent:deliver:ack', agentId, channelId, seq });
171
176
 
172
- if (!this.agents.has(key)) {
173
- console.warn(`[AgentManager] Agent ${agentId} channel=${channelId} not running, dropping seq=${seq}`);
177
+ if (!this.agents.has(key) && !this.starting.has(key)) {
178
+ // Agent not running queue the message and request config to spawn it
179
+ console.log(`[AgentManager] Agent ${agentId} channel=${channelId} not running, requesting start for seq=${seq}`);
180
+ if (!this._pendingMessages) this._pendingMessages = new Map();
181
+ const pending = this._pendingMessages.get(key) ?? [];
182
+ pending.push(msg);
183
+ this._pendingMessages.set(key, pending);
184
+ connection.send({ type: 'agent:request_start', agentId, channelId });
185
+ return;
186
+ }
187
+
188
+ if (this.starting.has(key)) {
189
+ // Spawn in progress — queue the message for delivery after start
190
+ console.log(`[AgentManager] Agent ${agentId} channel=${channelId} still starting, queuing seq=${seq}`);
191
+ if (!this._pendingMessages) this._pendingMessages = new Map();
192
+ const pending = this._pendingMessages.get(key) ?? [];
193
+ pending.push(msg);
194
+ this._pendingMessages.set(key, pending);
174
195
  return;
175
196
  }
176
197
 
@@ -179,6 +200,19 @@ export class AgentManager {
179
200
  this._write(key, text);
180
201
  }
181
202
 
203
+ _flushPending(key, connection) {
204
+ if (!this._pendingMessages) return;
205
+ const pending = this._pendingMessages.get(key);
206
+ if (!pending || pending.length === 0) return;
207
+ this._pendingMessages.delete(key);
208
+ for (const msg of pending) {
209
+ const { agentId, channelId, seq, message } = msg;
210
+ const text = `New message in ${message.channel_type === 'dm' ? `dm from` : `#${message.channel_name} from`} ${message.sender_name}: ${message.content}`;
211
+ console.log(`[AgentManager] Flushing queued seq=${seq} to agent ${agentId} channel=${channelId}`);
212
+ this._write(key, text);
213
+ }
214
+ }
215
+
182
216
  // Write a user message to the running Claude process via stdin
183
217
  _write(key, text) {
184
218
  const agent = this.agents.get(key);