@absolutejs/artifacts 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,6 +4,18 @@ import { Value } from "@sinclair/typebox/value";
4
4
 
5
5
  // src/types.ts
6
6
  var ARTIFACT_STATUSES = ["draft", "published", "archived"];
7
+ function isJsonValue(value) {
8
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
9
+ return true;
10
+ }
11
+ if (typeof value === "number")
12
+ return Number.isFinite(value);
13
+ if (Array.isArray(value))
14
+ return value.every(isJsonValue);
15
+ if (typeof value !== "object")
16
+ return false;
17
+ return Object.values(value).every(isJsonValue);
18
+ }
7
19
  var ARTIFACT_EVENT_TYPES = [
8
20
  "artifact.archived",
9
21
  "artifact.asset_attached",
@@ -35,7 +47,7 @@ var defineArtifactRegistry = (definitions) => ({
35
47
  if (!definition) {
36
48
  throw new ArtifactError("unknown_kind", `Unknown artifact kind: ${kind}`);
37
49
  }
38
- if (!Value.Check(definition.content, content)) {
50
+ if (!Value.Check(definition.content, content) || !isJsonValue(content)) {
39
51
  const issue = [...Value.Errors(definition.content, content)][0];
40
52
  const detail = issue ? `${issue.path || "/"}: ${issue.message}` : "invalid content";
41
53
  throw new ArtifactError("invalid_content", `Invalid ${kind} artifact content (${detail})`);
@@ -711,7 +723,15 @@ var createMemoryArtifactStore = (initial = []) => {
711
723
  };
712
724
  // src/tools.ts
713
725
  import { Type as Type2 } from "@sinclair/typebox";
714
- var record = (input) => input && typeof input === "object" && !Array.isArray(input) ? input : {};
726
+ var JsonValueSchema = Type2.Recursive((self) => Type2.Union([
727
+ Type2.String(),
728
+ Type2.Number(),
729
+ Type2.Boolean(),
730
+ Type2.Null(),
731
+ Type2.Array(self),
732
+ Type2.Record(Type2.String(), self)
733
+ ]));
734
+ var record = (input) => isJsonValue(input) && input !== null && typeof input === "object" && !Array.isArray(input) ? input : {};
715
735
  var stringValue = (input, key) => typeof input[key] === "string" ? input[key] : undefined;
716
736
  var createArtifactTools = (options) => ({
717
737
  artifact_create: {
@@ -720,7 +740,7 @@ var createArtifactTools = (options) => ({
720
740
  const input = record(raw);
721
741
  const kind = stringValue(input, "kind");
722
742
  const title = stringValue(input, "title");
723
- if (!kind || !title || input.content === undefined) {
743
+ if (!kind || !title || !isJsonValue(input.content)) {
724
744
  return "Provide kind, title, and content.";
725
745
  }
726
746
  const artifact = await options.service.create(options.ownerId, {
@@ -732,7 +752,7 @@ var createArtifactTools = (options) => ({
732
752
  return JSON.stringify(artifact);
733
753
  },
734
754
  input: Type2.Object({
735
- content: Type2.Unknown(),
755
+ content: JsonValueSchema,
736
756
  kind: Type2.String({ minLength: 1 }),
737
757
  title: Type2.String({ minLength: 1 })
738
758
  })
@@ -834,6 +854,7 @@ var createArtifactTools = (options) => ({
834
854
  });
835
855
  export {
836
856
  standardArtifactDefinitions,
857
+ isJsonValue,
837
858
  defineArtifactRegistry,
838
859
  createMemoryArtifactStore,
839
860
  createMemoryArtifactAssetStore,
@@ -138,13 +138,13 @@ export declare const artifactRevisions: import("drizzle-orm/pg-core").PgTableWit
138
138
  }>;
139
139
  document: import("drizzle-orm/pg-core").PgBuildColumn<"artifact_revisions", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
140
140
  dataType: "custom";
141
- data: Readonly<ArtifactRecord<unknown>>;
141
+ data: Readonly<ArtifactRecord<import("./types").JsonValue>>;
142
142
  driverParam: unknown;
143
143
  }>>, {
144
144
  name: string;
145
145
  tableName: "artifact_revisions";
146
146
  dataType: "custom";
147
- data: Readonly<ArtifactRecord<unknown>>;
147
+ data: Readonly<ArtifactRecord<import("./types").JsonValue>>;
148
148
  driverParam: unknown;
149
149
  notNull: true;
150
150
  hasDefault: false;
@@ -760,13 +760,13 @@ export declare const artifactDrizzleSchema: {
760
760
  }>;
761
761
  document: import("drizzle-orm/pg-core").PgBuildColumn<"artifact_revisions", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
762
762
  dataType: "custom";
763
- data: Readonly<ArtifactRecord<unknown>>;
763
+ data: Readonly<ArtifactRecord<import("./types").JsonValue>>;
764
764
  driverParam: unknown;
765
765
  }>>, {
766
766
  name: string;
767
767
  tableName: "artifact_revisions";
768
768
  dataType: "custom";
769
- data: Readonly<ArtifactRecord<unknown>>;
769
+ data: Readonly<ArtifactRecord<import("./types").JsonValue>>;
770
770
  driverParam: unknown;
771
771
  notNull: true;
772
772
  hasDefault: false;
@@ -1051,13 +1051,13 @@ export declare const ArtifactRevisionInsertSchema: import("drizzle-typebox").Bui
1051
1051
  }>;
1052
1052
  document: import("drizzle-orm/pg-core").PgBuildColumn<"artifact_revisions", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
1053
1053
  dataType: "custom";
1054
- data: Readonly<ArtifactRecord<unknown>>;
1054
+ data: Readonly<ArtifactRecord<import("./types").JsonValue>>;
1055
1055
  driverParam: unknown;
1056
1056
  }>>, {
1057
1057
  name: string;
1058
1058
  tableName: "artifact_revisions";
1059
1059
  dataType: "custom";
1060
- data: Readonly<ArtifactRecord<unknown>>;
1060
+ data: Readonly<ArtifactRecord<import("./types").JsonValue>>;
1061
1061
  driverParam: unknown;
1062
1062
  notNull: true;
1063
1063
  hasDefault: false;
@@ -1117,13 +1117,13 @@ export declare const ArtifactRevisionSelectSchema: import("drizzle-typebox").Bui
1117
1117
  }>;
1118
1118
  document: import("drizzle-orm/pg-core").PgBuildColumn<"artifact_revisions", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
1119
1119
  dataType: "custom";
1120
- data: Readonly<ArtifactRecord<unknown>>;
1120
+ data: Readonly<ArtifactRecord<import("./types").JsonValue>>;
1121
1121
  driverParam: unknown;
1122
1122
  }>>, {
1123
1123
  name: string;
1124
1124
  tableName: "artifact_revisions";
1125
1125
  dataType: "custom";
1126
- data: Readonly<ArtifactRecord<unknown>>;
1126
+ data: Readonly<ArtifactRecord<import("./types").JsonValue>>;
1127
1127
  driverParam: unknown;
1128
1128
  notNull: true;
1129
1129
  hasDefault: false;
@@ -1,7 +1,7 @@
1
- import type { ArtifactAssetWriteInput, ArtifactBundleCreateInput, ArtifactProvenance, ArtifactRecord } from "./types";
1
+ import type { ArtifactAssetWriteInput, ArtifactBundleCreateInput, ArtifactProvenance, ArtifactRecord, JsonObject, JsonValue } from "./types";
2
2
  export type ArtifactGenerationInput = {
3
3
  createdBy: string;
4
- input?: Record<string, unknown>;
4
+ input?: JsonObject;
5
5
  kind: string;
6
6
  ownerId: string;
7
7
  prompt?: string;
@@ -12,8 +12,8 @@ export type ArtifactGenerationContext = {
12
12
  };
13
13
  export type ArtifactGenerationResult = {
14
14
  assets?: ArtifactAssetWriteInput[];
15
- content: unknown;
16
- metadata?: Record<string, unknown>;
15
+ content: JsonValue;
16
+ metadata?: JsonObject;
17
17
  provenance?: ArtifactProvenance;
18
18
  title?: string;
19
19
  warnings?: string[];
@@ -13,4 +13,4 @@ export { createArtifactRendererRegistry, type ArtifactRenderer, type ArtifactRen
13
13
  export { createArtifactService, type ArtifactPublisher, type ArtifactService, type ArtifactServiceOptions, } from "./service";
14
14
  export { createMemoryArtifactStore, createMemoryArtifactAssetStore, type ArtifactAssetStore, type ArtifactAssetTransaction, type ArtifactStore, } from "./store";
15
15
  export { createArtifactTools, type ArtifactToolDefinition, type ArtifactToolMap, type ArtifactToolOptions, } from "./tools";
16
- export { ARTIFACT_STATUSES, ARTIFACT_EVENT_TYPES, ArtifactError, type ArtifactAssetReference, type ArtifactAssetRole, type ArtifactAssetWriteInput, type ArtifactBundleCreateInput, type ArtifactCapability, type ArtifactCreateInput, type ArtifactErrorCode, type ArtifactEvent, type ArtifactEventQuery, type ArtifactEventType, type ArtifactGarbageCollectionResult, type ArtifactIndexingState, type ArtifactIndexingStatus, type ArtifactListQuery, type ArtifactLineageReference, type ArtifactLineageRelation, type ArtifactProvenance, type ArtifactPublication, type ArtifactPublishInput, type ArtifactRecord, type ArtifactRevision, type ArtifactRetentionCandidate, type ArtifactStatus, type ArtifactUpdateInput, } from "./types";
16
+ export { ARTIFACT_STATUSES, ARTIFACT_EVENT_TYPES, ArtifactError, isJsonValue, type ArtifactAssetReference, type ArtifactAssetRole, type ArtifactAssetWriteInput, type ArtifactBundleCreateInput, type ArtifactCapability, type ArtifactCreateInput, type ArtifactErrorCode, type ArtifactEvent, type ArtifactEventQuery, type ArtifactEventType, type ArtifactGarbageCollectionResult, type ArtifactIndexingState, type ArtifactIndexingStatus, type ArtifactListQuery, type ArtifactLineageReference, type ArtifactLineageRelation, type ArtifactProvenance, type ArtifactPublication, type ArtifactPublishInput, type ArtifactRecord, type ArtifactRevision, type ArtifactRetentionCandidate, type ArtifactStatus, type ArtifactUpdateInput, type JsonObject, type JsonPrimitive, type JsonValue, } from "./types";
@@ -11,10 +11,10 @@ export declare const manifest: Omit<import("@absolutejs/manifest").PackageManife
11
11
  detach: (ownerId: string, artifactId: string, assetId: string, expectedRevision?: number) => Promise<import("./types").ArtifactRecord>;
12
12
  get: (ownerId: string, artifactId: string) => Promise<import("./types").ArtifactRecord>;
13
13
  getIndexingState: (ownerId: string, artifactId: string) => Promise<import("./types").ArtifactIndexingState | null>;
14
- getRevision: (ownerId: string, artifactId: string, revision: number) => Promise<Readonly<import("./types").ArtifactRecord<unknown>>>;
14
+ getRevision: (ownerId: string, artifactId: string, revision: number) => Promise<Readonly<import("./types").ArtifactRecord<import("./types").JsonValue>>>;
15
15
  list: (ownerId: string, query?: import("./types").ArtifactListQuery) => Promise<import("./types").ArtifactRecord[]>;
16
16
  listEvents: (query?: import("./types").ArtifactEventQuery) => Promise<import("./types").ArtifactEvent[]>;
17
- listRevisions: (ownerId: string, artifactId: string) => Promise<Readonly<import("./types").ArtifactRecord<unknown>>[]>;
17
+ listRevisions: (ownerId: string, artifactId: string) => Promise<Readonly<import("./types").ArtifactRecord<import("./types").JsonValue>>[]>;
18
18
  markEventProcessed: (eventId: string, processedAt?: string) => Promise<boolean>;
19
19
  markIndexing: (ownerId: string, artifactId: string, input: {
20
20
  documentIds?: string[];
@@ -46,10 +46,10 @@ export declare const manifest: Omit<import("@absolutejs/manifest").PackageManife
46
46
  detach: (ownerId: string, artifactId: string, assetId: string, expectedRevision?: number) => Promise<import("./types").ArtifactRecord>;
47
47
  get: (ownerId: string, artifactId: string) => Promise<import("./types").ArtifactRecord>;
48
48
  getIndexingState: (ownerId: string, artifactId: string) => Promise<import("./types").ArtifactIndexingState | null>;
49
- getRevision: (ownerId: string, artifactId: string, revision: number) => Promise<Readonly<import("./types").ArtifactRecord<unknown>>>;
49
+ getRevision: (ownerId: string, artifactId: string, revision: number) => Promise<Readonly<import("./types").ArtifactRecord<import("./types").JsonValue>>>;
50
50
  list: (ownerId: string, query?: import("./types").ArtifactListQuery) => Promise<import("./types").ArtifactRecord[]>;
51
51
  listEvents: (query?: import("./types").ArtifactEventQuery) => Promise<import("./types").ArtifactEvent[]>;
52
- listRevisions: (ownerId: string, artifactId: string) => Promise<Readonly<import("./types").ArtifactRecord<unknown>>[]>;
52
+ listRevisions: (ownerId: string, artifactId: string) => Promise<Readonly<import("./types").ArtifactRecord<import("./types").JsonValue>>[]>;
53
53
  markEventProcessed: (eventId: string, processedAt?: string) => Promise<boolean>;
54
54
  markIndexing: (ownerId: string, artifactId: string, input: {
55
55
  documentIds?: string[];
@@ -82,10 +82,10 @@ export declare const manifest: Omit<import("@absolutejs/manifest").PackageManife
82
82
  detach: (ownerId: string, artifactId: string, assetId: string, expectedRevision?: number) => Promise<import("./types").ArtifactRecord>;
83
83
  get: (ownerId: string, artifactId: string) => Promise<import("./types").ArtifactRecord>;
84
84
  getIndexingState: (ownerId: string, artifactId: string) => Promise<import("./types").ArtifactIndexingState | null>;
85
- getRevision: (ownerId: string, artifactId: string, revision: number) => Promise<Readonly<import("./types").ArtifactRecord<unknown>>>;
85
+ getRevision: (ownerId: string, artifactId: string, revision: number) => Promise<Readonly<import("./types").ArtifactRecord<import("./types").JsonValue>>>;
86
86
  list: (ownerId: string, query?: import("./types").ArtifactListQuery) => Promise<import("./types").ArtifactRecord[]>;
87
87
  listEvents: (query?: import("./types").ArtifactEventQuery) => Promise<import("./types").ArtifactEvent[]>;
88
- listRevisions: (ownerId: string, artifactId: string) => Promise<Readonly<import("./types").ArtifactRecord<unknown>>[]>;
88
+ listRevisions: (ownerId: string, artifactId: string) => Promise<Readonly<import("./types").ArtifactRecord<import("./types").JsonValue>>[]>;
89
89
  markEventProcessed: (eventId: string, processedAt?: string) => Promise<boolean>;
90
90
  markIndexing: (ownerId: string, artifactId: string, input: {
91
91
  documentIds?: string[];
@@ -1,5 +1,5 @@
1
1
  import type { Static, TSchema } from "@sinclair/typebox";
2
- import { type ArtifactCapability } from "./types";
2
+ import { type ArtifactCapability, type JsonValue } from "./types";
3
3
  export type ArtifactAssetPolicy = {
4
4
  /** Exact media types or wildcards such as image/* and application/*. */
5
5
  acceptedMediaTypes?: string[];
@@ -18,6 +18,6 @@ export type ArtifactContent<TDefinitions extends ArtifactKindDefinitions, TKind
18
18
  export type ArtifactRegistry<TDefinitions extends ArtifactKindDefinitions> = {
19
19
  definitions: TDefinitions;
20
20
  kindNames: Array<keyof TDefinitions & string>;
21
- parse<TKind extends keyof TDefinitions & string>(kind: TKind, content: unknown): ArtifactContent<TDefinitions, TKind>;
21
+ parse<TKind extends keyof TDefinitions & string>(kind: TKind, content: unknown): ArtifactContent<TDefinitions, TKind> & JsonValue;
22
22
  };
23
23
  export declare const defineArtifactRegistry: <const TDefinitions extends ArtifactKindDefinitions>(definitions: TDefinitions) => ArtifactRegistry<TDefinitions>;
@@ -37,10 +37,10 @@ export declare const createArtifactService: <TDefinitions extends ArtifactKindDe
37
37
  detach: (ownerId: string, artifactId: string, assetId: string, expectedRevision?: number) => Promise<ArtifactRecord>;
38
38
  get: (ownerId: string, artifactId: string) => Promise<ArtifactRecord>;
39
39
  getIndexingState: (ownerId: string, artifactId: string) => Promise<ArtifactIndexingState | null>;
40
- getRevision: (ownerId: string, artifactId: string, revision: number) => Promise<Readonly<ArtifactRecord<unknown>>>;
40
+ getRevision: (ownerId: string, artifactId: string, revision: number) => Promise<Readonly<ArtifactRecord<import("./types").JsonValue>>>;
41
41
  list: (ownerId: string, query?: ArtifactListQuery) => Promise<ArtifactRecord[]>;
42
42
  listEvents: (query?: ArtifactEventQuery) => Promise<ArtifactEvent[]>;
43
- listRevisions: (ownerId: string, artifactId: string) => Promise<Readonly<ArtifactRecord<unknown>>[]>;
43
+ listRevisions: (ownerId: string, artifactId: string) => Promise<Readonly<ArtifactRecord<import("./types").JsonValue>>[]>;
44
44
  markEventProcessed: (eventId: string, processedAt?: string) => Promise<boolean>;
45
45
  markIndexing: (ownerId: string, artifactId: string, input: {
46
46
  documentIds?: string[];
@@ -1,4 +1,10 @@
1
1
  export declare const ARTIFACT_STATUSES: readonly ["draft", "published", "archived"];
2
+ export type JsonPrimitive = boolean | null | number | string;
3
+ export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
4
+ export type JsonObject = {
5
+ [key: string]: JsonValue;
6
+ };
7
+ export declare function isJsonValue(value: unknown): value is JsonValue;
2
8
  export type ArtifactStatus = (typeof ARTIFACT_STATUSES)[number];
3
9
  export type ArtifactCapability = "attach" | "archive" | "edit" | "export" | "preview" | "publish" | "refine";
4
10
  export type ArtifactProvenance = {
@@ -31,7 +37,7 @@ export type ArtifactAssetReference = {
31
37
  id: string;
32
38
  createdAt: string;
33
39
  mediaType: string;
34
- metadata?: Record<string, unknown>;
40
+ metadata?: JsonObject;
35
41
  name: string;
36
42
  role: ArtifactAssetRole;
37
43
  size: number;
@@ -41,11 +47,11 @@ export type ArtifactAssetReference = {
41
47
  export type ArtifactAssetWriteInput = {
42
48
  data: Uint8Array;
43
49
  mediaType: string;
44
- metadata?: Record<string, unknown>;
50
+ metadata?: JsonObject;
45
51
  name: string;
46
52
  role?: ArtifactAssetRole;
47
53
  };
48
- export type ArtifactRecord<TContent = unknown> = {
54
+ export type ArtifactRecord<TContent = JsonValue> = {
49
55
  assets: ArtifactAssetReference[];
50
56
  capabilities: ArtifactCapability[];
51
57
  content: TContent;
@@ -53,7 +59,7 @@ export type ArtifactRecord<TContent = unknown> = {
53
59
  createdBy: string;
54
60
  id: string;
55
61
  kind: string;
56
- metadata: Record<string, unknown>;
62
+ metadata: JsonObject;
57
63
  ownerId: string;
58
64
  provenance?: ArtifactProvenance;
59
65
  publication?: ArtifactPublication;
@@ -70,7 +76,7 @@ export type ArtifactEvent = {
70
76
  createdAt: string;
71
77
  id: string;
72
78
  ownerId: string;
73
- payload?: Record<string, unknown>;
79
+ payload?: JsonObject;
74
80
  processedAt?: string;
75
81
  revision: number;
76
82
  type: ArtifactEventType;
@@ -91,7 +97,7 @@ export type ArtifactIndexingState = {
91
97
  updatedAt: string;
92
98
  };
93
99
  /** An immutable point-in-time copy of an artifact record. */
94
- export type ArtifactRevision<TContent = unknown> = Readonly<ArtifactRecord<TContent>>;
100
+ export type ArtifactRevision<TContent = JsonValue> = Readonly<ArtifactRecord<TContent>>;
95
101
  export type ArtifactListQuery = {
96
102
  kind?: string;
97
103
  limit?: number;
@@ -99,18 +105,18 @@ export type ArtifactListQuery = {
99
105
  };
100
106
  export type ArtifactCreateInput = {
101
107
  assets?: ArtifactAssetReference[];
102
- content: unknown;
108
+ content: JsonValue;
103
109
  createdBy: string;
104
110
  kind: string;
105
- metadata?: Record<string, unknown>;
111
+ metadata?: JsonObject;
106
112
  provenance?: ArtifactProvenance;
107
113
  title: string;
108
114
  };
109
115
  export type ArtifactUpdateInput = {
110
116
  assets?: ArtifactAssetReference[];
111
- content?: unknown;
117
+ content?: JsonValue;
112
118
  expectedRevision?: number;
113
- metadata?: Record<string, unknown>;
119
+ metadata?: JsonObject;
114
120
  title?: string;
115
121
  };
116
122
  export type ArtifactBundleCreateInput = Omit<ArtifactCreateInput, "assets"> & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/artifacts",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Typed, versioned artifacts for AI products — schemas, lifecycle, storage, rendering, publishing, revisions, and agent tools without prescribing a database or host.",
5
5
  "author": "Alex Kahn",
6
6
  "license": "BUSL-1.1",