spytial-core 4.0.0 → 4.0.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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { Diagnostic, DomainSchema, SelectorAssistant, SpecEditorThemeInput } from '../spec-editor';
2
+ import type { Diagnostic, DomainSchema, LayoutAssistant, SelectorAssistant, SpecEditorThemeInput } from '../spec-editor';
3
3
  import type { ConstraintData, DirectiveData } from './NoCodeView/interfaces';
4
4
  import type { IInputDataInstance } from '../data-instance/interfaces';
5
5
  /**
@@ -45,6 +45,12 @@ export interface CndLayoutInterfaceProps {
45
45
  theme?: SpecEditorThemeInput;
46
46
  /** Selector-writing assistant hook. */
47
47
  selectorAssistant?: SelectorAssistant;
48
+ /**
49
+ * Whole-spec suggestion hook. Supplying `suggest` adds a Suggest button to
50
+ * the editor toolbar; the proposal is applied to the document (one undo step)
51
+ * and surfaced through `onChange` like any other edit.
52
+ */
53
+ layoutAssistant?: LayoutAssistant;
48
54
  /** Row density. */
49
55
  density?: 'compact' | 'comfortable';
50
56
  /** Syntax highlighting in code view + selector fields (default true). */
@@ -26,6 +26,7 @@ export { ProjectionControls, ProjectionOrchestrator } from './ProjectionControls
26
26
  export type { ProjectionControlsProps, ProjectionChoice, ProjectionOrchestratorProps, ProjectionOrchestratorResult, } from './ProjectionControls';
27
27
  export { CndLayoutInterface } from './CndLayoutInterface';
28
28
  export type { CndLayoutInterfaceProps } from './CndLayoutInterface';
29
+ export type { SelectorAssistant, SelectorAssistContext, Completion, LayoutAssistant, LayoutAssistContext, LayoutSuggestionResult, LayoutSuggestionDetail, LayoutSuggestionConfidence, LayoutSuggestionOutcome, } from '../spec-editor';
29
30
  export { generateLayoutSpecYaml, parseLayoutSpecToData } from './NoCodeView';
30
31
  export type { ConstraintData, DirectiveData } from './NoCodeView';
31
32
  export { EvaluatorRepl } from './EvaluatorRepl/EvaluatorRepl';
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Whole-spec suggestion hook (HOOK 3).
3
+ *
4
+ * Where {@link SelectorAssistant} assists one selector field, a
5
+ * `LayoutAssistant` proposes an entire layout. Integrators provide the policy
6
+ * — a heuristic analyzer, a model, a synthesis engine — and the editor owns the
7
+ * affordance: a toolbar button, the apply-through-document semantics (so the
8
+ * suggestion is one undo step and refreshes the builder in place), and a
9
+ * read-only panel explaining what the suggester did.
10
+ *
11
+ * The contract is deliberately domain-agnostic. The context is
12
+ * `{domain, instance, currentYaml}` and nothing else; the optional
13
+ * per-suggestion metadata (`rationale`, `confidence`, `outcome`) is rendered
14
+ * generically, and a suggester with no such vocabulary simply omits it. Any
15
+ * host can plug in any suggester.
16
+ *
17
+ * Framework-agnostic — no React.
18
+ */
19
+ import type { IInputDataInstance } from '../../data-instance/interfaces';
20
+ import type { DomainSchema } from './domain-schema';
21
+ export interface LayoutAssistContext {
22
+ /** Domain awareness, as resolved by the editor (`domain` prop ?? extracted from `instance`). */
23
+ domain?: DomainSchema;
24
+ /** The live data instance, when the host passed one. */
25
+ instance?: IInputDataInstance;
26
+ /** The full current spec text, so a suggester can extend rather than replace. */
27
+ currentYaml: string;
28
+ }
29
+ /** How much the suggester trusts an individual suggestion. */
30
+ export type LayoutSuggestionConfidence = 'high' | 'medium' | 'low';
31
+ /**
32
+ * What became of a suggestion in the returned YAML. Suggesters that validate
33
+ * their own output use this to admit a fallback (`weakened`) or a drop
34
+ * (`omitted`) instead of silently shipping a shorter spec.
35
+ */
36
+ export type LayoutSuggestionOutcome = 'applied' | 'weakened' | 'omitted';
37
+ /** One line of the suggestions panel. All fields beyond `id` are optional. */
38
+ export interface LayoutSuggestionDetail {
39
+ /** Stable identifier, unique within a result. Used as the React key. */
40
+ id: string;
41
+ /** Why the suggester proposed this. Rendered as the body of the row. */
42
+ rationale?: string;
43
+ confidence?: LayoutSuggestionConfidence;
44
+ outcome?: LayoutSuggestionOutcome;
45
+ }
46
+ export interface LayoutSuggestionResult {
47
+ /** The proposed spec. Replaces the document wholesale, as one undo step. */
48
+ yaml: string;
49
+ /** Per-suggestion detail for the panel. Omit for an opaque suggestion. */
50
+ suggestions?: readonly LayoutSuggestionDetail[];
51
+ /** Result-level remarks (e.g. "2 suggestions used a weaker fallback"). */
52
+ notes?: readonly string[];
53
+ }
54
+ export interface LayoutAssistant {
55
+ /**
56
+ * Propose a whole spec for the current data. Powers the toolbar's Suggest
57
+ * affordance; the button is hidden entirely when this member is absent.
58
+ *
59
+ * Rejecting is a normal outcome — the editor surfaces the error message and
60
+ * leaves the document untouched.
61
+ */
62
+ suggest?(ctx: LayoutAssistContext): Promise<LayoutSuggestionResult>;
63
+ }
@@ -19,6 +19,7 @@ export type { DomainSchema, DomainRelation } from './domain/domain-schema';
19
19
  export { extractDomainSchema } from './domain/domain-schema';
