@animastor/assistant 0.1.0

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.
@@ -0,0 +1,50 @@
1
+ // ======================================================
2
+ // CHAT SESSION REPOSITORY — CONTRACT (Assistant-owned)
3
+ // ======================================================
4
+ // The port contract every chat-session persistence adapter must satisfy
5
+ // (the interface half of the A-1 repository seam). The concrete
6
+ // PostgreSQL implementation (the chat-sessions table) stays HOST-side
7
+ // (backend/src/storage/postgres/repositories/chat-session-repo.js) and is
8
+ // injected into the Assistant contour through the AssistantPorts
9
+ // sessionRepo field at the composition root — the package never knows the
10
+ // table, the SQL dialect or the driver.
11
+ // (docs/architecture/ai-assistant-extraction.md)
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * Runtime contract check for a chat-session repository adapter.
17
+ * Throws with a named message when a required method is missing — the
18
+ * composition root fails fast on a bad adapter instead of at request time.
19
+ *
20
+ * Required surface (the exact historical usage of the contour):
21
+ * listSessionsForBook(bookId) → Promise<rows>
22
+ * getSession(id) → Promise<row|null>
23
+ * getMessages(id) → Promise<Array>
24
+ * createSession(session) → Promise<void>
25
+ * setMessages(id, messages, updatedAt?) → Promise<void>
26
+ * renameSession(id, title, updatedAt?) → Promise<id|null>
27
+ * deleteSession(id) → Promise<id|null>
28
+ * getBookIdForSession(id) → Promise<bookId|null>
29
+ * purgeSessionsForBook(bookId) → Promise<void>
30
+ */
31
+ function assertSessionRepo(repo, label = 'sessionRepo') {
32
+ const required = [
33
+ 'listSessionsForBook',
34
+ 'getSession',
35
+ 'getMessages',
36
+ 'createSession',
37
+ 'setMessages',
38
+ 'renameSession',
39
+ 'deleteSession',
40
+ 'getBookIdForSession',
41
+ 'purgeSessionsForBook',
42
+ ];
43
+ const missing = required.filter((m) => typeof repo?.[m] !== 'function');
44
+ if (missing.length > 0) {
45
+ throw new Error(`${label}: missing required method(s): ${missing.join(', ')}`);
46
+ }
47
+ return repo;
48
+ }
49
+
50
+ module.exports = { assertSessionRepo };