@fieldwangai/agentflow 0.1.94 → 0.1.95

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.
@@ -7073,6 +7073,11 @@ function prdWorkflowEventsPath(scopedRoot, tapdId) {
7073
7073
  return path.join(rootDir, ".workspace", "prd-flow", "workflow-state", `${prdWorkflowSafeStateId(tapdId)}.events.json`);
7074
7074
  }
7075
7075
 
7076
+ function prdWorkflowAuditPath(scopedRoot, tapdId) {
7077
+ const rootDir = scopedRoot || process.cwd();
7078
+ return path.join(rootDir, ".workspace", "prd-flow", "workflow-state", `${prdWorkflowSafeStateId(tapdId)}.audit.jsonl`);
7079
+ }
7080
+
7076
7081
  function prdWorkflowReviewDir(scopedRoot, tapdId) {
7077
7082
  const rootDir = path.resolve(scopedRoot || process.cwd());
7078
7083
  return path.join(rootDir, ".workspace", "prd-flow", "reviews", prdWorkflowSafeStateId(tapdId));
@@ -7143,13 +7148,48 @@ function prdWorkflowReviewSplitFrontmatter(markdown) {
7143
7148
 
7144
7149
  function prdWorkflowReviewRenderFrontmatter(frontmatter) {
7145
7150
  if (!String(frontmatter || "").trim()) return "";
7146
- const rows = String(frontmatter || "").split(/\r?\n/)
7147
- .map((line) => {
7148
- const match = line.match(/^([^:]+):\s*(.*)$/);
7149
- if (!match) return `<tr><td colspan="2">${prdWorkflowReviewInlineMarkdown(line)}</td></tr>`;
7150
- return `<tr><th>${htmlEscapeAttribute(match[1].trim())}</th><td>${prdWorkflowReviewInlineMarkdown(match[2].trim())}</td></tr>`;
7151
- })
7152
- .join("");
7151
+ const rows = [];
7152
+ const lines = String(frontmatter || "").split(/\r?\n/);
7153
+ let current = null;
7154
+ const flush = () => {
7155
+ if (!current) return;
7156
+ let valueHtml = "";
7157
+ if (current.items.length) {
7158
+ valueHtml = `<ul class="frontmatter-list">${current.items.map((item) => `<li>${prdWorkflowReviewInlineMarkdown(item)}</li>`).join("")}</ul>`;
7159
+ } else {
7160
+ valueHtml = prdWorkflowReviewInlineMarkdown(current.value);
7161
+ }
7162
+ rows.push(`<tr><th>${htmlEscapeAttribute(current.key)}</th><td>${valueHtml}</td></tr>`);
7163
+ current = null;
7164
+ };
7165
+ for (const rawLine of lines) {
7166
+ const line = String(rawLine || "");
7167
+ const keyValue = line.match(/^([^:\s][^:]*):\s*(.*)$/);
7168
+ if (keyValue) {
7169
+ flush();
7170
+ const key = keyValue[1].trim();
7171
+ const value = keyValue[2].trim();
7172
+ const inlineList = value.match(/^\[(.*)\]$/);
7173
+ current = {
7174
+ key,
7175
+ value: inlineList ? "" : value,
7176
+ items: inlineList
7177
+ ? inlineList[1].split(",").map((item) => item.trim()).filter(Boolean)
7178
+ : [],
7179
+ };
7180
+ continue;
7181
+ }
7182
+ const listItem = line.match(/^\s*-\s+(.+)$/);
7183
+ if (listItem && current) {
7184
+ current.items.push(listItem[1].trim());
7185
+ continue;
7186
+ }
7187
+ if (line.trim()) {
7188
+ flush();
7189
+ rows.push(`<tr><td colspan="2">${prdWorkflowReviewInlineMarkdown(line.trim())}</td></tr>`);
7190
+ }
7191
+ }
7192
+ flush();
7153
7193
  return `<details class="frontmatter" open><summary>文档元数据</summary><table>${rows}</table></details>`;
7154
7194
  }
7155
7195
 
@@ -7260,6 +7300,13 @@ function prdWorkflowReviewHtml(title, markdown, meta = {}) {
7260
7300
  meta.issueKey ? `issue ${meta.issueKey}` : "",
7261
7301
  meta.createdAt || "",
7262
7302
  ].filter(Boolean).join(" · "));
7303
+ const durability = String(meta.durability || "").trim().toLowerCase();
7304
+ const lifecycle = [
7305
+ durability === "temporary" ? "Temporary review link" : durability === "durable" ? "Durable preview" : "",
7306
+ meta.expiresAt ? `Expires ${meta.expiresAt}` : "",
7307
+ meta.persistence ? `persistence ${meta.persistence}` : "",
7308
+ ].filter(Boolean).join(" · ");
7309
+ const escapedLifecycle = htmlEscapeAttribute(lifecycle);
7263
7310
  const renderedMarkdown = prdWorkflowReviewMarkdownToHtml(markdown || "");
7264
7311
  const rawHref = htmlEscapeAttribute(meta.rawHref || "?raw=1");
7265
7312
  return `<!doctype html>
@@ -7321,6 +7368,7 @@ function prdWorkflowReviewHtml(title, markdown, meta = {}) {
7321
7368
  .toolbar { flex: 0 0 auto; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
7322
7369
  .raw, .theme-toggle { border: 1px solid rgba(124,58,237,.34); border-radius: 999px; color: var(--button-text); background: var(--button); padding: 9px 14px; text-decoration: none; font-size: 13px; font-weight: 800; line-height: 1.2; }
7323
7370
  .theme-toggle { cursor: pointer; font-family: inherit; }
7371
+ .lifecycle { margin-top: 10px; display: inline-flex; max-width: 100%; border: 1px solid rgba(124,58,237,.30); border-radius: 999px; background: rgba(124,58,237,.12); color: var(--button-text); padding: 6px 10px; font-size: 12px; font-weight: 800; line-height: 1.35; overflow-wrap: anywhere; }
7324
7372
  article { min-width: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); box-shadow: 0 28px 80px var(--shadow); padding: clamp(20px, 4vw, 34px); }
7325
7373
  article > *:first-child { margin-top: 0; }
7326
7374
  article > *:last-child { margin-bottom: 0; }
@@ -7346,6 +7394,7 @@ function prdWorkflowReviewHtml(title, markdown, meta = {}) {
7346
7394
  .frontmatter summary { cursor: pointer; color: var(--body); font-weight: 800; }
7347
7395
  .frontmatter table { min-width: 0; margin-top: .7rem; }
7348
7396
  .frontmatter th { width: min(34%, 12rem); background: var(--panel-soft); color: var(--body); }
7397
+ .frontmatter-list { margin: 0; padding-left: 1.1rem; }
7349
7398
  @media (max-width: 720px) { main { padding: 28px 14px 48px; } header { display: block; } .toolbar { justify-content: flex-start; margin-top: 14px; } article { padding: 18px; } th, td { padding: .58rem .65rem; } }
7350
7399
  </style>
7351
7400
  </head>
@@ -7355,6 +7404,7 @@ function prdWorkflowReviewHtml(title, markdown, meta = {}) {
7355
7404
  <div>
7356
7405
  <h1>${escapedTitle}</h1>
7357
7406
  ${escapedMeta ? `<p class="meta">${escapedMeta}</p>` : ""}
7407
+ ${escapedLifecycle ? `<p class="lifecycle">${escapedLifecycle}</p>` : ""}
7358
7408
  </div>
7359
7409
  <div class="toolbar">
7360
7410
  <button class="theme-toggle" type="button" data-theme-toggle>明亮模式</button>
@@ -7423,6 +7473,19 @@ function prdWorkflowCreateReview(scopedRoot, tapdId, payload = {}, urlBase = "")
7423
7473
  fs.writeFileSync(paths.markdownPath, content.trimEnd() + "\n", "utf-8");
7424
7474
  fs.writeFileSync(paths.metaPath, JSON.stringify(meta, null, 2) + "\n", "utf-8");
7425
7475
  prdWorkflowPruneReviews(scopedRoot, tapdId);
7476
+ prdWorkflowAppendAudit(scopedRoot, tapdId, {
7477
+ type: "review-created",
7478
+ reviewId: paths.id,
7479
+ title,
7480
+ stage: meta.stage,
7481
+ action: meta.action,
7482
+ issueKey: meta.issueKey,
7483
+ durability,
7484
+ persistence: "runtime",
7485
+ sourceKind: String(meta.source?.kind || ""),
7486
+ expiresAt,
7487
+ contentBytes: Buffer.byteLength(content, "utf-8"),
7488
+ });
7426
7489
  const url = `${String(urlBase || "").replace(/\/+$/, "")}/api/prd-workflow/review/${encodeURIComponent(prdWorkflowSafeStateId(tapdId))}/${encodeURIComponent(paths.id)}`;
7427
7490
  return { ...meta, url, markdownPath: paths.markdownPath };
7428
7491
  }
@@ -7472,6 +7535,19 @@ function prdWorkflowWriteJsonFile(filePath, data) {
7472
7535
  return data;
7473
7536
  }
7474
7537
 
7538
+ function prdWorkflowAppendAudit(scopedRoot, tapdId, event = {}) {
7539
+ try {
7540
+ const p = prdWorkflowAuditPath(scopedRoot, tapdId);
7541
+ fs.mkdirSync(path.dirname(p), { recursive: true });
7542
+ const entry = {
7543
+ at: new Date().toISOString(),
7544
+ tapdId: String(tapdId || ""),
7545
+ ...event,
7546
+ };
7547
+ fs.appendFileSync(p, JSON.stringify(entry) + "\n", "utf-8");
7548
+ } catch (_) {}
7549
+ }
7550
+
7475
7551
  function prdWorkflowReadProjectState(scopedRoot, tapdId) {
7476
7552
  return prdWorkflowReadJsonFile(prdWorkflowProjectPath(scopedRoot, tapdId), {
7477
7553
  version: 1,
@@ -7712,12 +7788,25 @@ function prdWorkflowMergedClientIssues(clientRows = []) {
7712
7788
  return out;
7713
7789
  }
7714
7790
 
7791
+ function prdWorkflowArrayCount(value) {
7792
+ return Array.isArray(value) ? value.length : 0;
7793
+ }
7794
+
7795
+ function prdWorkflowSnapshotActionCount(snapshot = {}) {
7796
+ return prdWorkflowArrayCount(snapshot?.actions) +
7797
+ prdWorkflowArrayCount(snapshot?.workflowActions) +
7798
+ prdWorkflowArrayCount(snapshot?.workflow_actions) +
7799
+ prdWorkflowArrayCount(snapshot?.timeline) +
7800
+ prdWorkflowArrayCount(snapshot?.history);
7801
+ }
7802
+
7715
7803
  function prdWorkflowMaterializeSnapshot(root, scopedRoot, tapdId, userCtx = {}, opts = {}) {
7716
7804
  const flowSource = String(opts.flowSource || "user").trim() || "user";
7717
7805
  const flowId = String(opts.flowId || "").trim();
7718
7806
  const project = prdWorkflowReadProjectStateWithFallback(root, scopedRoot, tapdId);
7719
7807
  const legacy = prdWorkflowReadCachedSnapshotWithFallback(root, scopedRoot, tapdId);
7720
7808
  const latestClient = prdWorkflowLatestClientSnapshot(root, scopedRoot, tapdId);
7809
+ const baseSource = project?.snapshot ? "project" : latestClient ? "client-observations" : legacy?.snapshot ? "legacy-cache" : "empty";
7721
7810
  const base = (
7722
7811
  project?.snapshot ||
7723
7812
  latestClient ||
@@ -7743,6 +7832,45 @@ function prdWorkflowMaterializeSnapshot(root, scopedRoot, tapdId, userCtx = {},
7743
7832
  }));
7744
7833
  const clientRows = prdWorkflowClientObservationRows(root, scopedRoot, tapdId);
7745
7834
  const clientIssues = prdWorkflowMergedClientIssues(clientRows);
7835
+ const runtimeState = prdWorkflowReadRuntimeEvents(scopedRoot, tapdId);
7836
+ const projectionAudit = [
7837
+ {
7838
+ step: "select-base",
7839
+ source: baseSource,
7840
+ reason: project?.snapshot
7841
+ ? "project materialized snapshot is available"
7842
+ : latestClient
7843
+ ? "no project snapshot; latest client current observation is used as display base"
7844
+ : legacy?.snapshot
7845
+ ? "no project/client snapshot; legacy projection cache is used"
7846
+ : "no stored workflow projection exists",
7847
+ projectSnapshot: Boolean(project?.snapshot),
7848
+ latestClientSnapshot: Boolean(latestClient),
7849
+ legacySnapshot: Boolean(legacy?.snapshot),
7850
+ clientObservationCount: clientRows.length,
7851
+ runtimeEventCount: runtimeState.events.length,
7852
+ baseActionCount: prdWorkflowSnapshotActionCount(base),
7853
+ latestClientRevision: String(latestClient?.revision || ""),
7854
+ projectRevision: String(project?.snapshot?.revision || ""),
7855
+ },
7856
+ {
7857
+ step: "merge-client-issues",
7858
+ source: "clients",
7859
+ applied: !project?.snapshot && clientIssues.length > 0,
7860
+ issueCount: clientIssues.length,
7861
+ reason: project?.snapshot
7862
+ ? "project snapshot owns issue projection"
7863
+ : clientIssues.length
7864
+ ? "merged issue views from client observations"
7865
+ : "no client issue projection available",
7866
+ },
7867
+ {
7868
+ step: "merge-runtime-events",
7869
+ source: "runtime-events",
7870
+ eventCount: runtimeState.events.length,
7871
+ reason: "runtime events are merged after base selection and must not replace durable facts",
7872
+ },
7873
+ ];
7746
7874
  const materialized = prdWorkflowMergeRuntimeEvents(scopedRoot, tapdId, {
7747
7875
  ...base,
7748
7876
  issues: project?.snapshot ? base.issues : clientIssues.length ? clientIssues : base.issues,
@@ -7758,6 +7886,32 @@ function prdWorkflowMaterializeSnapshot(root, scopedRoot, tapdId, userCtx = {},
7758
7886
  clientsUpdatedAt: prdWorkflowReadClientStateWithFallback(root, scopedRoot, tapdId).updatedAt || "",
7759
7887
  checkedAt: new Date().toISOString(),
7760
7888
  },
7889
+ projectionAudit,
7890
+ });
7891
+ materialized.projectionAudit = [
7892
+ ...projectionAudit,
7893
+ {
7894
+ step: "result",
7895
+ source: "materialized",
7896
+ phase: String(materialized.phase || ""),
7897
+ pointer: String(materialized.pointer || ""),
7898
+ actionCount: prdWorkflowSnapshotActionCount(materialized) + prdWorkflowArrayCount(materialized.runtimeEvents) + prdWorkflowArrayCount(materialized.runtime_events),
7899
+ revision: String(materialized.revision || ""),
7900
+ },
7901
+ ];
7902
+ prdWorkflowAppendAudit(scopedRoot, tapdId, {
7903
+ type: "projection-materialized",
7904
+ flowSource,
7905
+ flowId,
7906
+ baseSource,
7907
+ projectSnapshot: Boolean(project?.snapshot),
7908
+ latestClientSnapshot: Boolean(latestClient),
7909
+ legacySnapshot: Boolean(legacy?.snapshot),
7910
+ clientObservationCount: clientRows.length,
7911
+ runtimeEventCount: runtimeState.events.length,
7912
+ baseActionCount: prdWorkflowSnapshotActionCount(base),
7913
+ resultActionCount: prdWorkflowSnapshotActionCount(materialized) + prdWorkflowArrayCount(materialized.runtimeEvents) + prdWorkflowArrayCount(materialized.runtime_events),
7914
+ revision: String(materialized.revision || ""),
7761
7915
  });
7762
7916
  if (!project?.snapshot && latestClient) {
7763
7917
  materialized.optionalGaps = [
@@ -8019,13 +8173,15 @@ function prdWorkflowAppendRuntimeEvent(scopedRoot, tapdId, event = {}) {
8019
8173
  if (String(item?.idempotencyKey || "").trim() === entryIdem) return true;
8020
8174
  return Array.isArray(item?.idempotencyHistory) && item.idempotencyHistory.includes(entryIdem);
8021
8175
  });
8176
+ const updatedExisting = index >= 0;
8177
+ let artifactConflict = false;
8022
8178
  const events = [...current.events];
8023
8179
  if (index >= 0) {
8024
8180
  const prevArtifact = prdWorkflowRuntimeEventArtifactSignature(events[index]);
8025
8181
  const nextArtifact = prdWorkflowRuntimeEventArtifactSignature(entry);
8026
- const artifactConflict = prevArtifact && nextArtifact && prevArtifact !== nextArtifact &&
8182
+ artifactConflict = Boolean(prevArtifact && nextArtifact && prevArtifact !== nextArtifact &&
8027
8183
  prdWorkflowRuntimeEventShouldConflictOnArtifact(events[index]) &&
8028
- prdWorkflowRuntimeEventShouldConflictOnArtifact(entry);
8184
+ prdWorkflowRuntimeEventShouldConflictOnArtifact(entry));
8029
8185
  const idempotencyHistory = [
8030
8186
  ...(events[index].idempotencyKey ? [events[index].idempotencyKey] : []),
8031
8187
  ...(entry.idempotencyKey ? [entry.idempotencyKey] : []),
@@ -8060,6 +8216,26 @@ function prdWorkflowAppendRuntimeEvent(scopedRoot, tapdId, event = {}) {
8060
8216
  events.push(entry);
8061
8217
  }
8062
8218
  prdWorkflowWriteRuntimeEvents(scopedRoot, tapdId, events);
8219
+ prdWorkflowAppendAudit(scopedRoot, tapdId, {
8220
+ type: "runtime-event-stored",
8221
+ eventId: entry.id,
8222
+ eventType: entry.type,
8223
+ source: entry.source,
8224
+ scope: entry.scope || "",
8225
+ issueKey: entry.issueKey || entry.issue_key || entry.issue || "",
8226
+ platform: entry.platform || "",
8227
+ stage: entry.stage || entry.stageKey || entry.stage_key || "",
8228
+ action: entry.action || entry.actionId || entry.action_id || "",
8229
+ status: entry.status || "",
8230
+ truth: entry.truth || "",
8231
+ authority: entry.authority || "",
8232
+ persistence: entry.persistence || "",
8233
+ idempotencyKey: entry.idempotencyKey || "",
8234
+ updatedExisting,
8235
+ artifactConflict,
8236
+ eventCount: events.length,
8237
+ note: "runtime event stored as append-only workflow event; projection may merge it into the visible timeline",
8238
+ });
8063
8239
  return entry;
8064
8240
  } catch {
8065
8241
  return null;
@@ -9515,6 +9691,23 @@ export function startUiServer({
9515
9691
  };
9516
9692
  const storedObservationSnapshot = prdWorkflowStoredObservationSnapshot(normalizedSnapshot, reportSource);
9517
9693
  prdWorkflowWriteClientObservation(scopedRoot, tapdId, reportMeta, storedObservationSnapshot);
9694
+ prdWorkflowAppendAudit(scopedRoot, tapdId, {
9695
+ type: "client-observation-stored",
9696
+ flowSource,
9697
+ flowId,
9698
+ clientId: reportMeta.clientId,
9699
+ userId: reportMeta.userId,
9700
+ observedAt: reportMeta.observedAt,
9701
+ reportedAt: reportMeta.reportedAt,
9702
+ phase: String(storedObservationSnapshot?.phase || ""),
9703
+ pointer: String(storedObservationSnapshot?.pointer || ""),
9704
+ revision: String(storedObservationSnapshot?.revision || ""),
9705
+ actionCount: prdWorkflowSnapshotActionCount(storedObservationSnapshot),
9706
+ truth: "observation",
9707
+ authority: "client",
9708
+ persistence: "runtime",
9709
+ note: "ordinary current snapshot stored as client observation; it must not overwrite project state",
9710
+ });
9518
9711
 
9519
9712
  const projectFactSource = reportMeta.scope === "project"
9520
9713
  ? prdWorkflowProjectFactSource(payload, rawSnapshot)
@@ -9573,6 +9766,20 @@ export function startUiServer({
9573
9766
  observedAt: reportMeta.observedAt,
9574
9767
  },
9575
9768
  });
9769
+ prdWorkflowAppendAudit(scopedRoot, tapdId, {
9770
+ type: "project-fact-stored",
9771
+ flowSource,
9772
+ flowId,
9773
+ clientId: reportMeta.clientId,
9774
+ observedAt: reportMeta.observedAt,
9775
+ phase: String(projectFactSnapshot?.phase || ""),
9776
+ pointer: String(projectFactSnapshot?.pointer || ""),
9777
+ revision: String(projectFactSnapshot?.revision || ""),
9778
+ actionCount: prdWorkflowSnapshotActionCount(projectFactSnapshot),
9779
+ truth: projectFactSource.truth,
9780
+ authority: projectFactSource.authority,
9781
+ persistence: projectFactSource.persistence,
9782
+ });
9576
9783
  }
9577
9784
  const materialized = prdWorkflowMaterializeSnapshot(root, scopedRoot, tapdId, userCtx, { flowSource, flowId });
9578
9785
  const withDiagnostic = prdWorkflowWithAgentflowTokenDiagnostic(materialized, getSessionTokenFromRequest(req) || "");
@@ -179,7 +179,7 @@ ${n("project:fileTruncated")}`:""]})]}):o.jsx("p",{children:n("project:noNodeFil
179
179
  <\/script>
180
180
  </body>
181
181
  </html>`}const AI=new Set(["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"]),g7=["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"];function y7(e,t){const n=e.slice(0,t),r=n.lastIndexOf("${");if(r<0)return null;const s=n.slice(r+2);return s.includes("}")?null:{atIndex:r,query:s}}function x7(e){const t=/\$\{([^}]*)\}/g,n=[];let r;for(;(r=t.exec(e))!==null;)n.push({start:r.index,end:r.index+r[0].length,key:r[1]});return n}function Ij(e){const t=new Set;if(!Array.isArray(e))return t;for(const n of e){const r=(n==null?void 0:n.name)!=null?String(n.name).trim():"";r&&t.add(r)}return t}function PI(e,{inputNames:t,outputNames:n}){const r=e.trim();if(!r)return!1;if(r.startsWith("input.")){const s=r.slice(6).trim();return s!==""&&t.has(s)}if(r.startsWith("output.")){const s=r.slice(7).trim();return s!==""&&n.has(s)}if(AI.has(r)||t.has(r)||n.has(r))return!0;if(!r.includes(".")){const s=`${r}.md`;if(t.has(s)||n.has(s))return!0}return!1}function II(e){return{inputNames:Ij(e==null?void 0:e.inputs),outputNames:Ij(e==null?void 0:e.outputs)}}function w7(e,t,n){const r=II(t),s=x7(e),i=[];for(const a of s)if(!PI(a.key,r)){const l=a.key.trim()===""?n("flow:placeholder.empty"):a.key.trim();i.push({start:a.start,end:a.end,message:n("flow:placeholder.invalidPlaceholder",{hint:l})})}return i}function b7(e,t){const n=II(t),r=/\$\{([^}]*)\}/g,s=[];let i=0,a;for(;(a=r.exec(e))!==null;){a.index>i&&s.push({kind:"plain",text:e.slice(i,a.index)});const l=a[0],c=PI(a[1],n);s.push({kind:c?"ph-valid":"ph-invalid",text:l}),i=a.index+l.length}return i<e.length&&s.push({kind:"plain",text:e.slice(i)}),s}function k7(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function v7(e){return e.map(t=>{const n=k7(t.text);return t.kind==="ph-invalid"?`<span class="af-body-ph-invalid">${n}</span>`:t.kind==="ph-valid"?`<span class="af-body-ph-valid">${n}</span>`:n}).join("")}function S7(e,t){const n=[];for(const r of(e==null?void 0:e.inputs)??[]){const s=(r==null?void 0:r.name)!=null?String(r.name).trim():"";if(!s)continue;const i=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"input",insert:`input.${s}`,label:s,subtitle:i?t("flow:placeholder.inputSubtitle",{type:i}):t("flow:placeholder.inputSubtitleNoType")})}for(const r of(e==null?void 0:e.outputs)??[]){const s=(r==null?void 0:r.name)!=null?String(r.name).trim():"";if(!s)continue;const i=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"output",insert:`output.${s}`,label:s,subtitle:i?t("flow:placeholder.outputSubtitle",{type:i}):t("flow:placeholder.outputSubtitleNoType")})}for(const r of g7)AI.has(r)&&n.push({section:"runtime",insert:r,label:r,subtitle:t("flow:placeholder.runtimeConst")});return n}function N7(e,t){const n=t.toLowerCase();return n?e.filter(r=>[r.insert,r.label,r.subtitle??""].map(i=>String(i).toLowerCase()).some(i=>i.includes(n))):e}function j7(e,t){if(!e||t<0)return null;const n=Math.min(t,e.value.length),r=getComputedStyle(e),s=document.createElement("div");s.setAttribute("aria-hidden","true"),s.style.visibility="hidden",s.style.position="fixed",s.style.top="0",s.style.left="-99999px",s.style.whiteSpace="pre-wrap",s.style.wordWrap="break-word",s.style.overflow="hidden";const i=e.clientWidth;if(i<=0)return null;s.style.width=`${i}px`,s.style.font=r.font,s.style.lineHeight=r.lineHeight,s.style.padding=r.padding,s.style.border=r.border,s.style.boxSizing=r.boxSizing,s.style.letterSpacing=r.letterSpacing,s.style.textIndent=r.textIndent,s.style.tabSize=r.tabSize||"8",s.textContent=e.value.slice(0,n);const a=document.createElement("span");a.textContent="​",s.appendChild(a),document.body.appendChild(s);const l=a.getBoundingClientRect(),c=parseFloat(r.lineHeight),u=Number.isFinite(c)&&c>0?c:l.height||16;return document.body.removeChild(s),{top:l.top,left:l.left,bottom:l.bottom,height:u}}function Hf({value:e,onChange:t,disabled:n,placeholder:r,rows:s=8,textareaClassName:i,ioSlots:a,variant:l="drawer",images:c,onImagesChange:u}){const{t:p}=Pr(),d=m.useId(),f=m.useRef(null),h=m.useRef(null),[g,k]=m.useState(0),[w,y]=m.useState(0),[v,x]=m.useState(null),j=m.useMemo(()=>Gi(c),[c]),N=m.useMemo(()=>w7(e,a,p),[e,a,p]),C=N.length>0,E=m.useMemo(()=>b7(e,a),[e,a]),A=m.useMemo(()=>v7(E),[E]),O=m.useMemo(()=>n?null:y7(e,g),[e,g,n]),H=m.useMemo(()=>{if(!O)return[];const B=S7(a,p);return N7(B,O.query)},[O,a,p]);m.useEffect(()=>{y(B=>{const M=Math.max(0,H.length-1);return Math.min(Math.max(0,B),M)})},[H.length]);const F=m.useCallback(()=>{const B=f.current;if(!B||!O||H.length===0){x(null);return}const M=j7(B,g);if(!M){x(null);return}const I=4,W=44,_=13.5*16,q=Math.min(H.length*W+8,_);let z=M.bottom+I;z+q>window.innerHeight-8&&(z=Math.max(8,M.top-q-I));const L=288;let te=M.left;te=Math.max(8,Math.min(te,window.innerWidth-L-8)),x({top:z,left:te})},[O,H.length,g]);m.useLayoutEffect(()=>{if(!O||H.length===0){x(null);return}const B=requestAnimationFrame(()=>F());return()=>cancelAnimationFrame(B)},[O,H.length,g,e,F]),m.useEffect(()=>{if(!O||H.length===0)return;const B=()=>F();return window.addEventListener("scroll",B,!0),window.addEventListener("resize",B),()=>{window.removeEventListener("scroll",B,!0),window.removeEventListener("resize",B)}},[O,H.length,F]);const D=m.useCallback(B=>{if(!O)return;const{atIndex:M}=O,I=e.slice(0,M)+"${"+B+"}"+e.slice(g);t(I);const W=M+B.length+3;queueMicrotask(()=>{const _=f.current;_&&(_.focus(),_.setSelectionRange(W,W)),k(W)})},[O,e,g,t]),$=m.useCallback(()=>{const B=f.current,M=h.current;!B||!M||(M.scrollTop=B.scrollTop,M.scrollLeft=B.scrollLeft,O&&H.length>0&&queueMicrotask(()=>F()))},[O,H.length,F]),T=m.useCallback(B=>{if(!n&&O&&H.length>0&&(B.key==="ArrowDown"||B.key==="ArrowUp"||B.key==="Enter")){if(B.key==="ArrowDown")B.preventDefault(),y(M=>(M+1)%H.length);else if(B.key==="ArrowUp")B.preventDefault(),y(M=>(M-1+H.length)%H.length);else if(B.key==="Enter"&&!B.shiftKey){B.preventDefault();const M=H[w];M&&D(M.insert)}}},[n,O,H,w,D]),K=m.useCallback(async B=>{if(n||typeof u!="function")return!1;const M=await CI({files:B,body:e,images:j});return M?(t(M.body),u(M.images),queueMicrotask(()=>{const I=f.current;if(!I)return;I.focus();const W=M.body.length;I.setSelectionRange(W,W),k(W)}),!0):!1},[n,j,t,u,e]);return o.jsxs("div",{className:"af-body-prompt-editor"+(l==="expand"?" af-body-prompt-editor--expand":""),children:[j.length>0?o.jsx("div",{className:"af-body-image-list","aria-label":"image attachments",children:j.map((B,M)=>o.jsxs("span",{className:"af-body-image-chip",title:B.name,children:[o.jsx("img",{src:B.dataUrl,alt:""}),o.jsxs("span",{children:["[",B.label||`image ${M+1}`,"]"]})]},B.id||M))}):null,o.jsxs("div",{className:"af-body-prompt-stack",children:[o.jsx("pre",{ref:h,className:"af-body-prompt-backdrop "+i,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:A+`
182
- `}}),o.jsx("textarea",{ref:f,className:"af-body-prompt-textarea "+i,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":C,"aria-describedby":C?d:void 0,onChange:B=>{t(B.target.value),k(B.target.selectionStart??B.target.value.length)},onSelect:B=>{const M=B.target;M instanceof HTMLTextAreaElement&&k(M.selectionStart??0)},onClick:B=>{const M=B.target;M instanceof HTMLTextAreaElement&&k(M.selectionStart??0)},onKeyUp:B=>{const M=B.target;M instanceof HTMLTextAreaElement&&k(M.selectionStart??M.value.length)},onKeyDown:T,onPaste:B=>{const M=jI(B);M.length!==0&&(B.preventDefault(),K(M).catch(()=>{}))},onDragOver:B=>{ju(B).length>0&&B.preventDefault()},onDrop:B=>{const M=ju(B);M.length!==0&&(B.preventDefault(),K(M).catch(()=>{}))},onScroll:$})]}),O&&H.length>0&&v?Cr.createPortal(o.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":p("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:v.top,left:v.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:H.map((B,M)=>o.jsx("li",{role:"option","aria-selected":M===w,children:o.jsxs("button",{type:"button",className:"af-composer-mention-item"+(M===w?" af-composer-mention-item--active":""),onMouseDown:I=>I.preventDefault(),onMouseEnter:()=>y(M),onClick:()=>D(B.insert),children:[o.jsx("span",{className:"af-composer-mention-id",children:`\${${B.insert}}`}),B.subtitle?o.jsx("span",{className:"af-composer-mention-sub",children:B.subtitle}):null]})},`${B.section}-${B.insert}`))}),document.body):null,C?o.jsx("p",{id:d,className:"af-body-ph-issues",role:"status",children:N.map(B=>B.message).join(" · ")}):null]})}const C7=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function Uc(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function Tj({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:i=!0}){const{t:a}=Pr(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),c=d=>r(n.filter((f,h)=>h!==d)),u=(d,f,h)=>{const g=n.map((k,w)=>{if(w!==d)return k;const y={...k,[f]:h};return f==="required"&&h===!0&&(y.showOnNode=!0),y});r(g)},p=e==="input"?"input":"output";return o.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[o.jsxs("div",{className:"af-node-props-io-head",children:[o.jsx("span",{className:"af-node-props-label",children:t}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-io-add",onClick:l,disabled:s,"aria-label":a("flow:nodeProps.addPinAriaLabel",{label:t}),children:a("flow:nodeProps.addPin")})]}),o.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:p})}),n.length===0?o.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?o.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[o.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[o.jsx("span",{children:a("flow:nodeProps.handle")}),o.jsx("span",{children:a("flow:nodeProps.type")}),o.jsx("span",{children:a("flow:nodeProps.name")}),o.jsx("span",{children:a("flow:nodeProps.defaultValue")}),o.jsx("span",{children:a("flow:nodeProps.description")}),o.jsx("span",{children:a("flow:nodeProps.required")}),o.jsx("span",{children:a("flow:nodeProps.showOnNode")}),o.jsx("span",{})]}),n.map((d,f)=>o.jsxs("div",{className:"af-node-props-io-row",children:[o.jsxs("span",{className:"af-node-props-io-handle",title:`${p}-${f}`,children:[p,"-",f]}),o.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:d.type,onChange:h=>u(f,"type",h.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:f}),children:["node","text","file","bool"].map(h=>o.jsx("option",{value:h,children:h},h))}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:d.name,onChange:h=>u(f,"name",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:f})}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:d.default,onChange:h=>u(f,"default",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:f})}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:d.description||"",onChange:h=>u(f,"description",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDescriptionAriaLabel",{label:t,index:f})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:o.jsx("input",{type:"checkbox",checked:!!d.required,onChange:h=>{i||u(f,"required",h.target.checked)},disabled:s||i,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:f})})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:o.jsx("input",{type:"checkbox",checked:d.showOnNode!==!1,onChange:h=>u(f,"showOnNode",h.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:f})})}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>c(f),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:f}),title:a("flow:nodeProps.deletePin"),children:o.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${p}-${f}`))]}):null]})}function _7({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:i,onIdBlur:a,onClose:l,onPublishToMarketplace:c,allowEditRequiredPins:u=!1,error:p,ioSlots:d}){const{t:f}=Pr(),[h,g]=m.useState(!1),[k,w]=m.useState(!1),[y,v]=m.useState({status:"idle",message:""}),x=m.useCallback($=>{t(T=>T&&{...T,...$})},[t]),{cursorList:j,opencodeList:N,claudeCodeList:C,codexList:E,currentNotInLists:A}=m.useMemo(()=>{const $=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],T=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],K=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],B=Array.isArray(s==null?void 0:s.codex)?s.codex:[],M=new Set([...$,...T,...K,...B].map(Uc)),I=((e==null?void 0:e.model)??"").trim(),W=I.startsWith("cursor:")?I.slice(7):I.startsWith("opencode:")?I.slice(9):I.startsWith("codex:")?I.slice(6):I.startsWith("claude-code:")?I.slice(12):I,_=I&&!M.has(W)?I:"";return{cursorList:$,opencodeList:T,claudeCodeList:K,codexList:B,currentNotInLists:_}},[s,e==null?void 0:e.model]);if(!e)return null;const O=String(e.script??""),H=n==="tool_nodejs"||O.trim()!=="",F=typeof c=="function"&&!i&&(e==null?void 0:e.newId),D=async()=>{if(F){v({status:"running",message:f("flow:nodeProps.publishRunning")});try{const $=await c(e,n);v({status:"success",message:$!=null&&$.definitionId?f("flow:nodeProps.publishSuccessWithId",{id:$.definitionId}):f("flow:nodeProps.publishSuccess")})}catch($){v({status:"error",message:String(($==null?void 0:$.message)||$)})}}};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[o.jsx("h2",{className:"af-pipeline-drawer-title",children:f("flow:nodeProps.title")}),o.jsxs("div",{className:"af-node-props-head-actions",children:[o.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:D,disabled:!F||y.status==="running",title:f("flow:nodeProps.publishToMarketplaceHint"),children:[o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),y.status==="running"?f("flow:nodeProps.publishing"):f("flow:nodeProps.publishToMarketplace")]}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:f("common:common.close")})]})]}),o.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[p?o.jsx("p",{className:"af-err af-node-props-err",children:p}):null,y.message?o.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${y.status}`,children:y.message}):null,o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:f("flow:node.nodeType")}),o.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:nodeProps.instanceId"),o.jsx("span",{className:"af-node-props-hint",children:f("flow:node.displayNameHint")})]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:$=>x({newId:$.target.value}),onBlur:a,disabled:i,spellCheck:!1,autoComplete:"off","aria-label":f("flow:nodeProps.instanceId")})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.displayName"),"(LABEL)"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:$=>x({label:$.target.value}),disabled:i,spellCheck:!1})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.role"),"(ROLE)"]}),o.jsx("select",{className:"af-node-props-select",value:rd.includes(e.role)?e.role:f("flow:roles.normal"),onChange:$=>x({role:$.target.value}),disabled:i,children:rd.map($=>o.jsx("option",{value:$,children:$},$))})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.model"),"(MODEL)"]}),o.jsx("span",{className:"af-node-props-sublabel",children:f("flow:node.modelHint")}),o.jsxs("select",{className:"af-node-props-select",value:(()=>{const $=(e.model||"").trim();return $?A||$:""})(),onChange:$=>x({model:$.target.value}),disabled:i,"aria-label":f("flow:nodeProps.modelAriaLabel"),children:[o.jsx("option",{value:"",children:f("flow:node.defaultModel")}),A?o.jsxs("option",{value:A,children:[A,f("flow:nodeProps.yamlValueNotInList")]}):null,j.length>0?o.jsx("optgroup",{label:"Cursor",children:j.map($=>o.jsx("option",{value:Uc($),children:$},`c-${$}`))}):null,N.length>0?o.jsx("optgroup",{label:"OpenCode",children:N.map($=>o.jsx("option",{value:`opencode:${Uc($)}`,children:$},`o-${$}`))}):null,E.length>0?o.jsx("optgroup",{label:"Codex",children:E.map($=>o.jsx("option",{value:`codex:${Uc($)}`,children:$},`codex-${$}`))}):null,C.length>0?o.jsx("optgroup",{label:"Claude Code",children:C.map($=>o.jsx("option",{value:`claude-code:${Uc($)}`,children:$},`cc-${$}`))}):null]})]}),o.jsx(Tj,{kind:"input",label:f("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:$=>x({inputs:$}),disabled:i,requiredReadonly:!u}),o.jsx(Tj,{kind:"output",label:f("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:$=>x({outputs:$}),disabled:i,requiredReadonly:!u}),H?o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.directCommand"),"(script)",o.jsx("span",{className:"af-node-props-hint",children:f("flow:node.scriptHint")})]}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>w(!0),"aria-label":f("flow:nodeProps.expandEditScript"),title:f("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Hf,{value:O,onChange:$=>x({script:$}),disabled:i,placeholder:f("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:d,variant:"drawer"})]}):null,o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:"Script file(scriptRef)"}),o.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/script.mjs"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.scriptRef||"",onChange:$=>x({scriptRef:$.target.value}),disabled:i,spellCheck:!1,autoComplete:"off"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:"Implementation file(implementationRef)"}),o.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/implementation.md"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.implementationRef||"",onChange:$=>x({implementationRef:$.target.value}),disabled:i,spellCheck:!1,autoComplete:"off"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:"Implementation mode"}),o.jsxs("select",{className:"af-node-props-select",value:e.implementationMode||"",onChange:$=>x({implementationMode:$.target.value}),disabled:i,children:[o.jsx("option",{value:"",children:"auto"}),o.jsx("option",{value:"script",children:"script"}),o.jsx("option",{value:"steps",children:"steps"}),o.jsx("option",{value:"hybrid",children:"hybrid"})]})]}),o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsx("span",{className:"af-node-props-label",children:f("flow:node.userPrompt")}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>g(!0),"aria-label":f("flow:nodeProps.expandEdit"),title:f("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Hf,{value:e.body,onChange:$=>x({body:$}),images:e.images,onImagesChange:$=>x({images:$}),disabled:i,placeholder:f("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:d,variant:"drawer"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:f("flow:node.systemDescription")}),o.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||f("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),k?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":f("flow:nodeProps.editScript"),onMouseDown:$=>{$.target===$.currentTarget&&w(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:f("flow:node.directCommand")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>w(!1),"aria-label":f("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx(Hf,{value:O,onChange:$=>x({script:$}),disabled:i,placeholder:f("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:d,variant:"expand"})]})}):null,h?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":f("flow:nodeProps.editUserPrompt"),onMouseDown:$=>{$.target===$.currentTarget&&g(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:f("flow:node.body")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>g(!1),"aria-label":f("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx(Hf,{value:e.body,onChange:$=>x({body:$}),images:e.images,onImagesChange:$=>x({images:$}),disabled:i,placeholder:f("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:d,variant:"expand"})]})}):null]})}function E7({open:e,onClose:t,flowId:n,flowSource:r,onArchived:s}){const{t:i}=Pr(),a=m.useId(),l=m.useRef(null),[c,u]=m.useState(""),[p,d]=m.useState(!1),[f,h]=m.useState("");if(m.useEffect(()=>{if(!e)return;u(""),h(""),d(!1);const y=requestAnimationFrame(()=>{var v;return(v=l.current)==null?void 0:v.focus()});return()=>cancelAnimationFrame(y)},[e,n]),!e)return null;const g=c.trim(),k=g===n;async function w(y){if(y.preventDefault(),!(!k||p)){d(!0),h("");try{const v=await fetch("/api/flow/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:g})}),x=await v.json().catch(()=>({}));if(!v.ok){h(typeof x.error=="string"?x.error:i("project:archiveModal.archiveFailed"));return}s()}catch(v){h(String((v==null?void 0:v.message)||v))}finally{d(!1)}}}return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&t()},children:o.jsxs("div",{ref:l,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":a,tabIndex:-1,onMouseDown:y=>y.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:a,className:"af-shortcuts-panel__title",children:i("project:archiveModal.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":i("project:archiveModal.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:w,children:[o.jsx("p",{className:"af-new-pipeline-lead",children:i("project:archiveModal.lead",{flowId:n})}),o.jsxs("label",{className:"af-new-pipeline-field",children:[o.jsx("span",{className:"af-pipeline-drawer-label",children:i("project:archiveModal.confirmLabel")}),o.jsx("input",{type:"text",className:"af-new-pipeline-input",value:c,onChange:y=>u(y.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":g.length>0&&!k})]}),f?o.jsx("p",{className:"af-err af-new-pipeline-err",children:f}):null,o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:p,children:i("project:archiveModal.cancel")}),o.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!k||p,children:i(p?"project:archiveModal.archiving":"project:archiveModal.confirmArchive")})]})]})]})})}function A7({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,onDeleted:i}){const{t:a}=Pr(),l=m.useId(),c=m.useRef(null),[u,p]=m.useState(""),[d,f]=m.useState(!1),[h,g]=m.useState("");if(m.useEffect(()=>{if(!e)return;p(""),g(""),f(!1);const v=requestAnimationFrame(()=>{var x;return(x=c.current)==null?void 0:x.focus()});return()=>cancelAnimationFrame(v)},[e,n]),!e)return null;const k=u.trim(),w=k===n;async function y(v){if(v.preventDefault(),!w||d)return;f(!0),g("");let x=null;try{const j=new AbortController;x=setTimeout(()=>j.abort(),15e3);const N=await fetch("/api/flow/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:k,flowArchived:s}),signal:j.signal}),C=await N.json().catch(()=>({}));if(!N.ok){g(typeof C.error=="string"?C.error:a("project:deleteModal.deleteFailed"));return}try{for(let E=localStorage.length-1;E>=0;E--){const A=localStorage.key(E);A&&(A.startsWith(`af:composer-sessions:${n}:${r}`)||A.startsWith(`af:composer-active-session:${n}:${r}`)||A.startsWith(`af:workspace-composer:${n}:${r}`))&&localStorage.removeItem(A)}}catch{}await i()}catch(j){if((j==null?void 0:j.name)==="AbortError"){g(a("project:deleteModal.deleteTimeout"));return}g(String((j==null?void 0:j.message)||j))}finally{x&&clearTimeout(x),f(!1)}}return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&t()},children:o.jsxs("div",{ref:c,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":l,tabIndex:-1,onMouseDown:v=>v.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:l,className:"af-shortcuts-panel__title",children:a("project:deleteModal.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":a("project:deleteModal.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:y,children:[o.jsx("p",{className:"af-new-pipeline-lead",children:a("project:deleteModal.lead",{flowId:n})}),o.jsxs("label",{className:"af-new-pipeline-field",children:[o.jsx("span",{className:"af-pipeline-drawer-label",children:a("project:deleteModal.confirmLabel")}),o.jsx("input",{type:"text",className:"af-new-pipeline-input",value:u,onChange:v=>p(v.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":k.length>0&&!w})]}),h?o.jsx("p",{className:"af-err af-new-pipeline-err",children:h}):null,o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:d,children:a("project:deleteModal.cancel")}),o.jsx("button",{type:"submit",className:"af-btn-primary af-btn-destructive",disabled:!w||d,children:a(d?"project:deleteModal.deleting":"project:deleteModal.confirmDelete")})]})]})]})})}const Rj=80,P7=220;function I7(e){if(!e||typeof e!="object")return e;const{selected:t,dragging:n,resizing:r,className:s,positionAbsolute:i,measured:a,internals:l,...c}=e;return c}function T7(e){if(!e||typeof e!="object")return e;const{selected:t,className:n,...r}=e;return r}function Wf(e,t,n){const r={nodes:Array.isArray(e)?e.map(I7):[],edges:Array.isArray(t)?t.map(T7):[],extra:n&&typeof n=="object"?n:{}},s=JSON.stringify(r);return{value:JSON.parse(s),signature:s}}function Zg(e,t){const n=[...e,t];return n.length>Rj?n.slice(n.length-Rj):n}function R7({nodes:e,edges:t,extra:n,enabled:r=!0,onRestore:s}){const[i,a]=m.useState(0),l=m.useRef([]),c=m.useRef([]),u=m.useRef(null),p=m.useRef(null),d=m.useRef(null),f=m.useRef(null),h=m.useRef(!1),g=m.useCallback(()=>a(N=>N+1),[]),k=m.useCallback(()=>{f.current&&(window.clearTimeout(f.current),f.current=null)},[]),w=m.useCallback(()=>{k();const N=p.current,C=d.current;return p.current=null,d.current=null,!N||!C||N.signature===C.signature?(C&&(u.current=C),!1):(l.current=Zg(l.current,N),c.current=[],u.current=C,g(),!0)},[g,k]),y=m.useCallback((N=[],C=[],E={})=>{k(),l.current=[],c.current=[],p.current=null,d.current=null,u.current=Wf(N,C,E),h.current=!1,g()},[g,k]),v=m.useCallback(N=>{h.current=!0,u.current=N,p.current=null,d.current=null,k(),s==null||s(N.value),g()},[g,k,s]),x=m.useCallback(()=>{w();const N=u.current||Wf(e,t,n),C=l.current.pop();return C?(c.current=Zg(c.current,N),v(C),!0):(g(),!1)},[g,t,n,w,e,v]),j=m.useCallback(()=>{w();const N=u.current||Wf(e,t,n),C=c.current.pop();return C?(l.current=Zg(l.current,N),v(C),!0):(g(),!1)},[g,t,n,w,e,v]);return m.useEffect(()=>()=>k(),[k]),m.useEffect(()=>{if(!r)return;const N=Wf(e,t,n);if(!u.current){u.current=N;return}if(h.current){h.current=!1,u.current=N;return}N.signature!==u.current.signature&&(p.current||(p.current=u.current),d.current=N,k(),f.current=window.setTimeout(()=>{w()},P7))},[k,t,r,n,w,e]),{canUndo:l.current.length>0||!!p.current,canRedo:c.current.length>0,resetHistory:y,undo:x,redo:j,version:i}}const M7="af:workspace-graph:v2",Mj="agentflow.workspace.sidebarCollapsed",dl=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],$7=new Set(["control_start","control_end","control_load_skills","control_load_mcp","control_cd_workspace","control_user_workspace"]),L7={id:"workspace_run",displayName:"Run",label:"Run",description:"Run the downstream workspace subgraph connected from this node.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},O7={id:"workspace_scheduled_run",displayName:"Scheduled Run",label:"Scheduled Run",description:"Run the downstream workspace subgraph on a schedule.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},D7={id:"control_load_skills",displayName:"Load Skills",label:"Load Skills",description:"Load the currently selected Workspace skill collection for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"skillsContext",default:"",showOnNode:!0}]},F7={id:"control_load_mcp",displayName:"Load MCP",label:"Load MCP",description:"Load selected Cursor MCP server tool manifests for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"serverNames",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"mcpContext",default:"",showOnNode:!0}]},z7={id:"control_cd_workspace",displayName:"加载知识库",label:"加载知识库",description:"Select one or more knowledge sources and pass knowledgeContext to downstream nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"path",default:"",showOnNode:!1},{type:"text",name:"label",default:"",showOnNode:!1},{type:"text",name:"knowledgeContext",default:"",showOnNode:!1},{type:"text",name:"workspaceContext",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"knowledgeContext",default:"",showOnNode:!0},{type:"text",name:"workspaceContext",default:"",showOnNode:!1},{type:"file",name:"cwd",default:"",showOnNode:!1}]},B7={id:"workspace_one_click_task",displayName:"一键任务",label:"一键任务",description:"输入任务,选择 Skills、workspace 上下文和输出类型后直接运行。",type:"agent",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1},{type:"bool",name:"includeWorkspaceContext",default:"true",showOnNode:!1},{type:"text",name:"displayType",default:"markdown",showOnNode:!1},{type:"text",name:"knowledgeContext",default:"",showOnNode:!1},{type:"text",name:"workspaceContext",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"content",default:"",showOnNode:!0},{type:"text",name:"displayType",default:"markdown",showOnNode:!1}]},H7=new Set(["png","jpg","jpeg","gif","webp","svg"]),TI=320,RI=180,MI=960,mh=96,$I=900,Zx=520,ew=320,Vf=52,Ta=240,Ra=160,tw="display-ref:",id="0 9 * * *",W7="Asia/Shanghai",V7="0.1.94";function K7(){const e=new URLSearchParams(window.location.search);return{flowId:e.get("flowId")||"",flowSource:e.get("flowSource")||"user",archived:e.get("archived")==="1"||e.get("flowArchived")==="1"}}function Or(e){const t=new URLSearchParams;return e.flowId&&t.set("flowId",e.flowId),e.flowSource&&t.set("flowSource",e.flowSource),e.archived&&t.set("archived","1"),t}function tk(e,t=4e3){const n=String(e??"").trim();return n?n.length>t?`${n.slice(0,t)}
182
+ `}}),o.jsx("textarea",{ref:f,className:"af-body-prompt-textarea "+i,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":C,"aria-describedby":C?d:void 0,onChange:B=>{t(B.target.value),k(B.target.selectionStart??B.target.value.length)},onSelect:B=>{const M=B.target;M instanceof HTMLTextAreaElement&&k(M.selectionStart??0)},onClick:B=>{const M=B.target;M instanceof HTMLTextAreaElement&&k(M.selectionStart??0)},onKeyUp:B=>{const M=B.target;M instanceof HTMLTextAreaElement&&k(M.selectionStart??M.value.length)},onKeyDown:T,onPaste:B=>{const M=jI(B);M.length!==0&&(B.preventDefault(),K(M).catch(()=>{}))},onDragOver:B=>{ju(B).length>0&&B.preventDefault()},onDrop:B=>{const M=ju(B);M.length!==0&&(B.preventDefault(),K(M).catch(()=>{}))},onScroll:$})]}),O&&H.length>0&&v?Cr.createPortal(o.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":p("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:v.top,left:v.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:H.map((B,M)=>o.jsx("li",{role:"option","aria-selected":M===w,children:o.jsxs("button",{type:"button",className:"af-composer-mention-item"+(M===w?" af-composer-mention-item--active":""),onMouseDown:I=>I.preventDefault(),onMouseEnter:()=>y(M),onClick:()=>D(B.insert),children:[o.jsx("span",{className:"af-composer-mention-id",children:`\${${B.insert}}`}),B.subtitle?o.jsx("span",{className:"af-composer-mention-sub",children:B.subtitle}):null]})},`${B.section}-${B.insert}`))}),document.body):null,C?o.jsx("p",{id:d,className:"af-body-ph-issues",role:"status",children:N.map(B=>B.message).join(" · ")}):null]})}const C7=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function Uc(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function Tj({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:i=!0}){const{t:a}=Pr(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),c=d=>r(n.filter((f,h)=>h!==d)),u=(d,f,h)=>{const g=n.map((k,w)=>{if(w!==d)return k;const y={...k,[f]:h};return f==="required"&&h===!0&&(y.showOnNode=!0),y});r(g)},p=e==="input"?"input":"output";return o.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[o.jsxs("div",{className:"af-node-props-io-head",children:[o.jsx("span",{className:"af-node-props-label",children:t}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-io-add",onClick:l,disabled:s,"aria-label":a("flow:nodeProps.addPinAriaLabel",{label:t}),children:a("flow:nodeProps.addPin")})]}),o.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:p})}),n.length===0?o.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?o.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[o.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[o.jsx("span",{children:a("flow:nodeProps.handle")}),o.jsx("span",{children:a("flow:nodeProps.type")}),o.jsx("span",{children:a("flow:nodeProps.name")}),o.jsx("span",{children:a("flow:nodeProps.defaultValue")}),o.jsx("span",{children:a("flow:nodeProps.description")}),o.jsx("span",{children:a("flow:nodeProps.required")}),o.jsx("span",{children:a("flow:nodeProps.showOnNode")}),o.jsx("span",{})]}),n.map((d,f)=>o.jsxs("div",{className:"af-node-props-io-row",children:[o.jsxs("span",{className:"af-node-props-io-handle",title:`${p}-${f}`,children:[p,"-",f]}),o.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:d.type,onChange:h=>u(f,"type",h.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:f}),children:["node","text","file","bool"].map(h=>o.jsx("option",{value:h,children:h},h))}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:d.name,onChange:h=>u(f,"name",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:f})}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:d.default,onChange:h=>u(f,"default",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:f})}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:d.description||"",onChange:h=>u(f,"description",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDescriptionAriaLabel",{label:t,index:f})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:o.jsx("input",{type:"checkbox",checked:!!d.required,onChange:h=>{i||u(f,"required",h.target.checked)},disabled:s||i,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:f})})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:o.jsx("input",{type:"checkbox",checked:d.showOnNode!==!1,onChange:h=>u(f,"showOnNode",h.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:f})})}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>c(f),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:f}),title:a("flow:nodeProps.deletePin"),children:o.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${p}-${f}`))]}):null]})}function _7({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:i,onIdBlur:a,onClose:l,onPublishToMarketplace:c,allowEditRequiredPins:u=!1,error:p,ioSlots:d}){const{t:f}=Pr(),[h,g]=m.useState(!1),[k,w]=m.useState(!1),[y,v]=m.useState({status:"idle",message:""}),x=m.useCallback($=>{t(T=>T&&{...T,...$})},[t]),{cursorList:j,opencodeList:N,claudeCodeList:C,codexList:E,currentNotInLists:A}=m.useMemo(()=>{const $=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],T=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],K=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],B=Array.isArray(s==null?void 0:s.codex)?s.codex:[],M=new Set([...$,...T,...K,...B].map(Uc)),I=((e==null?void 0:e.model)??"").trim(),W=I.startsWith("cursor:")?I.slice(7):I.startsWith("opencode:")?I.slice(9):I.startsWith("codex:")?I.slice(6):I.startsWith("claude-code:")?I.slice(12):I,_=I&&!M.has(W)?I:"";return{cursorList:$,opencodeList:T,claudeCodeList:K,codexList:B,currentNotInLists:_}},[s,e==null?void 0:e.model]);if(!e)return null;const O=String(e.script??""),H=n==="tool_nodejs"||O.trim()!=="",F=typeof c=="function"&&!i&&(e==null?void 0:e.newId),D=async()=>{if(F){v({status:"running",message:f("flow:nodeProps.publishRunning")});try{const $=await c(e,n);v({status:"success",message:$!=null&&$.definitionId?f("flow:nodeProps.publishSuccessWithId",{id:$.definitionId}):f("flow:nodeProps.publishSuccess")})}catch($){v({status:"error",message:String(($==null?void 0:$.message)||$)})}}};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[o.jsx("h2",{className:"af-pipeline-drawer-title",children:f("flow:nodeProps.title")}),o.jsxs("div",{className:"af-node-props-head-actions",children:[o.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:D,disabled:!F||y.status==="running",title:f("flow:nodeProps.publishToMarketplaceHint"),children:[o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),y.status==="running"?f("flow:nodeProps.publishing"):f("flow:nodeProps.publishToMarketplace")]}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:f("common:common.close")})]})]}),o.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[p?o.jsx("p",{className:"af-err af-node-props-err",children:p}):null,y.message?o.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${y.status}`,children:y.message}):null,o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:f("flow:node.nodeType")}),o.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:nodeProps.instanceId"),o.jsx("span",{className:"af-node-props-hint",children:f("flow:node.displayNameHint")})]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:$=>x({newId:$.target.value}),onBlur:a,disabled:i,spellCheck:!1,autoComplete:"off","aria-label":f("flow:nodeProps.instanceId")})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.displayName"),"(LABEL)"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:$=>x({label:$.target.value}),disabled:i,spellCheck:!1})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.role"),"(ROLE)"]}),o.jsx("select",{className:"af-node-props-select",value:rd.includes(e.role)?e.role:f("flow:roles.normal"),onChange:$=>x({role:$.target.value}),disabled:i,children:rd.map($=>o.jsx("option",{value:$,children:$},$))})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.model"),"(MODEL)"]}),o.jsx("span",{className:"af-node-props-sublabel",children:f("flow:node.modelHint")}),o.jsxs("select",{className:"af-node-props-select",value:(()=>{const $=(e.model||"").trim();return $?A||$:""})(),onChange:$=>x({model:$.target.value}),disabled:i,"aria-label":f("flow:nodeProps.modelAriaLabel"),children:[o.jsx("option",{value:"",children:f("flow:node.defaultModel")}),A?o.jsxs("option",{value:A,children:[A,f("flow:nodeProps.yamlValueNotInList")]}):null,j.length>0?o.jsx("optgroup",{label:"Cursor",children:j.map($=>o.jsx("option",{value:Uc($),children:$},`c-${$}`))}):null,N.length>0?o.jsx("optgroup",{label:"OpenCode",children:N.map($=>o.jsx("option",{value:`opencode:${Uc($)}`,children:$},`o-${$}`))}):null,E.length>0?o.jsx("optgroup",{label:"Codex",children:E.map($=>o.jsx("option",{value:`codex:${Uc($)}`,children:$},`codex-${$}`))}):null,C.length>0?o.jsx("optgroup",{label:"Claude Code",children:C.map($=>o.jsx("option",{value:`claude-code:${Uc($)}`,children:$},`cc-${$}`))}):null]})]}),o.jsx(Tj,{kind:"input",label:f("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:$=>x({inputs:$}),disabled:i,requiredReadonly:!u}),o.jsx(Tj,{kind:"output",label:f("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:$=>x({outputs:$}),disabled:i,requiredReadonly:!u}),H?o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.directCommand"),"(script)",o.jsx("span",{className:"af-node-props-hint",children:f("flow:node.scriptHint")})]}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>w(!0),"aria-label":f("flow:nodeProps.expandEditScript"),title:f("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Hf,{value:O,onChange:$=>x({script:$}),disabled:i,placeholder:f("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:d,variant:"drawer"})]}):null,o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:"Script file(scriptRef)"}),o.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/script.mjs"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.scriptRef||"",onChange:$=>x({scriptRef:$.target.value}),disabled:i,spellCheck:!1,autoComplete:"off"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:"Implementation file(implementationRef)"}),o.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/implementation.md"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.implementationRef||"",onChange:$=>x({implementationRef:$.target.value}),disabled:i,spellCheck:!1,autoComplete:"off"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:"Implementation mode"}),o.jsxs("select",{className:"af-node-props-select",value:e.implementationMode||"",onChange:$=>x({implementationMode:$.target.value}),disabled:i,children:[o.jsx("option",{value:"",children:"auto"}),o.jsx("option",{value:"script",children:"script"}),o.jsx("option",{value:"steps",children:"steps"}),o.jsx("option",{value:"hybrid",children:"hybrid"})]})]}),o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsx("span",{className:"af-node-props-label",children:f("flow:node.userPrompt")}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>g(!0),"aria-label":f("flow:nodeProps.expandEdit"),title:f("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Hf,{value:e.body,onChange:$=>x({body:$}),images:e.images,onImagesChange:$=>x({images:$}),disabled:i,placeholder:f("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:d,variant:"drawer"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:f("flow:node.systemDescription")}),o.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||f("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),k?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":f("flow:nodeProps.editScript"),onMouseDown:$=>{$.target===$.currentTarget&&w(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:f("flow:node.directCommand")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>w(!1),"aria-label":f("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx(Hf,{value:O,onChange:$=>x({script:$}),disabled:i,placeholder:f("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:d,variant:"expand"})]})}):null,h?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":f("flow:nodeProps.editUserPrompt"),onMouseDown:$=>{$.target===$.currentTarget&&g(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:f("flow:node.body")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>g(!1),"aria-label":f("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx(Hf,{value:e.body,onChange:$=>x({body:$}),images:e.images,onImagesChange:$=>x({images:$}),disabled:i,placeholder:f("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:d,variant:"expand"})]})}):null]})}function E7({open:e,onClose:t,flowId:n,flowSource:r,onArchived:s}){const{t:i}=Pr(),a=m.useId(),l=m.useRef(null),[c,u]=m.useState(""),[p,d]=m.useState(!1),[f,h]=m.useState("");if(m.useEffect(()=>{if(!e)return;u(""),h(""),d(!1);const y=requestAnimationFrame(()=>{var v;return(v=l.current)==null?void 0:v.focus()});return()=>cancelAnimationFrame(y)},[e,n]),!e)return null;const g=c.trim(),k=g===n;async function w(y){if(y.preventDefault(),!(!k||p)){d(!0),h("");try{const v=await fetch("/api/flow/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:g})}),x=await v.json().catch(()=>({}));if(!v.ok){h(typeof x.error=="string"?x.error:i("project:archiveModal.archiveFailed"));return}s()}catch(v){h(String((v==null?void 0:v.message)||v))}finally{d(!1)}}}return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&t()},children:o.jsxs("div",{ref:l,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":a,tabIndex:-1,onMouseDown:y=>y.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:a,className:"af-shortcuts-panel__title",children:i("project:archiveModal.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":i("project:archiveModal.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:w,children:[o.jsx("p",{className:"af-new-pipeline-lead",children:i("project:archiveModal.lead",{flowId:n})}),o.jsxs("label",{className:"af-new-pipeline-field",children:[o.jsx("span",{className:"af-pipeline-drawer-label",children:i("project:archiveModal.confirmLabel")}),o.jsx("input",{type:"text",className:"af-new-pipeline-input",value:c,onChange:y=>u(y.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":g.length>0&&!k})]}),f?o.jsx("p",{className:"af-err af-new-pipeline-err",children:f}):null,o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:p,children:i("project:archiveModal.cancel")}),o.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!k||p,children:i(p?"project:archiveModal.archiving":"project:archiveModal.confirmArchive")})]})]})]})})}function A7({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,onDeleted:i}){const{t:a}=Pr(),l=m.useId(),c=m.useRef(null),[u,p]=m.useState(""),[d,f]=m.useState(!1),[h,g]=m.useState("");if(m.useEffect(()=>{if(!e)return;p(""),g(""),f(!1);const v=requestAnimationFrame(()=>{var x;return(x=c.current)==null?void 0:x.focus()});return()=>cancelAnimationFrame(v)},[e,n]),!e)return null;const k=u.trim(),w=k===n;async function y(v){if(v.preventDefault(),!w||d)return;f(!0),g("");let x=null;try{const j=new AbortController;x=setTimeout(()=>j.abort(),15e3);const N=await fetch("/api/flow/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:k,flowArchived:s}),signal:j.signal}),C=await N.json().catch(()=>({}));if(!N.ok){g(typeof C.error=="string"?C.error:a("project:deleteModal.deleteFailed"));return}try{for(let E=localStorage.length-1;E>=0;E--){const A=localStorage.key(E);A&&(A.startsWith(`af:composer-sessions:${n}:${r}`)||A.startsWith(`af:composer-active-session:${n}:${r}`)||A.startsWith(`af:workspace-composer:${n}:${r}`))&&localStorage.removeItem(A)}}catch{}await i()}catch(j){if((j==null?void 0:j.name)==="AbortError"){g(a("project:deleteModal.deleteTimeout"));return}g(String((j==null?void 0:j.message)||j))}finally{x&&clearTimeout(x),f(!1)}}return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&t()},children:o.jsxs("div",{ref:c,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":l,tabIndex:-1,onMouseDown:v=>v.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:l,className:"af-shortcuts-panel__title",children:a("project:deleteModal.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":a("project:deleteModal.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:y,children:[o.jsx("p",{className:"af-new-pipeline-lead",children:a("project:deleteModal.lead",{flowId:n})}),o.jsxs("label",{className:"af-new-pipeline-field",children:[o.jsx("span",{className:"af-pipeline-drawer-label",children:a("project:deleteModal.confirmLabel")}),o.jsx("input",{type:"text",className:"af-new-pipeline-input",value:u,onChange:v=>p(v.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":k.length>0&&!w})]}),h?o.jsx("p",{className:"af-err af-new-pipeline-err",children:h}):null,o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:d,children:a("project:deleteModal.cancel")}),o.jsx("button",{type:"submit",className:"af-btn-primary af-btn-destructive",disabled:!w||d,children:a(d?"project:deleteModal.deleting":"project:deleteModal.confirmDelete")})]})]})]})})}const Rj=80,P7=220;function I7(e){if(!e||typeof e!="object")return e;const{selected:t,dragging:n,resizing:r,className:s,positionAbsolute:i,measured:a,internals:l,...c}=e;return c}function T7(e){if(!e||typeof e!="object")return e;const{selected:t,className:n,...r}=e;return r}function Wf(e,t,n){const r={nodes:Array.isArray(e)?e.map(I7):[],edges:Array.isArray(t)?t.map(T7):[],extra:n&&typeof n=="object"?n:{}},s=JSON.stringify(r);return{value:JSON.parse(s),signature:s}}function Zg(e,t){const n=[...e,t];return n.length>Rj?n.slice(n.length-Rj):n}function R7({nodes:e,edges:t,extra:n,enabled:r=!0,onRestore:s}){const[i,a]=m.useState(0),l=m.useRef([]),c=m.useRef([]),u=m.useRef(null),p=m.useRef(null),d=m.useRef(null),f=m.useRef(null),h=m.useRef(!1),g=m.useCallback(()=>a(N=>N+1),[]),k=m.useCallback(()=>{f.current&&(window.clearTimeout(f.current),f.current=null)},[]),w=m.useCallback(()=>{k();const N=p.current,C=d.current;return p.current=null,d.current=null,!N||!C||N.signature===C.signature?(C&&(u.current=C),!1):(l.current=Zg(l.current,N),c.current=[],u.current=C,g(),!0)},[g,k]),y=m.useCallback((N=[],C=[],E={})=>{k(),l.current=[],c.current=[],p.current=null,d.current=null,u.current=Wf(N,C,E),h.current=!1,g()},[g,k]),v=m.useCallback(N=>{h.current=!0,u.current=N,p.current=null,d.current=null,k(),s==null||s(N.value),g()},[g,k,s]),x=m.useCallback(()=>{w();const N=u.current||Wf(e,t,n),C=l.current.pop();return C?(c.current=Zg(c.current,N),v(C),!0):(g(),!1)},[g,t,n,w,e,v]),j=m.useCallback(()=>{w();const N=u.current||Wf(e,t,n),C=c.current.pop();return C?(l.current=Zg(l.current,N),v(C),!0):(g(),!1)},[g,t,n,w,e,v]);return m.useEffect(()=>()=>k(),[k]),m.useEffect(()=>{if(!r)return;const N=Wf(e,t,n);if(!u.current){u.current=N;return}if(h.current){h.current=!1,u.current=N;return}N.signature!==u.current.signature&&(p.current||(p.current=u.current),d.current=N,k(),f.current=window.setTimeout(()=>{w()},P7))},[k,t,r,n,w,e]),{canUndo:l.current.length>0||!!p.current,canRedo:c.current.length>0,resetHistory:y,undo:x,redo:j,version:i}}const M7="af:workspace-graph:v2",Mj="agentflow.workspace.sidebarCollapsed",dl=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],$7=new Set(["control_start","control_end","control_load_skills","control_load_mcp","control_cd_workspace","control_user_workspace"]),L7={id:"workspace_run",displayName:"Run",label:"Run",description:"Run the downstream workspace subgraph connected from this node.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},O7={id:"workspace_scheduled_run",displayName:"Scheduled Run",label:"Scheduled Run",description:"Run the downstream workspace subgraph on a schedule.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},D7={id:"control_load_skills",displayName:"Load Skills",label:"Load Skills",description:"Load the currently selected Workspace skill collection for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"skillsContext",default:"",showOnNode:!0}]},F7={id:"control_load_mcp",displayName:"Load MCP",label:"Load MCP",description:"Load selected Cursor MCP server tool manifests for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"serverNames",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"mcpContext",default:"",showOnNode:!0}]},z7={id:"control_cd_workspace",displayName:"加载知识库",label:"加载知识库",description:"Select one or more knowledge sources and pass knowledgeContext to downstream nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"path",default:"",showOnNode:!1},{type:"text",name:"label",default:"",showOnNode:!1},{type:"text",name:"knowledgeContext",default:"",showOnNode:!1},{type:"text",name:"workspaceContext",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"knowledgeContext",default:"",showOnNode:!0},{type:"text",name:"workspaceContext",default:"",showOnNode:!1},{type:"file",name:"cwd",default:"",showOnNode:!1}]},B7={id:"workspace_one_click_task",displayName:"一键任务",label:"一键任务",description:"输入任务,选择 Skills、workspace 上下文和输出类型后直接运行。",type:"agent",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1},{type:"bool",name:"includeWorkspaceContext",default:"true",showOnNode:!1},{type:"text",name:"displayType",default:"markdown",showOnNode:!1},{type:"text",name:"knowledgeContext",default:"",showOnNode:!1},{type:"text",name:"workspaceContext",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"content",default:"",showOnNode:!0},{type:"text",name:"displayType",default:"markdown",showOnNode:!1}]},H7=new Set(["png","jpg","jpeg","gif","webp","svg"]),TI=320,RI=180,MI=960,mh=96,$I=900,Zx=520,ew=320,Vf=52,Ta=240,Ra=160,tw="display-ref:",id="0 9 * * *",W7="Asia/Shanghai",V7="0.1.95";function K7(){const e=new URLSearchParams(window.location.search);return{flowId:e.get("flowId")||"",flowSource:e.get("flowSource")||"user",archived:e.get("archived")==="1"||e.get("flowArchived")==="1"}}function Or(e){const t=new URLSearchParams;return e.flowId&&t.set("flowId",e.flowId),e.flowSource&&t.set("flowSource",e.flowSource),e.archived&&t.set("archived","1"),t}function tk(e,t=4e3){const n=String(e??"").trim();return n?n.length>t?`${n.slice(0,t)}
183
183
  ...[truncated ${n.length-t} chars]`:n:""}function q7(e){const t=tk(e==null?void 0:e.text,4e3);return t?{role:(e==null?void 0:e.role)==="user"?"user":"assistant",...e!=null&&e.kind?{kind:String(e.kind)}:{},text:t,...e!=null&&e.error?{error:!0}:{},at:Number.isFinite(Number(e==null?void 0:e.at))?Number(e.at):Date.now()}:null}function nk(e,t=80){return(Array.isArray(e)?e:[]).map(q7).filter(Boolean).slice(-t)}function U7(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:{},n={};for(const[r,s]of Object.entries(t).slice(-80)){const i=String(r||"").trim();if(!i||!s||typeof s!="object")continue;const a=nk(s.messages,40),l=tk(s.draft||"",2e3);!a.length&&!l||(n[i]={sessionId:String(s.sessionId||`nodechat_${i}`),messages:a,...l?{draft:l}:{},candidateContent:"",running:!1,error:""})}return n}function Y7(e){return(Array.isArray(e)?e:[]).map(t=>{const n=String((t==null?void 0:t.id)||"").trim();if(!n)return null;const r=nk(t==null?void 0:t.messages,80);if(!r.length)return null;const s=String((t==null?void 0:t.status)||"done");return{id:n,label:tk((t==null?void 0:t.label)||n,120),status:s==="failed"?"failed":"done",messages:r}}).filter(Boolean).slice(-20)}function $j(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:{},n=t.composer&&typeof t.composer=="object"&&!Array.isArray(t.composer)?t.composer:{};return{composer:{activeSessionId:String(n.activeSessionId||"workspace").trim()||"workspace",messages:nk(n.messages,100),runSessions:Y7(n.runSessions)},nodeChats:U7(t.nodeChats)}}function gh(e){if(!e)return!1;const t=String(e.type||"");if(t&&/^image\//i.test(t))return!0;const n=String(e.name||"").toLowerCase().split(".").pop();return H7.has(n)}function od(e,t,n={}){const r=String(e||"").trim();if(!r)return"";if(/^(?:https?:|data:|blob:|file:)/i.test(r)||r.startsWith("/"))return r;const s=Or(t||{});return s.set("path",r),n.download&&s.set("download","1"),`/api/workspace/file/raw?${s.toString()}`}function G7(e){const t=String((e==null?void 0:e.flowId)||"").trim();if(!t)return"";const n=String((e==null?void 0:e.flowSource)||"user").trim()||"user";return`af:composer-skills:workspace:${t}:${n}${e!=null&&e.archived?":archived":""}`}function J7(e){const t=String((e==null?void 0:e.username)||(e==null?void 0:e.userId)||"").trim();return t?`${Mj}:${t}`:Mj}function X7(e){try{const t=window.localStorage.getItem(e);if(t==="false")return!1;if(t==="true")return!0}catch{}return!0}function Lj(e){return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable='true']")}function Q7(e){var t;if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)return Number(e.selectionStart??0)!==Number(e.selectionEnd??0);if(e instanceof Element&&e.closest('[contenteditable="true"]')){const n=(t=window.getSelection)==null?void 0:t.call(window);return!!(n&&!n.isCollapsed)}return!1}function Z7(e){return!e||typeof e.closest!="function"?!1:!!e.closest(".af-flow-node__prompt-stack")&&!Q7(e)}function eq(e){const t=String(e||"").trim();if(!t||tq(t))return"";if(/^运行完成/.test(t))return"运行完成";if(/^运行暂停/.test(t))return"运行暂停";if(/^运行停止/.test(t))return"运行停止";if(/^思考中/.test(t))return"模型正在思考";if(/^生成回复中/.test(t))return"模型正在生成回复";if(/^Timing\s+(.+?):\s+(\d+)ms/i.test(t)){const n=t.match(/^Timing\s+(.+?):\s+(\d+)ms/i);return`耗时:${(n==null?void 0:n[1])||"step"} ${(n==null?void 0:n[2])||"0"}ms`}if(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i.test(t)){const n=t.match(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i),r=String((n==null?void 0:n[1])||"tool").trim(),s=String((n==null?void 0:n[2])||"").toLowerCase();if(r==="thinking")return"模型正在思考";const i=r==="readToolCall"?"读取文件/上下文":r==="grepToolCall"?"搜索代码":r==="editToolCall"?"编辑文件":r;return s==="completed"?`完成:${i}`:`执行:${i}`}return/^\[stderr\]/.test(t)?t:""}function tq(e){return/^\[stderr\]/.test(e)?/Reading additional input from stdin/i.test(e)||/rmcp::transport::worker/i.test(e)||/Transport channel closed/i.test(e)||/http\/request failed/i.test(e)||/AuthRequiredError/i.test(e)||/No access token was provided/i.test(e)||/api\.githubcopilot\.com/i.test(e):!1}function nq(e){const t=String(e||"").trim();return t?/^模型/.test(t)?"model":/^(执行|完成|耗时):/.test(t)?"tool":/^运行/.test(t)?"run":/^\[stderr\]/.test(t)?"error":"other":"other"}function ey(e,t,n,r="Workspace Run"){var c;const s=String(n||"").trim(),i=Array.isArray(e)?e.find(u=>String((u==null?void 0:u.id)||"")===s):null,a=t&&typeof t=="object"?t[s]:null;return String(((c=i==null?void 0:i.data)==null?void 0:c.label)||(a==null?void 0:a.label)||"").trim()||s||r}function ty(e,t,n="Workspace Run"){const r=String(e||"").trim()||n,s=String(t||"").trim();return!s||r===s?r:`${r} (${s})`}function ca(e){const t=Math.max(0,Number(e)||0);if(t<1e3)return`${t}ms`;if(t<6e4)return`${(t/1e3).toFixed(t<1e4?1:0)}s`;const n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return`${n}m${r?`${r}s`:""}`}function Oj(e){const t=String(e||"").trim().toLowerCase();return{unselected:"未选择需求",unavailable:"未连接",json_unsupported:"待升级",command_failed:"读取失败",uninitialized:"未初始化",preflight_blocked:"环境阻塞",tech_design_missing:"缺技术方案",tech_design_draft_review:"方案待确认",tech_design_confirmed:"方案已确认",baseline_missing:"缺基线",plan_missing:"缺计划",plan_draft_review:"计划待确认",issue_binding_missing:"待绑定 Issue",ready_for_implementation:"待实现",implementation_ready:"待实现",implementing:"实现中",implementation_in_progress:"实现中",implementation_review:"实现待审",self_test_ready:"待自测",bugfix:"修 Bug",fix_ready:"待修复",fix_in_progress:"修复中",testing:"已提测",done:"完成",blocked:"阻塞",conflict:"冲突",requirement_changed:"需求变更"}[t]||t||"未知"}function rq(e){const t=String(e||"").trim().toLowerCase();return!t||["unselected","unavailable","json_unsupported","command_failed","uninitialized","preflight_blocked"].includes(t)?-1:/done|complete|closed|finished/.test(t)?3:/bug|fix|testing|test|self_test|submit_test/.test(t)?2:/implement|development|ready_for_implementation|issue_binding|gitlab|mr/.test(t)?1:0}function sq(e){const t=rq(e);return["方案确定","开发","Bug 修复","完成"].map((n,r)=>{let s="pending";return t>r?s="done":t===r&&(s=r===3?"done":"current"),{label:n,status:s}})}function LI(e){const t=String(e||"").trim();if(!/^https?:\/\//i.test(t))return t;try{const n=new URL(t);if(n.hostname==="0.0.0.0"||n.hostname==="::"||n.hostname==="[::]"){const r=window.location.hostname;n.hostname=r&&r!=="0.0.0.0"&&r!=="::"?r:"127.0.0.1"}return n.href}catch{return t}}function OI(e){const t=String((e==null?void 0:e.url)||(e==null?void 0:e.href)||"").trim();if(t)return LI(t);const n=String((e==null?void 0:e.path)||"").trim();return n?`file://${n}`:""}function Ko(e){const t=String(e||"").trim().toLowerCase();return["done","success","completed","passed"].includes(t)?"done":["current","running","active","next"].includes(t)?"current":["observed","observation"].includes(t)?"observed":["superseded","stale","replaced"].includes(t)?"superseded":["blocked","failed","error","conflict"].includes(t)?"blocked":"pending"}function Ma(e){if(!e||typeof e!="object")return"";const t=String(e.truth||e.stateTruth||e.state_truth||"").trim().toLowerCase();return t||(String(e.idempotencyKey||e.idempotency_key||"").trim().startsWith("snapshot-action:")||String(e.source||"")==="prd-flow-client"&&String(e.type||"")==="workflow-action"?"observation":String(e.type||"")==="review-link"?"runtime_event":"")}function rk(e){return Ko(e==null?void 0:e.status)==="done"&&Ma(e)!=="observation"}function Fi(e,t){return!e||typeof e!="object"?`Action ${t+1}`:String(e.title||e.label||e.name||e.actionLabel||e.action_label||e.id||e.action||`Action ${t+1}`)}function jp(e){return!e||typeof e!="object"?"":String(e.detail||e.description||e.summary||e.message||e.reason||"")}function sk(e){return!e||typeof e!="object"?"":[e.code,e.action,e.actionId,e.action_id,e.stage,e.stageKey,e.stage_key,e.type,e.title].map(t=>String(t||"")).join(" ").toLowerCase()}function iq(e,t="当前任务"){const r=[e==null?void 0:e.issueLabel,e==null?void 0:e.issue_label,e==null?void 0:e.title,e==null?void 0:e.label,e==null?void 0:e.name].map(s=>String(s||"")).join(" ").match(/\b(Issue\d+|Bug\d+)\b/i);return r?r[1].replace(/^issue/i,"Issue").replace(/^bug/i,"Bug"):t}function oq(e,t){const n=Fi(e,t),r=Ko(e==null?void 0:e.status),s=rk(e),a=`${$a(e)} ${sk(e)}`,l=iq(e);if(/issue-plan:|plan_draft_local|submit-plan|plan-doc|plan_doc_confirmed/.test(a)){if(s)return`${l} 方案已确认`;if(r==="observed"||r==="superseded"||Ma(e)==="observation")return`${l} 方案状态已观察`;if(r==="current"&&/^确认\s+/.test(n))return n}if(/issue-gitlab:|gitlab_issue_missing|ensure-gitlab-issue/.test(a)){if(s)return`已为 ${l} 创建/绑定 GitLab Issue`;if(r==="observed"||r==="superseded"||Ma(e)==="observation")return`${l} GitLab Issue 状态已观察`}return/implementation_in_progress|impl_in_progress/.test(a)?`正在实现 ${l}`:/implementation_ready/.test(a)?`可以开始实现 ${l}`:n}function aq(e){if(!e||typeof e!="object")return"";const t=Ko(e.status),n=Ma(e),r=rk(e),i=`${$a(e)} ${sk(e)}`,a=ik(e),l=a.some(d=>/方案|plan|markdown|review|预览/i.test(String(d.label||""))),c=a.some(d=>/gitlab issue/i.test(String(d.label||""))),u=a.some(d=>/gitlab epic/i.test(String(d.label||"")));if(/issue-plan:|plan_draft_local|submit-plan|plan-doc|plan_doc_confirmed/.test(i))return r?l?"方案已确认并归档;可从下方打开方案文档预览。":"方案已确认并归档。":n==="observation"||t==="observed"?"客户端上报了当前方案阶段;这不是 ai-doc 确认结果。":t==="superseded"?"该客户端观察已被更新状态替代,仅保留为运行态记录。":t==="current"?"方案草稿已生成,等待确认;确认后会归档为正式方案。":"方案草稿已生成,等待确认。";if(/issue-gitlab:|gitlab_issue_missing|ensure-gitlab-issue/.test(i))return r?c&&u?"GitLab Issue 和 Epic 已绑定;可从下方打开关联链接。":c?"GitLab Issue 已绑定;可从下方打开关联链接。":"GitLab Issue 绑定步骤已完成。":n==="observation"||t==="observed"?"客户端上报了 GitLab Issue 阶段;是否已绑定以 GitLab/ai-doc 事实为准。":t==="superseded"?"该客户端观察已被更新状态替代,仅保留为运行态记录。":"方案文档已归档,等待创建或绑定 GitLab Issue。";if(/implementation_in_progress|impl_in_progress/.test(i))return"需求分支已就绪,当前处于实现中;实现 MR 创建后会记录到本 Issue。";if(/implementation_ready/.test(i))return"方案文档和 GitLab Issue 已就绪,等待开始实现。";const p=jp(e);return p?p.length>180&&a.length?"相关结果和产物已更新;可从下方链接查看。":p:""}function yh(e){return!e||typeof e!="object"?"":String(e.time||e.at||e.observedAt||e.observed_at||e.reportedAt||e.reported_at||e.startedAt||e.started_at||e.completedAt||e.completed_at||e.updatedAt||e.updated_at||e.createdAt||e.created_at||"")}const DI="Asia/Shanghai",lq=new Intl.DateTimeFormat("zh-CN",{timeZone:DI,year:"numeric",month:"2-digit",day:"2-digit"}),cq=new Intl.DateTimeFormat("zh-CN",{timeZone:DI,hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});function FI(e){const t=yh(e);if(!t)return null;const n=Date.parse(t);return Number.isFinite(n)?new Date(n):null}function uq(e){const t=FI(e);return t?lq.format(t).replace(/\//g,"-"):"无时间"}function dq(e){const t=FI(e);return t?cq.format(t):""}function fq(e=[]){const t=[];return(Array.isArray(e)?e:[]).forEach((n,r)=>{const s=uq(n);let i=t[t.length-1];(!i||i.day!==s)&&(i={day:s,items:[]},t.push(i)),i.items.push({item:n,index:r})}),t}function zI(e){const t=Ko(e);return t==="done"?"完成":t==="current"?"当前":t==="observed"?"已观察":t==="superseded"?"已更新":t==="blocked"?"阻塞":"待处理"}function pq(e){const t=Ko(e==null?void 0:e.status);return Ma(e)==="observation"&&t==="done"?"已观察":zI(t)}function BI(e){if(!e||typeof e!="object")return[];const t=[],n=(i,a,l)=>{const c=String(l||"").trim();c&&t.push({key:`${i}:${c}`,type:i,label:String(a||c),value:c})},r=Ko(e.status),s=Ma(e)==="observation"&&r==="done"?"observed":r;return n("status",zI(s),s),n("issue",e.issueKey||e.issue_key||e.issue,e.issueKey||e.issue_key||e.issue),n("platform",e.platform,e.platform),t}function hq(e=[]){const t=new Map;return(Array.isArray(e)?e:[]).forEach(n=>{BI(n).forEach(r=>{const s=t.get(r.key);t.set(r.key,{...r,count:((s==null?void 0:s.count)||0)+1})})}),Array.from(t.values()).sort((n,r)=>{const s={status:0,issue:1,platform:2,source:3,actor:4};return(s[n.type]??9)-(s[r.type]??9)||r.count-n.count||n.label.localeCompare(r.label)})}function mq(e,t){const n=String(t||"all");return!n||n==="all"?!0:BI(e).some(r=>r.key===n)}function gq(e){if(!e||typeof e!="object")return[];const t=[],n=(r,s)=>{const i=String(s||"").trim();i&&t.push({label:r,value:i})};return n("Issue",e.issueKey||e.issue_key||e.issue),n("端",e.platform),t}function ik(e){const t=[],n=(c,u)=>{const p=LI(u);p&&t.push({label:String(c||p).trim()||p,href:p})},r=(c,u="链接",p=0)=>{if(p>3||c==null)return;if(typeof c=="string"){(/^(https?:\/\/|file:\/\/)/i.test(c)||c.startsWith("/"))&&n(u,c);return}if(Array.isArray(c)){c.forEach((f,h)=>r(f,`${u} ${h+1}`,p+1));return}if(typeof c!="object")return;const d=c.label||c.title||c.name||c.kind||c.type||u;n(d,c.url||c.href||c.path||c.file||c.filePath||c.file_path);for(const f of["links","urls","artifacts","outputs","output","results","result","files"])c[f]!=null&&r(c[f],f,p+1)},s=Array.isArray(e==null?void 0:e.links)?e.links:[];for(const c of s)typeof c=="string"?n("链接",c):n((c==null?void 0:c.label)||(c==null?void 0:c.title)||(c==null?void 0:c.kind)||"链接",(c==null?void 0:c.url)||(c==null?void 0:c.href));for(const c of Array.isArray(e==null?void 0:e.artifacts)?e.artifacts:[])n((c==null?void 0:c.label)||(c==null?void 0:c.title)||(c==null?void 0:c.kind)||"Artifact",OI(c));n("TAPD",(e==null?void 0:e.tapdUrl)||(e==null?void 0:e.tapd_url)),n("ai-doc",(e==null?void 0:e.docUrl)||(e==null?void 0:e.doc_url)||(e==null?void 0:e.aiDocUrl)||(e==null?void 0:e.ai_doc_url)),n("Plan",(e==null?void 0:e.planDocUrl)||(e==null?void 0:e.plan_doc_url)||(e==null?void 0:e.planUrl)||(e==null?void 0:e.plan_url)),n("Issue",(e==null?void 0:e.issueUrl)||(e==null?void 0:e.issue_url)),n("GitLab Issue",(e==null?void 0:e.gitlabIssue)||(e==null?void 0:e.gitlab_issue)),n("GitLab Epic",(e==null?void 0:e.gitlabEpic)||(e==null?void 0:e.gitlab_epic)),n("MR",(e==null?void 0:e.mrUrl)||(e==null?void 0:e.mr_url)||(e==null?void 0:e.mergeRequestUrl)||(e==null?void 0:e.merge_request_url)),n("实现 MR",(e==null?void 0:e.implMr)||(e==null?void 0:e.impl_mr)),n("修复 MR",(e==null?void 0:e.fixMr)||(e==null?void 0:e.fix_mr)),n("提测 MR",(e==null?void 0:e.testMr)||(e==null?void 0:e.test_mr)),n("集成 MR",(e==null?void 0:e.integrationMr)||(e==null?void 0:e.integration_mr)),n("Jenkins",(e==null?void 0:e.jenkinsUrl)||(e==null?void 0:e.jenkins_url)||(e==null?void 0:e.jenkinsBuildUrl)||(e==null?void 0:e.jenkins_build_url)),n("安装包",(e==null?void 0:e.jenkinsPackageUrl)||(e==null?void 0:e.jenkins_package_url)),n("二维码",(e==null?void 0:e.jenkinsQrUrl)||(e==null?void 0:e.jenkins_qr_url)),n("调整",(e==null?void 0:e.editUrl)||(e==null?void 0:e.edit_url)||(e==null?void 0:e.adjustUrl)||(e==null?void 0:e.adjust_url)),n("链接",(e==null?void 0:e.url)||(e==null?void 0:e.href)),r(e==null?void 0:e.urls,"URL"),r(e==null?void 0:e.outputs,"产物"),r(e==null?void 0:e.output,"产物"),r(e==null?void 0:e.results,"结果"),r(e==null?void 0:e.result,"结果"),r(e==null?void 0:e.files,"文件");const i=c=>{const u=String(c||"").trim();try{const p=new URL(u,window.location.origin);return`${p.origin}${p.pathname}`}catch{return u.split(/[?#]/)[0]}},a=c=>{const u=String(c||"");return/方案文档/.test(u)?50:/临时/.test(u)?40:/Markdown Review/i.test(u)?20:/预览|review/i.test(u)?10:0},l=new Map;for(const c of t){const u=/\/api\/prd-workflow\/review\//.test(String(c.href||"")),p=u?`review:${i(c.href)}`:`${c.label}
184
184
  ${c.href}`,d=l.get(p);if(!d){l.set(p,c);continue}if(u){const f=a(d.label),h=a(c.label);(h>f||h===f&&String(c.label||"").length>String(d.label||"").length)&&l.set(p,c)}}return Array.from(l.values())}function yq(e){return!e||typeof e!="object"?{}:{marker:e.marker||e.flag||"",command:e.command||e.nextCommand||e.next_command||"",runtimeOnly:e.runtimeOnly===!0||e.runtime_only===!0,markerOnly:e.markerOnly===!0||e.marker_only===!0,url:e.url||e.href||e.mrUrl||e.mr_url||e.mergeRequestUrl||e.merge_request_url||"",mr:e.mr||e.mrUrl||e.mr_url||e.mergeRequestUrl||e.merge_request_url||"",testEnv:e.testEnv||e.test_environment||"",summary:e.summary||e.detail||e.description||"",links:Array.isArray(e.links)?e.links:[],artifacts:Array.isArray(e.artifacts)?e.artifacts:[],outputs:Array.isArray(e.outputs)?e.outputs:[],results:Array.isArray(e.results)?e.results:[]}}function bo(e,t=0){return String((e==null?void 0:e.key)||(e==null?void 0:e.issueKey)||(e==null?void 0:e.issue_key)||(e==null?void 0:e.id)||(e==null?void 0:e.iid)||(e==null?void 0:e.title)||`issue-${t+1}`).trim()}function Dj(e,t=0){return String((e==null?void 0:e.title)||(e==null?void 0:e.name)||(e==null?void 0:e.label)||(e==null?void 0:e.summary)||bo(e,t)||`Issue ${t+1}`).trim()}function xq(e){return String((e==null?void 0:e.epicKey)||(e==null?void 0:e.epic_key)||(e==null?void 0:e.epic)||(e==null?void 0:e.epicTitle)||(e==null?void 0:e.epic_title)||(e==null?void 0:e.parentEpic)||(e==null?void 0:e.parent_epic)||"未归类").trim()}function wq(e){return String((e==null?void 0:e.parentKey)||(e==null?void 0:e.parent_key)||(e==null?void 0:e.parent)||(e==null?void 0:e.parentIssue)||(e==null?void 0:e.parent_issue)||"").trim()}function Fj(e){const t=ik(e),n=(s,i)=>{if(Array.isArray(s)){for(const a of s)if(a)if(typeof a=="string")t.push({label:i,href:a});else{const l=a.url||a.href||a.webUrl||a.web_url||a.mrUrl||a.mr_url||a.issueUrl||a.issue_url;l&&t.push({label:a.label||a.title||a.platform||a.kind||i,href:l})}}};n(e==null?void 0:e.mrs,"MR"),n(e==null?void 0:e.mergeRequests,"MR"),n(e==null?void 0:e.merge_requests,"MR"),n(e==null?void 0:e.implMrs,"MR"),n(e==null?void 0:e.impl_mrs,"MR"),n(e==null?void 0:e.platformMrs,"MR"),n(e==null?void 0:e.platform_mrs,"MR");const r=new Set;return t.filter(s=>{const i=String(s.href||"").trim();if(!i)return!1;const a=`${s.label}
185
185
  ${i}`;return r.has(a)?!1:(r.add(a),!0)})}function bq(e){const t=Array.isArray(e==null?void 0:e.epics)?e.epics:Array.isArray(e==null?void 0:e.epicGroups)?e.epicGroups:Array.isArray(e==null?void 0:e.epic_groups)?e.epic_groups:[],n=[],r=new Map,s=(a,l="")=>{const c=String(a||"未归类").trim()||"未归类";return r.has(c)?l&&r.get(c).title===c&&(r.get(c).title=String(l)):r.set(c,{key:c,title:String(l||c),issues:[]}),r.get(c)};for(const a of t){const l=String((a==null?void 0:a.key)||(a==null?void 0:a.id)||(a==null?void 0:a.title)||(a==null?void 0:a.name)||"未归类").trim(),c=s(l,(a==null?void 0:a.title)||(a==null?void 0:a.name)||l),u=Array.isArray(a==null?void 0:a.issues)?a.issues:Array.isArray(a==null?void 0:a.children)?a.children:Array.isArray(a==null?void 0:a.items)?a.items:[];for(const p of u)p&&typeof p=="object"&&c.issues.push({...p,epicKey:l})}for(const a of Array.isArray(e==null?void 0:e.issues)?e.issues:[])a&&typeof a=="object"&&n.push(a);for(const a of n)s(xq(a)).issues.push(a);const i=a=>{const l=new Map,c=[];return a.forEach((u,p)=>{const d=bo(u,p);l.set(d,{issue:u,children:[]})}),a.forEach((u,p)=>{const d=bo(u,p),f=wq(u),h=l.get(d);f&&l.has(f)?l.get(f).children.push(h):c.push(h)}),c};return Array.from(r.values()).map(a=>({...a,issues:i(a.issues)}))}function ad(e){return String((e==null?void 0:e.actionId)||(e==null?void 0:e.action_id)||(e==null?void 0:e.action)||(e==null?void 0:e.id)||"").trim()}function $a(e){if(!e||typeof e!="object")return"";const t=String(e.issueKey||e.issue_key||e.issue||"").trim(),n=String(e.action||e.actionId||e.action_id||ad(e)||"").trim(),r=String(e.stageKey||e.stage_key||e.stage||e.phase||e.code||e.pointer||n).trim(),s=[r,n,e.code,e.type,e.title].map(i=>String(i||"")).join(" ").toLowerCase();if(t){if(/plan_draft_local|submit-plan|plan-doc/.test(s))return`issue-plan:${t}`;if(/gitlab_issue_missing|ensure-gitlab-issue/.test(s))return`issue-gitlab:${t}`}return r}function xh(e){const t=yh(e)||String((e==null?void 0:e.startedAt)||(e==null?void 0:e.started_at)||(e==null?void 0:e.createdAt)||(e==null?void 0:e.created_at)||(e==null?void 0:e.updatedAt)||(e==null?void 0:e.updated_at)||""),n=Date.parse(t);return Number.isFinite(n)?n:NaN}function kq(e){var s,i,a,l,c,u,p,d,f,h,g,k;const t=[],n=w=>{w&&typeof w=="object"&&!Array.isArray(w)&&t.push(w)},r=w=>{if(!w||typeof w!="object"||Array.isArray(w))return;const y=Array.isArray(w.issues)?w.issues:Array.isArray(w.children)?w.children:Array.isArray(w.items)?w.items:[];for(const v of y)!v||typeof v!="object"||Array.isArray(v)||(v.issue&&typeof v.issue=="object"?(n(v.issue),Array.isArray(v.children)&&v.children.forEach(x=>n((x==null?void 0:x.issue)||x))):n(v))};return[e==null?void 0:e.issues,(s=e==null?void 0:e.raw)==null?void 0:s.issues,(a=(i=e==null?void 0:e.raw)==null?void 0:i.prd)==null?void 0:a.issues].forEach(w=>{Array.isArray(w)&&w.forEach(n)}),[e==null?void 0:e.epics,e==null?void 0:e.epicGroups,e==null?void 0:e.epic_groups,(l=e==null?void 0:e.raw)==null?void 0:l.epics,(c=e==null?void 0:e.raw)==null?void 0:c.epicGroups,(u=e==null?void 0:e.raw)==null?void 0:u.epic_groups,(d=(p=e==null?void 0:e.raw)==null?void 0:p.prd)==null?void 0:d.epics,(h=(f=e==null?void 0:e.raw)==null?void 0:f.prd)==null?void 0:h.epicGroups,(k=(g=e==null?void 0:e.raw)==null?void 0:g.prd)==null?void 0:k.epic_groups].forEach(w=>{Array.isArray(w)&&w.forEach(r)}),t}function vq(e,t){const n=String(t||"").trim();return n&&kq(e).find((r,s)=>bo(r,s)===n)||null}function Sq(e){var t,n,r,s,i,a,l,c;return String((e==null?void 0:e.gitlabEpic)||(e==null?void 0:e.gitlab_epic)||((t=e==null?void 0:e.prd)==null?void 0:t.gitlabEpic)||((n=e==null?void 0:e.prd)==null?void 0:n.gitlab_epic)||((r=e==null?void 0:e.raw)==null?void 0:r.gitlabEpic)||((s=e==null?void 0:e.raw)==null?void 0:s.gitlab_epic)||((a=(i=e==null?void 0:e.raw)==null?void 0:i.prd)==null?void 0:a.gitlabEpic)||((c=(l=e==null?void 0:e.raw)==null?void 0:l.prd)==null?void 0:c.gitlab_epic)||"").trim()}function Nq(e,t){if(!t||typeof t!="object")return t;const n=String(t.issueKey||t.issue_key||t.issue||"").trim(),r=vq(e,n),s=String((r==null?void 0:r.gitlabIssue)||(r==null?void 0:r.gitlab_issue)||t.gitlabIssue||t.gitlab_issue||"").trim(),i=Sq(e);if(!s&&!i)return t;const a=$a(t),l=`${a} ${sk(t)}`;if(!/issue-gitlab:|gitlab_issue_missing|ensure-gitlab-issue|implementation|impl_|fix_|testing|submit-test|self-test/i.test(l))return t;const u=[];s&&u.push({label:"GitLab Issue",kind:"gitlab-issue",durability:"durable",url:s}),i&&u.push({label:"GitLab Epic",kind:"gitlab-epic",durability:"durable",url:i});const p=Ko(t.status),d=s&&p==="done"&&/^issue-gitlab:/.test(a)&&/需要.*GitLab Issue/.test(String(t.title||t.label||""));return{...t,...s?{gitlabIssue:s,gitlab_issue:s}:{},...i?{gitlabEpic:i,gitlab_epic:i}:{},...d?{title:String(t.title||t.label||"GitLab Issue 已绑定").replace(/^需要为/,"已为").replace("创建或绑定","创建/绑定"),label:String(t.label||t.title||"GitLab Issue 已绑定").replace(/^需要为/,"已为").replace("创建或绑定","创建/绑定")}:{},artifacts:li(t.artifacts,u)}}function li(e,t){const n=[],r=new Set,s=i=>{if(!i)return;const a=typeof i=="string"?i:JSON.stringify(i);r.has(a)||(r.add(a),n.push(i))};return(Array.isArray(e)?e:[]).forEach(s),(Array.isArray(t)?t:[]).forEach(s),n}function zj(e,t){const n=xh(t),r=xh(e),s=Number.isFinite(n)&&(!Number.isFinite(r)||n>=r)?t:e,i=(s==null?void 0:s.status)||(t==null?void 0:t.status)||(e==null?void 0:e.status);return{...e,...t,title:Fi(s,0)||Fi(t,0)||Fi(e,0),detail:jp(s)||jp(t)||jp(e),status:i,links:li(e==null?void 0:e.links,t==null?void 0:t.links),artifacts:li(e==null?void 0:e.artifacts,t==null?void 0:t.artifacts),outputs:li(e==null?void 0:e.outputs,t==null?void 0:t.outputs),results:li(e==null?void 0:e.results,t==null?void 0:t.results),events:li(e==null?void 0:e.events,t==null?void 0:t.events),createdAt:(e==null?void 0:e.createdAt)||(e==null?void 0:e.created_at)||(t==null?void 0:t.createdAt)||(t==null?void 0:t.created_at),startedAt:(e==null?void 0:e.startedAt)||(e==null?void 0:e.started_at)||(t==null?void 0:t.startedAt)||(t==null?void 0:t.started_at),updatedAt:(s==null?void 0:s.updatedAt)||(s==null?void 0:s.updated_at)||(t==null?void 0:t.updatedAt)||(t==null?void 0:t.updated_at)||(e==null?void 0:e.updatedAt)||(e==null?void 0:e.updated_at)}}function jq(e,t){const n=[],r=new Map,s=new Map,i=new Map,a=d=>{var f,h;return!!(!d||typeof d!="object"||d.auxiliary===!0||d.auxiliary_event===!0||String(d.type||"")==="review-link"||String(d.type||"")==="action-preview"||d.preview===!0||String(d.type||"")==="same-platform-stage-conflict"&&/\/api\/prd-workflow\/review\//.test(String(((f=d.conflict)==null?void 0:f.previousArtifact)||((h=d.conflict)==null?void 0:h.incomingArtifact)||"")))},l=(d,f)=>({...d,links:li(d==null?void 0:d.links,f==null?void 0:f.links),artifacts:li(d==null?void 0:d.artifacts,f==null?void 0:f.artifacts),outputs:li(d==null?void 0:d.outputs,f==null?void 0:f.outputs),results:li(d==null?void 0:d.results,f==null?void 0:f.results)}),c=(d,f)=>{if(!d)return;const h=r.get(d);if(h!=null){n[h]=l(n[h],f);return}i.set(d,l(i.get(d)||{},f))},u=(d,f)=>d&&i.has(d)?l(f,i.get(d)):f,p=d=>{if(Array.isArray(d))for(const f of d){const h=$a(f);if(a(f)){c(h,f);continue}const g=String(f.id||f.eventId||f.event_id||f.actionId||f.action_id||"").trim(),k=h||g,w=k?r.get(k)??s.get(g):null;k&&w!=null?(n[w]=u(h,zj(n[w],f)),h&&r.set(h,w),g&&s.set(g,w)):(k&&r.set(k,n.length),g&&s.set(g,n.length),n.push(u(h,f)))}};if(p(e==null?void 0:e.actions),p(e==null?void 0:e.workflowActions),p(e==null?void 0:e.workflow_actions),p(e==null?void 0:e.timeline),p(e==null?void 0:e.history),p(e==null?void 0:e.events),p(e==null?void 0:e.runtimeEvents),p(e==null?void 0:e.runtime_events),t&&typeof t=="object"){const d=ad(t),f=$a(t),h=f?r.get(f):d?s.get(d):null,g={...t,status:t.status||"next",kind:"next_action"};h!=null?n[h]=zj(n[h],g):n.push(g)}return n.map((d,f)=>({item:d,index:f,ts:xh(d)})).sort((d,f)=>{const h=Number.isFinite(d.ts),g=Number.isFinite(f.ts);return h&&g?f.ts-d.ts||d.index-f.index:h?-1:g?1:d.index-f.index}).map(d=>Nq(e,d.item))}function Cq(e){return(Array.isArray(e==null?void 0:e.runtimeEvents)?e.runtimeEvents:Array.isArray(e==null?void 0:e.runtime_events)?e.runtime_events:[]).filter(n=>n&&typeof n=="object").map((n,r)=>({item:n,index:r,ts:xh(n)})).sort((n,r)=>{const s=Number.isFinite(n.ts),i=Number.isFinite(r.ts);return s&&i?r.ts-n.ts||r.index-n.index:s?-1:i?1:r.index-n.index}).slice(0,8).map(n=>n.item)}function _q(e,t){const n=String(t||"all");if(n==="all")return!0;const r=[e==null?void 0:e.status,e==null?void 0:e.type,e==null?void 0:e.kind,e==null?void 0:e.title,e==null?void 0:e.detail,e==null?void 0:e.error,JSON.stringify((e==null?void 0:e.links)||[]),JSON.stringify((e==null?void 0:e.artifacts)||[])].join(" ").toLowerCase();return n==="errors"?/error|failed|conflict|blocked|stale|revision|冲突|失败/.test(r):n==="review"?/review|temporary-review|临时/.test(r):n==="external"?/mr|merge request|gitlab|jenkins|package|build|tapd/.test(r):!0}function Eq(e,t){const n=typeof e=="string"?e:String((e==null?void 0:e.text)||""),r=typeof e=="object"?Number(e==null?void 0:e.stepMs):NaN,s=typeof e=="object"?Number(e==null?void 0:e.totalMs):NaN,i=Number.isFinite(r)&&Number.isFinite(s)?`(+${ca(r)} / 总 ${ca(s)})`:"";return`${t+1}. ${n}${i}`}function HI(e){if(String((e==null?void 0:e.type)||"")!=="raw")return null;const t=String((e==null?void 0:e.text)||"").trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}function fl(...e){for(const t of e){const n=Number(t);if(Number.isFinite(n))return n}return NaN}function Aq(e){const t=e!=null&&e.tool_call&&typeof e.tool_call=="object"?e.tool_call:{},n=Object.keys(t).find(r=>/ToolCall$/i.test(r))||"";return n||String((e==null?void 0:e.name)||(e==null?void 0:e.tool)||"tool_call")}function Pq(e){const t=e!=null&&e.tool_call&&typeof e.tool_call=="object"?e.tool_call:{},n=Object.keys(t).find(r=>/ToolCall$/i.test(r))||"";return n&&t[n]&&typeof t[n]=="object"?t[n]:{}}function Iq(e,t){var s;const n=String(((s=t==null?void 0:t.args)==null?void 0:s.command)||"");return/ck_fetch\.py/.test(n)?"CK 查询":/collect_important_mails\.py|list_mails_by_date\.py|read_mail_content\.py/.test(n)?"邮件脚本":/npm\s+run\s+build|build:web-ui/.test(n)?"前端构建":/python3/.test(n)?"Python 脚本":{shellToolCall:"Shell 命令",readToolCall:"读取文件/上下文",grepToolCall:"搜索代码",globToolCall:"查找文件",editToolCall:"编辑文件",writeToolCall:"写入文件"}[e]||e||"工具调用"}function Tq(e){var i,a,l;const t=HI(e);if(!t||typeof t!="object")return null;const n=String(t.type||""),r=String(t.subtype||""),s=fl(t.timestamp_ms,t.completedAtMs,t.startedAtMs,e==null?void 0:e.ts,Date.now());if(n==="tool_call"&&r==="completed"){const c=Pq(t),u=Aq(t),p=fl(t.startedAtMs,c==null?void 0:c.startedAtMs),d=fl(t.completedAtMs,c==null?void 0:c.completedAtMs),f=((i=c==null?void 0:c.result)==null?void 0:i.success)||((a=c==null?void 0:c.result)==null?void 0:a.failure)||{},h=Number.isFinite(p)&&Number.isFinite(d)?Math.max(0,d-p):fl(f.executionTime,f.localExecutionTimeMs),g=String(((l=c==null?void 0:c.args)==null?void 0:l.command)||f.command||"").trim(),k=g?g.split(`
@@ -15,7 +15,7 @@
15
15
  href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0"
16
16
  rel="stylesheet"
17
17
  />
18
- <script type="module" crossorigin src="/assets/index-CYwUDlvT.js"></script>
18
+ <script type="module" crossorigin src="/assets/index-b0Rwi6Tw.js"></script>
19
19
  <link rel="stylesheet" crossorigin href="/assets/index-DV-QkHHi.css">
20
20
  </head>
21
21
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fieldwangai/agentflow",
3
- "version": "0.1.94",
3
+ "version": "0.1.95",
4
4
  "description": "Orchestration system for long-running complex agent tasks using Cursor, OpenCode, Claude Code, or Codex as execution backends",
5
5
  "type": "module",
6
6
  "main": "bin/agentflow.mjs",