@enterstellar-ai/types 0.1.0

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 ADDED
@@ -0,0 +1,428 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/version.ts
4
+ var ENTERSTELLAR_TYPES_VERSION = "0.1.0";
5
+
6
+ // src/errors.ts
7
+ var EnterstellarError = class _EnterstellarError extends Error {
8
+ /**
9
+ * Machine-readable error code.
10
+ * Maps to documentation at `enterstellar.dev/errors/{code}`.
11
+ */
12
+ code;
13
+ /** The Enterstellar module that originated this error. */
14
+ module;
15
+ /**
16
+ * Whether the error is recoverable.
17
+ * Recoverable errors can be retried or handled gracefully.
18
+ * Non-recoverable errors indicate fatal conditions.
19
+ */
20
+ recoverable;
21
+ /**
22
+ * ISO 8601 timestamp of when the error was created.
23
+ * Useful for trace correlation and debugging.
24
+ */
25
+ timestamp;
26
+ /**
27
+ * Creates a new `EnterstellarError`.
28
+ *
29
+ * @param code - Machine-readable error code (e.g., `'ENS-1001'`).
30
+ * @param module - The Enterstellar module that originated the error.
31
+ * @param message - Human-readable error message.
32
+ * @param recoverable - Whether the error can be retried or handled gracefully.
33
+ * @param cause - Optional underlying error that caused this error.
34
+ */
35
+ constructor(code, module, message, recoverable = false, cause) {
36
+ super(message, { cause });
37
+ this.name = "EnterstellarError";
38
+ this.code = code;
39
+ this.module = module;
40
+ this.recoverable = recoverable;
41
+ this.timestamp = (/* @__PURE__ */ new Date()).toISOString();
42
+ if ("captureStackTrace" in Error) {
43
+ Error.captureStackTrace(this, _EnterstellarError);
44
+ }
45
+ }
46
+ /**
47
+ * Serializes the error to a plain object for logging, telemetry, or DevTools.
48
+ *
49
+ * @returns A plain object representation of the error.
50
+ */
51
+ toJSON() {
52
+ return {
53
+ name: this.name,
54
+ code: this.code,
55
+ module: this.module,
56
+ message: this.message,
57
+ recoverable: this.recoverable,
58
+ timestamp: this.timestamp,
59
+ stack: this.stack
60
+ };
61
+ }
62
+ };
63
+
64
+ // src/brands.ts
65
+ function createComponentId(name) {
66
+ if (!name.trim()) {
67
+ throw new EnterstellarError(
68
+ "ENS-1009",
69
+ "types",
70
+ "[ENS-1009] ComponentId name must be a non-empty string.",
71
+ false
72
+ );
73
+ }
74
+ return name;
75
+ }
76
+ function createZoneId(name) {
77
+ if (!name.trim()) {
78
+ throw new EnterstellarError(
79
+ "ENS-1009",
80
+ "types",
81
+ "[ENS-1009] ZoneId name must be a non-empty string.",
82
+ false
83
+ );
84
+ }
85
+ return name;
86
+ }
87
+ function createTraceId() {
88
+ return globalThis.crypto.randomUUID();
89
+ }
90
+ var ComponentContractSchema = z.object({
91
+ name: z.string().min(1, "Component name is required."),
92
+ id: z.string().min(1, "Component ID is required."),
93
+ description: z.string().min(1, "Description is required.").max(120, "Description must be 120 characters or fewer (R2)."),
94
+ category: z.string().min(1, "Category is required."),
95
+ tags: z.array(z.string()).min(1, "At least one tag is required (R3)."),
96
+ props: z.unknown(),
97
+ tokens: z.record(z.string(), z.string()),
98
+ accessibility: z.object({
99
+ role: z.string().min(1, "Accessibility role is required."),
100
+ ariaLabel: z.string().min(1, "Accessibility ariaLabel is required."),
101
+ announceOnUpdate: z.boolean()
102
+ }),
103
+ states: z.object({
104
+ loading: z.string().min(1),
105
+ error: z.string().min(1),
106
+ empty: z.string().min(1),
107
+ ready: z.string().min(1)
108
+ }),
109
+ examples: z.array(
110
+ z.object({
111
+ intent: z.string().min(1),
112
+ props: z.record(z.string(), z.unknown())
113
+ })
114
+ ),
115
+ dataSource: z.object({
116
+ adapter: z.string().min(1),
117
+ resource: z.string().min(1),
118
+ params: z.record(z.string(), z.unknown()).optional()
119
+ }).optional(),
120
+ auth: z.object({
121
+ required: z.boolean(),
122
+ roles: z.array(z.string())
123
+ }).optional(),
124
+ origin: z.object({
125
+ registryUrl: z.url(),
126
+ publisher: z.string().min(1),
127
+ verifiedAt: z.string().optional()
128
+ }).optional(),
129
+ _meta: z.object({
130
+ forged: z.boolean(),
131
+ version: z.string().min(1),
132
+ createdAt: z.string().min(1)
133
+ })
134
+ });
135
+ var DesignTokenSetSchema = z.record(
136
+ z.string(),
137
+ z.string().min(1, "Token value must be a non-empty string.")
138
+ );
139
+ var ComponentIntentSchema = z.object({
140
+ component: z.string().min(1, "Component name is required."),
141
+ props: z.record(z.string(), z.unknown()),
142
+ confidence: z.number().min(0, "Confidence must be >= 0.").max(1, "Confidence must be <= 1."),
143
+ layout: z.enum(["single", "split", "grid", "stack", "tabs"]).optional(),
144
+ mode: z.string().optional(),
145
+ interaction: z.enum(["read-only", "editable", "actionable"]).optional(),
146
+ _source: z.object({
147
+ protocol: z.enum([
148
+ "ag-ui",
149
+ "a2ui",
150
+ "mcp",
151
+ "websocket",
152
+ "sse",
153
+ "custom"
154
+ ]),
155
+ rawEventId: z.string().optional(),
156
+ correlationId: z.string().optional(),
157
+ raw: z.unknown().optional()
158
+ }).optional()
159
+ });
160
+ var CompilationErrorSchema = z.object({
161
+ code: z.string().min(1, "Error code is required."),
162
+ path: z.string(),
163
+ message: z.string().min(1, "Error message is required."),
164
+ received: z.unknown().optional(),
165
+ expected: z.unknown().optional(),
166
+ fix: z.object({
167
+ field: z.string().min(1),
168
+ was: z.unknown(),
169
+ shouldBe: z.unknown()
170
+ }).optional()
171
+ });
172
+ var CompilationResultSchema = z.object({
173
+ componentName: z.string().min(1, "Component name is required."),
174
+ props: z.record(z.string(), z.unknown()),
175
+ status: z.enum(["pass", "fail", "corrected"]),
176
+ provenance: z.object({
177
+ agent: z.string().min(1),
178
+ registry: z.string().min(1),
179
+ compiledAt: z.string().min(1),
180
+ compilerVersion: z.string().min(1),
181
+ forgeMode: z.enum(["local", "cloud"]).optional(),
182
+ contractOrigin: z.object({
183
+ registryUrl: z.string(),
184
+ publisher: z.string()
185
+ }).optional()
186
+ }),
187
+ errors: z.array(CompilationErrorSchema),
188
+ selfCorrectionAttempts: z.number().int().min(0),
189
+ diff: z.object({
190
+ raw: z.record(z.string(), z.unknown()),
191
+ compiled: z.record(z.string(), z.unknown())
192
+ }).optional(),
193
+ correctionTrace: z.array(
194
+ z.object({
195
+ tier: z.union([z.literal(1), z.literal(2)]),
196
+ errorCode: z.string().min(1),
197
+ field: z.string().min(1),
198
+ was: z.unknown(),
199
+ correctedTo: z.unknown(),
200
+ strategy: z.string().min(1)
201
+ })
202
+ ).optional()
203
+ });
204
+ var ZoneTraceSchema = z.object({
205
+ /** Unique zone-trace identifier. */
206
+ id: z.string().min(1, "Zone trace ID is required."),
207
+ /** The raw ComponentIntent that triggered compilation. */
208
+ intent: ComponentIntentSchema,
209
+ /**
210
+ * Compilation outcome data — status, errors, and self-correction attempts.
211
+ * Subset of the full TraceCompilation shape.
212
+ */
213
+ compilation: z.object({
214
+ /** Final compilation status. */
215
+ status: z.enum(["pass", "fail", "corrected"]),
216
+ /** Validation errors encountered during compilation. */
217
+ errors: z.array(CompilationErrorSchema),
218
+ /** Number of self-correction attempts made before final result. */
219
+ selfCorrectionAttempts: z.number().int().min(0)
220
+ }),
221
+ /**
222
+ * Provenance metadata from the CompilationResult.
223
+ * Mirrors the CompilationProvenance type shape exactly.
224
+ */
225
+ provenance: z.object({
226
+ /** Identifier of the AI agent/model. */
227
+ agent: z.string().min(1),
228
+ /** URL or name of the registry used. */
229
+ registry: z.string().min(1),
230
+ /** ISO 8601 timestamp when compilation occurred. */
231
+ compiledAt: z.string().min(1),
232
+ /** Semantic version of the compiler. */
233
+ compilerVersion: z.string().min(1),
234
+ /** Forge mode used, if the component was forged. */
235
+ forgeMode: z.enum(["local", "cloud"]).optional(),
236
+ /** Origin metadata for remote contracts. */
237
+ contractOrigin: z.object({
238
+ registryUrl: z.string(),
239
+ publisher: z.string()
240
+ }).optional()
241
+ }),
242
+ /** Zone-level performance metrics. */
243
+ metrics: z.object({
244
+ /** Total time from intent reception to render in milliseconds. */
245
+ totalMs: z.number().min(0),
246
+ /** Current retry attempt number (0-indexed). */
247
+ retryAttempt: z.number().int().min(0)
248
+ }),
249
+ /** ISO 8601 timestamp when this trace was created. */
250
+ timestamp: z.string().min(1, "Timestamp is required.")
251
+ });
252
+ var AgentTraceSchema = z.object({
253
+ id: z.string().min(1, "Trace ID is required."),
254
+ timestamp: z.string().min(1, "Timestamp is required."),
255
+ correlationId: z.string().optional(),
256
+ intent: z.object({
257
+ raw: z.string(),
258
+ component: z.string().min(1),
259
+ confidence: z.number().min(0).max(1),
260
+ mode: z.string().optional(),
261
+ interaction: z.string().optional()
262
+ }),
263
+ resolution: z.object({
264
+ strategy: z.enum(["exact", "semantic", "forge", "fallback"]),
265
+ resolvedComponent: z.string().min(1),
266
+ similarityScore: z.number().min(0).max(1).optional(),
267
+ candidatesConsidered: z.number().int().min(0)
268
+ }),
269
+ compilation: z.object({
270
+ status: z.enum(["pass", "fail", "corrected"]),
271
+ errorCount: z.number().int().min(0),
272
+ selfCorrectionAttempts: z.number().int().min(0),
273
+ tokensValidated: z.boolean(),
274
+ accessibilityInjected: z.boolean()
275
+ }),
276
+ determinism: z.object({
277
+ level: z.number().min(0).max(1),
278
+ cacheHit: z.boolean(),
279
+ zone: z.string().min(1)
280
+ }),
281
+ metrics: z.object({
282
+ totalMs: z.number().min(0),
283
+ resolutionMs: z.number().min(0),
284
+ compilationMs: z.number().min(0),
285
+ renderMs: z.number().min(0)
286
+ }),
287
+ consent: z.object({
288
+ anonymizedAggregation: z.boolean()
289
+ })
290
+ });
291
+ var ZoneConfigSchema = z.object({
292
+ id: z.string().min(1, "Zone ID is required."),
293
+ name: z.string().min(1, "Zone name is required."),
294
+ determinism: z.number().min(0, "Determinism must be >= 0.").max(1, "Determinism must be <= 1."),
295
+ allowedComponents: z.array(z.string()),
296
+ fallbackComponent: z.string().min(1, "Fallback component is required."),
297
+ agentTimeoutMs: z.number().int().positive("Agent timeout must be positive."),
298
+ cache: z.object({
299
+ enabled: z.boolean(),
300
+ ttl: z.number().int().positive("TTL must be positive.")
301
+ }),
302
+ activateOn: z.enum(["mount", "visible", "manual"])
303
+ });
304
+ var ForgeSignalSchema = z.object({
305
+ intentHash: z.string().min(1, "Intent hash is required."),
306
+ componentName: z.string().min(1, "Component name is required."),
307
+ intentCategory: z.enum([
308
+ "clinical",
309
+ "admin",
310
+ "navigation",
311
+ "data-display",
312
+ "form",
313
+ "feedback",
314
+ "utility"
315
+ ]),
316
+ compilationStatus: z.enum(["pass", "fail", "corrected"]),
317
+ forgeMode: z.enum(["none", "local", "cloud"]),
318
+ forgeUsed: z.boolean(),
319
+ latencyMs: z.number().min(0),
320
+ selfCorrectionAttempts: z.number().int().min(0),
321
+ correctionTokensUsed: z.number().int().min(0),
322
+ timestamp: z.string().min(1, "Timestamp is required."),
323
+ sdkVersion: z.string().min(1, "SDK version is required."),
324
+ registrySize: z.number().int().min(0),
325
+ platform: z.enum(["web", "native", "desktop", "cli", "unknown"])
326
+ });
327
+ var ZoneStateSchema = z.object({
328
+ name: z.string().min(1),
329
+ lifecycleState: z.enum(["loading", "ready", "streaming", "error", "empty"]),
330
+ determinism: z.number().min(0).max(1),
331
+ lastComponent: z.string().optional(),
332
+ lastUpdated: z.string().min(1)
333
+ });
334
+ var SessionStateSchema = z.object({
335
+ id: z.string().min(1),
336
+ threadId: z.string().optional(),
337
+ startedAt: z.string().min(1)
338
+ });
339
+ var SerializedStateSchema = z.object({
340
+ schemaVersion: z.string().min(1, "Schema version is required."),
341
+ zones: z.record(z.string(), ZoneStateSchema),
342
+ traceIds: z.array(z.string()),
343
+ session: SessionStateSchema,
344
+ extensions: z.record(z.string(), z.unknown())
345
+ });
346
+ var UserSignalSchema = z.object({
347
+ type: z.enum(["click", "submit", "input", "custom"]),
348
+ zone: z.string().min(1, "Zone name is required."),
349
+ component: z.string().min(1, "Component name is required."),
350
+ payload: z.record(z.string(), z.unknown()),
351
+ timestamp: z.string().min(1, "Timestamp is required."),
352
+ correlationId: z.string().optional()
353
+ });
354
+ var SemanticSearchResultSchema = z.object({
355
+ /** PascalCase name of the matched component. */
356
+ componentName: z.string().min(1),
357
+ /**
358
+ * Cosine similarity score. Clamped to [0.0, 1.0].
359
+ */
360
+ similarity: z.number().min(0).max(1),
361
+ /** The matched component's full contract. */
362
+ contract: ComponentContractSchema
363
+ });
364
+ var ForgeResultSchema = z.object({
365
+ success: z.boolean(),
366
+ /**
367
+ * `z.unknown().nullable()` instead of `ComponentContractSchema.nullable()`
368
+ * to avoid circular schema references (forge → contract → compiler).
369
+ * TS type is properly typed as `ComponentContract | null`.
370
+ */
371
+ contract: z.unknown().nullable(),
372
+ /**
373
+ * `z.unknown().nullable()` for the same reason — avoids circular
374
+ * schema dependency with `CompilationResultSchema`.
375
+ * TS type is properly typed as `CompilationResult | null`.
376
+ */
377
+ compilationResult: z.unknown().nullable(),
378
+ fallbackUsed: z.boolean(),
379
+ forgeMode: z.enum(["local", "cloud"])
380
+ });
381
+ var ForgeTraceRecordSchema = z.object({
382
+ intentSlug: z.string().min(1),
383
+ intentHash: z.string().min(1),
384
+ forgeMode: z.enum(["local", "cloud"]),
385
+ success: z.boolean(),
386
+ timestamp: z.string().min(1),
387
+ context: z.record(z.string(), z.unknown()).optional()
388
+ });
389
+
390
+ // src/guards.ts
391
+ function isComponentId(value) {
392
+ return typeof value === "string" && value.length > 0;
393
+ }
394
+ function isZoneId(value) {
395
+ return typeof value === "string" && value.length > 0;
396
+ }
397
+ function isTraceId(value) {
398
+ return typeof value === "string" && value.length > 0;
399
+ }
400
+ function isForgeSignal(value) {
401
+ if (typeof value !== "object" || value === null) return false;
402
+ const obj = value;
403
+ return typeof obj["intentHash"] === "string" && typeof obj["componentName"] === "string" && typeof obj["compilationStatus"] === "string" && typeof obj["forgeMode"] === "string" && typeof obj["latencyMs"] === "number" && typeof obj["timestamp"] === "string";
404
+ }
405
+ function isCompilationResult(value) {
406
+ if (typeof value !== "object" || value === null) return false;
407
+ const obj = value;
408
+ return typeof obj["componentName"] === "string" && typeof obj["status"] === "string" && typeof obj["provenance"] === "object" && obj["provenance"] !== null && Array.isArray(obj["errors"]);
409
+ }
410
+ function isComponentIntent(value) {
411
+ if (typeof value !== "object" || value === null) return false;
412
+ const obj = value;
413
+ return typeof obj["component"] === "string" && typeof obj["props"] === "object" && obj["props"] !== null && typeof obj["confidence"] === "number";
414
+ }
415
+ function isAgentTrace(value) {
416
+ if (typeof value !== "object" || value === null) return false;
417
+ const obj = value;
418
+ return typeof obj["id"] === "string" && typeof obj["timestamp"] === "string" && typeof obj["intent"] === "object" && obj["intent"] !== null && typeof obj["resolution"] === "object" && obj["resolution"] !== null && typeof obj["compilation"] === "object" && obj["compilation"] !== null;
419
+ }
420
+ function isUserSignal(value) {
421
+ if (typeof value !== "object" || value === null) return false;
422
+ const obj = value;
423
+ return typeof obj["type"] === "string" && typeof obj["zone"] === "string" && typeof obj["component"] === "string" && typeof obj["payload"] === "object" && obj["payload"] !== null && typeof obj["timestamp"] === "string";
424
+ }
425
+
426
+ export { AgentTraceSchema, CompilationErrorSchema, CompilationResultSchema, ComponentContractSchema, ComponentIntentSchema, DesignTokenSetSchema, ENTERSTELLAR_TYPES_VERSION, EnterstellarError, ForgeResultSchema, ForgeSignalSchema, ForgeTraceRecordSchema, SemanticSearchResultSchema, SerializedStateSchema, SessionStateSchema, UserSignalSchema, ZoneConfigSchema, ZoneStateSchema, ZoneTraceSchema, createComponentId, createTraceId, createZoneId, isAgentTrace, isCompilationResult, isComponentId, isComponentIntent, isForgeSignal, isTraceId, isUserSignal, isZoneId };
427
+ //# sourceMappingURL=index.js.map
428
+ //# sourceMappingURL=index.js.map