refactor(routing): share optional agent id normalization · openclaw/openclaw@056e5b6
vincentkoc
·
2026-06-23
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -64,6 +64,7 @@ import { createSubsystemLogger } from "../logging/subsystem.js";
|
64 | 64 | import { |
65 | 65 | isSubagentSessionKey, |
66 | 66 | normalizeAgentId, |
| 67 | +normalizeOptionalAgentId, |
67 | 68 | parseAgentSessionKey, |
68 | 69 | resolveAgentIdFromSessionKey, |
69 | 70 | } from "../routing/session-key.js"; |
@@ -531,14 +532,6 @@ function resolveConfiguredAcpSubagentTargetIds(cfg: OpenClawConfig): string[] {
|
531 | 532 | return Array.from(ids); |
532 | 533 | } |
533 | 534 | |
534 | | -function normalizeOptionalAgentId(value: string | undefined | null): string | undefined { |
535 | | -const trimmed = normalizeOptionalString(value) ?? ""; |
536 | | -if (!trimmed) { |
537 | | -return undefined; |
538 | | -} |
539 | | -return normalizeAgentId(trimmed); |
540 | | -} |
541 | | - |
542 | 535 | function summarizeError(err: unknown): string { |
543 | 536 | return formatErrorMessage(err); |
544 | 537 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | // Doctor scanner and repair for subagent allowlists that reference missing agents. |
2 | | -import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
3 | 2 | import { listAgentIds } from "../../../agents/agent-scope-config.js"; |
4 | 3 | import type { OpenClawConfig } from "../../../config/types.openclaw.js"; |
5 | | -import { normalizeAgentId } from "../../../routing/session-key.js"; |
| 4 | +import { normalizeAgentId, normalizeOptionalAgentId } from "../../../routing/session-key.js"; |
6 | 5 | |
7 | 6 | export type StaleSubagentAllowlistHit = { |
8 | 7 | /** Config path containing the stale allowAgents entry. */ |
@@ -13,14 +12,6 @@ export type StaleSubagentAllowlistHit = {
|
13 | 12 | normalizedAgentId: string; |
14 | 13 | }; |
15 | 14 | |
16 | | -function normalizeOptionalAgentId(value: string | undefined | null): string | undefined { |
17 | | -const trimmed = normalizeOptionalString(value) ?? ""; |
18 | | -if (!trimmed) { |
19 | | -return undefined; |
20 | | -} |
21 | | -return normalizeAgentId(trimmed); |
22 | | -} |
23 | | - |
24 | 15 | function collectConfiguredSubagentTargetIds(cfg: OpenClawConfig): Set<string> { |
25 | 16 | const ids = new Set<string>(listAgentIds(cfg)); |
26 | 17 | for (const agent of cfg.agents?.list ?? []) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | /** Name, agent id, and payload text normalization helpers for cron service ops. */ |
2 | | -import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
3 | | -import { normalizeAgentId } from "../../routing/session-key.js"; |
| 2 | +import { normalizeOptionalAgentId } from "../../routing/session-key.js"; |
4 | 3 | import { truncateUtf16Safe } from "../../utils.js"; |
5 | 4 | import type { CronPayload } from "../types.js"; |
6 | 5 | |
@@ -24,13 +23,7 @@ function truncateText(input: string, maxLen: number) {
|
24 | 23 | } |
25 | 24 | |
26 | 25 | /** Normalizes optional cron agent ids through the canonical session-key agent id rules. */ |
27 | | -export function normalizeOptionalAgentId(raw: unknown) { |
28 | | -const trimmed = normalizeOptionalString(raw); |
29 | | -if (!trimmed) { |
30 | | -return undefined; |
31 | | -} |
32 | | -return normalizeAgentId(trimmed); |
33 | | -} |
| 26 | +export { normalizeOptionalAgentId }; |
34 | 27 | |
35 | 28 | /** Infers a compact cron job name from payload text first, then schedule shape. */ |
36 | 29 | export function inferCronJobName(job: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | // Routing session key helpers build stable session keys from route targets. |
2 | | -import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce"; |
| 2 | +import { |
| 3 | +normalizeLowercaseStringOrEmpty, |
| 4 | +normalizeOptionalString, |
| 5 | +} from "@openclaw/normalization-core/string-coerce"; |
3 | 6 | import type { ChatType } from "../channels/chat-type.js"; |
4 | 7 | import { |
5 | 8 | isCronRunSessionKey, |
@@ -191,6 +194,11 @@ export function normalizeAgentId(value: string | undefined | null): string {
|
191 | 194 | ); |
192 | 195 | } |
193 | 196 | |
| 197 | +export function normalizeOptionalAgentId(value: unknown): string | undefined { |
| 198 | +const trimmed = normalizeOptionalString(value); |
| 199 | +return trimmed ? normalizeAgentId(trimmed) : undefined; |
| 200 | +} |
| 201 | + |
194 | 202 | export function isValidAgentId(value: string | undefined | null): boolean { |
195 | 203 | const trimmed = (value ?? "").trim(); |
196 | 204 | return Boolean(trimmed) && VALID_ID_RE.test(trimmed); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。