@rsconcept/rstool 1.7.1 → 2.0.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 (126) hide show
  1. package/README.md +7 -7
  2. package/dist/index.js +1 -1
  3. package/dist/mappers/model-adapter.d.ts +6 -2
  4. package/dist/mappers/model-adapter.js +28 -3
  5. package/dist/mappers/model-adapter.js.map +1 -1
  6. package/dist/mappers/schema-adapter.d.ts +1 -2
  7. package/dist/mappers/schema-adapter.js +1 -1
  8. package/dist/mappers/types.d.ts +4 -5
  9. package/dist/models/index.js +1 -1
  10. package/dist/models/rstool-agent.js +1 -2
  11. package/dist/{models-DG2uTaV_.js → models-D06g8LId.js} +6 -5
  12. package/dist/{models-DG2uTaV_.js.map → models-D06g8LId.js.map} +1 -1
  13. package/dist/{rsform-builder-DKwZfJvN.js → rsform-builder-BlXEe5Ow.js} +2 -2
  14. package/dist/{rsform-builder-DKwZfJvN.js.map → rsform-builder-BlXEe5Ow.js.map} +1 -1
  15. package/dist/session/session-store.d.ts +3 -3
  16. package/dist/session/session-store.js +1 -2
  17. package/dist/wrapper/client.d.ts +15 -9
  18. package/dist/wrapper/client.js +79 -12
  19. package/dist/wrapper/client.js.map +1 -1
  20. package/dist/wrapper/stdio-wrapper.d.ts +1 -1
  21. package/dist/wrapper/stdio-wrapper.js +18 -10
  22. package/dist/wrapper/stdio-wrapper.js.map +1 -1
  23. package/docs/BRIEF.md +93 -0
  24. package/docs/CONCEPTUAL-SCHEMA.md +17 -2
  25. package/docs/CONSTRUCTIONS.md +384 -0
  26. package/docs/DIAGNOSTICS.md +9 -8
  27. package/docs/DOMAIN.md +12 -0
  28. package/docs/METHOD.md +208 -0
  29. package/docs/MODEL-TESTING.md +48 -0
  30. package/docs/PORTAL-API.md +38 -285
  31. package/docs/PORTAL-MODELS.md +24 -0
  32. package/docs/PORTAL-OSS.md +56 -0
  33. package/docs/PORTAL-PUBLISH.md +39 -0
  34. package/docs/PORTAL-READ.md +301 -0
  35. package/docs/README.md +8 -4
  36. package/docs/REQUIREMENTS.md +61 -0
  37. package/docs/SYNTAX.md +5 -4
  38. package/docs/TYPIFICATION.md +12 -3
  39. package/docs/brief.schema.json +173 -0
  40. package/examples/README.md +16 -2
  41. package/examples/access-control/NOTES.md +23 -0
  42. package/examples/access-control/anti/collapsed.json +439 -0
  43. package/examples/access-control/anti/weakened.json +439 -0
  44. package/examples/access-control/brief-v1.json +231 -0
  45. package/examples/access-control/brief.json +310 -0
  46. package/examples/access-control/build-rsform.ts +151 -0
  47. package/examples/access-control/requirements-v1.md +9 -0
  48. package/examples/access-control/requirements-v2.md +4 -0
  49. package/examples/access-control/rsform-session-v1.json +439 -0
  50. package/examples/access-control/rsform-session.json +523 -0
  51. package/examples/audit-diagnostics.ts +9 -1
  52. package/examples/briefs.test.ts +126 -0
  53. package/examples/clinic-booking/NOTES.md +24 -0
  54. package/examples/clinic-booking/anti/collapsed.json +615 -0
  55. package/examples/clinic-booking/anti/species-as-genus.json +568 -0
  56. package/examples/clinic-booking/brief-v1.json +332 -0
  57. package/examples/clinic-booking/brief.json +405 -0
  58. package/examples/clinic-booking/build-rsform.ts +174 -0
  59. package/examples/clinic-booking/requirements-v1.md +9 -0
  60. package/examples/clinic-booking/requirements-v2.md +4 -0
  61. package/examples/clinic-booking/rsform-session-v1.json +615 -0
  62. package/examples/clinic-booking/rsform-session.json +700 -0
  63. package/examples/diagnostics-utils.ts +26 -0
  64. package/examples/kinship/brief.json +337 -0
  65. package/examples/kinship/build-rsform.ts +7 -4
  66. package/examples/kinship/rsform-session.json +20 -63
  67. package/examples/kinship/rsmodel-session.json +14 -14
  68. package/examples/kinship-subordination/NOTES.md +49 -0
  69. package/examples/kinship-subordination/brief.json +161 -0
  70. package/examples/kinship-subordination/build-rsform.ts +100 -0
  71. package/examples/kinship-subordination/rsform-session.json +795 -0
  72. package/examples/library-loans/NOTES.md +46 -0
  73. package/examples/library-loans/anti/collapsed.json +481 -0
  74. package/examples/library-loans/anti/species-as-genus.json +334 -0
  75. package/examples/library-loans/anti/uncovered.json +406 -0
  76. package/examples/library-loans/anti/weakened.json +464 -0
  77. package/examples/library-loans/brief-v1.json +340 -0
  78. package/examples/library-loans/brief.json +502 -0
  79. package/examples/library-loans/build-rsform.ts +239 -0
  80. package/examples/library-loans/requirements-v1.md +11 -0
  81. package/examples/library-loans/requirements-v2.md +5 -0
  82. package/examples/library-loans/rsform-session-v1.json +481 -0
  83. package/examples/library-loans/rsform-session.json +652 -0
  84. package/examples/library-loans/source-markup.md +18 -0
  85. package/examples/movd/brief.json +220 -0
  86. package/examples/movd/build-rsform.ts +5 -2
  87. package/examples/movd/rsform-session.json +14 -46
  88. package/examples/subordination/NOTES.md +59 -0
  89. package/examples/subordination/anti/collapsed.json +556 -0
  90. package/examples/subordination/anti/single-relation.json +125 -0
  91. package/examples/subordination/anti/transitive.json +573 -0
  92. package/examples/subordination/anti/weakened.json +539 -0
  93. package/examples/subordination/brief.json +386 -0
  94. package/examples/subordination/build-rsform.ts +63 -0
  95. package/examples/subordination/constants.ts +115 -0
  96. package/examples/subordination/rsform-session.json +556 -0
  97. package/examples/subordination/source-markup.md +19 -0
  98. package/examples/subordination/source.md +40 -0
  99. package/package.json +29 -20
  100. package/skills/INSTALL.md +28 -29
  101. package/skills/README.md +25 -10
  102. package/skills/rs-core/SKILL.md +56 -0
  103. package/skills/rs-explain/SKILL.md +28 -0
  104. package/skills/rs-explicate/SKILL.md +71 -0
  105. package/skills/rs-interpret/SKILL.md +67 -0
  106. package/skills/rs-portal/SKILL.md +51 -0
  107. package/skills/rs-review/SKILL.md +79 -0
  108. package/skills/rs-scope/SKILL.md +67 -0
  109. package/skills/rs-synthesis/SKILL.md +52 -0
  110. package/skills/rstool/SKILL.md +70 -0
  111. package/skills/rstool-helper/GUIDE.md +18 -272
  112. package/skills/rstool-helper/SKILL.md +8 -55
  113. package/skills/{rstool-helper → rstool-runtime}/EXAMPLES.md +40 -12
  114. package/skills/{rstool-helper → rstool-runtime}/REFERENCE.md +28 -7
  115. package/skills/rstool-runtime/SKILL.md +96 -0
  116. package/skills/scripts/brief-check.test.ts +165 -0
  117. package/skills/scripts/brief-check.ts +826 -0
  118. package/skills/scripts/check-brief.ts +94 -0
  119. package/skills/scripts/rstool-skills.mjs +119 -0
  120. package/skills/scripts/skill-stubs.test.ts +48 -0
  121. package/src/mappers/model-adapter.ts +34 -1
  122. package/src/models/rstool-agent.test.ts +95 -0
  123. package/src/wrapper/client.test.ts +43 -4
  124. package/src/wrapper/client.ts +95 -16
  125. package/src/wrapper/stdio-handler.test.ts +43 -0
  126. package/src/wrapper/stdio-handler.ts +19 -5
