@hasna/conversations 0.1.4 → 0.1.5
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 +121 -6
- package/bin/mcp.js +72 -1
- package/dist/lib/presence.d.ts +1 -0
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -3055,6 +3055,22 @@ function listAgents(opts) {
|
|
|
3055
3055
|
const rows = db2.prepare(query).all(...params);
|
|
3056
3056
|
return rows.map(parsePresence);
|
|
3057
3057
|
}
|
|
3058
|
+
function removePresence(agent) {
|
|
3059
|
+
const db2 = getDb();
|
|
3060
|
+
const result = db2.prepare("DELETE FROM agent_presence WHERE agent = ?").run(agent);
|
|
3061
|
+
return result.changes > 0;
|
|
3062
|
+
}
|
|
3063
|
+
function renameAgent(oldName, newName) {
|
|
3064
|
+
const db2 = getDb();
|
|
3065
|
+
const existing = db2.prepare("SELECT agent FROM agent_presence WHERE agent = ?").get(oldName);
|
|
3066
|
+
if (!existing)
|
|
3067
|
+
return false;
|
|
3068
|
+
const conflict = db2.prepare("SELECT agent FROM agent_presence WHERE agent = ?").get(newName);
|
|
3069
|
+
if (conflict)
|
|
3070
|
+
throw new Error(`Agent "${newName}" already exists`);
|
|
3071
|
+
db2.prepare("UPDATE agent_presence SET agent = ? WHERE agent = ?").run(newName, oldName);
|
|
3072
|
+
return true;
|
|
3073
|
+
}
|
|
3058
3074
|
var ONLINE_THRESHOLD_SECONDS = 60;
|
|
3059
3075
|
var init_presence = __esm(() => {
|
|
3060
3076
|
init_db();
|
|
@@ -3064,7 +3080,7 @@ var init_presence = __esm(() => {
|
|
|
3064
3080
|
var require_package = __commonJS((exports, module) => {
|
|
3065
3081
|
module.exports = {
|
|
3066
3082
|
name: "@hasna/conversations",
|
|
3067
|
-
version: "0.1.
|
|
3083
|
+
version: "0.1.5",
|
|
3068
3084
|
description: "Real-time CLI messaging for AI agents",
|
|
3069
3085
|
type: "module",
|
|
3070
3086
|
bin: {
|
|
@@ -32708,6 +32724,61 @@ var init_mcp2 = __esm(() => {
|
|
|
32708
32724
|
content: [{ type: "text", text: JSON.stringify(agents, null, 2) }]
|
|
32709
32725
|
};
|
|
32710
32726
|
});
|
|
32727
|
+
server.registerTool("remove_agent", {
|
|
32728
|
+
title: "Remove Agent",
|
|
32729
|
+
description: "Remove an agent from the presence list. Only the agent itself should remove its own presence.",
|
|
32730
|
+
inputSchema: {
|
|
32731
|
+
from: exports_external.string().optional().describe("Your agent ID. Falls back to CONVERSATIONS_AGENT_ID env var."),
|
|
32732
|
+
agent: exports_external.string().optional().describe("Agent to remove (defaults to yourself)")
|
|
32733
|
+
}
|
|
32734
|
+
}, async ({ from: fromParam, agent: targetAgent }) => {
|
|
32735
|
+
const self = resolveIdentity(fromParam);
|
|
32736
|
+
const agent = targetAgent?.trim() || self;
|
|
32737
|
+
const removed = removePresence(agent);
|
|
32738
|
+
if (!removed) {
|
|
32739
|
+
return {
|
|
32740
|
+
content: [{ type: "text", text: `Agent "${agent}" not found` }],
|
|
32741
|
+
isError: true
|
|
32742
|
+
};
|
|
32743
|
+
}
|
|
32744
|
+
return {
|
|
32745
|
+
content: [{ type: "text", text: JSON.stringify({ agent, removed: true }, null, 2) }]
|
|
32746
|
+
};
|
|
32747
|
+
});
|
|
32748
|
+
server.registerTool("rename_agent", {
|
|
32749
|
+
title: "Rename Agent",
|
|
32750
|
+
description: "Rename an agent in the presence list. By default renames yourself.",
|
|
32751
|
+
inputSchema: {
|
|
32752
|
+
from: exports_external.string().optional().describe("Your current agent ID. Falls back to CONVERSATIONS_AGENT_ID env var."),
|
|
32753
|
+
new_name: exports_external.string().describe("The new name for the agent")
|
|
32754
|
+
}
|
|
32755
|
+
}, async ({ from: fromParam, new_name }) => {
|
|
32756
|
+
const oldName = resolveIdentity(fromParam);
|
|
32757
|
+
const newName = new_name.trim();
|
|
32758
|
+
if (!newName) {
|
|
32759
|
+
return {
|
|
32760
|
+
content: [{ type: "text", text: "New name cannot be empty" }],
|
|
32761
|
+
isError: true
|
|
32762
|
+
};
|
|
32763
|
+
}
|
|
32764
|
+
try {
|
|
32765
|
+
const renamed = renameAgent(oldName, newName);
|
|
32766
|
+
if (!renamed) {
|
|
32767
|
+
return {
|
|
32768
|
+
content: [{ type: "text", text: `Agent "${oldName}" not found in presence list` }],
|
|
32769
|
+
isError: true
|
|
32770
|
+
};
|
|
32771
|
+
}
|
|
32772
|
+
return {
|
|
32773
|
+
content: [{ type: "text", text: JSON.stringify({ old_name: oldName, new_name: newName, renamed: true }, null, 2) }]
|
|
32774
|
+
};
|
|
32775
|
+
} catch (e) {
|
|
32776
|
+
return {
|
|
32777
|
+
content: [{ type: "text", text: e.message }],
|
|
32778
|
+
isError: true
|
|
32779
|
+
};
|
|
32780
|
+
}
|
|
32781
|
+
});
|
|
32711
32782
|
isDirectRun = import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("mcp.js") || process.argv[1]?.endsWith("mcp.ts");
|
|
32712
32783
|
if (isDirectRun) {
|
|
32713
32784
|
startMcpServer().catch((error48) => {
|
|
@@ -34979,17 +35050,18 @@ program2.command("unpin").description("Unpin a message").argument("<id>", "Messa
|
|
|
34979
35050
|
}
|
|
34980
35051
|
closeDb();
|
|
34981
35052
|
});
|
|
34982
|
-
program2.command("agents").description("
|
|
35053
|
+
var agents = program2.command("agents").description("Manage agents");
|
|
35054
|
+
agents.command("list").description("List all agents with their presence status").option("--online", "Only show online agents").option("--json", "Output as JSON").action((opts) => {
|
|
34983
35055
|
const agent = resolveIdentity();
|
|
34984
35056
|
heartbeat(agent);
|
|
34985
|
-
const
|
|
35057
|
+
const agentsList = listAgents({ online_only: opts.online });
|
|
34986
35058
|
if (opts.json) {
|
|
34987
|
-
console.log(JSON.stringify(
|
|
35059
|
+
console.log(JSON.stringify(agentsList, null, 2));
|
|
34988
35060
|
} else {
|
|
34989
|
-
if (
|
|
35061
|
+
if (agentsList.length === 0) {
|
|
34990
35062
|
console.log(chalk2.dim("No agents found."));
|
|
34991
35063
|
} else {
|
|
34992
|
-
for (const a of
|
|
35064
|
+
for (const a of agentsList) {
|
|
34993
35065
|
const status = a.online ? chalk2.green("online") : chalk2.dim("offline");
|
|
34994
35066
|
const lastSeen = chalk2.dim(a.last_seen_at.slice(0, 19));
|
|
34995
35067
|
const agentName = a.agent === agent ? chalk2.cyan(`${a.agent} (you)`) : chalk2.cyan(a.agent);
|
|
@@ -34999,6 +35071,49 @@ program2.command("agents").description("List all agents with their presence stat
|
|
|
34999
35071
|
}
|
|
35000
35072
|
closeDb();
|
|
35001
35073
|
});
|
|
35074
|
+
agents.command("remove").description("Remove an agent from the presence list").argument("<name>", "Agent name to remove").option("--json", "Output as JSON").action((name, opts) => {
|
|
35075
|
+
const agentName = typeof name === "string" ? name.trim() : "";
|
|
35076
|
+
if (!agentName) {
|
|
35077
|
+
console.error(chalk2.red("Agent name cannot be empty."));
|
|
35078
|
+
process.exit(1);
|
|
35079
|
+
}
|
|
35080
|
+
const removed = removePresence(agentName);
|
|
35081
|
+
if (opts.json) {
|
|
35082
|
+
console.log(JSON.stringify({ agent: agentName, removed }));
|
|
35083
|
+
} else {
|
|
35084
|
+
if (removed) {
|
|
35085
|
+
console.log(chalk2.green(`Agent "${agentName}" removed.`));
|
|
35086
|
+
} else {
|
|
35087
|
+
console.error(chalk2.red(`Agent "${agentName}" not found.`));
|
|
35088
|
+
process.exit(1);
|
|
35089
|
+
}
|
|
35090
|
+
}
|
|
35091
|
+
closeDb();
|
|
35092
|
+
});
|
|
35093
|
+
agents.command("rename").description("Rename an agent in the presence list").argument("<old-name>", "Current agent name").argument("<new-name>", "New agent name").option("--json", "Output as JSON").action((oldName, newName, opts) => {
|
|
35094
|
+
const old = typeof oldName === "string" ? oldName.trim() : "";
|
|
35095
|
+
const renamed = typeof newName === "string" ? newName.trim() : "";
|
|
35096
|
+
if (!old || !renamed) {
|
|
35097
|
+
console.error(chalk2.red("Both old and new names are required."));
|
|
35098
|
+
process.exit(1);
|
|
35099
|
+
}
|
|
35100
|
+
try {
|
|
35101
|
+
const ok = renameAgent(old, renamed);
|
|
35102
|
+
if (!ok) {
|
|
35103
|
+
console.error(chalk2.red(`Agent "${old}" not found.`));
|
|
35104
|
+
process.exit(1);
|
|
35105
|
+
}
|
|
35106
|
+
if (opts.json) {
|
|
35107
|
+
console.log(JSON.stringify({ old_name: old, new_name: renamed, renamed: true }));
|
|
35108
|
+
} else {
|
|
35109
|
+
console.log(chalk2.green(`Agent "${old}" renamed to "${renamed}".`));
|
|
35110
|
+
}
|
|
35111
|
+
} catch (e) {
|
|
35112
|
+
console.error(chalk2.red(e.message));
|
|
35113
|
+
process.exit(1);
|
|
35114
|
+
}
|
|
35115
|
+
closeDb();
|
|
35116
|
+
});
|
|
35002
35117
|
program2.command("mcp").description("Start MCP server").action(async () => {
|
|
35003
35118
|
const { startMcpServer: startMcpServer2 } = await Promise.resolve().then(() => (init_mcp2(), exports_mcp));
|
|
35004
35119
|
await startMcpServer2();
|
package/bin/mcp.js
CHANGED
|
@@ -29465,10 +29465,26 @@ function listAgents(opts) {
|
|
|
29465
29465
|
const rows = db2.prepare(query).all(...params);
|
|
29466
29466
|
return rows.map(parsePresence);
|
|
29467
29467
|
}
|
|
29468
|
+
function removePresence(agent) {
|
|
29469
|
+
const db2 = getDb();
|
|
29470
|
+
const result = db2.prepare("DELETE FROM agent_presence WHERE agent = ?").run(agent);
|
|
29471
|
+
return result.changes > 0;
|
|
29472
|
+
}
|
|
29473
|
+
function renameAgent(oldName, newName) {
|
|
29474
|
+
const db2 = getDb();
|
|
29475
|
+
const existing = db2.prepare("SELECT agent FROM agent_presence WHERE agent = ?").get(oldName);
|
|
29476
|
+
if (!existing)
|
|
29477
|
+
return false;
|
|
29478
|
+
const conflict = db2.prepare("SELECT agent FROM agent_presence WHERE agent = ?").get(newName);
|
|
29479
|
+
if (conflict)
|
|
29480
|
+
throw new Error(`Agent "${newName}" already exists`);
|
|
29481
|
+
db2.prepare("UPDATE agent_presence SET agent = ? WHERE agent = ?").run(newName, oldName);
|
|
29482
|
+
return true;
|
|
29483
|
+
}
|
|
29468
29484
|
// package.json
|
|
29469
29485
|
var package_default = {
|
|
29470
29486
|
name: "@hasna/conversations",
|
|
29471
|
-
version: "0.1.
|
|
29487
|
+
version: "0.1.5",
|
|
29472
29488
|
description: "Real-time CLI messaging for AI agents",
|
|
29473
29489
|
type: "module",
|
|
29474
29490
|
bin: {
|
|
@@ -30224,6 +30240,61 @@ server.registerTool("list_agents", {
|
|
|
30224
30240
|
content: [{ type: "text", text: JSON.stringify(agents, null, 2) }]
|
|
30225
30241
|
};
|
|
30226
30242
|
});
|
|
30243
|
+
server.registerTool("remove_agent", {
|
|
30244
|
+
title: "Remove Agent",
|
|
30245
|
+
description: "Remove an agent from the presence list. Only the agent itself should remove its own presence.",
|
|
30246
|
+
inputSchema: {
|
|
30247
|
+
from: exports_external.string().optional().describe("Your agent ID. Falls back to CONVERSATIONS_AGENT_ID env var."),
|
|
30248
|
+
agent: exports_external.string().optional().describe("Agent to remove (defaults to yourself)")
|
|
30249
|
+
}
|
|
30250
|
+
}, async ({ from: fromParam, agent: targetAgent }) => {
|
|
30251
|
+
const self = resolveIdentity(fromParam);
|
|
30252
|
+
const agent = targetAgent?.trim() || self;
|
|
30253
|
+
const removed = removePresence(agent);
|
|
30254
|
+
if (!removed) {
|
|
30255
|
+
return {
|
|
30256
|
+
content: [{ type: "text", text: `Agent "${agent}" not found` }],
|
|
30257
|
+
isError: true
|
|
30258
|
+
};
|
|
30259
|
+
}
|
|
30260
|
+
return {
|
|
30261
|
+
content: [{ type: "text", text: JSON.stringify({ agent, removed: true }, null, 2) }]
|
|
30262
|
+
};
|
|
30263
|
+
});
|
|
30264
|
+
server.registerTool("rename_agent", {
|
|
30265
|
+
title: "Rename Agent",
|
|
30266
|
+
description: "Rename an agent in the presence list. By default renames yourself.",
|
|
30267
|
+
inputSchema: {
|
|
30268
|
+
from: exports_external.string().optional().describe("Your current agent ID. Falls back to CONVERSATIONS_AGENT_ID env var."),
|
|
30269
|
+
new_name: exports_external.string().describe("The new name for the agent")
|
|
30270
|
+
}
|
|
30271
|
+
}, async ({ from: fromParam, new_name }) => {
|
|
30272
|
+
const oldName = resolveIdentity(fromParam);
|
|
30273
|
+
const newName = new_name.trim();
|
|
30274
|
+
if (!newName) {
|
|
30275
|
+
return {
|
|
30276
|
+
content: [{ type: "text", text: "New name cannot be empty" }],
|
|
30277
|
+
isError: true
|
|
30278
|
+
};
|
|
30279
|
+
}
|
|
30280
|
+
try {
|
|
30281
|
+
const renamed = renameAgent(oldName, newName);
|
|
30282
|
+
if (!renamed) {
|
|
30283
|
+
return {
|
|
30284
|
+
content: [{ type: "text", text: `Agent "${oldName}" not found in presence list` }],
|
|
30285
|
+
isError: true
|
|
30286
|
+
};
|
|
30287
|
+
}
|
|
30288
|
+
return {
|
|
30289
|
+
content: [{ type: "text", text: JSON.stringify({ old_name: oldName, new_name: newName, renamed: true }, null, 2) }]
|
|
30290
|
+
};
|
|
30291
|
+
} catch (e) {
|
|
30292
|
+
return {
|
|
30293
|
+
content: [{ type: "text", text: e.message }],
|
|
30294
|
+
isError: true
|
|
30295
|
+
};
|
|
30296
|
+
}
|
|
30297
|
+
});
|
|
30227
30298
|
async function startMcpServer() {
|
|
30228
30299
|
const transport = new StdioServerTransport;
|
|
30229
30300
|
await server.connect(transport);
|
package/dist/lib/presence.d.ts
CHANGED