@rsconcept/rstool 0.3.0 → 0.4.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.
- package/README.md +3 -1
- package/dist/index-uhkmwruf.d.ts +46 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/mappers/model-adapter.d.ts +1 -1
- package/dist/mappers/schema-adapter.d.ts +1 -1
- package/dist/models/index.d.ts +5 -4
- package/dist/models/index.js +2 -2
- package/dist/models/rstool-agent.d.ts +1 -1
- package/dist/models/rstool-agent.js +1 -92
- package/dist/models/session.d.ts +1 -1
- package/dist/models/tool-contract.d.ts +1 -1
- package/dist/models/tool-contract.js +1 -1
- package/dist/models/tool-contract.js.map +1 -1
- package/dist/rstool-agent-BZi5jO1y.js +158 -0
- package/dist/rstool-agent-BZi5jO1y.js.map +1 -0
- package/dist/{rstool-agent-DkeH5Qml.d.ts → rstool-agent-pRaPnZay.d.ts} +6 -4
- package/dist/session/session-store.d.ts +2 -1
- package/dist/session/session-store.js +3 -0
- package/dist/session/session-store.js.map +1 -1
- package/dist/{session-BHGCCLfQ.d.ts → session-BPgsE80c.d.ts} +12 -1
- package/dist/{tool-contract-CsGqg_0P.d.ts → tool-contract-n1ghUOrK.d.ts} +5 -3
- package/dist/wrapper/stdio-wrapper.js +13 -1
- package/dist/wrapper/stdio-wrapper.js.map +1 -1
- package/package.json +1 -1
- package/skills/rstool-helper/EXAMPLES.md +9 -0
- package/skills/rstool-helper/GUIDE.md +1 -0
- package/skills/rstool-helper/REFERENCE.md +42 -11
- package/src/index.ts +6 -0
- package/src/models/index.ts +8 -0
- package/src/models/portal-json.ts +45 -0
- package/src/models/rstool-agent.test.ts +98 -0
- package/src/models/rstool-agent.ts +72 -4
- package/src/models/session.ts +11 -0
- package/src/models/tool-contract.ts +3 -1
- package/src/session/session-store.ts +3 -0
- package/src/wrapper/stdio-wrapper.ts +14 -0
- package/dist/models/rstool-agent.js.map +0 -1
package/README.md
CHANGED
|
@@ -85,6 +85,8 @@ Supported methods (current contract version: see [`CONTRACT_VERSION`](src/models
|
|
|
85
85
|
- `listDiagnostics`
|
|
86
86
|
- `commitStep`
|
|
87
87
|
- `exportSession`
|
|
88
|
+
- `exportPortalSchema`
|
|
89
|
+
- `exportPortalModel`
|
|
88
90
|
- `importSession`
|
|
89
91
|
- `setConstituentaValue`
|
|
90
92
|
- `setConstituentaValues`
|
|
@@ -103,7 +105,7 @@ Example request:
|
|
|
103
105
|
Example response:
|
|
104
106
|
|
|
105
107
|
```json
|
|
106
|
-
{ "id": "1", "ok": true, "result": { "sessionId": "...", "contractVersion": "1.
|
|
108
|
+
{ "id": "1", "ok": true, "result": { "sessionId": "...", "contractVersion": "1.4.0" } }
|
|
107
109
|
```
|
|
108
110
|
|
|
109
111
|
## Typed client example
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { o as RSToolValue, t as BasicBinding } from "./common-DxLg3eXX.js";
|
|
2
|
+
//#region src/models/portal-json.d.ts
|
|
3
|
+
/** Portal JSON import/export format version (schema and model files). */
|
|
4
|
+
declare const PORTAL_JSON_CONTRACT_VERSION = "1.0.0";
|
|
5
|
+
interface PortalImportMetadata {
|
|
6
|
+
contract_version: string;
|
|
7
|
+
title: string;
|
|
8
|
+
alias: string;
|
|
9
|
+
description: string;
|
|
10
|
+
}
|
|
11
|
+
interface PortalTermForm {
|
|
12
|
+
text: string;
|
|
13
|
+
tags: string;
|
|
14
|
+
}
|
|
15
|
+
interface PortalSchemaConstituenta {
|
|
16
|
+
id: number;
|
|
17
|
+
alias: string;
|
|
18
|
+
convention: string;
|
|
19
|
+
crucial: boolean;
|
|
20
|
+
cst_type: string;
|
|
21
|
+
definition_formal: string;
|
|
22
|
+
typification_manual: string;
|
|
23
|
+
value_is_property: boolean;
|
|
24
|
+
definition_raw: string;
|
|
25
|
+
definition_resolved: string;
|
|
26
|
+
term_raw: string;
|
|
27
|
+
term_resolved: string;
|
|
28
|
+
term_forms: PortalTermForm[];
|
|
29
|
+
}
|
|
30
|
+
interface PortalSchemaImportData extends PortalImportMetadata {
|
|
31
|
+
items: PortalSchemaConstituenta[];
|
|
32
|
+
attribution: Array<{
|
|
33
|
+
container: number;
|
|
34
|
+
attribute: number;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
interface PortalModelImportData extends PortalImportMetadata {
|
|
38
|
+
items: Array<{
|
|
39
|
+
id: number;
|
|
40
|
+
type: string;
|
|
41
|
+
value: RSToolValue | BasicBinding;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { PortalSchemaImportData as a, PortalSchemaConstituenta as i, PortalImportMetadata as n, PortalTermForm as o, PortalModelImportData as r, PORTAL_JSON_CONTRACT_VERSION as t };
|
|
46
|
+
//# sourceMappingURL=index-uhkmwruf.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { n as ListDiagnosticsFilters, t as DiagnosticRecord } from "./diagnostic
|
|
|
4
4
|
import { i as ConstituentaState, n as AddOrUpdateConstituentaResult, r as ConstituentaDraft, t as AddOrUpdateConstituentaInput } from "./constituenta-Dnd6iToB.js";
|
|
5
5
|
import { n as EvaluateExpressionInput, r as EvaluationResult, t as EvaluateConstituentaInput } from "./evaluation-CCVYH0wA.js";
|
|
6
6
|
import { a as SetConstituentaValueInput, i as SessionModelState, n as ModelValueState, o as SetConstituentaValuesInput, r as RecalculateModelResult, t as ClearConstituentaValuesInput } from "./model-value-SFAVj0dw.js";
|
|
7
|
-
import { n as
|
|
8
|
-
import { n as
|
|
9
|
-
import { t as
|
|
7
|
+
import { a as PortalSchemaImportData, i as PortalSchemaConstituenta, n as PortalImportMetadata, o as PortalTermForm, r as PortalModelImportData, t as PORTAL_JSON_CONTRACT_VERSION } from "./index-uhkmwruf.js";
|
|
8
|
+
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "./session-BPgsE80c.js";
|
|
9
|
+
import { n as RSToolAgentContract, t as CONTRACT_VERSION } from "./tool-contract-n1ghUOrK.js";
|
|
10
|
+
import { t as RSToolAgent } from "./rstool-agent-pRaPnZay.js";
|
|
10
11
|
import { DomainAnalysisLike, DomainErrorLike, toPublicAnalysis, toPublicError } from "./mappers/types.js";
|
|
11
12
|
import { RSToolWrapperClient, RSToolWrapperClientOptions, WrapperResponse } from "./wrapper/client.js";
|
|
12
|
-
export { type AddOrUpdateConstituentaInput, type AddOrUpdateConstituentaResult, type AnalysisResult, type AnalyzeExpressionInput, type BasicBinding, CONTRACT_VERSION, type ClearConstituentaValuesInput, type ConstituentaDraft, type ConstituentaState, CstType, type DiagnosticRecord, type DomainAnalysisLike, type DomainErrorLike, EvalStatus, type EvaluateConstituentaInput, type EvaluateExpressionInput, type EvaluationResult, type ListDiagnosticsFilters, type ModelValueState, RSErrorCode, RSToolAgent, type RSToolAgentContract, type RSToolErrorDescription, type RSToolValue, RSToolWrapperClient, type RSToolWrapperClientOptions, type RecalculateModelResult, type SessionHandle, type SessionModelState, type SessionRevision, type SessionState, type SetConstituentaValueInput, type SetConstituentaValuesInput, ValueClass, type WrapperResponse, toPublicAnalysis, toPublicError };
|
|
13
|
+
export { type AddOrUpdateConstituentaInput, type AddOrUpdateConstituentaResult, type AnalysisResult, type AnalyzeExpressionInput, type BasicBinding, CONTRACT_VERSION, type ClearConstituentaValuesInput, type ConstituentaDraft, type ConstituentaState, CstType, type DiagnosticRecord, type DomainAnalysisLike, type DomainErrorLike, EvalStatus, type EvaluateConstituentaInput, type EvaluateExpressionInput, type EvaluationResult, type ListDiagnosticsFilters, type ModelValueState, PORTAL_JSON_CONTRACT_VERSION, type PortalImportMetadata, type PortalModelImportData, type PortalSchemaConstituenta, type PortalSchemaImportData, type PortalTermForm, RSErrorCode, RSToolAgent, type RSToolAgentContract, type RSToolErrorDescription, type RSToolValue, RSToolWrapperClient, type RSToolWrapperClientOptions, type RecalculateModelResult, type SessionHandle, type SessionModelState, type SessionRevision, type SessionState, type SetConstituentaValueInput, type SetConstituentaValuesInput, ValueClass, type WrapperResponse, toPublicAnalysis, toPublicError };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toPublicAnalysis, toPublicError } from "./mappers/types.js";
|
|
2
2
|
import { CstType, EvalStatus, RSErrorCode, ValueClass } from "./models/common.js";
|
|
3
|
+
import { n as PORTAL_JSON_CONTRACT_VERSION, t as RSToolAgent } from "./rstool-agent-BZi5jO1y.js";
|
|
3
4
|
import { CONTRACT_VERSION } from "./models/tool-contract.js";
|
|
4
|
-
import { RSToolAgent } from "./models/rstool-agent.js";
|
|
5
5
|
import "./models/index.js";
|
|
6
6
|
import { RSToolWrapperClient } from "./wrapper/client.js";
|
|
7
|
-
export { CONTRACT_VERSION, CstType, EvalStatus, RSErrorCode, RSToolAgent, RSToolWrapperClient, ValueClass, toPublicAnalysis, toPublicError };
|
|
7
|
+
export { CONTRACT_VERSION, CstType, EvalStatus, PORTAL_JSON_CONTRACT_VERSION, RSErrorCode, RSToolAgent, RSToolWrapperClient, ValueClass, toPublicAnalysis, toPublicError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as EvaluationResult } from "../evaluation-CCVYH0wA.js";
|
|
2
2
|
import { a as SetConstituentaValueInput, i as SessionModelState, r as RecalculateModelResult } from "../model-value-SFAVj0dw.js";
|
|
3
|
-
import { r as SessionState } from "../session-
|
|
3
|
+
import { r as SessionState } from "../session-BPgsE80c.js";
|
|
4
4
|
import { CstType } from "@rsconcept/domain/library/rsform";
|
|
5
5
|
import { RSEngine } from "@rsconcept/domain/library/rsengine";
|
|
6
6
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as AnalysisResult } from "../analysis-JiwOYDKx.js";
|
|
2
2
|
import { t as DiagnosticRecord } from "../diagnostic-BMYvciz8.js";
|
|
3
3
|
import { i as ConstituentaState, r as ConstituentaDraft } from "../constituenta-Dnd6iToB.js";
|
|
4
|
-
import { r as SessionState } from "../session-
|
|
4
|
+
import { r as SessionState } from "../session-BPgsE80c.js";
|
|
5
5
|
import { RSForm } from "@rsconcept/domain/library/rsform";
|
|
6
6
|
import { RSLangAnalyzer } from "@rsconcept/domain/rslang";
|
|
7
7
|
|
package/dist/models/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { n as ListDiagnosticsFilters, t as DiagnosticRecord } from "../diagnosti
|
|
|
4
4
|
import { i as ConstituentaState, n as AddOrUpdateConstituentaResult, r as ConstituentaDraft, t as AddOrUpdateConstituentaInput } from "../constituenta-Dnd6iToB.js";
|
|
5
5
|
import { n as EvaluateExpressionInput, r as EvaluationResult, t as EvaluateConstituentaInput } from "../evaluation-CCVYH0wA.js";
|
|
6
6
|
import { a as SetConstituentaValueInput, i as SessionModelState, n as ModelValueState, o as SetConstituentaValuesInput, r as RecalculateModelResult, t as ClearConstituentaValuesInput } from "../model-value-SFAVj0dw.js";
|
|
7
|
-
import { n as
|
|
8
|
-
import { n as
|
|
9
|
-
import { t as
|
|
10
|
-
|
|
7
|
+
import { a as PortalSchemaImportData, i as PortalSchemaConstituenta, n as PortalImportMetadata, o as PortalTermForm, r as PortalModelImportData, t as PORTAL_JSON_CONTRACT_VERSION } from "../index-uhkmwruf.js";
|
|
8
|
+
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "../session-BPgsE80c.js";
|
|
9
|
+
import { n as RSToolAgentContract, t as CONTRACT_VERSION } from "../tool-contract-n1ghUOrK.js";
|
|
10
|
+
import { t as RSToolAgent } from "../rstool-agent-pRaPnZay.js";
|
|
11
|
+
export { type AddOrUpdateConstituentaInput, type AddOrUpdateConstituentaResult, type AnalysisResult, type AnalyzeExpressionInput, type BasicBinding, CONTRACT_VERSION, type ClearConstituentaValuesInput, type ConstituentaDraft, type ConstituentaState, CstType, type DiagnosticRecord, EvalStatus, type EvaluateConstituentaInput, type EvaluateExpressionInput, type EvaluationResult, type ListDiagnosticsFilters, type ModelValueState, PORTAL_JSON_CONTRACT_VERSION, type PortalImportMetadata, type PortalModelImportData, type PortalSchemaConstituenta, type PortalSchemaImportData, type PortalTermForm, RSErrorCode, RSToolAgent, type RSToolAgentContract, type RSToolErrorDescription, type RSToolValue, type RecalculateModelResult, type SessionHandle, type SessionModelState, type SessionRevision, type SessionState, type SetConstituentaValueInput, type SetConstituentaValuesInput, ValueClass };
|
package/dist/models/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CstType, EvalStatus, RSErrorCode, ValueClass } from "./common.js";
|
|
2
|
+
import { n as PORTAL_JSON_CONTRACT_VERSION, t as RSToolAgent } from "../rstool-agent-BZi5jO1y.js";
|
|
2
3
|
import { CONTRACT_VERSION } from "./tool-contract.js";
|
|
3
|
-
|
|
4
|
-
export { CONTRACT_VERSION, CstType, EvalStatus, RSErrorCode, RSToolAgent, ValueClass };
|
|
4
|
+
export { CONTRACT_VERSION, CstType, EvalStatus, PORTAL_JSON_CONTRACT_VERSION, RSErrorCode, RSToolAgent, ValueClass };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as RSToolAgent } from "../rstool-agent-
|
|
1
|
+
import { t as RSToolAgent } from "../rstool-agent-pRaPnZay.js";
|
|
2
2
|
export { RSToolAgent };
|
|
@@ -1,93 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SchemaAdapter } from "../mappers/schema-adapter.js";
|
|
3
|
-
import { SessionStore } from "../session/session-store.js";
|
|
4
|
-
import { CONTRACT_VERSION } from "./tool-contract.js";
|
|
5
|
-
//#region src/models/rstool-agent.ts
|
|
6
|
-
var RSToolAgent = class {
|
|
7
|
-
contractVersion = CONTRACT_VERSION;
|
|
8
|
-
sessions = new SessionStore();
|
|
9
|
-
adapter = new SchemaAdapter();
|
|
10
|
-
evaluation = new ModelAdapter();
|
|
11
|
-
createSession(initial) {
|
|
12
|
-
return this.sessions.create(initial, this.contractVersion);
|
|
13
|
-
}
|
|
14
|
-
addOrUpdateConstituenta(sessionId, input) {
|
|
15
|
-
const envelope = this.sessions.get(sessionId);
|
|
16
|
-
const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, input.draft);
|
|
17
|
-
const state = this.adapter.mergeStateWithDraft(envelope.state, input.draft, result);
|
|
18
|
-
this.sessions.appendDiagnostics(sessionId, diagnostics);
|
|
19
|
-
return {
|
|
20
|
-
state,
|
|
21
|
-
diagnostics
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
analyzeExpression(sessionId, input) {
|
|
25
|
-
const envelope = this.sessions.get(sessionId);
|
|
26
|
-
const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, {
|
|
27
|
-
id: -1,
|
|
28
|
-
alias: "_analysis",
|
|
29
|
-
cstType: input.cstType,
|
|
30
|
-
definitionFormal: input.expression
|
|
31
|
-
});
|
|
32
|
-
this.sessions.appendDiagnostics(sessionId, diagnostics.map((item) => ({
|
|
33
|
-
...item,
|
|
34
|
-
constituentId: void 0
|
|
35
|
-
})));
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
getFormState(sessionId) {
|
|
39
|
-
const envelope = this.sessions.get(sessionId);
|
|
40
|
-
return structuredClone(envelope.state);
|
|
41
|
-
}
|
|
42
|
-
listDiagnostics(sessionId, filters) {
|
|
43
|
-
return this.sessions.listDiagnostics(sessionId, filters);
|
|
44
|
-
}
|
|
45
|
-
commitStep(sessionId, message) {
|
|
46
|
-
return this.sessions.addRevision(sessionId, message);
|
|
47
|
-
}
|
|
48
|
-
exportSession(sessionId) {
|
|
49
|
-
const envelope = this.sessions.get(sessionId);
|
|
50
|
-
return JSON.stringify({
|
|
51
|
-
contractVersion: this.contractVersion,
|
|
52
|
-
state: envelope.state,
|
|
53
|
-
diagnostics: envelope.diagnostics
|
|
54
|
-
}, null, 2);
|
|
55
|
-
}
|
|
56
|
-
importSession(payload) {
|
|
57
|
-
const parsed = JSON.parse(payload);
|
|
58
|
-
if (!parsed.state.model) parsed.state.model = { items: [] };
|
|
59
|
-
return this.sessions.create(parsed.state, this.contractVersion);
|
|
60
|
-
}
|
|
61
|
-
async setConstituentaValue(sessionId, input) {
|
|
62
|
-
const envelope = this.sessions.get(sessionId);
|
|
63
|
-
return this.evaluation.setConstituentaValue(envelope.state, input);
|
|
64
|
-
}
|
|
65
|
-
async setConstituentaValues(sessionId, input) {
|
|
66
|
-
const envelope = this.sessions.get(sessionId);
|
|
67
|
-
return this.evaluation.setConstituentaValues(envelope.state, input);
|
|
68
|
-
}
|
|
69
|
-
async clearConstituentaValues(sessionId, input) {
|
|
70
|
-
const envelope = this.sessions.get(sessionId);
|
|
71
|
-
return this.evaluation.clearConstituentaValues(envelope.state, input.items);
|
|
72
|
-
}
|
|
73
|
-
getModelState(sessionId) {
|
|
74
|
-
const envelope = this.sessions.get(sessionId);
|
|
75
|
-
return structuredClone(envelope.state.model);
|
|
76
|
-
}
|
|
77
|
-
evaluateExpression(sessionId, input) {
|
|
78
|
-
const envelope = this.sessions.get(sessionId);
|
|
79
|
-
return this.evaluation.evaluateExpression(envelope.state, input.expression, input.cstType);
|
|
80
|
-
}
|
|
81
|
-
evaluateConstituenta(sessionId, input) {
|
|
82
|
-
const envelope = this.sessions.get(sessionId);
|
|
83
|
-
return this.evaluation.evaluateConstituenta(envelope.state, input.constituentId);
|
|
84
|
-
}
|
|
85
|
-
recalculateModel(sessionId) {
|
|
86
|
-
const envelope = this.sessions.get(sessionId);
|
|
87
|
-
return this.evaluation.recalculateModel(envelope.state);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
//#endregion
|
|
1
|
+
import { t as RSToolAgent } from "../rstool-agent-BZi5jO1y.js";
|
|
91
2
|
export { RSToolAgent };
|
|
92
|
-
|
|
93
|
-
//# sourceMappingURL=rstool-agent.js.map
|
package/dist/models/session.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "../session-
|
|
1
|
+
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "../session-BPgsE80c.js";
|
|
2
2
|
export { SessionHandle, SessionRevision, SessionState };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as RSToolAgentContract, t as CONTRACT_VERSION } from "../tool-contract-
|
|
1
|
+
import { n as RSToolAgentContract, t as CONTRACT_VERSION } from "../tool-contract-n1ghUOrK.js";
|
|
2
2
|
export { CONTRACT_VERSION, RSToolAgentContract };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-contract.js","names":[],"sources":["../../src/models/tool-contract.ts"],"sourcesContent":["import { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';\nimport {\n type AddOrUpdateConstituentaInput,\n type AddOrUpdateConstituentaResult\n} from './constituenta';\nimport {\n type DiagnosticRecord,\n type ListDiagnosticsFilters\n} from './diagnostic';\nimport {\n type EvaluateConstituentaInput,\n type EvaluateExpressionInput,\n type EvaluationResult\n} from './evaluation';\nimport {\n type ClearConstituentaValuesInput,\n type RecalculateModelResult,\n type SessionModelState,\n type SetConstituentaValueInput,\n type SetConstituentaValuesInput\n} from './model-value';\nimport {\n type SessionHandle,\n type SessionRevision,\n type SessionState\n} from './session';\n\nexport const CONTRACT_VERSION = '1.
|
|
1
|
+
{"version":3,"file":"tool-contract.js","names":[],"sources":["../../src/models/tool-contract.ts"],"sourcesContent":["import { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';\nimport {\n type AddOrUpdateConstituentaInput,\n type AddOrUpdateConstituentaResult\n} from './constituenta';\nimport {\n type DiagnosticRecord,\n type ListDiagnosticsFilters\n} from './diagnostic';\nimport {\n type EvaluateConstituentaInput,\n type EvaluateExpressionInput,\n type EvaluationResult\n} from './evaluation';\nimport {\n type ClearConstituentaValuesInput,\n type RecalculateModelResult,\n type SessionModelState,\n type SetConstituentaValueInput,\n type SetConstituentaValuesInput\n} from './model-value';\nimport {\n type SessionHandle,\n type SessionRevision,\n type SessionState\n} from './session';\n\nexport const CONTRACT_VERSION = '1.4.0';\n\nexport interface RSToolAgentContract {\n readonly contractVersion: string;\n createSession(initial?: Partial<SessionState>): SessionHandle;\n addOrUpdateConstituenta(sessionId: string, input: AddOrUpdateConstituentaInput): AddOrUpdateConstituentaResult;\n analyzeExpression(sessionId: string, input: AnalyzeExpressionInput): AnalysisResult;\n getFormState(sessionId: string): SessionState;\n listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[];\n commitStep(sessionId: string, message?: string): SessionRevision;\n exportSession(sessionId: string): string;\n exportPortalSchema(sessionId: string): string;\n exportPortalModel(sessionId: string): string;\n importSession(payload: string): SessionHandle;\n setConstituentaValue(sessionId: string, input: SetConstituentaValueInput): Promise<SessionModelState>;\n setConstituentaValues(sessionId: string, input: SetConstituentaValuesInput): Promise<SessionModelState>;\n clearConstituentaValues(sessionId: string, input: ClearConstituentaValuesInput): Promise<SessionModelState>;\n getModelState(sessionId: string): SessionModelState;\n evaluateExpression(sessionId: string, input: EvaluateExpressionInput): EvaluationResult;\n evaluateConstituenta(sessionId: string, input: EvaluateConstituentaInput): EvaluationResult;\n recalculateModel(sessionId: string): RecalculateModelResult;\n}\n"],"mappings":";AA2BA,MAAa,mBAAmB"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { ModelAdapter } from "./mappers/model-adapter.js";
|
|
2
|
+
import { SchemaAdapter } from "./mappers/schema-adapter.js";
|
|
3
|
+
import { SessionStore } from "./session/session-store.js";
|
|
4
|
+
import { CONTRACT_VERSION } from "./models/tool-contract.js";
|
|
5
|
+
//#region src/models/portal-json.ts
|
|
6
|
+
/** Portal JSON import/export format version (schema and model files). */
|
|
7
|
+
const PORTAL_JSON_CONTRACT_VERSION = "1.0.0";
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/models/rstool-agent.ts
|
|
10
|
+
function normalizeImportedState(state) {
|
|
11
|
+
return {
|
|
12
|
+
...state,
|
|
13
|
+
alias: state.alias ?? "",
|
|
14
|
+
title: state.title ?? "",
|
|
15
|
+
comment: state.comment ?? "",
|
|
16
|
+
model: state.model ?? { items: [] }
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function portalImportMetadata(session, kind) {
|
|
20
|
+
const defaults = kind === "schema" ? {
|
|
21
|
+
title: "Conceptual schema",
|
|
22
|
+
alias: "SCHEMA"
|
|
23
|
+
} : {
|
|
24
|
+
title: "Conceptual model",
|
|
25
|
+
alias: "MODEL"
|
|
26
|
+
};
|
|
27
|
+
const title = session.title.trim();
|
|
28
|
+
const alias = session.alias.trim();
|
|
29
|
+
return {
|
|
30
|
+
title: title.length > 0 ? title : defaults.title,
|
|
31
|
+
alias: alias.length > 0 ? alias : defaults.alias,
|
|
32
|
+
description: session.comment.trim()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var RSToolAgent = class {
|
|
36
|
+
contractVersion = CONTRACT_VERSION;
|
|
37
|
+
sessions = new SessionStore();
|
|
38
|
+
adapter = new SchemaAdapter();
|
|
39
|
+
evaluation = new ModelAdapter();
|
|
40
|
+
createSession(initial) {
|
|
41
|
+
return this.sessions.create(initial, this.contractVersion);
|
|
42
|
+
}
|
|
43
|
+
addOrUpdateConstituenta(sessionId, input) {
|
|
44
|
+
const envelope = this.sessions.get(sessionId);
|
|
45
|
+
const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, input.draft);
|
|
46
|
+
const state = this.adapter.mergeStateWithDraft(envelope.state, input.draft, result);
|
|
47
|
+
this.sessions.appendDiagnostics(sessionId, diagnostics);
|
|
48
|
+
return {
|
|
49
|
+
state,
|
|
50
|
+
diagnostics
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
analyzeExpression(sessionId, input) {
|
|
54
|
+
const envelope = this.sessions.get(sessionId);
|
|
55
|
+
const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, {
|
|
56
|
+
id: -1,
|
|
57
|
+
alias: "_analysis",
|
|
58
|
+
cstType: input.cstType,
|
|
59
|
+
definitionFormal: input.expression
|
|
60
|
+
});
|
|
61
|
+
this.sessions.appendDiagnostics(sessionId, diagnostics.map((item) => ({
|
|
62
|
+
...item,
|
|
63
|
+
constituentId: void 0
|
|
64
|
+
})));
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
getFormState(sessionId) {
|
|
68
|
+
const envelope = this.sessions.get(sessionId);
|
|
69
|
+
return structuredClone(envelope.state);
|
|
70
|
+
}
|
|
71
|
+
listDiagnostics(sessionId, filters) {
|
|
72
|
+
return this.sessions.listDiagnostics(sessionId, filters);
|
|
73
|
+
}
|
|
74
|
+
commitStep(sessionId, message) {
|
|
75
|
+
return this.sessions.addRevision(sessionId, message);
|
|
76
|
+
}
|
|
77
|
+
exportSession(sessionId) {
|
|
78
|
+
const envelope = this.sessions.get(sessionId);
|
|
79
|
+
return JSON.stringify({
|
|
80
|
+
contractVersion: this.contractVersion,
|
|
81
|
+
state: envelope.state,
|
|
82
|
+
diagnostics: envelope.diagnostics
|
|
83
|
+
}, null, 2);
|
|
84
|
+
}
|
|
85
|
+
exportPortalSchema(sessionId) {
|
|
86
|
+
const envelope = this.sessions.get(sessionId);
|
|
87
|
+
const payload = {
|
|
88
|
+
contract_version: PORTAL_JSON_CONTRACT_VERSION,
|
|
89
|
+
...portalImportMetadata(envelope.state, "schema"),
|
|
90
|
+
items: envelope.state.items.map((item) => ({
|
|
91
|
+
id: item.id,
|
|
92
|
+
alias: item.alias,
|
|
93
|
+
convention: item.convention,
|
|
94
|
+
crucial: false,
|
|
95
|
+
cst_type: item.cstType,
|
|
96
|
+
definition_formal: item.definitionFormal,
|
|
97
|
+
typification_manual: "",
|
|
98
|
+
value_is_property: false,
|
|
99
|
+
definition_raw: item.definitionText,
|
|
100
|
+
definition_resolved: item.definitionText,
|
|
101
|
+
term_raw: item.term,
|
|
102
|
+
term_resolved: item.term,
|
|
103
|
+
term_forms: []
|
|
104
|
+
})),
|
|
105
|
+
attribution: []
|
|
106
|
+
};
|
|
107
|
+
return JSON.stringify(payload, null, 2);
|
|
108
|
+
}
|
|
109
|
+
exportPortalModel(sessionId) {
|
|
110
|
+
const envelope = this.sessions.get(sessionId);
|
|
111
|
+
const payload = {
|
|
112
|
+
contract_version: PORTAL_JSON_CONTRACT_VERSION,
|
|
113
|
+
...portalImportMetadata(envelope.state, "model"),
|
|
114
|
+
items: envelope.state.model.items.map((item) => ({
|
|
115
|
+
id: item.id,
|
|
116
|
+
type: item.type,
|
|
117
|
+
value: item.value
|
|
118
|
+
}))
|
|
119
|
+
};
|
|
120
|
+
return JSON.stringify(payload, null, 2);
|
|
121
|
+
}
|
|
122
|
+
importSession(payload) {
|
|
123
|
+
const parsed = JSON.parse(payload);
|
|
124
|
+
return this.sessions.create(normalizeImportedState(parsed.state), this.contractVersion);
|
|
125
|
+
}
|
|
126
|
+
async setConstituentaValue(sessionId, input) {
|
|
127
|
+
const envelope = this.sessions.get(sessionId);
|
|
128
|
+
return this.evaluation.setConstituentaValue(envelope.state, input);
|
|
129
|
+
}
|
|
130
|
+
async setConstituentaValues(sessionId, input) {
|
|
131
|
+
const envelope = this.sessions.get(sessionId);
|
|
132
|
+
return this.evaluation.setConstituentaValues(envelope.state, input);
|
|
133
|
+
}
|
|
134
|
+
async clearConstituentaValues(sessionId, input) {
|
|
135
|
+
const envelope = this.sessions.get(sessionId);
|
|
136
|
+
return this.evaluation.clearConstituentaValues(envelope.state, input.items);
|
|
137
|
+
}
|
|
138
|
+
getModelState(sessionId) {
|
|
139
|
+
const envelope = this.sessions.get(sessionId);
|
|
140
|
+
return structuredClone(envelope.state.model);
|
|
141
|
+
}
|
|
142
|
+
evaluateExpression(sessionId, input) {
|
|
143
|
+
const envelope = this.sessions.get(sessionId);
|
|
144
|
+
return this.evaluation.evaluateExpression(envelope.state, input.expression, input.cstType);
|
|
145
|
+
}
|
|
146
|
+
evaluateConstituenta(sessionId, input) {
|
|
147
|
+
const envelope = this.sessions.get(sessionId);
|
|
148
|
+
return this.evaluation.evaluateConstituenta(envelope.state, input.constituentId);
|
|
149
|
+
}
|
|
150
|
+
recalculateModel(sessionId) {
|
|
151
|
+
const envelope = this.sessions.get(sessionId);
|
|
152
|
+
return this.evaluation.recalculateModel(envelope.state);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
//#endregion
|
|
156
|
+
export { PORTAL_JSON_CONTRACT_VERSION as n, RSToolAgent as t };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=rstool-agent-BZi5jO1y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rstool-agent-BZi5jO1y.js","names":[],"sources":["../src/models/portal-json.ts","../src/models/rstool-agent.ts"],"sourcesContent":["import { type BasicBinding, type RSToolValue } from './common';\n\n/** Portal JSON import/export format version (schema and model files). */\nexport const PORTAL_JSON_CONTRACT_VERSION = '1.0.0';\n\nexport interface PortalImportMetadata {\n contract_version: string;\n title: string;\n alias: string;\n description: string;\n}\n\nexport interface PortalTermForm {\n text: string;\n tags: string;\n}\n\nexport interface PortalSchemaConstituenta {\n id: number;\n alias: string;\n convention: string;\n crucial: boolean;\n cst_type: string;\n definition_formal: string;\n typification_manual: string;\n value_is_property: boolean;\n definition_raw: string;\n definition_resolved: string;\n term_raw: string;\n term_resolved: string;\n term_forms: PortalTermForm[];\n}\n\nexport interface PortalSchemaImportData extends PortalImportMetadata {\n items: PortalSchemaConstituenta[];\n attribution: Array<{ container: number; attribute: number }>;\n}\n\nexport interface PortalModelImportData extends PortalImportMetadata {\n items: Array<{\n id: number;\n type: string;\n value: RSToolValue | BasicBinding;\n }>;\n}\n","import { ModelAdapter } from '../mappers/model-adapter';\nimport { SchemaAdapter } from '../mappers/schema-adapter';\nimport { SessionStore } from '../session/session-store';\nimport { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';\nimport {\n type AddOrUpdateConstituentaInput,\n type AddOrUpdateConstituentaResult\n} from './constituenta';\nimport { type ListDiagnosticsFilters } from './diagnostic';\nimport {\n type EvaluateConstituentaInput,\n type EvaluateExpressionInput,\n type EvaluationResult\n} from './evaluation';\nimport {\n type ClearConstituentaValuesInput,\n type RecalculateModelResult,\n type SessionModelState,\n type SetConstituentaValueInput,\n type SetConstituentaValuesInput\n} from './model-value';\nimport {\n PORTAL_JSON_CONTRACT_VERSION,\n type PortalModelImportData,\n type PortalSchemaImportData\n} from './portal-json';\nimport { type SessionHandle, type SessionRevision, type SessionState } from './session';\nimport { CONTRACT_VERSION, type RSToolAgentContract } from './tool-contract';\n\nfunction normalizeImportedState(state: SessionState): SessionState {\n return {\n ...state,\n alias: state.alias ?? '',\n title: state.title ?? '',\n comment: state.comment ?? '',\n model: state.model ?? { items: [] }\n };\n}\n\nfunction portalImportMetadata(\n session: SessionState,\n kind: 'schema' | 'model'\n): Pick<PortalSchemaImportData, 'title' | 'alias' | 'description'> {\n const defaults =\n kind === 'schema'\n ? { title: 'Conceptual schema', alias: 'SCHEMA' }\n : { title: 'Conceptual model', alias: 'MODEL' };\n const title = session.title.trim();\n const alias = session.alias.trim();\n return {\n title: title.length > 0 ? title : defaults.title,\n alias: alias.length > 0 ? alias : defaults.alias,\n description: session.comment.trim()\n };\n}\n\nexport class RSToolAgent implements RSToolAgentContract {\n public readonly contractVersion = CONTRACT_VERSION;\n private readonly sessions = new SessionStore();\n private readonly adapter = new SchemaAdapter();\n private readonly evaluation = new ModelAdapter();\n\n public createSession(initial?: Partial<SessionState>): SessionHandle {\n return this.sessions.create(initial, this.contractVersion);\n }\n\n public addOrUpdateConstituenta(\n sessionId: string,\n input: AddOrUpdateConstituentaInput\n ): AddOrUpdateConstituentaResult {\n const envelope = this.sessions.get(sessionId);\n const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, input.draft);\n const state = this.adapter.mergeStateWithDraft(envelope.state, input.draft, result);\n this.sessions.appendDiagnostics(sessionId, diagnostics);\n return {\n state,\n diagnostics\n };\n }\n\n public analyzeExpression(sessionId: string, input: AnalyzeExpressionInput): AnalysisResult {\n const envelope = this.sessions.get(sessionId);\n const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, {\n id: -1,\n alias: '_analysis',\n cstType: input.cstType,\n definitionFormal: input.expression\n });\n this.sessions.appendDiagnostics(\n sessionId,\n diagnostics.map(item => ({ ...item, constituentId: undefined }))\n );\n return result;\n }\n\n public getFormState(sessionId: string): SessionState {\n const envelope = this.sessions.get(sessionId);\n return structuredClone(envelope.state);\n }\n\n public listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters) {\n return this.sessions.listDiagnostics(sessionId, filters);\n }\n\n public commitStep(sessionId: string, message?: string): SessionRevision {\n return this.sessions.addRevision(sessionId, message);\n }\n\n public exportSession(sessionId: string): string {\n const envelope = this.sessions.get(sessionId);\n return JSON.stringify(\n {\n contractVersion: this.contractVersion,\n state: envelope.state,\n diagnostics: envelope.diagnostics\n },\n null,\n 2\n );\n }\n\n public exportPortalSchema(sessionId: string): string {\n const envelope = this.sessions.get(sessionId);\n const payload: PortalSchemaImportData = {\n contract_version: PORTAL_JSON_CONTRACT_VERSION,\n ...portalImportMetadata(envelope.state, 'schema'),\n items: envelope.state.items.map(item => ({\n id: item.id,\n alias: item.alias,\n convention: item.convention,\n crucial: false,\n cst_type: item.cstType,\n definition_formal: item.definitionFormal,\n typification_manual: '',\n value_is_property: false,\n definition_raw: item.definitionText,\n definition_resolved: item.definitionText,\n term_raw: item.term,\n term_resolved: item.term,\n term_forms: []\n })),\n attribution: []\n };\n return JSON.stringify(payload, null, 2);\n }\n\n public exportPortalModel(sessionId: string): string {\n const envelope = this.sessions.get(sessionId);\n const payload: PortalModelImportData = {\n contract_version: PORTAL_JSON_CONTRACT_VERSION,\n ...portalImportMetadata(envelope.state, 'model'),\n items: envelope.state.model.items.map(item => ({\n id: item.id,\n type: item.type,\n value: item.value\n }))\n };\n return JSON.stringify(payload, null, 2);\n }\n\n public importSession(payload: string): SessionHandle {\n const parsed = JSON.parse(payload) as {\n state: SessionState;\n };\n return this.sessions.create(normalizeImportedState(parsed.state), this.contractVersion);\n }\n\n public async setConstituentaValue(\n sessionId: string,\n input: SetConstituentaValueInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.setConstituentaValue(envelope.state, input);\n }\n\n public async setConstituentaValues(\n sessionId: string,\n input: SetConstituentaValuesInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.setConstituentaValues(envelope.state, input);\n }\n\n public async clearConstituentaValues(\n sessionId: string,\n input: ClearConstituentaValuesInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.clearConstituentaValues(envelope.state, input.items);\n }\n\n public getModelState(sessionId: string): SessionModelState {\n const envelope = this.sessions.get(sessionId);\n return structuredClone(envelope.state.model);\n }\n\n public evaluateExpression(sessionId: string, input: EvaluateExpressionInput): EvaluationResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.evaluateExpression(envelope.state, input.expression, input.cstType);\n }\n\n public evaluateConstituenta(sessionId: string, input: EvaluateConstituentaInput): EvaluationResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.evaluateConstituenta(envelope.state, input.constituentId);\n }\n\n public recalculateModel(sessionId: string): RecalculateModelResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.recalculateModel(envelope.state);\n }\n}\n"],"mappings":";;;;;;AAGA,MAAa,+BAA+B;;;AC0B5C,SAAS,uBAAuB,OAAmC;CACjE,OAAO;EACL,GAAG;EACH,OAAO,MAAM,SAAS;EACtB,OAAO,MAAM,SAAS;EACtB,SAAS,MAAM,WAAW;EAC1B,OAAO,MAAM,SAAS,EAAE,OAAO,CAAC,EAAE;CACpC;AACF;AAEA,SAAS,qBACP,SACA,MACiE;CACjE,MAAM,WACJ,SAAS,WACL;EAAE,OAAO;EAAqB,OAAO;CAAS,IAC9C;EAAE,OAAO;EAAoB,OAAO;CAAQ;CAClD,MAAM,QAAQ,QAAQ,MAAM,KAAK;CACjC,MAAM,QAAQ,QAAQ,MAAM,KAAK;CACjC,OAAO;EACL,OAAO,MAAM,SAAS,IAAI,QAAQ,SAAS;E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AAW,sBAAsB,SAAS,OAAO,KAAK;CACpE;CAEA,MAAa,wBACX,WACA,OAC4B;EAC5B,MAAM,WAAW,KAAK,SAAS,IAAI,SAAS;EAC5C,OAAO,KAAK,WAAW,wBAAwB,SAAS,OAAO,MAAM,KAAK;CAC5E;CAEA,cAAqB,WAAsC;EACzD,MAAM,WAAW,KAAK,SAAS,IAAI,SAAS;EAC5C,OAAO,gBAAgB,SAAS,MAAM,KAAK;CAC7C;CAEA,mBAA0B,WAAmB,OAAkD;EAC7F,MAAM,WAAW,KAAK,SAAS,IAAI,SAAS;EAC5C,OAAO,KAAK,WAAW,mBAAmB,SAAS,OAAO,MAAM,YAAY,MAAM,OAAO;CAC3F;CAEA,qBAA4B,WAAmB,OAAoD;EACjG,MAAM,WAAW,KAAK,SAAS,IAAI,SAAS;EAC5C,OAAO,KAAK,WAAW,qBAAqB,SAAS,OAAO,MAAM,aAAa;CACjF;CAEA,iBAAwB,WAA2C;EACjE,MAAM,WAAW,KAAK,SAAS,IAAI,SAAS;EAC5C,OAAO,KAAK,WAAW,iBAAiB,SAAS,KAAK;CACxD;AACF"}
|
|
@@ -3,12 +3,12 @@ import { n as ListDiagnosticsFilters, t as DiagnosticRecord } from "./diagnostic
|
|
|
3
3
|
import { n as AddOrUpdateConstituentaResult, t as AddOrUpdateConstituentaInput } from "./constituenta-Dnd6iToB.js";
|
|
4
4
|
import { n as EvaluateExpressionInput, r as EvaluationResult, t as EvaluateConstituentaInput } from "./evaluation-CCVYH0wA.js";
|
|
5
5
|
import { a as SetConstituentaValueInput, i as SessionModelState, o as SetConstituentaValuesInput, r as RecalculateModelResult, t as ClearConstituentaValuesInput } from "./model-value-SFAVj0dw.js";
|
|
6
|
-
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "./session-
|
|
7
|
-
import { n as RSToolAgentContract } from "./tool-contract-
|
|
6
|
+
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "./session-BPgsE80c.js";
|
|
7
|
+
import { n as RSToolAgentContract } from "./tool-contract-n1ghUOrK.js";
|
|
8
8
|
|
|
9
9
|
//#region src/models/rstool-agent.d.ts
|
|
10
10
|
declare class RSToolAgent implements RSToolAgentContract {
|
|
11
|
-
readonly contractVersion = "1.
|
|
11
|
+
readonly contractVersion = "1.4.0";
|
|
12
12
|
private readonly sessions;
|
|
13
13
|
private readonly adapter;
|
|
14
14
|
private readonly evaluation;
|
|
@@ -19,6 +19,8 @@ declare class RSToolAgent implements RSToolAgentContract {
|
|
|
19
19
|
listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[];
|
|
20
20
|
commitStep(sessionId: string, message?: string): SessionRevision;
|
|
21
21
|
exportSession(sessionId: string): string;
|
|
22
|
+
exportPortalSchema(sessionId: string): string;
|
|
23
|
+
exportPortalModel(sessionId: string): string;
|
|
22
24
|
importSession(payload: string): SessionHandle;
|
|
23
25
|
setConstituentaValue(sessionId: string, input: SetConstituentaValueInput): Promise<SessionModelState>;
|
|
24
26
|
setConstituentaValues(sessionId: string, input: SetConstituentaValuesInput): Promise<SessionModelState>;
|
|
@@ -30,4 +32,4 @@ declare class RSToolAgent implements RSToolAgentContract {
|
|
|
30
32
|
}
|
|
31
33
|
//#endregion
|
|
32
34
|
export { RSToolAgent as t };
|
|
33
|
-
//# sourceMappingURL=rstool-agent-
|
|
35
|
+
//# sourceMappingURL=rstool-agent-pRaPnZay.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { n as ListDiagnosticsFilters, t as DiagnosticRecord } from "../diagnostic-BMYvciz8.js";
|
|
2
|
-
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "../session-
|
|
2
|
+
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "../session-BPgsE80c.js";
|
|
3
|
+
|
|
3
4
|
//#region src/session/session-store.d.ts
|
|
4
5
|
interface SessionEnvelope {
|
|
5
6
|
state: SessionState;
|
|
@@ -7,6 +7,9 @@ var SessionStore = class {
|
|
|
7
7
|
const sessionId = initial?.sessionId ?? randomUUID();
|
|
8
8
|
const state = {
|
|
9
9
|
sessionId,
|
|
10
|
+
alias: initial?.alias ?? "",
|
|
11
|
+
title: initial?.title ?? "",
|
|
12
|
+
comment: initial?.comment ?? "",
|
|
10
13
|
createdAt: initial?.createdAt ?? now,
|
|
11
14
|
updatedAt: now,
|
|
12
15
|
revisions: initial?.revisions ?? [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-store.js","names":[],"sources":["../../src/session/session-store.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport {\n type DiagnosticRecord,\n type ListDiagnosticsFilters,\n type SessionHandle,\n type SessionRevision,\n type SessionState\n} from '../models';\n\ninterface SessionEnvelope {\n state: SessionState;\n diagnostics: DiagnosticRecord[];\n}\n\nexport class SessionStore {\n private sessions = new Map<string, SessionEnvelope>();\n\n public create(initial?: Partial<SessionState>, contractVersion?: string): SessionHandle {\n const now = new Date().toISOString();\n const sessionId = initial?.sessionId ?? randomUUID();\n const state: SessionState = {\n sessionId,\n createdAt: initial?.createdAt ?? now,\n updatedAt: now,\n revisions: initial?.revisions ?? [],\n items: initial?.items ?? [],\n model: initial?.model ?? { items: [] }\n };\n this.sessions.set(sessionId, {\n state,\n diagnostics: []\n });\n return {\n sessionId,\n contractVersion: contractVersion ?? '1.0.0'\n };\n }\n\n public get(sessionId: string): SessionEnvelope {\n const found = this.sessions.get(sessionId);\n if (!found) {\n throw new Error(`Unknown session: ${sessionId}`);\n }\n return found;\n }\n\n public replaceState(sessionId: string, nextState: SessionState): void {\n const found = this.get(sessionId);\n found.state = {\n ...nextState,\n updatedAt: new Date().toISOString()\n };\n }\n\n public addRevision(sessionId: string, message?: string): SessionRevision {\n const found = this.get(sessionId);\n const revision: SessionRevision = {\n revisionId: randomUUID(),\n at: new Date().toISOString(),\n message\n };\n found.state.revisions.push(revision);\n found.state.updatedAt = revision.at;\n return revision;\n }\n\n public appendDiagnostics(sessionId: string, records: DiagnosticRecord[]): void {\n const found = this.get(sessionId);\n found.diagnostics.push(...records);\n found.state.updatedAt = new Date().toISOString();\n }\n\n public listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[] {\n const found = this.get(sessionId);\n if (!filters?.constituentId) {\n return [...found.diagnostics];\n }\n return found.diagnostics.filter(record => record.constituentId === filters.constituentId);\n }\n}\n"],"mappings":";;AAeA,IAAa,eAAb,MAA0B;CACxB,2BAAmB,IAAI,IAA6B;CAEpD,OAAc,SAAiC,iBAAyC;EACtF,MAAM,uBAAM,IAAI,KAAK,GAAE,YAAY;EACnC,MAAM,YAAY,SAAS,aAAa,WAAW;EACnD,MAAM,QAAsB;GAC1B;GACA,WAAW,SAAS,aAAa;GACjC,WAAW;GACX,WAAW,SAAS,aAAa,CAAC;GAClC,OAAO,SAAS,SAAS,CAAC;GAC1B,OAAO,SAAS,SAAS,EAAE,OAAO,CAAC,EAAE;EACvC;EACA,KAAK,SAAS,IAAI,WAAW;GAC3B;GACA,aAAa,CAAC;EAChB,CAAC;EACD,OAAO;GACL;GACA,iBAAiB,mBAAmB;EACtC;CACF;CAEA,IAAW,WAAoC;EAC7C,MAAM,QAAQ,KAAK,SAAS,IAAI,SAAS;EACzC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,oBAAoB,WAAW;EAEjD,OAAO;CACT;CAEA,aAAoB,WAAmB,WAA+B;EACpE,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,QAAQ;GACZ,GAAG;GACH,4BAAW,IAAI,KAAK,GAAE,YAAY;EACpC;CACF;CAEA,YAAmB,WAAmB,SAAmC;EACvE,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,WAA4B;GAChC,YAAY,WAAW;GACvB,qBAAI,IAAI,KAAK,GAAE,YAAY;GAC3B;EACF;EACA,MAAM,MAAM,UAAU,KAAK,QAAQ;EACnC,MAAM,MAAM,YAAY,SAAS;EACjC,OAAO;CACT;CAEA,kBAAyB,WAAmB,SAAmC;EAC7E,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,YAAY,KAAK,GAAG,OAAO;EACjC,MAAM,MAAM,6BAAY,IAAI,KAAK,GAAE,YAAY;CACjD;CAEA,gBAAuB,WAAmB,SAAsD;EAC9F,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,IAAI,CAAC,SAAS,eACZ,OAAO,CAAC,GAAG,MAAM,WAAW;EAE9B,OAAO,MAAM,YAAY,QAAO,WAAU,OAAO,kBAAkB,QAAQ,aAAa;CAC1F;AACF"}
|
|
1
|
+
{"version":3,"file":"session-store.js","names":[],"sources":["../../src/session/session-store.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport {\n type DiagnosticRecord,\n type ListDiagnosticsFilters,\n type SessionHandle,\n type SessionRevision,\n type SessionState\n} from '../models';\n\ninterface SessionEnvelope {\n state: SessionState;\n diagnostics: DiagnosticRecord[];\n}\n\nexport class SessionStore {\n private sessions = new Map<string, SessionEnvelope>();\n\n public create(initial?: Partial<SessionState>, contractVersion?: string): SessionHandle {\n const now = new Date().toISOString();\n const sessionId = initial?.sessionId ?? randomUUID();\n const state: SessionState = {\n sessionId,\n alias: initial?.alias ?? '',\n title: initial?.title ?? '',\n comment: initial?.comment ?? '',\n createdAt: initial?.createdAt ?? now,\n updatedAt: now,\n revisions: initial?.revisions ?? [],\n items: initial?.items ?? [],\n model: initial?.model ?? { items: [] }\n };\n this.sessions.set(sessionId, {\n state,\n diagnostics: []\n });\n return {\n sessionId,\n contractVersion: contractVersion ?? '1.0.0'\n };\n }\n\n public get(sessionId: string): SessionEnvelope {\n const found = this.sessions.get(sessionId);\n if (!found) {\n throw new Error(`Unknown session: ${sessionId}`);\n }\n return found;\n }\n\n public replaceState(sessionId: string, nextState: SessionState): void {\n const found = this.get(sessionId);\n found.state = {\n ...nextState,\n updatedAt: new Date().toISOString()\n };\n }\n\n public addRevision(sessionId: string, message?: string): SessionRevision {\n const found = this.get(sessionId);\n const revision: SessionRevision = {\n revisionId: randomUUID(),\n at: new Date().toISOString(),\n message\n };\n found.state.revisions.push(revision);\n found.state.updatedAt = revision.at;\n return revision;\n }\n\n public appendDiagnostics(sessionId: string, records: DiagnosticRecord[]): void {\n const found = this.get(sessionId);\n found.diagnostics.push(...records);\n found.state.updatedAt = new Date().toISOString();\n }\n\n public listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[] {\n const found = this.get(sessionId);\n if (!filters?.constituentId) {\n return [...found.diagnostics];\n }\n return found.diagnostics.filter(record => record.constituentId === filters.constituentId);\n }\n}\n"],"mappings":";;AAeA,IAAa,eAAb,MAA0B;CACxB,2BAAmB,IAAI,IAA6B;CAEpD,OAAc,SAAiC,iBAAyC;EACtF,MAAM,uBAAM,IAAI,KAAK,GAAE,YAAY;EACnC,MAAM,YAAY,SAAS,aAAa,WAAW;EACnD,MAAM,QAAsB;GAC1B;GACA,OAAO,SAAS,SAAS;GACzB,OAAO,SAAS,SAAS;GACzB,SAAS,SAAS,WAAW;GAC7B,WAAW,SAAS,aAAa;GACjC,WAAW;GACX,WAAW,SAAS,aAAa,CAAC;GAClC,OAAO,SAAS,SAAS,CAAC;GAC1B,OAAO,SAAS,SAAS,EAAE,OAAO,CAAC,EAAE;EACvC;EACA,KAAK,SAAS,IAAI,WAAW;GAC3B;GACA,aAAa,CAAC;EAChB,CAAC;EACD,OAAO;GACL;GACA,iBAAiB,mBAAmB;EACtC;CACF;CAEA,IAAW,WAAoC;EAC7C,MAAM,QAAQ,KAAK,SAAS,IAAI,SAAS;EACzC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,oBAAoB,WAAW;EAEjD,OAAO;CACT;CAEA,aAAoB,WAAmB,WAA+B;EACpE,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,QAAQ;GACZ,GAAG;GACH,4BAAW,IAAI,KAAK,GAAE,YAAY;EACpC;CACF;CAEA,YAAmB,WAAmB,SAAmC;EACvE,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,WAA4B;GAChC,YAAY,WAAW;GACvB,qBAAI,IAAI,KAAK,GAAE,YAAY;GAC3B;EACF;EACA,MAAM,MAAM,UAAU,KAAK,QAAQ;EACnC,MAAM,MAAM,YAAY,SAAS;EACjC,OAAO;CACT;CAEA,kBAAyB,WAAmB,SAAmC;EAC7E,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,YAAY,KAAK,GAAG,OAAO;EACjC,MAAM,MAAM,6BAAY,IAAI,KAAK,GAAE,YAAY;CACjD;CAEA,gBAAuB,WAAmB,SAAsD;EAC9F,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,IAAI,CAAC,SAAS,eACZ,OAAO,CAAC,GAAG,MAAM,WAAW;EAE9B,OAAO,MAAM,YAAY,QAAO,WAAU,OAAO,kBAAkB,QAAQ,aAAa;CAC1F;AACF"}
|
|
@@ -13,12 +13,23 @@ interface SessionRevision {
|
|
|
13
13
|
}
|
|
14
14
|
interface SessionState {
|
|
15
15
|
sessionId: string;
|
|
16
|
+
/** Library item alias for the conceptual schema or model. */
|
|
17
|
+
alias: string;
|
|
18
|
+
/** Human-readable title. */
|
|
19
|
+
title: string;
|
|
20
|
+
/** Developer comment (Portal JSON `description` on export). */
|
|
21
|
+
comment: string;
|
|
22
|
+
/** Date of creation. */
|
|
16
23
|
createdAt: string;
|
|
24
|
+
/** Date of last update. */
|
|
17
25
|
updatedAt: string;
|
|
26
|
+
/** List of revisions. */
|
|
18
27
|
revisions: SessionRevision[];
|
|
28
|
+
/** List of constituents in the session. */
|
|
19
29
|
items: ConstituentaState[];
|
|
30
|
+
/** Model state. */
|
|
20
31
|
model: SessionModelState;
|
|
21
32
|
}
|
|
22
33
|
//#endregion
|
|
23
34
|
export { SessionRevision as n, SessionState as r, SessionHandle as t };
|
|
24
|
-
//# sourceMappingURL=session-
|
|
35
|
+
//# sourceMappingURL=session-BPgsE80c.d.ts.map
|
|
@@ -3,10 +3,10 @@ import { n as ListDiagnosticsFilters, t as DiagnosticRecord } from "./diagnostic
|
|
|
3
3
|
import { n as AddOrUpdateConstituentaResult, t as AddOrUpdateConstituentaInput } from "./constituenta-Dnd6iToB.js";
|
|
4
4
|
import { n as EvaluateExpressionInput, r as EvaluationResult, t as EvaluateConstituentaInput } from "./evaluation-CCVYH0wA.js";
|
|
5
5
|
import { a as SetConstituentaValueInput, i as SessionModelState, o as SetConstituentaValuesInput, r as RecalculateModelResult, t as ClearConstituentaValuesInput } from "./model-value-SFAVj0dw.js";
|
|
6
|
-
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "./session-
|
|
6
|
+
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "./session-BPgsE80c.js";
|
|
7
7
|
|
|
8
8
|
//#region src/models/tool-contract.d.ts
|
|
9
|
-
declare const CONTRACT_VERSION = "1.
|
|
9
|
+
declare const CONTRACT_VERSION = "1.4.0";
|
|
10
10
|
interface RSToolAgentContract {
|
|
11
11
|
readonly contractVersion: string;
|
|
12
12
|
createSession(initial?: Partial<SessionState>): SessionHandle;
|
|
@@ -16,6 +16,8 @@ interface RSToolAgentContract {
|
|
|
16
16
|
listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[];
|
|
17
17
|
commitStep(sessionId: string, message?: string): SessionRevision;
|
|
18
18
|
exportSession(sessionId: string): string;
|
|
19
|
+
exportPortalSchema(sessionId: string): string;
|
|
20
|
+
exportPortalModel(sessionId: string): string;
|
|
19
21
|
importSession(payload: string): SessionHandle;
|
|
20
22
|
setConstituentaValue(sessionId: string, input: SetConstituentaValueInput): Promise<SessionModelState>;
|
|
21
23
|
setConstituentaValues(sessionId: string, input: SetConstituentaValuesInput): Promise<SessionModelState>;
|
|
@@ -27,4 +29,4 @@ interface RSToolAgentContract {
|
|
|
27
29
|
}
|
|
28
30
|
//#endregion
|
|
29
31
|
export { RSToolAgentContract as n, CONTRACT_VERSION as t };
|
|
30
|
-
//# sourceMappingURL=tool-contract-
|
|
32
|
+
//# sourceMappingURL=tool-contract-n1ghUOrK.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { RSToolAgent } from "../
|
|
2
|
+
import { t as RSToolAgent } from "../rstool-agent-BZi5jO1y.js";
|
|
3
3
|
import readline from "node:readline";
|
|
4
4
|
//#region src/wrapper/stdio-wrapper.ts
|
|
5
5
|
const tool = new RSToolAgent();
|
|
@@ -11,6 +11,8 @@ const METHODS = [
|
|
|
11
11
|
"listDiagnostics",
|
|
12
12
|
"commitStep",
|
|
13
13
|
"exportSession",
|
|
14
|
+
"exportPortalSchema",
|
|
15
|
+
"exportPortalModel",
|
|
14
16
|
"importSession",
|
|
15
17
|
"setConstituentaValue",
|
|
16
18
|
"setConstituentaValues",
|
|
@@ -84,6 +86,16 @@ async function handleRequest(request) {
|
|
|
84
86
|
ok: true,
|
|
85
87
|
result: tool.exportSession(requiredString(params, "sessionId"))
|
|
86
88
|
};
|
|
89
|
+
case "exportPortalSchema": return {
|
|
90
|
+
id: request.id,
|
|
91
|
+
ok: true,
|
|
92
|
+
result: tool.exportPortalSchema(requiredString(params, "sessionId"))
|
|
93
|
+
};
|
|
94
|
+
case "exportPortalModel": return {
|
|
95
|
+
id: request.id,
|
|
96
|
+
ok: true,
|
|
97
|
+
result: tool.exportPortalModel(requiredString(params, "sessionId"))
|
|
98
|
+
};
|
|
87
99
|
case "importSession": return {
|
|
88
100
|
id: request.id,
|
|
89
101
|
ok: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio-wrapper.js","names":[],"sources":["../../src/wrapper/stdio-wrapper.ts"],"sourcesContent":["#!/usr/bin/env node\nimport readline from 'node:readline';\n\nimport { RSToolAgent } from '../models/rstool-agent';\n\ninterface StdioRequest {\n id: string | number;\n method: string;\n params?: unknown;\n}\n\ninterface StdioResponse {\n id: string | number | null;\n ok: boolean;\n result?: unknown;\n error?: {\n code: string;\n message: string;\n details?: unknown;\n };\n}\n\nconst tool = new RSToolAgent();\n\nconst METHODS = [\n 'createSession',\n 'addOrUpdateConstituenta',\n 'analyzeExpression',\n 'getFormState',\n 'listDiagnostics',\n 'commitStep',\n 'exportSession',\n 'importSession',\n 'setConstituentaValue',\n 'setConstituentaValues',\n 'clearConstituentaValues',\n 'getModelState',\n 'evaluateExpression',\n 'evaluateConstituenta',\n 'recalculateModel'\n] as const;\n\nfunction writeResponse(response: StdioResponse): void {\n if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) {\n return;\n }\n try {\n process.stdout.write(`${JSON.stringify(response)}\\n`);\n } catch {\n // The client might have already closed stdout (EPIPE). Safe to ignore.\n }\n}\n\nfunction asObject(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return {};\n }\n return value as Record<string, unknown>;\n}\n\nfunction requiredString(input: Record<string, unknown>, key: string): string {\n const value = input[key];\n if (typeof value !== 'string' || value.length === 0) {\n throw new Error(`Missing or invalid \"${key}\"`);\n }\n return value;\n}\n\nasync function handleRequest(request: StdioRequest): Promise<StdioResponse> {\n try {\n const params = asObject(request.params);\n switch (request.method) {\n case 'ping':\n return { id: request.id, ok: true, result: { pong: true } };\n case 'methods':\n return { id: request.id, ok: true, result: METHODS };\n case 'createSession':\n return {\n id: request.id,\n ok: true,\n result: tool.createSession(params.initial as never)\n };\n case 'addOrUpdateConstituenta':\n return {\n id: request.id,\n ok: true,\n result: tool.addOrUpdateConstituenta(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'analyzeExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.analyzeExpression(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'getFormState':\n return {\n id: request.id,\n ok: true,\n result: tool.getFormState(requiredString(params, 'sessionId'))\n };\n case 'listDiagnostics':\n return {\n id: request.id,\n ok: true,\n result: tool.listDiagnostics(requiredString(params, 'sessionId'), params.filters as never)\n };\n case 'commitStep':\n return {\n id: request.id,\n ok: true,\n result: tool.commitStep(requiredString(params, 'sessionId'), params.message as string | undefined)\n };\n case 'exportSession':\n return {\n id: request.id,\n ok: true,\n result: tool.exportSession(requiredString(params, 'sessionId'))\n };\n case 'importSession':\n return {\n id: request.id,\n ok: true,\n result: tool.importSession(requiredString(params, 'payload'))\n };\n case 'setConstituentaValue':\n return {\n id: request.id,\n ok: true,\n result: await tool.setConstituentaValue(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'setConstituentaValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.setConstituentaValues(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'clearConstituentaValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.clearConstituentaValues(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'getModelState':\n return {\n id: request.id,\n ok: true,\n result: tool.getModelState(requiredString(params, 'sessionId'))\n };\n case 'evaluateExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluateExpression(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'evaluateConstituenta':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluateConstituenta(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'recalculateModel':\n return {\n id: request.id,\n ok: true,\n result: tool.recalculateModel(requiredString(params, 'sessionId'))\n };\n default:\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'METHOD_NOT_FOUND',\n message: `Unknown method: ${request.method}`\n }\n };\n }\n } catch (error) {\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'INTERNAL_ERROR',\n message: error instanceof Error ? error.message : 'Unknown error',\n details: error\n }\n };\n }\n}\n\nconst input = readline.createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nwriteResponse({\n id: null,\n ok: true,\n result: {\n ready: true,\n wrapper: 'rstool-stdio',\n contractVersion: tool.contractVersion\n }\n});\n\ninput.on('line', line => {\n if (!line.trim()) {\n return;\n }\n try {\n const request = JSON.parse(line) as StdioRequest;\n if (!('id' in request) || !('method' in request)) {\n throw new Error('Request must include \"id\" and \"method\"');\n }\n void handleRequest(request).then(writeResponse);\n } catch (error) {\n writeResponse({\n id: null,\n ok: false,\n error: {\n code: 'BAD_REQUEST',\n message: error instanceof Error ? error.message : 'Invalid JSON'\n }\n });\n }\n});\n"],"mappings":";;;;AAsBA,MAAM,OAAO,IAAI,YAAY;AAE7B,MAAM,UAAU;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,cAAc,UAA+B;CACpD,IAAI,CAAC,QAAQ,OAAO,YAAY,QAAQ,OAAO,aAAa,QAAQ,OAAO,eACzE;CAEF,IAAI;EACF,QAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,QAAQ,EAAE,GAAG;CACtD,QAAQ,CAER;AACF;AAEA,SAAS,SAAS,OAAyC;CACzD,IAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAC5D,OAAO,CAAC;CAEV,OAAO;AACT;AAEA,SAAS,eAAe,OAAgC,KAAqB;CAC3E,MAAM,QAAQ,MAAM;CACpB,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAChD,MAAM,IAAI,MAAM,uBAAuB,IAAI,EAAE;CAE/C,OAAO;AACT;AAEA,eAAe,cAAc,SAA+C;CAC1E,IAAI;EACF,MAAM,SAAS,SAAS,QAAQ,MAAM;EACtC,QAAQ,QAAQ,QAAhB;GACE,KAAK,QACH,OAAO;IAAE,IAAI,QAAQ;IAAI,IAAI;IAAM,QAAQ,EAAE,MAAM,KAAK;GAAE;GAC5D,KAAK,WACH,OAAO;IAAE,IAAI,QAAQ;IAAI,IAAI;IAAM,QAAQ;GAAQ;GACrD,KAAK,iBACH,OAAO;IACL,IAAI,QAAQ;IACZ,IAAI;IACJ,QAAQ,KAAK,cAAc,OAAO,OAAgB;GACpD;GACF,KAAK,2BACH,OAAO;IACL,IAAI,QAAQ;IACZ,IAAI;IACJ,QAAQ,KAAK,wBAAwB,eAAe,QAAQ,WAAW,GAAG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"sources":["../../src/wrapper/stdio-wrapper.ts"],"sourcesContent":["#!/usr/bin/env node\nimport readline from 'node:readline';\n\nimport { RSToolAgent } from '../models/rstool-agent';\n\ninterface StdioRequest {\n id: string | number;\n method: string;\n params?: unknown;\n}\n\ninterface StdioResponse {\n id: string | number | null;\n ok: boolean;\n result?: unknown;\n error?: {\n code: string;\n message: string;\n details?: unknown;\n };\n}\n\nconst tool = new RSToolAgent();\n\nconst METHODS = [\n 'createSession',\n 'addOrUpdateConstituenta',\n 'analyzeExpression',\n 'getFormState',\n 'listDiagnostics',\n 'commitStep',\n 'exportSession',\n 'exportPortalSchema',\n 'exportPortalModel',\n 'importSession',\n 'setConstituentaValue',\n 'setConstituentaValues',\n 'clearConstituentaValues',\n 'getModelState',\n 'evaluateExpression',\n 'evaluateConstituenta',\n 'recalculateModel'\n] as const;\n\nfunction writeResponse(response: StdioResponse): void {\n if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) {\n return;\n }\n try {\n process.stdout.write(`${JSON.stringify(response)}\\n`);\n } catch {\n // The client might have already closed stdout (EPIPE). Safe to ignore.\n }\n}\n\nfunction asObject(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return {};\n }\n return value as Record<string, unknown>;\n}\n\nfunction requiredString(input: Record<string, unknown>, key: string): string {\n const value = input[key];\n if (typeof value !== 'string' || value.length === 0) {\n throw new Error(`Missing or invalid \"${key}\"`);\n }\n return value;\n}\n\nasync function handleRequest(request: StdioRequest): Promise<StdioResponse> {\n try {\n const params = asObject(request.params);\n switch (request.method) {\n case 'ping':\n return { id: request.id, ok: true, result: { pong: true } };\n case 'methods':\n return { id: request.id, ok: true, result: METHODS };\n case 'createSession':\n return {\n id: request.id,\n ok: true,\n result: tool.createSession(params.initial as never)\n };\n case 'addOrUpdateConstituenta':\n return {\n id: request.id,\n ok: true,\n result: tool.addOrUpdateConstituenta(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'analyzeExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.analyzeExpression(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'getFormState':\n return {\n id: request.id,\n ok: true,\n result: tool.getFormState(requiredString(params, 'sessionId'))\n };\n case 'listDiagnostics':\n return {\n id: request.id,\n ok: true,\n result: tool.listDiagnostics(requiredString(params, 'sessionId'), params.filters as never)\n };\n case 'commitStep':\n return {\n id: request.id,\n ok: true,\n result: tool.commitStep(requiredString(params, 'sessionId'), params.message as string | undefined)\n };\n case 'exportSession':\n return {\n id: request.id,\n ok: true,\n result: tool.exportSession(requiredString(params, 'sessionId'))\n };\n case 'exportPortalSchema':\n return {\n id: request.id,\n ok: true,\n result: tool.exportPortalSchema(requiredString(params, 'sessionId'))\n };\n case 'exportPortalModel':\n return {\n id: request.id,\n ok: true,\n result: tool.exportPortalModel(requiredString(params, 'sessionId'))\n };\n case 'importSession':\n return {\n id: request.id,\n ok: true,\n result: tool.importSession(requiredString(params, 'payload'))\n };\n case 'setConstituentaValue':\n return {\n id: request.id,\n ok: true,\n result: await tool.setConstituentaValue(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'setConstituentaValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.setConstituentaValues(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'clearConstituentaValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.clearConstituentaValues(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'getModelState':\n return {\n id: request.id,\n ok: true,\n result: tool.getModelState(requiredString(params, 'sessionId'))\n };\n case 'evaluateExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluateExpression(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'evaluateConstituenta':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluateConstituenta(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'recalculateModel':\n return {\n id: request.id,\n ok: true,\n result: tool.recalculateModel(requiredString(params, 'sessionId'))\n };\n default:\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'METHOD_NOT_FOUND',\n message: `Unknown method: ${request.method}`\n }\n };\n }\n } catch (error) {\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'INTERNAL_ERROR',\n message: error instanceof Error ? error.message : 'Unknown error',\n details: error\n }\n };\n }\n}\n\nconst input = readline.createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nwriteResponse({\n id: null,\n ok: true,\n result: {\n ready: true,\n wrapper: 'rstool-stdio',\n contractVersion: tool.contractVersion\n }\n});\n\ninput.on('line', line => {\n if (!line.trim()) {\n return;\n }\n try {\n const request = JSON.parse(line) as StdioRequest;\n if (!('id' in request) || !('method' in request)) {\n throw new Error('Request must include \"id\" and \"method\"');\n }\n void handleRequest(request).then(writeResponse);\n } catch (error) {\n writeResponse({\n id: null,\n ok: false,\n error: {\n code: 'BAD_REQUEST',\n message: error instanceof Error ? error.message : 'Invalid JSON'\n }\n });\n }\n});\n"],"mappings":";;;;AAsBA,MAAM,OAAO,IAAI,YAAY;AAE7B,MAAM,UAAU;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,cAAc,UAA+B;CACpD,IAAI,CAAC,QAAQ,OAAO,YAAY,QAAQ,OAAO,aAAa,QAAQ,OAAO,eACzE;CAEF,IAAI;EACF,QAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,QAAQ,EAAE,GAAG;CACtD,QAAQ,CAER;AACF;AAEA,SAAS,SAAS,OAAyC;CACzD,IAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAC5D,OAAO,CAAC;CAEV,OAAO;AACT;AAEA,SAAS,eAAe,OAAgC,KAAqB;CAC3E,MAAM,QAAQ,MAAM;CACpB,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAChD,MAAM,IAAI,MAAM,uBAAuB,IAAI,EAAE;CAE/C,OAAO;AACT;AAEA,eAAe,cAAc,SA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IACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;IAClD,SAAS;GACX;EACF;CACF;AACF;AAEA,MAAM,QAAQ,SAAS,gBAAgB;CACrC,OAAO,QAAQ;CACf,WAAW;AACb,CAAC;AAED,cAAc;CACZ,IAAI;CACJ,IAAI;CACJ,QAAQ;EACN,OAAO;EACP,SAAS;EACT,iBAAiB,KAAK;CACxB;AACF,CAAC;AAED,MAAM,GAAG,SAAQ,SAAQ;CACvB,IAAI,CAAC,KAAK,KAAK,GACb;CAEF,IAAI;EACF,MAAM,UAAU,KAAK,MAAM,IAAI;EAC/B,IAAI,EAAE,QAAQ,YAAY,EAAE,YAAY,UACtC,MAAM,IAAI,MAAM,4CAAwC;EAE1D,AAAK,cAAc,OAAO,EAAE,KAAK,aAAa;CAChD,SAAS,OAAO;EACd,cAAc;GACZ,IAAI;GACJ,IAAI;GACJ,OAAO;IACL,MAAM;IACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACpD;EACF,CAAC;CACH;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsconcept/rstool",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Agent-facing library for incremental RSForm construction, RSLang analysis, diagnostics, modeling, and evaluation. Wraps @rsconcept/domain with a deterministic session contract and stdio wrapper.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "IRBorisov",
|
|
@@ -92,6 +92,15 @@ const restored = tool.importSession(payload);
|
|
|
92
92
|
|
|
93
93
|
Export includes session state and model values.
|
|
94
94
|
|
|
95
|
+
To create files the user can upload to an existing Portal object:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const schemaJson = tool.exportPortalSchema(sessionId);
|
|
99
|
+
const modelJson = tool.exportPortalModel(sessionId);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Use `schemaJson` on a schema page and `modelJson` on a model page via **Load from JSON**.
|
|
103
|
+
|
|
95
104
|
## Evaluation
|
|
96
105
|
|
|
97
106
|
```ts
|
|
@@ -39,6 +39,7 @@ Paths are relative to this file.
|
|
|
39
39
|
8. Set base/model values with `setConstituentaValue(s)`.
|
|
40
40
|
9. Evaluate with `evaluateExpression`, `evaluateConstituenta`, or `recalculateModel`.
|
|
41
41
|
10. Persist with `exportSession` / `importSession`.
|
|
42
|
+
11. For user-uploadable Portal files, use `exportPortalSchema` for schema JSON or `exportPortalModel` for model JSON.
|
|
42
43
|
|
|
43
44
|
## Portal REST
|
|
44
45
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## rstool contract
|
|
4
4
|
|
|
5
5
|
- Package: `@rsconcept/rstool`
|
|
6
|
-
- Contract version: `1.
|
|
6
|
+
- Contract version: `1.4.0` (`CONTRACT_VERSION`)
|
|
7
7
|
- Core class: `RSToolAgent`
|
|
8
8
|
- Public imports: `@rsconcept/rstool` and `@rsconcept/rstool/wrapper`
|
|
9
9
|
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
| `listDiagnostics(sessionId, filters?)` | Accumulated diagnostics; optional `constituentId` filter |
|
|
19
19
|
| `commitStep(sessionId, message?)` | Record revision checkpoint |
|
|
20
20
|
| `exportSession(sessionId)` | JSON string `{ contractVersion, state, diagnostics }` |
|
|
21
|
+
| `exportPortalSchema(sessionId)` | Portal schema import JSON string using versioned schema shape |
|
|
22
|
+
| `exportPortalModel(sessionId)` | Portal model import JSON string using versioned model values shape |
|
|
21
23
|
| `importSession(payload)` | New session from export |
|
|
22
24
|
| `setConstituentaValue(sessionId, { target, type?, value })` | Set one base binding or structured value → `SessionModelState` |
|
|
23
25
|
| `setConstituentaValues(sessionId, { items })` | Batch set values → `SessionModelState` |
|
|
@@ -43,6 +45,20 @@
|
|
|
43
45
|
|
|
44
46
|
Omitted text fields default to `''` in stored state.
|
|
45
47
|
|
|
48
|
+
### `SessionState` metadata
|
|
49
|
+
|
|
50
|
+
Set on `createSession(initial?)` or via `importSession`:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
{
|
|
54
|
+
alias: string; // library item alias
|
|
55
|
+
title: string; // display title
|
|
56
|
+
comment: string; // developer notes
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
All default to `''` when omitted.
|
|
61
|
+
|
|
46
62
|
### Model and evaluation types
|
|
47
63
|
|
|
48
64
|
```ts
|
|
@@ -69,7 +85,7 @@ Base/constant bindings use `type: "basic"` and `value: { "0": "label", … }`. S
|
|
|
69
85
|
|
|
70
86
|
Process: `npx rstool-wrapper`
|
|
71
87
|
|
|
72
|
-
1. **Ready** (no request): `{"id":null,"ok":true,"result":{"ready":true,"wrapper":"rstool-stdio","contractVersion":"1.
|
|
88
|
+
1. **Ready** (no request): `{"id":null,"ok":true,"result":{"ready":true,"wrapper":"rstool-stdio","contractVersion":"1.4.0"}}`
|
|
73
89
|
2. **Request**: `{"id":"<unique>","method":"<name>","params":{...}}`
|
|
74
90
|
3. **Response**: `{"id":"<same>","ok":true,"result":...}` or `{"id":"...","ok":false,"error":{"code":"...","message":"..."}}`
|
|
75
91
|
|
|
@@ -85,6 +101,8 @@ Example chain:
|
|
|
85
101
|
{"id":"4","method":"listDiagnostics","params":{"sessionId":"…"}}
|
|
86
102
|
{"id":"5","method":"commitStep","params":{"sessionId":"…","message":"checkpoint"}}
|
|
87
103
|
{"id":"6","method":"exportSession","params":{"sessionId":"…"}}
|
|
104
|
+
{"id":"6a","method":"exportPortalSchema","params":{"sessionId":"…"}}
|
|
105
|
+
{"id":"6b","method":"exportPortalModel","params":{"sessionId":"…"}}
|
|
88
106
|
{"id":"7","method":"setConstituentaValue","params":{"sessionId":"…","input":{"target":1,"value":{"0":"a","1":"b"}}}}
|
|
89
107
|
{"id":"8","method":"evaluateExpression","params":{"sessionId":"…","input":{"expression":"1+2","cstType":"term"}}}
|
|
90
108
|
{"id":"9","method":"evaluateConstituenta","params":{"sessionId":"…","input":{"constituentId":3}}}
|
|
@@ -109,7 +127,7 @@ interface AnalysisResult {
|
|
|
109
127
|
- **Term graph**: directed dependencies between constituenta via alias references in definitions.
|
|
110
128
|
- **`S#` vs `D#`**: same `×` token — in `ℬ(X1×X1)` on `S#` it forms a **grade** (pair type); in `X1×X1` on `D#` it is the **Cartesian product** (all pairs). Relations: `S#` + `convention`, then derived `D#` (`Pr1(S1)`, …).
|
|
111
129
|
|
|
112
|
-
Intro (help): language is FOL-based; set vs logic expression split; parameterized templates for term/predicate functions
|
|
130
|
+
Intro (help): language is FOL-based; set vs logic expression split; parameterized templates for term/predicate functions.
|
|
113
131
|
|
|
114
132
|
## Grammar tokens (selected)
|
|
115
133
|
|
|
@@ -134,15 +152,15 @@ Standalone agents should consult the bundled distilled docs (`docs/*.md` inside
|
|
|
134
152
|
|
|
135
153
|
| Topic | Bundled doc |
|
|
136
154
|
| ------------------------------------ | ------------------------------------------ |
|
|
137
|
-
| Identifiers, literals | `docs/SYNTAX.md` §
|
|
155
|
+
| Identifiers, literals | `docs/SYNTAX.md` § _Identifier rules_ |
|
|
138
156
|
| Grades, `Logic`, parameterized types | `docs/TYPIFICATION.md` |
|
|
139
|
-
| Logical expressions | `docs/SYNTAX.md` §
|
|
140
|
-
| Set operators | `docs/SYNTAX.md` §
|
|
141
|
-
| Integer arithmetic | `docs/SYNTAX.md` §
|
|
142
|
-
| Structural / typification reshaping | `docs/TYPIFICATION.md` §
|
|
143
|
-
| Quantifiers | `docs/SYNTAX.md` §
|
|
144
|
-
| Parameterized functions, templates | `docs/SYNTAX.md` §
|
|
145
|
-
| Correctness / validation mindset | `docs/SYNTAX.md` §
|
|
157
|
+
| Logical expressions | `docs/SYNTAX.md` § _Logical expressions_ |
|
|
158
|
+
| Set operators | `docs/SYNTAX.md` § _Set-theoretic_ |
|
|
159
|
+
| Integer arithmetic | `docs/SYNTAX.md` § _Arithmetic_ |
|
|
160
|
+
| Structural / typification reshaping | `docs/TYPIFICATION.md` § _Forming/derived_ |
|
|
161
|
+
| Quantifiers | `docs/SYNTAX.md` § _Quantifiers_ |
|
|
162
|
+
| Parameterized functions, templates | `docs/SYNTAX.md` § _Parameterised_ |
|
|
163
|
+
| Correctness / validation mindset | `docs/SYNTAX.md` § _Correctness model_ |
|
|
146
164
|
| Definition semantic tests | `docs/MODEL-TESTING.md` |
|
|
147
165
|
| Domain vocabulary | `docs/DOMAIN.md` |
|
|
148
166
|
| Constituent fields and ordering | `docs/CONSTITUENTA.md` |
|
|
@@ -167,6 +185,19 @@ Categories:
|
|
|
167
185
|
|
|
168
186
|
`exportSession(sessionId)` returns a JSON string with `{ contractVersion, state, diagnostics }`.
|
|
169
187
|
|
|
188
|
+
- `state.alias`, `state.title`, `state.comment` — library-item metadata for Portal export (`comment` → JSON `description`).
|
|
170
189
|
- `state.items[]` contains each constituent with `id`, `alias`, `cstType`, `definitionFormal`, optional text fields, and nested analysis output.
|
|
171
190
|
- `state.model.items[]` is present when interpretation values have been set.
|
|
172
191
|
- `diagnostics[]` contains accumulated diagnostics with offsets and codes.
|
|
192
|
+
|
|
193
|
+
## Portal import JSON
|
|
194
|
+
|
|
195
|
+
For **Load from JSON** on an existing Portal schema or model:
|
|
196
|
+
|
|
197
|
+
- `exportPortalSchema(sessionId)` — schema file
|
|
198
|
+
- `exportPortalModel(sessionId)` — model file
|
|
199
|
+
|
|
200
|
+
Both return `contract_version` `1.0.0` plus required `title`, `alias`, `description`, and `items`. Schema files may include `attribution`. Values come from `state.title`, `state.alias`, and `state.comment` (empty fields fall back to `Conceptual schema` / `SCHEMA` or `Conceptual model` / `MODEL` and `""`).
|
|
201
|
+
|
|
202
|
+
- Schema `items[]`: versioned constituent fields (`cst_type`, `definition_formal`, `term_raw`, …).
|
|
203
|
+
- Model `items[]`: `{ id, type, value }` per binding.
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,12 @@ export {
|
|
|
25
25
|
type EvaluationResult,
|
|
26
26
|
type ListDiagnosticsFilters,
|
|
27
27
|
type ModelValueState,
|
|
28
|
+
PORTAL_JSON_CONTRACT_VERSION,
|
|
29
|
+
type PortalImportMetadata,
|
|
30
|
+
type PortalModelImportData,
|
|
31
|
+
type PortalSchemaConstituenta,
|
|
32
|
+
type PortalSchemaImportData,
|
|
33
|
+
type PortalTermForm,
|
|
28
34
|
type RecalculateModelResult,
|
|
29
35
|
type RSToolAgentContract,
|
|
30
36
|
type RSToolErrorDescription,
|
package/src/models/index.ts
CHANGED
|
@@ -28,6 +28,14 @@ export {
|
|
|
28
28
|
type SetConstituentaValueInput,
|
|
29
29
|
type SetConstituentaValuesInput
|
|
30
30
|
} from './model-value';
|
|
31
|
+
export {
|
|
32
|
+
PORTAL_JSON_CONTRACT_VERSION,
|
|
33
|
+
type PortalImportMetadata,
|
|
34
|
+
type PortalModelImportData,
|
|
35
|
+
type PortalSchemaConstituenta,
|
|
36
|
+
type PortalSchemaImportData,
|
|
37
|
+
type PortalTermForm
|
|
38
|
+
} from './portal-json';
|
|
31
39
|
export { RSToolAgent } from './rstool-agent';
|
|
32
40
|
export { type SessionHandle, type SessionRevision, type SessionState } from './session';
|
|
33
41
|
export { CONTRACT_VERSION, type RSToolAgentContract } from './tool-contract';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type BasicBinding, type RSToolValue } from './common';
|
|
2
|
+
|
|
3
|
+
/** Portal JSON import/export format version (schema and model files). */
|
|
4
|
+
export const PORTAL_JSON_CONTRACT_VERSION = '1.0.0';
|
|
5
|
+
|
|
6
|
+
export interface PortalImportMetadata {
|
|
7
|
+
contract_version: string;
|
|
8
|
+
title: string;
|
|
9
|
+
alias: string;
|
|
10
|
+
description: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PortalTermForm {
|
|
14
|
+
text: string;
|
|
15
|
+
tags: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PortalSchemaConstituenta {
|
|
19
|
+
id: number;
|
|
20
|
+
alias: string;
|
|
21
|
+
convention: string;
|
|
22
|
+
crucial: boolean;
|
|
23
|
+
cst_type: string;
|
|
24
|
+
definition_formal: string;
|
|
25
|
+
typification_manual: string;
|
|
26
|
+
value_is_property: boolean;
|
|
27
|
+
definition_raw: string;
|
|
28
|
+
definition_resolved: string;
|
|
29
|
+
term_raw: string;
|
|
30
|
+
term_resolved: string;
|
|
31
|
+
term_forms: PortalTermForm[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PortalSchemaImportData extends PortalImportMetadata {
|
|
35
|
+
items: PortalSchemaConstituenta[];
|
|
36
|
+
attribution: Array<{ container: number; attribute: number }>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PortalModelImportData extends PortalImportMetadata {
|
|
40
|
+
items: Array<{
|
|
41
|
+
id: number;
|
|
42
|
+
type: string;
|
|
43
|
+
value: RSToolValue | BasicBinding;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
@@ -126,6 +126,104 @@ describe('RSToolAgent', () => {
|
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
+
it('stores and exports session metadata', () => {
|
|
130
|
+
const tool = new RSToolAgent();
|
|
131
|
+
const session = tool.createSession({
|
|
132
|
+
alias: 'KIN',
|
|
133
|
+
title: 'Kinship',
|
|
134
|
+
comment: 'Example schema'
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(tool.getFormState(session.sessionId)).toMatchObject({
|
|
138
|
+
alias: 'KIN',
|
|
139
|
+
title: 'Kinship',
|
|
140
|
+
comment: 'Example schema'
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const exported = JSON.parse(tool.exportPortalSchema(session.sessionId)) as {
|
|
144
|
+
title: string;
|
|
145
|
+
alias: string;
|
|
146
|
+
description: string;
|
|
147
|
+
};
|
|
148
|
+
expect(exported).toMatchObject({
|
|
149
|
+
title: 'Kinship',
|
|
150
|
+
alias: 'KIN',
|
|
151
|
+
description: 'Example schema'
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('exports schema data for Portal JSON import', () => {
|
|
156
|
+
const tool = new RSToolAgent();
|
|
157
|
+
const session = tool.createSession();
|
|
158
|
+
tool.addOrUpdateConstituenta(session.sessionId, {
|
|
159
|
+
draft: {
|
|
160
|
+
id: 15,
|
|
161
|
+
alias: 'D2',
|
|
162
|
+
cstType: CstType.TERM,
|
|
163
|
+
definitionFormal: '1',
|
|
164
|
+
term: 'natural number',
|
|
165
|
+
definitionText: 'A positive integer',
|
|
166
|
+
convention: 'Standard arithmetic'
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const exported = JSON.parse(tool.exportPortalSchema(session.sessionId)) as {
|
|
171
|
+
contract_version: string;
|
|
172
|
+
title: string;
|
|
173
|
+
alias: string;
|
|
174
|
+
description: string;
|
|
175
|
+
items: Array<Record<string, unknown>>;
|
|
176
|
+
attribution: unknown[];
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
expect(exported.contract_version).toBe('1.0.0');
|
|
180
|
+
expect(exported.title).toBe('Conceptual schema');
|
|
181
|
+
expect(exported.alias).toBe('SCHEMA');
|
|
182
|
+
expect(exported.description).toBe('');
|
|
183
|
+
|
|
184
|
+
expect(exported.items[0]).toMatchObject({
|
|
185
|
+
id: 15,
|
|
186
|
+
alias: 'D2',
|
|
187
|
+
cst_type: CstType.TERM,
|
|
188
|
+
definition_formal: '1',
|
|
189
|
+
definition_raw: 'A positive integer',
|
|
190
|
+
term_raw: 'natural number',
|
|
191
|
+
convention: 'Standard arithmetic',
|
|
192
|
+
crucial: false
|
|
193
|
+
});
|
|
194
|
+
expect(exported.attribution).toEqual([]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('exports model data for Portal JSON import', async () => {
|
|
198
|
+
const tool = new RSToolAgent();
|
|
199
|
+
const session = tool.createSession();
|
|
200
|
+
buildSampleForm(tool, session.sessionId);
|
|
201
|
+
await tool.setConstituentaValue(session.sessionId, {
|
|
202
|
+
target: 1,
|
|
203
|
+
value: { 1: 'Alice' }
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const exported = JSON.parse(tool.exportPortalModel(session.sessionId)) as {
|
|
207
|
+
contract_version: string;
|
|
208
|
+
title: string;
|
|
209
|
+
alias: string;
|
|
210
|
+
description: string;
|
|
211
|
+
items: Array<Record<string, unknown>>;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
expect(exported.contract_version).toBe('1.0.0');
|
|
215
|
+
expect(exported.title).toBe('Conceptual model');
|
|
216
|
+
expect(exported.alias).toBe('MODEL');
|
|
217
|
+
|
|
218
|
+
expect(exported.items).toEqual([
|
|
219
|
+
{
|
|
220
|
+
id: 1,
|
|
221
|
+
type: 'basic',
|
|
222
|
+
value: { 1: 'Alice' }
|
|
223
|
+
}
|
|
224
|
+
]);
|
|
225
|
+
});
|
|
226
|
+
|
|
129
227
|
it('defaults missing text fields to empty strings', () => {
|
|
130
228
|
const tool = new RSToolAgent();
|
|
131
229
|
const session = tool.createSession();
|
|
@@ -19,9 +19,41 @@ import {
|
|
|
19
19
|
type SetConstituentaValueInput,
|
|
20
20
|
type SetConstituentaValuesInput
|
|
21
21
|
} from './model-value';
|
|
22
|
+
import {
|
|
23
|
+
PORTAL_JSON_CONTRACT_VERSION,
|
|
24
|
+
type PortalModelImportData,
|
|
25
|
+
type PortalSchemaImportData
|
|
26
|
+
} from './portal-json';
|
|
22
27
|
import { type SessionHandle, type SessionRevision, type SessionState } from './session';
|
|
23
28
|
import { CONTRACT_VERSION, type RSToolAgentContract } from './tool-contract';
|
|
24
29
|
|
|
30
|
+
function normalizeImportedState(state: SessionState): SessionState {
|
|
31
|
+
return {
|
|
32
|
+
...state,
|
|
33
|
+
alias: state.alias ?? '',
|
|
34
|
+
title: state.title ?? '',
|
|
35
|
+
comment: state.comment ?? '',
|
|
36
|
+
model: state.model ?? { items: [] }
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function portalImportMetadata(
|
|
41
|
+
session: SessionState,
|
|
42
|
+
kind: 'schema' | 'model'
|
|
43
|
+
): Pick<PortalSchemaImportData, 'title' | 'alias' | 'description'> {
|
|
44
|
+
const defaults =
|
|
45
|
+
kind === 'schema'
|
|
46
|
+
? { title: 'Conceptual schema', alias: 'SCHEMA' }
|
|
47
|
+
: { title: 'Conceptual model', alias: 'MODEL' };
|
|
48
|
+
const title = session.title.trim();
|
|
49
|
+
const alias = session.alias.trim();
|
|
50
|
+
return {
|
|
51
|
+
title: title.length > 0 ? title : defaults.title,
|
|
52
|
+
alias: alias.length > 0 ? alias : defaults.alias,
|
|
53
|
+
description: session.comment.trim()
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
25
57
|
export class RSToolAgent implements RSToolAgentContract {
|
|
26
58
|
public readonly contractVersion = CONTRACT_VERSION;
|
|
27
59
|
private readonly sessions = new SessionStore();
|
|
@@ -87,14 +119,50 @@ export class RSToolAgent implements RSToolAgentContract {
|
|
|
87
119
|
);
|
|
88
120
|
}
|
|
89
121
|
|
|
122
|
+
public exportPortalSchema(sessionId: string): string {
|
|
123
|
+
const envelope = this.sessions.get(sessionId);
|
|
124
|
+
const payload: PortalSchemaImportData = {
|
|
125
|
+
contract_version: PORTAL_JSON_CONTRACT_VERSION,
|
|
126
|
+
...portalImportMetadata(envelope.state, 'schema'),
|
|
127
|
+
items: envelope.state.items.map(item => ({
|
|
128
|
+
id: item.id,
|
|
129
|
+
alias: item.alias,
|
|
130
|
+
convention: item.convention,
|
|
131
|
+
crucial: false,
|
|
132
|
+
cst_type: item.cstType,
|
|
133
|
+
definition_formal: item.definitionFormal,
|
|
134
|
+
typification_manual: '',
|
|
135
|
+
value_is_property: false,
|
|
136
|
+
definition_raw: item.definitionText,
|
|
137
|
+
definition_resolved: item.definitionText,
|
|
138
|
+
term_raw: item.term,
|
|
139
|
+
term_resolved: item.term,
|
|
140
|
+
term_forms: []
|
|
141
|
+
})),
|
|
142
|
+
attribution: []
|
|
143
|
+
};
|
|
144
|
+
return JSON.stringify(payload, null, 2);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public exportPortalModel(sessionId: string): string {
|
|
148
|
+
const envelope = this.sessions.get(sessionId);
|
|
149
|
+
const payload: PortalModelImportData = {
|
|
150
|
+
contract_version: PORTAL_JSON_CONTRACT_VERSION,
|
|
151
|
+
...portalImportMetadata(envelope.state, 'model'),
|
|
152
|
+
items: envelope.state.model.items.map(item => ({
|
|
153
|
+
id: item.id,
|
|
154
|
+
type: item.type,
|
|
155
|
+
value: item.value
|
|
156
|
+
}))
|
|
157
|
+
};
|
|
158
|
+
return JSON.stringify(payload, null, 2);
|
|
159
|
+
}
|
|
160
|
+
|
|
90
161
|
public importSession(payload: string): SessionHandle {
|
|
91
162
|
const parsed = JSON.parse(payload) as {
|
|
92
163
|
state: SessionState;
|
|
93
164
|
};
|
|
94
|
-
|
|
95
|
-
parsed.state.model = { items: [] };
|
|
96
|
-
}
|
|
97
|
-
return this.sessions.create(parsed.state, this.contractVersion);
|
|
165
|
+
return this.sessions.create(normalizeImportedState(parsed.state), this.contractVersion);
|
|
98
166
|
}
|
|
99
167
|
|
|
100
168
|
public async setConstituentaValue(
|
package/src/models/session.ts
CHANGED
|
@@ -14,9 +14,20 @@ export interface SessionRevision {
|
|
|
14
14
|
|
|
15
15
|
export interface SessionState {
|
|
16
16
|
sessionId: string;
|
|
17
|
+
/** Library item alias for the conceptual schema or model. */
|
|
18
|
+
alias: string;
|
|
19
|
+
/** Human-readable title. */
|
|
20
|
+
title: string;
|
|
21
|
+
/** Developer comment (Portal JSON `description` on export). */
|
|
22
|
+
comment: string;
|
|
23
|
+
/** Date of creation. */
|
|
17
24
|
createdAt: string;
|
|
25
|
+
/** Date of last update. */
|
|
18
26
|
updatedAt: string;
|
|
27
|
+
/** List of revisions. */
|
|
19
28
|
revisions: SessionRevision[];
|
|
29
|
+
/** List of constituents in the session. */
|
|
20
30
|
items: ConstituentaState[];
|
|
31
|
+
/** Model state. */
|
|
21
32
|
model: SessionModelState;
|
|
22
33
|
}
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
type SessionState
|
|
26
26
|
} from './session';
|
|
27
27
|
|
|
28
|
-
export const CONTRACT_VERSION = '1.
|
|
28
|
+
export const CONTRACT_VERSION = '1.4.0';
|
|
29
29
|
|
|
30
30
|
export interface RSToolAgentContract {
|
|
31
31
|
readonly contractVersion: string;
|
|
@@ -36,6 +36,8 @@ export interface RSToolAgentContract {
|
|
|
36
36
|
listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[];
|
|
37
37
|
commitStep(sessionId: string, message?: string): SessionRevision;
|
|
38
38
|
exportSession(sessionId: string): string;
|
|
39
|
+
exportPortalSchema(sessionId: string): string;
|
|
40
|
+
exportPortalModel(sessionId: string): string;
|
|
39
41
|
importSession(payload: string): SessionHandle;
|
|
40
42
|
setConstituentaValue(sessionId: string, input: SetConstituentaValueInput): Promise<SessionModelState>;
|
|
41
43
|
setConstituentaValues(sessionId: string, input: SetConstituentaValuesInput): Promise<SessionModelState>;
|
|
@@ -21,6 +21,9 @@ export class SessionStore {
|
|
|
21
21
|
const sessionId = initial?.sessionId ?? randomUUID();
|
|
22
22
|
const state: SessionState = {
|
|
23
23
|
sessionId,
|
|
24
|
+
alias: initial?.alias ?? '',
|
|
25
|
+
title: initial?.title ?? '',
|
|
26
|
+
comment: initial?.comment ?? '',
|
|
24
27
|
createdAt: initial?.createdAt ?? now,
|
|
25
28
|
updatedAt: now,
|
|
26
29
|
revisions: initial?.revisions ?? [],
|
|
@@ -30,6 +30,8 @@ const METHODS = [
|
|
|
30
30
|
'listDiagnostics',
|
|
31
31
|
'commitStep',
|
|
32
32
|
'exportSession',
|
|
33
|
+
'exportPortalSchema',
|
|
34
|
+
'exportPortalModel',
|
|
33
35
|
'importSession',
|
|
34
36
|
'setConstituentaValue',
|
|
35
37
|
'setConstituentaValues',
|
|
@@ -116,6 +118,18 @@ async function handleRequest(request: StdioRequest): Promise<StdioResponse> {
|
|
|
116
118
|
ok: true,
|
|
117
119
|
result: tool.exportSession(requiredString(params, 'sessionId'))
|
|
118
120
|
};
|
|
121
|
+
case 'exportPortalSchema':
|
|
122
|
+
return {
|
|
123
|
+
id: request.id,
|
|
124
|
+
ok: true,
|
|
125
|
+
result: tool.exportPortalSchema(requiredString(params, 'sessionId'))
|
|
126
|
+
};
|
|
127
|
+
case 'exportPortalModel':
|
|
128
|
+
return {
|
|
129
|
+
id: request.id,
|
|
130
|
+
ok: true,
|
|
131
|
+
result: tool.exportPortalModel(requiredString(params, 'sessionId'))
|
|
132
|
+
};
|
|
119
133
|
case 'importSession':
|
|
120
134
|
return {
|
|
121
135
|
id: request.id,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rstool-agent.js","names":[],"sources":["../../src/models/rstool-agent.ts"],"sourcesContent":["import { ModelAdapter } from '../mappers/model-adapter';\nimport { SchemaAdapter } from '../mappers/schema-adapter';\nimport { SessionStore } from '../session/session-store';\nimport { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';\nimport {\n type AddOrUpdateConstituentaInput,\n type AddOrUpdateConstituentaResult\n} from './constituenta';\nimport { type ListDiagnosticsFilters } from './diagnostic';\nimport {\n type EvaluateConstituentaInput,\n type EvaluateExpressionInput,\n type EvaluationResult\n} from './evaluation';\nimport {\n type ClearConstituentaValuesInput,\n type RecalculateModelResult,\n type SessionModelState,\n type SetConstituentaValueInput,\n type SetConstituentaValuesInput\n} from './model-value';\nimport { type SessionHandle, type SessionRevision, type SessionState } from './session';\nimport { CONTRACT_VERSION, type RSToolAgentContract } from './tool-contract';\n\nexport class RSToolAgent implements RSToolAgentContract {\n public readonly contractVersion = CONTRACT_VERSION;\n private readonly sessions = new SessionStore();\n private readonly adapter = new SchemaAdapter();\n private readonly evaluation = new ModelAdapter();\n\n public createSession(initial?: Partial<SessionState>): SessionHandle {\n return this.sessions.create(initial, this.contractVersion);\n }\n\n public addOrUpdateConstituenta(\n sessionId: string,\n input: AddOrUpdateConstituentaInput\n ): AddOrUpdateConstituentaResult {\n const envelope = this.sessions.get(sessionId);\n const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, input.draft);\n const state = this.adapter.mergeStateWithDraft(envelope.state, input.draft, result);\n this.sessions.appendDiagnostics(sessionId, diagnostics);\n return {\n state,\n diagnostics\n };\n }\n\n public analyzeExpression(sessionId: string, input: AnalyzeExpressionInput): AnalysisResult {\n const envelope = this.sessions.get(sessionId);\n const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, {\n id: -1,\n alias: '_analysis',\n cstType: input.cstType,\n definitionFormal: input.expression\n });\n this.sessions.appendDiagnostics(\n sessionId,\n diagnostics.map(item => ({ ...item, constituentId: undefined }))\n );\n return result;\n }\n\n public getFormState(sessionId: string): SessionState {\n const envelope = this.sessions.get(sessionId);\n return structuredClone(envelope.state);\n }\n\n public listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters) {\n return this.sessions.listDiagnostics(sessionId, filters);\n }\n\n public commitStep(sessionId: string, message?: string): SessionRevision {\n return this.sessions.addRevision(sessionId, message);\n }\n\n public exportSession(sessionId: string): string {\n const envelope = this.sessions.get(sessionId);\n return JSON.stringify(\n {\n contractVersion: this.contractVersion,\n state: envelope.state,\n diagnostics: envelope.diagnostics\n },\n null,\n 2\n );\n }\n\n public importSession(payload: string): SessionHandle {\n const parsed = JSON.parse(payload) as {\n state: SessionState;\n };\n if (!parsed.state.model) {\n parsed.state.model = { items: [] };\n }\n return this.sessions.create(parsed.state, this.contractVersion);\n }\n\n public async setConstituentaValue(\n sessionId: string,\n input: SetConstituentaValueInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.setConstituentaValue(envelope.state, input);\n }\n\n public async setConstituentaValues(\n sessionId: string,\n input: SetConstituentaValuesInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.setConstituentaValues(envelope.state, input);\n }\n\n public async clearConstituentaValues(\n sessionId: string,\n input: ClearConstituentaValuesInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.clearConstituentaValues(envelope.state, input.items);\n }\n\n public getModelState(sessionId: string): SessionModelState {\n const envelope = this.sessions.get(sessionId);\n return structuredClone(envelope.state.model);\n }\n\n public evaluateExpression(sessionId: string, input: EvaluateExpressionInput): EvaluationResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.evaluateExpression(envelope.state, input.expression, input.cstType);\n }\n\n public evaluateConstituenta(sessionId: string, input: EvaluateConstituentaInput): EvaluationResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.evaluateConstituenta(envelope.state, input.constituentId);\n }\n\n public recalculateModel(sessionId: string): RecalculateModelResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.recalculateModel(envelope.state);\n }\n}\n"],"mappings":";;;;;AAwBA,IAAa,cAAb,MAAwD;CACtD,kBAAkC;CAClC,WAA4B,IAAI,aAAa;CAC7C,UAA2B,IAAI,cAAc;CAC7C,aAA8B,IAAI,aAAa;CAE/C,cAAqB,SAAgD;EACnE,OAAO,KAAK,SAAS,OAAO,SAAS,KAAK,eAAe;CAC3D;CAEA,wBACE,WACA,OAC+B;EAC/B,MAAM,WAAW,KAAK,SAAS,IAAI,SAAS;EAC5C,MAAM,EAAE,QAAQ,gBAAgB,KAAK,QAAQ,sBAAsB,SAAS,OAAO,MAAM,KAAK;EAC9F,MAAM,QAAQ,KAAK,QAAQ,oBAAoB,SAAS,OAAO,MAAM,OAAO,MAAM;EAClF,KAAK,SAAS,kBAAkB,WAAW,WAAW;EACtD,OAAO;GACL;GACA;EACF;CACF;CAEA,kBAAyB,WAAmB,OAA+C;EACzF,MAAM,WAAW,KAAK,SAAS,IAAI,SAAS;EAC5C,MAAM,EAAE,QAAQ,gBAAgB,KAAK,QAAQ,sBAAsB,SAAS,OAAO;GACjF,IAAI;GACJ,OAAO;GACP,SAAS,MAAM;GACf,kBAAkB,MAAM;E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