package/README.md CHANGED
@@ -2,11 +2,11 @@
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.2.0` — see [skills/rstool-helper/REFERENCE.md](./skills/rstool-helper/REFERENCE.md) for the full v3 API.
5
+ **Contract version:** `3.3.0` — see [skills/rstool-runtime/REFERENCE.md](./skills/rstool-runtime/REFERENCE.md) for the full v3 API.
6
6
 
7
7
  ## Agent skill
8
8
 
9
- RS language + rstool workflows for agents: `skills/rstool-helper/` (`GUIDE.md`, `REFERENCE.md`, `EXAMPLES.md`) and `docs/` (`DOMAIN.md`, `CONCEPTUAL-SCHEMA.md`, `SYNTAX.md`, …). A **thin** entry skill is installed into the project’s agent skills folder; see [Installing the agent skill](#installing-the-agent-skill) below.
9
+ Agents build conceptual schemas that answer the user's request, not just pass the analyzer. The router skill `skills/rstool/` picks the scenario and names the stage skills (`skills/rs-scope`, `rs-core`, `rs-explicate`, `rs-interpret`, `rs-review`, `rs-synthesis`, `rs-explain`, `rs-portal`, `rstool-runtime`). The method is in `docs/METHOD.md`; a schema brief (`docs/BRIEF.md`) holds the expressiveness requirements, decisions and labelled scenarios, checked by `skills/scripts/check-brief.ts`. Only a **stub** of the router is installed into the project; see [Installing the agent skill](#installing-the-agent-skill) below.
10
10
 
11
11
  ## Install
12
12
 
@@ -26,7 +26,7 @@ The agent should read and follow:
26
26
 
27
27
  `node_modules/@rsconcept/rstool/skills/INSTALL.md`
28
28
 
29
- That copies `skills/rstool-helper/SKILL.md` from the package into your host’s project skills directory (for example `.agents/skills/rstool-helper/SKILL.md`). Full guidance stays in the package (`skills/rstool-helper/GUIDE.md`, `docs/*.md`) and is read from `node_modules` when needed.
29
+ The procedure is agent-neutral: the agent adds a routing line to the project `AGENTS.md` (or the instructions file its host loads) and, if its host loads a project skills folder, a stub `rstool/SKILL.md` there (name, description and a path into `node_modules`; `npx rstool-skills install --dir <skills-dir>`). The skills and `docs/*.md` stay in the package and are read from `node_modules` when needed, so nothing is re-copied after an update.
30
30
 
31
31
  Details: `skills/README.md`.
32
32
 
@@ -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.2.0`):
80
+ Supported methods (contract `3.3.0`):
81
81
 
82
82
  - `ping`
83
83
  - `methods`
@@ -100,7 +100,7 @@ Supported methods (contract `3.2.0`):
100
100
  - `restoreOrder`
101
101
  - `synthesize`
102
102
 
103
- Params are **flat** at the top level (no `params.input` wrapper). Optional `sessionId` sits alongside method fields.
103
+ Params are **flat** at the top level (no `params.input` wrapper). Optional `sessionId` sits alongside method fields. `listDiagnostics` takes flat `constituentId` / `kind` / `severity` filters (a legacy nested `filters` object is still accepted).
104
104
 
105
105
  Example `createSession`:
106
106
 
@@ -113,7 +113,7 @@ Request:
113
113
  Response:
114
114
 
115
115
  ```json
116
- { "id": "1", "ok": true, "result": { "sessionId": "...", "contractVersion": "3.2.0" } }
116
+ { "id": "1", "ok": true, "result": { "sessionId": "...", "contractVersion": "3.3.0" } }
117
117
  ```
118
118
 
119
119
  Example `applySchemaPatch`:
@@ -142,7 +142,7 @@ Response:
142
142
  "ok": true,
143
143
  "result": {
144
144
  "success": true,
145
- "session": { "sessionId": "...", "contractVersion": "3.2.0" },
145
+ "session": { "sessionId": "...", "contractVersion": "3.3.0" },
146
146
  "summary": { "itemCount": 3 }
147
147
  }
148
148
  }
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-DG2uTaV_.js";
4
+ import { r as PORTAL_JSON_CONTRACT_VERSION, t as RSToolAgent } from "./models-D06g8LId.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 };
@@ -5,7 +5,7 @@ import "../models/index.js";
5
5
  import { CstType } from "@rsconcept/domain/library/rsform";
6
6
  import { RSEngine } from "@rsconcept/domain/library/rsengine";
7
7
  //#region src/mappers/model-adapter.d.ts
8
- declare class ModelAdapter {
8
+ export declare class ModelAdapter {
9
9
  setConstituentaValue(session: SessionState, input: SetConstituentaValueInput): Promise<SessionModelState>;
10
10
  setConstituentaValues(session: SessionState, input: {
11
11
  items: SetConstituentaValueInput[];
@@ -15,8 +15,12 @@ declare class ModelAdapter {
15
15
  evaluateConstituenta(session: SessionState, constituentId: number): EvaluationResult;
16
16
  recalculateModel(session: SessionState): RecalculateModelResult;
17
17
  createEngine(session: SessionState): RSEngine;
18
+ /**
19
+ * Computes values of inferrable constituents referenced by a scratch expression (directly or
20
+ * through `F#` / `P#` bodies). A fresh engine only holds interpreted `X#` / `C#` / `S#` values.
21
+ */
22
+ private prepareReferencedValues;
18
23
  private validateSetInput;
