Refine simulation batch timestamps and update source messaging
This commit is contained in:
1 parent
d00fa1b960
commit
d77c0505d8
5 files changed
+69
-9
No files matched your search
@@ -529,6 +529,7 @@ seal-use simulation search "任务 fe1993e4" --since 7d --all --corp <corpId>
|
||||
```
|
||||
|
||||
> **本地聚合,不是云端原生检索**:`/api/v1/simulation/batches` 只有 `limit`/`offset`,没有名称或关键词检索,批次对象也没有 `name` 字段(界面的「任务 fe1993e4」是 UUID 末 8 位)。`list --query/--since/--until` 与 `search` 都是 CLI 先把批次拉到本地再过滤,返回体固定带 `retrieval: { mode: "local_scan", serverSideSearch: false, scanned }`;命中范围以 `scanned` 为准,不覆盖未扫描的批次(`truncated: true` 时用 `--all` 或调大 `--max-scan`)。不要把它当作服务端能力向用户描述。
|
||||
> 每个批次返回 `id`、`status`、`approvalCode`、`sourceSystem`、`totalCount/processedCount/successCount/failedCount`、`requestSummary`、`resultSummary`、`createdAt`/`updatedAt`(北京时间秒级,如 `2026-10-10T14:38:17+08:00`)、`createdAtMs`(精确毫秒)、`flowIds`/`packageIds`/`packageLabel`/`templateId`,可据此直接核对界面任务与取数时间窗。
|
||||
|
||||
## Failure Handling
|
||||
|
||||
|
||||
@@ -160,18 +160,32 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
// `.old.<timestamp>` backup (undeletable while its image was executing).
|
||||
pruneUpdateLeftovers(process.execPath);
|
||||
|
||||
const releases = await fetchGitHubReleases(repo, 30);
|
||||
const { releases, source } = await fetchReleasesWithSource(repo, 30);
|
||||
const release = targetVersion
|
||||
? (releases.find((r) => r.version === targetVersion || r.tagName === targetVersion || r.tagName === `v${targetVersion}`) ??
|
||||
await fetchGitHubRelease(repo, targetVersion))
|
||||
: (releases[0] ?? await fetchGitHubRelease(repo));
|
||||
|
||||
if (!release) {
|
||||
const mirrorMode = getMirrorMode();
|
||||
const newest = releases[0]?.version;
|
||||
const wanted = targetVersion ? `v${targetVersion.replace(/^v/, "")}` : "最新版本";
|
||||
const sourcesTried = mirrorMode === "auto"
|
||||
? ["Gitea 国内镜像", "GitHub"]
|
||||
: mirrorMode === "gitea" ? ["Gitea 国内镜像"] : ["GitHub"];
|
||||
const message = targetVersion && newest
|
||||
? `${source === "gitea" ? "国内镜像(Gitea)" : "GitHub"} 尚未提供 ${wanted}(该源当前最新 v${newest})。已尝试的更新源:${sourcesTried.join("、")};镜像同步存在时间差,请稍后重试。`
|
||||
: `无法访问更新源(已尝试:${sourcesTried.join("、")})。请检查网络后重试。`;
|
||||
|
||||
printJson({
|
||||
updated: false,
|
||||
currentVersion: VERSION,
|
||||
mode: "binary",
|
||||
message: `Failed to query releases from repository '${repo}'`
|
||||
mirrorMode,
|
||||
sourcesTried,
|
||||
releaseSource: source,
|
||||
sourceLatestVersion: newest ?? null,
|
||||
message
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -445,7 +459,10 @@ export function getMirrorMode(): "auto" | "github" | "gitea" {
|
||||
return "auto";
|
||||
}
|
||||
|
||||
async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRelease[]> {
|
||||
async function fetchReleasesWithSource(
|
||||
repo: string,
|
||||
limit = 20
|
||||
): Promise<{ releases: GitHubRelease[]; source: "gitea" | "github" | null }> {
|
||||
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
||||
const headers: Record<string, string> = {
|
||||
"User-Agent": `seal-use/${VERSION}`,
|
||||
@@ -509,13 +526,20 @@ async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRele
|
||||
assets
|
||||
});
|
||||
}
|
||||
if (list.length > 0) return list;
|
||||
if (list.length > 0) {
|
||||
return { releases: list, source: url.includes("git.ying-qing.cn") ? "gitea" : "github" };
|
||||
}
|
||||
} catch {
|
||||
// try next source
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
return { releases: [], source: null };
|
||||
}
|
||||
|
||||
async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRelease[]> {
|
||||
const { releases } = await fetchReleasesWithSource(repo, limit);
|
||||
return releases;
|
||||
}
|
||||
|
||||
async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise<GitHubRelease | undefined> {
|
||||
|
||||
@@ -791,6 +791,15 @@ describe("simulation tool handlers", () => {
|
||||
}
|
||||
});
|
||||
expect((result.batches as Array<{ id: string }>)[0]?.id).toBe(newer.id);
|
||||
// 时间统一为北京时间秒级, 并附带 epoch 毫秒与单号标识, 便于核对界面任务
|
||||
expect((result.batches as Array<Record<string, unknown>>)[0]).toMatchObject({
|
||||
createdAt: "2026-10-10T14:38:17+08:00",
|
||||
createdAtMs: Date.parse("2026-10-10T06:38:17.757Z"),
|
||||
updatedAt: "2026-08-24T16:50:16+08:00",
|
||||
flowIds: ["B26017701"],
|
||||
packageIds: [],
|
||||
templateId: null
|
||||
});
|
||||
});
|
||||
|
||||
test("list tool paginates when all=true is requested", async () => {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import * as helpers from "./helpers.js";
|
||||
import { parseDurationMs } from "../../../core/duration.js";
|
||||
import {
|
||||
batchTimestampMs,
|
||||
collectSimulationBatches,
|
||||
DEFAULT_SIMULATION_MAX_SCAN,
|
||||
DEFAULT_SIMULATION_SCAN_LIMIT,
|
||||
@@ -28,6 +29,26 @@ const {
|
||||
filterRuns
|
||||
} = helpers;
|
||||
|
||||
/**
|
||||
* 列表/检索的统一展示: 时间统一成北京时间秒级(附 epoch 毫秒便于精确比较),
|
||||
* 并带上单号/材料包标识, 让检索结果无需二次 get 就能对上界面里的任务。
|
||||
*/
|
||||
function presentSimulationBatch(batch: SimulationBatch) {
|
||||
const createdAtMs = batchTimestampMs(batch.createdAt);
|
||||
const updatedAtMs = batchTimestampMs(batch.updatedAt);
|
||||
|
||||
return {
|
||||
...summarizeSimulationBatch(batch),
|
||||
createdAt: createdAtMs === null ? (batch.createdAt ?? null) : formatBeijingIso(createdAtMs),
|
||||
createdAtMs,
|
||||
updatedAt: updatedAtMs === null ? (batch.updatedAt ?? null) : formatBeijingIso(updatedAtMs),
|
||||
flowIds: batch.params?.flowIds ?? [],
|
||||
packageIds: batch.params?.packageIds ?? [],
|
||||
packageLabel: batch.params?.packageLabel ?? null,
|
||||
templateId: batch.params?.templateId ?? null
|
||||
};
|
||||
}
|
||||
|
||||
export const simulationCapabilities = [
|
||||
{
|
||||
name: "sealSimulationFeishuApprovalDefinitionsList",
|
||||
@@ -265,7 +286,7 @@ export const simulationCapabilities = [
|
||||
until: untilMs === undefined ? null : formatBeijingIso(untilMs)
|
||||
},
|
||||
count: matched.length,
|
||||
batches: matched.map(summarizeSimulationBatch),
|
||||
batches: matched.map(presentSimulationBatch),
|
||||
next: {
|
||||
getBatch: "seal-use simulation get <batchId>",
|
||||
getRecords: "seal-use simulation batch-records <batchId>",
|
||||
|
||||
@@ -89,12 +89,17 @@ function batchHaystack(batch: SimulationBatch): string {
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
function batchCreatedAtMs(batch: SimulationBatch): number | null {
|
||||
if (batch.createdAt === undefined) return null;
|
||||
const ms = typeof batch.createdAt === "number" ? batch.createdAt : Date.parse(batch.createdAt);
|
||||
/** 批次时间戳既可能是 epoch 毫秒,也可能是上游原样返回的 ISO 字符串。 */
|
||||
export function batchTimestampMs(value: string | number | undefined): number | null {
|
||||
if (value === undefined) return null;
|
||||
const ms = typeof value === "number" ? value : Date.parse(value);
|
||||
return Number.isFinite(ms) ? ms : null;
|
||||
}
|
||||
|
||||
function batchCreatedAtMs(batch: SimulationBatch): number | null {
|
||||
return batchTimestampMs(batch.createdAt);
|
||||
}
|
||||
|
||||
export function filterSimulationBatches(
|
||||
batches: SimulationBatch[],
|
||||
filter: SimulationBatchFilter = {}
|
||||
|
||||
Reference in new issue
Block a user