fix: restore social context path and relax weibo cookie requirement

This commit is contained in:
Jason
2026-04-13 23:30:57 +08:00
parent 9f45c3f5eb
commit 2e77d9468a
3 changed files with 45 additions and 5 deletions

View File

@@ -796,6 +796,47 @@ ${topMentionText}
return total
}
private formatWeiboTimestamp(raw: string): string {
const parsed = Date.parse(String(raw || ''))
if (!Number.isFinite(parsed)) {
return String(raw || '').trim()
}
return new Date(parsed).toLocaleString('zh-CN')
}
private async getSocialContextSection(sessionId: string): Promise<string> {
const allowSocialContext = this.config.get('aiInsightAllowSocialContext') === true
if (!allowSocialContext) return ''
const rawCookie = String(this.config.get('aiInsightWeiboCookie') || '').trim()
if (!rawCookie) return ''
const bindings =
(this.config.get('aiInsightWeiboBindings') as Record<string, { uid?: string; screenName?: string }> | undefined) || {}
const binding = bindings[sessionId]
const uid = String(binding?.uid || '').trim()
if (!uid) return ''
const socialCountRaw = Number(this.config.get('aiInsightSocialContextCount') || 3)
const socialCount = Math.max(1, Math.min(5, Math.floor(socialCountRaw) || 3))
try {
const posts = await weiboService.fetchRecentPosts(uid, rawCookie, socialCount)
if (posts.length === 0) return ''
const lines = posts.map((post) => {
const time = this.formatWeiboTimestamp(post.createdAt)
const text = post.text.length > 180 ? `${post.text.slice(0, 180)}...` : post.text
return `[微博 ${time}] ${text}`
})
insightLog('INFO', `已加载 ${lines.length} 条微博公开内容 (uid=${uid})`)
return `近期公开社交平台内容(实验性,来源:微博,最近 ${lines.length} 条):\n${lines.join('\n')}`
} catch (error) {
insightLog('WARN', `拉取微博公开内容失败 (uid=${uid}): ${(error as Error).message}`)
return ''
}
}
// ── 沉默联系人扫描 ──────────────────────────────────────────────────────────
private scheduleSilenceScan(): void {
@@ -1072,6 +1113,7 @@ ${topMentionText}
`时间统计:${todayStatsDesc}`,
`全局统计:${globalStatsDesc}`,
contextSection,
socialContextSection,
'请给出你的见解≤80字'
].filter(Boolean).join('\n\n')

View File

@@ -203,7 +203,7 @@ class WeiboService {
const uid = normalizeWeiboUid(uidInput)
const cookie = normalizeWeiboCookieInput(cookieInput)
if (!cookie) {
return { success: false, error: '请先填写有效的微博 Cookie' }
return { success: true, uid }
}
const timeline = await this.fetchTimeline(uid, cookie)

View File

@@ -3268,8 +3268,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
<label style={{ marginBottom: 0 }}> AI </label>
<button
className="button-secondary"
style={{ fontSize: 12, padding: '3px 10px' }}
className="btn btn-secondary btn-sm"
onClick={async () => {
// 恢复默认清空自定义值UI 回到显示默认内容的状态
setAiInsightSystemPrompt('')
@@ -3676,8 +3675,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
<label style={{ marginBottom: 0 }}></label>
<button
className="button-secondary"
style={{ fontSize: 12, padding: '3px 10px' }}
className="btn btn-secondary btn-sm"
onClick={async () => {
setAiFootprintSystemPrompt('')
await configService.setAiFootprintSystemPrompt('')