19
24
  }
20
25
  //#endregion
21
- export { ModelAdapter };
22
26
  //# sourceMappingURL=model-adapter.d.ts.map
@@ -1,8 +1,10 @@
1
1
  import { r as expressionDiagnostic, t as DiagnosticKind } from "../diagnostic-assembly-B-r0NyHL.js";
2
- import { t as buildRSFormFromSession } from "../rsform-builder-DKwZfJvN.js";
2
+ import { t as buildRSFormFromSession } from "../rsform-builder-BlXEe5Ow.js";
3
3
  import { EvalStatus } from "@rsconcept/domain/library/rsmodel";
4
4
  import { isBaseSet } from "@rsconcept/domain/library/rsform-api";
5
5
  import { isInferrable, isInterpretable, toBasicBinding, validateBasicBindingData, validateValueData } from "@rsconcept/domain/library/rsmodel-api";
6
+ import { extractGlobals } from "@rsconcept/domain/rslang/api";
7
+ import { normalizeValue } from "@rsconcept/domain/rslang/eval/value-api";
6
8
  import { RSEngine } from "@rsconcept/domain/library/rsengine";
7
9
  //#region src/mappers/model-adapter.ts
8
10
  const SESSION_MODEL_ID = 0;
@@ -14,7 +16,11 @@ var ModelAdapter = class {
14
16
  if (isBaseSet(frontendType)) {
15
17
  const binding = toBasicBinding(input.value);
16
18
  await engine.setBasicValue(input.target, binding);
17
- } else await engine.setStructureValue(input.target, input.value);
19
+ } else {
20
+ const value = structuredClone(input.value);
21
+ normalizeValue(value);
22
+ await engine.setStructureValue(input.target, value);
23
+ }
18
24
  session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
