@pingagent/sdk 0.1.3 → 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.
package/bin/pingagent.js CHANGED
@@ -1077,6 +1077,10 @@ history
1077
1077
  .description('List messages in a conversation (default: most recent conversation)')
1078
1078
  .argument('[conversation_id]', 'Conversation ID (omit to use most recent from local history)')
1079
1079
  .option('--limit <n>', 'Limit', '50')
1080
+ .option('--before-seq <n>', 'Page older messages: return the most recent <limit> messages with seq < n')
1081
+ .option('--after-seq <n>', 'Filter: seq > n (ascending order)')
1082
+ .option('--before-ts <ms>', 'Page older messages by timestamp (ms since epoch): ts_ms < ms')
1083
+ .option('--after-ts <ms>', 'Filter: ts_ms > ms (ascending order)')
1080
1084
  .option('--json', 'Output as JSON')
1081
1085
  .action((conversationId, opts) => {
1082
1086
  const store = openStore();
@@ -1094,7 +1098,25 @@ history
1094
1098
  console.log(`Using most recent conversation: ${cid}\n`);
1095
1099
  }
1096
1100
  }
1097
- const messages = mgr.list(cid, { limit: parseInt(opts.limit) });
1101
+ const limit = parseInt(opts.limit);
1102
+ const beforeSeq = opts.beforeSeq != null ? parseInt(opts.beforeSeq) : undefined;
1103
+ const afterSeq = opts.afterSeq != null ? parseInt(opts.afterSeq) : undefined;
1104
+ const beforeTs = opts.beforeTs != null ? parseInt(opts.beforeTs) : undefined;
1105
+ const afterTs = opts.afterTs != null ? parseInt(opts.afterTs) : undefined;
1106
+
1107
+ let messages;
1108
+ if (beforeSeq != null && !Number.isNaN(beforeSeq)) {
1109
+ messages = mgr.listBeforeSeq(cid, beforeSeq, Number.isFinite(limit) ? limit : 50);
1110
+ } else if (beforeTs != null && !Number.isNaN(beforeTs)) {
1111
+ messages = mgr.listBeforeTs(cid, beforeTs, Number.isFinite(limit) ? limit : 50);
1112
+ } else {
1113
+ messages = mgr.list(cid, {
1114
+ limit: Number.isFinite(limit) ? limit : 50,
1115
+ afterSeq: afterSeq != null && !Number.isNaN(afterSeq) ? afterSeq : undefined,
1116
+ beforeTsMs: beforeTs != null && !Number.isNaN(beforeTs) ? beforeTs : undefined,
1117
+ afterTsMs: afterTs != null && !Number.isNaN(afterTs) ? afterTs : undefined,
1118
+ });
1119
+ }
1098
1120
  if (opts.json) {
1099
1121
  console.log(JSON.stringify(messages, null, 2));
1100
1122
  } else if (messages.length === 0) {