@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.
@@ -0,0 +1,2297 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * @module @enterstellar-ai/types/version
5
+ * @description Enterstellar Types package version constant.
6
+ *
7
+ * Exported for runtime compatibility checks and DevTools version display.
8
+ * @see Design Choice T14
9
+ */
10
+ /** Current version of the @enterstellar-ai/types package. Follows semver. */
11
+ declare const ENTERSTELLAR_TYPES_VERSION: "0.1.0";
12
+
13
+ /**
14
+ * @module @enterstellar-ai/types/brands
15
+ * @description Branded types for type-safe identifiers across the Enterstellar ecosystem.
16
+ *
17
+ * Branded types prevent accidentally passing a zone name where a component ID
18
+ * is expected, or using a plain string where a trace ID is required.
19
+ *
20
+ * @see Design Choice T10
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { createComponentId, createZoneId, createTraceId } from '@enterstellar-ai/types';
25
+ *
26
+ * const compId = createComponentId('PatientVitals');
27
+ * const zoneId = createZoneId('main-content');
28
+ * const traceId = createTraceId();
29
+ * ```
30
+ */
31
+ /**
32
+ * A branded string identifying a registered component.
33
+ * Prevents accidental misuse of plain strings as component identifiers.
34
+ */
35
+ type ComponentId = string & {
36
+ readonly __brand: 'ComponentId';
37
+ };
38
+ /**
39
+ * A branded string identifying an Zone instance.
40
+ * Ensures zone references are explicit and type-checked.
41
+ */
42
+ type ZoneId = string & {
43
+ readonly __brand: 'ZoneId';
44
+ };
45
+ /**
46
+ * A branded string identifying an AgentTrace record.
47
+ * Guarantees trace references are unique and type-safe.
48
+ */
49
+ type TraceId = string & {
50
+ readonly __brand: 'TraceId';
51
+ };
52
+ /**
53
+ * Creates a type-safe `ComponentId` from a PascalCase component name.
54
+ *
55
+ * @param name - PascalCase component name, must be non-empty.
56
+ * @returns A branded `ComponentId`.
57
+ * @throws {EnterstellarError} `ENS-1009` if `name` is empty or contains only whitespace.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const id = createComponentId('PatientVitals');
62
+ * ```
63
+ */
64
+ declare function createComponentId(name: string): ComponentId;
65
+ /**
66
+ * Creates a type-safe `ZoneId` from a zone name.
67
+ *
68
+ * @param name - Zone name, must be non-empty. Typically kebab-case.
69
+ * @returns A branded `ZoneId`.
70
+ * @throws {EnterstellarError} `ENS-1009` if `name` is empty or contains only whitespace.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const id = createZoneId('patient-sidebar');
75
+ * ```
76
+ */
77
+ declare function createZoneId(name: string): ZoneId;
78
+ /**
79
+ * Creates a type-safe `TraceId` using a UUIDv4.
80
+ *
81
+ * @returns A branded `TraceId` backed by a cryptographically random UUID.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const id = createTraceId();
86
+ * // e.g., "c0a80164-b1c2-4d3e-a456-789012345678"
87
+ * ```
88
+ */
89
+ declare function createTraceId(): TraceId;
90
+
91
+ /**
92
+ * @module @enterstellar-ai/types/errors
93
+ * @description Enterstellar error class and error code taxonomy.
94
+ *
95
+ * All Enterstellar errors extend `EnterstellarError`, carrying a machine-readable `code`,
96
+ * the originating `module`, and whether the error is `recoverable`.
97
+ *
98
+ * Error code ranges:
99
+ * - `ENS-1xxx` — Registry errors
100
+ * - `ENS-2xxx` — Compiler errors
101
+ * - `ENS-3xxx` — Lifecycle / Zone errors
102
+ * - `ENS-4xxx` — Forge / State errors
103
+ * - `ENS-5xxx` — Cloud / Index errors
104
+ * - `ENS-6xxx` — Normalizer errors
105
+ * - `ENS-7xxx` — Adapter errors
106
+ * - `ENS-8xxx` — Agent SDK errors
107
+ * - `ENS-9xxx` — CLI errors
108
+ *
109
+ * @see Coding Rules — Error Taxonomy
110
+ * @see Design Choice C14
111
+ */
112
+ /**
113
+ * Machine-readable error code following the `ENS-XXXX` convention.
114
+ * Each code maps to documentation at `enterstellar.dev/errors/ENS-XXXX`.
115
+ */
116
+ type EnterstellarErrorCode = 'ENS-1001' | 'ENS-1002' | 'ENS-1003' | 'ENS-1004' | 'ENS-1005' | 'ENS-1006' | 'ENS-1007' | 'ENS-1008' | 'ENS-1009' | 'ENS-1010' | 'ENS-2001' | 'ENS-2002' | 'ENS-2003' | 'ENS-2004' | 'ENS-2005' | 'ENS-2006' | 'ENS-2007' | 'ENS-2008' | 'ENS-2009' | 'ENS-2010' | 'ENS-3001' | 'ENS-3002' | 'ENS-3003' | 'ENS-3004' | 'ENS-3005' | 'ENS-3010' | 'ENS-4001' | 'ENS-4002' | 'ENS-4003' | 'ENS-4004' | 'ENS-4005' | 'ENS-4006' | 'ENS-4007' | 'ENS-5001' | 'ENS-5002' | 'ENS-5003' | 'ENS-5004' | 'ENS-5005' | 'ENS-5006' | 'ENS-5007' | 'ENS-5008' | 'ENS-5009' | 'ENS-5010' | 'ENS-5020' | 'ENS-5021' | 'ENS-5022' | 'ENS-5023' | 'ENS-5024' | 'ENS-5025' | 'ENS-6001' | 'ENS-6002' | 'ENS-6003' | 'ENS-6004' | 'ENS-6005' | 'ENS-7001' | 'ENS-7002' | 'ENS-7003' | 'ENS-7004' | 'ENS-7005' | 'ENS-8001' | 'ENS-8002' | 'ENS-8003' | 'ENS-8004' | 'ENS-8005' | 'ENS-9001' | 'ENS-9002' | 'ENS-9003' | 'ENS-9004' | 'ENS-9005' | 'ENS-9006' | 'ENS-5030' | 'ENS-5031' | 'ENS-5032' | 'ENS-5033' | 'ENS-5034' | 'ENS-5035';
117
+ /** The Enterstellar module that originated the error. */
118
+ type EnterstellarErrorModule = 'types' | 'registry' | 'compiler' | 'state' | 'telemetry' | 'react' | 'connection' | 'lifecycle' | 'normalizer' | 'forge' | 'cache' | 'semantic-index' | 'cloud' | 'global-index' | 'agent-sdk' | 'devtools' | 'test' | 'cli' | 'adapters';
119
+ /**
120
+ * Base error class for all Enterstellar errors.
121
+ *
122
+ * Extends the native `Error` with structured metadata for observability,
123
+ * DevTools integration, and programmatic error handling.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * throw new EnterstellarError(
128
+ * 'ENS-1001',
129
+ * 'registry',
130
+ * 'Component "Foo" is already registered.',
131
+ * true, // recoverable
132
+ * );
133
+ * ```
134
+ */
135
+ declare class EnterstellarError extends Error {
136
+ /**
137
+ * Machine-readable error code.
138
+ * Maps to documentation at `enterstellar.dev/errors/{code}`.
139
+ */
140
+ readonly code: EnterstellarErrorCode;
141
+ /** The Enterstellar module that originated this error. */
142
+ readonly module: EnterstellarErrorModule;
143
+ /**
144
+ * Whether the error is recoverable.
145
+ * Recoverable errors can be retried or handled gracefully.
146
+ * Non-recoverable errors indicate fatal conditions.
147
+ */
148
+ readonly recoverable: boolean;
149
+ /**
150
+ * ISO 8601 timestamp of when the error was created.
151
+ * Useful for trace correlation and debugging.
152
+ */
153
+ readonly timestamp: string;
154
+ /**
155
+ * Creates a new `EnterstellarError`.
156
+ *
157
+ * @param code - Machine-readable error code (e.g., `'ENS-1001'`).
158
+ * @param module - The Enterstellar module that originated the error.
159
+ * @param message - Human-readable error message.
160
+ * @param recoverable - Whether the error can be retried or handled gracefully.
161
+ * @param cause - Optional underlying error that caused this error.
162
+ */
163
+ constructor(code: EnterstellarErrorCode, module: EnterstellarErrorModule, message: string, recoverable?: boolean, cause?: unknown);
164
+ /**
165
+ * Serializes the error to a plain object for logging, telemetry, or DevTools.
166
+ *
167
+ * @returns A plain object representation of the error.
168
+ */
169
+ toJSON(): {
170
+ name: string;
171
+ code: EnterstellarErrorCode;
172
+ module: EnterstellarErrorModule;
173
+ message: string;
174
+ recoverable: boolean;
175
+ timestamp: string;
176
+ stack: string | undefined;
177
+ };
178
+ }
179
+
180
+ /**
181
+ * @module @enterstellar-ai/types/contract
182
+ * @description ComponentContract — the canonical data shape for registering
183
+ * a component in the Enterstellar ecosystem.
184
+ *
185
+ * A `ComponentContract` is pure data: schema, metadata, accessibility, and
186
+ * design tokens. It has **no `render` field** — rendering is handled by
187
+ * platform-specific renderer packages (`@enterstellar-ai/react`, `@enterstellar-ai/render-native`, etc.)
188
+ * per Design Choice R6.
189
+ *
190
+ * @see Bible §3.1
191
+ * @see Design Choices R1–R20, T1, T5, T9, T11
192
+ */
193
+
194
+ /**
195
+ * Predefined component categories.
196
+ * Extensible via `custom:{name}` prefix for domain-specific categories.
197
+ *
198
+ * @see Design Choice R11
199
+ */
200
+ type ComponentCategory = 'clinical' | 'admin' | 'navigation' | 'data-display' | 'form' | 'feedback' | 'layout' | 'utility' | `custom:${string}`;
201
+ /**
202
+ * Origin metadata for contracts fetched from federated registries.
203
+ * Populated when a contract is published or discovered remotely.
204
+ */
205
+ type ContractOrigin = {
206
+ /** URL of the remote registry that published this contract. */
207
+ readonly registryUrl: string;
208
+ /** Publisher identifier (e.g., org name or developer handle). */
209
+ readonly publisher: string;
210
+ /** ISO 8601 timestamp when the contract was verified. */
211
+ readonly verifiedAt?: string;
212
+ };
213
+ /**
214
+ * Internal metadata attached to every contract.
215
+ * Used for DevTools, telemetry, and Forge tracking.
216
+ */
217
+ type ContractMeta = {
218
+ /** Whether this contract was generated by the Forge. */
219
+ readonly forged: boolean;
220
+ /** Semantic version of the contract definition. */
221
+ readonly version: string;
222
+ /** ISO 8601 timestamp when the contract was created. */
223
+ readonly createdAt: string;
224
+ };
225
+ /**
226
+ * Accessibility configuration for a component.
227
+ * Enforced by the compiler's accessibility audit step.
228
+ */
229
+ type ComponentAccessibility = {
230
+ /** WAI-ARIA role for the component's root element. */
231
+ readonly role: string;
232
+ /** Accessible label describing the component. */
233
+ readonly ariaLabel: string;
234
+ /** Whether screen readers should announce dynamic updates. */
235
+ readonly announceOnUpdate: boolean;
236
+ };
237
+ /**
238
+ * Data source configuration for adapter-driven data fetching.
239
+ * Optional — components without a data source receive props directly.
240
+ */
241
+ type ComponentDataSource = {
242
+ /** Adapter type used to fetch data (e.g., `'supabase'`, `'firebase'`). */
243
+ readonly adapter: string;
244
+ /** The resource/table/collection to query. */
245
+ readonly resource: string;
246
+ /** Static query parameters merged with runtime params. */
247
+ readonly params?: Readonly<Record<string, unknown>>;
248
+ };
249
+ /**
250
+ * Auth requirements for rendering a component.
251
+ * When defined, the `AuthAdapter` gates component visibility.
252
+ */
253
+ type ComponentAuth = {
254
+ /** Whether the user must be authenticated to view this component. */
255
+ readonly required: boolean;
256
+ /** Roles permitted to view this component. Empty = any authenticated user. */
257
+ readonly roles: readonly string[];
258
+ };
259
+ /**
260
+ * Example data for a component contract.
261
+ * Powers the test harness, semantic index warmup, and DevTools previews.
262
+ *
263
+ * @see Design Choice R10
264
+ */
265
+ type ComponentExample = {
266
+ /** Machine-readable canonical intent query for this component. */
267
+ readonly intent: string;
268
+ /** Example props matching the component's schema. */
269
+ readonly props: Readonly<Record<string, unknown>>;
270
+ };
271
+ /**
272
+ * Lifecycle state renderers — each component must declare placeholder
273
+ * content for all four lifecycle states.
274
+ *
275
+ * @see Principle L9
276
+ */
277
+ type ComponentStates = {
278
+ /** Renderer key or content for the loading state. */
279
+ readonly loading: string;
280
+ /** Renderer key or content for the error state. */
281
+ readonly error: string;
282
+ /** Renderer key or content for the empty state. */
283
+ readonly empty: string;
284
+ /** Renderer key or content for the ready state. */
285
+ readonly ready: string;
286
+ };
287
+ /**
288
+ * The canonical data shape for a registered Enterstellar component.
289
+ *
290
+ * A `ComponentContract` is the "API surface" of a UI component within the
291
+ * Enterstellar ecosystem. It declares the component's schema (via Zod), semantics,
292
+ * accessibility requirements, design tokens, and lifecycle states.
293
+ *
294
+ * **Important:** This type has NO `render` field. Rendering is decoupled
295
+ * from the contract and handled by platform-specific renderers (L15, R6).
296
+ *
297
+ * @see Bible §3.1
298
+ */
299
+ type ComponentContract = {
300
+ /** PascalCase component name, unique within the registry. */
301
+ readonly name: string;
302
+ /** Branded component identifier derived from the name. */
303
+ readonly id: ComponentId;
304
+ /** Concise human-readable description. Max 120 characters (R2). */
305
+ readonly description: string;
306
+ /** Component category for classification and Forge routing. */
307
+ readonly category: ComponentCategory;
308
+ /** Semantic tags for fuzzy matching. Overlap between components is expected (R12). */
309
+ readonly tags: readonly string[];
310
+ /**
311
+ * Zod schema defining the component's prop interface.
312
+ * Used by the compiler for validation and self-correction.
313
+ */
314
+ readonly props: z.ZodType;
315
+ /** Design tokens referenced by this component. Values are symbolic (e.g., `'token:danger'`). */
316
+ readonly tokens: Readonly<Record<string, string>>;
317
+ /** Accessibility configuration. Enforced by the compiler. */
318
+ readonly accessibility: ComponentAccessibility;
319
+ /** Lifecycle state renderers. All four states are required (L9). */
320
+ readonly states: ComponentStates;
321
+ /** Example data for testing, warmup, and previews. */
322
+ readonly examples: readonly ComponentExample[];
323
+ /** Optional data source configuration for adapter-driven fetching. */
324
+ readonly dataSource?: ComponentDataSource;
325
+ /** Optional auth requirements for gating component visibility. */
326
+ readonly auth?: ComponentAuth;
327
+ /** Optional origin metadata for federated/remote contracts. */
328
+ readonly origin?: ContractOrigin;
329
+ /** Internal metadata for DevTools and telemetry. */
330
+ readonly _meta: ContractMeta;
331
+ };
332
+ /**
333
+ * Zod schema for validating `ComponentContract` data at runtime.
334
+ *
335
+ * Used by consumers to validate contracts fetched from remote registries,
336
+ * and internally by `@enterstellar-ai/registry` during registration.
337
+ *
338
+ * @see Design Choice T7
339
+ */
340
+ declare const ComponentContractSchema: z.ZodObject<{
341
+ name: z.ZodString;
342
+ id: z.ZodString;
343
+ description: z.ZodString;
344
+ category: z.ZodString;
345
+ tags: z.ZodArray<z.ZodString>;
346
+ props: z.ZodUnknown;
347
+ tokens: z.ZodRecord<z.ZodString, z.ZodString>;
348
+ accessibility: z.ZodObject<{
349
+ role: z.ZodString;
350
+ ariaLabel: z.ZodString;
351
+ announceOnUpdate: z.ZodBoolean;
352
+ }, z.core.$strip>;
353
+ states: z.ZodObject<{
354
+ loading: z.ZodString;
355
+ error: z.ZodString;
356
+ empty: z.ZodString;
357
+ ready: z.ZodString;
358
+ }, z.core.$strip>;
359
+ examples: z.ZodArray<z.ZodObject<{
360
+ intent: z.ZodString;
361
+ props: z.ZodRecord<z.ZodString, z.ZodUnknown>;
362
+ }, z.core.$strip>>;
363
+ dataSource: z.ZodOptional<z.ZodObject<{
364
+ adapter: z.ZodString;
365
+ resource: z.ZodString;
366
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
367
+ }, z.core.$strip>>;
368
+ auth: z.ZodOptional<z.ZodObject<{
369
+ required: z.ZodBoolean;
370
+ roles: z.ZodArray<z.ZodString>;
371
+ }, z.core.$strip>>;
372
+ origin: z.ZodOptional<z.ZodObject<{
373
+ registryUrl: z.ZodURL;
374
+ publisher: z.ZodString;
375
+ verifiedAt: z.ZodOptional<z.ZodString>;
376
+ }, z.core.$strip>>;
377
+ _meta: z.ZodObject<{
378
+ forged: z.ZodBoolean;
379
+ version: z.ZodString;
380
+ createdAt: z.ZodString;
381
+ }, z.core.$strip>;
382
+ }, z.core.$strip>;
383
+
384
+ /**
385
+ * @module @enterstellar-ai/types/token
386
+ * @description Design token types and resolver interface.
387
+ *
388
+ * Design tokens are symbolic references (e.g., `'token:danger'`) that the
389
+ * compiler validates and the renderer resolves to concrete CSS values at
390
+ * render time. This keeps contracts platform-agnostic and theme-portable.
391
+ *
392
+ * @see Bible §3.1b
393
+ * @see Design Choices R13, R14
394
+ * @see Appendix F T3 (W3C DTCG compliance)
395
+ */
396
+
397
+ /**
398
+ * A map of token names to symbolic token values.
399
+ *
400
+ * Values follow the `token:{name}` convention (e.g., `'token:danger'`,
401
+ * `'token:card-bg'`). Actual CSS values are resolved at render time
402
+ * by the platform-specific `TokenResolver`.
403
+ *
404
+ * @see Design Choice R13 — tokens resolved at render time, not registration.
405
+ * @see Design Choice R14 — no theming in DesignTokenSet; renderer handles themes.
406
+ */
407
+ type DesignTokenSet = Readonly<Record<string, string>>;
408
+ /**
409
+ * Zod schema for validating a `DesignTokenSet` at runtime.
410
+ * Ensures all values are non-empty strings.
411
+ */
412
+ declare const DesignTokenSetSchema: z.ZodType<Record<string, string>>;
413
+ /**
414
+ * Contextual information provided to the `TokenResolver` during
415
+ * token resolution. Enables platform-aware and theme-aware lookups.
416
+ */
417
+ type TokenResolverContext = {
418
+ /** Active platform for resolution (e.g., `'web'`, `'native'`, `'desktop'`). */
419
+ readonly platform?: string;
420
+ /** Active theme (e.g., `'light'`, `'dark'`). */
421
+ readonly theme?: string;
422
+ /** Display density (e.g., `'compact'`, `'comfortable'`, `'spacious'`). */
423
+ readonly density?: string;
424
+ };
425
+ /**
426
+ * Resolves symbolic design token paths to concrete CSS (or platform-specific) values.
427
+ *
428
+ * Implementations map W3C DTCG-compliant token paths to concrete values
429
+ * based on the active platform, theme, and density context.
430
+ *
431
+ * @see Appendix F T3 — W3C DTCG path mapping.
432
+ * @see Design Choice R13 — resolution happens at render time.
433
+ * @see Design Choice R14 — the resolver handles light/dark mode, not the contract.
434
+ *
435
+ * @example
436
+ * ```ts
437
+ * const resolver: TokenResolver = {
438
+ * resolve: (path, ctx) => {
439
+ * if (path === 'token:danger') {
440
+ * return ctx?.theme === 'dark' ? '#ff4444' : '#ff0000';
441
+ * }
442
+ * return undefined;
443
+ * },
444
+ * validate: (path) => path.startsWith('token:'),
445
+ * };
446
+ * ```
447
+ */
448
+ interface TokenResolver {
449
+ /**
450
+ * Resolves a token path to a concrete value.
451
+ *
452
+ * @param tokenPath - The symbolic token path (e.g., `'token:danger'`).
453
+ * @param context - Optional resolution context (platform, theme, density).
454
+ * @returns The resolved concrete value, or `undefined` if the token is unknown.
455
+ */
456
+ resolve(tokenPath: string, context?: TokenResolverContext): string | undefined;
457
+ /**
458
+ * Validates whether a token path exists in the active token set.
459
+ *
460
+ * @param tokenPath - The symbolic token path to validate.
461
+ * @returns `true` if the token path is known and resolvable.
462
+ */
463
+ validate(tokenPath: string): boolean;
464
+ }
465
+
466
+ /**
467
+ * @module @enterstellar-ai/types/intent
468
+ * @description ComponentIntent — the normalized message from an AI agent
469
+ * to the Enterstellar rendering pipeline.
470
+ *
471
+ * A `ComponentIntent` is what the normalizer produces from any protocol
472
+ * (AG-UI, A2UI, MCP, WebSocket, SSE). It is the universal input to the
473
+ * compiler.
474
+ *
475
+ * @see Bible §3.2
476
+ * @see Design Choices T3, T11
477
+ * @see Appendix E P2 (correlationId), P8 (mode, interaction)
478
+ */
479
+
480
+ /**
481
+ * Protocol that produced this intent.
482
+ * Each normalizer handles one protocol.
483
+ *
484
+ * @see Bible §4.9 — Normalizer
485
+ */
486
+ type IntentProtocol = 'ag-ui' | 'a2ui' | 'mcp' | 'websocket' | 'sse' | 'custom';
487
+ /**
488
+ * Layout hint for multi-zone rendering.
489
+ * Used by the resolver to position components within a zone.
490
+ */
491
+ type IntentLayout = 'single' | 'split' | 'grid' | 'stack' | 'tabs';
492
+ /**
493
+ * Interaction mode for the component.
494
+ * Closed enum — 3 values are exhaustive.
495
+ *
496
+ * @see Appendix E P8
497
+ */
498
+ type IntentInteraction = 'read-only' | 'editable' | 'actionable';
499
+ /**
500
+ * Source metadata injected by the normalizer.
501
+ * Preserves protocol-specific context for tracing and debugging.
502
+ */
503
+ type IntentSource = {
504
+ /** The protocol that produced this intent. */
505
+ readonly protocol: IntentProtocol;
506
+ /** Raw event ID from the source protocol, if available. */
507
+ readonly rawEventId?: string;
508
+ /**
509
+ * Correlation ID tying related events across a multi-step interaction chain.
510
+ * Extracted from the protocol (AG-UI `runId`, MCP `requestId`) or UUIDv4-generated.
511
+ *
512
+ * @see Appendix E P2
513
+ */
514
+ readonly correlationId?: string;
515
+ /** Raw payload from the source protocol, preserved for debugging. */
516
+ readonly raw?: unknown;
517
+ };
518
+ /**
519
+ * The normalized message from an AI agent to the Enterstellar rendering pipeline.
520
+ *
521
+ * Produced by the normalizer from any supported protocol. Consumed by the
522
+ * compiler for validation, token enforcement, and accessibility auditing.
523
+ *
524
+ * @see Bible §3.2
525
+ */
526
+ type ComponentIntent = {
527
+ /** PascalCase name of the target component in the registry. */
528
+ readonly component: string;
529
+ /** Props to pass to the component, validated by the compiler against the contract schema. */
530
+ readonly props: Readonly<Record<string, unknown>>;
531
+ /**
532
+ * Confidence score from the agent (0.0–1.0).
533
+ * Used by the compiler for fallback decisions and trace reporting.
534
+ */
535
+ readonly confidence: number;
536
+ /** Optional layout hint for multi-zone rendering. */
537
+ readonly layout?: IntentLayout;
538
+ /**
539
+ * Display mode hint for disambiguation.
540
+ * Open type — allows domain-specific modes without requiring `@enterstellar-ai/types` releases.
541
+ * Recommended values: `'snapshot'`, `'time-series'`, `'comparison'`, `'detail'`,
542
+ * `'summary'`, `'list'`.
543
+ *
544
+ * @see Appendix E P8
545
+ */
546
+ readonly mode?: string;
547
+ /**
548
+ * Interaction mode for the component.
549
+ * Helps the semantic index disambiguate (e.g., "show vitals" vs "edit vitals").
550
+ *
551
+ * @see Appendix E P8
552
+ */
553
+ readonly interaction?: IntentInteraction;
554
+ /** Protocol-specific source metadata injected by the normalizer. */
555
+ readonly _source?: IntentSource;
556
+ };
557
+ /**
558
+ * Zod schema for validating `ComponentIntent` data at runtime.
559
+ *
560
+ * @see Design Choice T7
561
+ */
562
+ declare const ComponentIntentSchema: z.ZodObject<{
563
+ component: z.ZodString;
564
+ props: z.ZodRecord<z.ZodString, z.ZodUnknown>;
565
+ confidence: z.ZodNumber;
566
+ layout: z.ZodOptional<z.ZodEnum<{
567
+ split: "split";
568
+ single: "single";
569
+ grid: "grid";
570
+ stack: "stack";
571
+ tabs: "tabs";
572
+ }>>;
573
+ mode: z.ZodOptional<z.ZodString>;
574
+ interaction: z.ZodOptional<z.ZodEnum<{
575
+ "read-only": "read-only";
576
+ editable: "editable";
577
+ actionable: "actionable";
578
+ }>>;
579
+ _source: z.ZodOptional<z.ZodObject<{
580
+ protocol: z.ZodEnum<{
581
+ custom: "custom";
582
+ "ag-ui": "ag-ui";
583
+ a2ui: "a2ui";
584
+ mcp: "mcp";
585
+ websocket: "websocket";
586
+ sse: "sse";
587
+ }>;
588
+ rawEventId: z.ZodOptional<z.ZodString>;
589
+ correlationId: z.ZodOptional<z.ZodString>;
590
+ raw: z.ZodOptional<z.ZodUnknown>;
591
+ }, z.core.$strip>>;
592
+ }, z.core.$strip>;
593
+
594
+ /**
595
+ * @module @enterstellar-ai/types/compiler
596
+ * @description Compilation result types — the output of the Enterstellar UI Compiler.
597
+ *
598
+ * After the compiler validates a `ComponentIntent` against its
599
+ * `ComponentContract`, it produces a `CompilationResult` with provenance,
600
+ * validation status, and any errors encountered.
601
+ *
602
+ * @see Bible §3.3
603
+ * @see Design Choices C1–C20, T1, T5, T11
604
+ */
605
+
606
+ /**
607
+ * Compilation outcome status.
608
+ * - `'pass'` — intent validated successfully, component is safe to render.
609
+ * - `'fail'` — validation failed, fallback should be rendered.
610
+ * - `'corrected'` — LLM self-correction fixed the original errors.
611
+ */
612
+ type CompilationStatus = 'pass' | 'fail' | 'corrected';
613
+ /**
614
+ * Provenance metadata attached to every compilation result.
615
+ * Tracks the agent, registry, and compiler that produced the result
616
+ * for auditability and the trust frame.
617
+ *
618
+ * @see Design Choice C12 — consumer passes `agent` via explicit parameter.
619
+ */
620
+ type CompilationProvenance = {
621
+ /** Identifier of the AI agent/model that generated the intent (e.g., `'gpt-4o'`). */
622
+ readonly agent: string;
623
+ /** URL or name of the registry used for component resolution. */
624
+ readonly registry: string;
625
+ /** ISO 8601 timestamp when compilation occurred. */
626
+ readonly compiledAt: string;
627
+ /** Semantic version of the compiler that produced this result. */
628
+ readonly compilerVersion: string;
629
+ /** Forge mode used, if the component was forged. `undefined` for registry components. */
630
+ readonly forgeMode?: 'local' | 'cloud';
631
+ /** Origin metadata for the resolved contract, if it came from a remote registry. */
632
+ readonly contractOrigin?: {
633
+ /** URL of the originating registry. */
634
+ readonly registryUrl: string;
635
+ /** Publisher of the contract. */
636
+ readonly publisher: string;
637
+ };
638
+ };
639
+ /**
640
+ * Machine-readable suggestion for fixing a compilation error.
641
+ * Enables auto-fix in DevTools, self-correction loops, and CI reporting.
642
+ *
643
+ * @see Design Choice C15
644
+ */
645
+ type CompilationFix = {
646
+ /** The prop field path that should be changed (e.g., `'tokens.color'`). */
647
+ readonly field: string;
648
+ /** The invalid value that was provided. */
649
+ readonly was: unknown;
650
+ /** The correct value that should be used instead. */
651
+ readonly shouldBe: unknown;
652
+ };
653
+ /**
654
+ * A single compilation error with a machine-readable code, path, and optional fix.
655
+ *
656
+ * @see Design Choice C14 — `ENS-2xxx` codes for compiler errors.
657
+ * @see Design Choice C15 — all errors include a `fix` suggestion where applicable.
658
+ */
659
+ type CompilationError = {
660
+ /** Machine-readable error code (e.g., `'ENS-2001'`). */
661
+ readonly code: string;
662
+ /** Dot-path to the invalid field (e.g., `'props.riskLevel'`). */
663
+ readonly path: string;
664
+ /** Human-readable error message. */
665
+ readonly message: string;
666
+ /** The value that was received. */
667
+ readonly received?: unknown;
668
+ /** The value that was expected. */
669
+ readonly expected?: unknown;
670
+ /** Machine-readable fix suggestion, if applicable. */
671
+ readonly fix?: CompilationFix;
672
+ };
673
+ /**
674
+ * The output of the Enterstellar UI Compiler after validating a `ComponentIntent`.
675
+ *
676
+ * Contains the resolved component name, validated props, compilation status,
677
+ * provenance for auditability, and any errors encountered during validation.
678
+ *
679
+ * @see Bible §3.3
680
+ */
681
+ type CompilationResult = {
682
+ /** PascalCase name of the resolved component. */
683
+ readonly componentName: string;
684
+ /** Validated props after schema parsing, token enforcement, and accessibility injection. */
685
+ readonly props: Readonly<Record<string, unknown>>;
686
+ /** Compilation outcome status. */
687
+ readonly status: CompilationStatus;
688
+ /** Provenance metadata for tracing and the trust frame. */
689
+ readonly provenance: CompilationProvenance;
690
+ /** Validation errors encountered during compilation. Empty if `status === 'pass'`. */
691
+ readonly errors: readonly CompilationError[];
692
+ /** Number of self-correction attempts made before final result. */
693
+ readonly selfCorrectionAttempts: number;
694
+ /**
695
+ * Diff between raw LLM props and final compiled props.
696
+ * Included when `includeDiff` config flag is `true` (default in dev, off in prod).
697
+ *
698
+ * @see Design Choice C13
699
+ */
700
+ readonly diff?: {
701
+ /** The raw props as received from the agent. */
702
+ readonly raw: Readonly<Record<string, unknown>>;
703
+ /** The final compiled props after correction, stripping, and injection. */
704
+ readonly compiled: Readonly<Record<string, unknown>>;
705
+ };
706
+ /**
707
+ * Correction trace for DevTools and performance profiling.
708
+ *
709
+ * Populated when `selfCorrection.trace === true` in the compiler config.
710
+ * Each entry records a single correction applied by Tier 1 (deterministic)
711
+ * or Tier 2 (template), including the field, original value, corrected value,
712
+ * and the strategy used.
713
+ *
714
+ * Default: omitted in production. Enabled automatically when DevTools are
715
+ * attached, or explicitly via `selfCorrection: { trace: true }`.
716
+ *
717
+ * @see Design Choice SC-11 — correction trace entry design.
718
+ * @see Design Choice SC-08 — `trace` flag in `SelfCorrectionConfig`.
719
+ */
720
+ readonly correctionTrace?: readonly {
721
+ /** Which tier applied this correction (`1` = deterministic, `2` = template). */
722
+ readonly tier: 1 | 2;
723
+ /** The error code that was corrected (e.g., `'ENS-2001'`). */
724
+ readonly errorCode: string;
725
+ /** The field path that was corrected. */
726
+ readonly field: string;
727
+ /** The original invalid value. */
728
+ readonly was: unknown;
729
+ /** The corrected value. */
730
+ readonly correctedTo: unknown;
731
+ /** The correction strategy used (e.g., `'type-coercion'`, `'enum-nearest'`). */
732
+ readonly strategy: string;
733
+ }[];
734
+ };
735
+ /**
736
+ * Zod schema for validating a `CompilationError` at runtime.
737
+ *
738
+ * @see Design Choice T7
739
+ */
740
+ declare const CompilationErrorSchema: z.ZodObject<{
741
+ code: z.ZodString;
742
+ path: z.ZodString;
743
+ message: z.ZodString;
744
+ received: z.ZodOptional<z.ZodUnknown>;
745
+ expected: z.ZodOptional<z.ZodUnknown>;
746
+ fix: z.ZodOptional<z.ZodObject<{
747
+ field: z.ZodString;
748
+ was: z.ZodUnknown;
749
+ shouldBe: z.ZodUnknown;
750
+ }, z.core.$strip>>;
751
+ }, z.core.$strip>;
752
+ /**
753
+ * Zod schema for validating a `CompilationResult` at runtime.
754
+ *
755
+ * @see Design Choice T7
756
+ */
757
+ declare const CompilationResultSchema: z.ZodObject<{
758
+ componentName: z.ZodString;
759
+ props: z.ZodRecord<z.ZodString, z.ZodUnknown>;
760
+ status: z.ZodEnum<{
761
+ pass: "pass";
762
+ fail: "fail";
763
+ corrected: "corrected";
764
+ }>;
765
+ provenance: z.ZodObject<{
766
+ agent: z.ZodString;
767
+ registry: z.ZodString;
768
+ compiledAt: z.ZodString;
769
+ compilerVersion: z.ZodString;
770
+ forgeMode: z.ZodOptional<z.ZodEnum<{
771
+ cloud: "cloud";
772
+ local: "local";
773
+ }>>;
774
+ contractOrigin: z.ZodOptional<z.ZodObject<{
775
+ registryUrl: z.ZodString;
776
+ publisher: z.ZodString;
777
+ }, z.core.$strip>>;
778
+ }, z.core.$strip>;
779
+ errors: z.ZodArray<z.ZodObject<{
780
+ code: z.ZodString;
781
+ path: z.ZodString;
782
+ message: z.ZodString;
783
+ received: z.ZodOptional<z.ZodUnknown>;
784
+ expected: z.ZodOptional<z.ZodUnknown>;
785
+ fix: z.ZodOptional<z.ZodObject<{
786
+ field: z.ZodString;
787
+ was: z.ZodUnknown;
788
+ shouldBe: z.ZodUnknown;
789
+ }, z.core.$strip>>;
790
+ }, z.core.$strip>>;
791
+ selfCorrectionAttempts: z.ZodNumber;
792
+ diff: z.ZodOptional<z.ZodObject<{
793
+ raw: z.ZodRecord<z.ZodString, z.ZodUnknown>;
794
+ compiled: z.ZodRecord<z.ZodString, z.ZodUnknown>;
795
+ }, z.core.$strip>>;
796
+ correctionTrace: z.ZodOptional<z.ZodArray<z.ZodObject<{
797
+ tier: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>;
798
+ errorCode: z.ZodString;
799
+ field: z.ZodString;
800
+ was: z.ZodUnknown;
801
+ correctedTo: z.ZodUnknown;
802
+ strategy: z.ZodString;
803
+ }, z.core.$strip>>>;
804
+ }, z.core.$strip>;
805
+
806
+ /**
807
+ * @module @enterstellar-ai/types/trace
808
+ * @description AgentTrace — the observability record for every Enterstellar pipeline execution.
809
+ *
810
+ * Every intent processed by Enterstellar produces an `AgentTrace` capturing intent,
811
+ * resolution, compilation, determinism, and performance metrics. Traces power
812
+ * the DevTools timeline, validation log, and performance profiler.
813
+ *
814
+ * @see Bible §3.4
815
+ * @see Design Choices T5, T11
816
+ * @see Appendix E P2 (correlationId), consent fields
817
+ */
818
+
819
+ /**
820
+ * Intent data captured in the trace.
821
+ * Records what the agent requested.
822
+ */
823
+ type TraceIntent = {
824
+ /** Raw intent string or component name from the agent. */
825
+ readonly raw: string;
826
+ /** Parsed component name after normalization. */
827
+ readonly component: string;
828
+ /** Confidence score from the agent (0.0–1.0). */
829
+ readonly confidence: number;
830
+ /** Display mode, if provided. */
831
+ readonly mode?: string;
832
+ /** Interaction type, if provided. */
833
+ readonly interaction?: string;
834
+ };
835
+ /**
836
+ * Resolution data captured in the trace.
837
+ * Records how the intent was resolved to a component.
838
+ */
839
+ type TraceResolution = {
840
+ /** How the component was resolved. */
841
+ readonly strategy: 'exact' | 'semantic' | 'forge' | 'fallback';
842
+ /** Name of the resolved component. */
843
+ readonly resolvedComponent: string;
844
+ /** Semantic similarity score, if semantic search was used. */
845
+ readonly similarityScore?: number;
846
+ /** Number of candidate components considered before selection. */
847
+ readonly candidatesConsidered: number;
848
+ };
849
+ /**
850
+ * Compilation data captured in the trace.
851
+ * Records the compiler's validation outcome.
852
+ */
853
+ type TraceCompilation = {
854
+ /** Final compilation status. */
855
+ readonly status: 'pass' | 'fail' | 'corrected';
856
+ /** Number of validation errors encountered (including self-corrected ones). */
857
+ readonly errorCount: number;
858
+ /** Number of self-correction attempts made. */
859
+ readonly selfCorrectionAttempts: number;
860
+ /** Whether design token enforcement was applied. */
861
+ readonly tokensValidated: boolean;
862
+ /** Whether accessibility attributes were auto-injected. */
863
+ readonly accessibilityInjected: boolean;
864
+ };
865
+ /**
866
+ * Determinism data captured in the trace.
867
+ * Records the zone's determinism configuration at render time.
868
+ */
869
+ type TraceDeterminism = {
870
+ /** Zone determinism level (0.0–1.0). */
871
+ readonly level: number;
872
+ /** Whether a cached result was used. */
873
+ readonly cacheHit: boolean;
874
+ /** The zone name this trace belongs to. */
875
+ readonly zone: string;
876
+ };
877
+ /**
878
+ * Performance metrics captured in the trace.
879
+ * Powers the DevTools performance profiler.
880
+ */
881
+ type TraceMetrics = {
882
+ /** Total pipeline latency in milliseconds (intent → rendered). */
883
+ readonly totalMs: number;
884
+ /** Time from intent reception to resolution in milliseconds. */
885
+ readonly resolutionMs: number;
886
+ /** Time from resolution to compilation completion in milliseconds. */
887
+ readonly compilationMs: number;
888
+ /** Time from compilation to rendered output in milliseconds. */
889
+ readonly renderMs: number;
890
+ };
891
+ /**
892
+ * User consent state for trace aggregation.
893
+ * Required for Enterstellar Cloud's trace aggregation API (opt-in).
894
+ *
895
+ * @see Appendix E — TL10 (ForgeSignal vs AgentTrace consent distinction)
896
+ */
897
+ type TraceConsent = {
898
+ /** Whether this trace can be aggregated anonymously for analytics. */
899
+ readonly anonymizedAggregation: boolean;
900
+ };
901
+ /**
902
+ * Partial trace produced by `Zone` during compilation.
903
+ *
904
+ * `ZoneTrace` captures what the zone actually has at compile time:
905
+ * intent, compilation status/errors, provenance, and zone-level metrics.
906
+ * It does NOT include `resolution`, `determinism`, or `consent` fields —
907
+ * those require the full compiler/lifecycle pipeline to produce.
908
+ *
909
+ * The fully resolved `AgentTrace` is assembled downstream by
910
+ * `@enterstellar-ai/lifecycle` when all pipeline stages are complete.
911
+ *
912
+ * @see {@link AgentTrace} — the fully resolved trace with all pipeline stages.
913
+ * @see Bible §5.3 — Zone specification.
914
+ * @see Design Choice RE18 — `onError` callback receives this trace type.
915
+ */
916
+ type ZoneTrace = {
917
+ /** Unique zone-trace identifier (format: `{zoneName}-{compilationId}-{timestamp}`). */
918
+ readonly id: string;
919
+ /** The raw `ComponentIntent` that triggered compilation. */
920
+ readonly intent: ComponentIntent;
921
+ /**
922
+ * Compilation outcome data — status, errors, and self-correction attempts.
923
+ * This is a subset of the full `TraceCompilation` shape.
924
+ */
925
+ readonly compilation: {
926
+ /** Final compilation status (`pass`, `fail`, or `corrected`). */
927
+ readonly status: CompilationStatus;
928
+ /** Validation errors encountered during compilation. */
929
+ readonly errors: readonly CompilationError[];
930
+ /** Number of self-correction attempts made before final result. */
931
+ readonly selfCorrectionAttempts: number;
932
+ };
933
+ /** Provenance metadata from the `CompilationResult`. */
934
+ readonly provenance: CompilationProvenance;
935
+ /**
936
+ * Zone-level performance metrics.
937
+ *
938
+ * Unlike `TraceMetrics` (which breaks down resolution/compilation/render),
939
+ * this only captures total latency and retry attempt count.
940
+ */
941
+ readonly metrics: {
942
+ /** Total time from intent reception to render in milliseconds. */
943
+ readonly totalMs: number;
944
+ /** Current retry attempt number (0-indexed). */
945
+ readonly retryAttempt: number;
946
+ };
947
+ /** ISO 8601 timestamp when this trace was created. */
948
+ readonly timestamp: string;
949
+ };
950
+ /**
951
+ * Zod schema for validating a `ZoneTrace` at runtime.
952
+ *
953
+ * This is the **canonical single-source-of-truth** for `ZoneTrace` validation.
954
+ * Used by:
955
+ * - `Provider` to register the `'traces'` store extension (S2).
956
+ * - DevTools for trace data integrity validation.
957
+ * - Tests for fixture construction.
958
+ *
959
+ * The schema reuses `ComponentIntentSchema` and `CompilationErrorSchema`
960
+ * from their respective modules (T7: co-located schemas, no duplication).
961
+ *
962
+ * @see Design Choice T7 — every type has a co-located Zod schema.
963
+ * @see Design Choice S2 — typed `store.extend()` requires a Zod schema.
964
+ * @see {@link ZoneTrace} — the TypeScript type this schema validates.
965
+ */
966
+ declare const ZoneTraceSchema: z.ZodObject<{
967
+ id: z.ZodString;
968
+ intent: z.ZodObject<{
969
+ component: z.ZodString;
970
+ props: z.ZodRecord<z.ZodString, z.ZodUnknown>;
971
+ confidence: z.ZodNumber;
972
+ layout: z.ZodOptional<z.ZodEnum<{
973
+ split: "split";
974
+ single: "single";
975
+ grid: "grid";
976
+ stack: "stack";
977
+ tabs: "tabs";
978
+ }>>;
979
+ mode: z.ZodOptional<z.ZodString>;
980
+ interaction: z.ZodOptional<z.ZodEnum<{
981
+ "read-only": "read-only";
982
+ editable: "editable";
983
+ actionable: "actionable";
984
+ }>>;
985
+ _source: z.ZodOptional<z.ZodObject<{
986
+ protocol: z.ZodEnum<{
987
+ custom: "custom";
988
+ "ag-ui": "ag-ui";
989
+ a2ui: "a2ui";
990
+ mcp: "mcp";
991
+ websocket: "websocket";
992
+ sse: "sse";
993
+ }>;
994
+ rawEventId: z.ZodOptional<z.ZodString>;
995
+ correlationId: z.ZodOptional<z.ZodString>;
996
+ raw: z.ZodOptional<z.ZodUnknown>;
997
+ }, z.core.$strip>>;
998
+ }, z.core.$strip>;
999
+ compilation: z.ZodObject<{
1000
+ status: z.ZodEnum<{
1001
+ pass: "pass";
1002
+ fail: "fail";
1003
+ corrected: "corrected";
1004
+ }>;
1005
+ errors: z.ZodArray<z.ZodObject<{
1006
+ code: z.ZodString;
1007
+ path: z.ZodString;
1008
+ message: z.ZodString;
1009
+ received: z.ZodOptional<z.ZodUnknown>;
1010
+ expected: z.ZodOptional<z.ZodUnknown>;
1011
+ fix: z.ZodOptional<z.ZodObject<{
1012
+ field: z.ZodString;
1013
+ was: z.ZodUnknown;
1014
+ shouldBe: z.ZodUnknown;
1015
+ }, z.core.$strip>>;
1016
+ }, z.core.$strip>>;
1017
+ selfCorrectionAttempts: z.ZodNumber;
1018
+ }, z.core.$strip>;
1019
+ provenance: z.ZodObject<{
1020
+ agent: z.ZodString;
1021
+ registry: z.ZodString;
1022
+ compiledAt: z.ZodString;
1023
+ compilerVersion: z.ZodString;
1024
+ forgeMode: z.ZodOptional<z.ZodEnum<{
1025
+ cloud: "cloud";
1026
+ local: "local";
1027
+ }>>;
1028
+ contractOrigin: z.ZodOptional<z.ZodObject<{
1029
+ registryUrl: z.ZodString;
1030
+ publisher: z.ZodString;
1031
+ }, z.core.$strip>>;
1032
+ }, z.core.$strip>;
1033
+ metrics: z.ZodObject<{
1034
+ totalMs: z.ZodNumber;
1035
+ retryAttempt: z.ZodNumber;
1036
+ }, z.core.$strip>;
1037
+ timestamp: z.ZodString;
1038
+ }, z.core.$strip>;
1039
+ /**
1040
+ * The complete observability record for a single Enterstellar pipeline execution.
1041
+ *
1042
+ * Produced on every `compile()` call. Stored in `EnterstellarStore.traces[]`.
1043
+ * Consumed by DevTools (timeline, inspector, profiler, replay) and
1044
+ * optionally by Enterstellar Cloud for aggregated analytics.
1045
+ *
1046
+ * @see Bible §3.4
1047
+ * @see {@link ZoneTrace} — the zone-level precursor trace produced by `Zone`.
1048
+ */
1049
+ type AgentTrace = {
1050
+ /** Unique trace identifier. */
1051
+ readonly id: TraceId;
1052
+ /** ISO 8601 timestamp when the trace was created. */
1053
+ readonly timestamp: string;
1054
+ /**
1055
+ * Correlation ID tying related events across a multi-step interaction chain.
1056
+ * Enables DevTools Trace Timeline to group related events.
1057
+ *
1058
+ * @see Appendix E P2
1059
+ */
1060
+ readonly correlationId?: string;
1061
+ /** Intent data: what the agent requested. */
1062
+ readonly intent: TraceIntent;
1063
+ /** Resolution data: how the component was found. */
1064
+ readonly resolution: TraceResolution;
1065
+ /** Compilation data: the compiler's validation outcome. */
1066
+ readonly compilation: TraceCompilation;
1067
+ /** Determinism data: the zone's configuration at render time. */
1068
+ readonly determinism: TraceDeterminism;
1069
+ /** Performance metrics: latency breakdown. */
1070
+ readonly metrics: TraceMetrics;
1071
+ /** User consent state for trace aggregation. */
1072
+ readonly consent: TraceConsent;
1073
+ };
1074
+ /**
1075
+ * Zod schema for validating an `AgentTrace` at runtime.
1076
+ *
1077
+ * @see Design Choice T7
1078
+ */
1079
+ declare const AgentTraceSchema: z.ZodObject<{
1080
+ id: z.ZodString;
1081
+ timestamp: z.ZodString;
1082
+ correlationId: z.ZodOptional<z.ZodString>;
1083
+ intent: z.ZodObject<{
1084
+ raw: z.ZodString;
1085
+ component: z.ZodString;
1086
+ confidence: z.ZodNumber;
1087
+ mode: z.ZodOptional<z.ZodString>;
1088
+ interaction: z.ZodOptional<z.ZodString>;
1089
+ }, z.core.$strip>;
1090
+ resolution: z.ZodObject<{
1091
+ strategy: z.ZodEnum<{
1092
+ forge: "forge";
1093
+ exact: "exact";
1094
+ semantic: "semantic";
1095
+ fallback: "fallback";
1096
+ }>;
1097
+ resolvedComponent: z.ZodString;
1098
+ similarityScore: z.ZodOptional<z.ZodNumber>;
1099
+ candidatesConsidered: z.ZodNumber;
1100
+ }, z.core.$strip>;
1101
+ compilation: z.ZodObject<{
1102
+ status: z.ZodEnum<{
1103
+ pass: "pass";
1104
+ fail: "fail";
1105
+ corrected: "corrected";
1106
+ }>;
1107
+ errorCount: z.ZodNumber;
1108
+ selfCorrectionAttempts: z.ZodNumber;
1109
+ tokensValidated: z.ZodBoolean;
1110
+ accessibilityInjected: z.ZodBoolean;
1111
+ }, z.core.$strip>;
1112
+ determinism: z.ZodObject<{
1113
+ level: z.ZodNumber;
1114
+ cacheHit: z.ZodBoolean;
1115
+ zone: z.ZodString;
1116
+ }, z.core.$strip>;
1117
+ metrics: z.ZodObject<{
1118
+ totalMs: z.ZodNumber;
1119
+ resolutionMs: z.ZodNumber;
1120
+ compilationMs: z.ZodNumber;
1121
+ renderMs: z.ZodNumber;
1122
+ }, z.core.$strip>;
1123
+ consent: z.ZodObject<{
1124
+ anonymizedAggregation: z.ZodBoolean;
1125
+ }, z.core.$strip>;
1126
+ }, z.core.$strip>;
1127
+
1128
+ /**
1129
+ * @module @enterstellar-ai/types/config
1130
+ * @description ZoneConfig — configuration for an Zone instance.
1131
+ *
1132
+ * A `ZoneConfig` defines the behavior, constraints, and rendering rules
1133
+ * for a specific Zone. The `determinism` dial (0.0–1.0) controls
1134
+ * how much AI influence the zone allows.
1135
+ *
1136
+ * @see Bible §3.5
1137
+ * @see Design Choices T13 (determinism as raw number), RE5–RE8
1138
+ */
1139
+
1140
+ /**
1141
+ * Cache configuration for a zone.
1142
+ * Controls whether and how the zone caches compiled results.
1143
+ */
1144
+ type ZoneCacheConfig = {
1145
+ /** Whether caching is enabled for this zone. */
1146
+ readonly enabled: boolean;
1147
+ /** Time-to-live for cached entries in seconds. Default: 3600. */
1148
+ readonly ttl: number;
1149
+ };
1150
+ /**
1151
+ * Configuration for an Zone instance.
1152
+ *
1153
+ * The `determinism` value is the primary control:
1154
+ * - `0.0` → fully static, agent never called (compliance zones)
1155
+ * - `0.0–1.0` → hybrid: fixed layout with agent-selected components in slots
1156
+ * - `1.0` → fully dynamic, agent controls everything in the zone
1157
+ *
1158
+ * @see Bible §3.5
1159
+ * @see Design Choice T13 — raw number with Zod validation, not branded type.
1160
+ */
1161
+ type ZoneConfig = {
1162
+ /** Branded zone identifier. */
1163
+ readonly id: ZoneId;
1164
+ /** Human-readable zone name (e.g., `'patient-sidebar'`). */
1165
+ readonly name: string;
1166
+ /**
1167
+ * Determinism level (0.0–1.0).
1168
+ * Controls AI influence over the zone's content.
1169
+ *
1170
+ * @see Design Choice T13 — validated via `z.number().min(0).max(1)`.
1171
+ */
1172
+ readonly determinism: number;
1173
+ /** Whitelist of component names allowed in this zone. Empty = all allowed. */
1174
+ readonly allowedComponents: readonly string[];
1175
+ /** Fallback component name to render when the agent fails or times out. */
1176
+ readonly fallbackComponent: string;
1177
+ /** Maximum time in milliseconds to wait for the agent before rendering fallback. */
1178
+ readonly agentTimeoutMs: number;
1179
+ /** Cache configuration for this zone. */
1180
+ readonly cache: ZoneCacheConfig;
1181
+ /**
1182
+ * Zone activation strategy.
1183
+ * - `'mount'` — call agent on component mount (default).
1184
+ * - `'visible'` — call agent when zone enters viewport (IntersectionObserver).
1185
+ * - `'manual'` — consumer calls `zone.activate()` programmatically.
1186
+ *
1187
+ * @see Design Choice RE6
1188
+ */
1189
+ readonly activateOn: 'mount' | 'visible' | 'manual';
1190
+ };
1191
+ /**
1192
+ * Zod schema for validating `ZoneConfig` data at runtime.
1193
+ *
1194
+ * @see Design Choice T7, T13
1195
+ */
1196
+ declare const ZoneConfigSchema: z.ZodObject<{
1197
+ id: z.ZodString;
1198
+ name: z.ZodString;
1199
+ determinism: z.ZodNumber;
1200
+ allowedComponents: z.ZodArray<z.ZodString>;
1201
+ fallbackComponent: z.ZodString;
1202
+ agentTimeoutMs: z.ZodNumber;
1203
+ cache: z.ZodObject<{
1204
+ enabled: z.ZodBoolean;
1205
+ ttl: z.ZodNumber;
1206
+ }, z.core.$strip>;
1207
+ activateOn: z.ZodEnum<{
1208
+ mount: "mount";
1209
+ visible: "visible";
1210
+ manual: "manual";
1211
+ }>;
1212
+ }, z.core.$strip>;
1213
+
1214
+ /**
1215
+ * @module @enterstellar-ai/types/adapters
1216
+ * @description Adapter interfaces for infrastructure integration.
1217
+ *
1218
+ * Adapters provide the bridge between Enterstellar components and external services
1219
+ * (auth, data, errors, analytics). Each adapter follows a strict interface
1220
+ * defined here — implementations live in `@enterstellar-ai/adapter-*` packages.
1221
+ *
1222
+ * @see Bible §3.6
1223
+ * @see Design Choice T1 — interfaces for objects with methods.
1224
+ */
1225
+ /**
1226
+ * Authentication adapter interface.
1227
+ *
1228
+ * Implementations gate component visibility based on auth state.
1229
+ * Three methods: `getSession()` for current state, `hasRole()` for
1230
+ * RBAC (clinical vs admin zones), and `onAuthChange()` for reactive
1231
+ * auth gating — zones re-evaluate visibility when sessions expire
1232
+ * or roles change.
1233
+ *
1234
+ * `signIn()`/`signOut()` are NOT adapter concerns — they belong to
1235
+ * the auth provider (Supabase, Clerk, Firebase, etc.).
1236
+ *
1237
+ * @see Bible §3.6
1238
+ * @see Design Choice AD1
1239
+ */
1240
+ interface AuthAdapter {
1241
+ /**
1242
+ * Gets the current authentication session, if any.
1243
+ *
1244
+ * @returns Session object with user ID and roles, or `null` if unauthenticated.
1245
+ */
1246
+ getSession(): Promise<{
1247
+ userId: string;
1248
+ roles: string[];
1249
+ } | null>;
1250
+ /**
1251
+ * Checks whether the current user has a specific role.
1252
+ * Essential for RBAC — determines clinical vs admin zone visibility.
1253
+ *
1254
+ * @param role - The role to check for (e.g., `'clinician'`, `'admin'`).
1255
+ * @returns `true` if the user has the role.
1256
+ */
1257
+ hasRole(role: string): Promise<boolean>;
1258
+ /**
1259
+ * Subscribes to authentication state changes.
1260
+ *
1261
+ * Essential for reactive auth gating — zones re-evaluate visibility
1262
+ * when sessions expire or roles change. Every major auth provider
1263
+ * supports this: Supabase `onAuthStateChange()`, Firebase
1264
+ * `onAuthStateChanged()`, Clerk `addListener()`.
1265
+ *
1266
+ * @param callback - Called when auth state changes. Receives the new
1267
+ * session object, or `null` if the user became unauthenticated.
1268
+ * @returns An unsubscribe function (synchronous).
1269
+ *
1270
+ * @example
1271
+ * ```ts
1272
+ * const unsubscribe = auth.onAuthChange((session) => {
1273
+ * if (!session) console.log('User signed out');
1274
+ * });
1275
+ * // Later: unsubscribe();
1276
+ * ```
1277
+ */
1278
+ onAuthChange(callback: (session: {
1279
+ userId: string;
1280
+ roles: string[];
1281
+ } | null) => void): () => void;
1282
+ }
1283
+ /**
1284
+ * Data access adapter interface.
1285
+ * Implementations resolve component `dataSource` fields to actual data.
1286
+ *
1287
+ * @see Bible §3.6
1288
+ */
1289
+ interface DataAdapter {
1290
+ /**
1291
+ * Queries a resource by name with optional parameters.
1292
+ *
1293
+ * @param resource - The resource/table/collection to query.
1294
+ * @param params - Optional query parameters (filters, pagination, sorting).
1295
+ * @returns The query result as an array of records.
1296
+ */
1297
+ query(resource: string, params?: Readonly<Record<string, unknown>>): Promise<readonly Record<string, unknown>[]>;
1298
+ /**
1299
+ * Performs a mutation (create, update, delete) on a resource.
1300
+ *
1301
+ * @param resource - The resource to mutate.
1302
+ * @param action - The mutation type (`'create'`, `'update'`, `'delete'`).
1303
+ * @param data - The mutation payload.
1304
+ * @returns The mutated record, or `null` for deletes.
1305
+ */
1306
+ mutate(resource: string, action: 'create' | 'update' | 'delete', data: Readonly<Record<string, unknown>>): Promise<Record<string, unknown> | null>;
1307
+ /**
1308
+ * Subscribes to real-time changes on a resource.
1309
+ *
1310
+ * @param resource - The resource to subscribe to.
1311
+ * @param callback - Called when the resource changes.
1312
+ * @returns An unsubscribe function.
1313
+ */
1314
+ subscribe(resource: string, callback: (data: readonly Record<string, unknown>[]) => void): () => void;
1315
+ }
1316
+ /**
1317
+ * Error handling adapter interface.
1318
+ *
1319
+ * Implementations provide error reporting, retry logic, and PII sanitization.
1320
+ * All methods are async per AD2 — even `shouldRetry` and `sanitize` which
1321
+ * may seem synchronous in simple implementations, but production adapters
1322
+ * may require remote circuit breaker checks or external PII detection
1323
+ * services (Google DLP, AWS Comprehend, Microsoft Presidio).
1324
+ *
1325
+ * @see Bible §3.6
1326
+ * @see Design Choice AD2
1327
+ */
1328
+ interface ErrorAdapter {
1329
+ /**
1330
+ * Reports an error to the external error tracking service.
1331
+ *
1332
+ * @param error - The error to report (may be an `EnterstellarError`).
1333
+ * @param context - Optional contextual metadata for the error report.
1334
+ */
1335
+ report(error: Error, context?: Readonly<Record<string, unknown>>): Promise<void>;
1336
+ /**
1337
+ * Determines whether a failed operation should be retried.
1338
+ *
1339
+ * Async to support production implementations that consult remote
1340
+ * circuit breakers (LaunchDarkly, Unleash) or rate-limit services
1341
+ * before deciding whether to retry.
1342
+ *
1343
+ * @param error - The error that caused the failure.
1344
+ * @param attemptNumber - The current retry attempt (1-based).
1345
+ * @returns `true` if the operation should be retried.
1346
+ */
1347
+ shouldRetry(error: Error, attemptNumber: number): Promise<boolean>;
1348
+ /**
1349
+ * Sanitizes an error before it is logged or displayed.
1350
+ * Strips any PII or sensitive data from the error message and stack.
1351
+ *
1352
+ * Async to support production implementations that call external
1353
+ * PII detection services (Google DLP, AWS Comprehend Medical)
1354
+ * for HIPAA-compliant sanitization.
1355
+ *
1356
+ * @param error - The error to sanitize.
1357
+ * @returns A sanitized copy of the error.
1358
+ */
1359
+ sanitize(error: Error): Promise<Error>;
1360
+ }
1361
+ /**
1362
+ * Analytics adapter interface.
1363
+ * Implementations forward user interaction events to analytics services.
1364
+ *
1365
+ * @see Bible §3.6
1366
+ */
1367
+ interface AnalyticsAdapter {
1368
+ /**
1369
+ * Tracks a named event with optional properties.
1370
+ *
1371
+ * @param event - The event name (e.g., `'zone_rendered'`, `'intent_resolved'`).
1372
+ * @param properties - Optional event properties for segmentation.
1373
+ */
1374
+ track(event: string, properties?: Readonly<Record<string, unknown>>): void;
1375
+ /**
1376
+ * Identifies the current user for analytics attribution.
1377
+ *
1378
+ * @param userId - Unique user identifier.
1379
+ * @param traits - Optional user traits (role, plan, etc.).
1380
+ */
1381
+ identify(userId: string, traits?: Readonly<Record<string, unknown>>): void;
1382
+ }
1383
+
1384
+ /**
1385
+ * @module @enterstellar-ai/types/telemetry
1386
+ * @description ForgeSignal — the mandatory telemetry payload for every compilation.
1387
+ *
1388
+ * ForgeSignals are the atomic unit of the ForgeSignal Corpus (M2 moat).
1389
+ * They contain ZERO PII — only hashed intents, component names, and metrics.
1390
+ * Every render emits a ForgeSignal; this is non-negotiable (L12).
1391
+ *
1392
+ * @see Bible §3.7
1393
+ * @see Design Choices TL1–TL12, T12
1394
+ * @see Principle L12
1395
+ */
1396
+
1397
+ /**
1398
+ * Classification of the intent that produced this signal.
1399
+ * Fixed set — not consumer-extensible. Updated only in `@enterstellar-ai/types` releases.
1400
+ *
1401
+ * @see Design Choice T12
1402
+ */
1403
+ type IntentCategory = 'clinical' | 'admin' | 'navigation' | 'data-display' | 'form' | 'feedback' | 'utility';
1404
+ /**
1405
+ * Forge mode that generated the component (if forged).
1406
+ * `'none'` indicates the component came from the registry (no forge).
1407
+ */
1408
+ type ForgeMode = 'none' | 'local' | 'cloud';
1409
+ /**
1410
+ * Platform that produced this signal.
1411
+ * Auto-set by the renderer package — never consumer-configured (P9).
1412
+ */
1413
+ type SignalPlatform = 'web' | 'native' | 'desktop' | 'cli' | 'unknown';
1414
+ /**
1415
+ * The mandatory telemetry payload emitted after every Enterstellar compilation.
1416
+ *
1417
+ * ForgeSignals are the training data for the Intent Router (M4) and
1418
+ * Forge Model (M5). They power the self-reinforcing data flywheel.
1419
+ *
1420
+ * **PII policy:** Zero PII. The `intentHash` is a SHA-256 of the raw intent —
1421
+ * the raw string never leaves the device.
1422
+ *
1423
+ * @see Bible §3.7
1424
+ * @see Design Choice TL3 — hashing happens in `record()`, not caller.
1425
+ */
1426
+ type ForgeSignal = {
1427
+ /** SHA-256 hash of the raw intent string. No PII. */
1428
+ readonly intentHash: string;
1429
+ /** PascalCase name of the resolved component. */
1430
+ readonly componentName: string;
1431
+ /** Classification of the intent. */
1432
+ readonly intentCategory: IntentCategory;
1433
+ /** Whether compilation passed, failed, or was corrected. */
1434
+ readonly compilationStatus: 'pass' | 'fail' | 'corrected';
1435
+ /** Whether the Forge was used, and which mode. */
1436
+ readonly forgeMode: ForgeMode;
1437
+ /** Whether the Forge was invoked at all. */
1438
+ readonly forgeUsed: boolean;
1439
+ /** Total pipeline latency from intent to rendered output, in milliseconds. */
1440
+ readonly latencyMs: number;
1441
+ /** Number of self-correction attempts before final result. */
1442
+ readonly selfCorrectionAttempts: number;
1443
+ /**
1444
+ * Token usage for self-correction calls, if any.
1445
+ * Tracked for cost observability, not enforced with a hard budget (C7).
1446
+ */
1447
+ readonly correctionTokensUsed: number;
1448
+ /** ISO 8601 timestamp when the signal was recorded. */
1449
+ readonly timestamp: string;
1450
+ /** Semantic version of the Enterstellar SDK that produced this signal. */
1451
+ readonly sdkVersion: string;
1452
+ /** Number of components in the registry at the time of this signal. */
1453
+ readonly registrySize: number;
1454
+ /** Platform that produced this signal. */
1455
+ readonly platform: SignalPlatform;
1456
+ };
1457
+ /**
1458
+ * Zod schema for validating a `ForgeSignal` at runtime.
1459
+ *
1460
+ * @see Design Choice T7
1461
+ */
1462
+ declare const ForgeSignalSchema: z.ZodObject<{
1463
+ intentHash: z.ZodString;
1464
+ componentName: z.ZodString;
1465
+ intentCategory: z.ZodEnum<{
1466
+ clinical: "clinical";
1467
+ admin: "admin";
1468
+ navigation: "navigation";
1469
+ "data-display": "data-display";
1470
+ form: "form";
1471
+ feedback: "feedback";
1472
+ utility: "utility";
1473
+ }>;
1474
+ compilationStatus: z.ZodEnum<{
1475
+ pass: "pass";
1476
+ fail: "fail";
1477
+ corrected: "corrected";
1478
+ }>;
1479
+ forgeMode: z.ZodEnum<{
1480
+ cloud: "cloud";
1481
+ local: "local";
1482
+ none: "none";
1483
+ }>;
1484
+ forgeUsed: z.ZodBoolean;
1485
+ latencyMs: z.ZodNumber;
1486
+ selfCorrectionAttempts: z.ZodNumber;
1487
+ correctionTokensUsed: z.ZodNumber;
1488
+ timestamp: z.ZodString;
1489
+ sdkVersion: z.ZodString;
1490
+ registrySize: z.ZodNumber;
1491
+ platform: z.ZodEnum<{
1492
+ cli: "cli";
1493
+ unknown: "unknown";
1494
+ web: "web";
1495
+ native: "native";
1496
+ desktop: "desktop";
1497
+ }>;
1498
+ }, z.core.$strip>;
1499
+
1500
+ /**
1501
+ * @module @enterstellar-ai/types/state
1502
+ * @description EnterstellarStore — the framework-agnostic persistent state container.
1503
+ *
1504
+ * The EnterstellarStore is the "OS's memory." It holds zone state, trace history,
1505
+ * and session metadata. It is a pure TypeScript interface with zero
1506
+ * framework dependencies (L15).
1507
+ *
1508
+ * @see Bible §3.8
1509
+ * @see Design Choices S1–S15, T1, T5
1510
+ * @see Appendix E P3 (threadId)
1511
+ * @see Appendix D Ruling 3
1512
+ */
1513
+
1514
+ /**
1515
+ * State of a single zone within the store.
1516
+ * Auto-populated when an `Zone` mounts (S15).
1517
+ */
1518
+ type ZoneState = {
1519
+ /** Zone name. */
1520
+ readonly name: string;
1521
+ /** Current lifecycle state. */
1522
+ readonly lifecycleState: 'loading' | 'ready' | 'streaming' | 'error' | 'empty';
1523
+ /** Determinism level at mount time. */
1524
+ readonly determinism: number;
1525
+ /** Last compiled component name, if any. */
1526
+ readonly lastComponent?: string;
1527
+ /** ISO 8601 timestamp of the last update. */
1528
+ readonly lastUpdated: string;
1529
+ };
1530
+ /**
1531
+ * Session metadata within the store.
1532
+ * Ephemeral session data + optional persistent `threadId`.
1533
+ */
1534
+ type SessionState = {
1535
+ /** Ephemeral session ID generated on app mount. Lost on refresh. */
1536
+ readonly id: string;
1537
+ /**
1538
+ * Persistent conversation thread ID that survives across sessions.
1539
+ * Passed via `<Provider threadId="...">`.
1540
+ * When `undefined`, Enterstellar operates in stateless mode (no conversation resumption).
1541
+ *
1542
+ * @see Appendix E P3
1543
+ */
1544
+ readonly threadId?: string;
1545
+ /** ISO 8601 timestamp when the session started. */
1546
+ readonly startedAt: string;
1547
+ };
1548
+ /**
1549
+ * Serializable representation of the full store state.
1550
+ * Produced by `snapshot()`, consumed by `restore()`.
1551
+ */
1552
+ type SerializedState = {
1553
+ /** Semver string for schema versioning (e.g., `"1.0.0"`). */
1554
+ readonly schemaVersion: string;
1555
+ /** Zone state map, keyed by zone name. */
1556
+ readonly zones: Readonly<Record<string, ZoneState>>;
1557
+ /** Trace ID history (most recent first). */
1558
+ readonly traceIds: readonly string[];
1559
+ /** Session metadata. */
1560
+ readonly session: SessionState;
1561
+ /** Extension data from `store.extend()`. Keyed by extension name. */
1562
+ readonly extensions: Readonly<Record<string, unknown>>;
1563
+ };
1564
+ /**
1565
+ * Configuration for a store state migration.
1566
+ * Migrations chain sequentially from older versions to current.
1567
+ *
1568
+ * @see Design Choice S5 (amended v2)
1569
+ */
1570
+ type MigrationConfig = {
1571
+ /** Source schema version (semver). */
1572
+ readonly from: string;
1573
+ /** Target schema version (semver). */
1574
+ readonly to: string;
1575
+ /** Migration function that transforms the state. */
1576
+ readonly migrate: (state: SerializedState) => SerializedState;
1577
+ };
1578
+ /**
1579
+ * Persistence strategy for the store.
1580
+ * Determines where state is stored between sessions.
1581
+ *
1582
+ * @see Design Choices S5–S7
1583
+ */
1584
+ type PersistenceStrategy = 'memory' | 'local-storage' | 'indexed-db' | 'custom';
1585
+ /**
1586
+ * Configuration for cross-device state sync.
1587
+ *
1588
+ * @see Design Choices S9–S12
1589
+ */
1590
+ type SyncConfig = {
1591
+ /** Whether sync is enabled. */
1592
+ readonly enabled: boolean;
1593
+ /** Endpoint URL for state synchronization. */
1594
+ readonly endpoint: string;
1595
+ /** Sync debounce interval in milliseconds. Default: 100ms. */
1596
+ readonly debounceMs: number;
1597
+ };
1598
+ /**
1599
+ * Framework-agnostic persistent state container — the OS's memory.
1600
+ *
1601
+ * This is an **interface** (not a type) because it has methods.
1602
+ * Implementations are provided by `@enterstellar-ai/state` (`createEnterstellarStore()`).
1603
+ * React binding is provided by `@enterstellar-ai/react` (`useEnterstellarStore()` hook via
1604
+ * `useSyncExternalStore`).
1605
+ *
1606
+ * @see Bible §3.8
1607
+ * @see Design Choice T1 — interfaces for objects with methods.
1608
+ * @see Design Choice S1 — single global store per app.
1609
+ */
1610
+ interface EnterstellarStore {
1611
+ /**
1612
+ * Gets a value from the store by key.
1613
+ * In development mode, validates against the registered Zod schema.
1614
+ *
1615
+ * @param key - The store key to read.
1616
+ * @returns The stored value, or `undefined` if not found.
1617
+ *
1618
+ * @see Design Choice S3
1619
+ */
1620
+ get<T = unknown>(key: string): T | undefined;
1621
+ /**
1622
+ * Sets a value in the store.
1623
+ * Updates memory immediately; persistence is write-behind (debounced, S8).
1624
+ * Fires subscriptions only on actual value change (shallow equality, S4).
1625
+ *
1626
+ * @param key - The store key to write.
1627
+ * @param value - The value to store.
1628
+ */
1629
+ set(key: string, value: unknown): void;
1630
+ /**
1631
+ * Subscribes to store changes.
1632
+ * Callback fires only on actual value change (shallow equality check, S4).
1633
+ *
1634
+ * @param callback - Called when any store value changes.
1635
+ * @returns An unsubscribe function.
1636
+ */
1637
+ subscribe(callback: () => void): () => void;
1638
+ /**
1639
+ * Extends the store with a named, schema-validated section.
1640
+ * Prevents untyped global state.
1641
+ *
1642
+ * The `schema` parameter is intentionally `z.ZodType` (unparameterized)
1643
+ * to allow consumers to register any valid Zod schema shape.
1644
+ *
1645
+ * @param name - Extension name (e.g., `'preferences'`).
1646
+ * @param schema - Zod schema for the extension's value shape.
1647
+ *
1648
+ * @see Design Choice S2
1649
+ */
1650
+ extend(name: string, schema: z.ZodType): void;
1651
+ /**
1652
+ * Checks whether a named extension has been registered via `extend()`.
1653
+ *
1654
+ * Use this to guard idempotent extension registration in components that
1655
+ * may mount multiple times (e.g., `Provider` re-renders). This method
1656
+ * returns `true` only for extension keys — fixed schema keys (`zones`,
1657
+ * `traceIds`, `session`) are NOT considered extensions and always return
1658
+ * `false`.
1659
+ *
1660
+ * @param name - Extension name to check (e.g., `'traces'`, `'preferences'`).
1661
+ * @returns `true` if `extend(name, schema)` was previously called for this name.
1662
+ *
1663
+ * @example
1664
+ * ```ts
1665
+ * if (!store.hasExtension('traces')) {
1666
+ * store.extend('traces', z.array(ZoneTraceSchema));
1667
+ * }
1668
+ * ```
1669
+ *
1670
+ * @see Design Choice S2 — typed extension point.
1671
+ */
1672
+ hasExtension(name: string): boolean;
1673
+ /**
1674
+ * Serializes the entire store state for cross-device transfer.
1675
+ * Zone configs only — NOT render trees (S9, max 1MB).
1676
+ *
1677
+ * @returns A `SerializedState` snapshot with `schemaVersion`.
1678
+ * @throws {EnterstellarError} If state exceeds 1MB (ENS-4006).
1679
+ */
1680
+ snapshot(): SerializedState;
1681
+ /**
1682
+ * Restores state from a snapshot. Full overwrite, not merge (S10).
1683
+ * Applies chained migrations if snapshot version is older.
1684
+ * Hard-rejects major version forward jumps (ENS-4007).
1685
+ *
1686
+ * @param state - The serialized state to restore.
1687
+ * @throws {EnterstellarError} If major version is ahead (ENS-4007).
1688
+ *
1689
+ * @see Design Choice S5 (amended v2)
1690
+ */
1691
+ restore(state: SerializedState): void;
1692
+ /**
1693
+ * Registers a migration for handling older state snapshots.
1694
+ *
1695
+ * @param config - Migration config with `from`, `to`, and `migrate` function.
1696
+ */
1697
+ registerMigration(config: MigrationConfig): void;
1698
+ /**
1699
+ * Returns the full store snapshot for `useSyncExternalStore` compatibility.
1700
+ * React's `useSyncExternalStore` requires a `getSnapshot` function.
1701
+ */
1702
+ getSnapshot(): SerializedState;
1703
+ /**
1704
+ * Destroys the store, clearing all state and subscriptions.
1705
+ * Called when `Provider` unmounts.
1706
+ */
1707
+ destroy(): void;
1708
+ }
1709
+ /**
1710
+ * Zod schema for validating `ZoneState` at runtime.
1711
+ *
1712
+ * @see Design Choice T7
1713
+ */
1714
+ declare const ZoneStateSchema: z.ZodObject<{
1715
+ name: z.ZodString;
1716
+ lifecycleState: z.ZodEnum<{
1717
+ error: "error";
1718
+ loading: "loading";
1719
+ empty: "empty";
1720
+ ready: "ready";
1721
+ streaming: "streaming";
1722
+ }>;
1723
+ determinism: z.ZodNumber;
1724
+ lastComponent: z.ZodOptional<z.ZodString>;
1725
+ lastUpdated: z.ZodString;
1726
+ }, z.core.$strip>;
1727
+ /**
1728
+ * Zod schema for validating `SessionState` at runtime.
1729
+ *
1730
+ * @see Design Choice T7
1731
+ */
1732
+ declare const SessionStateSchema: z.ZodObject<{
1733
+ id: z.ZodString;
1734
+ threadId: z.ZodOptional<z.ZodString>;
1735
+ startedAt: z.ZodString;
1736
+ }, z.core.$strip>;
1737
+ /**
1738
+ * Zod schema for validating `SerializedState` at runtime.
1739
+ * Used by `restore()` to validate snapshots before applying.
1740
+ *
1741
+ * @see Design Choice T7, S5
1742
+ */
1743
+ declare const SerializedStateSchema: z.ZodObject<{
1744
+ schemaVersion: z.ZodString;
1745
+ zones: z.ZodRecord<z.ZodString, z.ZodObject<{
1746
+ name: z.ZodString;
1747
+ lifecycleState: z.ZodEnum<{
1748
+ error: "error";
1749
+ loading: "loading";
1750
+ empty: "empty";
1751
+ ready: "ready";
1752
+ streaming: "streaming";
1753
+ }>;
1754
+ determinism: z.ZodNumber;
1755
+ lastComponent: z.ZodOptional<z.ZodString>;
1756
+ lastUpdated: z.ZodString;
1757
+ }, z.core.$strip>>;
1758
+ traceIds: z.ZodArray<z.ZodString>;
1759
+ session: z.ZodObject<{
1760
+ id: z.ZodString;
1761
+ threadId: z.ZodOptional<z.ZodString>;
1762
+ startedAt: z.ZodString;
1763
+ }, z.core.$strip>;
1764
+ extensions: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1765
+ }, z.core.$strip>;
1766
+
1767
+ /**
1768
+ * @module @enterstellar-ai/types/connection
1769
+ * @description UserSignal and EnterstellarAgentConnection — the contract between
1770
+ * the UI layer and AI agents.
1771
+ *
1772
+ * `UserSignal` is the fire-and-forget message from a user interaction
1773
+ * (click, submit, input) back to the agent. `EnterstellarAgentConnection` is the
1774
+ * transport-agnostic interface for bidirectional agent communication.
1775
+ *
1776
+ * @see Bible §3.9, §3.10
1777
+ * @see Appendix E P1 (UserSignal), P7 (event whitelist), P11 (connection factory)
1778
+ */
1779
+
1780
+ /**
1781
+ * Type of user interaction signal dispatched to the agent.
1782
+ *
1783
+ * @see Appendix E P1
1784
+ */
1785
+ type UserSignalType = 'click' | 'submit' | 'input' | 'custom';
1786
+ /**
1787
+ * Agent-to-UI event types that trigger zone re-renders.
1788
+ * Internal agent events (graph node transitions, reducer internals)
1789
+ * are NOT surfaced.
1790
+ *
1791
+ * @see Appendix E P7
1792
+ */
1793
+ type AgentEventType = 'intent' | 'lifecycle' | 'data' | 'message' | 'reconnect';
1794
+ /**
1795
+ * A user interaction signal dispatched from an Zone to the agent.
1796
+ *
1797
+ * Dispatched via `EnterstellarAgentConnection.dispatch()`. Fire-and-forget with
1798
+ * enqueue guarantee — the promise resolves when the signal is queued,
1799
+ * NOT when the agent processes it.
1800
+ *
1801
+ * @see Bible §3.9
1802
+ * @see Appendix E P1
1803
+ */
1804
+ type UserSignal = {
1805
+ /** Type of user interaction. */
1806
+ readonly type: UserSignalType;
1807
+ /** Name of the zone that originated this signal. */
1808
+ readonly zone: string;
1809
+ /** Name of the component that originated this signal. */
1810
+ readonly component: string;
1811
+ /** Arbitrary payload from the interaction (form data, click target, etc.). */
1812
+ readonly payload: Readonly<Record<string, unknown>>;
1813
+ /** ISO 8601 timestamp of when the interaction occurred. */
1814
+ readonly timestamp: string;
1815
+ /**
1816
+ * Optional correlation ID for tying this signal to an ongoing interaction chain.
1817
+ *
1818
+ * @see Appendix E P2
1819
+ */
1820
+ readonly correlationId?: string;
1821
+ };
1822
+ /**
1823
+ * Transport-agnostic interface for bidirectional agent communication.
1824
+ *
1825
+ * Implementations are provided by `@enterstellar-ai/connection` (`createAgentConnection()`)
1826
+ * or custom consumer implementations. The connection is created and owned by
1827
+ * the consumer, not by Enterstellar (RE3).
1828
+ *
1829
+ * This is an **interface** (not a type) because it has methods.
1830
+ *
1831
+ * @see Bible §3.10
1832
+ * @see Design Choices RE3, P1, P5, P7, P11, P12
1833
+ * @see Design Choice T1 — interfaces for objects with methods.
1834
+ */
1835
+ interface EnterstellarAgentConnection {
1836
+ /**
1837
+ * Dispatches a user interaction signal to the agent.
1838
+ * Fire-and-forget: resolves when enqueued in the outbound queue,
1839
+ * NOT when the agent processes it.
1840
+ *
1841
+ * @param signal - The user signal to dispatch.
1842
+ * @param options - Optional dispatch options.
1843
+ * @returns Resolves when the signal is enqueued.
1844
+ *
1845
+ * @see Appendix E P1, P6 (debounce)
1846
+ */
1847
+ dispatch(signal: UserSignal, options?: {
1848
+ readonly immediate?: boolean;
1849
+ }): Promise<void>;
1850
+ /**
1851
+ * Subscribes to agent-to-UI events.
1852
+ * Only whitelisted event types are surfaced (P7).
1853
+ *
1854
+ * @param event - The event type to listen for.
1855
+ * @param callback - Called when the event fires.
1856
+ * @returns An unsubscribe function.
1857
+ *
1858
+ * @see Appendix E P7
1859
+ */
1860
+ on(event: AgentEventType, callback: (data: unknown) => void): () => void;
1861
+ /**
1862
+ * Subscribes to ALL raw agent events, including internal ones.
1863
+ * Escape hatch for custom DevTools panels and advanced use cases.
1864
+ *
1865
+ * @param callback - Called for every raw event.
1866
+ * @returns An unsubscribe function.
1867
+ *
1868
+ * @see Appendix E P7
1869
+ */
1870
+ onRawEvent(callback: (event: unknown) => void): () => void;
1871
+ /** Whether the connection is currently active. */
1872
+ readonly connected: boolean;
1873
+ /**
1874
+ * Disconnects the agent connection.
1875
+ * Queued signals are flushed before disconnecting.
1876
+ */
1877
+ disconnect(): Promise<void>;
1878
+ }
1879
+ /**
1880
+ * Zod schema for validating a `UserSignal` at runtime.
1881
+ *
1882
+ * @see Design Choice T7
1883
+ */
1884
+ declare const UserSignalSchema: z.ZodObject<{
1885
+ type: z.ZodEnum<{
1886
+ custom: "custom";
1887
+ input: "input";
1888
+ click: "click";
1889
+ submit: "submit";
1890
+ }>;
1891
+ zone: z.ZodString;
1892
+ component: z.ZodString;
1893
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1894
+ timestamp: z.ZodString;
1895
+ correlationId: z.ZodOptional<z.ZodString>;
1896
+ }, z.core.$strip>;
1897
+
1898
+ /**
1899
+ * @module @enterstellar-ai/types/spatial
1900
+ * @description SpatialContext — DOM-awareness data for AI-informed layout decisions.
1901
+ *
1902
+ * The `SpatialContext` is the return type of the `useSpatialContext()` hook
1903
+ * in `@enterstellar-ai/react`. It provides zone dimensions, visibility state, and an
1904
+ * optional `captureContext()` method for explicit context capture.
1905
+ *
1906
+ * **Two modes:**
1907
+ * - Passive (default): returns `{ zone, width, height, isVisible, focusedElement? }`
1908
+ * from `ResizeObserver` / `IntersectionObserver`. Never sent to agent automatically.
1909
+ * - Active: consumer calls `captureContext()` explicitly (e.g., on Cmd+K, "Ask AI" click).
1910
+ *
1911
+ * @see Appendix E P13
1912
+ * @see Design Choice RE12
1913
+ */
1914
+ /**
1915
+ * DOM-awareness data returned by `useSpatialContext()`.
1916
+ *
1917
+ * Provides zone dimensions and visibility state for AI-informed layout
1918
+ * decisions. No DOM tree walking, no ancestor traversal — naturally
1919
+ * bounded by structure.
1920
+ *
1921
+ * @see Design Choice RE12
1922
+ * @see Appendix E P13
1923
+ */
1924
+ type SpatialContext = {
1925
+ /** Zone name this context belongs to. */
1926
+ readonly zone: string;
1927
+ /** Current width of the zone element in pixels. Updated via `ResizeObserver`. */
1928
+ readonly width: number;
1929
+ /** Current height of the zone element in pixels. Updated via `ResizeObserver`. */
1930
+ readonly height: number;
1931
+ /** Whether the zone is currently visible in the viewport. Updated via `IntersectionObserver`. */
1932
+ readonly isVisible: boolean;
1933
+ /** ID or selector of the currently focused element within the zone, if any. */
1934
+ readonly focusedElement?: string;
1935
+ /**
1936
+ * Explicitly captures the current spatial context for sending to the agent.
1937
+ * Consumer decides when to trigger (e.g., Cmd+K, "Ask AI" button).
1938
+ * Returns the captured context snapshot.
1939
+ *
1940
+ * @returns A snapshot of the current spatial context data.
1941
+ */
1942
+ readonly captureContext: () => SpatialContextSnapshot;
1943
+ };
1944
+ /**
1945
+ * A frozen snapshot of spatial context at a point in time.
1946
+ * Produced by `SpatialContext.captureContext()`.
1947
+ */
1948
+ type SpatialContextSnapshot = {
1949
+ /** Zone name. */
1950
+ readonly zone: string;
1951
+ /** Zone width at capture time. */
1952
+ readonly width: number;
1953
+ /** Zone height at capture time. */
1954
+ readonly height: number;
1955
+ /** Visibility at capture time. */
1956
+ readonly isVisible: boolean;
1957
+ /** Focused element at capture time. */
1958
+ readonly focusedElement?: string;
1959
+ /** ISO 8601 timestamp of when the capture occurred. */
1960
+ readonly capturedAt: string;
1961
+ };
1962
+
1963
+ /**
1964
+ * @module @enterstellar-ai/types/manifest
1965
+ * @description Compact Manifest types — the token-efficient component
1966
+ * descriptions sent to the LLM's system prompt.
1967
+ *
1968
+ * The compact manifest reduces context window consumption from ~50K tokens
1969
+ * to ~200 by including only the essential component metadata for selection.
1970
+ *
1971
+ * @see Bible §4.1 — Registry manifest generation
1972
+ * @see Design Choices R8, R9, R10
1973
+ */
1974
+ /**
1975
+ * A single entry in the compact manifest — the minimal representation of a
1976
+ * component sent to the LLM for component selection.
1977
+ *
1978
+ * Format per Design Choice R8: custom compact JSON with name, description,
1979
+ * prop summaries, and category. NOT full JSON Schema (too verbose).
1980
+ *
1981
+ * @see Design Choice R8 — compact JSON format
1982
+ * @see Design Choice R9 — descriptions max 120 chars (enforced by `defineComponent`)
1983
+ * @see Design Choice SI8 — similarity scores included when available
1984
+ */
1985
+ type CompactManifestEntry = {
1986
+ /** PascalCase component name. Max 30 characters. */
1987
+ readonly name: string;
1988
+ /** Concise component description. Max 120 characters. */
1989
+ readonly description: string;
1990
+ /** Component category for classification. */
1991
+ readonly category: string;
1992
+ /** Summary of key props: `{ "patientId": "string (UUID)", "riskLevel": "enum: low|medium|high|critical" }`. */
1993
+ readonly props: Readonly<Record<string, string>>;
1994
+ /**
1995
+ * Display mode, if specified in the contract.
1996
+ *
1997
+ * @see Appendix E P8
1998
+ */
1999
+ readonly mode?: string;
2000
+ /**
2001
+ * Interaction type, if specified in the contract.
2002
+ *
2003
+ * @see Appendix E P8
2004
+ */
2005
+ readonly interaction?: string;
2006
+ /**
2007
+ * Semantic similarity score (0.0–1.0).
2008
+ * Only present when the manifest entry comes from a semantic search result.
2009
+ * Helps the LLM prioritize high-confidence matches.
2010
+ *
2011
+ * @see Design Choice SI8
2012
+ */
2013
+ readonly score?: number;
2014
+ };
2015
+
2016
+ /**
2017
+ * @module @enterstellar-ai/types/semantic-index
2018
+ * @description Semantic Index types — search results and related data shapes
2019
+ * for the embedding-based component retrieval engine.
2020
+ *
2021
+ * The Semantic Index reduces the LLM context window from ~50K tokens to ~200
2022
+ * by selecting only the most relevant components for a given intent.
2023
+ *
2024
+ * **Naming:** Types for data shapes (`SemanticSearchResult`), not interfaces —
2025
+ * per Design Choice T1 (interfaces for objects with methods).
2026
+ *
2027
+ * **L15 compliance:** Zero framework imports. Pure data types only.
2028
+ *
2029
+ * @see Implementation Bible §4.7
2030
+ * @see Design Choices SI1–SI12
2031
+ */
2032
+
2033
+ /**
2034
+ * A single result from a semantic index search.
2035
+ *
2036
+ * Returned by `SemanticIndex.search()` — each result pairs a component
2037
+ * with its cosine similarity score to the queried intent.
2038
+ *
2039
+ * @see Design Choice SI8 — similarity scores included in manifest entries.
2040
+ * @see Design Choice SI5 — default `topK: 5`, max 20.
2041
+ * @see Design Choice SI6 — below `noMatchThreshold` (0.4) → Forge activates.
2042
+ */
2043
+ type SemanticSearchResult = {
2044
+ /** PascalCase name of the matched component. */
2045
+ readonly componentName: string;
2046
+ /**
2047
+ * Cosine similarity score between the intent embedding and
2048
+ * the component's embedding vector. Range: 0.0–1.0.
2049
+ *
2050
+ * Scores above `noMatchThreshold` (default 0.4) indicate viable matches.
2051
+ * Scores below trigger Forge activation (caller's responsibility).
2052
+ */
2053
+ readonly similarity: number;
2054
+ /**
2055
+ * The full `ComponentContract` of the matched component.
2056
+ * Provides immediate access to props schema, tokens, and metadata
2057
+ * without a second registry lookup.
2058
+ */
2059
+ readonly contract: ComponentContract;
2060
+ };
2061
+ /**
2062
+ * Zod schema for `SemanticSearchResult`.
2063
+ *
2064
+ * Enables runtime validation of search results — useful for
2065
+ * cross-boundary data validation (e.g., results received from
2066
+ * a cloud semantic index endpoint).
2067
+ *
2068
+ * @see Design Choice T7 — export both TS type and Zod schema.
2069
+ */
2070
+ declare const SemanticSearchResultSchema: z.ZodObject<{
2071
+ componentName: z.ZodString;
2072
+ similarity: z.ZodNumber;
2073
+ contract: z.ZodObject<{
2074
+ name: z.ZodString;
2075
+ id: z.ZodString;
2076
+ description: z.ZodString;
2077
+ category: z.ZodString;
2078
+ tags: z.ZodArray<z.ZodString>;
2079
+ props: z.ZodUnknown;
2080
+ tokens: z.ZodRecord<z.ZodString, z.ZodString>;
2081
+ accessibility: z.ZodObject<{
2082
+ role: z.ZodString;
2083
+ ariaLabel: z.ZodString;
2084
+ announceOnUpdate: z.ZodBoolean;
2085
+ }, z.core.$strip>;
2086
+ states: z.ZodObject<{
2087
+ loading: z.ZodString;
2088
+ error: z.ZodString;
2089
+ empty: z.ZodString;
2090
+ ready: z.ZodString;
2091
+ }, z.core.$strip>;
2092
+ examples: z.ZodArray<z.ZodObject<{
2093
+ intent: z.ZodString;
2094
+ props: z.ZodRecord<z.ZodString, z.ZodUnknown>;
2095
+ }, z.core.$strip>>;
2096
+ dataSource: z.ZodOptional<z.ZodObject<{
2097
+ adapter: z.ZodString;
2098
+ resource: z.ZodString;
2099
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
2100
+ }, z.core.$strip>>;
2101
+ auth: z.ZodOptional<z.ZodObject<{
2102
+ required: z.ZodBoolean;
2103
+ roles: z.ZodArray<z.ZodString>;
2104
+ }, z.core.$strip>>;
2105
+ origin: z.ZodOptional<z.ZodObject<{
2106
+ registryUrl: z.ZodURL;
2107
+ publisher: z.ZodString;
2108
+ verifiedAt: z.ZodOptional<z.ZodString>;
2109
+ }, z.core.$strip>>;
2110
+ _meta: z.ZodObject<{
2111
+ forged: z.ZodBoolean;
2112
+ version: z.ZodString;
2113
+ createdAt: z.ZodString;
2114
+ }, z.core.$strip>;
2115
+ }, z.core.$strip>;
2116
+ }, z.core.$strip>;
2117
+
2118
+ /**
2119
+ * @module @enterstellar-ai/types/forge
2120
+ * @description Forge types — runtime component generation and Cold Path pipeline.
2121
+ *
2122
+ * The Forge generates temporary ComponentContracts when the registry has
2123
+ * no match. LocalForge uses templates (free), CloudForge uses LLM (metered).
2124
+ *
2125
+ * @see Bible §4.10 — Forge
2126
+ * @see Design Choices F1–F14
2127
+ * @see Appendix D Ruling 7
2128
+ */
2129
+
2130
+ /**
2131
+ * The output of a Forge invocation.
2132
+ * Contains the generated contract (if successful), compilation status,
2133
+ * and which forge mode was used.
2134
+ *
2135
+ * @see Bible §4.10
2136
+ * @see Design Choice F8 (auto-routing)
2137
+ */
2138
+ type ForgeResult = {
2139
+ /** Whether the forge successfully generated a valid contract. */
2140
+ readonly success: boolean;
2141
+ /**
2142
+ * The generated ComponentContract, or `null` on failure.
2143
+ * Marked with `_meta.forged = true`.
2144
+ * Named with prefix `__forged_{name}_{8-char-hash}` (F13).
2145
+ */
2146
+ readonly contract: ComponentContract | null;
2147
+ /** Compilation result — forged contracts MUST pass the compiler (L3, L13). */
2148
+ readonly compilationResult: CompilationResult | null;
2149
+ /** Whether the fallback component was used instead. */
2150
+ readonly fallbackUsed: boolean;
2151
+ /**
2152
+ * Which forge mode generated this contract.
2153
+ *
2154
+ * @see Appendix D Ruling 7
2155
+ */
2156
+ readonly forgeMode: 'local' | 'cloud';
2157
+ };
2158
+ /**
2159
+ * Trace record for Cold Path intent clustering.
2160
+ * Every forge invocation is logged for clustering analysis.
2161
+ *
2162
+ * @see Bible §4.10 — Cold Path Rules
2163
+ */
2164
+ type ForgeTraceRecord = {
2165
+ /** Slugified intent name. */
2166
+ readonly intentSlug: string;
2167
+ /** Raw intent string hash (SHA-256). */
2168
+ readonly intentHash: string;
2169
+ /** Which forge mode was used. */
2170
+ readonly forgeMode: 'local' | 'cloud';
2171
+ /** Whether the forge succeeded. */
2172
+ readonly success: boolean;
2173
+ /** ISO 8601 timestamp. */
2174
+ readonly timestamp: string;
2175
+ /** Optional context provided during forge invocation. */
2176
+ readonly context?: Readonly<Record<string, unknown>>;
2177
+ };
2178
+ /**
2179
+ * Configuration for the Forge's Cold Path pipeline.
2180
+ *
2181
+ * @see Design Choices F10–F12
2182
+ */
2183
+ type ColdPathConfig = {
2184
+ /** Whether the Cold Path is enabled. */
2185
+ readonly enabled: boolean;
2186
+ /** Minimum occurrences of a similar intent before clustering. Default: 5 (F11). */
2187
+ readonly clusterThreshold: number;
2188
+ /** Whether to auto-queue clustered contracts for HITL review. */
2189
+ readonly autoPromote: boolean;
2190
+ };
2191
+ /**
2192
+ * Zod schema for validating a `ForgeResult` at runtime.
2193
+ *
2194
+ * @see Design Choice T7
2195
+ */
2196
+ declare const ForgeResultSchema: z.ZodObject<{
2197
+ success: z.ZodBoolean;
2198
+ contract: z.ZodNullable<z.ZodUnknown>;
2199
+ compilationResult: z.ZodNullable<z.ZodUnknown>;
2200
+ fallbackUsed: z.ZodBoolean;
2201
+ forgeMode: z.ZodEnum<{
2202
+ cloud: "cloud";
2203
+ local: "local";
2204
+ }>;
2205
+ }, z.core.$strip>;
2206
+ /**
2207
+ * Zod schema for validating a `ForgeTraceRecord` at runtime.
2208
+ */
2209
+ declare const ForgeTraceRecordSchema: z.ZodObject<{
2210
+ intentSlug: z.ZodString;
2211
+ intentHash: z.ZodString;
2212
+ forgeMode: z.ZodEnum<{
2213
+ cloud: "cloud";
2214
+ local: "local";
2215
+ }>;
2216
+ success: z.ZodBoolean;
2217
+ timestamp: z.ZodString;
2218
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
2219
+ }, z.core.$strip>;
2220
+
2221
+ /**
2222
+ * @module @enterstellar-ai/types/guards
2223
+ * @description Type guard functions for runtime type narrowing.
2224
+ *
2225
+ * Type guards are lightweight checks (one `typeof` + field existence)
2226
+ * for branded types and discriminated unions. Full Zod-based validation
2227
+ * remains in consumer modules (e.g., `@enterstellar-ai/registry`).
2228
+ *
2229
+ * @see Design Choice T17
2230
+ */
2231
+
2232
+ /**
2233
+ * Checks whether a value is a valid `ComponentId`.
2234
+ * Validates that the value is a non-empty string.
2235
+ *
2236
+ * @param value - The value to check.
2237
+ * @returns `true` if the value is a valid `ComponentId`.
2238
+ */
2239
+ declare function isComponentId(value: unknown): value is ComponentId;
2240
+ /**
2241
+ * Checks whether a value is a valid `ZoneId`.
2242
+ * Validates that the value is a non-empty string.
2243
+ *
2244
+ * @param value - The value to check.
2245
+ * @returns `true` if the value is a valid `ZoneId`.
2246
+ */
2247
+ declare function isZoneId(value: unknown): value is ZoneId;
2248
+ /**
2249
+ * Checks whether a value is a valid `TraceId`.
2250
+ * Validates that the value is a non-empty string.
2251
+ *
2252
+ * @param value - The value to check.
2253
+ * @returns `true` if the value is a valid `TraceId`.
2254
+ */
2255
+ declare function isTraceId(value: unknown): value is TraceId;
2256
+ /**
2257
+ * Checks whether a value is a valid `ForgeSignal` shape.
2258
+ * Lightweight structural check — NOT full Zod validation.
2259
+ *
2260
+ * @param value - The value to check.
2261
+ * @returns `true` if the value has the shape of a `ForgeSignal`.
2262
+ */
2263
+ declare function isForgeSignal(value: unknown): value is ForgeSignal;
2264
+ /**
2265
+ * Checks whether a value is a valid `CompilationResult` shape.
2266
+ * Lightweight structural check — NOT full Zod validation.
2267
+ *
2268
+ * @param value - The value to check.
2269
+ * @returns `true` if the value has the shape of a `CompilationResult`.
2270
+ */
2271
+ declare function isCompilationResult(value: unknown): value is CompilationResult;
2272
+ /**
2273
+ * Checks whether a value is a valid `ComponentIntent` shape.
2274
+ * Lightweight structural check — NOT full Zod validation.
2275
+ *
2276
+ * @param value - The value to check.
2277
+ * @returns `true` if the value has the shape of a `ComponentIntent`.
2278
+ */
2279
+ declare function isComponentIntent(value: unknown): value is ComponentIntent;
2280
+ /**
2281
+ * Checks whether a value is a valid `AgentTrace` shape.
2282
+ * Lightweight structural check — NOT full Zod validation.
2283
+ *
2284
+ * @param value - The value to check.
2285
+ * @returns `true` if the value has the shape of an `AgentTrace`.
2286
+ */
2287
+ declare function isAgentTrace(value: unknown): value is AgentTrace;
2288
+ /**
2289
+ * Checks whether a value is a valid `UserSignal` shape.
2290
+ * Lightweight structural check — NOT full Zod validation.
2291
+ *
2292
+ * @param value - The value to check.
2293
+ * @returns `true` if the value has the shape of a `UserSignal`.
2294
+ */
2295
+ declare function isUserSignal(value: unknown): value is UserSignal;
2296
+
2297
+ export { type AgentEventType, type AgentTrace, AgentTraceSchema, type AnalyticsAdapter, type AuthAdapter, type ColdPathConfig, type CompactManifestEntry, type CompilationError, CompilationErrorSchema, type CompilationFix, type CompilationProvenance, type CompilationResult, CompilationResultSchema, type CompilationStatus, type ComponentAccessibility, type ComponentAuth, type ComponentCategory, type ComponentContract, ComponentContractSchema, type ComponentDataSource, type ComponentExample, type ComponentId, type ComponentIntent, ComponentIntentSchema, type ComponentStates, type ContractMeta, type ContractOrigin, type DataAdapter, type DesignTokenSet, DesignTokenSetSchema, ENTERSTELLAR_TYPES_VERSION, type EnterstellarAgentConnection, EnterstellarError, type EnterstellarErrorCode, type EnterstellarErrorModule, type EnterstellarStore, type ErrorAdapter, type ForgeMode, type ForgeResult, ForgeResultSchema, type ForgeSignal, ForgeSignalSchema, type ForgeTraceRecord, ForgeTraceRecordSchema, type IntentCategory, type IntentInteraction, type IntentLayout, type IntentProtocol, type IntentSource, type MigrationConfig, type PersistenceStrategy, type SemanticSearchResult, SemanticSearchResultSchema, type SerializedState, SerializedStateSchema, type SessionState, SessionStateSchema, type SignalPlatform, type SpatialContext, type SpatialContextSnapshot, type SyncConfig, type TokenResolver, type TokenResolverContext, type TraceCompilation, type TraceConsent, type TraceDeterminism, type TraceId, type TraceIntent, type TraceMetrics, type TraceResolution, type UserSignal, UserSignalSchema, type UserSignalType, type ZoneCacheConfig, type ZoneConfig, ZoneConfigSchema, type ZoneId, type ZoneState, ZoneStateSchema, type ZoneTrace, ZoneTraceSchema, createComponentId, createTraceId, createZoneId, isAgentTrace, isCompilationResult, isComponentId, isComponentIntent, isForgeSignal, isTraceId, isUserSignal, isZoneId };