@artinet/sdk
Version:
A TypeScript SDK for building collaborative AI agents.
29 lines (28 loc) • 912 B
JavaScript
/**
* Copyright 2025 The Artinet Project
* SPDX-License-Identifier: Apache-2.0
*/
export function updateArtifact(_artifact, update) {
if (!update.append)
return update.artifact;
const artifactUpdate = update.artifact;
const artifact = _artifact;
artifact.metadata = {
...(artifact.metadata || {}),
...artifactUpdate.metadata,
};
artifact.description = artifactUpdate.description;
artifact.name = artifactUpdate.name;
artifact.parts.push(...artifactUpdate.parts);
return artifact;
}
export function upsertArtifact(artifacts, update) {
const updateId = update.artifact.artifactId;
const index = artifacts.findIndex((a) => a.artifactId === updateId);
if (index === -1) {
artifacts.push({ ...update.artifact });
return artifacts;
}
artifacts[index] = updateArtifact(artifacts[index], update);
return artifacts;
}