19
25
  return structuredClone(session.model);
20
26
  }
@@ -31,7 +37,9 @@ var ModelAdapter = class {
31
37
  return structuredClone(session.model);
32
38
  }
33
39
  evaluateExpression(session, expression, cstType) {
34
- const result = this.createEngine(session).evaluateExpression(expression, cstType);
40
+ const engine = this.createEngine(session);
41
+ this.prepareReferencedValues(engine, session, expression);
42
+ const result = engine.evaluateExpression(expression, cstType);
35
43
  const status = result.value === null ? result.errors.length > 0 ? EvalStatus.EVAL_FAIL : EvalStatus.EMPTY : EvalStatus.HAS_DATA;
36
44
  return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status, expression);
37
45
  }
@@ -63,6 +71,23 @@ var ModelAdapter = class {
63
71
  engine.loadData(schema, model);
64
72
  return engine;
65
73
  }
74
+ /**
75
+ * Computes values of inferrable constituents referenced by a scratch expression (directly or
76
+ * through `F#` / `P#` bodies). A fresh engine only holds interpreted `X#` / `C#` / `S#` values.
77
+ */
78
+ prepareReferencedValues(engine, session, expression) {
79
+ const schema = engine.schema;
80
+ if (!schema) return;
81
+ const globals = extractGlobals(expression);
82
+ const referenced = session.items.filter((item) => globals.has(item.alias)).map((item) => item.id);
83
+ if (referenced.length === 0) return;
84
+ const required = /* @__PURE__ */ new Set([...referenced, ...schema.graph.expandAllInputs(referenced)]);
85
+ for (const cstID of schema.graph.topologicalOrder()) {
86
+ if (!required.has(cstID)) continue;
87
+ const cst = schema.cstByID.get(cstID);
88
+ if (cst && isInferrable(cst.cst_type)) engine.calculateCst(cstID);
89
+ }
90
+ }
66
91
  validateSetInput(session, input) {
67
92
  const cst = session.items.find((item) => item.id === input.target);
68
93
  if (!cst) throw new Error(`Unknown constituent: ${input.target}`);
@@ -1 +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;EAC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AS,yBACP,OACA,QACA,YACA,WACA,QACA,YACA,QACkB;CAClB,MAAM,cAAc,OAAO,KAAI,WAAU;EACvC,GAAG,qBAAqB,OAAO,YAAY,MAAM;EACjD,MAAM,eAAe;CACvB,EAAE;CACF,OAAO;EACL,SAAS,YAAY,WAAW,KAAK,UAAU;EACxC;EACP;EACA;EACA;EACA;CACF;AACF"}
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 { extractGlobals } from '@rsconcept/domain/rslang/api';\nimport { normalizeValue } from '@rsconcept/domain/rslang/eval/value-api';\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 // Set operations in the evaluator assume canonical form (sorted, deduplicated);\n // agents may pass elements in arbitrary order.\n const value = structuredClone(input.value) as Value;\n normalizeValue(value);\n await engine.setStructureValue(input.target, 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 this.prepareReferencedValues(engine, session, expression);\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 /**\n * Computes values of inferrable constituents referenced by a scratch expression (directly or\n * through `F#` / `P#` bodies). A fresh engine only holds interpreted `X#` / `C#` / `S#` values.\n */\n private prepareReferencedValues(engine: RSEngine, session: SessionState, expression: string): void {\n const schema = engine.schema;\n if (!schema) {\n return;\n }\n const globals = extractGlobals(expression);\n const referenced = session.items.filter(item => globals.has(item.alias)).map(item => item.id);\n if (referenced.length === 0) {\n return;\n }\n const required = new Set([...referenced, ...schema.graph.expandAllInputs(referenced)]);\n for (const cstID of schema.graph.topologicalOrder()) {\n if (!required.has(cstID)) {\n continue;\n }\n const cst = schema.cstByID.get(cstID);\n if (cst && isInferrable(cst.cst_type)) {\n engine.calculateCst(cstID);\n }\n }\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":";;;;;;;;;AAyBA,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,OAAO;GAGL,MAAM,QAAQ,gBAAgB,MAAM,KAAK;GACzC,eAAe,KAAK;GACpB,MAAM,OAAO,kBAAkB,MAAM,QAAQ,KAAK;EACpD;EACA,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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,WAAW;GAC/B,KAAK,MAAM,QAAQ,MAAM;IACvB,MAAM,QAAQ;KACZ,IAAI,KAAK;KACT,MAAM,KAAK;KACX,OAAO,KAAK;IACd;IACA,MAAM,QAAQ,QAAQ,MAAM,MAAM,WAAU,aAAY,SAAS,OAAO,KAAK,MAAM;IACnF,IAAI,UAAU,IACZ,QAAQ,MAAM,MAAM,KAAK,KAAK;SAE9B,QAAQ,MAAM,MAAM,SAAS;GAEjC;EACF;EACA,aAAa,OAAO,EAAE,WAAW;GAC/B,MAAM,MAAM,IAAI,IAAI,KAAK,KAAK;GAC9B,QAAQ,MAAM,QAAQ,QAAQ,MAAM,MAAM,QAAO,SAAQ,CAAC,IAAI,IAAI,KAAK,EAAE,CAAC;EAC5E;CACF;AACF;AAEA,SAAS,wBAAwB,SAAgC;CAC/D,OAAO;EACL,IAAI;EACJ,QAAQ;EACR,SAAS,CAAC;EACV,OAAO,QAAQ,MAAM,MAAM,KAAI,UAAS;GACtC,IAAI,KAAK;GACT,MAAM,KAAK;GACX,OAAO,KAAK;EACd,EAAE;CACJ;AACF;AAEA,SAAS,yBACP,OACA,QACA,YACA,WACA,QACA,YACA,QACkB;CAClB,MAAM,cAAc,OAAO,KAAI,WAAU;EACvC,GAAG,qBAAqB,OAAO,YAAY,MAAM;EACjD,MAAM,eAAe;CACvB,EAAE;CACF,OAAO;EACL,SAAS,YAAY,WAAW,KAAK,UAAU;EACxC;EACP;EACA;EACA;EACA;CACF;AACF"}
@@ -6,7 +6,7 @@ import "../models/index.js";
6
6
  import { RSForm } from "@rsconcept/domain/library/rsform";
7
7
  import { RSLangAnalyzer } from "@rsconcept/domain/rslang";
8
8
  //#region src/mappers/schema-adapter.d.ts
9
- declare class SchemaAdapter {
9
+ export declare class SchemaAdapter {
10
10
  analyzeAgainstSession(session: SessionState, draft: ConstituentaDraft): {
11
11
  result: AnalysisResult;
12
12
  diagnostics: Diagnostic[];
@@ -20,5 +20,4 @@ declare class SchemaAdapter {
20
20
  private toAnalysisSchema;
21
21
  }
22
22
  //#endregion
23
- export { SchemaAdapter };
24
23
  //# sourceMappingURL=schema-adapter.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { toPublicAnalysis } from "./types.js";
2
- import { t as buildRSFormFromSession } from "../rsform-builder-DKwZfJvN.js";
2
+ import { t as buildRSFormFromSession } from "../rsform-builder-BlXEe5Ow.js";
3
3
  import { getAnalysisFor } from "@rsconcept/domain/library/rsform-api";
4
4
  //#region src/mappers/schema-adapter.ts
5
5
  var SchemaAdapter = class {
@@ -4,7 +4,7 @@ import "../models/index.js";
4
4
  import { RSErrorDescription, ValueClass } from "@rsconcept/domain/rslang";
5
5
  //#region src/mappers/types.d.ts
6
6
  /** Minimal domain error shape before mapping to {@link Diagnostic}. */
7
- interface DomainErrorLike {
7
+ export interface DomainErrorLike {
8
8
  code: number;
9
9
  from: number;
10
10
  to: number;
@@ -12,16 +12,15 @@ interface DomainErrorLike {
12
12
  stack?: RSErrorDescription['stack'];
13
13
  }
14
14
  /** Minimal domain analysis shape before mapping to {@link AnalysisResult}. */
15
- interface DomainAnalysisLike {
15
+ export interface DomainAnalysisLike {
16
16
  success: boolean;
17
17
  type: Record<string, unknown> | null;
18
18
  valueClass: ValueClass | null;
19
19
  errors: DomainErrorLike[];
20
20
  }
21
21
  /** Map a domain parser/semantic error to the public diagnostic shape. */
22
- declare function toDiagnostic(error: DomainErrorLike, expression: string, target?: DiagnosticTarget): Diagnostic;
22
+ export declare function toDiagnostic(error: DomainErrorLike, expression: string, target?: DiagnosticTarget): Diagnostic;
23
23
  /** Map a domain analysis result to the public {@link AnalysisResult} shape. */
24
- declare function toPublicAnalysis(analysis: DomainAnalysisLike, expression: string, target?: DiagnosticTarget): AnalysisResult;
24
+ export declare function toPublicAnalysis(analysis: DomainAnalysisLike, expression: string, target?: DiagnosticTarget): AnalysisResult;
25
25
  //#endregion
26
- export { DomainAnalysisLike, DomainErrorLike, toDiagnostic, toPublicAnalysis };
27
26
  //# sourceMappingURL=types.d.ts.map
@@ -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-DG2uTaV_.js";
3
+ import { i as portalItemToDraft, r as PORTAL_JSON_CONTRACT_VERSION, t as RSToolAgent } from "../models-D06g8LId.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 @@
1
- import { t as RSToolAgent } from "../models-DG2uTaV_.js";
2
- export { RSToolAgent };
1
+ export { t as RSToolAgent } from "../models-D06g8LId.js";
@@ -2,14 +2,14 @@ import { n as expandCstDiagnostic, o as modelStatusDiagnostic, t as DiagnosticKi
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 } from "./rsform-builder-DKwZfJvN.js";
5
+ import { n as enrichSessionConstituents } from "./rsform-builder-BlXEe5Ow.js";
6
6
  import { ModelAdapter } from "./mappers/model-adapter.js";
7
7
  import { SchemaAdapter } from "./mappers/schema-adapter.js";
8
8
  import { CONTRACT_VERSION } from "./models/tool-contract.js";
9
9
  import { inlineSynthesis, restoreConstituentOrder } from "@rsconcept/domain/library/rsform-api";
10
10
  import { isModelIssue } from "@rsconcept/domain/library/rsmodel-api";
11
- import { Graph } from "@rsconcept/domain/graph/graph";
12
11
  import { extractGlobals } from "@rsconcept/domain/rslang/api";
12
+ import { Graph } from "@rsconcept/domain/graph/graph";
13
13
  import { randomUUID } from "node:crypto";
14
14
  import fs from "node:fs";
15
15
  import path from "node:path";
@@ -548,12 +548,13 @@ var RSToolAgent = class {
548
548
  restoreOrder(sessionId) {
549
549
  const id = this.resolveSessionId(sessionId);
550
550
  const envelope = this.sessions.get(id);
551
- const ordered = restoreConstituentOrder(envelope.state.items.map((item) => ({
551
+ const orderable = envelope.state.items.map((item) => ({
552
552
  id: item.id,
553
553
  alias: item.alias,
554
554
  cst_type: item.cstType,
555
555
  definition_formal: item.definitionFormal
556
- })));
556
+ }));
557
+ const ordered = restoreConstituentOrder(orderable);
557
558
  const byId = new Map(envelope.state.items.map((item) => [item.id, item]));
558
559
  envelope.state.items = ordered.map((item) => byId.get(item.id));
559
560
  envelope.state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -877,4 +878,4 @@ function toSynthesizableSessionItem(item) {
877
878
  //#endregion
878
879
  export { portalItemToDraft as i, SessionStore as n, PORTAL_JSON_CONTRACT_VERSION as r, RSToolAgent as t };
879
880
 
880
- //# sourceMappingURL=models-DG2uTaV_.js.map
881
+ //# sourceMappingURL=models-D06g8LId.js.map