mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-28 07:16:53 +05:00
feat(ipuaro): add session configuration
- Add SessionConfigSchema with persistIndefinitely, maxHistoryMessages, saveInputHistory - Implement Session.truncateHistory() method for limiting message history - Update HandleMessage to support history truncation and input history toggle - Add config flow through useSession and App components - Add 19 unit tests for SessionConfigSchema - Update CHANGELOG.md and ROADMAP.md for v0.22.2
This commit is contained in:
@@ -79,7 +79,7 @@ export class AuthService {
|
||||
return {
|
||||
token,
|
||||
expiresAt,
|
||||
userId: user.id
|
||||
userId: user.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ async function main(): Promise<void> {
|
||||
email: "demo@example.com",
|
||||
name: "Demo User",
|
||||
password: "password123",
|
||||
role: "admin"
|
||||
role: "admin",
|
||||
})
|
||||
|
||||
logger.info("Demo user created", { userId: user.id })
|
||||
|
||||
@@ -25,9 +25,7 @@ export class UserService {
|
||||
}
|
||||
|
||||
// Check if user already exists
|
||||
const existingUser = Array.from(this.users.values()).find(
|
||||
(u) => u.email === dto.email
|
||||
)
|
||||
const existingUser = Array.from(this.users.values()).find((u) => u.email === dto.email)
|
||||
|
||||
if (existingUser) {
|
||||
throw new Error("User with this email already exists")
|
||||
@@ -40,7 +38,7 @@ export class UserService {
|
||||
name: dto.name,
|
||||
role: dto.role || "user",
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
updatedAt: new Date(),
|
||||
}
|
||||
|
||||
this.users.set(user.id, user)
|
||||
@@ -71,7 +69,7 @@ export class UserService {
|
||||
...user,
|
||||
...(dto.name && { name: dto.name }),
|
||||
...(dto.role && { role: dto.role }),
|
||||
updatedAt: new Date()
|
||||
updatedAt: new Date(),
|
||||
}
|
||||
|
||||
this.users.set(id, updated)
|
||||
|
||||
@@ -30,7 +30,7 @@ export class Logger {
|
||||
level,
|
||||
context: this.context,
|
||||
message,
|
||||
...(meta && { meta })
|
||||
...(meta && { meta }),
|
||||
}
|
||||
console.log(JSON.stringify(logEntry))
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ export function sanitizeInput(input: string): string {
|
||||
export class ValidationError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public field: string
|
||||
public field: string,
|
||||
) {
|
||||
super(message)
|
||||
this.name = "ValidationError"
|
||||
|
||||
@@ -18,7 +18,7 @@ describe("UserService", () => {
|
||||
const user = await userService.createUser({
|
||||
email: "test@example.com",
|
||||
name: "Test User",
|
||||
password: "password123"
|
||||
password: "password123",
|
||||
})
|
||||
|
||||
expect(user).toBeDefined()
|
||||
@@ -32,8 +32,8 @@ describe("UserService", () => {
|
||||
userService.createUser({
|
||||
email: "invalid-email",
|
||||
name: "Test User",
|
||||
password: "password123"
|
||||
})
|
||||
password: "password123",
|
||||
}),
|
||||
).rejects.toThrow(ValidationError)
|
||||
})
|
||||
|
||||
@@ -42,8 +42,8 @@ describe("UserService", () => {
|
||||
userService.createUser({
|
||||
email: "test@example.com",
|
||||
name: "Test User",
|
||||
password: "weak"
|
||||
})
|
||||
password: "weak",
|
||||
}),
|
||||
).rejects.toThrow(ValidationError)
|
||||
})
|
||||
|
||||
@@ -51,15 +51,15 @@ describe("UserService", () => {
|
||||
await userService.createUser({
|
||||
email: "test@example.com",
|
||||
name: "Test User",
|
||||
password: "password123"
|
||||
password: "password123",
|
||||
})
|
||||
|
||||
await expect(
|
||||
userService.createUser({
|
||||
email: "test@example.com",
|
||||
name: "Another User",
|
||||
password: "password123"
|
||||
})
|
||||
password: "password123",
|
||||
}),
|
||||
).rejects.toThrow("already exists")
|
||||
})
|
||||
})
|
||||
@@ -69,7 +69,7 @@ describe("UserService", () => {
|
||||
const created = await userService.createUser({
|
||||
email: "test@example.com",
|
||||
name: "Test User",
|
||||
password: "password123"
|
||||
password: "password123",
|
||||
})
|
||||
|
||||
const found = await userService.getUserById(created.id)
|
||||
@@ -87,11 +87,11 @@ describe("UserService", () => {
|
||||
const user = await userService.createUser({
|
||||
email: "test@example.com",
|
||||
name: "Test User",
|
||||
password: "password123"
|
||||
password: "password123",
|
||||
})
|
||||
|
||||
const updated = await userService.updateUser(user.id, {
|
||||
name: "Updated Name"
|
||||
name: "Updated Name",
|
||||
})
|
||||
|
||||
expect(updated.name).toBe("Updated Name")
|
||||
@@ -99,9 +99,9 @@ describe("UserService", () => {
|
||||
})
|
||||
|
||||
it("should throw error for non-existent user", async () => {
|
||||
await expect(
|
||||
userService.updateUser("non-existent", { name: "Test" })
|
||||
).rejects.toThrow("not found")
|
||||
await expect(userService.updateUser("non-existent", { name: "Test" })).rejects.toThrow(
|
||||
"not found",
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -110,7 +110,7 @@ describe("UserService", () => {
|
||||
const user = await userService.createUser({
|
||||
email: "test@example.com",
|
||||
name: "Test User",
|
||||
password: "password123"
|
||||
password: "password123",
|
||||
})
|
||||
|
||||
await userService.deleteUser(user.id)
|
||||
@@ -125,13 +125,13 @@ describe("UserService", () => {
|
||||
await userService.createUser({
|
||||
email: "user1@example.com",
|
||||
name: "User 1",
|
||||
password: "password123"
|
||||
password: "password123",
|
||||
})
|
||||
|
||||
await userService.createUser({
|
||||
email: "user2@example.com",
|
||||
name: "User 2",
|
||||
password: "password123"
|
||||
password: "password123",
|
||||
})
|
||||
|
||||
const users = await userService.listUsers()
|
||||
|
||||
@@ -3,6 +3,6 @@ import { defineConfig } from "vitest/config"
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: "node"
|
||||
}
|
||||
environment: "node",
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user