@decentnetwork/lan 0.1.84 → 0.1.86

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.
Binary file
Binary file
Binary file
Binary file
@@ -232,6 +232,25 @@ export declare function cmdProxyUse(args: {
232
232
  * `friends.autoAccept: false` (otherwise requests are accepted instantly and
233
233
  * never queue).
234
234
  */
235
+ /**
236
+ * Send a text message (native Carrier chat, packet 64) to a friend by userid.
237
+ * Routed through the running daemon's Carrier identity over IPC — the daemon
238
+ * owns the keypair, so the CLI never opens a competing Peer.
239
+ */
240
+ export declare function cmdChatSend(args: {
241
+ to: string;
242
+ text: string;
243
+ configDir?: string;
244
+ }): Promise<void>;
245
+ /**
246
+ * Print chat history (sent + received). Incoming messages are logged by the
247
+ * daemon as they arrive, so this is also how you READ messages from friends.
248
+ * Optionally filter to one peer by userid prefix.
249
+ */
250
+ export declare function cmdChatHistory(args: {
251
+ peer?: string;
252
+ configDir?: string;
253
+ }): Promise<void>;
235
254
  export declare function cmdUi(args: {
236
255
  port?: number;
237
256
  listen?: string;
@@ -1049,6 +1049,44 @@ export async function cmdProxyUse(args) {
1049
1049
  * `friends.autoAccept: false` (otherwise requests are accepted instantly and
1050
1050
  * never queue).
1051
1051
  */
1052
+ /**
1053
+ * Send a text message (native Carrier chat, packet 64) to a friend by userid.
1054
+ * Routed through the running daemon's Carrier identity over IPC — the daemon
1055
+ * owns the keypair, so the CLI never opens a competing Peer.
1056
+ */
1057
+ export async function cmdChatSend(args) {
1058
+ const dir = args.configDir || ConfigLoader.defaultConfigDir();
1059
+ const config = await ConfigLoader.load(resolve(dir, "config.yaml"));
1060
+ const res = await ipcCall(config, { op: "chat-send", userid: args.to, text: args.text });
1061
+ if (!res.ok)
1062
+ throw new Error(`Daemon refused: ${res.error}`);
1063
+ console.log(`-> ${args.to.slice(0, 16)}… ${args.text}`);
1064
+ }
1065
+ /**
1066
+ * Print chat history (sent + received). Incoming messages are logged by the
1067
+ * daemon as they arrive, so this is also how you READ messages from friends.
1068
+ * Optionally filter to one peer by userid prefix.
1069
+ */
1070
+ export async function cmdChatHistory(args) {
1071
+ const dir = args.configDir || ConfigLoader.defaultConfigDir();
1072
+ const config = await ConfigLoader.load(resolve(dir, "config.yaml"));
1073
+ const res = await ipcCall(config, { op: "chat-history" });
1074
+ if (!res.ok)
1075
+ throw new Error(`Daemon refused: ${res.error}`);
1076
+ const chats = (res.data?.chats ?? {});
1077
+ const userids = Object.keys(chats).filter((u) => !args.peer || u.startsWith(args.peer));
1078
+ if (userids.length === 0) {
1079
+ console.log(args.peer ? `No chat history with ${args.peer}.` : "No chat history yet.");
1080
+ return;
1081
+ }
1082
+ for (const uid of userids) {
1083
+ console.log(`\n=== ${uid} ===`);
1084
+ for (const m of chats[uid]) {
1085
+ const t = new Date(m.ts).toLocaleString();
1086
+ console.log(` [${t}] ${m.dir === "in" ? "<-" : "->"} ${m.text}`);
1087
+ }
1088
+ }
1089
+ }
1052
1090
  export async function cmdUi(args) {
1053
1091
  const dir = args.configDir || ConfigLoader.defaultConfigDir();
1054
1092
  const config = await ConfigLoader.load(resolve(dir, "config.yaml"));
package/dist/cli/index.js CHANGED
@@ -10,7 +10,7 @@ import { hideBin } from "yargs/helpers";
10
10
  // Belt-and-braces — also raise it here in case the CLI is run directly
11
11
  // (e.g. `node dist/cli/index.js` rather than via dist/index.js).
12
12
  EventEmitter.defaultMaxListeners = 100;
13
- import { cmdInit, cmdIdentityShow, cmdPeersList, cmdIpamAssign, cmdGrant, cmdRevoke, cmdResolve, cmdStatus, cmdUp, cmdAuditLog, cmdFriendRequest, cmdFriendAccept, cmdFriendsList, cmdFriendsPending, cmdFriendsAccept, cmdFriendsReject, cmdProxyEnable, cmdProxyDisable, cmdProxyStatus, cmdProxyAllowHost, cmdProxyRevokeHost, cmdProxyListHosts, cmdProxyUse, cmdProxyRouter, cmdDoraEnable, cmdDoraDisable, cmdDoraStatus, cmdDoraAutofriend, cmdDiag, cmdDoctor, cmdDnsInstall, cmdDnsHosts, cmdServiceInstall, cmdRestart, cmdServiceStatus, cmdServiceRestart, cmdUi, } from "./commands.js";
13
+ import { cmdInit, cmdIdentityShow, cmdPeersList, cmdIpamAssign, cmdGrant, cmdRevoke, cmdResolve, cmdStatus, cmdUp, cmdAuditLog, cmdFriendRequest, cmdFriendAccept, cmdFriendsList, cmdFriendsPending, cmdFriendsAccept, cmdFriendsReject, cmdProxyEnable, cmdProxyDisable, cmdProxyStatus, cmdProxyAllowHost, cmdProxyRevokeHost, cmdProxyListHosts, cmdProxyUse, cmdProxyRouter, cmdDoraEnable, cmdDoraDisable, cmdDoraStatus, cmdDoraAutofriend, cmdDiag, cmdDoctor, cmdDnsInstall, cmdDnsHosts, cmdServiceInstall, cmdRestart, cmdServiceStatus, cmdServiceRestart, cmdUi, cmdChatSend, cmdChatHistory, } from "./commands.js";
14
14
  async function main() {
15
15
  await yargs(hideBin(process.argv))
16
16
  .scriptName("agentnet")
@@ -85,6 +85,21 @@ async function main() {
85
85
  })
86
86
  .command("diag", "Query the running daemon over IPC for a JSON snapshot of its runtime state (stats, friends, IPAM)", (y) => y.option("config-dir", { type: "string" }), async (argv) => {
87
87
  await cmdDiag({ configDir: argv["config-dir"] });
88
+ })
89
+ .command("chat", "Send / read text messages with a friend (native Carrier chat)", (y) => y
90
+ .command("send <to> <text>", "Send a text message to a friend by userid", (yy) => yy
91
+ .positional("to", { type: "string", demandOption: true, describe: "Friend userid" })
92
+ .positional("text", { type: "string", demandOption: true, describe: "Message text" })
93
+ .option("config-dir", { type: "string" }), async (argv) => {
94
+ await cmdChatSend({ to: argv.to, text: argv.text, configDir: argv["config-dir"] });
95
+ })
96
+ .command("history", "Show chat history (sent + received); incoming messages are logged as they arrive", (yy) => yy
97
+ .option("peer", { type: "string", describe: "Filter to one friend by userid prefix" })
98
+ .option("config-dir", { type: "string" }), async (argv) => {
99
+ await cmdChatHistory({ peer: argv.peer, configDir: argv["config-dir"] });
100
+ })
101
+ .demandCommand(1, "Specify a chat subcommand: send | history"), () => {
102
+ // parent handler — never invoked because demandCommand above
88
103
  })
89
104
  .command("doctor", "Self-check: diagnoses config/daemon/dora/peer problems and prints the fix for each", (y) => y.option("config-dir", { type: "string" }), async (argv) => {
90
105
  await cmdDoctor({ configDir: argv["config-dir"] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/lan",
3
- "version": "0.1.84",
3
+ "version": "0.1.86",
4
4
  "description": "Private virtual LAN for self-hosted services and AI agents, built on Elastos Carrier. NAT-traversal, name service, ACL, all over a peer-to-peer mesh — no public IP required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "dependencies": {
79
79
  "@decentnetwork/dora": "^0.1.6",
80
- "@decentnetwork/peer": "^0.1.38",
80
+ "@decentnetwork/peer": "^0.1.39",
81
81
  "js-yaml": "^4.1.0",
82
82
  "yargs": "^17.7.2"
83
83
  },