

























@@ -39,6 +39,71 @@ function hasNonEmptyStringArray(value: unknown): boolean {
3939return Array.isArray(value) && value.some(hasNonEmptyString);
4040}
414142+function collectStringValues(value: unknown, output: Set<string>) {
43+if (typeof value === "string" && value.trim()) {
44+output.add(value.trim());
45+return;
46+}
47+if (!Array.isArray(value)) {
48+return;
49+}
50+for (const entry of value) {
51+if (typeof entry === "string" && entry.trim()) {
52+output.add(entry.trim());
53+}
54+}
55+}
56+57+function collectMediaUrlsFromRecord(record: Record<string, unknown>, output: Set<string>) {
58+collectStringValues(record.mediaUrl, output);
59+collectStringValues(record.mediaUrls, output);
60+collectStringValues(record.path, output);
61+collectStringValues(record.url, output);
62+collectStringValues(record.filePath, output);
63+const attachments = record.attachments;
64+if (Array.isArray(attachments)) {
65+for (const attachment of attachments) {
66+if (attachment && typeof attachment === "object" && !Array.isArray(attachment)) {
67+collectMediaUrlsFromRecord(attachment as Record<string, unknown>, output);
68+}
69+}
70+}
71+}
72+73+export function collectDeliveredMediaUrls(result: AgentDeliveryEvidence): string[] {
74+const urls = new Set<string>();
75+if (Array.isArray(result.payloads)) {
76+for (const payload of result.payloads) {
77+if (payload && typeof payload === "object" && !Array.isArray(payload)) {
78+collectMediaUrlsFromRecord(payload as Record<string, unknown>, urls);
79+}
80+}
81+}
82+collectStringValues(result.messagingToolSentMediaUrls, urls);
83+if (Array.isArray(result.messagingToolSentTargets)) {
84+for (const target of result.messagingToolSentTargets) {
85+if (target && typeof target === "object" && !Array.isArray(target)) {
86+collectMediaUrlsFromRecord(target as Record<string, unknown>, urls);
87+}
88+}
89+}
90+return Array.from(urls);
91+}
92+93+export function hasDeliveredExpectedMedia(
94+result: AgentDeliveryEvidence,
95+expectedMediaUrls: readonly string[],
96+): boolean {
97+const expected = Array.from(
98+new Set(expectedMediaUrls.map((url) => url.trim()).filter((url) => url.length > 0)),
99+);
100+if (expected.length === 0) {
101+return true;
102+}
103+const delivered = new Set(collectDeliveredMediaUrls(result));
104+return expected.every((url) => delivered.has(url));
105+}
106+42107function hasPositiveNumber(value: unknown): boolean {
43108return typeof value === "number" && Number.isFinite(value) && value > 0;
44109}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。