MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / artifactsSave

Function artifactsSave

packages/core/sdk/src/executor.ts:4793–4845  ·  view source on GitHub ↗
(
      input: SaveArtifactInput,
    )

Source from the content-addressed store, hash-verified

4791 });
4792
4793 const artifactsSave = (
4794 input: SaveArtifactInput,
4795 ): Effect.Effect<Artifact, ArtifactNotFoundError | StorageFailure> =>
4796 Effect.gen(function* () {
4797 const now = new Date();
4798 const description = input.description ?? null;
4799 // An explicit id overwrites in place (v1 keeps no version history). It
4800 // must already resolve to a visible row: minting a caller-chosen id
4801 // would let a stale client resurrect a deleted artifact silently.
4802 if (input.id !== undefined) {
4803 const where = artifactById(input.id);
4804 const existing = yield* core.findFirst("artifact", { where });
4805 if (!existing) {
4806 return yield* new ArtifactNotFoundError({ id: ArtifactId.make(input.id) });
4807 }
4808 // `bindings` is written on every overwrite, including back to null:
4809 // it interprets `code`, so carrying the previous value forward under
4810 // new source would bind roles the new code never declares. `preview`
4811 // is written for exactly the same reason, and the case it prevents is
4812 // visible: an image preview captured from the OLD render would
4813 // otherwise keep advertising a version of the artifact that no longer
4814 // exists.
4815 const set = {
4816 title: input.title,
4817 description,
4818 code: input.code,
4819 bindings: input.bindings ?? null,
4820 preview: input.preview ?? null,
4821 updated_at: now,
4822 };
4823 yield* core.updateMany("artifact", { where, set });
4824 return rowToArtifact({ ...existing, ...set });
4825 }
4826 yield* requireUserSubject("user");
4827 const keys = yield* Effect.try({
4828 try: () => ownedKeys("user"),
4829 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
4830 });
4831 const created = yield* core.create("artifact", {
4832 tenant: keys.tenant,
4833 owner: keys.owner,
4834 subject: keys.subject,
4835 id: `art_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
4836 title: input.title,
4837 description,
4838 code: input.code,
4839 bindings: input.bindings ?? null,
4840 preview: input.preview ?? null,
4841 created_at: now,
4842 updated_at: now,
4843 });
4844 return rowToArtifact(created);
4845 });
4846
4847 /**
4848 * Replace an artifact's preview with a snapshot of a settled render.

Callers

nothing calls this directly

Calls 6

rowToArtifactFunction · 0.90
artifactByIdFunction · 0.85
requireUserSubjectFunction · 0.85
ownedKeysFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected