mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Do not throw error when no edit blocks in write mode on obsidian
Editing is an option, not a requirement in file write/edit mode.
This commit is contained in:
@@ -447,28 +447,21 @@ For context, the user is currently working on the following files:
|
|||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
let error: { type: 'missing_field' | 'invalid_format' | 'preprocessing' | 'unknown', message: string, details?: string } | null = null;
|
let error: { type: 'missing_field' | 'invalid_format' | 'preprocessing' | 'unknown', message: string, details?: string } | null = null;
|
||||||
if (!editData) {
|
if (editData && !editData.file) {
|
||||||
error = {
|
|
||||||
type: 'invalid_format',
|
|
||||||
message: 'Invalid edit block format',
|
|
||||||
details: 'The edit block does not match the expected format'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (!editData.file) {
|
|
||||||
error = {
|
error = {
|
||||||
type: 'missing_field',
|
type: 'missing_field',
|
||||||
message: 'Missing "file" field in edit block',
|
message: 'Missing "file" field in edit block',
|
||||||
details: 'The "file" field is required and should contain the target file name'
|
details: 'The "file" field is required and should contain the target file name'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (editData.find === undefined || editData.find === null) {
|
else if (editData && (editData.find === undefined || editData.find === null)) {
|
||||||
error = {
|
error = {
|
||||||
type: 'missing_field',
|
type: 'missing_field',
|
||||||
message: 'Missing "find" field markers',
|
message: 'Missing "find" field markers',
|
||||||
details: 'The "find" field is required and should contain the content to find in the file'
|
details: 'The "find" field is required and should contain the content to find in the file'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (!editData.replace) {
|
else if (editData && !editData.replace) {
|
||||||
error = {
|
error = {
|
||||||
type: 'missing_field',
|
type: 'missing_field',
|
||||||
message: 'Missing "replace" field in edit block',
|
message: 'Missing "replace" field in edit block',
|
||||||
@@ -524,7 +517,7 @@ For context, the user is currently working on the following files:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!editData) {
|
if (!editData) {
|
||||||
console.error("No edit data parsed");
|
console.debug("No edit data parsed");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -898,6 +891,10 @@ For context, the user is currently working on the following files:
|
|||||||
|
|
||||||
// Parse the block content
|
// Parse the block content
|
||||||
const { editData, cleanContent, error, inProgress } = this.parseEditBlock(content, isComplete);
|
const { editData, cleanContent, error, inProgress } = this.parseEditBlock(content, isComplete);
|
||||||
|
if (!editData && !error) {
|
||||||
|
// If no edit data and no error, skip this block
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Escape content for HTML display
|
// Escape content for HTML display
|
||||||
const diff = diffWords(editData?.find || '', editData?.replace || '');
|
const diff = diffWords(editData?.find || '', editData?.replace || '');
|
||||||
@@ -913,7 +910,7 @@ For context, the user is currently working on the following files:
|
|||||||
).join('').trim();
|
).join('').trim();
|
||||||
|
|
||||||
let htmlRender = '';
|
let htmlRender = '';
|
||||||
if (error || !editData) {
|
if (error) {
|
||||||
// Error block
|
// Error block
|
||||||
console.error("Error parsing khoj-edit block:", error);
|
console.error("Error parsing khoj-edit block:", error);
|
||||||
console.error("Content causing error:", content);
|
console.error("Content causing error:", content);
|
||||||
@@ -928,7 +925,7 @@ For context, the user is currently working on the following files:
|
|||||||
<pre><code class="language-md error">${diffContent}</code></pre>
|
<pre><code class="language-md error">${diffContent}</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</details>`;
|
</details>`;
|
||||||
} else if (inProgress) {
|
} else if (editData && inProgress) {
|
||||||
// In-progress block
|
// In-progress block
|
||||||
htmlRender = `<details class="khoj-edit-accordion in-progress">
|
htmlRender = `<details class="khoj-edit-accordion in-progress">
|
||||||
<summary>📄 ${editData.file} <span class="khoj-edit-status">In Progress</span></summary>
|
<summary>📄 ${editData.file} <span class="khoj-edit-status">In Progress</span></summary>
|
||||||
@@ -936,7 +933,7 @@ For context, the user is currently working on the following files:
|
|||||||
<pre><code class="language-md">${diffContent}</code></pre>
|
<pre><code class="language-md">${diffContent}</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</details>`;
|
</details>`;
|
||||||
} else {
|
} else if (editData) {
|
||||||
// Success block
|
// Success block
|
||||||
// Find the actual file that will be modified
|
// Find the actual file that will be modified
|
||||||
const targetFile = this.findBestMatchingFile(editData.file, files);
|
const targetFile = this.findBestMatchingFile(editData.file, files);
|
||||||
|
|||||||
Reference in New Issue
Block a user