test: simplify channel setup account collectors · openclaw/openclaw@d510401
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,16 @@ const matrixNamedAccountPromotionKeys = [
|
34 | 34 | ] as const; |
35 | 35 | const telegramSingleAccountKeysToMove = ["streaming"] as const; |
36 | 36 | |
| 37 | +function collectNamedAccountIds(accounts: Record<string, unknown>): string[] { |
| 38 | +const ids: string[] = []; |
| 39 | +for (const accountId of Object.keys(accounts)) { |
| 40 | +if (accountId) { |
| 41 | +ids.push(accountId); |
| 42 | +} |
| 43 | +} |
| 44 | +return ids; |
| 45 | +} |
| 46 | + |
37 | 47 | function resolveMatrixSingleAccountPromotionTarget(params: { |
38 | 48 | channel: { defaultAccount?: string; accounts?: Record<string, unknown> }; |
39 | 49 | }): string { |
@@ -48,7 +58,7 @@ function resolveMatrixSingleAccountPromotionTarget(params: {
|
48 | 58 | ) ?? DEFAULT_ACCOUNT_ID |
49 | 59 | ); |
50 | 60 | } |
51 | | -const namedAccounts = Object.keys(accounts).filter(Boolean); |
| 61 | +const namedAccounts = collectNamedAccountIds(accounts); |
52 | 62 | return namedAccounts.length === 1 ? namedAccounts[0] : DEFAULT_ACCOUNT_ID; |
53 | 63 | } |
54 | 64 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -84,6 +84,16 @@ const matrixNamedAccountPromotionKeys = [
|
84 | 84 | ] as const; |
85 | 85 | const telegramSingleAccountKeysToMove = ["streaming"] as const; |
86 | 86 | |
| 87 | +function collectNamedAccountIds(accounts: Record<string, unknown>): string[] { |
| 88 | +const ids: string[] = []; |
| 89 | +for (const accountId of Object.keys(accounts)) { |
| 90 | +if (accountId) { |
| 91 | +ids.push(accountId); |
| 92 | +} |
| 93 | +} |
| 94 | +return ids; |
| 95 | +} |
| 96 | + |
87 | 97 | function resolveMatrixSingleAccountPromotionTarget(params: { |
88 | 98 | channel: { defaultAccount?: string; accounts?: Record<string, unknown> }; |
89 | 99 | }): string { |
@@ -98,7 +108,7 @@ function resolveMatrixSingleAccountPromotionTarget(params: {
|
98 | 108 | ) ?? DEFAULT_ACCOUNT_ID |
99 | 109 | ); |
100 | 110 | } |
101 | | -const namedAccounts = Object.keys(accounts).filter(Boolean); |
| 111 | +const namedAccounts = collectNamedAccountIds(accounts); |
102 | 112 | return namedAccounts.length === 1 ? namedAccounts[0] : DEFAULT_ACCOUNT_ID; |
103 | 113 | } |
104 | 114 | |
@@ -152,10 +162,14 @@ function createTokenPrompter(params: { confirms: boolean[]; texts: string[] }) {
|
152 | 162 | } |
153 | 163 | |
154 | 164 | function parseCsvInputs(value: string): string[] { |
155 | | -return value |
156 | | -.split(",") |
157 | | -.map((part) => part.trim()) |
158 | | -.filter(Boolean); |
| 165 | +const entries: string[] = []; |
| 166 | +for (const part of value.split(",")) { |
| 167 | +const entry = part.trim(); |
| 168 | +if (entry) { |
| 169 | +entries.push(entry); |
| 170 | +} |
| 171 | +} |
| 172 | +return entries; |
159 | 173 | } |
160 | 174 | |
161 | 175 | type AllowFromResolver = (params: { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。