mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-13 02:01:16 +00:00
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
|
import {
|
|
findLatestTaskFlowForOwnerKey,
|
|
getTaskFlowById,
|
|
listTaskFlowsForOwnerKey,
|
|
} from "./task-flow-registry.js";
|
|
import type { TaskFlowRecord } from "./task-flow-registry.types.js";
|
|
|
|
export function getTaskFlowByIdForOwner(params: {
|
|
flowId: string;
|
|
callerOwnerKey: string;
|
|
}): TaskFlowRecord | undefined {
|
|
const flow = getTaskFlowById(params.flowId);
|
|
return flow &&
|
|
normalizeOptionalString(flow.ownerKey) === normalizeOptionalString(params.callerOwnerKey)
|
|
? flow
|
|
: undefined;
|
|
}
|
|
|
|
export function listTaskFlowsForOwner(params: { callerOwnerKey: string }): TaskFlowRecord[] {
|
|
const ownerKey = normalizeOptionalString(params.callerOwnerKey);
|
|
return ownerKey ? listTaskFlowsForOwnerKey(ownerKey) : [];
|
|
}
|
|
|
|
export function findLatestTaskFlowForOwner(params: {
|
|
callerOwnerKey: string;
|
|
}): TaskFlowRecord | undefined {
|
|
const ownerKey = normalizeOptionalString(params.callerOwnerKey);
|
|
return ownerKey ? findLatestTaskFlowForOwnerKey(ownerKey) : undefined;
|
|
}
|
|
|
|
export function resolveTaskFlowForLookupTokenForOwner(params: {
|
|
token: string;
|
|
callerOwnerKey: string;
|
|
}): TaskFlowRecord | undefined {
|
|
const direct = getTaskFlowByIdForOwner({
|
|
flowId: params.token,
|
|
callerOwnerKey: params.callerOwnerKey,
|
|
});
|
|
if (direct) {
|
|
return direct;
|
|
}
|
|
const normalizedToken = normalizeOptionalString(params.token);
|
|
const normalizedCallerOwnerKey = normalizeOptionalString(params.callerOwnerKey);
|
|
if (!normalizedToken || normalizedToken !== normalizedCallerOwnerKey) {
|
|
return undefined;
|
|
}
|
|
return findLatestTaskFlowForOwner({ callerOwnerKey: normalizedCallerOwnerKey });
|
|
}
|