mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-04-22 15:09:04 +00:00
Merge pull request #25 from Jasonzhu1207/fix/insight-social-context-runtime-and-cookie-optional
fix: restore social context path and make Weibo cookie optional for binding
This commit is contained in:
@@ -796,6 +796,47 @@ ${topMentionText}
|
|||||||
return total
|
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 {
|
private scheduleSilenceScan(): void {
|
||||||
@@ -1072,6 +1113,7 @@ ${topMentionText}
|
|||||||
`时间统计:${todayStatsDesc}`,
|
`时间统计:${todayStatsDesc}`,
|
||||||
`全局统计:${globalStatsDesc}`,
|
`全局统计:${globalStatsDesc}`,
|
||||||
contextSection,
|
contextSection,
|
||||||
|
socialContextSection,
|
||||||
'请给出你的见解(≤80字):'
|
'请给出你的见解(≤80字):'
|
||||||
].filter(Boolean).join('\n\n')
|
].filter(Boolean).join('\n\n')
|
||||||
|
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ class WeiboService {
|
|||||||
const uid = normalizeWeiboUid(uidInput)
|
const uid = normalizeWeiboUid(uidInput)
|
||||||
const cookie = normalizeWeiboCookieInput(cookieInput)
|
const cookie = normalizeWeiboCookieInput(cookieInput)
|
||||||
if (!cookie) {
|
if (!cookie) {
|
||||||
return { success: false, error: '请先填写有效的微博 Cookie' }
|
return { success: true, uid }
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeline = await this.fetchTimeline(uid, cookie)
|
const timeline = await this.fetchTimeline(uid, cookie)
|
||||||
|
|||||||
@@ -3268,8 +3268,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
|||||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
|
||||||
<label style={{ marginBottom: 0 }}>自定义 AI 见解提示词</label>
|
<label style={{ marginBottom: 0 }}>自定义 AI 见解提示词</label>
|
||||||
<button
|
<button
|
||||||
className="button-secondary"
|
className="btn btn-secondary btn-sm"
|
||||||
style={{ fontSize: 12, padding: '3px 10px' }}
|
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
// 恢复默认:清空自定义值,UI 回到显示默认内容的状态
|
// 恢复默认:清空自定义值,UI 回到显示默认内容的状态
|
||||||
setAiInsightSystemPrompt('')
|
setAiInsightSystemPrompt('')
|
||||||
@@ -3676,8 +3675,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
|||||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
|
||||||
<label style={{ marginBottom: 0 }}>足迹总结提示词</label>
|
<label style={{ marginBottom: 0 }}>足迹总结提示词</label>
|
||||||
<button
|
<button
|
||||||
className="button-secondary"
|
className="btn btn-secondary btn-sm"
|
||||||
style={{ fontSize: 12, padding: '3px 10px' }}
|
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setAiFootprintSystemPrompt('')
|
setAiFootprintSystemPrompt('')
|
||||||
await configService.setAiFootprintSystemPrompt('')
|
await configService.setAiFootprintSystemPrompt('')
|
||||||
|
|||||||
Reference in New Issue
Block a user