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

Function artifactsSave

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

Source from the content-addressed store, hash-verified

5521 });
5522
5523 const artifactsSave = (
5524 input: SaveArtifactInput,
5525 ): Effect.Effect<Artifact, ArtifactNotFoundError | StorageFailure> =>
5526 Effect.gen(function* () {
5527 const now = new Date();
5528 const description = input.description ?? null;
5529 // An explicit id overwrites in place (v1 keeps no version history). It
5530 // must already resolve to a visible row: minting a caller-chosen id
5531 // would let a stale client resurrect a deleted artifact silently.
5532 if (input.id !== undefined) {
5533 const where = artifactById(input.id);
5534 const existing = yield* core.findFirst("artifact", { where });
5535 if (!existing) {
5536 return yield* new ArtifactNotFoundError({ id: ArtifactId.make(input.id) });
5537 }
5538 // `bindings` is written on every overwrite, including back to null:
5539 // it interprets `code`, so carrying the previous value forward under
5540 // new source would bind roles the new code never declares. `preview`
5541 // is written for exactly the same reason, and the case it prevents is
5542 // visible: an image preview captured from the OLD render would
5543 // otherwise keep advertising a version of the artifact that no longer
5544 // exists.
5545 const set = {
5546 title: input.title,
5547 description,
5548 code: input.code,
5549 bindings: input.bindings ?? null,
5550 preview: input.preview ?? null,
5551 updated_at: now,
5552 };
5553 yield* core.updateMany("artifact", { where, set });
5554 return rowToArtifact({ ...existing, ...set });
5555 }
5556 yield* requireUserSubject("user");
5557 const keys = yield* Effect.try({
5558 try: () => ownedKeys("user"),
5559 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
5560 });
5561 const created = yield* core.create("artifact", {
5562 tenant: keys.tenant,
5563 owner: keys.owner,
5564 subject: keys.subject,
5565 id: `art_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
5566 title: input.title,
5567 description,
5568 code: input.code,
5569 bindings: input.bindings ?? null,
5570 preview: input.preview ?? null,
5571 created_at: now,
5572 updated_at: now,
5573 });
5574 return rowToArtifact(created);
5575 });
5576
5577 /**
5578 * 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