@rsconcept/rstool 1.4.3 → 1.6.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.
Files changed (52) hide show
  1. package/README.md +5 -4
  2. package/dist/{agent-workflow-D22FeODL.d.ts → agent-workflow-BTwrxOoX.d.ts} +9 -2
  3. package/dist/{diagnostic-assembly-DRunIcKQ.js → diagnostic-assembly-B-6vIA5I.js} +3 -1
  4. package/dist/{diagnostic-assembly-DRunIcKQ.js.map → diagnostic-assembly-B-6vIA5I.js.map} +1 -1
  5. package/dist/index.d.ts +3 -3
  6. package/dist/index.js +1 -1
  7. package/dist/mappers/model-adapter.js +127 -1
  8. package/dist/mappers/model-adapter.js.map +1 -0
  9. package/dist/mappers/schema-adapter.d.ts +5 -1
  10. package/dist/mappers/schema-adapter.js +44 -11
  11. package/dist/mappers/schema-adapter.js.map +1 -1
  12. package/dist/mappers/types.js +1 -1
  13. package/dist/models/agent-workflow.d.ts +2 -2
  14. package/dist/models/diagnostic.js +1 -1
  15. package/dist/models/index.d.ts +4 -4
  16. package/dist/models/index.js +1 -1
  17. package/dist/models/rstool-agent.d.ts +1 -1
  18. package/dist/models/rstool-agent.js +1 -1
  19. package/dist/models/tool-contract.d.ts +1 -1
  20. package/dist/models/tool-contract.js +1 -1
  21. package/dist/models/tool-contract.js.map +1 -1
  22. package/dist/{models-B255GaEC.js → models-LMyDB0md.js} +25 -4
  23. package/dist/models-LMyDB0md.js.map +1 -0
  24. package/dist/rsform-builder-DKwZfJvN.js +102 -0
  25. package/dist/rsform-builder-DKwZfJvN.js.map +1 -0
  26. package/dist/{rstool-agent-BGQAzFly.d.ts → rstool-agent-BrAFJcoE.d.ts} +6 -4
  27. package/dist/session/session-store.js +1 -1
  28. package/dist/{tool-contract-sQfr-DYD.d.ts → tool-contract-BUaDRHoO.d.ts} +8 -3
  29. package/dist/wrapper/stdio-wrapper.js +8 -2
  30. package/dist/wrapper/stdio-wrapper.js.map +1 -1
  31. package/docs/CONCEPTUAL-SCHEMA.md +44 -0
  32. package/docs/CONSTITUENTA.md +1 -1
  33. package/docs/DIAGNOSTICS.md +32 -31
  34. package/docs/README.md +3 -3
  35. package/package.json +19 -18
  36. package/skills/README.md +3 -3
  37. package/skills/rstool-helper/EXAMPLES.md +194 -3
  38. package/skills/rstool-helper/GUIDE.md +79 -8
  39. package/skills/rstool-helper/REFERENCE.md +192 -34
  40. package/skills/rstool-helper/SKILL.md +28 -8
  41. package/src/mappers/diagnostic-assembly.ts +3 -0
  42. package/src/mappers/rsform-builder.ts +1 -1
  43. package/src/mappers/schema-adapter.ts +48 -16
  44. package/src/models/agent-workflow.ts +8 -0
  45. package/src/models/index.ts +1 -0
  46. package/src/models/rstool-agent.test.ts +21 -0
  47. package/src/models/rstool-agent.ts +23 -0
  48. package/src/models/tool-contract.ts +8 -1
  49. package/src/wrapper/stdio-handler.ts +8 -1
  50. package/dist/model-adapter-D-YmIvQW.js +0 -225
  51. package/dist/model-adapter-D-YmIvQW.js.map +0 -1
  52. package/dist/models-B255GaEC.js.map +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Agent-facing library for **incremental RSForm construction**, **RSLang expression analysis**, **diagnostics**, **modeling**, and **evaluation**. It wraps [`@rsconcept/domain`](https://www.npmjs.com/package/@rsconcept/domain) with a deterministic session contract and a stdio JSON wrapper for LLM agents. MCP hosts can use it through [`@rsconcept/rstool-mcp`](https://www.npmjs.com/package/@rsconcept/rstool-mcp).
4
4
 
5
- **Contract version:** `3.0.0` — see [skills/rstool-helper/REFERENCE.md](./skills/rstool-helper/REFERENCE.md) for the full v3 API.
5
+ **Contract version:** `3.1.0` — see [skills/rstool-helper/REFERENCE.md](./skills/rstool-helper/REFERENCE.md) for the full v3 API.
6
6
 
7
7
  ## Agent skill
8
8
 
@@ -77,7 +77,7 @@ Maintainers: see [PUBLISHING.md](./PUBLISHING.md) for npm release steps.
77
77
  - If a session method is called without an active session, rstool creates one lazily.
78
78
  - On startup, a ready handshake is printed.
79
79
 
80
- Supported methods (contract `3.0.0`):
80
+ Supported methods (contract `3.1.0`):
81
81
 
82
82
  - `ping`
83
83
  - `methods`
@@ -97,6 +97,7 @@ Supported methods (contract `3.0.0`):
97
97
  - `getModelState`
98
98
  - `evaluate`
99
99
  - `recalculateModel`
100
+ - `restoreOrder`
100
101
 
101
102
  Params are **flat** at the top level (no `params.input` wrapper). Optional `sessionId` sits alongside method fields.
102
103
 
@@ -111,7 +112,7 @@ Request:
111
112
  Response:
112
113
 
113
114
  ```json
114
- { "id": "1", "ok": true, "result": { "sessionId": "...", "contractVersion": "3.0.0" } }
115
+ { "id": "1", "ok": true, "result": { "sessionId": "...", "contractVersion": "3.1.0" } }
115
116
  ```
116
117
 
117
118
  Example `applySchemaPatch`:
@@ -140,7 +141,7 @@ Response:
140
141
  "ok": true,
141
142
  "result": {
142
143
  "success": true,
143
- "session": { "sessionId": "...", "contractVersion": "3.0.0" },
144
+ "session": { "sessionId": "...", "contractVersion": "3.1.0" },
144
145
  "summary": { "itemCount": 3 }
145
146
  }
146
147
  }
@@ -32,6 +32,13 @@ interface ApplySchemaPatchInput {
32
32
  /** When set, a revision is recorded after a successful patch. */
33
33
  commitMessage?: string;
34
34
  }
35
+ /** Result of {@link RSToolAgent.restoreOrder}. */
36
+ interface RestoreOrderResult {
37
+ /** Constituent ids in the restored declaration order. */
38
+ orderedIds: number[];
39
+ /** Aliases in the same order as {@link orderedIds}. */
40
+ orderedAliases: string[];
41
+ }
35
42
  /** Compact view of one constituent in a session summary. */
36
43
  interface SessionSummaryItem {
37
44
  id: number;
@@ -60,5 +67,5 @@ interface ApplySchemaPatchResult extends ApplyConstituentsResult {
60
67
  revision?: SessionRevision;
61
68
  }
62
69
  //#endregion
63
- export { SessionStateResult as a, SessionStateDetail as i, ApplySchemaPatchInput as n, SessionSummary as o, ApplySchemaPatchResult as r, SessionSummaryItem as s, AgentConstituentaPatch as t };
64
- //# sourceMappingURL=agent-workflow-D22FeODL.d.ts.map
70
+ export { SessionStateDetail as a, SessionSummaryItem as c, RestoreOrderResult as i, ApplySchemaPatchInput as n, SessionStateResult as o, ApplySchemaPatchResult as r, SessionSummary as s, AgentConstituentaPatch as t };
71
+ //# sourceMappingURL=agent-workflow-BTwrxOoX.d.ts.map
@@ -45,10 +45,12 @@ function expressionForCstDiagnostic(cst, diagnostic) {
45
45
  case RSDiagnosticCode.schemaMissingTerm: return cst.term_resolved;
46
46
  case RSDiagnosticCode.schemaMissingConvention: return cst.convention;
47
47
  case RSDiagnosticCode.schemaTypeMismatch: return cst.typification_manual;
48
+ case RSDiagnosticCode.schemaDependencyCycle:
49
+ case RSDiagnosticCode.schemaFormalDuplicate: return cst.definition_formal;
48
50
  default: return cst.definition_formal;
49
51
  }
50
52
  }
51
53
  //#endregion
52
54
  export { getDiagnosticSeverity as a, getDiagnosticName as i, expandCstDiagnostic as n, modelStatusDiagnostic as o, expressionDiagnostic as r, DiagnosticKind as t };
53
55
 
