@almadar/core 10.41.0 → 10.43.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.
@@ -1,5 +1,69 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ /**
4
+ * JSON primitives — the universal "data crossed a boundary" type.
5
+ *
6
+ * Every value that arrives over the wire from an LLM (tool-call args),
7
+ * from disk (workspace files), or from an HTTP body before
8
+ * domain-specific validation is a `JsonValue`. Narrow with a typed
9
+ * predicate (`is`-guard) at the boundary; don't widen back to `unknown`.
10
+ *
11
+ * `JsonObject` and `ToolArgs` are aliases for the common
12
+ * `Record<string, JsonValue>` shape. `ToolArgs` is the name the
13
+ * agent surface uses for LLM-emitted tool-call arguments; `JsonObject`
14
+ * is the general-purpose alias. They are the same type — the alias
15
+ * exists so call sites read at the right semantic level.
16
+ *
17
+ * Why not `Record<string, unknown>`? Two reasons. (1) `unknown` widens
18
+ * back to anything, which defeats the purpose of typing the boundary.
19
+ * (2) The `@almadar/eslint-plugin/no-record-string-unknown` rule blocks
20
+ * the wider form — `JsonValue`-based records are the typed answer.
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+
25
+ /**
26
+ * Recursive JSON value union — every shape JSON can carry.
27
+ */
28
+ type JsonValue = string | number | boolean | null | JsonValue[] | {
29
+ [key: string]: JsonValue;
30
+ };
31
+ /**
32
+ * JSON object — keyed string→JsonValue. The wire form of arbitrary
33
+ * structured data. Replaces `Record<string, unknown>` at typed
34
+ * boundaries (LLM emits, file reads, HTTP bodies).
35
+ */
36
+ type JsonObject = {
37
+ [key: string]: JsonValue;
38
+ };
39
+ /**
40
+ * LLM tool-call arguments — same shape as `JsonObject`, named for the
41
+ * agent-surface call site. Each tool's `execute(args: ToolArgs)`
42
+ * receives this and narrows via an `is`-guard predicate before any
43
+ * field access.
44
+ */
45
+ type ToolArgs = JsonObject;
46
+ /**
47
+ * Universal type-guard input — every runtime value shape a predicate can
48
+ * be handed, enumerated instead of `unknown` (the repo bans `unknown`
49
+ * even at guard boundaries). Primitives cover every `typeof` result;
50
+ * `object` covers arrays, records, class instances, and functions.
51
+ */
52
+ type RuntimeValue = string | number | bigint | boolean | symbol | Date | null | undefined | object;
53
+ /**
54
+ * Type guard: is the given value a JSON primitive (non-array,
55
+ * non-object)? Used by walkers that decide whether to recurse.
56
+ */
57
+ declare function isJsonPrimitive(value: JsonValue): value is string | number | boolean | null;
58
+ /**
59
+ * Type guard: is the given value a JSON object (non-array, non-null)?
60
+ */
61
+ declare function isJsonObject(value: JsonValue): value is JsonObject;
62
+ /**
63
+ * Type guard: is the given value a JSON array?
64
+ */
65
+ declare function isJsonArray(value: JsonValue): value is JsonValue[];
66
+
3
67
  /**
4
68
  * S-Expression Types
5
69
  *
@@ -25,7 +89,11 @@ import { z } from 'zod';
25
89
  * - A binding reference (string starting with @)
26
90
  * - A call expression (array with operator as first element)
27
91
  */
28
- type SExprAtom = string | number | boolean | null | Record<string, unknown>;
92
+ /** Object literal branch of an S-expression atom (payload data, props, etc.). */
93
+ interface SExprObject {
94
+ [key: string]: SExpr;
95
+ }
96
+ type SExprAtom = string | number | boolean | null | SExprObject;
29
97
  type SExpr = SExprAtom | SExpr[];
30
98
  /**
31
99
  * Expression type - S-expressions only.
@@ -35,6 +103,13 @@ type SExpr = SExprAtom | SExpr[];
35
103
  * All expressions must be S-expression arrays.
36
104
  */
37
105
  type Expression = SExpr;
