feat: add summary

This commit is contained in:
熊潇 2025-06-28 02:46:50 +08:00
parent 204165bf73
commit e2d0720698
14 changed files with 158 additions and 15 deletions

View File

@ -38,6 +38,7 @@ export const getSign = async (signInfo: SignInfo, options?: SignOptions): Promis
// signUrl = 'http://localhost:5005/sign';
// const urlA1 = ''http://light.xiongxiao.me:5006/a1';
// const urlA1 = 'http://localhost:5005/a1';
// console.log('sign', signUrl);
const signs = await fetch(signUrl, {
method: 'POST',
headers: {
@ -215,6 +216,7 @@ export class XhsClient extends XhsClientBase {
try {
const response = await this.post(uri, data, { sign: this.sign.bind(this) });
console.log('getNoteById response', response, typeof response);
// return response['items'][0]['node_card'];
return response;
} catch (error) {

View File

@ -1 +1,2 @@
import './mentions/index.ts'
import './mentions/index.ts'
import './notes/index.ts'

View File

@ -7,8 +7,8 @@ app
})
.define(async (ctx) => {
const client = xhsServices.getClient();
const res = await client.c
if (res.code === 0) {
}
// const res = await client.getNote({});
// if (res.code === 0) {
// }
})
.addTo(app);

View File

@ -0,0 +1,18 @@
import { app, xhsServices } from '@kevisual/xhs/app.ts';
app
.route({
path: 'note',
key: 'getNote',
description: '获取笔记详情',
})
.define(async (ctx) => {
const { node_id, xsec_token } = ctx.query;
const client = xhsServices.getClient();
const res = await client.getNote(node_id, xsec_token);
if (res.code === 200) {
ctx.body = res.data || {};
} else {
ctx.throw(`获取笔记失败: ${node_id}`);
}
})
.addTo(app);

View File

@ -1 +1,2 @@
import './create-note.ts'
import './create-note.ts'
import './get-note.ts'

View File

@ -104,6 +104,16 @@ export class XhsServices {
}
return user.userid === xhsUserInfo.userid;
}
isReplayAi(data: any, key?: string) {
const mention = data?.mention || {};
const user_info = mention?.comment_info?.target_comment?.user_info || {};
if (user_info?.userid) {
const xhsUserInfo = this.getXhsUserInfo(key);
// 处理用户信息
return user_info.userid === xhsUserInfo.userid;
}
return false;
}
setCookie(cookie: string, key?: string) {
const xhsClient = this.map.get(this.getKey(key));
if (xhsClient) {
@ -123,4 +133,17 @@ export class XhsServices {
xhsClient.options.username = user.username;
}
}
setSignConfig(signConfig: { signUrl: string }, key?: string) {
const xhsClient = this.map.get(this.getKey(key));
if (xhsClient) {
xhsClient.options.signConfig = signConfig;
xhsClient.client.signConfig = signConfig;
}
console.log('setSignConfig', xhsClient?.options?.signConfig);
}
getSignConfig(key?: string) {
const xhsClient = this.map.get(this.getKey(key));
return xhsClient?.options?.signConfig || {};
}
}

View File

@ -8,17 +8,27 @@ import util from 'node:util';
// });
const getNoteById = async () => {
const client = xhsServices.getClient();
client.getNoteById('68136dab0000000007034c46', 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM').then((res) => {
console.log(res);
});
// client.getNoteById('68136dab0000000007034c46', 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM').then((res) => {
// console.log(res);
// });
const res = await client.getNoteById('68136dab0000000007034c46', 'LB6fmNfsd0keAQNjh3zOejDC2TVQLGY3zlTZjeRazBZdI=');
// console.log(res);
};
const getNote = async () => {
// const id = '68136dab0000000007034c46';
// const x = 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM=';
const id = '68136dab0000000007034c46';
const x = 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM=';
const x = 'LB6fmNfsd0keAQNjh3zOejDC2TVQLGY3zlTZjeRazBZdI=';
const client = xhsServices.getClient();
client.getNote(id, x).then((res) => {
const res = await client.getNote(id, x).then((res) => {
console.log(util.inspect(res, { depth: null }));
return res;
});
console.log('type res', typeof res);
if (res.code === 0) {
console.log('desc', res.data.desc);
}
};
program
.command('get-note')

View File

@ -27,6 +27,14 @@ export const cmdList: {
key: 'call-xiaoxiao',
},
},
{
category: '指令总结',
description: `总结当前的笔记,缩写当前笔记的内容`,
action: {
path: 'tools',
key: 'summarize-note',
},
},
];
agent
@ -96,4 +104,3 @@ ${text}
ctx.body = { cmd, text: text };
})
.addTo(agent);