54
- //# sourceMappingURL=diagnostic-assembly-DRunIcKQ.js.map
56
+ //# sourceMappingURL=diagnostic-assembly-B-6vIA5I.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostic-assembly-DRunIcKQ.js","names":[],"sources":["../src/mappers/diagnostic-assembly.ts"],"sourcesContent":["import {\n type Constituenta,\n type CstDiagnostic,\n DiagnosticKind,\n modelStatusCstDiagnostic,\n RSDiagnosticCode\n} from '@rsconcept/domain/library';\nimport { EvalStatus } from '@rsconcept/domain/library/rsmodel';\nimport { isCritical, RSErrorCode, type RSErrorDescription } from '@rsconcept/domain/rslang/error';\n\nexport { DiagnosticKind, RSDiagnosticCode };\n\n/** Severity of a {@link Diagnostic}. */\nexport type DiagnosticSeverity = 'error' | 'warning';\n\n/** Agent-facing diagnostic with redundant fields for autonomous repair. */\nexport interface Diagnostic extends CstDiagnostic {\n name: string;\n severity: DiagnosticSeverity;\n constituentId?: number;\n alias?: string;\n expression: string;\n from: number;\n to: number;\n}\n\n/** Context for attributing a {@link Diagnostic} to a constituent. */\nexport interface DiagnosticTarget {\n constituentId?: number;\n alias?: string;\n}\n\nconst DIAGNOSTIC_NAMES: ReadonlyMap<number, string> = new Map([\n ...Object.entries(RSErrorCode).map(([name, code]) => [code, name] as const),\n ...Object.entries(RSDiagnosticCode).map(([name, code]) => [code, name] as const)\n]);\n\nexport function getDiagnosticName(code: number): string {\n return DIAGNOSTIC_NAMES.get(code) ?? `0x${code.toString(16).toUpperCase()}`;\n}\n\nexport function getDiagnosticSeverity(code: number): DiagnosticSeverity {\n return isCritical(code as RSErrorCode) ? 'error' : 'warning';\n}\n\nexport function expandCstDiagnostic(cst: Constituenta, diagnostic: CstDiagnostic): Diagnostic {\n const expression = expressionForCstDiagnostic(cst, diagnostic);\n return {\n ...diagnostic,\n name: getDiagnosticName(diagnostic.code),\n severity: getDiagnosticSeverity(diagnostic.code),\n constituentId: cst.id,\n alias: cst.alias,\n expression,\n from: 0,\n to: diagnostic.kind === DiagnosticKind.MODEL ? 0 : Math.max(expression.length, 1)\n };\n}\n\nexport function expressionDiagnostic(\n error: RSErrorDescription,\n expression: string,\n target?: DiagnosticTarget\n): Diagnostic {\n return {\n kind: DiagnosticKind.EXPRESSION,\n code: error.code,\n name: getDiagnosticName(error.code),\n severity: getDiagnosticSeverity(error.code),\n constituentId: target?.constituentId,\n alias: target?.alias,\n expression,\n from: error.from,\n to: error.to,\n ...(error.params ? { params: error.params } : {})\n };\n}\n\nexport function modelStatusDiagnostic(status: EvalStatus, cst: Constituenta): Diagnostic | null {\n const base = modelStatusCstDiagnostic(status, cst.cst_type);\n return base ? expandCstDiagnostic(cst, base) : null;\n}\n\nfunction expressionForCstDiagnostic(cst: Constituenta, diagnostic: CstDiagnostic): string {\n switch (diagnostic.code) {\n case RSDiagnosticCode.schemaHomonym:\n case RSDiagnosticCode.schemaMissingTerm:\n return cst.term_resolved;\n case RSDiagnosticCode.schemaMissingConvention:\n return cst.convention;\n case RSDiagnosticCode.schemaTypeMismatch:\n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B,YAAmC;CACxF,QAAQ,WAAW,MAAnB;EACE,KAAK,iBAAiB;EACtB,KAAK,iBAAiB,mBACpB,OAAO,IAAI;EACb,KAAK,iBAAiB,yBACpB,OAAO,IAAI;EACb,KAAK,iBAAiB,oBACpB,OAAO,IAAI;EACb,SACE,OAAO,IAAI;CACf;AACF"}
1
+ {"version":3,"file":"diagnostic-assembly-B-6vIA5I.js","names":[],"sources":["../src/mappers/diagnostic-assembly.ts"],"sourcesContent":["import {\n type Constituenta,\n type CstDiagnostic,\n DiagnosticKind,\n modelStatusCstDiagnostic,\n RSDiagnosticCode\n} from '@rsconcept/domain/library';\nimport { EvalStatus } from '@rsconcept/domain/library/rsmodel';\nimport { isCritical, RSErrorCode, type RSErrorDescription } from '@rsconcept/domain/rslang/error';\n\nexport { DiagnosticKind, RSDiagnosticCode };\n\n/** Severity of a {@link Diagnostic}. */\nexport type DiagnosticSeverity = 'error' | 'warning';\n\n/** Agent-facing diagnostic with redundant fields for autonomous repair. */\nexport interface Diagnostic extends CstDiagnostic {\n name: string;\n severity: DiagnosticSeverity;\n constituentId?: number;\n alias?: string;\n expression: string;\n from: number;\n to: number;\n}\n\n/** Context for attributing a {@link Diagnostic} to a constituent. */\nexport interface DiagnosticTarget {\n constituentId?: number;\n alias?: string;\n}\n\nconst DIAGNOSTIC_NAMES: ReadonlyMap<number, string> = new Map([\n ...Object.entries(RSErrorCode).map(([name, code]) => [code, name] as const),\n ...Object.entries(RSDiagnosticCode).map(([name, code]) => [code, name] as const)\n]);\n\nexport function getDiagnosticName(code: number): string {\n return DIAGNOSTIC_NAMES.get(code) ?? `0x${code.toString(16).toUpperCase()}`;\n}\n\nexport function getDiagnosticSeverity(code: number): DiagnosticSeverity {\n return isCritical(code as RSErrorCode) ? 'error' : 'warning';\n}\n\nexport function expandCstDiagnostic(cst: Constituenta, diagnostic: CstDiagnostic): Diagnostic {\n const expression = expressionForCstDiagnostic(cst, diagnostic);\n return {\n ...diagnostic,\n name: getDiagnosticName(diagnostic.code),\n severity: getDiagnosticSeverity(diagnostic.code),\n constituentId: cst.id,\n alias: cst.alias,\n expression,\n from: 0,\n to: diagnostic.kind === DiagnosticKind.MODEL ? 0 : Math.max(expression.length, 1)\n };\n}\n\nexport function expressionDiagnostic(\n error: RSErrorDescription,\n expression: string,\n target?: DiagnosticTarget\n): Diagnostic {\n return {\n kind: DiagnosticKind.EXPRESSION,\n code: error.code,\n name: getDiagnosticName(error.code),\n severity: getDiagnosticSeverity(error.code),\n constituentId: target?.constituentId,\n alias: target?.alias,\n expression,\n from: error.from,\n to: error.to,\n ...(error.params ? { params: error.params } : {})\n };\n}\n\nexport function modelStatusDiagnostic(status: EvalStatus, cst: Constituenta): Diagnostic | null {\n const base = modelStatusCstDiagnostic(status, cst.cst_type);\n return base ? expandCstDiagnostic(cst, base) : null;\n}\n\nfunction expressionForCstDiagnostic(cst: Constituenta, diagnostic: CstDiagnostic): string {\n switch (diagnostic.code) {\n case RSDiagnosticCode.schemaHomonym:\n case RSDiagnosticCode.schemaMissingTerm:\n return cst.term_resolved;\n case RSDiagnosticCode.schemaMissingConvention:\n return cst.convention;\n case RSDiagnosticCode.schemaTypeMismatch:\n return cst.typification_manual;\n case RSDiagnosticCode.schemaDependencyCycle:\n case RSDiagnosticCode.schemaFormalDuplicate:\n return cst.definition_formal;\n default:\n return cst.definition_formal;\n }\n}\n"],"mappings":";;;AAgCA,MAAM,mBAAgD,IAAI,IAAI,CAC5D,GAAG,OAAO,QAAQ,WAAW,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,MAAM,IAAI,CAAU,GAC1E,GAAG,OAAO,QAAQ,gBAAgB,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,MAAM,IAAI,CAAU,CACjF,CAAC;AAED,SAAgB,kBAAkB,MAAsB;CACtD,OAAO,iBAAiB,IAAI,IAAI,KAAK,KAAK,KAAK,SAAS,EAAE,CAAC,CAAC,YAAY;AAC1E;AAEA,SAAgB,sBAAsB,MAAkC;CACtE,OAAO,WAAW,IAAmB,IAAI,UAAU;AACrD;AAEA,SAAgB,oBAAoB,KAAmB,YAAuC;CAC5F,MAAM,aAAa,2BAA2B,KAAK,UAAU;CAC7D,OAAO;EACL,GAAG;EACH,MAAM,kBAAkB,WAAW,IAAI;EACvC,UAAU,sBAAsB,WAAW,IAAI;EAC/C,eAAe,IAAI;EACnB,OAAO,IAAI;EACX;EACA,MAAM;EACN,IAAI,WAAW,SAAS,eAAe,QAAQ,IAAI,KAAK,IAAI,WAAW,QAAQ,CAAC;CAClF;AACF;AAEA,SAAgB,qBACd,OACA,YACA,QACY;CACZ,OAAO;EACL,MAAM,eAAe;EACrB,MAAM,MAAM;EACZ,MAAM,kBAAkB,MAAM,IAAI;EAClC,UAAU,sBAAsB,MAAM,IAAI;EAC1C,eAAe,QAAQ;EACvB,OAAO,QAAQ;EACf;EACA,MAAM,MAAM;EACZ,IAAI,MAAM;EACV,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;CACjD;AACF;AAEA,SAAgB,sBAAsB,QAAoB,KAAsC;CAC9F,MAAM,OAAO,yBAAyB,QAAQ,IAAI,QAAQ;CAC1D,OAAO,OAAO,oBAAoB,KAAK,IAAI,IAAI;AACjD;AAEA,SAAS,2BAA2B,KAAmB,YAAmC;CACxF,QAAQ,WAAW,MAAnB;EACE,KAAK,iBAAiB;EACtB,KAAK,iBAAiB,mBACpB,OAAO,IAAI;EACb,KAAK,iBAAiB,yBACpB,OAAO,IAAI;EACb,KAAK,iBAAiB,oBACpB,OAAO,IAAI;EACb,KAAK,iBAAiB;EACtB,KAAK,iBAAiB,uBACpB,OAAO,IAAI;EACb,SACE,OAAO,IAAI;CACf;AACF"}
package/dist/index.d.ts CHANGED
@@ -4,10 +4,10 @@ import { n as AnalyzeExpressionInput, t as AnalysisResult } from "./analysis-DA4
4
4
  import { o as ConstituentaDraft, s as ConstituentaState } from "./constituenta-QY5w1x91.js";
