@agimon-ai/po-workflow 0.0.0-alpha.213 → 0.0.0-alpha.215

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.
@@ -2740,18 +2740,18 @@ var WorkflowRegistryService = class {
2740
2740
  }
2741
2741
  /**
2742
2742
  * List the current generation of every run across all workspaces or a single workspace.
2743
+ * `mentioning` skips latest runs whose saved state never names that text; callers still scope.
2744
+ * An invalid newest generation hides its key rather than resurrecting an older one.
2743
2745
  */
2744
- async listRuns(workspace) {
2746
+ async listRuns(workspace, mentioning) {
2745
2747
  const runs = await this.store.listRuns({
2746
2748
  authorityId: this.authorityId,
2747
- ...workspace ? { workspaceId: this.resolveWorkspace(workspace) } : {}
2749
+ ...workspace ? { workspaceId: this.resolveWorkspace(workspace) } : {},
2750
+ latestPerKey: true,
2751
+ ...mentioning === void 0 ? {} : { mentioning }
2748
2752
  });
2749
2753
  const records = [];
2750
- const seen = /* @__PURE__ */ new Set();
2751
2754
  for (const run of runs) {
2752
- const key = JSON.stringify([run.workspaceId, run.runKey]);
2753
- if (seen.has(key)) continue;
2754
- seen.add(key);
2755
2755
  const record = this.tryRecord(run);
2756
2756
  if (record) records.push(this.inspectRunning(record));
2757
2757
  }
@@ -12792,7 +12792,7 @@ async function readWorkflowRuns(runtime, options = {}) {
12792
12792
  };
12793
12793
  const scope = options.scope;
12794
12794
  const runs = [];
12795
- for (const record of await registry.listRuns()) {
12795
+ for (const record of await registry.listRuns(void 0, scope?.sessionId)) {
12796
12796
  const parsed = parseWorkflowRunRecord(JSON.stringify(record));
12797
12797
  if (parsed === void 0) continue;
12798
12798
  if (scope && !runBelongsToSession(parsed, scope.sessionId) && !(scope.launched && runLaunchedBySession(parsed, scope.sessionId))) continue;
@@ -14200,9 +14200,27 @@ var PoDbWorkflowStoreService = class PoDbWorkflowStoreService {
14200
14200
  return (await this.db.database.get("SELECT revision FROM workflow_runs WHERE run_id = ?", runId))?.revision;
14201
14201
  }
14202
14202
  async listRuns(input) {
14203
- return (await this.db.database.all(`SELECT * FROM workflow_runs WHERE authority_id = ? AND (? IS NULL OR workspace_id = ?)
14203
+ const filters = [
14204
+ input.authorityId,
14205
+ input.workspaceId ?? null,
14206
+ input.workspaceId ?? null,
14207
+ input.lifecycle ?? null,
14208
+ input.lifecycle ?? null,
14209
+ input.includeTombstoned ? 1 : 0
14210
+ ];
14211
+ if (!input.latestPerKey) return (await this.db.database.all(`SELECT * FROM workflow_runs WHERE authority_id = ? AND (? IS NULL OR workspace_id = ?)
14204
14212
  AND (? IS NULL OR lifecycle = ?) AND (? = 1 OR tombstoned_at IS NULL)
14205
- ORDER BY created_at DESC, generation DESC`, input.authorityId, input.workspaceId ?? null, input.workspaceId ?? null, input.lifecycle ?? null, input.lifecycle ?? null, input.includeTombstoned ? 1 : 0)).map(runFrom);
14213
+ ORDER BY created_at DESC, generation DESC`, ...filters)).map(runFrom);
14214
+ const needle = input.mentioning !== void 0 && JSON.stringify(input.mentioning) === `"${input.mentioning}"` ? input.mentioning : null;
14215
+ return (await this.db.database.all(`SELECT runs.* FROM (
14216
+ SELECT rowid AS run_rowid, ROW_NUMBER() OVER (PARTITION BY workspace_id, run_key
14217
+ ORDER BY created_at DESC, generation DESC, run_id DESC) AS row_rank
14218
+ FROM workflow_runs WHERE authority_id = ? AND (? IS NULL OR workspace_id = ?)
14219
+ AND (? IS NULL OR lifecycle = ?) AND (? = 1 OR tombstoned_at IS NULL)
14220
+ ) AS ranked
14221
+ JOIN workflow_runs AS runs ON runs.rowid = ranked.run_rowid
14222
+ WHERE ranked.row_rank = 1 AND (? IS NULL OR instr(runs.state, ?) > 0)
14223
+ ORDER BY runs.created_at DESC, runs.generation DESC, runs.run_id DESC`, ...filters, needle, needle)).map(runFrom);
14206
14224
  }
14207
14225
  async latestRun(input) {
14208
14226
  const row = await this.db.database.get(`SELECT * FROM workflow_runs WHERE authority_id = ? AND workspace_id = ? AND run_key = ? AND tombstoned_at IS NULL
@@ -20447,7 +20465,7 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
20447
20465
  ...scope ? { scope } : {}
20448
20466
  });
20449
20467
  const stale = /* @__PURE__ */ new Map();
20450
- for (const home of new Set(runs.filter((run) => run.view.stage === "running").map((run) => run.registryHome ?? ownHome))) for (const record of await featureFor(home).registry.listRuns()) if (record.stale) stale.set(`${home}/${record.workspace}/${record.runKey}`, record.staleReason);
20468
+ for (const home of new Set(runs.filter((run) => run.view.stage === "running").map((run) => run.registryHome ?? ownHome))) for (const record of await featureFor(home).registry.listRuns(void 0, scope?.sessionId)) if (record.stale) stale.set(`${home}/${record.workspace}/${record.runKey}`, record.staleReason);
20451
20469
  return runs.map((run) => run.view.stage === "running" && stale.has(`${run.registryHome ?? ownHome}/${run.view.workspace}/${run.view.runKey}`) ? {
20452
20470
  ...run,
20453
20471
  view: {