Introduce a ChatId domain type #31
Labels
No labels
in-review
ready-for-agent
ready-for-human
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
weiwen/evie#31
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What to build
The chat-id string that keys every session (
tg-{telegram_id},api-{client_id}) is currently hand-built withformat!in five places, its validation rule lives alone in the HTTP interface, and the session-id minting ({chat_id}_{timestamp}) lives in the session manager.CONTEXT.mddocuments a format the code does not actually produce. Introduce a singleChatIddomain type that owns all three concerns — namespacing, validation, and session-id minting — so the format has exactly one home and cannot drift again.This is a pure refactor: keep the existing wire format (
tg-/api-hyphen namespaces, Unix-epoch session timestamp). Reconcile the documented drift by updatingCONTEXT.mdto match the code (hyphen + epoch), NOT by changing the code — so no session-map keys or on-disk session filenames change.Decision from grilling — enum representation:
ChatIdErrormaps into the HTTP interface's existingInvalidChatIdvariant via#[from], preserving the current 400 response and messages. The Telegram whitelist check keeps comparing the rawi64;ChatIdis only for the session key and session id.Acceptance criteria
ChatIdenum withtelegram, fallibleapi,session_id(ts), andDisplay, in its own module.format!("tg-…")/format!("api-…")sites and the session-id minting go throughChatId.-,_) lives onChatId::api; the HTTP handler calls it and maps the error to the existinginvalid_chat_id400 response.tg-{id},api-{id},{chat_id}_{epoch}), verified by unit tests onDisplayandsession_id.session_idtakes the timestamp as a parameter and is unit-tested deterministically.CONTEXT.mdChat ID / Session ID entries updated to describe the actual format (hyphen namespaces, epoch timestamp).just checkgreen.Blocked by
None - can start immediately.
Implemented
ChatIddomain type on branchsandcastle/issue-31(commit 63130cf).What was done:
src/chat_id.rs:ChatIdenum (Telegram(i64)/Api(String)) withDisplay(tg-{id}/api-{id}), infallibletelegram(), fallibleapi()(absorbs validation logic),session_id(ts)for deterministic session ID minting.ChatIdError(InvalidLength/InvalidChars) maps toApiError::InvalidChatIdvia#[from].format!("tg-…")/format!("api-…")sites replaced withEvieChatId::telegram(id)/ChatId::api(raw)?.SessionManager::send_message,clear_session,get_statusnow accept&ChatId; session IDs minted viachat_id.session_id(ts).CONTEXT.mdChat ID / Session ID glossary updated to match actual wire format (hyphen separator, Unix-epoch timestamp).Notes: No Rust toolchain available in sandbox — CI must validate compilation and tests.
Implementation complete on branch sandcastle/issue-31. All acceptance criteria met: ChatId enum with telegram/api/session_id/Display in chat_id.rs, all format! sites consolidated, HTTP validation absorbed into ChatId::api(), CONTEXT.md updated. No Rust toolchain in sandbox — CI must confirm just check green.