5
5
  import { a as SetConstituentaValueInput, i as SessionModelState, n as ModelValueState, r as RecalculateModelResult, s as SetModelValuesInput } from "./model-value-BUhr2IjA.js";
6
6
  import { n as SessionRevision, r as SessionState, t as SessionHandle } from "./session-CI4rLYby.js";
7
- import { a as SessionStateResult, i as SessionStateDetail, n as ApplySchemaPatchInput, o as SessionSummary, r as ApplySchemaPatchResult, s as SessionSummaryItem, t as AgentConstituentaPatch } from "./agent-workflow-D22FeODL.js";
7
+ import { a as SessionStateDetail, c as SessionSummaryItem, n as ApplySchemaPatchInput, o as SessionStateResult, r as ApplySchemaPatchResult, s as SessionSummary, t as AgentConstituentaPatch } from "./agent-workflow-BTwrxOoX.js";
8
8
  import { i as EvaluationResult, r as EvaluateInput } from "./evaluation-Cd4S7-3t.js";
9
- import { a as ExportPortalInput, c as PortalExportKind, d as PortalModelImportData, f as PortalRsformDetails, h as PortalTermForm, i as ExportFormat, l as PORTAL_JSON_CONTRACT_VERSION, m as PortalSchemaImportData, n as RSToolAgentContract, o as ExportPortalResult, p as PortalSchemaConstituenta, r as RSToolAgentOptions, s as ImportDataKind, t as CONTRACT_VERSION, u as PortalImportMetadata } from "./tool-contract-sQfr-DYD.js";
10
- import { t as RSToolAgent } from "./rstool-agent-BGQAzFly.js";
9
+ import { a as ExportPortalInput, c as PortalExportKind, d as PortalModelImportData, f as PortalRsformDetails, h as PortalTermForm, i as ExportFormat, l as PORTAL_JSON_CONTRACT_VERSION, m as PortalSchemaImportData, n as RSToolAgentContract, o as ExportPortalResult, p as PortalSchemaConstituenta, r as RSToolAgentOptions, s as ImportDataKind, t as CONTRACT_VERSION, u as PortalImportMetadata } from "./tool-contract-BUaDRHoO.js";
10
+ import { t as RSToolAgent } from "./rstool-agent-BrAFJcoE.js";
11
11
  import { DomainAnalysisLike, DomainErrorLike, toDiagnostic, toPublicAnalysis } from "./mappers/types.js";
12
12
  import { RSToolWrapperClient, RSToolWrapperClientOptions, WrapperResponse } from "./wrapper/client.js";
13
13
  export { type AgentConstituentaPatch, type AnalysisResult, type AnalyzeExpressionInput, type ApplySchemaPatchInput, type ApplySchemaPatchResult, type BasicBinding, CONTRACT_VERSION, type ConstituentaDraft, type ConstituentaState, type CstDiagnostic, CstType, type Diagnostic, DiagnosticKind, type DiagnosticSeverity, type DomainAnalysisLike, type DomainErrorLike, EvalStatus, type EvaluateInput, type EvaluationResult, type ExportFormat, type ExportPortalInput, type ExportPortalResult, type ImportDataKind, type ListDiagnosticsFilters, type ModelValueState, PORTAL_JSON_CONTRACT_VERSION, type PortalExportKind, type PortalImportMetadata, type PortalModelImportData, type PortalRsformDetails, type PortalSchemaConstituenta, type PortalSchemaImportData, type PortalTermForm, RSDiagnosticCode, RSErrorCode, RSToolAgent, type RSToolAgentContract, type RSToolAgentOptions, type RSToolValue, RSToolWrapperClient, type RSToolWrapperClientOptions, type RecalculateModelResult, type SessionHandle, type SessionModelState, type SessionRevision, type SessionState, type SessionStateDetail, type SessionStateResult, type SessionSummary, type SessionSummaryItem, type SetConstituentaValueInput, type SetModelValuesInput, ValueClass, type WrapperResponse, toDiagnostic, toPublicAnalysis };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { toDiagnostic, toPublicAnalysis } from "./mappers/types.js";
2
2
  import { CstType, EvalStatus, RSErrorCode, ValueClass } from "./models/common.js";
3
3
  import { DiagnosticKind, RSDiagnosticCode } from "./models/diagnostic.js";
4
- import { r as PORTAL_JSON_CONTRACT_VERSION, t as RSToolAgent } from "./models-B255GaEC.js";
4
+ import { r as PORTAL_JSON_CONTRACT_VERSION, t as RSToolAgent } from "./models-LMyDB0md.js";
5
5
  import { CONTRACT_VERSION } from "./models/tool-contract.js";
6
6
  import { RSToolWrapperClient } from "./wrapper/client.js";
7
7
  export { CONTRACT_VERSION, CstType, DiagnosticKind, EvalStatus, PORTAL_JSON_CONTRACT_VERSION, RSDiagnosticCode, RSErrorCode, RSToolAgent, RSToolWrapperClient, ValueClass, toDiagnostic, toPublicAnalysis };
@@ -1,2 +1,128 @@
1
- import { t as ModelAdapter } from "../model-adapter-D-YmIvQW.js";
1
+ import { r as expressionDiagnostic, t as DiagnosticKind } from "../diagnostic-assembly-B-6vIA5I.js";
2
+ import { t as buildRSFormFromSession } from "../rsform-builder-DKwZfJvN.js";
3
+ import { EvalStatus } from "@rsconcept/domain/library/rsmodel";
4
+ import { isBaseSet } from "@rsconcept/domain/library/rsform-api";
5
+ import { isInferrable, isInterpretable, toBasicBinding, validateBasicBindingData, validateValueData } from "@rsconcept/domain/library/rsmodel-api";
6
+ import { RSEngine } from "@rsconcept/domain/library/rsengine";
7
+ //#region src/mappers/model-adapter.ts
8
+ const SESSION_MODEL_ID = 0;
9
+ var ModelAdapter = class {
10
+ async setConstituentaValue(session, input) {
11
+ this.validateSetInput(session, input);
12
+ const engine = this.createEngine(session);
13
+ const frontendType = session.items.find((item) => item.id === input.target).cstType;
14
+ if (isBaseSet(frontendType)) {
15
+ const binding = toBasicBinding(input.value);
16
+ await engine.setBasicValue(input.target, binding);
17
+ } else await engine.setStructureValue(input.target, input.value);
18
+ session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
19
+ return structuredClone(session.model);
20
+ }
21
+ async setConstituentaValues(session, input) {
22
+ for (const item of input.items) await this.setConstituentaValue(session, item);
23
+ return structuredClone(session.model);
24
+ }
25
+ async clearConstituentaValues(session, ids) {
26
+ const engine = this.createEngine(session);
27
+ for (const id of ids) {
28
+ await engine.resetValue(id);
29
+ session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
30
+ }
31
+ return structuredClone(session.model);
32
+ }
33
+ evaluateExpression(session, expression, cstType) {
34
+ const result = this.createEngine(session).evaluateExpression(expression, cstType);
35
+ const status = result.value === null ? result.errors.length > 0 ? EvalStatus.EVAL_FAIL : EvalStatus.EMPTY : EvalStatus.HAS_DATA;
36
+ return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status, expression);
37
+ }
38
+ evaluateConstituenta(session, constituentId) {
39
+ const cst = session.items.find((item) => item.id === constituentId);
40
+ if (!cst) throw new Error(`Unknown constituent: ${constituentId}`);
41
+ const engine = this.createEngine(session);
42
+ const result = engine.calculateCst(constituentId);
43
+ const status = engine.getCstStatus(constituentId);
44
+ return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status, cst.definitionFormal, {
45
+ constituentId: cst.id,
46
+ alias: cst.alias
47
+ });
48
+ }
49
+ recalculateModel(session) {
50
+ const engine = this.createEngine(session);
51
+ engine.recalculateAll();
52
+ return { items: session.items.map((item) => ({
53
+ id: item.id,
54
+ alias: item.alias,
55
+ value: engine.getCstValue(item.id),
56
+ status: engine.getCstStatus(item.id)
57
+ })) };
58
+ }
59
+ createEngine(session) {
60
+ const schema = buildRSFormFromSession(session);
61
+ const model = buildRSModelFromSession(session);
62
+ const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));
63
+ engine.loadData(schema, model);
64
+ return engine;
65
+ }
66
+ validateSetInput(session, input) {
67
+ const cst = session.items.find((item) => item.id === input.target);
68
+ if (!cst) throw new Error(`Unknown constituent: ${input.target}`);
69
+ const frontendType = cst.cstType;
70
+ if (!isInterpretable(frontendType)) throw new Error(`Constituent ${cst.alias} is not interpretable`);
71
+ if (isInferrable(frontendType)) throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);
72
+ if (isBaseSet(frontendType)) {
73
+ if (!validateBasicBindingData(input.value)) throw new Error(`Invalid basic binding for ${cst.alias}`);
74
+ return;
75
+ }
76
+ if (!validateValueData(input.value)) throw new Error(`Invalid structured value for ${cst.alias}`);
77
+ }
78
+ };
79
+ function createInMemoryServices(session) {
80
+ return {
81
+ setCstValue: async ({ data }) => {
82
+ for (const item of data) {
83
+ const entry = {
84
+ id: item.target,
85
+ type: item.type,
86
+ value: item.data
87
+ };
88
+ const index = session.model.items.findIndex((existing) => existing.id === item.target);
89
+ if (index === -1) session.model.items.push(entry);
90
+ else session.model.items[index] = entry;
91
+ }
92
+ },
93
+ clearValues: async ({ data }) => {
94
+ const ids = new Set(data.items);
95
+ session.model.items = session.model.items.filter((item) => !ids.has(item.id));
96
+ }
97
+ };
98
+ }
99
+ function buildRSModelFromSession(session) {
100
+ return {
101
+ id: SESSION_MODEL_ID,
102
+ schema: 0,
103
+ editors: [],
104
+ items: session.model.items.map((item) => ({
105
+ id: item.id,
106
+ type: item.type,
107
+ value: item.value
108
+ }))
109
+ };
110
+ }
111
+ function toPublicEvaluationResult(value, errors, iterations, cacheHits, status, expression, target) {
112
+ const diagnostics = errors.map((error) => ({
113
+ ...expressionDiagnostic(error, expression, target),
114
+ kind: DiagnosticKind.MODEL
115
+ }));
116
+ return {
117
+ success: diagnostics.length === 0 && value !== null,
118
+ value,
119
+ status,
120
+ iterations,
121
+ cacheHits,
122
+ diagnostics
123
+ };
124
+ }
125
+ //#endregion
2
126
  export { ModelAdapter };
