mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:31:36 +00:00
refactor: extract shared sandbox and gateway plumbing
This commit is contained in:
9
src/auto-reply/reply/reply-inline-whitespace.test.ts
Normal file
9
src/auto-reply/reply/reply-inline-whitespace.test.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { collapseInlineHorizontalWhitespace } from "./reply-inline-whitespace.js";
|
||||
|
||||
describe("collapseInlineHorizontalWhitespace", () => {
|
||||
it("collapses spaces and tabs but preserves newlines", () => {
|
||||
const value = "hello\t\tworld\n next\tline";
|
||||
expect(collapseInlineHorizontalWhitespace(value)).toBe("hello world\n next line");
|
||||
});
|
||||
});
|
||||
5
src/auto-reply/reply/reply-inline-whitespace.ts
Normal file
5
src/auto-reply/reply/reply-inline-whitespace.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
const INLINE_HORIZONTAL_WHITESPACE_RE = /[^\S\n]+/g;
|
||||
|
||||
export function collapseInlineHorizontalWhitespace(value: string): string {
|
||||
return value.replace(INLINE_HORIZONTAL_WHITESPACE_RE, " ");
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { collapseInlineHorizontalWhitespace } from "./reply-inline-whitespace.js";
|
||||
|
||||
const INLINE_SIMPLE_COMMAND_ALIASES = new Map<string, string>([
|
||||
["/help", "/help"],
|
||||
["/commands", "/commands"],
|
||||
@@ -24,10 +26,7 @@ export function extractInlineSimpleCommand(body?: string): {
|
||||
if (!command) {
|
||||
return null;
|
||||
}
|
||||
const cleaned = body
|
||||
.replace(match[0], " ")
|
||||
.replace(/[^\S\n]+/g, " ")
|
||||
.trim();
|
||||
const cleaned = collapseInlineHorizontalWhitespace(body.replace(match[0], " ")).trim();
|
||||
return { command, cleaned };
|
||||
}
|
||||
|
||||
@@ -41,9 +40,6 @@ export function stripInlineStatus(body: string): {
|
||||
}
|
||||
// Use [^\S\n]+ instead of \s+ to only collapse horizontal whitespace,
|
||||
// preserving newlines so multi-line messages keep their paragraph structure.
|
||||
const cleaned = trimmed
|
||||
.replace(INLINE_STATUS_RE, " ")
|
||||
.replace(/[^\S\n]+/g, " ")
|
||||
.trim();
|
||||
const cleaned = collapseInlineHorizontalWhitespace(trimmed.replace(INLINE_STATUS_RE, " ")).trim();
|
||||
return { cleaned, didStrip: cleaned !== trimmed };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user