@firstlovecenter/ai-chat 0.8.1 → 0.9.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.
@@ -114,8 +114,14 @@ type SystemBlock = {
114
114
  * regardless of the chosen ORM.
115
115
  */
116
116
 
117
+ /**
118
+ * Chat session and message identifiers are short URL-safe UIDs (12 chars,
119
+ * ~72 bits of entropy, alphabet matches nanoid's URL-safe set). The
120
+ * package generates them in `createSession`/`appendMessage` so adapters
121
+ * never need to know about auto-increment vs UID.
122
+ */
117
123
  type ChatSession = {
118
- id: number;
124
+ id: string;
119
125
  userId: number;
120
126
  title: string;
121
127
  createdAt: Date;
@@ -129,8 +135,8 @@ type ChatMessageRole = 'user' | 'assistant';
129
135
  * narrator. `errorJson` is set when an assistant turn failed mid-stream.
130
136
  */
131
137
  type ChatMessage = {
132
- id: number;
133
- sessionId: number;
138
+ id: string;
139
+ sessionId: string;
134
140
  role: ChatMessageRole;
135
141
  question: string | null;
136
142
  blocks: unknown | null;
@@ -244,7 +250,7 @@ type CreateSessionInput = {
244
250
  title: string;
245
251
  };
246
252
  type AppendMessageInput = {
247
- sessionId: number;
253
+ sessionId: string;
248
254
  role: ChatMessageRole;
249
255
  question?: string | null;
250
256
  blocks?: unknown | null;
@@ -277,15 +283,15 @@ type AiSettingsPatch = {
277
283
  type PersistencePort = {
278
284
  createSession(input: CreateSessionInput): Promise<ChatSession>;
279
285
  /** Returns null when the session doesn't exist OR doesn't belong to this user. */
280
- getSession(id: number, userId: number): Promise<ChatSession | null>;
286
+ getSession(id: string, userId: number): Promise<ChatSession | null>;
281
287
  listSessionsForUser(userId: number, opts?: ListSessionsOpts): Promise<ChatSession[]>;
282
288
  /** No-op when session doesn't exist or doesn't belong to user — caller asserted authorisation. */
283
- updateSession(id: number, userId: number, patch: {
289
+ updateSession(id: string, userId: number, patch: {
284
290
  title?: string;
285
291
  }): Promise<void>;
286
- deleteSession(id: number, userId: number): Promise<void>;
292
+ deleteSession(id: string, userId: number): Promise<void>;
287
293
  appendMessage(input: AppendMessageInput): Promise<ChatMessage>;
288
- listMessagesForSession(sessionId: number, userId: number): Promise<ChatMessage[]>;
294
+ listMessagesForSession(sessionId: string, userId: number): Promise<ChatMessage[]>;
289
295
  /** Returns the singleton row, applying defaults if it's never been written. */
290
296
  getAiSettings(): Promise<AiSettings>;
291
297
  /**
@@ -114,8 +114,14 @@ type SystemBlock = {
114
114
  * regardless of the chosen ORM.
115
115
  */
116
116
 
117
+ /**
118
+ * Chat session and message identifiers are short URL-safe UIDs (12 chars,
119
+ * ~72 bits of entropy, alphabet matches nanoid's URL-safe set). The
120
+ * package generates them in `createSession`/`appendMessage` so adapters
121
+ * never need to know about auto-increment vs UID.
122
+ */
117
123
  type ChatSession = {
118
- id: number;
124
+ id: string;
119
125
  userId: number;
120
126
  title: string;
121
127
  createdAt: Date;
@@ -129,8 +135,8 @@ type ChatMessageRole = 'user' | 'assistant';
129
135
  * narrator. `errorJson` is set when an assistant turn failed mid-stream.
130
136
  */
131
137
  type ChatMessage = {
132
- id: number;
133
- sessionId: number;
138
+ id: string;
139
+ sessionId: string;
134
140
  role: ChatMessageRole;
135
141
  question: string | null;
136
142
  blocks: unknown | null;
@@ -244,7 +250,7 @@ type CreateSessionInput = {
244
250
  title: string;
245
251
  };
246
252
  type AppendMessageInput = {
247
- sessionId: number;
253
+ sessionId: string;
248
254
  role: ChatMessageRole;
249
255
  question?: string | null;
250
256
  blocks?: unknown | null;
@@ -277,15 +283,15 @@ type AiSettingsPatch = {
277
283
  type PersistencePort = {
278
284
  createSession(input: CreateSessionInput): Promise<ChatSession>;
279
285
  /** Returns null when the session doesn't exist OR doesn't belong to this user. */
280
- getSession(id: number, userId: number): Promise<ChatSession | null>;
286
+ getSession(id: string, userId: number): Promise<ChatSession | null>;
281
287
  listSessionsForUser(userId: number, opts?: ListSessionsOpts): Promise<ChatSession[]>;
282
288
  /** No-op when session doesn't exist or doesn't belong to user — caller asserted authorisation. */
283
- updateSession(id: number, userId: number, patch: {
289
+ updateSession(id: string, userId: number, patch: {
284
290
  title?: string;
285
291
  }): Promise<void>;
286
- deleteSession(id: number, userId: number): Promise<void>;
292
+ deleteSession(id: string, userId: number): Promise<void>;
287
293
  appendMessage(input: AppendMessageInput): Promise<ChatMessage>;
288
- listMessagesForSession(sessionId: number, userId: number): Promise<ChatMessage[]>;
294
+ listMessagesForSession(sessionId: string, userId: number): Promise<ChatMessage[]>;
289
295
  /** Returns the singleton row, applying defaults if it's never been written. */
290
296
  getAiSettings(): Promise<AiSettings>;
291
297
  /**