127
+
128
+ //# sourceMappingURL=model-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-adapter.js","names":[],"sources":["../../src/mappers/model-adapter.ts"],"sourcesContent":["import { DiagnosticKind, expressionDiagnostic } from './diagnostic-assembly';\nimport { type RSErrorDescription, type Value } from '@rsconcept/domain/rslang';\nimport { isBaseSet } from '@rsconcept/domain/library/rsform-api';\nimport { CstType, type RSForm } from '@rsconcept/domain/library/rsform';\nimport { RSEngine, type RSEngineServices } from '@rsconcept/domain/library/rsengine';\nimport { type BasicBinding, EvalStatus, type RSModel } from '@rsconcept/domain/library/rsmodel';\nimport {\n isInferrable,\n isInterpretable,\n toBasicBinding,\n validateBasicBindingData,\n validateValueData\n} from '@rsconcept/domain/library/rsmodel-api';\n\nimport {\n type EvaluationResult,\n type RecalculateModelResult,\n type SessionModelState,\n type SessionState,\n type SetConstituentaValueInput\n} from '../models';\nimport { buildRSFormFromSession } from './rsform-builder';\n\nconst SESSION_MODEL_ID = 0;\n\nexport class ModelAdapter {\n public async setConstituentaValue(\n session: SessionState,\n input: SetConstituentaValueInput\n ): Promise<SessionModelState> {\n this.validateSetInput(session, input);\n const engine = this.createEngine(session);\n const cst = session.items.find(item => item.id === input.target)!;\n const frontendType = cst.cstType;\n\n if (isBaseSet(frontendType)) {\n const binding = toBasicBinding(input.value as Record<string | number, string>);\n await engine.setBasicValue(input.target, binding);\n } else {\n await engine.setStructureValue(input.target, input.value as Value);\n }\n session.updatedAt = new Date().toISOString();\n return structuredClone(session.model);\n }\n\n public async setConstituentaValues(\n session: SessionState,\n input: { items: SetConstituentaValueInput[] }\n ): Promise<SessionModelState> {\n for (const item of input.items) {\n await this.setConstituentaValue(session, item);\n }\n return structuredClone(session.model);\n }\n\n public async clearConstituentaValues(session: SessionState, ids: number[]): Promise<SessionModelState> {\n const engine = this.createEngine(session);\n for (const id of ids) {\n await engine.resetValue(id);\n session.updatedAt = new Date().toISOString();\n }\n return structuredClone(session.model);\n }\n\n public evaluateExpression(session: SessionState, expression: string, cstType: CstType): EvaluationResult {\n const engine = this.createEngine(session);\n const result = engine.evaluateExpression(expression, cstType);\n const status =\n result.value === null\n ? result.errors.length > 0\n ? EvalStatus.EVAL_FAIL\n : EvalStatus.EMPTY\n : EvalStatus.HAS_DATA;\n return toPublicEvaluationResult(\n result.value,\n result.errors,\n result.iterations,\n result.cacheHits,\n status,\n expression\n );\n }\n\n public evaluateConstituenta(session: SessionState, constituentId: number): EvaluationResult {\n const cst = session.items.find(item => item.id === constituentId);\n if (!cst) {\n throw new Error(`Unknown constituent: ${constituentId}`);\n }\n const engine = this.createEngine(session);\n const result = engine.calculateCst(constituentId);\n const status = engine.getCstStatus(constituentId);\n return toPublicEvaluationResult(\n result.value,\n result.errors,\n result.iterations,\n result.cacheHits,\n status,\n cst.definitionFormal,\n { constituentId: cst.id, alias: cst.alias }\n );\n }\n\n public recalculateModel(session: SessionState): RecalculateModelResult {\n const engine = this.createEngine(session);\n engine.recalculateAll();\n const items = session.items.map(item => ({\n id: item.id,\n alias: item.alias,\n value: engine.getCstValue(item.id) as number | number[] | null,\n status: engine.getCstStatus(item.id)\n }));\n return { items };\n }\n\n public createEngine(session: SessionState): RSEngine {\n const schema = buildRSFormFromSession(session);\n const model = buildRSModelFromSession(session);\n const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));\n engine.loadData(schema, model);\n return engine;\n }\n\n private validateSetInput(session: SessionState, input: SetConstituentaValueInput): void {\n const cst = session.items.find(item => item.id === input.target);\n if (!cst) {\n throw new Error(`Unknown constituent: ${input.target}`);\n }\n const frontendType = cst.cstType;\n if (!isInterpretable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is not interpretable`);\n }\n if (isInferrable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);\n }\n if (isBaseSet(frontendType)) {\n if (!validateBasicBindingData(input.value)) {\n throw new Error(`Invalid basic binding for ${cst.alias}`);\n }\n return;\n }\n if (!validateValueData(input.value)) {\n throw new Error(`Invalid structured value for ${cst.alias}`);\n }\n }\n}\n\nfunction createInMemoryServices(session: SessionState): RSEngineServices {\n return {\n setCstValue: async ({ data }) => {\n for (const item of data) {\n const entry = {\n id: item.target,\n type: item.type,\n value: item.data as Value | BasicBinding\n };\n const index = session.model.items.findIndex(existing => existing.id === item.target);\n if (index === -1) {\n session.model.items.push(entry);\n } else {\n session.model.items[index] = entry;\n }\n }\n },\n clearValues: async ({ data }) => {\n const ids = new Set(data.items);\n session.model.items = session.model.items.filter(item => !ids.has(item.id));\n }\n };\n}\n\nfunction buildRSModelFromSession(session: SessionState): RSModel {\n return {\n id: SESSION_MODEL_ID,\n schema: 0,\n editors: [],\n items: session.model.items.map(item => ({\n id: item.id,\n type: item.type,\n value: item.value as Value | BasicBinding\n }))\n } as unknown as RSModel;\n}\n\nfunction toPublicEvaluationResult(\n value: Value | null,\n errors: RSErrorDescription[],\n iterations: number,\n cacheHits: number,\n status: EvalStatus,\n expression: string,\n target?: { constituentId?: number; alias?: string }\n): EvaluationResult {\n const diagnostics = errors.map(error => ({\n ...expressionDiagnostic(error, expression, target),\n kind: DiagnosticKind.MODEL\n }));\n return {\n success: diagnostics.length === 0 && value !== null,\n value: value as EvaluationResult['value'],\n status,\n iterations,\n cacheHits,\n diagnostics\n };\n}\n"],"mappings":";;;;;;;AAuBA,MAAM,mBAAmB;AAEzB,IAAa,eAAb,MAA0B;CACxB,MAAa,qBACX,SACA,OAC4B;EAC5B,KAAK,iBAAiB,SAAS,KAAK;EACpC,MAAM,SAAS,KAAK,aAAa,OAAO;EAExC,MAAM,eADM,QAAQ,MAAM,MAAK,SAAQ,KAAK,OAAO,MAAM,MACpC,CAAA,CAAI;EAEzB,IAAI,UAAU,YAAY,GAAG;GAC3B,MAAM,UAAU,eAAe,MAAM,KAAwC;GAC7E,MAAM,OAAO,cAAc,MAAM,QAAQ,OAAO;EAClD,OACE,MAAM,OAAO,kBAAkB,MAAM,QAAQ,MAAM,KAAc;EAEnE,QAAQ,6BAAY,IAAI,KAAK,EAAC,CAAC,YAAY;EAC3C,OAAO,gBAAgB,QAAQ,KAAK;CACtC;CAEA,MAAa,sBACX,SACA,OAC4B;EAC5B,KAAK,MAAM,QAAQ,MAAM,OACvB,MAAM,KAAK,qBAAqB,SAAS,IAAI;EAE/C,OAAO,gBAAgB,QAAQ,KAAK;CACtC;CAEA,MAAa,wBAAwB,SAAuB,KAA2C;EACrG,MAAM,SAAS,KAAK,aAAa,OAAO;EACxC,KAAK,MAAM,MAAM,KAAK;GACpB,MAAM,OAAO,WAAW,EAAE;GAC1B,QAAQ,6BAAY,IAAI,KAAK,EAAC,CAAC,YAAY;EAC7C;EACA,OAAO,gBAAgB,QAAQ,KAAK;CACtC;CAEA,mBAA0B,SAAuB,YAAoB,SAAoC;EAEvG,MAAM,SADS,KAAK,aAAa,OAClB,CAAA,CAAO,mBAAmB,YAAY,OAAO;EAC5D,MAAM,SACJ,OAAO,UAAU,OACb,OAAO,OAAO,SAAS,IACrB,WAAW,YACX,WAAW,QACb,WAAW;EACjB,OAAO,yBACL,OAAO,OACP,OAAO,QACP,OAAO,YACP,OAAO,WACP,QACA,UACF;CACF;CAEA,qBA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ysis: AnalysisResult): ConstituentaState;
15
15
  toPseudoRSFormState(session: SessionState, analyzer: RSLangAnalyzer): Pick<RSForm, 'items' | 'cstByAlias' | 'analyzer'>;
