Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds pagination functionality and caching to the list_rooms tool, implementing smart caching with 5-minute TTL to reduce ChatWork API calls and pagination via offset/limit parameters for better user experience when handling large room lists.
- Implements pagination with offset/limit parameters for efficient data retrieval
- Adds Redux-based caching system with 5-minute TTL to minimize API calls
- Introduces comprehensive Zod schema validation for ChatWork Room objects
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/room.ts | Defines comprehensive Zod schema for ChatWork Room objects with validation helpers |
| src/toolCallbacks.ts | Refactors listRooms to support pagination and caching via Redux store |
| src/store/roomsSlice.ts | Implements Redux slice for room caching with TTL-based expiration |
| src/store/roomsSlice.test.ts | Comprehensive test coverage for Redux slice and pagination logic |
| src/store/index.ts | Configures Redux store with rooms slice and exports convenience functions |
| src/server.ts | Updates server registration to use new pagination schema |
| src/schema.ts | Adds pagination parameters schema for list_rooms tool |
| package.json | Adds Redux Toolkit dependency |
src/types/room.ts
Outdated
|
|
||
| role: z | ||
| .enum(['admin', 'member', 'readonly']) | ||
| .describe('ルールでの自分の権限 (admin: 管理者, member: メンバー, readonly: 閲覧のみ)'), |
There was a problem hiding this comment.
The word 'ルール' should be 'ルーム' (room) instead of 'ルール' (rule) in the Japanese description.
| .describe('ルールでの自分の権限 (admin: 管理者, member: メンバー, readonly: 閲覧のみ)'), | |
| .describe('ルームでの自分の権限 (admin: 管理者, member: メンバー, readonly: 閲覧のみ)'), |
| getDefaultMiddleware({ | ||
| // Disable serializability check for Date objects in TTL | ||
| serializableCheck: { | ||
| ignoredPaths: ['rooms.rooms.timestamp'], |
There was a problem hiding this comment.
[nitpick] The nested path 'rooms.rooms.timestamp' creates confusion due to the redundant naming. Consider renaming the slice or the property to improve clarity.
| ignoredPaths: ['rooms.rooms.timestamp'], | |
| ignoredPaths: ['rooms.data.timestamp'], |
| response: JSON.stringify(minifiedResponse), | ||
| }; | ||
| }; | ||
| const CACHE_TTL = 5 * 60 * 1000; // 5分 |
There was a problem hiding this comment.
[nitpick] The cache TTL should be configurable rather than hardcoded. Consider moving this to a configuration file or environment variable.
| const CACHE_TTL = 5 * 60 * 1000; // 5分 | |
| const CACHE_TTL = Number(process.env.CACHE_TTL_MS) || 5 * 60 * 1000; // Default to 5 minutes |
| listContacts, | ||
| ); | ||
| server.tool('list_rooms', 'チャット一覧を取得します。', listRooms); | ||
| server.registerTool( |
There was a problem hiding this comment.
registerToolに変更したのは、こちらのほうが最新のAPIであり、toolはさまざまな引数に対応できるoverloadを実現しているのでやや扱いにくいため、将来的にこちらを利用すべきと考えたため。
This change implements pagination for the list_rooms tool to improve performance and usability when dealing with large numbers of rooms. A TTL-based cache system was added to prevent unnecessary API calls when fetching room data. Changes: - Add pagination parameters (offset, limit) to listRoomsParamsSchema - Implement Cache class with TTL functionality for efficient data caching - Update listRooms implementation to use cache and support pagination - Modify server.ts to use new parameter schema for list_rooms tool 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
… Zod validation Replace the class-based cache system with Redux Toolkit for functional programming approach and add comprehensive Zod schema validation for ChatWork Room objects. Changes: - Remove src/cache.ts class-based implementation - Add Redux Toolkit store with TTL-enabled state management - Implement roomsSlice with pure function reducers and selectors - Add comprehensive Zod schema for Room type validation (src/types/room.ts) - Update listRooms to use Redux store and runtime validation - Add extensive unit tests for Redux slice and selectors - Maintain pagination functionality with improved type safety Benefits: - Functional programming approach with pure functions - Runtime type validation with Zod schemas - Immutable state management via Redux Toolkit - Enhanced extensibility for future middleware additions - Better testability with predictable state transitions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
bfc607f to
d3bb14c
Compare
概要
list_roomsツールにページネーション機能を追加し、APIアクセス削減のためのキャッシュ機能を実装しました。主な機能
実装詳細
メリット
Test plan
🤖 Generated with Claude Code
以下人間による追加。
動作確認方法として、
を使って動作を確認。
試した引数
reduxを使ったら理由の補足。classが使われる実装になったため。classの代わりの代替えの方法としては、クロージャかreduxを使う手段が検討できる。クロージャを使う場合も実質オブジェクト指向なので、関数的なreduxを採用している。