106
+ /**
107
+ * Recursive schema for s-expr-shaped DATA in literal positions (object
108
+ * values, effect arguments). Unlike `SExprSchema`, arrays may be empty or
109
+ * non-operator-headed — literal data lists (`children: []`, `tiles: [...]`)
110
+ * are valid here; only call positions get the operator-head refine.
111
+ */
112
+ declare const SExprDataSchema: z.ZodType<SExpr>;
38
113
  /**
39
114
  * Schema for atomic S-expression values (non-array)
40
115
  * Includes objects for payload data, props, etc.
@@ -59,7 +134,7 @@ declare const ExpressionSchema: z.ZodType<Expression>;
59
134
  * @param value - Value to check
60
135
  * @returns true if value is an S-expression (array with string operator)
61
136
  */
62
- declare function isSExpr(value: unknown): value is SExpr[];
137
+ declare function isSExpr(value: RuntimeValue): value is SExpr[];
63
138
  /**
64
139
  * Type guard for S-expression atoms (non-array values).
65
140
  *
@@ -67,7 +142,7 @@ declare function isSExpr(value: unknown): value is SExpr[];
67
142
  * Includes null, strings, numbers, booleans, and objects. Used to
68
143
  * distinguish atomic values from S-expression calls (arrays).
69
144
  *
70
- * @param {unknown} value - Value to check
145
+ * @param {RuntimeValue} value - Value to check
71
146
  * @returns {boolean} True if value is an S-expression atom, false otherwise
72
147
  *
73
148
  * @example
@@ -77,7 +152,7 @@ declare function isSExpr(value: unknown): value is SExpr[];
77
152
  * isSExprAtom({ key: 'value' }); // returns true
78
153
  * isSExprAtom(['+', 1, 2]); // returns false
79
154
  */
80
- declare function isSExprAtom(value: unknown): value is SExprAtom;
155
+ declare function isSExprAtom(value: RuntimeValue): value is SExprAtom;
81
156
  /**
82
157
  * Checks if a value is a binding reference.
83
158
  *
@@ -85,7 +160,7 @@ declare function isSExprAtom(value: unknown): value is SExprAtom;
85
160
  * Bindings reference runtime values like @entity.health, @payload.amount, @now.
86
161
  * Used for identifying bindings in S-expressions and validation.
87
162
  *
88
- * @param {unknown} value - Value to check
163
+ * @param {RuntimeValue} value - Value to check
89
164
  * @returns {boolean} True if value is a binding reference, false otherwise
90
165
  *
91
166
  * @example
@@ -94,14 +169,14 @@ declare function isSExprAtom(value: unknown): value is SExprAtom;
94
169
  * isBinding('not-a-binding'); // returns false
95
170
  * isBinding(123); // returns false
96
171
  */
97
- declare function isBinding(value: unknown): value is string;
172
+ declare function isBinding(value: RuntimeValue): value is string;
98
173
  /**
99
174
  * Checks if a value is a valid S-expression call (array with operator).
100
175
  *
101
176
  * Alias for isSExpr() - validates S-expression call structure.
102
177
  * Used to distinguish between S-expression calls and atom values.
103
178
  *
104
- * @param {unknown} value - Value to check
179
+ * @param {RuntimeValue} value - Value to check
105
180
  * @returns {boolean} True if value is a valid S-expression call, false otherwise
106
181
  *
107
182
  * @example
@@ -109,7 +184,7 @@ declare function isBinding(value: unknown): value is string;
109
184
  * isSExprCall(['set', '@entity.health', 100]); // returns true
110
185
  * isSExprCall('not-a-call'); // returns false
111
186
  */
112
- declare function isSExprCall(value: unknown): value is SExpr[];
187
+ declare function isSExprCall(value: RuntimeValue): value is SExpr[];
113
188
  /**
114
189
  * Parsed binding reference
115
190
  */
