mateclaw/mateclaw-server/src/main/java/vip/mate/workspace/conversation
倪程伟 d84be668fa feat(webchat): explicit empty-session creation endpoint POST /sessions
Complements the implicit getOrCreate in /stream: lets a caller pre-create
an empty thread (message_count = 0) and receive sessionId / conversationId /
visitorToken up front, then decide when to send the first message via
/stream. Mirrors how downstream CRM/ticketing systems model "create the
conversation object first, message later".

Auth is the visitor's first touch — only X-MC-Key is required (no
X-MC-Visitor-Token, which the visitor can't have yet); the server signs
and returns a fresh visitorToken the caller must echo back on subsequent
GET/PUT/DELETE.

Behavior (issue #351):
- Idempotent on sessionId collision → returns the existing thread 200,
  does NOT clobber title.
- Empty-session quota ≤ 5 per (channel, visitor); 409 with a clear
  message when exceeded. Existing rows are exempt (re-create is idempotent).
- Caller-supplied title (1-100 chars) is persisted; absent title leaves
  the default "新对话" so the first /stream user message still derives
  it. getOrCreateWebchatConversation now accepts an optional title and
  only writes it on insert (existing rows untouched).
- agentId override mirrors /stream's workspace check.

ConversationService.getOrCreateWebchatConversation gains a title-aware
overload; the original 5-arg signature delegates with title = null.

End-to-end coverage in WebChatCreateSessionTest (@SpringBootTest, H2
with V147 migration): happy path, caller-title survives first user
message, default-title still derived, idempotent collision, quota 409,
bad API key 401, illegal sessionId/title 400, listed after creation.
2026-06-17 23:21:08 +08:00
..
config feat(db): introduce Flyway migration framework and unify H2/MySQL schemas 2026-04-11 16:34:09 +08:00
controller fix(conversation): surface webchat visitor sessions in the admin console 2026-06-17 23:21:08 +08:00
event fix(approval): clear in-memory pendingMap on conversation delete via domain event 2026-05-06 16:45:23 +08:00
model fix(webchat): list sessions whose conversationId hashed (long ids) 2026-06-17 23:21:08 +08:00
repository Initial commit: MateClaw — Java + Vue 3 AI Assistant System 2026-04-04 19:03:49 +08:00
vo fix(webchat): list sessions whose conversationId hashed (long ids) 2026-06-17 23:21:08 +08:00
ConversationService.java feat(webchat): explicit empty-session creation endpoint POST /sessions 2026-06-17 23:21:08 +08:00
TokenUsageService.java Initial commit: MateClaw — Java + Vue 3 AI Assistant System 2026-04-04 19:03:49 +08:00