mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:31:23 +00:00
refactor(auto-reply): share directive arg parsing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { QueueDropPolicy, QueueMode } from "./types.js";
|
||||
import { parseDurationMs } from "../../../cli/parse-duration.js";
|
||||
import { skipDirectiveArgPrefix, takeDirectiveToken } from "../directive-parsing.js";
|
||||
import { normalizeQueueDropPolicy, normalizeQueueMode } from "./normalize.js";
|
||||
|
||||
function parseQueueDebounce(raw?: string): number | undefined {
|
||||
@@ -45,17 +46,8 @@ function parseQueueDirectiveArgs(raw: string): {
|
||||
rawDrop?: string;
|
||||
hasOptions: boolean;
|
||||
} {
|
||||
let i = 0;
|
||||
const len = raw.length;
|
||||
while (i < len && /\s/.test(raw[i])) {
|
||||
i += 1;
|
||||
}
|
||||
if (raw[i] === ":") {
|
||||
i += 1;
|
||||
while (i < len && /\s/.test(raw[i])) {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
let i = skipDirectiveArgPrefix(raw);
|
||||
let consumed = i;
|
||||
let queueMode: QueueMode | undefined;
|
||||
let queueReset = false;
|
||||
@@ -68,21 +60,9 @@ function parseQueueDirectiveArgs(raw: string): {
|
||||
let rawDrop: string | undefined;
|
||||
let hasOptions = false;
|
||||
const takeToken = (): string | null => {
|
||||
if (i >= len) {
|
||||
return null;
|
||||
}
|
||||
const start = i;
|
||||
while (i < len && !/\s/.test(raw[i])) {
|
||||
i += 1;
|
||||
}
|
||||
if (start === i) {
|
||||
return null;
|
||||
}
|
||||
const token = raw.slice(start, i);
|
||||
while (i < len && /\s/.test(raw[i])) {
|
||||
i += 1;
|
||||
}
|
||||
return token;
|
||||
const res = takeDirectiveToken(raw, i);
|
||||
i = res.nextIndex;
|
||||
return res.token;
|
||||
};
|
||||
while (i < len) {
|
||||
const token = takeToken();
|
||||
|
||||
Reference in New Issue
Block a user