Skip to content

Commit 9976922

Browse files
committed
fix: bug
1 parent 625de30 commit 9976922

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

apps/core/src/modules/ai/ai-agent/ai-agent-conversation.service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,24 @@ export class AiAgentConversationService {
8787
updated: new Date(),
8888
},
8989
},
90-
{ returnDocument: 'after', projection: { messages: 0 }, lean: true },
90+
{ returnDocument: 'after', lean: true },
9191
)
9292
if (!result) {
9393
throw new BizException(
9494
ErrorCodeEnum.ContentNotFoundCantProcess,
9595
'Conversation not found',
9696
)
9797
}
98-
return result
98+
99+
if (
100+
!result.title &&
101+
messages.some((m) => m.role === 'assistant' || m.type === 'assistant')
102+
) {
103+
this.generateTitle(id, messages, result.model, result.providerId)
104+
}
105+
106+
const { messages: _messages, ...rest } = result
107+
return rest
99108
}
100109

101110
async updateById(

apps/core/src/modules/page/page.controller.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,30 @@ export class PageController {
4545
async getPagesSummary(@Query() query: PagerDto, @Lang() lang?: string) {
4646
const { size, select, page, sortBy, sortOrder } = query
4747

48+
// When lang is present, ensure text/meta are fetched for translation even if not in select
49+
let paginateSelect = select
50+
if (lang && paginateSelect) {
51+
for (const field of [
52+
'text',
53+
'meta',
54+
'subtitle',
55+
'content',
56+
'contentFormat',
57+
'modified',
58+
'created',
59+
]) {
60+
if (!paginateSelect.includes(field)) {
61+
paginateSelect = `${paginateSelect} ${field}`
62+
}
63+
}
64+
}
65+
4866
const result = await this.pageService.model.paginate(
4967
{},
5068
{
5169
limit: size,
5270
page,
53-
select,
71+
select: paginateSelect,
5472
sort: sortBy ? { [sortBy]: sortOrder || -1 } : { order: -1 },
5573
},
5674
)
@@ -101,6 +119,26 @@ export class PageController {
101119
})
102120
}
103121

122+
// Strip fields that were added only for translation
123+
if (select) {
124+
const stripFields = [
125+
'text',
126+
'meta',
127+
'subtitle',
128+
'content',
129+
'contentFormat',
130+
'modified',
131+
'created',
132+
].filter((f) => !select.includes(f))
133+
if (stripFields.length) {
134+
for (const doc of result.docs) {
135+
for (const field of stripFields) {
136+
delete (doc as any)[field]
137+
}
138+
}
139+
}
140+
}
141+
104142
return result
105143
}
106144

0 commit comments

Comments
 (0)