@cynodia/axiom-agent-api 0.4.0-alpha.1 → 0.5.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,11 @@ framework.
8
8
  The machine-facing interface: semantic queries over the graph, field-level dependency
9
9
  and mutation-impact analysis, and transactional graph transformations.
10
10
 
11
+ Presentation and UX are queryable too — which action a view presents as primary, which
12
+ controls are destructive, how a form is grouped, what happens on a compact display, which
13
+ screens carry presentation warnings — and transformable: "make this form compact" is one
14
+ semantic change, and an application-wide restyling is a single theme change.
15
+
11
16
  ## Installation
12
17
 
13
18
  ```bash
package/dist/api.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import type { ApplicationGraph, ValidationResult } from '@cynodia/axiom-core';
2
- import { GraphQueries } from './queries.js';
2
+ import { PresentationQueries } from './presentation-queries.js';
3
3
  import { Transaction } from './transaction.js';
4
4
  import type { ChangeSet } from './changes.js';
5
5
  /**
6
6
  * The machine-facing interface to an application. Agents query semantics and apply
7
7
  * structural transformations; they never edit generated code.
8
8
  */
9
- export declare class AgentAPI extends GraphQueries {
9
+ export declare class AgentAPI extends PresentationQueries {
10
10
  private readonly changeLog;
11
11
  constructor(graph: ApplicationGraph);
12
12
  validate(): ValidationResult;
package/dist/api.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { validateGraph } from '@cynodia/axiom-core';
2
- import { GraphQueries } from './queries.js';
2
+ import { PresentationQueries } from './presentation-queries.js';
3
3
  import { Transaction } from './transaction.js';
4
4
  /**
5
5
  * The machine-facing interface to an application. Agents query semantics and apply
6
6
  * structural transformations; they never edit generated code.
7
7
  */
8
- export class AgentAPI extends GraphQueries {
8
+ export class AgentAPI extends PresentationQueries {
9
9
  changeLog = [];
10
10
  constructor(graph) {
11
11
  super(graph);
package/dist/changes.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AnyNode, FieldDef, FieldId, GraphEdge, NodeId } from '@cynodia/axiom-core';
2
- export type GraphChange = AddNodeChange | RemoveNodeChange | UpdateNodeChange | AddFieldChange | RemoveFieldChange | AddEdgeChange | RemoveEdgeChange;
1
+ import type { AnyNode, FieldDef, FieldId, GraphEdge, NodeId, ThemeInput } from '@cynodia/axiom-core';
2
+ export type GraphChange = AddNodeChange | RemoveNodeChange | UpdateNodeChange | AddFieldChange | RemoveFieldChange | AddEdgeChange | RemoveEdgeChange | SetThemeChange;
3
3
  export interface AddNodeChange {
4
4
  kind: 'add-node';
5
5
  nodeId: NodeId;
@@ -35,6 +35,16 @@ export interface RemoveEdgeChange {
35
35
  kind: 'remove-edge';
36
36
  edge: GraphEdge;
37
37
  }
38
+ /**
39
+ * A change to the application's visual identity. It is recorded like any other change and
40
+ * can never alter behaviour, which is why an application-wide restyling is one operation
41
+ * rather than an edit to every node.
42
+ */
43
+ export interface SetThemeChange {
44
+ kind: 'set-theme';
45
+ before?: ThemeInput;
46
+ after?: ThemeInput;
47
+ }
38
48
  /** A semantic change record: graph operations and intent, never a textual diff. */
39
49
  export interface ChangeSet {
40
50
  id: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './changes.js';
2
2
  export * from './queries.js';
3
+ export * from './presentation-queries.js';
3
4
  export * from './transaction.js';
4
5
  export * from './api.js';
5
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './changes.js';
2
2
  export * from './queries.js';
3
+ export * from './presentation-queries.js';
3
4
  export * from './transaction.js';
4
5
  export * from './api.js';
@@ -0,0 +1,81 @@
1
+ import type { ActionDef, Density, DeviceClass, FormNode, NodeId, Presentation, PresentationRole, ResolvedPresentation, ResolvedResponsive, StateDef, Theme, UINode, UxRole, ValidationIssue, ViewNode } from '@cynodia/axiom-core';
2
+ import { GraphQueries } from './queries.js';
3
+ /** One grouped part of a form, and what it contains. */
4
+ export interface FormSectionSummary {
5
+ nodeId: NodeId;
6
+ name?: string;
7
+ /** Text nodes inside the section that act as headings. */
8
+ headings: string[];
9
+ inputIds: NodeId[];
10
+ }
11
+ /**
12
+ * The shape of a form as UX, rather than as a list of children: which parts are sections,
13
+ * which controls are required, where the actions are and which one is primary.
14
+ */
15
+ export interface FormStructure {
16
+ formId: NodeId;
17
+ density: Density;
18
+ submitActionId?: NodeId;
19
+ sections: FormSectionSummary[];
20
+ /** Inputs that belong to no section. */
21
+ ungroupedInputIds: NodeId[];
22
+ actionGroupIds: NodeId[];
23
+ primaryActionIds: NodeId[];
24
+ destructiveActionIds: NodeId[];
25
+ requiredInputIds: NodeId[];
26
+ }
27
+ /**
28
+ * Presentation and UX queries, §46 and §47.
29
+ *
30
+ * These are the questions that cannot be answered from a stylesheet: which control is the
31
+ * primary action, which regions are grouped and why, what happens on a narrow display,
32
+ * where the presentation contradicts the application's own semantics. They are answerable
33
+ * here only because UX intent is structured data.
34
+ *
35
+ * Resolution is recomputed per call rather than cached: a transaction mutates the graph
36
+ * underneath these queries, and a stale presentation answer would be worse than a slow one.
37
+ */
38
+ export declare class PresentationQueries extends GraphQueries {
39
+ /** The application's visual identity, completed against the default theme. */
40
+ getTheme(): Theme;
41
+ /** Exactly what a node declares, before defaults, inheritance or inference. */
42
+ getPresentation(nodeId: NodeId): Presentation | undefined;
43
+ /** Presentation with every question answered, as a renderer receives it. */
44
+ resolvePresentation(nodeId: NodeId): ResolvedPresentation | undefined;
45
+ /** Resolved presentation for every UI node in the application. */
46
+ resolveAllPresentation(): Record<NodeId, ResolvedPresentation>;
47
+ getUxRole(nodeId: NodeId): UxRole | undefined;
48
+ /** What changes on a compact, regular or wide display. */
49
+ getResponsiveBehavior(nodeId: NodeId): Partial<Record<DeviceClass, ResolvedResponsive>>;
50
+ /** Every UI node whose resolved UX role is this one. */
51
+ findNodesByUxRole(uxRole: UxRole): UINode[];
52
+ /** Every UI node presented in this role, however the role was decided. */
53
+ findNodesByRole(role: PresentationRole): UINode[];
54
+ /** Which nodes end up at a given density, inheritance included. */
55
+ findNodesByDensity(density: Density): UINode[];
56
+ /** Views that present anything in this role — "which views use this theme role?". */
57
+ getViewsUsingRole(role: PresentationRole): ViewNode[];
58
+ /** Actions a view presents as primary. */
59
+ getPrimaryActions(viewId: NodeId): ActionDef[];
60
+ /** Actions a view presents as destructive, whether declared or inferred. */
61
+ getDestructiveActions(viewId: NodeId): ActionDef[];
62
+ /** Forms that offer no primary action, which is a hierarchy an agent can repair. */
63
+ getFormsWithoutPrimaryAction(): FormNode[];
64
+ /** Nodes carrying renderer-specific presentation that cannot be analyzed. */
65
+ getOpaquePresentationNodes(): UINode[];
66
+ /** States marked as ephemeral presentation state rather than domain facts. */
67
+ getEphemeralStates(): StateDef[];
68
+ /**
69
+ * Presentation and UX findings, optionally narrowed to one view. These are the answers
70
+ * to "which views contain presentation warnings?".
71
+ */
72
+ getPresentationWarnings(viewId?: NodeId): ValidationIssue[];
73
+ /** A form described as UX: sections, controls, action groups and hierarchy. */
74
+ getFormStructure(formId: NodeId): FormStructure;
75
+ protected presentationMap(): Record<NodeId, ResolvedPresentation>;
76
+ protected uiNodes(): UINode[];
77
+ protected descendants(id: NodeId): UINode[];
78
+ protected descendantIds(id: NodeId): NodeId[];
79
+ private actionsWithUxRole;
80
+ }
81
+ //# sourceMappingURL=presentation-queries.d.ts.map
@@ -0,0 +1,254 @@
1
+ import { isUINode, resolvePresentationMap, uiChildIds, validateGraph, } from '@cynodia/axiom-core';
2
+ import { GraphQueries } from './queries.js';
3
+ /** Diagnostic codes produced by the presentation layer. */
4
+ const PRESENTATION_CODES = [
5
+ 'UNKNOWN_PRESENTATION_TOKEN',
6
+ 'PRESENTATION_SEMANTIC_CONFLICT',
7
+ 'MULTIPLE_PRIMARY_ACTIONS',
8
+ 'FORM_WITHOUT_PRIMARY_ACTION',
9
+ 'DESTRUCTIVE_ACTION_PRESENTED_AS_SUCCESS',
10
+ 'DESTRUCTIVE_ACTION_UNMARKED',
11
+ 'EXCESSIVE_HORIZONTAL_ACTIONS',
12
+ 'EMPTY_STATE_WITHOUT_RECOVERY_ACTION',
13
+ 'RIGID_HORIZONTAL_LAYOUT',
14
+ 'CONFLICTING_SIZING',
15
+ 'INTERACTIVE_ELEMENT_MISSING_LABEL',
16
+ 'FORM_INPUT_MISSING_LABEL',
17
+ 'INVALID_HEADING_STRUCTURE',
18
+ 'OPAQUE_PRESENTATION',
19
+ ];
20
+ /**
21
+ * Presentation and UX queries, §46 and §47.
22
+ *
23
+ * These are the questions that cannot be answered from a stylesheet: which control is the
24
+ * primary action, which regions are grouped and why, what happens on a narrow display,
25
+ * where the presentation contradicts the application's own semantics. They are answerable
26
+ * here only because UX intent is structured data.
27
+ *
28
+ * Resolution is recomputed per call rather than cached: a transaction mutates the graph
29
+ * underneath these queries, and a stale presentation answer would be worse than a slow one.
30
+ */
31
+ export class PresentationQueries extends GraphQueries {
32
+ /** The application's visual identity, completed against the default theme. */
33
+ getTheme() {
34
+ return this.graph.theme;
35
+ }
36
+ /** Exactly what a node declares, before defaults, inheritance or inference. */
37
+ getPresentation(nodeId) {
38
+ const node = this.graph.getNode(nodeId);
39
+ return node && isUINode(node) ? node.presentation : undefined;
40
+ }
41
+ /** Presentation with every question answered, as a renderer receives it. */
42
+ resolvePresentation(nodeId) {
43
+ return this.presentationMap()[nodeId];
44
+ }
45
+ /** Resolved presentation for every UI node in the application. */
46
+ resolveAllPresentation() {
47
+ return this.presentationMap();
48
+ }
49
+ getUxRole(nodeId) {
50
+ return this.resolvePresentation(nodeId)?.uxRole;
51
+ }
52
+ /** What changes on a compact, regular or wide display. */
53
+ getResponsiveBehavior(nodeId) {
54
+ return this.resolvePresentation(nodeId)?.responsive ?? {};
55
+ }
56
+ /** Every UI node whose resolved UX role is this one. */
57
+ findNodesByUxRole(uxRole) {
58
+ const resolved = this.presentationMap();
59
+ return this.uiNodes().filter((node) => resolved[node.id]?.uxRole === uxRole);
60
+ }
61
+ /** Every UI node presented in this role, however the role was decided. */
62
+ findNodesByRole(role) {
63
+ const resolved = this.presentationMap();
64
+ return this.uiNodes().filter((node) => resolved[node.id]?.role === role);
65
+ }
66
+ /** Which nodes end up at a given density, inheritance included. */
67
+ findNodesByDensity(density) {
68
+ const resolved = this.presentationMap();
69
+ return this.uiNodes().filter((node) => resolved[node.id]?.density === density);
70
+ }
71
+ /** Views that present anything in this role — "which views use this theme role?". */
72
+ getViewsUsingRole(role) {
73
+ const views = new Map();
74
+ for (const node of this.findNodesByRole(role)) {
75
+ for (const view of this.enclosingViews(node.id)) {
76
+ views.set(view.id, view);
77
+ }
78
+ }
79
+ return [...views.values()];
80
+ }
81
+ /** Actions a view presents as primary. */
82
+ getPrimaryActions(viewId) {
83
+ return this.actionsWithUxRole(viewId, 'primary-action');
84
+ }
85
+ /** Actions a view presents as destructive, whether declared or inferred. */
86
+ getDestructiveActions(viewId) {
87
+ return this.actionsWithUxRole(viewId, 'destructive-action');
88
+ }
89
+ /** Forms that offer no primary action, which is a hierarchy an agent can repair. */
90
+ getFormsWithoutPrimaryAction() {
91
+ return this.graph
92
+ .getNodesByKind('form')
93
+ .filter((form) => this.getFormStructure(form.id).primaryActionIds.length === 0);
94
+ }
95
+ /** Nodes carrying renderer-specific presentation that cannot be analyzed. */
96
+ getOpaquePresentationNodes() {
97
+ const resolved = this.presentationMap();
98
+ return this.uiNodes().filter((node) => resolved[node.id]?.opaque === true);
99
+ }
100
+ /** States marked as ephemeral presentation state rather than domain facts. */
101
+ getEphemeralStates() {
102
+ return this.graph.getNodesByKind('state').filter((state) => state.ephemeral === true);
103
+ }
104
+ /**
105
+ * Presentation and UX findings, optionally narrowed to one view. These are the answers
106
+ * to "which views contain presentation warnings?".
107
+ */
108
+ getPresentationWarnings(viewId) {
109
+ const result = validateGraph(this.graph);
110
+ const findings = [...result.errors, ...result.warnings].filter((finding) => PRESENTATION_CODES.includes(finding.code));
111
+ if (!viewId) {
112
+ return findings;
113
+ }
114
+ const scope = new Set([viewId, ...this.descendantIds(viewId)]);
115
+ return findings.filter((finding) => finding.nodeId !== undefined && scope.has(finding.nodeId));
116
+ }
117
+ /** A form described as UX: sections, controls, action groups and hierarchy. */
118
+ getFormStructure(formId) {
119
+ const form = this.graph.getNode(formId);
120
+ if (!form || form.kind !== 'form') {
121
+ throw new Error(`${formId} is not a form`);
122
+ }
123
+ const resolved = this.presentationMap();
124
+ const sections = [];
125
+ const sectionInputs = new Set();
126
+ const actionGroupIds = [];
127
+ const primaryActionIds = new Set();
128
+ const destructiveActionIds = new Set();
129
+ const requiredInputIds = [];
130
+ const allInputIds = [];
131
+ if (form.submitActionId) {
132
+ primaryActionIds.add(form.submitActionId);
133
+ }
134
+ for (const node of this.descendants(formId)) {
135
+ const view = resolved[node.id];
136
+ if (view?.uxRole === 'form-section') {
137
+ const inner = this.descendants(node.id);
138
+ const inputIds = inner.filter((child) => child.kind === 'input').map((child) => child.id);
139
+ inputIds.forEach((id) => sectionInputs.add(id));
140
+ sections.push({
141
+ nodeId: node.id,
142
+ ...(node.name ? { name: node.name } : {}),
143
+ headings: inner
144
+ .filter((child) => child.kind === 'text')
145
+ .filter((child) => isHeading(resolved[child.id]))
146
+ .map((child) => (typeof child.value === 'string' ? child.value : '')),
147
+ inputIds,
148
+ });
149
+ }
150
+ if (view?.uxRole === 'action-group' || view?.uxRole === 'toolbar') {
151
+ actionGroupIds.push(node.id);
152
+ }
153
+ if (node.kind === 'input') {
154
+ allInputIds.push(node.id);
155
+ // Required is a fact about the model, not a presentation decision.
156
+ const addressed = requiredFieldOf(this, node);
157
+ if (addressed) {
158
+ requiredInputIds.push(node.id);
159
+ }
160
+ }
161
+ if (node.kind === 'button') {
162
+ if (view?.uxRole === 'primary-action') {
163
+ primaryActionIds.add(node.actionId);
164
+ }
165
+ if (view?.uxRole === 'destructive-action') {
166
+ destructiveActionIds.add(node.actionId);
167
+ }
168
+ }
169
+ }
170
+ return {
171
+ formId,
172
+ density: resolved[formId]?.density ?? 'comfortable',
173
+ ...(form.submitActionId ? { submitActionId: form.submitActionId } : {}),
174
+ sections,
175
+ ungroupedInputIds: allInputIds.filter((id) => !sectionInputs.has(id)),
176
+ actionGroupIds,
177
+ primaryActionIds: [...primaryActionIds],
178
+ destructiveActionIds: [...destructiveActionIds],
179
+ requiredInputIds,
180
+ };
181
+ }
182
+ // ---------------------------------------------------------------- internals
183
+ presentationMap() {
184
+ return resolvePresentationMap(this.graph.listNodes(), this.graph.theme);
185
+ }
186
+ uiNodes() {
187
+ return this.graph.listNodes().filter((node) => isUINode(node));
188
+ }
189
+ descendants(id) {
190
+ const found = [];
191
+ const seen = new Set([id]);
192
+ const visit = (current) => {
193
+ const node = this.graph.getNode(current);
194
+ if (!node || !isUINode(node)) {
195
+ return;
196
+ }
197
+ for (const childId of uiChildIds(node)) {
198
+ if (seen.has(childId)) {
199
+ continue;
200
+ }
201
+ seen.add(childId);
202
+ const child = this.graph.getNode(childId);
203
+ if (child && isUINode(child)) {
204
+ found.push(child);
205
+ visit(childId);
206
+ }
207
+ }
208
+ };
209
+ visit(id);
210
+ return found;
211
+ }
212
+ descendantIds(id) {
213
+ return this.descendants(id).map((node) => node.id);
214
+ }
215
+ actionsWithUxRole(viewId, uxRole) {
216
+ const resolved = this.presentationMap();
217
+ const found = new Map();
218
+ const candidates = [this.graph.getNode(viewId), ...this.descendants(viewId)];
219
+ for (const node of candidates) {
220
+ if (!node || !isUINode(node) || node.kind !== 'button') {
221
+ continue;
222
+ }
223
+ if (resolved[node.id]?.uxRole !== uxRole) {
224
+ continue;
225
+ }
226
+ const action = this.graph.getNode(node.actionId);
227
+ if (action?.kind === 'action') {
228
+ found.set(action.id, action);
229
+ }
230
+ }
231
+ // A form's own submit is a primary action even without a button node of its own.
232
+ if (uxRole === 'primary-action') {
233
+ for (const node of candidates) {
234
+ if (node && isUINode(node) && node.kind === 'form' && node.submitActionId) {
235
+ const action = this.graph.getNode(node.submitActionId);
236
+ if (action?.kind === 'action') {
237
+ found.set(action.id, action);
238
+ }
239
+ }
240
+ }
241
+ }
242
+ return [...found.values()];
243
+ }
244
+ }
245
+ function isHeading(resolved) {
246
+ const role = resolved?.textRole;
247
+ return role === 'heading' || role === 'title' || role === 'display';
248
+ }
249
+ /** Whether the field an input addresses is declared required. */
250
+ function requiredFieldOf(queries, node) {
251
+ const location = node.binding.location;
252
+ const fieldId = location.kind === 'field' ? location.fieldId : undefined;
253
+ return fieldId ? queries.getField(fieldId)?.field.required === true : false;
254
+ }
package/dist/queries.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ActionDef, AnyNode, ApplicationGraph, ConstraintDef, EdgeKind, Expression, FieldId, FormNode, GraphEdge, Location, NodeId, StateDef, UINode, ViewNode } from '@cynodia/axiom-core';
1
+ import type { ActionDef, AnyNode, ApplicationGraph, ConstraintDef, EdgeKind, Expression, FieldId, FormNode, GraphEdge, Location, NodeId, StateDef, TransitionConstraintDef, UINode, ViewNode } from '@cynodia/axiom-core';
2
2
  export interface SubgraphRequest {
3
3
  root: NodeId;
4
4
  depth?: number;
@@ -16,7 +16,17 @@ export interface MutationImpact {
16
16
  directWriters: AnyNode[];
17
17
  dependentDerivedStates: StateDef[];
18
18
  affectedConstraints: ConstraintDef[];
19
+ /** Rules that govern how this state may change, whatever writes it. */
20
+ affectedTransitionConstraints: TransitionConstraintDef[];
19
21
  affectedViews: ViewNode[];
22
+ /**
23
+ * False when something in the graph cannot be analyzed — a native operation that does
24
+ * not declare its effects, for instance. An incomplete answer says so rather than
25
+ * presenting itself as exhaustive.
26
+ */
27
+ analysisComplete: boolean;
28
+ /** Why the analysis is incomplete, when it is. */
29
+ analysisGaps: string[];
20
30
  }
21
31
  export declare class GraphQueries {
22
32
  protected graph: ApplicationGraph;
@@ -33,6 +43,15 @@ export declare class GraphQueries {
33
43
  /** States whose value type mentions the entity. */
34
44
  getStatesForEntity(entityId: NodeId): StateDef[];
35
45
  getConstraintsForEntity(entityId: NodeId): ConstraintDef[];
46
+ /** Rules governing how instances of this entity may change. */
47
+ getTransitionConstraintsForEntity(entityId: NodeId): TransitionConstraintDef[];
48
+ /** Every rule that protects a location, whichever path attempts the write. */
49
+ getRulesProtecting(location: Location): {
50
+ constraints: ConstraintDef[];
51
+ transitionConstraints: TransitionConstraintDef[];
52
+ };
53
+ /** Parts of the graph whose reads and writes cannot be derived. */
54
+ private analysisGaps;
36
55
  /** Actions that write a state holding the entity, or that construct instances of it. */
37
56
  getActionsForEntity(entityId: NodeId): ActionDef[];
38
57
  /** Every UI node that binds or displays one of the entity's fields. */
package/dist/queries.js CHANGED
@@ -45,6 +45,32 @@ export class GraphQueries {
45
45
  getConstraintsForEntity(entityId) {
46
46
  return this.graph.getNodesByKind('constraint').filter((constraint) => constraint.entityId === entityId);
47
47
  }
48
+ /** Rules governing how instances of this entity may change. */
49
+ getTransitionConstraintsForEntity(entityId) {
50
+ return this.graph
51
+ .getNodesByKind('transition-constraint')
52
+ .filter((constraint) => constraint.entityId === entityId);
53
+ }
54
+ /** Every rule that protects a location, whichever path attempts the write. */
55
+ getRulesProtecting(location) {
56
+ const impact = this.getMutationImpact(location);
57
+ return {
58
+ constraints: impact.affectedConstraints,
59
+ transitionConstraints: impact.affectedTransitionConstraints,
60
+ };
61
+ }
62
+ /** Parts of the graph whose reads and writes cannot be derived. */
63
+ analysisGaps() {
64
+ const gaps = [];
65
+ for (const action of this.graph.getNodesByKind('action')) {
66
+ for (const operation of action.operations ?? []) {
67
+ if (operation.kind === 'native' && (operation.declaredEffects ?? []).length === 0) {
68
+ gaps.push(`${action.name ?? action.id} runs the native operation "${operation.implementationId}" without declaring its effects`);
69
+ }
70
+ }
71
+ }
72
+ return gaps;
73
+ }
48
74
  /** Actions that write a state holding the entity, or that construct instances of it. */
49
75
  getActionsForEntity(entityId) {
50
76
  const stateIds = new Set(this.getStatesForEntity(entityId).map((state) => state.id));
@@ -203,6 +229,10 @@ export class GraphQueries {
203
229
  views.set(view.id, view);
204
230
  }
205
231
  }
232
+ const affectedTransitionConstraints = this.graph
233
+ .getNodesByKind('transition-constraint')
234
+ .filter((constraint) => entityIds.has(constraint.entityId));
235
+ const gaps = this.analysisGaps();
206
236
  return {
207
237
  location,
208
238
  rootStateId,
@@ -210,7 +240,10 @@ export class GraphQueries {
210
240
  directWriters,
211
241
  dependentDerivedStates,
212
242
  affectedConstraints,
243
+ affectedTransitionConstraints,
213
244
  affectedViews: [...views.values()],
245
+ analysisComplete: gaps.length === 0,
246
+ analysisGaps: gaps,
214
247
  };
215
248
  }
216
249
  constraintTouches(constraint, fieldIds) {
@@ -1,6 +1,6 @@
1
1
  import { ApplicationGraph } from '@cynodia/axiom-core';
2
- import type { ActionDef, AnyNode, ButtonNode, ConditionalNode, ConstraintDef, ContainerNode, EdgeId, EdgeKind, Expression, FieldDef, FieldDisplayNode, FieldId, FormNode, InputNode, Location, NodeId, RepeatNode, RouteDef, StateDef, TextNode, UINode, ValidationResult, ViewNode } from '@cynodia/axiom-core';
3
- import { GraphQueries } from './queries.js';
2
+ import type { ActionDef, AnyNode, ButtonNode, ConditionalNode, ConstraintDef, ContainerNode, Density, DeviceClass, EdgeId, EdgeKind, Expression, FieldDef, FieldDisplayNode, FieldId, FormNode, InputNode, Location, NodeId, Presentation, RepeatNode, ResponsiveOverride, RouteDef, StateDef, TextNode, ThemeInput, UINode, UxRole, ValidationResult, ValueFormat, ViewNode } from '@cynodia/axiom-core';
3
+ import { PresentationQueries } from './presentation-queries.js';
4
4
  import type { ChangeSet, GraphChange } from './changes.js';
5
5
  export declare class TransactionError extends Error {
6
6
  readonly result?: ValidationResult;
@@ -13,7 +13,7 @@ type UIInput<T extends UINode> = Omit<T, 'id' | 'kind'> & {
13
13
  * A staged set of graph transformations. Every change is applied to a private copy, so
14
14
  * the graph an agent (or a runtime) can observe is unchanged until `commit()` succeeds.
15
15
  */
16
- export declare class Transaction extends GraphQueries {
16
+ export declare class Transaction extends PresentationQueries {
17
17
  private readonly target;
18
18
  private readonly onCommit;
19
19
  private readonly operations;
@@ -81,6 +81,28 @@ export declare class Transaction extends GraphQueries {
81
81
  * field added to the model is also populated by the actions that create records.
82
82
  */
83
83
  addFieldToConstructors(entityId: NodeId, fieldId: FieldId, value: Expression): NodeId[];
84
+ /**
85
+ * Replaces a node's presentation intent outright.
86
+ *
87
+ * "Make this form more compact" is one of these calls, not seventeen edited style
88
+ * declarations — and because the result is still semantic data, the next agent can read
89
+ * back what was intended rather than infer it from CSS.
90
+ */
91
+ setPresentation(nodeId: NodeId, presentation: Presentation | undefined): void;
92
+ /** Merges presentation intent, leaving whatever the node already said in place. */
93
+ mergePresentation(nodeId: NodeId, patch: Presentation): void;
94
+ setUxRole(nodeId: NodeId, uxRole: UxRole | undefined): void;
95
+ setDensity(nodeId: NodeId, density: Density): void;
96
+ setValueFormat(nodeId: NodeId, format: ValueFormat | undefined): void;
97
+ /** States what a node does on one class of display. */
98
+ setResponsiveBehavior(nodeId: NodeId, device: DeviceClass, override: ResponsiveOverride | undefined): void;
99
+ /**
100
+ * Replaces the theme. An application-wide visual change belongs here rather than in the
101
+ * UI nodes: a theme cannot alter an action, a constraint, a location or a route.
102
+ */
103
+ setTheme(theme: ThemeInput | undefined): void;
104
+ /** Changes part of the theme, keeping the rest of what the application declared. */
105
+ mergeTheme(patch: ThemeInput): void;
84
106
  appendChild(parentId: NodeId, childId: NodeId, position?: number): void;
85
107
  addNode<T extends AnyNode>(node: T): NodeId;
86
108
  updateNode(node: AnyNode): void;
@@ -97,6 +119,7 @@ export declare class Transaction extends GraphQueries {
97
119
  rollback(): void;
98
120
  private assertOpen;
99
121
  private addUiNode;
122
+ private requireUiNode;
100
123
  private requireNode;
101
124
  }
102
125
  export {};
@@ -1,5 +1,5 @@
1
- import { ApplicationGraph, createFieldId, createNodeId, randomHex, synchronizeEdges, validateGraph, } from '@cynodia/axiom-core';
2
- import { GraphQueries } from './queries.js';
1
+ import { ApplicationGraph, createFieldId, createNodeId, isUINode, randomHex, synchronizeEdges, validateGraph, } from '@cynodia/axiom-core';
2
+ import { PresentationQueries } from './presentation-queries.js';
3
3
  export class TransactionError extends Error {
4
4
  result;
5
5
  constructor(message, result) {
@@ -12,7 +12,7 @@ export class TransactionError extends Error {
12
12
  * A staged set of graph transformations. Every change is applied to a private copy, so
13
13
  * the graph an agent (or a runtime) can observe is unchanged until `commit()` succeeds.
14
14
  */
15
- export class Transaction extends GraphQueries {
15
+ export class Transaction extends PresentationQueries {
16
16
  target;
17
17
  onCommit;
18
18
  operations = [];
@@ -180,6 +180,70 @@ export class Transaction extends GraphQueries {
180
180
  }
181
181
  return updated;
182
182
  }
183
+ // ------------------------------------------------------- presentation and theme
184
+ /**
185
+ * Replaces a node's presentation intent outright.
186
+ *
187
+ * "Make this form more compact" is one of these calls, not seventeen edited style
188
+ * declarations — and because the result is still semantic data, the next agent can read
189
+ * back what was intended rather than infer it from CSS.
190
+ */
191
+ setPresentation(nodeId, presentation) {
192
+ const node = this.requireUiNode(nodeId);
193
+ if (presentation === undefined) {
194
+ delete node.presentation;
195
+ }
196
+ else {
197
+ node.presentation = structuredClone(presentation);
198
+ }
199
+ this.updateNode(node);
200
+ }
201
+ /** Merges presentation intent, leaving whatever the node already said in place. */
202
+ mergePresentation(nodeId, patch) {
203
+ const node = this.requireUiNode(nodeId);
204
+ node.presentation = { ...(node.presentation ?? {}), ...structuredClone(patch) };
205
+ this.updateNode(node);
206
+ }
207
+ setUxRole(nodeId, uxRole) {
208
+ this.mergePresentation(nodeId, { uxRole });
209
+ }
210
+ setDensity(nodeId, density) {
211
+ this.mergePresentation(nodeId, { density });
212
+ }
213
+ setValueFormat(nodeId, format) {
214
+ this.mergePresentation(nodeId, { format });
215
+ }
216
+ /** States what a node does on one class of display. */
217
+ setResponsiveBehavior(nodeId, device, override) {
218
+ const node = this.requireUiNode(nodeId);
219
+ const responsive = { ...(node.presentation?.responsive ?? {}) };
220
+ if (override === undefined) {
221
+ delete responsive[device];
222
+ }
223
+ else {
224
+ responsive[device] = structuredClone(override);
225
+ }
226
+ node.presentation = { ...(node.presentation ?? {}), responsive };
227
+ this.updateNode(node);
228
+ }
229
+ /**
230
+ * Replaces the theme. An application-wide visual change belongs here rather than in the
231
+ * UI nodes: a theme cannot alter an action, a constraint, a location or a route.
232
+ */
233
+ setTheme(theme) {
234
+ const before = this.graph.declaredTheme;
235
+ this.graph.setTheme(theme);
236
+ this.operations.push({
237
+ kind: 'set-theme',
238
+ ...(before ? { before } : {}),
239
+ ...(theme ? { after: structuredClone(theme) } : {}),
240
+ });
241
+ }
242
+ /** Changes part of the theme, keeping the rest of what the application declared. */
243
+ mergeTheme(patch) {
244
+ const before = this.graph.declaredTheme ?? {};
245
+ this.setTheme(mergeThemeInput(before, patch));
246
+ }
183
247
  appendChild(parentId, childId, position) {
184
248
  const parent = this.graph.getNode(parentId);
185
249
  if (!parent || !('children' in parent) || !Array.isArray(parent.children)) {
@@ -280,6 +344,13 @@ export class Transaction extends GraphQueries {
280
344
  const id = node.id ?? createNodeId(node.kind.replace('-', '_'));
281
345
  return this.addNode({ ...node, id });
282
346
  }
347
+ requireUiNode(id) {
348
+ const node = this.graph.getNode(id);
349
+ if (!node || !isUINode(node)) {
350
+ throw new TransactionError(`${id} is not a UI node`);
351
+ }
352
+ return node;
353
+ }
283
354
  requireNode(id, kind) {
284
355
  const node = this.graph.getNode(id);
285
356
  if (!node || node.kind !== kind) {
@@ -288,3 +359,20 @@ export class Transaction extends GraphQueries {
288
359
  return node;
289
360
  }
290
361
  }
362
+ /** Deep merge of two partial themes, so a patch never has to restate whole tables. */
363
+ function mergeThemeInput(base, patch) {
364
+ const isPlain = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
365
+ const merge = (left, right) => {
366
+ if (!isPlain(right)) {
367
+ return right === undefined ? left : right;
368
+ }
369
+ const result = isPlain(left) ? { ...left } : {};
370
+ for (const [key, value] of Object.entries(right)) {
371
+ if (value !== undefined) {
372
+ result[key] = merge(result[key], value);
373
+ }
374
+ }
375
+ return result;
376
+ };
377
+ return merge(structuredClone(base), structuredClone(patch));
378
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cynodia/axiom-agent-api",
3
- "version": "0.4.0-alpha.1",
3
+ "version": "0.5.0-alpha.1",
4
4
  "description": "Semantic queries and transactional graph transformations for AI agents.",
5
5
  "license": "MIT",
6
6
  "author": "AskTech AS",
@@ -31,7 +31,7 @@
31
31
  }
32
32
  },
33
33
  "dependencies": {
34
- "@cynodia/axiom-core": "0.4.0-alpha.1"
34
+ "@cynodia/axiom-core": "0.5.0-alpha.1"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsc -b tsconfig.json tsconfig.test.json",