update , add mcp server stdio and sse

This commit is contained in:
duanfuxiang
2025-06-02 20:38:40 +08:00
parent 8ca5216b71
commit b1315aa6b1
30 changed files with 2639 additions and 955 deletions

View File

@@ -20,6 +20,72 @@ interface SearchResponse {
organic_results?: SearchResult[];
}
export interface EventProps {
[key: string]: string | number | boolean
}
export async function onEnt(
N: string,
props?: EventProps,
): Promise<void> {
return new Promise<void>((resolve) => {
try {
const eventUrl = `obsidian://plugin/infio-copilot/${N}`
const payload = {
name: N,
url: eventUrl,
domain: "copilot.infio.app",
...(props && Object.keys(props).length > 0 && { props })
}
const postData = JSON.stringify(payload)
const apiUrl = new URL(`https://api.infio.com/e1/api/event`)
const options = {
hostname: apiUrl.hostname,
port: apiUrl.port || 443,
path: apiUrl.pathname,
method: 'POST',
rejectUnauthorized: false,
headers: {
'User-Agent': navigator.userAgent,
'X-Forwarded-For': '127.0.0.1',
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData),
'X-Debug-Request': 'true'
}
}
const req = https.request(options, (res) => {
let data = ''
res.on('data', (chunk) => { data += chunk })
res.on('end', () => {
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
// console.log(`✅ successfully: ${N}`)
} else {
console.error(`❌ (${res.statusCode}):`, data)
}
resolve()
})
})
req.on('error', (error) => {
console.error('❌ Failed:', error)
resolve()
})
req.write(postData)
req.end()
} catch (error) {
console.error('❌ Failed:', error)
resolve()
}
})
}
// 添加余弦相似度计算函数
function cosineSimilarity(vecA: number[], vecB: number[]): number {
const dotProduct = vecA.reduce((sum, a, i) => sum + a * vecB[i], 0);