mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-13 20:42:29 +08:00
fix context logic
This commit is contained in:
parent
f482b3b4c8
commit
9834e77bb4
@ -103,15 +103,11 @@ export class ContextExtractor {
|
|||||||
formattedContent += '```\n' + content + '\n```';
|
formattedContent += '```\n' + content + '\n```';
|
||||||
break;
|
break;
|
||||||
case 'canvas':
|
case 'canvas':
|
||||||
case 'mindMap':
|
|
||||||
case 'relationMap':
|
|
||||||
case 'geoMap':
|
|
||||||
if (mime === 'application/json') {
|
if (mime === 'application/json') {
|
||||||
try {
|
try {
|
||||||
// Parse JSON content
|
// Parse JSON content
|
||||||
const jsonContent = JSON.parse(content);
|
const jsonContent = JSON.parse(content);
|
||||||
|
|
||||||
if (type === 'canvas') {
|
|
||||||
// Extract text elements from canvas
|
// Extract text elements from canvas
|
||||||
if (jsonContent.elements && Array.isArray(jsonContent.elements)) {
|
if (jsonContent.elements && Array.isArray(jsonContent.elements)) {
|
||||||
const texts = jsonContent.elements
|
const texts = jsonContent.elements
|
||||||
@ -119,10 +115,24 @@ export class ContextExtractor {
|
|||||||
.map((element: any) => element.text);
|
.map((element: any) => element.text);
|
||||||
|
|
||||||
formattedContent += 'Canvas content:\n' + texts.join('\n');
|
formattedContent += 'Canvas content:\n' + texts.join('\n');
|
||||||
|
} else {
|
||||||
|
formattedContent += '[Empty canvas]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e: any) {
|
||||||
|
formattedContent += `[Error parsing canvas content: ${e.message}]`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
formattedContent += '[Canvas content]';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
case 'mindMap':
|
||||||
else if (type === 'mindMap') {
|
if (mime === 'application/json') {
|
||||||
|
try {
|
||||||
|
// Parse JSON content
|
||||||
|
const jsonContent = JSON.parse(content);
|
||||||
|
|
||||||
// Extract node text from mind map
|
// Extract node text from mind map
|
||||||
const extractMindMapNodes = (node: any): string[] => {
|
const extractMindMapNodes = (node: any): string[] => {
|
||||||
let texts: string[] = [];
|
let texts: string[] = [];
|
||||||
@ -139,10 +149,24 @@ export class ContextExtractor {
|
|||||||
|
|
||||||
if (jsonContent.root) {
|
if (jsonContent.root) {
|
||||||
formattedContent += 'Mind map content:\n' + extractMindMapNodes(jsonContent.root).join('\n');
|
formattedContent += 'Mind map content:\n' + extractMindMapNodes(jsonContent.root).join('\n');
|
||||||
|
} else {
|
||||||
|
formattedContent += '[Empty mind map]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e: any) {
|
||||||
|
formattedContent += `[Error parsing mind map content: ${e.message}]`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
formattedContent += '[Mind map content]';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
case 'relationMap':
|
||||||
else if (type === 'relationMap') {
|
if (mime === 'application/json') {
|
||||||
|
try {
|
||||||
|
// Parse JSON content
|
||||||
|
const jsonContent = JSON.parse(content);
|
||||||
|
|
||||||
// Extract relation map entities and connections
|
// Extract relation map entities and connections
|
||||||
let result = 'Relation map content:\n';
|
let result = 'Relation map content:\n';
|
||||||
|
|
||||||
@ -166,31 +190,45 @@ export class ContextExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
formattedContent += result;
|
formattedContent += result;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else if (type === 'geoMap') {
|
catch (e: any) {
|
||||||
|
formattedContent += `[Error parsing relation map content: ${e.message}]`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
formattedContent += '[Relation map content]';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'geoMap':
|
||||||
|
if (mime === 'application/json') {
|
||||||
|
try {
|
||||||
|
// Parse JSON content
|
||||||
|
const jsonContent = JSON.parse(content);
|
||||||
|
|
||||||
let result = 'Geographic map content:\n';
|
let result = 'Geographic map content:\n';
|
||||||
|
|
||||||
if (jsonContent.markers && Array.isArray(jsonContent.markers)) {
|
if (jsonContent.markers && Array.isArray(jsonContent.markers)) {
|
||||||
|
if (jsonContent.markers.length > 0) {
|
||||||
result += jsonContent.markers
|
result += jsonContent.markers
|
||||||
.map((marker: any) => {
|
.map((marker: any) => {
|
||||||
return `Location: ${marker.title || ''} (${marker.lat}, ${marker.lng})${marker.description ? ' - ' + marker.description : ''}`;
|
return `Location: ${marker.title || ''} (${marker.lat}, ${marker.lng})${marker.description ? ' - ' + marker.description : ''}`;
|
||||||
})
|
})
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
} else {
|
||||||
|
result += 'Empty geographic map';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result += 'Empty geographic map';
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedContent += result || 'Empty geographic map';
|
formattedContent += result;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
formattedContent += `[Error parsing ${type} content: ${e.message}]`;
|
formattedContent += `[Error parsing geographic map content: ${e.message}]`;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
formattedContent += '[Geographic map content]';
|
||||||
}
|
}
|
||||||
|
|
||||||
// If JSON parsing or specific handling failed, use default handling
|
|
||||||
formattedContent += `[${type} content]`;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mermaid':
|
case 'mermaid':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user