16
- private buildAnalyzer;
16
+ /**
17
+ * Schema view for analysis: session items with the draft expression merged in so the
18
+ * dependency graph (and cycle diagnostics) reflect the expression under check.
19
+ */
20
+ private toAnalysisSchema;
17
21
  }
18
22
  //#endregion
19
23
  export { SchemaAdapter };
@@ -1,12 +1,10 @@
1
1
  import { toPublicAnalysis } from "./types.js";
2
- import { CstType } from "@rsconcept/domain/library/rsform";
3
- import { RSLangAnalyzer } from "@rsconcept/domain/rslang";
2
+ import { t as buildRSFormFromSession } from "../rsform-builder-DKwZfJvN.js";
4
3
  import { getAnalysisFor } from "@rsconcept/domain/library/rsform-api";
5
4
  //#region src/mappers/schema-adapter.ts
6
5
  var SchemaAdapter = class {
7
6
  analyzeAgainstSession(session, draft) {
8
- const analyzer = this.buildAnalyzer(session);
9
- const schema = this.toPseudoRSFormState(session, analyzer);
7
+ const schema = this.toAnalysisSchema(session, draft);
10
8
  const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema, draft.alias);
11
9
  const target = {
12
10
  constituentId: draft.id,
@@ -45,13 +43,48 @@ var SchemaAdapter = class {
45
43
  analyzer
46
44
  };
47
45
  }
48
- buildAnalyzer(session) {
49
- const analyzer = new RSLangAnalyzer();
50
- for (const item of session.items) {
51
- if (item.cstType === CstType.BASE) analyzer.addBase(item.alias);
52
- analyzer.setGlobal(item.alias, item.analysis.type, item.analysis.valueClass);
53
- }
54
- return analyzer;
46
+ /**
47
+ * Schema view for analysis: session items with the draft expression merged in so the
48
+ * dependency graph (and cycle diagnostics) reflect the expression under check.
49
+ */
50
+ toAnalysisSchema(session, draft) {
51
+ const items = session.items.map((item) => {
52
+ if (item.id !== draft.id) return item;
53
+ return {
54
+ ...item,
55
+ alias: draft.alias,
56
+ cstType: draft.cstType,
57
+ definitionFormal: draft.definitionFormal,
58
+ term: draft.term ?? item.term,
59
+ definitionText: draft.definitionText ?? item.definitionText,
60
+ convention: draft.convention ?? item.convention,
61
+ analysis: {
62
+ ...item.analysis,
63
+ success: false,
64
+ type: null,
65
+ valueClass: null
66
+ }
67
+ };
68
+ });
69
+ if (!items.some((item) => item.id === draft.id)) items.push({
70
+ id: draft.id,
71
+ alias: draft.alias,
72
+ cstType: draft.cstType,
73
+ definitionFormal: draft.definitionFormal,
74
+ term: draft.term ?? "",
75
+ definitionText: draft.definitionText ?? "",
76
+ convention: draft.convention ?? "",
77
+ analysis: {
78
+ success: false,
79
+ type: null,
80
+ valueClass: null,
81
+ diagnostics: []
82
+ }
83
+ });
84
+ return buildRSFormFromSession({
85
+ ...session,
86
+ items
87
+ });
55
88
  }
56
89
  };
57
90
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"schema-adapter.js","names":[],"sources":["../../src/mappers/schema-adapter.ts"],"sourcesContent":["import { RSLangAnalyzer, type AnalysisFull, type ValueClass } from '@rsconcept/domain/rslang';\nimport { getAnalysisFor } from '@rsconcept/domain/library/rsform-api';\nimport { CstType, type RSForm } from '@rsconcept/domain/library/rsform';\n\nimport {\n type AnalysisResult,\n type ConstituentaDraft,\n type ConstituentaState,\n type Diagnostic,\n type SessionState\n} from '../models';\nimport { toPublicAnalysis } from './types';\n\nexport class SchemaAdapter {\n public analyzeAgainstSession(\n session: SessionState,\n draft: ConstituentaDraft\n ): { result: AnalysisResult; diagnostics: Diagnostic[] } {\n const analyzer = this.buildAnalyzer(session);\n const schema = this.toPseudoRSFormState(session, analyzer);\n const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema as unknown as RSForm, draft.alias);\n const target = { constituentId: draft.id, alias: draft.alias };\n const result = toPublicAnalysis(\n {\n success: analysis.success,\n type: analysis.type as Record<string, unknown> | null,\n valueClass: analysis.valueClass,\n errors: analysis.errors\n },\n draft.definitionFormal,\n target\n );\n return {\n result,\n diagnostics: result.diagnostics\n };\n }\n\n public mergeStateWithDraft(\n session: SessionState,\n draft: ConstituentaDraft,\n analysis: AnalysisResult\n ): ConstituentaState {\n const state: ConstituentaState = {\n ...draft,\n term: draft.term ?? '',\n definitionText: draft.definitionText ?? '',\n convention: draft.convention ?? '',\n analysis\n };\n const index = session.items.findIndex(item => item.id === draft.id);\n if (index === -1) {\n session.items.push(state);\n } else {\n session.items[index] = state;\n }\n session.updatedAt = new Date().toISOString();\n return state;\n }\n\n public toPseudoRSFormState(\n session: SessionState,\n analyzer: RSLangAnalyzer\n ): Pick<RSForm, 'items' | 'cstByAlias' | 'analyzer'> {\n const cstByAlias = new Map(session.items.map(item => [item.alias, item]));\n return {\n items: session.items as unknown as RSForm['items'],\n cstByAlias: cstByAlias as unknown as RSForm['cstByAlias'],\n analyzer\n };\n }\n\n private buildAnalyzer(session: SessionState): RSLangAnalyzer {\n const analyzer = new RSLangAnalyzer();\n for (const item of session.items) {\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(item.alias);\n }\n analyzer.setGlobal(\n item.alias,\n item.analysis.type as AnalysisFull['type'],\n item.analysis.valueClass as ValueClass | null\n );\n }\n return analyzer;\n }\n}\n"],"mappings":";;;;;AAaA,IAAa,gBAAb,MAA2B;CACzB,sBACE,SACA,OACuD;EACvD,MAAM,WAAW,KAAK,cAAc,OAAO;EAC3C,MAAM,SAAS,KAAK,oBAAoB,SAAS,QAAQ;EACzD,MAAM,WAAW,eAAe,MAAM,kBAAkB,MAAM,SAAS,QAA6B,MAAM,KAAK;EAC/G,MAAM,SAAS;GAAE,eAAe,MAAM;GAAI,OAAO,MAAM;EAAM;EAC7D,MAAM,SAAS,iBACb;GACE,SAAS,SAAS;GAClB,MAAM,SAAS;GACf,YAAY,SAAS;GACrB,QAAQ,SAAS;EACnB,GACA,MAAM,kBACN,MACF;EACA,OAAO;GACL;GACA,aAAa,OAAO;EACtB;CACF;CAEA,oBACE,SACA,OACA,UACmB;EACnB,MAAM,QAA2B;GAC/B,GAAG;GACH,MAAM,MAAM,QAAQ;GACpB,gBAAgB,MAAM,kBAAkB;GACxC,YAAY,MAAM,cAAc;GAChC;EACF;EACA,MAAM,QAAQ,QAAQ,MAAM,WAAU,SAAQ,KAAK,OAAO,MAAM,EAAE;EAClE,IAAI,UAAU,IACZ,QAAQ,MAAM,KAAK,KAAK;OAExB,QAAQ,MAAM,SAAS;EAEzB,QAAQ,6BAAY,IAAI,KAAK,EAAC,CAAC,YAAY;EAC3C,OAAO;CACT;CAEA,oBACE,SACA,UACmD;EACnD,MAAM,aAAa,IAAI,IAAI,QAAQ,MAAM,KAAI,SAAQ,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC;EACxE,OAAO;GACL,OAAO,QAAQ;GACH;GACZ;EACF;CACF;CAEA,cAAsB,SAAuC;EAC3D,MAAM,WAAW,IAAI,eAAe;EACpC,KAAK,MAAM,QAAQ,QAAQ,OAAO;GAChC,IAAI,KAAK,YAAY,QAAQ,MAC3B,SAAS,QAAQ,KAAK,KAAK;GAE7B,SAAS,UACP,KAAK,OACL,KAAK,SAAS,MACd,KAAK,SAAS,UAChB;EACF;EACA,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"schema-adapter.js","names":[],"sources":["../../src/mappers/schema-adapter.ts"],"sourcesContent":["import { getAnalysisFor } from '@rsconcept/domain/library/rsform-api';\nimport { type RSForm } from '@rsconcept/domain/library/rsform';\nimport { RSLangAnalyzer } from '@rsconcept/domain/rslang';\n\nimport {\n type AnalysisResult,\n type ConstituentaDraft,\n type ConstituentaState,\n type Diagnostic,\n type SessionState\n} from '../models';\nimport { buildRSFormFromSession } from './rsform-builder';\nimport { toPublicAnalysis } from './types';\n\nexport class SchemaAdapter {\n public analyzeAgainstSession(\n session: SessionState,\n draft: ConstituentaDraft\n ): { result: AnalysisResult; diagnostics: Diagnostic[] } {\n const schema = this.toAnalysisSchema(session, draft);\n const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema, draft.alias);\n const target = { constituentId: draft.id, alias: draft.alias };\n const result = toPublicAnalysis(\n {\n success: analysis.success,\n type: analysis.type as Record<string, unknown> | null,\n valueClass: analysis.valueClass,\n errors: analysis.errors\n },\n draft.definitionFormal,\n target\n );\n return {\n result,\n diagnostics: result.diagnostics\n };\n }\n\n public mergeStateWithDraft(\n session: SessionState,\n draft: ConstituentaDraft,\n analysis: AnalysisResult\n ): ConstituentaState {\n const state: ConstituentaState = {\n ...draft,\n term: draft.term ?? '',\n definitionText: draft.definitionText ?? '',\n convention: draft.convention ?? '',\n analysis\n };\n const index = session.items.findIndex(item => item.id === draft.id);\n if (index === -1) {\n session.items.push(state);\n } else {\n session.items[index] = state;\n }\n session.updatedAt = new Date().toISOString();\n return state;\n }\n\n public toPseudoRSFormState(\n session: SessionState,\n analyzer: RSLangAnalyzer\n ): Pick<RSForm, 'items' | 'cstByAlias' | 'analyzer'> {\n const cstByAlias = new Map(session.items.map(item => [item.alias, item]));\n return {\n items: session.items as unknown as RSForm['items'],\n cstByAlias: cstByAlias as unknown as RSForm['cstByAlias'],\n analyzer\n };\n }\n\n /**\n * Schema view for analysis: session items with the draft expression merged in so the\n * dependency graph (and cycle diagnostics) reflect the expression under check.\n */\n private toAnalysisSchema(session: SessionState, draft: ConstituentaDraft): RSForm {\n const items = session.items.map(item => {\n if (item.id !== draft.id) {\n return item;\n }\n return {\n ...item,\n alias: draft.alias,\n cstType: draft.cstType,\n definitionFormal: draft.definitionFormal,\n term: draft.term ?? item.term,\n definitionText: draft.definitionText ?? item.definitionText,\n convention: draft.convention ?? item.convention,\n // Drop cached type so mutual references surface as untyped → cycle.\n analysis: {\n ...item.analysis,\n success: false,\n type: null,\n valueClass: null\n }\n };\n });\n if (!items.some(item => item.id === draft.id)) {\n items.push({\n id: draft.id,\n alias: draft.alias,\n cstType: draft.cstType,\n definitionFormal: draft.definitionFormal,\n term: draft.term ?? '',\n definitionText: draft.definitionText ?? '',\n convention: draft.convention ?? '',\n analysis: {\n success: false,\n type: null,\n valueClass: null,\n diagnostics: []\n }\n });\n }\n\n return buildRSFormFromSession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,cAAc,KAAK;IAErC,UAAU;KACR,GAAG,KAAK;KACR,SAAS;KACT,MAAM;KACN,YAAY;IACd;GACF;EACF,CAAC;EACD,IAAI,CAAC,MAAM,MAAK,SAAQ,KAAK,OAAO,MAAM,EAAE,GAC1C,MAAM,KAAK;GACT,IAAI,MAAM;GACV,OAAO,MAAM;GACb,SAAS,MAAM;GACf,kBAAkB,MAAM;GACxB,MAAM,MAAM,QAAQ;GACpB,gBAAgB,MAAM,kBAAkB;GACxC,YAAY,MAAM,cAAc;GAChC,UAAU;IACR,SAAS;IACT,MAAM;IACN,YAAY;IACZ,aAAa,CAAC;GAChB;EACF,CAAC;EAGH,OAAO,uBAAuB;GAAE,GAAG;GAAS;EAAM,CAAC;CACrD;AACF"}
@@ -1,4 +1,4 @@
1
- import { r as expressionDiagnostic } from "../diagnostic-assembly-DRunIcKQ.js";
1
+ import { r as expressionDiagnostic } from "../diagnostic-assembly-B-6vIA5I.js";
2
2
  //#region src/mappers/types.ts
3
3
  /** Map a domain parser/semantic error to the public diagnostic shape. */
4
4
  function toDiagnostic(error, expression, target) {
@@ -1,2 +1,2 @@
1
- import { a as SessionStateResult, i as SessionStateDetail, n as ApplySchemaPatchInput, o as SessionSummary, r as ApplySchemaPatchResult, s as SessionSummaryItem, t as AgentConstituentaPatch } from "../agent-workflow-D22FeODL.js";
2
- export { AgentConstituentaPatch, ApplySchemaPatchInput, ApplySchemaPatchResult, SessionStateDetail, SessionStateResult, SessionSummary, SessionSummaryItem };
1
+ import { a as SessionStateDetail, c as SessionSummaryItem, i as RestoreOrderResult, n as ApplySchemaPatchInput, o as SessionStateResult, r as ApplySchemaPatchResult, s as SessionSummary, t as AgentConstituentaPatch } from "../agent-workflow-BTwrxOoX.js";
2
+ export { AgentConstituentaPatch, ApplySchemaPatchInput, ApplySchemaPatchResult, RestoreOrderResult, SessionStateDetail, SessionStateResult, SessionSummary, SessionSummaryItem };
@@ -1,3 +1,3 @@
1
- import { a as getDiagnosticSeverity, i as getDiagnosticName, n as expandCstDiagnostic, o as modelStatusDiagnostic, r as expressionDiagnostic } from "../diagnostic-assembly-DRunIcKQ.js";
1
+ import { a as getDiagnosticSeverity, i as getDiagnosticName, n as expandCstDiagnostic, o as modelStatusDiagnostic, r as expressionDiagnostic } from "../diagnostic-assembly-B-6vIA5I.js";
2
2
  import { DiagnosticKind, RSDiagnosticCode } from "@rsconcept/domain/library";
3
3
  export { DiagnosticKind, RSDiagnosticCode, expandCstDiagnostic, expressionDiagnostic, getDiagnosticName, getDiagnosticSeverity, modelStatusDiagnostic };
@@ -4,8 +4,8 @@ import { n as AnalyzeExpressionInput, t as AnalysisResult } from "../analysis-DA
4
4
  import { i as ApplyConstituentsMode, o as ConstituentaDraft, s as ConstituentaState } from "../constituenta-QY5w1x91.js";
5
5
  import { a as SetConstituentaValueInput, i as SessionModelState, n as ModelValueState, r as RecalculateModelResult, s as SetModelValuesInput } from "../model-value-BUhr2IjA.js";
6
6
  import { n as SessionRevision, r as SessionState, t as SessionHandle } from "../session-CI4rLYby.js";
7
- import { a as SessionStateResult, i as SessionStateDetail, n as ApplySchemaPatchInput, o as SessionSummary, r as ApplySchemaPatchResult, s as SessionSummaryItem, t as AgentConstituentaPatch } from "../agent-workflow-D22FeODL.js";
7
+ import { a as SessionStateDetail, c as SessionSummaryItem, i as RestoreOrderResult, n as ApplySchemaPatchInput, o as SessionStateResult, r as ApplySchemaPatchResult, s as SessionSummary, t as AgentConstituentaPatch } from "../agent-workflow-BTwrxOoX.js";
8
8
  import { i as EvaluationResult, r as EvaluateInput } from "../evaluation-Cd4S7-3t.js";
9
- import { a as ExportPortalInput, c as PortalExportKind, d as PortalModelImportData, f as PortalRsformDetails, g as portalItemToDraft, h as PortalTermForm, i as ExportFormat, l as PORTAL_JSON_CONTRACT_VERSION, m as PortalSchemaImportData, n as RSToolAgentContract, o as ExportPortalResult, p as PortalSchemaConstituenta, r as RSToolAgentOptions, s as ImportDataKind, t as CONTRACT_VERSION, u as PortalImportMetadata } from "../tool-contract-sQfr-DYD.js";
10
- import { t as RSToolAgent } from "../rstool-agent-BGQAzFly.js";
11
- export { type AgentConstituentaPatch, type AnalysisResult, type AnalyzeExpressionInput, type ApplyConstituentsMode, type ApplySchemaPatchInput, type ApplySchemaPatchResult, type BasicBinding, CONTRACT_VERSION, type ConstituentaDraft, type ConstituentaState, type CstDiagnostic, CstType, type Diagnostic, DiagnosticKind, type DiagnosticSeverity, EvalStatus, type EvaluateInput, type EvaluationResult, type ExportFormat, type ExportPortalInput, type ExportPortalResult, type ImportDataKind, type ListDiagnosticsFilters, type ModelValueState, PORTAL_JSON_CONTRACT_VERSION, type PortalExportKind, type PortalImportMetadata, type PortalModelImportData, type PortalRsformDetails, type PortalSchemaConstituenta, type PortalSchemaImportData, type PortalTermForm, RSDiagnosticCode, RSErrorCode, RSToolAgent, type RSToolAgentContract, type RSToolAgentOptions, type RSToolValue, type RecalculateModelResult, type SessionHandle, type SessionModelState, type SessionRevision, type SessionState, type SessionStateDetail, type SessionStateResult, type SessionSummary, type SessionSummaryItem, type SetConstituentaValueInput, type SetModelValuesInput, ValueClass, portalItemToDraft };
9
+ import { a as ExportPortalInput, c as PortalExportKind, d as PortalModelImportData, f as PortalRsformDetails, g as portalItemToDraft, h as PortalTermForm, i as ExportFormat, l as PORTAL_JSON_CONTRACT_VERSION, m as PortalSchemaImportData, n as RSToolAgentContract, o as ExportPortalResult, p as PortalSchemaConstituenta, r as RSToolAgentOptions, s as ImportDataKind, t as CONTRACT_VERSION, u as PortalImportMetadata } from "../tool-contract-BUaDRHoO.js";
10
+ import { t as RSToolAgent } from "../rstool-agent-BrAFJcoE.js";
11
+ export { type AgentConstituentaPatch, type AnalysisResult, type AnalyzeExpressionInput, type ApplyConstituentsMode, type ApplySchemaPatchInput, type ApplySchemaPatchResult, type BasicBinding, CONTRACT_VERSION, type ConstituentaDraft, type ConstituentaState, type CstDiagnostic, CstType, type Diagnostic, DiagnosticKind, type DiagnosticSeverity, EvalStatus, type EvaluateInput, type EvaluationResult, type ExportFormat, type ExportPortalInput, type ExportPortalResult, type ImportDataKind, type ListDiagnosticsFilters, type ModelValueState, PORTAL_JSON_CONTRACT_VERSION, type PortalExportKind, type PortalImportMetadata, type PortalModelImportData, type PortalRsformDetails, type PortalSchemaConstituenta, type PortalSchemaImportData, type PortalTermForm, RSDiagnosticCode, RSErrorCode, RSToolAgent, type RSToolAgentContract, type RSToolAgentOptions, type RSToolValue, type RecalculateModelResult, type RestoreOrderResult, type SessionHandle, type SessionModelState, type SessionRevision, type SessionState, type SessionStateDetail, type SessionStateResult, type SessionSummary, type SessionSummaryItem, type SetConstituentaValueInput, type SetModelValuesInput, ValueClass, portalItemToDraft };
@@ -1,5 +1,5 @@
1
1
  import { CstType, EvalStatus, RSErrorCode, ValueClass } from "./common.js";
2
2
  import { DiagnosticKind, RSDiagnosticCode } from "./diagnostic.js";
3
- import { i as portalItemToDraft, r as PORTAL_JSON_CONTRACT_VERSION, t as RSToolAgent } from "../models-B255GaEC.js";
3
+ import { i as portalItemToDraft, r as PORTAL_JSON_CONTRACT_VERSION, t as RSToolAgent } from "../models-LMyDB0md.js";
4
4
  import { CONTRACT_VERSION } from "./tool-contract.js";
5
5
  export { CONTRACT_VERSION, CstType, DiagnosticKind, EvalStatus, PORTAL_JSON_CONTRACT_VERSION, RSDiagnosticCode, RSErrorCode, RSToolAgent, ValueClass, portalItemToDraft };
@@ -1,2 +1,2 @@
1
- import { t as RSToolAgent } from "../rstool-agent-BGQAzFly.js";
1
+ import { t as RSToolAgent } from "../rstool-agent-BrAFJcoE.js";
2
2
  export { RSToolAgent };
@@ -1,2 +1,2 @@
1
- import { t as RSToolAgent } from "../models-B255GaEC.js";
1
+ import { t as RSToolAgent } from "../models-LMyDB0md.js";
2
2
  export { RSToolAgent };
@@ -1,2 +1,2 @@
1
- import { n as RSToolAgentContract, r as RSToolAgentOptions, t as CONTRACT_VERSION } from "../tool-contract-sQfr-DYD.js";
1
+ import { n as RSToolAgentContract, r as RSToolAgentOptions, t as CONTRACT_VERSION } from "../tool-contract-BUaDRHoO.js";
2
2
  export { CONTRACT_VERSION, RSToolAgentContract, RSToolAgentOptions };
@@ -1,6 +1,6 @@
1
1
  //#region src/models/tool-contract.ts
2
2
  /** Agent-visible contract version; bump on breaking API changes. */
3
- const CONTRACT_VERSION = "3.0.0";
3
+ const CONTRACT_VERSION = "3.1.0";
4
4
  //#endregion
5
5
  export { CONTRACT_VERSION };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"tool-contract.js","names":[],"sources":["../../src/models/tool-contract.ts"],"sourcesContent":["import {\n type ApplySchemaPatchInput,\n type ApplySchemaPatchResult,\n type SessionStateDetail,\n type SessionStateResult\n} from './agent-workflow';\nimport { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';\nimport { type Diagnostic, type ListDiagnosticsFilters } from './diagnostic';\nimport { type EvaluateInput, type EvaluationResult } from './evaluation';\nimport { type ExportPortalInput, type ExportPortalResult, type ImportDataKind } from './import-export';\nimport { type RecalculateModelResult, type SessionModelState, type SetModelValuesInput } from './model-value';\nimport { type SessionHandle, type SessionRevision, type SessionState } from './session';\n\n/** Agent-visible contract version; bump on breaking API changes. */\nexport const CONTRACT_VERSION = '3.0.0';\n\n/** Options for constructing an {@link RSToolAgent}. */\nexport interface RSToolAgentOptions {\n /** When set, sessions are persisted to this directory and survive process restarts. */\n persistenceDir?: string;\n}\n\n/**\n * Public method surface of {@link RSToolAgent}.\n *\n * Each method accepts an optional `sessionId`; when omitted, the current session is used\n * (or a new one is created where noted).\n */\nexport interface RSToolAgentContract {\n /** Current contract version string (same as {@link CONTRACT_VERSION}). */\n readonly contractVersion: string;\n\n /** Return the current session, or create one with optional `initial` metadata. */\n ensureSession(initial?: Partial<SessionState>): SessionHandle;\n\n /** Create a new session and make it current. */\n createSession(initial?: Partial<SessionState>): SessionHandle;\n\n /** Return the current session handle, or `null` when none is active. */\n getCurrentSession(): SessionHandle | null;\n\n /** Switch the active session; throws when `sessionId` is unknown. */\n setCurrentSession(sessionId: string): SessionHandle;\n\n /** Apply constituent patches to the schema (analyze, merge, optionally commit). */\n applySchemaPatch(input: ApplySchemaPatchInput, sessionId?: string): ApplySchemaPatchResult;\n\n /** Return session summary (default) or full cloned state when `detail` is `'full'`. */\n getSessionState(detail?: SessionStateDetail, sessionId?: string): SessionStateResult;\n\n /** List diagnostics for the session, optionally filtered by constituent or kind. */\n listDiagnostics(filters?: ListDiagnosticsFilters, sessionId?: string): Diagnostic[];\n\n /** Parse and type-check an RSLang expression against the current schema context. */\n analyzeExpression(input: AnalyzeExpressionInput, sessionId?: string): AnalysisResult;\n\n /** Record a revision checkpoint with an optional message. */\n commitStep(message?: string, sessionId?: string): SessionRevision;\n\n /** Export the session as a JSON string (state + diagnostics). */\n exportSession(sessionId?: string): string;\n\n /** Export schema or model payload in Portal JSON format. */\n exportPortal(input: ExportPortalInput, sessionId?: string): ExportPortalResult;\n\n /**\n * Import a session export or Portal JSON payload and make the new session current.\n *\n * When `kind` is `'auto'`, the payload shape is detected automatically.\n */\n importData(payload: string | object, kind?: ImportDataKind): SessionHandle;\n\n /** Set or clear model values for constituents; returns the updated model state. */\n setModelValues(input: SetModelValuesInput, sessionId?: string): Promise<SessionModelState>;\n\n /** Return a deep clone of the session model state. */\n getModelState(sessionId?: string): SessionModelState;\n\n /**\n * Evaluate a stored constituent or a scratch expression.\n *\n * Provide `constituentId`, or both `expression` and `cstType`.\n */\n evaluate(input: EvaluateInput, sessionId?: string): EvaluationResult;\n\n /** Recompute derived model values for all constituents. */\n recalculateModel(sessionId?: string): RecalculateModelResult;\n}\n"],"mappings":";;AAcA,MAAa,mBAAmB"}
1
+ {"version":3,"file":"tool-contract.js","names":[],"sources":["../../src/models/tool-contract.ts"],"sourcesContent":["import {\n type ApplySchemaPatchInput,\n type ApplySchemaPatchResult,\n type RestoreOrderResult,\n type SessionStateDetail,\n type SessionStateResult\n} from './agent-workflow';\nimport { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';\nimport { type Diagnostic, type ListDiagnosticsFilters } from './diagnostic';\nimport { type EvaluateInput, type EvaluationResult } from './evaluation';\nimport { type ExportPortalInput, type ExportPortalResult, type ImportDataKind } from './import-export';\nimport { type RecalculateModelResult, type SessionModelState, type SetModelValuesInput } from './model-value';\nimport { type SessionHandle, type SessionRevision, type SessionState } from './session';\n\n/** Agent-visible contract version; bump on breaking API changes. */\nexport const CONTRACT_VERSION = '3.1.0';\n\n/** Options for constructing an {@link RSToolAgent}. */\nexport interface RSToolAgentOptions {\n /** When set, sessions are persisted to this directory and survive process restarts. */\n persistenceDir?: string;\n}\n\n/**\n * Public method surface of {@link RSToolAgent}.\n *\n * Each method accepts an optional `sessionId`; when omitted, the current session is used\n * (or a new one is created where noted).\n */\nexport interface RSToolAgentContract {\n /** Current contract version string (same as {@link CONTRACT_VERSION}). */\n readonly contractVersion: string;\n\n /** Return the current session, or create one with optional `initial` metadata. */\n ensureSession(initial?: Partial<SessionState>): SessionHandle;\n\n /** Create a new session and make it current. */\n createSession(initial?: Partial<SessionState>): SessionHandle;\n\n /** Return the current session handle, or `null` when none is active. */\n getCurrentSession(): SessionHandle | null;\n\n /** Switch the active session; throws when `sessionId` is unknown. */\n setCurrentSession(sessionId: string): SessionHandle;\n\n /** Apply constituent patches to the schema (analyze, merge, optionally commit). */\n applySchemaPatch(input: ApplySchemaPatchInput, sessionId?: string): ApplySchemaPatchResult;\n\n /** Return session summary (default) or full cloned state when `detail` is `'full'`. */\n getSessionState(detail?: SessionStateDetail, sessionId?: string): SessionStateResult;\n\n /** List diagnostics for the session, optionally filtered by constituent or kind. */\n listDiagnostics(filters?: ListDiagnosticsFilters, sessionId?: string): Diagnostic[];\n\n /** Parse and type-check an RSLang expression against the current schema context. */\n analyzeExpression(input: AnalyzeExpressionInput, sessionId?: string): AnalysisResult;\n\n /** Record a revision checkpoint with an optional message. */\n commitStep(message?: string, sessionId?: string): SessionRevision;\n\n /** Export the session as a JSON string (state + diagnostics). */\n exportSession(sessionId?: string): string;\n\n /** Export schema or model payload in Portal JSON format. */\n exportPortal(input: ExportPortalInput, sessionId?: string): ExportPortalResult;\n\n /**\n * Import a session export or Portal JSON payload and make the new session current.\n *\n * When `kind` is `'auto'`, the payload shape is detected automatically.\n */\n importData(payload: string | object, kind?: ImportDataKind): SessionHandle;\n\n /** Set or clear model values for constituents; returns the updated model state. */\n setModelValues(input: SetModelValuesInput, sessionId?: string): Promise<SessionModelState>;\n\n /** Return a deep clone of the session model state. */\n getModelState(sessionId?: string): SessionModelState;\n\n /**\n * Evaluate a stored constituent or a scratch expression.\n *\n * Provide `constituentId`, or both `expression` and `cstType`.\n */\n evaluate(input: EvaluateInput, sessionId?: string): EvaluationResult;\n\n /** Recompute derived model values for all constituents. */\n recalculateModel(sessionId?: string): RecalculateModelResult;\n\n /**\n * Restore declaration order: formal topology, semantic clusters when ready,\n * otherwise stable against type/kernel preferred ranks.\n */\n restoreOrder(sessionId?: string): RestoreOrderResult;\n}\n"],"mappings":";;AAeA,MAAa,mBAAmB"}
@@ -1,10 +1,12 @@
1
- import { n as expandCstDiagnostic, o as modelStatusDiagnostic, t as DiagnosticKind } from "./diagnostic-assembly-DRunIcKQ.js";
1
+ import { n as expandCstDiagnostic, o as modelStatusDiagnostic, t as DiagnosticKind } from "./diagnostic-assembly-B-6vIA5I.js";
2
2
  import { toDiagnostic } from "./mappers/types.js";
3
3
  import { CstType } from "./models/common.js";
4
4
  import "./models/diagnostic.js";
5
- import { n as enrichSessionConstituents, t as ModelAdapter } from "./model-adapter-D-YmIvQW.js";
5
+ import { n as enrichSessionConstituents } from "./rsform-builder-DKwZfJvN.js";
6
+ import { ModelAdapter } from "./mappers/model-adapter.js";
6
7
  import { SchemaAdapter } from "./mappers/schema-adapter.js";
7
8
  import { CONTRACT_VERSION } from "./models/tool-contract.js";
9
+ import { restoreConstituentOrder } from "@rsconcept/domain/library/rsform-api";
8
10
  import { isModelIssue } from "@rsconcept/domain/library/rsmodel-api";
9
11
  import { Graph } from "@rsconcept/domain/graph/graph";
10
12
  import { extractGlobals } from "@rsconcept/domain/rslang/api";
@@ -217,7 +219,7 @@ var SessionStore = class {
217
219
  this.persist(sessionId, envelope);
218
220
  return {
219
221
  sessionId,
220
- contractVersion: contractVersion ?? "3.0.0"
222
+ contractVersion: contractVersion ?? "3.1.0"
221
223
  };
222
224
  }
223
225
  get(sessionId) {
@@ -542,6 +544,25 @@ var RSToolAgent = class {
542
544
  this.refreshModelDiagnostics(id);
543
545
  return result;
544
546
  }
547
+ /** @inheritdoc */
548
+ restoreOrder(sessionId) {
549
+ const id = this.resolveSessionId(sessionId);
550
+ const envelope = this.sessions.get(id);
551
+ const ordered = restoreConstituentOrder(envelope.state.items.map((item) => ({
552
+ id: item.id,
553
+ alias: item.alias,
554
+ cst_type: item.cstType,
555
+ definition_formal: item.definitionFormal
556
+ })));
557
+ const byId = new Map(envelope.state.items.map((item) => [item.id, item]));
558
+ envelope.state.items = ordered.map((item) => byId.get(item.id));
559
+ envelope.state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
560
+ this.sessions.replaceState(id, envelope.state);
561
+ return {
562
+ orderedIds: ordered.map((item) => item.id),
563
+ orderedAliases: ordered.map((item) => item.alias)
564
+ };
565
+ }
545
566
  addOrUpdateConstituenta(input, sessionId) {
546
567
  const id = this.resolveSessionId(sessionId);
547
568
  const envelope = this.sessions.get(id);
@@ -743,4 +764,4 @@ var RSToolAgent = class {
743
764
  //#endregion
744
765
  export { portalItemToDraft as i, SessionStore as n, PORTAL_JSON_CONTRACT_VERSION as r, RSToolAgent as t };
745
766
 
746
- //# sourceMappingURL=models-B255GaEC.js.map
767
+ //# sourceMappingURL=models-LMyDB0md.js.map