@fieldwangai/agentflow 0.1.163 → 0.1.165

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -155,8 +155,9 @@ export function marketplaceFlowOriginPath(flowDir) {
155
155
  }
156
156
 
157
157
  export function writeMarketplaceFlowOrigin(flowDir, origin = {}) {
158
+ const kind = safeText(origin.kind, 32) === "project-flow" ? "project-flow" : "flow";
158
159
  const value = {
159
- kind: "flow",
160
+ kind,
160
161
  id: safeText(origin.id),
161
162
  version: safeText(origin.version, 80),
162
163
  installedAt: safeText(origin.installedAt || new Date().toISOString(), 80),
@@ -169,8 +170,8 @@ export function writeMarketplaceFlowOrigin(flowDir, origin = {}) {
169
170
  export function readMarketplaceFlowOrigin(flowDir) {
170
171
  try {
171
172
  const parsed = JSON.parse(fs.readFileSync(marketplaceFlowOriginPath(flowDir), "utf-8"));
172
- if (parsed?.kind !== "flow" || !parsed.id || !parsed.version) return null;
173
- return { kind: "flow", id: String(parsed.id), version: String(parsed.version) };
173
+ if (!["flow", "project-flow"].includes(parsed?.kind) || !parsed.id || !parsed.version) return null;
174
+ return { kind: parsed.kind, id: String(parsed.id), version: String(parsed.version) };
174
175
  } catch {
175
176
  return null;
176
177
  }
@@ -1272,6 +1272,7 @@ function buildAdminUsageDashboard(workspaceRoot) {
1272
1272
  username: String(run.username || run.userId || ""),
1273
1273
  flowId: String(run.flowId || ""),
1274
1274
  flowSource: String(run.flowSource || "user"),
1275
+ archived: run.archived === true,
1275
1276
  runId: String(run.runId || ""),
1276
1277
  at: Number(run.at || 0),
1277
1278
  endedAt: run.endedAt == null ? null : Number(run.endedAt),
@@ -1993,6 +1994,50 @@ function setWorkspaceScheduleEnabled(root, payload = {}, authUser = {}, userCtx
1993
1994
  return { success: true, workspaceSchedules };
1994
1995
  }
1995
1996
 
1997
+ function schedulesForRequest(root, authUser = {}, userCtx = {}) {
1998
+ if (!authUser?.isAdmin) {
1999
+ return {
2000
+ adminView: false,
2001
+ users: [],
2002
+ schedules: listWorkspaceScheduleStatuses(root, userCtx),
2003
+ };
2004
+ }
2005
+ const users = listAuthUsers();
2006
+ const usernames = new Map(users.map((user) => [user.userId, user.username || user.userId]));
2007
+ const byIdentity = new Map();
2008
+ for (const user of users) {
2009
+ const rows = listWorkspaceScheduleStatuses(root, { ...userCtx, userId: user.userId });
2010
+ for (const row of rows) {
2011
+ const ownerUserId = String(row.ownerUserId || row.userId || user.userId);
2012
+ const key = String(row.key || `${ownerUserId}:${row.flowSource || "user"}:${row.flowId || ""}:${row.scheduleNodeId || ""}`);
2013
+ const identity = String(row.flowSource || "user") === "workspace"
2014
+ ? `workspace:${row.workspaceId || row.flowId || ""}:${row.scheduleNodeId || ""}`
2015
+ : key;
2016
+ const existing = byIdentity.get(identity);
2017
+ if (existing && (existing.registered || !row.registered)) continue;
2018
+ byIdentity.set(identity, {
2019
+ ...row,
2020
+ ownerUserId,
2021
+ ownerUsername: usernames.get(ownerUserId) || row.ownerUsername || ownerUserId,
2022
+ });
2023
+ }
2024
+ }
2025
+ const schedules = [...byIdentity.values()].sort((a, b) => {
2026
+ const ea = a.enabled ? 0 : 1;
2027
+ const eb = b.enabled ? 0 : 1;
2028
+ return ea - eb
2029
+ || String(a.nextRunAt || "").localeCompare(String(b.nextRunAt || ""))
2030
+ || String(a.ownerUsername || a.ownerUserId || "").localeCompare(String(b.ownerUsername || b.ownerUserId || ""))
2031
+ || String(a.flowId || "").localeCompare(String(b.flowId || ""));
2032
+ });
2033
+ const ownerIds = new Set(schedules.map((schedule) => String(schedule.ownerUserId || "")).filter(Boolean));
2034
+ return {
2035
+ adminView: true,
2036
+ users: users.filter((user) => ownerIds.has(user.userId)),
2037
+ schedules,
2038
+ };
2039
+ }
2040
+
1996
2041
  function pollWorkspaceSchedules(root) {
1997
2042
  const now = Date.now();
1998
2043
  const registry = readWorkspaceScheduleRegistry();
@@ -4578,14 +4623,7 @@ finishedAt: "${new Date().toISOString()}"
4578
4623
  try {
4579
4624
  // 旧 Pipeline schedule 随 Start/End 执行一并下线:它们只会驱动已废弃的
4580
4625
  // `agentflow apply`,列出来只会给用户永远不会触发的条目。
4581
- const workspaceSchedules = listWorkspaceScheduleStatuses(root, userCtx);
4582
- json(res, 200, {
4583
- schedules: [...workspaceSchedules].sort((a, b) => {
4584
- const ea = a.enabled ? 0 : 1;
4585
- const eb = b.enabled ? 0 : 1;
4586
- return ea - eb || String(a.nextRunAt || "").localeCompare(String(b.nextRunAt || "")) || String(a.flowId || "").localeCompare(String(b.flowId || ""));
4587
- }),
4588
- });
4626
+ json(res, 200, schedulesForRequest(root, authUser, userCtx));
4589
4627
  } catch (e) {
4590
4628
  json(res, 500, { error: (e && e.message) || String(e) });
4591
4629
  }
@@ -4603,7 +4641,23 @@ finishedAt: "${new Date().toISOString()}"
4603
4641
  const kind = String(payload.kind || "").trim();
4604
4642
  if (kind === "workspace") {
4605
4643
  try {
4606
- const result = setWorkspaceScheduleEnabled(root, payload, authUser, userCtx);
4644
+ const requestedOwnerId = String(payload.ownerUserId || userCtx.userId || "").trim();
4645
+ if (requestedOwnerId !== String(userCtx.userId || "") && !authUser?.isAdmin) {
4646
+ json(res, 403, { error: "Admin permission required to manage another user's schedule" });
4647
+ return;
4648
+ }
4649
+ const targetRecord = readAuthUsers()[requestedOwnerId];
4650
+ if (!targetRecord) {
4651
+ json(res, 404, { error: "Schedule owner not found" });
4652
+ return;
4653
+ }
4654
+ const targetAuthUser = {
4655
+ userId: requestedOwnerId,
4656
+ username: String(targetRecord.username || requestedOwnerId),
4657
+ isAdmin: Boolean(targetRecord.isAdmin),
4658
+ };
4659
+ const targetUserCtx = { ...userCtx, userId: requestedOwnerId };
4660
+ const result = setWorkspaceScheduleEnabled(root, payload, targetAuthUser, targetUserCtx);
4607
4661
  if (!result.success) {
4608
4662
  json(res, 400, { error: result.error || "Could not update workspace schedule" });
4609
4663
  return;