fix: add default values for optional config fields #3
@@ -25,8 +25,24 @@ export type Decision = {
|
|||||||
reason: string;
|
reason: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip trailing OpenClaw metadata blocks from the prompt to get the actual message content.
|
||||||
|
* The prompt format is: [prepend instruction]\n\n[message]\n\nConversation info (untrusted metadata):\n```json\n{...}\n```\n\nSender (untrusted metadata):\n```json\n{...}\n```
|
||||||
|
*/
|
||||||
|
function stripTrailingMetadata(input: string): string {
|
||||||
|
// Remove all trailing "XXX (untrusted metadata):\n```json\n...\n```" blocks
|
||||||
|
let text = input;
|
||||||
|
// eslint-disable-next-line no-constant-condition
|
||||||
|
while (true) {
|
||||||
|
const m = text.match(/\n*[A-Z][^\n]*\(untrusted metadata\):\s*```json\s*[\s\S]*?```\s*$/);
|
||||||
|
if (!m) break;
|
||||||
|
text = text.slice(0, text.length - m[0].length);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
function getLastChar(input: string): string {
|
function getLastChar(input: string): string {
|
||||||
const t = input.trim();
|
const t = stripTrailingMetadata(input).trim();
|
||||||
return t.length ? t[t.length - 1] : "";
|
return t.length ? t[t.length - 1] : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user