mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:30:42 +00:00
refactor: share approval session lookup
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { resolveStorePath } from "../config/sessions/paths.js";
|
||||
import { loadSessionStore } from "../config/sessions/store-load.js";
|
||||
import type { SessionEntry } from "../config/sessions/types.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { normalizeOptionalAccountId } from "../routing/account-id.js";
|
||||
import { parseAgentSessionKey } from "../routing/session-key.js";
|
||||
@@ -8,21 +9,26 @@ import { normalizeMessageChannel } from "../utils/message-channel.js";
|
||||
import type { ExecApprovalRequest } from "./exec-approvals.js";
|
||||
import type { PluginApprovalRequest } from "./plugin-approvals.js";
|
||||
|
||||
type ApprovalRequestLike = ExecApprovalRequest | PluginApprovalRequest;
|
||||
export type ApprovalRequestLike = ExecApprovalRequest | PluginApprovalRequest;
|
||||
|
||||
type ApprovalRequestSessionBinding = {
|
||||
channel?: string;
|
||||
accountId?: string;
|
||||
};
|
||||
|
||||
export type PersistedApprovalRequestSessionEntry = {
|
||||
sessionKey: string;
|
||||
entry: SessionEntry;
|
||||
};
|
||||
|
||||
function normalizeOptionalChannel(value?: string | null): string | undefined {
|
||||
return normalizeMessageChannel(value);
|
||||
}
|
||||
|
||||
function resolvePersistedApprovalRequestSessionBinding(params: {
|
||||
export function resolvePersistedApprovalRequestSessionEntry(params: {
|
||||
cfg: OpenClawConfig;
|
||||
request: ApprovalRequestLike;
|
||||
}): ApprovalRequestSessionBinding | null {
|
||||
}): PersistedApprovalRequestSessionEntry | null {
|
||||
const sessionKey = normalizeOptionalString(params.request.request.sessionKey);
|
||||
if (!sessionKey) {
|
||||
return null;
|
||||
@@ -35,6 +41,18 @@ function resolvePersistedApprovalRequestSessionBinding(params: {
|
||||
if (!entry) {
|
||||
return null;
|
||||
}
|
||||
return { sessionKey, entry };
|
||||
}
|
||||
|
||||
function resolvePersistedApprovalRequestSessionBinding(params: {
|
||||
cfg: OpenClawConfig;
|
||||
request: ApprovalRequestLike;
|
||||
}): ApprovalRequestSessionBinding | null {
|
||||
const persisted = resolvePersistedApprovalRequestSessionEntry(params);
|
||||
if (!persisted) {
|
||||
return null;
|
||||
}
|
||||
const { entry } = persisted;
|
||||
const channel = normalizeOptionalChannel(entry.origin?.provider ?? entry.lastChannel);
|
||||
const accountId = normalizeOptionalAccountId(entry.origin?.accountId ?? entry.lastAccountId);
|
||||
return channel || accountId ? { channel, accountId } : null;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { resolveSessionConversationRef } from "../channels/plugins/session-conversation.js";
|
||||
import { resolveStorePath } from "../config/sessions/paths.js";
|
||||
import { loadSessionStore } from "../config/sessions/store-load.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { parseAgentSessionKey } from "../routing/session-key.js";
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
import { normalizeMessageChannel } from "../utils/message-channel.js";
|
||||
import { doesApprovalRequestMatchChannelAccount } from "./approval-request-account-binding.js";
|
||||
import {
|
||||
doesApprovalRequestMatchChannelAccount,
|
||||
resolvePersistedApprovalRequestSessionEntry,
|
||||
} from "./approval-request-account-binding.js";
|
||||
import type { ExecApprovalRequest } from "./exec-approvals.js";
|
||||
import { resolveSessionDeliveryTarget } from "./outbound/targets.js";
|
||||
import type { PluginApprovalRequest } from "./plugin-approvals.js";
|
||||
@@ -127,17 +127,16 @@ export function resolveExecApprovalSessionTarget(params: {
|
||||
if (!sessionKey) {
|
||||
return null;
|
||||
}
|
||||
const parsed = parseAgentSessionKey(sessionKey);
|
||||
const agentId = parsed?.agentId ?? params.request.request.agentId ?? "main";
|
||||
const storePath = resolveStorePath(params.cfg.session?.store, { agentId });
|
||||
const store = loadSessionStore(storePath);
|
||||
const entry = store[sessionKey];
|
||||
if (!entry) {
|
||||
const persisted = resolvePersistedApprovalRequestSessionEntry({
|
||||
cfg: params.cfg,
|
||||
request: params.request,
|
||||
});
|
||||
if (!persisted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const target = resolveSessionDeliveryTarget({
|
||||
entry,
|
||||
entry: persisted.entry,
|
||||
requestedChannel: "last",
|
||||
turnSourceChannel: normalizeOptionalString(params.turnSourceChannel),
|
||||
turnSourceTo: normalizeOptionalString(params.turnSourceTo),
|
||||
|
||||
Reference in New Issue
Block a user