🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
:bug: fix: fix cli message/topic list page indexing (#13731)
Rylan Cai5613935b7359
diff --git a/apps/cli/src/commands/message.test.ts b/apps/cli/src/commands/message.test.tsindex dcffe03b939..2013e171a6c 100644--- a/apps/cli/src/commands/message.test.ts+++ b/apps/cli/src/commands/message.test.ts@@ -79,6 +79,57 @@ describe('message command', () => {);expect(mockTrpcClient.message.listAll.query).not.toHaveBeenCalled();});++ it('should keep first page on the backend default offset for filtered queries', async () => {+ mockTrpcClient.message.getMessages.query.mockResolvedValue([]);++ const program = createProgram();+ await program.parseAsync([+ 'node',+ 'test',+ 'message',+ 'list',+ '--topic-id',+ 't1',+ '-L',+ '200',+ ]);++ expect(mockTrpcClient.message.getMessages.query).toHaveBeenCalledWith(+ expect.objectContaining({ pageSize: 200, topicId: 't1' }),+ );+ });++ it('should convert page 2 to current 1 for filtered queries', async () => {+ mockTrpcClient.message.getMessages.query.mockResolvedValue([]);++ const program = createProgram();+ await program.parseAsync([+ 'node',+ 'test',+ 'message',+ 'list',+ '--topic-id',+ 't1',+ '--page',+ '2',+ ]);++ expect(mockTrpcClient.message.getMessages.query).toHaveBeenCalledWith(+ expect.objectContaining({ current: 1, topicId: 't1' }),+ );+ });++ it('should support the short page flag for filtered queries', async () => {+ mockTrpcClient.message.getMessages.query.mockResolvedValue([]);++ const program = createProgram();+ await program.parseAsync(['node', 'test', 'message', 'list', '--topic-id', 't1', '-P', '2']);++ expect(mockTrpcClient.message.getMessages.query).toHaveBeenCalledWith(+ expect.objectContaining({ current: 1, topicId: 't1' }),+ );+ });});describe('search', () => {diff --git a/apps/cli/src/commands/message.ts b/apps/cli/src/commands/message.tsindex 062b935f90c..01871adffd4 100644--- a/apps/cli/src/commands/message.ts+++ b/apps/cli/src/commands/message.ts@@ -16,7 +16,7 @@ export function registerMessageCommand(program: Command) {.option('--topic-id <id>', 'Filter by topic ID').option('--agent-id <id>', 'Filter by agent ID').option('-L, --limit <n>', 'Page size', '30')- .option('--page <n>', 'Page number', '1')+ .option('-P, --page <n>', 'Page number', '1').option('--user', 'Only show user messages').option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)').action(@@ -32,7 +32,9 @@ export function registerMessageCommand(program: Command) {const hasFilter = options.topicId || options.agentId;const pageSize = options.limit ? Number.parseInt(options.limit, 10) : undefined;- const current = options.page ? Number.parseInt(options.page, 10) : undefined;+ const current = options.page+ ? Math.max(Number.parseInt(options.page, 10) - 1, 0)+ : undefined;let items: any[];diff --git a/apps/cli/src/commands/topic.test.ts b/apps/cli/src/commands/topic.test.tsindex e3f4f707477..fdff6d8127c 100644--- a/apps/cli/src/commands/topic.test.ts+++ b/apps/cli/src/commands/topic.test.ts@@ -77,6 +77,48 @@ describe('topic command', () => {expect.objectContaining({ agentId: 'a1' }),);});++ it('should keep first page on the backend default offset', async () => {+ mockTrpcClient.topic.getTopics.query.mockResolvedValue([]);++ const program = createProgram();+ await program.parseAsync(['node', 'test', 'topic', 'list', '--agent-id', 'a1', '-L', '200']);++ expect(mockTrpcClient.topic.getTopics.query).toHaveBeenCalledWith(+ expect.objectContaining({ agentId: 'a1', pageSize: 200 }),+ );+ });++ it('should convert page 2 to current 1', async () => {+ mockTrpcClient.topic.getTopics.query.mockResolvedValue([]);++ const program = createProgram();+ await program.parseAsync([+ 'node',+ 'test',+ 'topic',+ 'list',+ '--agent-id',+ 'a1',+ '--page',+ '2',+ ]);++ expect(mockTrpcClient.topic.getTopics.query).toHaveBeenCalledWith(+ expect.objectContaining({ agentId: 'a1', current: 1 }),+ );+ });++ it('should support the short page flag', async () => {+ mockTrpcClient.topic.getTopics.query.mockResolvedValue([]);++ const program = createProgram();+ await program.parseAsync(['node', 'test', 'topic', 'list', '--agent-id', 'a1', '-P', '2']);++ expect(mockTrpcClient.topic.getTopics.query).toHaveBeenCalledWith(+ expect.objectContaining({ agentId: 'a1', current: 1 }),+ );+ });});describe('search', () => {diff --git a/apps/cli/src/commands/topic.ts b/apps/cli/src/commands/topic.tsindex f097d856407..7e62ffa2151 100644--- a/apps/cli/src/commands/topic.ts+++ b/apps/cli/src/commands/topic.ts@@ -17,7 +17,7 @@ export function registerTopicCommand(program: Command) {.description('List topics').option('--agent-id <id>', 'Filter by agent ID').option('-L, --limit <n>', 'Page size', '30')- .option('--page <n>', 'Page number', '1')+ .option('-P, --page <n>', 'Page number', '1').option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)').action(async (options: {@@ -31,7 +31,8 @@ export function registerTopicCommand(program: Command) {const input: Record<string, any> = {};if (options.agentId) input.agentId = options.agentId;if (options.limit) input.pageSize = Number.parseInt(options.limit, 10);- if (options.page) input.current = Number.parseInt(options.page, 10);+ const page = options.page ? Number.parseInt(options.page, 10) : undefined;+ if (page !== undefined && page > 1) input.current = page - 1;const result = await client.topic.getTopics.query(input as any);const items = Array.isArray(result) ? result : ((result as any).items ?? []);