View File

@ -22,7 +22,7 @@ agent
{
role: 'user',
content: `
500500markdown模式HTML标签或其他格式化内容
500markdown模式HTML标签或其他格式化内容
@ -64,6 +64,6 @@ ${text}
if (!ans) {
logger.error('Empty response from AI:', res);
}
ctx.body = getTagContent(ans)
ctx.body = getTagContent(ans);
})
.addTo(agent);

View File

@ -8,5 +8,6 @@ import './fix/prompt.ts';
import './xhs.ts';
import './tools/kuaren.ts';
import './tools/call-xiaoxiao.ts';
import './tools/summarize-note.ts';
export { agent };

View File

@ -0,0 +1,53 @@
import { agent } from '../agent.ts';
import { ai } from '../ai.ts';
agent
.route({
path: 'tools',
key: 'summarize-note',
})
.define(async (ctx: any) => {
const text = ctx?.query?.text || '';
const note = ctx?.query?.note || '';
if (!text) {
ctx.throw('请提供要总结的笔记内容');
}
const prompt = `
0. "当前内容不需要总结"
1.
2. 使
3.
4. 使
5.
6. 250
7.
8.
${text ? text : '无'}
${note}
`;
const res = await ai.chat(
[
{
role: 'user',
content: prompt,
},
],
{
// @ts-ignore
enable_thinking: false,
},
);
const pickRes = res.choices[0]?.message?.content || '';
if (!pickRes) {
ctx.throw('AI 没有返回任何内容,请稍后再试');
}
// 返回总结内容
ctx.body = pickRes.trim();
})
.addTo(agent);

View File

@ -1,3 +1,5 @@
import { useConfig } from '@kevisual/use-config/env';
export const config = useConfig();
export const isDev = config.ENV === 'development';

View File

@ -116,7 +116,9 @@ taskApp
// 检测是这个用户的username的笔记如果是的话需要有at的用户信息才继续。
const isOwner = xhsServices.isOwner({ username: note_username, userid: note_userid });
const isReplayAi = xhsServices.isReplayAi(data);
const xsec_token = data.xsec_token;
console.log(data);
const comment_id = data.comment.comment_id;
let content: string = data.comment?.content || 'test';
const postData = {
@ -132,12 +134,29 @@ taskApp
return;
}
}
content = content.replace('@' + note_username, '');
content = content.replace('@' + note_username, '');
const sliceContentCmd = content.slice(0, 20);
let note = '';
let hasNote = false;
if (sliceContentCmd.includes('笔记') || sliceContentCmd.includes('总结')) {
const res = await xhsApp.call({ path: 'note', key: 'getNote', payload: { node_id: note_id, xsec_token } });
if (res.code === 200) {
note = res.body?.desc || '';
hasNote = note ? true : false;
}
}
if (isReplayAi) {
// 如果是对AI回复的评论则不需要再回复
console.log('不需要AI回复AI的评论', note_username, note_id, content);
return;
}
const resAgent = await agent.call({
path: 'xhs',
payload: {
text: content,
note,
hasNote,
},
});
let responseText = '';

View File

@ -7,7 +7,7 @@ import { app as xhsApp, xhsServices as xhs, xhsRootClient, XhsServices } from '@
import { nanoid } from 'nanoid';
export const XHS_GET_UNREAD = 'unread_count';
export const XHS_QUEUE_NAME = 'XHS_QUEUE';
import { config } from '../modules/config.ts';
import { config, isDev } from '../modules/config.ts';
const server: XhsServices = xhs;
server.setCookie(config.XHS_ROOT_COOKIE || '');
@ -15,7 +15,13 @@ server.setUserInfo({
userid: config.XHS_USER_ID || '',
username: config.XHS_USER_NAME || '',
});
if (isDev) {
server.setSignConfig({
signUrl: 'http://localhost:5006/sign',
});
}
console.log('XHS_USER_INFO', config.XHS_USER_ID, config.XHS_USER_NAME, 'XHS_ROOT_COOKIE', config.XHS_ROOT_COOKIE);
console.log('XHS_SIGN_URL', server.getSignConfig().signUrl);
export const taskApp = new QueryRouterServer();
export { xhsApp };
export const xhsServices = server;