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

Function artifactsSave

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

Source from the content-addressed store, hash-verified

4083 });
4084
4085 const artifactsSave = (
4086 input: SaveArtifactInput,
4087 ): Effect.Effect<Artifact, ArtifactNotFoundError | StorageFailure> =>
4088 Effect.gen(function* () {
4089 const now = new Date();
4090 const description = input.description ?? null;
4091 // An explicit id overwrites in place (v1 keeps no version history). It
4092 // must already resolve to a visible row: minting a caller-chosen id
4093 // would let a stale client resurrect a deleted artifact silently.
4094 if (input.id !== undefined) {
4095 const where = artifactById(input.id);
4096 const existing = yield* core.findFirst("artifact", { where });
4097 if (!existing) {
4098 return yield* new ArtifactNotFoundError({ id: ArtifactId.make(input.id) });
4099 }
4100 // `bindings` is written on every overwrite, including back to null:
4101 // it interprets `code`, so carrying the previous value forward under
4102 // new source would bind roles the new code never declares. `preview`
4103 // is written for exactly the same reason, and the case it prevents is
4104 // visible: an image preview captured from the OLD render would
4105 // otherwise keep advertising a version of the artifact that no longer
4106 // exists.
4107 const set = {
4108 title: input.title,
4109 description,
4110 code: input.code,
4111 bindings: input.bindings ?? null,
4112 preview: input.preview ?? null,
4113 updated_at: now,
4114 };
4115 yield* core.updateMany("artifact", { where, set });
4116 return rowToArtifact({ ...existing, ...set });
4117 }
4118 yield* requireUserSubject("user");
4119 const keys = yield* Effect.try({
4120 try: () => ownedKeys("user"),
4121 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
4122 });
4123 const created = yield* core.create("artifact", {
4124 tenant: keys.tenant,
4125 owner: keys.owner,
4126 subject: keys.subject,
4127 id: `art_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
4128 title: input.title,
4129 description,
4130 code: input.code,
4131 bindings: input.bindings ?? null,
4132 preview: input.preview ?? null,
4133 created_at: now,
4134 updated_at: now,
4135 });
4136 return rowToArtifact(created);
4137 });
4138
4139 /**
4140 * 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