@hasna/conversations 0.1.21 → 0.1.23
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/bin/index.js +84 -50
- package/bin/mcp.js +48 -43
- package/dist/index.js +18 -12
- package/package.json +1 -1
- package/dashboard/dist/assets/index-Bw0wMcXE.js +0 -186
- package/dashboard/dist/assets/index-CF_GDtNp.css +0 -1
- package/dashboard/dist/index.html +0 -13
- package/dashboard/dist/logo.jpg +0 -0
package/bin/mcp.js
CHANGED
|
@@ -6302,7 +6302,7 @@ var require_formats = __commonJS((exports) => {
|
|
|
6302
6302
|
}
|
|
6303
6303
|
var TIME = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;
|
|
6304
6304
|
function getTime(strictTimeZone) {
|
|
6305
|
-
return function
|
|
6305
|
+
return function time3(str) {
|
|
6306
6306
|
const matches = TIME.exec(str);
|
|
6307
6307
|
if (!matches)
|
|
6308
6308
|
return false;
|
|
@@ -29252,10 +29252,6 @@ function getProjectByName(name) {
|
|
|
29252
29252
|
}
|
|
29253
29253
|
function updateProject(id, updates) {
|
|
29254
29254
|
const db2 = getDb();
|
|
29255
|
-
const existing = db2.prepare("SELECT * FROM projects WHERE id = ?").get(id);
|
|
29256
|
-
if (!existing) {
|
|
29257
|
-
throw new Error(`Project not found: ${id}`);
|
|
29258
|
-
}
|
|
29259
29255
|
const sets = [];
|
|
29260
29256
|
const params = [];
|
|
29261
29257
|
if (updates.name !== undefined) {
|
|
@@ -29291,10 +29287,15 @@ function updateProject(id, updates) {
|
|
|
29291
29287
|
params.push(JSON.stringify(updates.settings));
|
|
29292
29288
|
}
|
|
29293
29289
|
if (sets.length === 0) {
|
|
29294
|
-
|
|
29290
|
+
const row2 = db2.prepare("SELECT * FROM projects WHERE id = ?").get(id);
|
|
29291
|
+
if (!row2)
|
|
29292
|
+
throw new Error(`Project not found: ${id}`);
|
|
29293
|
+
return parseProject(row2);
|
|
29295
29294
|
}
|
|
29296
29295
|
params.push(id);
|
|
29297
29296
|
const row = db2.prepare(`UPDATE projects SET ${sets.join(", ")} WHERE id = ? RETURNING *`).get(...params);
|
|
29297
|
+
if (!row)
|
|
29298
|
+
throw new Error(`Project not found: ${id}`);
|
|
29298
29299
|
return parseProject(row);
|
|
29299
29300
|
}
|
|
29300
29301
|
function deleteProject(id) {
|
|
@@ -29738,6 +29739,7 @@ function heartbeat(agent, status, metadata) {
|
|
|
29738
29739
|
const db2 = getDb();
|
|
29739
29740
|
const metadataJson = metadata ? JSON.stringify(metadata) : null;
|
|
29740
29741
|
const resolvedStatus = status || "online";
|
|
29742
|
+
const normalizedAgent = agent.trim().toLowerCase();
|
|
29741
29743
|
db2.prepare(`
|
|
29742
29744
|
INSERT INTO agent_presence (agent, status, last_seen_at, metadata)
|
|
29743
29745
|
VALUES (?, ?, strftime('%Y-%m-%dT%H:%M:%f', 'now'), ?)
|
|
@@ -29745,7 +29747,7 @@ function heartbeat(agent, status, metadata) {
|
|
|
29745
29747
|
status = excluded.status,
|
|
29746
29748
|
last_seen_at = excluded.last_seen_at,
|
|
29747
29749
|
metadata = excluded.metadata
|
|
29748
|
-
`).run(
|
|
29750
|
+
`).run(normalizedAgent, resolvedStatus, metadataJson);
|
|
29749
29751
|
}
|
|
29750
29752
|
function listAgents(opts) {
|
|
29751
29753
|
const db2 = getDb();
|
|
@@ -29760,24 +29762,27 @@ function listAgents(opts) {
|
|
|
29760
29762
|
}
|
|
29761
29763
|
function removePresence(agent) {
|
|
29762
29764
|
const db2 = getDb();
|
|
29763
|
-
const
|
|
29765
|
+
const normalizedAgent = agent.trim().toLowerCase();
|
|
29766
|
+
const result = db2.prepare("DELETE FROM agent_presence WHERE LOWER(agent) = ?").run(normalizedAgent);
|
|
29764
29767
|
return result.changes > 0;
|
|
29765
29768
|
}
|
|
29766
29769
|
function renameAgent(oldName, newName) {
|
|
29767
29770
|
const db2 = getDb();
|
|
29768
|
-
const
|
|
29771
|
+
const normalizedOld = oldName.trim().toLowerCase();
|
|
29772
|
+
const normalizedNew = newName.trim().toLowerCase();
|
|
29773
|
+
const existing = db2.prepare("SELECT agent FROM agent_presence WHERE LOWER(agent) = ?").get(normalizedOld);
|
|
29769
29774
|
if (!existing)
|
|
29770
29775
|
return false;
|
|
29771
|
-
const conflict = db2.prepare("SELECT agent FROM agent_presence WHERE agent = ?").get(
|
|
29776
|
+
const conflict = db2.prepare("SELECT agent FROM agent_presence WHERE LOWER(agent) = ?").get(normalizedNew);
|
|
29772
29777
|
if (conflict)
|
|
29773
|
-
throw new Error(`Agent "${
|
|
29774
|
-
db2.prepare("UPDATE agent_presence SET agent = ? WHERE agent = ?").run(
|
|
29778
|
+
throw new Error(`Agent "${normalizedNew}" already exists`);
|
|
29779
|
+
db2.prepare("UPDATE agent_presence SET agent = ? WHERE LOWER(agent) = ?").run(normalizedNew, normalizedOld);
|
|
29775
29780
|
return true;
|
|
29776
29781
|
}
|
|
29777
29782
|
// package.json
|
|
29778
29783
|
var package_default = {
|
|
29779
29784
|
name: "@hasna/conversations",
|
|
29780
|
-
version: "0.1.
|
|
29785
|
+
version: "0.1.23",
|
|
29781
29786
|
description: "Real-time CLI messaging for AI agents",
|
|
29782
29787
|
type: "module",
|
|
29783
29788
|
bin: {
|
|
@@ -29879,7 +29884,7 @@ server.registerTool("send_message", {
|
|
|
29879
29884
|
blocking
|
|
29880
29885
|
});
|
|
29881
29886
|
return {
|
|
29882
|
-
content: [{ type: "text", text: JSON.stringify(msg
|
|
29887
|
+
content: [{ type: "text", text: JSON.stringify(msg) }]
|
|
29883
29888
|
};
|
|
29884
29889
|
});
|
|
29885
29890
|
server.registerTool("read_messages", {
|
|
@@ -29896,7 +29901,7 @@ server.registerTool("read_messages", {
|
|
|
29896
29901
|
}, async (args) => {
|
|
29897
29902
|
const messages = readMessages(args);
|
|
29898
29903
|
return {
|
|
29899
|
-
content: [{ type: "text", text: JSON.stringify(messages
|
|
29904
|
+
content: [{ type: "text", text: JSON.stringify(messages) }]
|
|
29900
29905
|
};
|
|
29901
29906
|
});
|
|
29902
29907
|
server.registerTool("list_sessions", {
|
|
@@ -29908,7 +29913,7 @@ server.registerTool("list_sessions", {
|
|
|
29908
29913
|
const { agent } = args;
|
|
29909
29914
|
const sessions = listSessions(agent);
|
|
29910
29915
|
return {
|
|
29911
|
-
content: [{ type: "text", text: JSON.stringify(sessions
|
|
29916
|
+
content: [{ type: "text", text: JSON.stringify(sessions) }]
|
|
29912
29917
|
};
|
|
29913
29918
|
});
|
|
29914
29919
|
server.registerTool("reply", {
|
|
@@ -29938,7 +29943,7 @@ server.registerTool("reply", {
|
|
|
29938
29943
|
space
|
|
29939
29944
|
});
|
|
29940
29945
|
return {
|
|
29941
|
-
content: [{ type: "text", text: JSON.stringify(msg
|
|
29946
|
+
content: [{ type: "text", text: JSON.stringify(msg) }]
|
|
29942
29947
|
};
|
|
29943
29948
|
});
|
|
29944
29949
|
server.registerTool("mark_read", {
|
|
@@ -29963,7 +29968,7 @@ server.registerTool("mark_read", {
|
|
|
29963
29968
|
};
|
|
29964
29969
|
}
|
|
29965
29970
|
return {
|
|
29966
|
-
content: [{ type: "text", text: JSON.stringify({ marked_read: count }
|
|
29971
|
+
content: [{ type: "text", text: JSON.stringify({ marked_read: count }) }]
|
|
29967
29972
|
};
|
|
29968
29973
|
});
|
|
29969
29974
|
server.registerTool("search_messages", {
|
|
@@ -29979,7 +29984,7 @@ server.registerTool("search_messages", {
|
|
|
29979
29984
|
const { query, space, from, to, limit } = args;
|
|
29980
29985
|
const messages = searchMessages({ query, space, from, to, limit });
|
|
29981
29986
|
return {
|
|
29982
|
-
content: [{ type: "text", text: JSON.stringify(messages
|
|
29987
|
+
content: [{ type: "text", text: JSON.stringify(messages) }]
|
|
29983
29988
|
};
|
|
29984
29989
|
});
|
|
29985
29990
|
server.registerTool("export_messages", {
|
|
@@ -30014,7 +30019,7 @@ server.registerTool("create_space", {
|
|
|
30014
30019
|
try {
|
|
30015
30020
|
const sp = createSpace(name, agent, { description, parent_id, project_id });
|
|
30016
30021
|
return {
|
|
30017
|
-
content: [{ type: "text", text: JSON.stringify(sp
|
|
30022
|
+
content: [{ type: "text", text: JSON.stringify(sp) }]
|
|
30018
30023
|
};
|
|
30019
30024
|
} catch (e) {
|
|
30020
30025
|
if (e.message?.includes("UNIQUE constraint")) {
|
|
@@ -30050,7 +30055,7 @@ server.registerTool("list_spaces", {
|
|
|
30050
30055
|
opts.include_archived = true;
|
|
30051
30056
|
const spaces = listSpaces(opts);
|
|
30052
30057
|
return {
|
|
30053
|
-
content: [{ type: "text", text: JSON.stringify(spaces
|
|
30058
|
+
content: [{ type: "text", text: JSON.stringify(spaces) }]
|
|
30054
30059
|
};
|
|
30055
30060
|
});
|
|
30056
30061
|
server.registerTool("send_to_space", {
|
|
@@ -30082,7 +30087,7 @@ server.registerTool("send_to_space", {
|
|
|
30082
30087
|
blocking
|
|
30083
30088
|
});
|
|
30084
30089
|
return {
|
|
30085
|
-
content: [{ type: "text", text: JSON.stringify(msg
|
|
30090
|
+
content: [{ type: "text", text: JSON.stringify(msg) }]
|
|
30086
30091
|
};
|
|
30087
30092
|
});
|
|
30088
30093
|
server.registerTool("read_space", {
|
|
@@ -30096,7 +30101,7 @@ server.registerTool("read_space", {
|
|
|
30096
30101
|
const { space, since, limit } = args;
|
|
30097
30102
|
const messages = readMessages({ space, since, limit });
|
|
30098
30103
|
return {
|
|
30099
|
-
content: [{ type: "text", text: JSON.stringify(messages
|
|
30104
|
+
content: [{ type: "text", text: JSON.stringify(messages) }]
|
|
30100
30105
|
};
|
|
30101
30106
|
});
|
|
30102
30107
|
server.registerTool("join_space", {
|
|
@@ -30116,7 +30121,7 @@ server.registerTool("join_space", {
|
|
|
30116
30121
|
};
|
|
30117
30122
|
}
|
|
30118
30123
|
return {
|
|
30119
|
-
content: [{ type: "text", text: JSON.stringify({ space, agent, joined: true }
|
|
30124
|
+
content: [{ type: "text", text: JSON.stringify({ space, agent, joined: true }) }]
|
|
30120
30125
|
};
|
|
30121
30126
|
});
|
|
30122
30127
|
server.registerTool("leave_space", {
|
|
@@ -30130,7 +30135,7 @@ server.registerTool("leave_space", {
|
|
|
30130
30135
|
const agent = resolveIdentity(fromParam);
|
|
30131
30136
|
const left = leaveSpace(space, agent);
|
|
30132
30137
|
return {
|
|
30133
|
-
content: [{ type: "text", text: JSON.stringify({ space, agent, left }
|
|
30138
|
+
content: [{ type: "text", text: JSON.stringify({ space, agent, left }) }]
|
|
30134
30139
|
};
|
|
30135
30140
|
});
|
|
30136
30141
|
server.registerTool("update_space", {
|
|
@@ -30153,7 +30158,7 @@ server.registerTool("update_space", {
|
|
|
30153
30158
|
try {
|
|
30154
30159
|
const sp = updateSpace(name, updates);
|
|
30155
30160
|
return {
|
|
30156
|
-
content: [{ type: "text", text: JSON.stringify(sp
|
|
30161
|
+
content: [{ type: "text", text: JSON.stringify(sp) }]
|
|
30157
30162
|
};
|
|
30158
30163
|
} catch (e) {
|
|
30159
30164
|
return {
|
|
@@ -30171,7 +30176,7 @@ server.registerTool("archive_space", {
|
|
|
30171
30176
|
try {
|
|
30172
30177
|
const sp = archiveSpace(name);
|
|
30173
30178
|
return {
|
|
30174
|
-
content: [{ type: "text", text: JSON.stringify(sp
|
|
30179
|
+
content: [{ type: "text", text: JSON.stringify(sp) }]
|
|
30175
30180
|
};
|
|
30176
30181
|
} catch (e) {
|
|
30177
30182
|
return {
|
|
@@ -30189,7 +30194,7 @@ server.registerTool("unarchive_space", {
|
|
|
30189
30194
|
try {
|
|
30190
30195
|
const sp = unarchiveSpace(name);
|
|
30191
30196
|
return {
|
|
30192
|
-
content: [{ type: "text", text: JSON.stringify(sp
|
|
30197
|
+
content: [{ type: "text", text: JSON.stringify(sp) }]
|
|
30193
30198
|
};
|
|
30194
30199
|
} catch (e) {
|
|
30195
30200
|
return {
|
|
@@ -30258,7 +30263,7 @@ server.registerTool("create_project", {
|
|
|
30258
30263
|
settings: parsedSettings
|
|
30259
30264
|
});
|
|
30260
30265
|
return {
|
|
30261
|
-
content: [{ type: "text", text: JSON.stringify(project
|
|
30266
|
+
content: [{ type: "text", text: JSON.stringify(project) }]
|
|
30262
30267
|
};
|
|
30263
30268
|
} catch (e) {
|
|
30264
30269
|
if (e.message?.includes("UNIQUE constraint")) {
|
|
@@ -30282,7 +30287,7 @@ server.registerTool("list_projects", {
|
|
|
30282
30287
|
const { status } = args;
|
|
30283
30288
|
const projects = listProjects(status ? { status } : undefined);
|
|
30284
30289
|
return {
|
|
30285
|
-
content: [{ type: "text", text: JSON.stringify(projects
|
|
30290
|
+
content: [{ type: "text", text: JSON.stringify(projects) }]
|
|
30286
30291
|
};
|
|
30287
30292
|
});
|
|
30288
30293
|
server.registerTool("get_project", {
|
|
@@ -30302,7 +30307,7 @@ server.registerTool("get_project", {
|
|
|
30302
30307
|
};
|
|
30303
30308
|
}
|
|
30304
30309
|
return {
|
|
30305
|
-
content: [{ type: "text", text: JSON.stringify(project
|
|
30310
|
+
content: [{ type: "text", text: JSON.stringify(project) }]
|
|
30306
30311
|
};
|
|
30307
30312
|
});
|
|
30308
30313
|
server.registerTool("update_project", {
|
|
@@ -30364,7 +30369,7 @@ server.registerTool("update_project", {
|
|
|
30364
30369
|
try {
|
|
30365
30370
|
const project = updateProject(id, updates);
|
|
30366
30371
|
return {
|
|
30367
|
-
content: [{ type: "text", text: JSON.stringify(project
|
|
30372
|
+
content: [{ type: "text", text: JSON.stringify(project) }]
|
|
30368
30373
|
};
|
|
30369
30374
|
} catch (e) {
|
|
30370
30375
|
return {
|
|
@@ -30388,7 +30393,7 @@ server.registerTool("delete_project", {
|
|
|
30388
30393
|
};
|
|
30389
30394
|
}
|
|
30390
30395
|
return {
|
|
30391
|
-
content: [{ type: "text", text: JSON.stringify({ id, deleted: true }
|
|
30396
|
+
content: [{ type: "text", text: JSON.stringify({ id, deleted: true }) }]
|
|
30392
30397
|
};
|
|
30393
30398
|
} catch (e) {
|
|
30394
30399
|
return {
|
|
@@ -30414,7 +30419,7 @@ server.registerTool("delete_message", {
|
|
|
30414
30419
|
};
|
|
30415
30420
|
}
|
|
30416
30421
|
return {
|
|
30417
|
-
content: [{ type: "text", text: JSON.stringify({ deleted: true }
|
|
30422
|
+
content: [{ type: "text", text: JSON.stringify({ deleted: true }) }]
|
|
30418
30423
|
};
|
|
30419
30424
|
});
|
|
30420
30425
|
server.registerTool("edit_message", {
|
|
@@ -30435,7 +30440,7 @@ server.registerTool("edit_message", {
|
|
|
30435
30440
|
};
|
|
30436
30441
|
}
|
|
30437
30442
|
return {
|
|
30438
|
-
content: [{ type: "text", text: JSON.stringify(msg
|
|
30443
|
+
content: [{ type: "text", text: JSON.stringify(msg) }]
|
|
30439
30444
|
};
|
|
30440
30445
|
});
|
|
30441
30446
|
server.registerTool("pin_message", {
|
|
@@ -30452,7 +30457,7 @@ server.registerTool("pin_message", {
|
|
|
30452
30457
|
};
|
|
30453
30458
|
}
|
|
30454
30459
|
return {
|
|
30455
|
-
content: [{ type: "text", text: JSON.stringify(msg
|
|
30460
|
+
content: [{ type: "text", text: JSON.stringify(msg) }]
|
|
30456
30461
|
};
|
|
30457
30462
|
});
|
|
30458
30463
|
server.registerTool("unpin_message", {
|
|
@@ -30469,7 +30474,7 @@ server.registerTool("unpin_message", {
|
|
|
30469
30474
|
};
|
|
30470
30475
|
}
|
|
30471
30476
|
return {
|
|
30472
|
-
content: [{ type: "text", text: JSON.stringify(msg
|
|
30477
|
+
content: [{ type: "text", text: JSON.stringify(msg) }]
|
|
30473
30478
|
};
|
|
30474
30479
|
});
|
|
30475
30480
|
server.registerTool("get_pinned_messages", {
|
|
@@ -30483,7 +30488,7 @@ server.registerTool("get_pinned_messages", {
|
|
|
30483
30488
|
const { space, session_id, limit } = args;
|
|
30484
30489
|
const messages = getPinnedMessages({ space, session_id, limit });
|
|
30485
30490
|
return {
|
|
30486
|
-
content: [{ type: "text", text: JSON.stringify(messages
|
|
30491
|
+
content: [{ type: "text", text: JSON.stringify(messages) }]
|
|
30487
30492
|
};
|
|
30488
30493
|
});
|
|
30489
30494
|
server.registerTool("heartbeat", {
|
|
@@ -30497,7 +30502,7 @@ server.registerTool("heartbeat", {
|
|
|
30497
30502
|
const agent = resolveIdentity(fromParam);
|
|
30498
30503
|
heartbeat(agent, status);
|
|
30499
30504
|
return {
|
|
30500
|
-
content: [{ type: "text", text: JSON.stringify({ agent, status: status || "online", heartbeat: true }
|
|
30505
|
+
content: [{ type: "text", text: JSON.stringify({ agent, status: status || "online", heartbeat: true }) }]
|
|
30501
30506
|
};
|
|
30502
30507
|
});
|
|
30503
30508
|
server.registerTool("list_agents", {
|
|
@@ -30509,7 +30514,7 @@ server.registerTool("list_agents", {
|
|
|
30509
30514
|
const { online_only } = args;
|
|
30510
30515
|
const agents = listAgents({ online_only });
|
|
30511
30516
|
return {
|
|
30512
|
-
content: [{ type: "text", text: JSON.stringify(agents
|
|
30517
|
+
content: [{ type: "text", text: JSON.stringify(agents) }]
|
|
30513
30518
|
};
|
|
30514
30519
|
});
|
|
30515
30520
|
server.registerTool("get_blockers", {
|
|
@@ -30522,7 +30527,7 @@ server.registerTool("get_blockers", {
|
|
|
30522
30527
|
const agent = resolveIdentity(fromParam);
|
|
30523
30528
|
const blockers = getUnreadBlockers(agent);
|
|
30524
30529
|
return {
|
|
30525
|
-
content: [{ type: "text", text: JSON.stringify(blockers
|
|
30530
|
+
content: [{ type: "text", text: JSON.stringify(blockers) }]
|
|
30526
30531
|
};
|
|
30527
30532
|
});
|
|
30528
30533
|
server.registerTool("remove_agent", {
|
|
@@ -30543,7 +30548,7 @@ server.registerTool("remove_agent", {
|
|
|
30543
30548
|
};
|
|
30544
30549
|
}
|
|
30545
30550
|
return {
|
|
30546
|
-
content: [{ type: "text", text: JSON.stringify({ agent, removed: true }
|
|
30551
|
+
content: [{ type: "text", text: JSON.stringify({ agent, removed: true }) }]
|
|
30547
30552
|
};
|
|
30548
30553
|
});
|
|
30549
30554
|
server.registerTool("rename_agent", {
|
|
@@ -30571,7 +30576,7 @@ server.registerTool("rename_agent", {
|
|
|
30571
30576
|
};
|
|
30572
30577
|
}
|
|
30573
30578
|
return {
|
|
30574
|
-
content: [{ type: "text", text: JSON.stringify({ old_name: oldName, new_name: newName, renamed: true }
|
|
30579
|
+
content: [{ type: "text", text: JSON.stringify({ old_name: oldName, new_name: newName, renamed: true }) }]
|
|
30575
30580
|
};
|
|
30576
30581
|
} catch (e) {
|
|
30577
30582
|
return {
|
package/dist/index.js
CHANGED
|
@@ -2821,10 +2821,6 @@ function getProjectByName(name) {
|
|
|
2821
2821
|
}
|
|
2822
2822
|
function updateProject(id, updates) {
|
|
2823
2823
|
const db2 = getDb();
|
|
2824
|
-
const existing = db2.prepare("SELECT * FROM projects WHERE id = ?").get(id);
|
|
2825
|
-
if (!existing) {
|
|
2826
|
-
throw new Error(`Project not found: ${id}`);
|
|
2827
|
-
}
|
|
2828
2824
|
const sets = [];
|
|
2829
2825
|
const params = [];
|
|
2830
2826
|
if (updates.name !== undefined) {
|
|
@@ -2860,10 +2856,15 @@ function updateProject(id, updates) {
|
|
|
2860
2856
|
params.push(JSON.stringify(updates.settings));
|
|
2861
2857
|
}
|
|
2862
2858
|
if (sets.length === 0) {
|
|
2863
|
-
|
|
2859
|
+
const row2 = db2.prepare("SELECT * FROM projects WHERE id = ?").get(id);
|
|
2860
|
+
if (!row2)
|
|
2861
|
+
throw new Error(`Project not found: ${id}`);
|
|
2862
|
+
return parseProject(row2);
|
|
2864
2863
|
}
|
|
2865
2864
|
params.push(id);
|
|
2866
2865
|
const row = db2.prepare(`UPDATE projects SET ${sets.join(", ")} WHERE id = ? RETURNING *`).get(...params);
|
|
2866
|
+
if (!row)
|
|
2867
|
+
throw new Error(`Project not found: ${id}`);
|
|
2867
2868
|
return parseProject(row);
|
|
2868
2869
|
}
|
|
2869
2870
|
function deleteProject(id) {
|
|
@@ -3425,6 +3426,7 @@ function heartbeat(agent, status, metadata) {
|
|
|
3425
3426
|
const db2 = getDb();
|
|
3426
3427
|
const metadataJson = metadata ? JSON.stringify(metadata) : null;
|
|
3427
3428
|
const resolvedStatus = status || "online";
|
|
3429
|
+
const normalizedAgent = agent.trim().toLowerCase();
|
|
3428
3430
|
db2.prepare(`
|
|
3429
3431
|
INSERT INTO agent_presence (agent, status, last_seen_at, metadata)
|
|
3430
3432
|
VALUES (?, ?, strftime('%Y-%m-%dT%H:%M:%f', 'now'), ?)
|
|
@@ -3432,11 +3434,12 @@ function heartbeat(agent, status, metadata) {
|
|
|
3432
3434
|
status = excluded.status,
|
|
3433
3435
|
last_seen_at = excluded.last_seen_at,
|
|
3434
3436
|
metadata = excluded.metadata
|
|
3435
|
-
`).run(
|
|
3437
|
+
`).run(normalizedAgent, resolvedStatus, metadataJson);
|
|
3436
3438
|
}
|
|
3437
3439
|
function getPresence(agent) {
|
|
3438
3440
|
const db2 = getDb();
|
|
3439
|
-
const
|
|
3441
|
+
const normalizedAgent = agent.trim().toLowerCase();
|
|
3442
|
+
const row = db2.prepare("SELECT * FROM agent_presence WHERE LOWER(agent) = ?").get(normalizedAgent);
|
|
3440
3443
|
return row ? parsePresence(row) : null;
|
|
3441
3444
|
}
|
|
3442
3445
|
function listAgents(opts) {
|
|
@@ -3452,18 +3455,21 @@ function listAgents(opts) {
|
|
|
3452
3455
|
}
|
|
3453
3456
|
function removePresence(agent) {
|
|
3454
3457
|
const db2 = getDb();
|
|
3455
|
-
const
|
|
3458
|
+
const normalizedAgent = agent.trim().toLowerCase();
|
|
3459
|
+
const result = db2.prepare("DELETE FROM agent_presence WHERE LOWER(agent) = ?").run(normalizedAgent);
|
|
3456
3460
|
return result.changes > 0;
|
|
3457
3461
|
}
|
|
3458
3462
|
function renameAgent(oldName, newName) {
|
|
3459
3463
|
const db2 = getDb();
|
|
3460
|
-
const
|
|
3464
|
+
const normalizedOld = oldName.trim().toLowerCase();
|
|
3465
|
+
const normalizedNew = newName.trim().toLowerCase();
|
|
3466
|
+
const existing = db2.prepare("SELECT agent FROM agent_presence WHERE LOWER(agent) = ?").get(normalizedOld);
|
|
3461
3467
|
if (!existing)
|
|
3462
3468
|
return false;
|
|
3463
|
-
const conflict = db2.prepare("SELECT agent FROM agent_presence WHERE agent = ?").get(
|
|
3469
|
+
const conflict = db2.prepare("SELECT agent FROM agent_presence WHERE LOWER(agent) = ?").get(normalizedNew);
|
|
3464
3470
|
if (conflict)
|
|
3465
|
-
throw new Error(`Agent "${
|
|
3466
|
-
db2.prepare("UPDATE agent_presence SET agent = ? WHERE agent = ?").run(
|
|
3471
|
+
throw new Error(`Agent "${normalizedNew}" already exists`);
|
|
3472
|
+
db2.prepare("UPDATE agent_presence SET agent = ? WHERE LOWER(agent) = ?").run(normalizedNew, normalizedOld);
|
|
3467
3473
|
return true;
|
|
3468
3474
|
}
|
|
3469
3475
|
export {
|