@evex-dev/linejs-cli 0.1.2 → 0.1.4

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.
@@ -2,7 +2,7 @@ import { i as toErrorPayload, n as UsageError, r as errorMessage, t as CliError
2
2
  import { chmod, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
3
3
  import { basename, dirname, extname, isAbsolute, join, resolve, sep } from "node:path";
4
4
  import { inspect } from "node:util";
5
- import { Client, SquareMessage } from "@evex-dev/linejs";
5
+ import { Client, SquareMessage, TalkMessage } from "@evex-dev/linejs";
6
6
  import { BaseClient } from "@evex-dev/linejs/base";
7
7
  import { BaseStorage, MemoryStorage } from "@evex-dev/linejs/storage";
8
8
  import { encode, renderANSI, renderUnicode, renderUnicodeCompact } from "uqr";
@@ -731,14 +731,15 @@ function tokenExpiry(storage) {
731
731
  expiresAt: null,
732
732
  expired: null
733
733
  };
734
- const date = new Date(value);
734
+ const milliseconds = value < 0xe8d4a51000 ? value * 1e3 : value;
735
+ const date = new Date(milliseconds);
735
736
  if (Number.isNaN(date.getTime())) return {
736
737
  expiresAt: null,
737
738
  expired: null
738
739
  };
739
740
  return {
740
741
  expiresAt: date.toISOString(),
741
- expired: Date.now() >= value
742
+ expired: Date.now() >= milliseconds
742
743
  };
743
744
  }
744
745
  var ProfileStore = class ProfileStore {
@@ -1174,6 +1175,48 @@ function outOption(description = "Write the result to this file.") {
1174
1175
  function asRecord(value) {
1175
1176
  return value && typeof value === "object" ? value : {};
1176
1177
  }
1178
+ /**
1179
+ * User (1:1) mids start with "u". `talk.getChat` only serves group/room
1180
+ * chats, so user mids must go through the message-box APIs instead.
1181
+ */
1182
+ function isUserMid(mid) {
1183
+ return mid.startsWith("u");
1184
+ }
1185
+ function userChatSummary(mid) {
1186
+ return {
1187
+ mid,
1188
+ type: "USER"
1189
+ };
1190
+ }
1191
+ /**
1192
+ * Fetch recent talk messages for a 1:1 (user) mid via the message-box APIs.
1193
+ * Group/room mids keep using `Chat.fetchMessages`; this is the user-mid
1194
+ * counterpart that `client.getChat` cannot serve.
1195
+ */
1196
+ async function fetchUserTalkMessages(client, userMid, limit) {
1197
+ const box = (await client.base.talk.getMessageBoxes({ messageBoxListRequest: {} })).messageBoxes.find((entry) => entry.id === userMid);
1198
+ if (!box) throw new CliError("NOT_FOUND", `Message box ${userMid} was not found`, { details: {
1199
+ chatMid: userMid,
1200
+ hint: "Open the 1:1 chat once in an official client, then retry."
1201
+ } });
1202
+ const raws = await client.base.talk.getPreviousMessagesV2WithRequest({ request: {
1203
+ messageBoxId: box.id,
1204
+ endMessageId: {
1205
+ messageId: box.lastDeliveredMessageId.messageId,
1206
+ deliveredTime: box.lastDeliveredMessageId.deliveredTime
1207
+ },
1208
+ messagesCount: limit
1209
+ } });
1210
+ return await Promise.all(raws.map((raw) => TalkMessage.fromRawTalk(raw, client)));
1211
+ }
1212
+ /**
1213
+ * Fetch recent talk messages for any talk mid. User (1:1) mids go through
1214
+ * the message-box path; group/room mids keep the existing `getChat` path.
1215
+ */
1216
+ async function fetchTalkMessages(client, chatMid, limit) {
1217
+ if (!isUserMid(chatMid)) return (await client.getChat(chatMid)).fetchMessages(limit);
1218
+ return fetchUserTalkMessages(client, chatMid, limit);
1219
+ }
1177
1220
  function chatSummary(chat, includeRaw = false) {
1178
1221
  const raw = asRecord(chat.raw);
1179
1222
  return {
@@ -2509,7 +2552,7 @@ const chatsCommands = [
2509
2552
  category: "Chats",
2510
2553
  args: [{
2511
2554
  name: "chatMid",
2512
- description: "Chat MID.",
2555
+ description: "Chat MID (c..., r..., or u... for 1:1).",
2513
2556
  required: true
2514
2557
  }],
2515
2558
  options: [limitOption(20)],
@@ -2520,6 +2563,13 @@ const chatsCommands = [
2520
2563
  const limit = context.getNumber("limit") ?? 20;
2521
2564
  if (limit <= 0) throw new UsageError("--limit must be positive");
2522
2565
  return await withClient(context, async ({ client }) => {
2566
+ if (isUserMid(chatMid)) {
2567
+ const messages = await fetchUserTalkMessages(client, chatMid, limit);
2568
+ return {
2569
+ chat: userChatSummary(chatMid),
2570
+ messages: messages.map((message) => talkMessageSummary(message, context.json))
2571
+ };
2572
+ }
2523
2573
  const chat = await client.getChat(chatMid);
2524
2574
  const messages = await chat.fetchMessages(limit);
2525
2575
  return {
@@ -3762,7 +3812,7 @@ function bigIntId(value) {
3762
3812
  return BigInt(value);
3763
3813
  }
3764
3814
  async function resolveTalkMessage(client, chatMid, messageId, limit = 100) {
3765
- const message = (await (await client.getChat(chatMid)).fetchMessages(limit)).find((entry) => entry.raw.id === messageId);
3815
+ const message = (await fetchTalkMessages(client, chatMid, limit)).find((entry) => entry.raw.id === messageId);
3766
3816
  if (!message) throw new CliError("NOT_FOUND", `Message ${messageId} was not found in the last ${limit} messages`, { details: {
3767
3817
  chatMid,
3768
3818
  messageId,
@@ -3957,7 +4007,7 @@ const showCommand = {
3957
4007
  category: "Messages",
3958
4008
  args: [{
3959
4009
  name: "chatMid",
3960
- description: "Chat MID.",
4010
+ description: "Chat MID (c..., r..., or u... for 1:1).",
3961
4011
  required: true
3962
4012
  }, {
3963
4013
  name: "messageId",
@@ -4012,7 +4062,7 @@ const pinCommand = {
4012
4062
  category: "Messages",
4013
4063
  args: [{
4014
4064
  name: "chatMid",
4015
- description: "Chat MID.",
4065
+ description: "Chat MID (c..., r..., or u... for 1:1).",
4016
4066
  required: true
4017
4067
  }, {
4018
4068
  name: "messageId",
@@ -4080,7 +4130,7 @@ const messagesCommands = [
4080
4130
  category: "Messages",
4081
4131
  args: [{
4082
4132
  name: "chatMid",
4083
- description: "Chat MID.",
4133
+ description: "Chat MID (c..., r..., or u... for 1:1).",
4084
4134
  required: true
4085
4135
  }, {
4086
4136
  name: "messageId",
@@ -4466,7 +4516,7 @@ const mcpCommands = [{
4466
4516
  mcp: false,
4467
4517
  silent: true,
4468
4518
  async run(context) {
4469
- const { runMcpServer } = await import("./server-BmHHfR6J.mjs");
4519
+ const { runMcpServer } = await import("./server-DGKFX_3-.mjs");
4470
4520
  return { exitCode: await runMcpServer({
4471
4521
  input: process.stdin,
4472
4522
  output: process.stdout,
@@ -6381,7 +6431,7 @@ function resolveCommandTokens(tokens) {
6381
6431
  * Single-sourced from package.json so a release bump (the publish workflow
6382
6432
  * rewrites the manifest) never needs a second edit here.
6383
6433
  */
6384
- const VERSION = "0.1.2";
6434
+ const VERSION = "0.1.4";
6385
6435
  // src/help.ts
6386
6436
  function describeOption(spec) {
6387
6437
  const value = spec.type === "boolean" ? "" : ` <${spec.valueName ?? (spec.type === "array" ? "value" : "value")}>`;
@@ -6728,4 +6778,4 @@ async function runCli(argv, options = {}) {
6728
6778
  }
6729
6779
  export { commandMetadata as a, resolveCommandTokens as i, VERSION as n, isMcpExecutable as o, allCommands as r, splitLeadingGlobalOptions as s, runCli as t };
6730
6780
 
6731
- //# sourceMappingURL=cli-BcD4Tq1b.mjs.map
6781
+ //# sourceMappingURL=cli-B-byNdKi.mjs.map