@@ -223,7 +298,7 @@ interface EventPayload {
223
298
  * Runtime guard for `EventPayloadValue` — narrows interpreter-produced
224
299
  * `unknown` values at typed substrate boundaries (e.g. `TraceContext.emit`).
225
300
  */
226
- declare function isEventPayloadValue(value: unknown): value is EventPayloadValue;
301
+ declare function isEventPayloadValue(value: RuntimeValue): value is EventPayloadValue;
227
302
  /**
228
303
  * Allowed leaf value for `LogMeta`. Mirrors `EventPayloadValue` shape so
229
304
  * the same row/list data flows through logs without manual flattening,
@@ -235,4 +310,4 @@ interface LogMeta {
235
310
  [key: string]: LogMetaValue;
236
311
  }
237
312
 
238
- export { CORE_BINDINGS as C, type Expression as E, type LogMeta as L, type ParsedBinding as P, type SExpr as S, type EventPayload as a, type CoreBinding as b, type EvalContext as c, type EventPayloadValue as d, type ExpressionInput as e, ExpressionSchema as f, type LogMetaValue as g, type SExprAtom as h, SExprAtomSchema as i, type SExprInput as j, SExprSchema as k, collectBindings as l, getArgs as m, getOperator as n, isBinding as o, isEventPayloadValue as p, isSExpr as q, isSExprAtom as r, isSExprCall as s, isValidBinding as t, parseBinding as u, sexpr as v, walkSExpr as w };
313
+ export { parseBinding as A, sexpr as B, CORE_BINDINGS as C, walkSExpr as D, type Expression as E, type JsonValue as J, type LogMeta as L, type ParsedBinding as P, type RuntimeValue as R, type SExpr as S, type ToolArgs as T, type EventPayload as a, type CoreBinding as b, type EvalContext as c, type EventPayloadValue as d, type ExpressionInput as e, ExpressionSchema as f, type JsonObject as g, type LogMetaValue as h, type SExprAtom as i, SExprAtomSchema as j, SExprDataSchema as k, type SExprInput as l, type SExprObject as m, SExprSchema as n, collectBindings as o, getArgs as p, getOperator as q, isBinding as r, isEventPayloadValue as s, isJsonArray as t, isJsonObject as u, isJsonPrimitive as v, isSExpr as w, isSExprAtom as x, isSExprCall as y, isValidBinding as z };
@@ -1,11 +1,9 @@
1
- import { h as FactoryParamValue, c as FactoryConfigTier, b as FactoryConfigParam, F as FactoryCallSite, j as FactorySignature, R as RuleOverlay, p as RuleOverlayEntry, o as PresentationOverlay, T as TraitOverlay } from '../types-CzocAZtG.js';
2
- export { a as FactoryCallSiteParams, d as FactoryEntitySignature, e as FactoryEventSignature, f as FactoryExposure, g as FactoryPageSignature, i as FactoryProvenance, k as FactorySignatureCatalog, l as FactorySignatureEntityField, m as FactoryTraitSignature, J as JsonSchema, n as JsonSchemaType, O as OwnershipOverlayEntry, P as PresentationNavItem, S as SchemaFieldType, q as TraitOverlayEntry, r as TraitOverlayListener } from '../types-CzocAZtG.js';
3
- import { E as EntityPersistence, a as EntityField } from '../entity-DfD-iXkn.js';
4
- export { J as JsonValue } from '../entity-DfD-iXkn.js';
5
- import { a as TraitReference } from '../trait-2E6TQw19.js';
1
+ import { h as FactoryParamValue, c as FactoryConfigTier, b as FactoryConfigParam, F as FactoryCallSite, j as FactorySignature, R as RuleOverlay, p as RuleOverlayEntry, o as PresentationOverlay, T as TraitOverlay } from '../types-B4NVh8V9.js';
2
+ export { a as FactoryCallSiteParams, d as FactoryEntitySignature, e as FactoryEventSignature, f as FactoryExposure, g as FactoryPageSignature, i as FactoryProvenance, k as FactorySignatureCatalog, l as FactorySignatureEntityField, m as FactoryTraitSignature, J as JsonSchema, n as JsonSchemaType, O as OwnershipOverlayEntry, P as PresentationNavItem, S as SchemaFieldType, q as TraitOverlayEntry, r as TraitOverlayListener } from '../types-B4NVh8V9.js';
3
+ import { a as EntityPersistence, E as EntityField } from '../effect-NbTgX2yB.js';
4
+ import { a as TraitReference } from '../trait-DdBiEffx.js';
5
+ export { J as JsonValue } from '../expression-Yf7qvvOs.js';
6
6
  import 'zod';
7
- import '../expression-DpAj1RzP.js';
8
- import '../effect-DSbx6joe.js';
9
7
 
10
8
  /**
11
9
  * Typed questionnaire surface — shapes the studio renders + answers.
@@ -1,9 +1,9 @@
1
- import { O as OrbitalSchema, M as MakeTraitRefOpts, a as OrbitalDefinition } from '../builders-CikYSzX6.js';
2
- import { C as CallSiteConfig, b as CallSiteConfigEntry, c as Trait } from '../trait-2E6TQw19.js';
3
- import { a as EntityField, E as EntityPersistence } from '../entity-DfD-iXkn.js';
1
+ import { O as OrbitalSchema, a as OrbitalDefinition } from '../schema-DdcBBHkb.js';
2
+ import { h as CallSiteConfig, i as CallSiteConfigEntry, g as Trait } from '../trait-DdBiEffx.js';
3
+ import { E as EntityField, a as EntityPersistence } from '../effect-NbTgX2yB.js';
4
+ import { MakeTraitRefOpts } from '../builders.js';
5
+ import '../expression-Yf7qvvOs.js';
4
6
  import 'zod';
5
- import '../effect-DSbx6joe.js';
6
- import '../expression-DpAj1RzP.js';
7
7
 
8
8
  /**
9
9
  * Orbital factory manifest types — shared across all packages.
@@ -343,7 +343,7 @@ var OrbitalEntitySchema = z.object({
343
343
  identity: z.boolean().optional(),
344
344
  collection: z.string().optional(),
345
345
  fields: z.array(EntityFieldSchema).min(1, "At least one field is required"),
346
- instances: z.array(z.record(z.unknown())).optional(),
346
+ instances: z.array(z.record(JsonValueSchema)).optional(),
347
347
  timestamps: z.boolean().optional(),
348
348
  softDelete: z.boolean().optional(),
349
349
  description: z.string().optional(),
@@ -354,6 +354,29 @@ var EntitySchema = OrbitalEntitySchema;
354
354
  function persistenceModeAllowsOverrides(persistence) {
355
355
  return persistence === "persistent" || persistence === void 0;
356
356
  }
357
+ var SExprDataSchema = z.lazy(
358
+ () => z.union([SExprAtomSchema, z.array(SExprDataSchema)])
359
+ );
360
+ var SExprAtomSchema = z.union([
361
+ z.string(),
362
+ z.number(),
363
+ z.boolean(),
364
+ z.null(),
365
+ z.record(SExprDataSchema)
366
+ // Objects for payload data
367
+ ]);
368
+ var SExprSchema = z.lazy(
369
+ () => z.union([
370
+ SExprAtomSchema,
371
+ z.array(z.lazy(() => SExprSchema)).min(1).refine(
372
+ (arr) => typeof arr[0] === "string",
373
+ { message: "S-expression array must have a string operator as first element" }
374
+ )
375
+ ])
376
+ );
377
+ var ExpressionSchema = SExprSchema;
378
+
379
+ // src/types/effect.ts
357
380
  var UI_SLOTS = [
358
381
  // App slots
359
382
  "main",
@@ -383,28 +406,10 @@ var UI_SLOTS = [
383
406
  "overlay.pause"
384
407
  ];
385
408
  z.enum(UI_SLOTS);
386
- var EffectSchema = z.array(z.unknown()).min(1).refine(
409
+ var EffectSchema = z.array(SExprDataSchema).min(1).refine(
387
410
  (arr) => typeof arr[0] === "string",
388
411
  { message: "Effect must be an S-expression with a string operator as first element" }
389
412
  );
390
- var SExprAtomSchema = z.union([
391
- z.string(),
392
- z.number(),
393
- z.boolean(),
394
- z.null(),
395
- z.record(z.unknown())
396
- // Objects for payload data
397
- ]);
398
- var SExprSchema = z.lazy(
399
- () => z.union([
400
- SExprAtomSchema,
401
- z.array(z.lazy(() => SExprSchema)).min(1).refine(
402
- (arr) => typeof arr[0] === "string",
403
- { message: "S-expression array must have a string operator as first element" }
404
- )
405
- ])
406
- );
407
- var ExpressionSchema = SExprSchema;
408
413
 
409
414
  // src/types/state-machine.ts
410
415
  var StateSchema = z.object({
@@ -638,7 +643,7 @@ var RequiredFieldSchema = z.object({
638
643
  type: z.enum(["string", "number", "boolean", "date", "array", "object", "timestamp", "datetime", "enum", "email", "url", "phone", "uuid", "image"]),
639
644
  description: z.string().optional()
640
645
  });
641
- z.object({
646
+ var TraitReferenceSchema = z.object({
642
647
  ref: z.string().min(1),
643
648
  refId: TraitIdSchema.optional(),
644
649
  // V4 local declaration id (see the interface doc) — declared so the
@@ -664,12 +669,9 @@ z.object({
664
669
  // through to the recursive TraitConfigValue union.
665
670
  config: z.record(z.union([ConfigFieldDeclarationSchema, TraitConfigValueSchema])).optional(),
666
671
  appliesTo: z.array(z.string()).optional(),
667
- // Phase F.7: zod accepts an array (the inliner validates element
668
- // shape). The full ListenDefinition shape isn't recursively encoded
669
- // here because TraitReference is the call-site form — listen entries
670
- // pasted in are already-resolved structured definitions, not nested
671
- // overrides.
672
- listens: z.array(z.unknown()).optional(),
672
+ // Phase F.7: caller-supplied listen entries are already-resolved
673
+ // structured definitions (see `TraitReference.listens`).
674
+ listens: z.array(TraitEventListenerSchema).optional(),
673
675
  emitsScope: z.enum(["internal", "external"]).optional(),
674
676
  // Phase F.8: per-transition effects override. The keys are event
675
677
  // names (the transition triggers AFTER renames); values are SExpr
@@ -691,6 +693,22 @@ z.object({
691
693
  path: ["events"]
692
694
  }
693
695
  );
696
+ var TraitUIBindingSchema = z.record(
697
+ z.object({
698
+ presentation: z.enum(["modal", "drawer", "popover", "inline", "confirm-dialog"]),
699
+ content: z.union([z.record(JsonValueSchema), z.array(z.record(JsonValueSchema))]),
700
+ props: z.object({
701
+ size: z.enum(["sm", "md", "lg", "xl", "full"]).optional(),
702
+ position: z.enum(["left", "right", "top", "bottom", "center"]).optional(),
703
+ title: z.string().optional(),
704
+ closable: z.boolean().optional(),
705
+ width: z.string().optional(),
706
+ showProgress: z.boolean().optional(),
707
+ step: z.number().optional(),
708
+ totalSteps: z.number().optional()
709
+ }).optional()
710
+ })
711
+ );
694
712
  var TraitScopeSchema = z.enum(["instance", "collection"]);
695
713
  var EntityFieldContractSchema = z.object({
696
714
  requires: z.array(z.string()),
@@ -724,26 +742,14 @@ var TraitSchema = z.object({
724
742
  ticks: z.array(TraitTickSchema).optional(),
725
743
  emits: z.array(TraitEventContractSchema).optional(),
726
744
  listens: z.array(TraitEventListenerSchema).optional(),
727
- ui: z.record(z.unknown()).optional(),
745
+ ui: TraitUIBindingSchema.optional(),
728
746
  config: DeclaredTraitConfigSchema.optional(),
729
747
  sourceBehavior: SourceBehaviorMetadataSchema.optional(),
730
748
  sourceEntityDefinition: EntitySchema.optional()
731
749
  });
732
750
  var TraitRefSchema = z.union([
733
751
  z.string().min(1),
734
- z.object({
735
- ref: z.string().min(1),
736
- config: TraitConfigSchema.optional(),
737
- linkedEntity: z.string().optional(),
738
- name: z.string().optional(),
739
- // Phase F.4: same non-empty refine as TraitReferenceSchema.events.
740
- // Both schemas accept the same call-site argument shape, so the
741
- // validators should agree.
742
- events: z.record(
743
- z.string().min(1, "events key (atom event name) must be non-empty"),
744
- z.string().min(1, "events value (caller event name) must be non-empty")
745
- ).optional()
746
- }),
752
+ TraitReferenceSchema,
747
753
  TraitSchema
748
754
  // Allow inline trait definitions
749
755
  ]);