forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartifact-serialization.ts
More file actions
31 lines (29 loc) · 1 KB
/
Copy pathartifact-serialization.ts
File metadata and controls
31 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { SerializedArtifact } from "../protocol.js";
import type { AgentArtifact } from "./types.js";
export function serializeArtifact(artifact: AgentArtifact): SerializedArtifact {
return {
artifactId: artifact.artifactId,
sessionId: artifact.sessionId,
runId: artifact.runId,
attemptId: artifact.attemptId,
kind: artifact.kind,
role: artifact.role,
uri: artifact.uri,
displayName: artifact.displayName,
mimeType: artifact.mimeType,
contentHash: artifact.contentHash,
sizeBytes: artifact.sizeBytes,
lifecycleState: artifact.lifecycleState,
lifecycleUpdatedAtMs: artifact.lifecycleUpdatedAtMs,
metadata: parseJsonObject(artifact.metadataJson),
createdAtMs: artifact.createdAtMs,
};
}
export function parseJsonObject(value: string): Record<string, unknown> {
try {
const parsed = JSON.parse(value);
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed as Record<string, unknown> : {};
} catch {
return {};
}
}