20
20
  export { validateAgainstDomain, extractSelectorIdentifiers, } from './domain/domain-validation';
21
21
  export type { SelectorAssistant, SelectorAssistContext, Completion, } from './domain/assistant';
22
+ export type { LayoutAssistant, LayoutAssistContext, LayoutSuggestionResult, LayoutSuggestionDetail, LayoutSuggestionConfidence, LayoutSuggestionOutcome, } from './domain/layout-assistant';
22
23
  export { getSelectorKeywordCompletions, getDomainCompletions, createBuiltinCompletionSource, mergeCompletions, MAX_ATOM_COMPLETIONS, } from './domain/completions';
23
24
  export type { SpecEditorTheme } from './ui/theme';
24
25
  export { lightTheme, darkTheme, themeToCssVars, registerSpecEditorThemes, resolveSpecEditorTheme } from './ui/theme';
@@ -35,5 +36,7 @@ export type { CodeViewProps } from './ui/CodeView';
35
36
  export { CodeView } from './ui/CodeView';
36
37
  export type { BuilderViewProps } from './ui/BuilderView';
37
38
  export { BuilderView } from './ui/BuilderView';
39
+ export type { SuggestionsPanelProps } from './ui/SuggestionsPanel';
40
+ export { SuggestionsPanel } from './ui/SuggestionsPanel';
38
41
  export type { SpecEditorProps } from './ui/SpecEditor';
39
42
  export { SpecEditor } from './ui/SpecEditor';
@@ -23,12 +23,18 @@
23
23
  * with `assistant.complete()`; `assistant.synthesize` powers the ✨ affordance;
24
24
  * `assistant.review()` results are merged into the field diagnostics (debounced,
25
25
  * stale-dropped, failures swallowed).
26
+ *
27
+ * Layout assistance: `layoutAssistant.suggest` powers the toolbar's Suggest
28
+ * button. The proposal is applied through `replaceFromYaml` + `emit`, so it is
29
+ * one undo step, refreshes the builder in place, and re-validates — the same
30
+ * path a code-view edit takes. Its rationale renders in the suggestions panel.
26
31
  */
27
32
  import React from 'react';
28
33
  import './spec-editor.css';
29
34
  import type { Diagnostic } from '../core/types';
30
35
  import type { DomainSchema } from '../domain/domain-schema';
31
36
  import type { SelectorAssistant } from '../domain/assistant';
37
+ import type { LayoutAssistant } from '../domain/layout-assistant';
32
38
  import type { IInputDataInstance } from '../../data-instance/interfaces';
33
39
  import { SpecEditorThemeInput } from './theme';
34
40
  export interface SpecEditorProps {
@@ -47,6 +53,11 @@ export interface SpecEditorProps {
47
53
  */
48
54
  theme?: SpecEditorThemeInput;
49
55
  selectorAssistant?: SelectorAssistant;
56
+ /**
57
+ * Whole-spec suggestion hook. When it provides `suggest`, the toolbar grows a
58
+ * Suggest button; otherwise nothing is rendered and the editor is unchanged.
59
+ */
60
+ layoutAssistant?: LayoutAssistant;
50
61
  /** appearance */
51
62
  density?: 'compact' | 'comfortable';
52
63
  /**
@@ -0,0 +1,18 @@
1
+ /**
2
+ * {@link SuggestionsPanel} — the read-only explanation of a
3
+ * {@link LayoutAssistant} run.
4
+ *
5
+ * The suggestion itself has already been applied to the document by the time
6
+ * this renders; the panel exists so the reasoning isn't thrown away. Each row
7
+ * shows the suggester's rationale plus two optional generic chips (confidence,
8
+ * outcome), and result-level `notes` follow the list. Nothing here is
9
+ * interactive beyond dismissal — accepting or rejecting individual suggestions
10
+ * would require the suggester to recompose the spec, which is host policy.
11
+ */
12
+ import React from 'react';
13
+ import type { LayoutSuggestionResult } from '../domain/layout-assistant';
14
+ export interface SuggestionsPanelProps {
15
+ result: LayoutSuggestionResult;
16
+ onDismiss(): void;
17
+ }
18
+ export declare const SuggestionsPanel: React.FC<SuggestionsPanelProps>;
@@ -26,5 +26,7 @@ export type { CodeViewProps } from './CodeView';
26
26
  export { CodeView } from './CodeView';
27
27
  export type { BuilderViewProps } from './BuilderView';
28
28
  export { BuilderView } from './BuilderView';
29
+ export type { SuggestionsPanelProps } from './SuggestionsPanel';
30
+ export { SuggestionsPanel } from './SuggestionsPanel';
29
31
  export type { SpecEditorProps } from './SpecEditor';
30
32
  export { SpecEditor } from './SpecEditor';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spytial-core",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "A fully client-side application for SpyTial.",
5
5
  "main": "./dist/browser/spytial-core-complete.global.js",
6
6
  "types": "./dist/types/index.d.ts",