refactor: share visible approval list mapping · openclaw/openclaw@6464f8d
vincentkoc
·
2026-05-30
·
via Recent Commits to openclaw:main
File tree
src/gateway/server-methods
| Original file line number | Diff line number | Diff line change |
|---|
@@ -44,6 +44,13 @@ type RequestedApprovalEvent<TPayload extends ApprovalTurnSourceFields> = {
|
44 | 44 | expiresAtMs: number; |
45 | 45 | }; |
46 | 46 | |
| 47 | +type PendingApprovalListEntry<TPayload> = { |
| 48 | +id: string; |
| 49 | +request: TPayload; |
| 50 | +createdAtMs: number; |
| 51 | +expiresAtMs: number; |
| 52 | +}; |
| 53 | + |
47 | 54 | function isPromiseLike<T>(value: T | Promise<T>): value is Promise<T> { |
48 | 55 | return typeof value === "object" && value !== null && "then" in value; |
49 | 56 | } |
@@ -114,6 +121,26 @@ export function isApprovalRecordVisibleToClient<TPayload>(params: {
|
114 | 121 | return true; |
115 | 122 | } |
116 | 123 | |
| 124 | +export function listVisiblePendingApprovalRequests<TPayload>(params: { |
| 125 | +manager: ExecApprovalManager<TPayload>; |
| 126 | +client?: GatewayClient | null; |
| 127 | +}): PendingApprovalListEntry<TPayload>[] { |
| 128 | +return params.manager |
| 129 | +.listPendingRecords() |
| 130 | +.filter((record) => |
| 131 | +isApprovalRecordVisibleToClient({ |
| 132 | + record, |
| 133 | +client: params.client ?? null, |
| 134 | +}), |
| 135 | +) |
| 136 | +.map((record) => ({ |
| 137 | +id: record.id, |
| 138 | +request: record.request, |
| 139 | +createdAtMs: record.createdAtMs, |
| 140 | +expiresAtMs: record.expiresAtMs, |
| 141 | +})); |
| 142 | +} |
| 143 | + |
117 | 144 | export function resolveApprovalRequestRecipientConnIds<TPayload>(params: { |
118 | 145 | context: GatewayRequestContext; |
119 | 146 | record: ExecApprovalRecord<TPayload>; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,7 @@ import {
|
37 | 37 | handleApprovalResolve, |
38 | 38 | isApprovalDecision, |
39 | 39 | isApprovalRecordVisibleToClient, |
| 40 | +listVisiblePendingApprovalRequests, |
40 | 41 | respondPendingApprovalLookupError, |
41 | 42 | resolvePendingApprovalRecord, |
42 | 43 | } from "./approval-shared.js"; |
@@ -136,19 +137,7 @@ export function createExecApprovalHandlers(
|
136 | 137 | ); |
137 | 138 | }, |
138 | 139 | "exec.approval.list": async ({ respond, client }) => { |
139 | | -respond( |
140 | | -true, |
141 | | -manager |
142 | | -.listPendingRecords() |
143 | | -.filter((record) => isApprovalRecordVisibleToClient({ record, client })) |
144 | | -.map((record) => ({ |
145 | | -id: record.id, |
146 | | -request: record.request, |
147 | | -createdAtMs: record.createdAtMs, |
148 | | -expiresAtMs: record.expiresAtMs, |
149 | | -})), |
150 | | -undefined, |
151 | | -); |
| 140 | +respond(true, listVisiblePendingApprovalRequests({ manager, client }), undefined); |
152 | 141 | }, |
153 | 142 | "exec.approval.request": async ({ params, respond, context, client }) => { |
154 | 143 | if (!validateExecApprovalRequestParams(params)) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -21,7 +21,7 @@ import {
|
21 | 21 | handleApprovalWaitDecision, |
22 | 22 | handlePendingApprovalRequest, |
23 | 23 | isApprovalDecision, |
24 | | -isApprovalRecordVisibleToClient, |
| 24 | +listVisiblePendingApprovalRequests, |
25 | 25 | } from "./approval-shared.js"; |
26 | 26 | import type { GatewayRequestHandlers } from "./types.js"; |
27 | 27 | |
@@ -31,19 +31,7 @@ export function createPluginApprovalHandlers(
|
31 | 31 | ): GatewayRequestHandlers { |
32 | 32 | return { |
33 | 33 | "plugin.approval.list": async ({ respond, client }) => { |
34 | | -respond( |
35 | | -true, |
36 | | -manager |
37 | | -.listPendingRecords() |
38 | | -.filter((record) => isApprovalRecordVisibleToClient({ record, client })) |
39 | | -.map((record) => ({ |
40 | | -id: record.id, |
41 | | -request: record.request, |
42 | | -createdAtMs: record.createdAtMs, |
43 | | -expiresAtMs: record.expiresAtMs, |
44 | | -})), |
45 | | -undefined, |
46 | | -); |
| 34 | +respond(true, listVisiblePendingApprovalRequests({ manager, client }), undefined); |
47 | 35 | }, |
48 | 36 | "plugin.approval.request": async ({ params, client, respond, context }) => { |
49 | 37 | if (!validatePluginApprovalRequestParams(params)) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。