@rsconcept/rstool 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -26
- package/dist/analysis-JiwOYDKx.d.ts +16 -0
- package/dist/common-DxLg3eXX.d.ts +17 -0
- package/dist/constituenta-Dnd6iToB.d.ts +36 -0
- package/dist/diagnostic-BMYvciz8.d.ts +15 -0
- package/dist/evaluation-CCVYH0wA.d.ts +21 -0
- package/dist/index.d.ts +12 -15
- package/dist/index.js +7 -585
- package/dist/mappers/model-adapter.d.ts +18 -23
- package/dist/mappers/model-adapter.js +183 -231
- package/dist/mappers/model-adapter.js.map +1 -1
- package/dist/mappers/schema-adapter.d.ts +16 -18
- package/dist/mappers/schema-adapter.js +55 -84
- package/dist/mappers/schema-adapter.js.map +1 -1
- package/dist/mappers/types.d.ts +15 -16
- package/dist/mappers/types.js +16 -17
- package/dist/mappers/types.js.map +1 -1
- package/dist/model-value-SFAVj0dw.d.ts +35 -0
- package/dist/models/analysis.d.ts +2 -18
- package/dist/models/analysis.js +1 -1
- package/dist/models/common.d.ts +2 -15
- package/dist/models/common.js +1 -8
- package/dist/models/constituenta.d.ts +2 -38
- package/dist/models/constituenta.js +1 -1
- package/dist/models/diagnostic.d.ts +2 -17
- package/dist/models/diagnostic.js +1 -1
- package/dist/models/evaluation.d.ts +2 -23
- package/dist/models/evaluation.js +1 -1
- package/dist/models/index.d.ts +10 -13
- package/dist/models/index.js +4 -491
- package/dist/models/model-value.d.ts +2 -37
- package/dist/models/model-value.js +1 -1
- package/dist/models/rstool-agent.d.ts +2 -36
- package/dist/models/rstool-agent.js +90 -477
- package/dist/models/rstool-agent.js.map +1 -1
- package/dist/models/session.d.ts +2 -29
- package/dist/models/session.js +1 -1
- package/dist/models/tool-contract.d.ts +2 -33
- package/dist/models/tool-contract.js +5 -5
- package/dist/models/tool-contract.js.map +1 -1
- package/dist/rstool-agent-DkeH5Qml.d.ts +33 -0
- package/dist/session/session-store.d.ts +14 -21
- package/dist/session/session-store.js +59 -63
- package/dist/session/session-store.js.map +1 -1
- package/dist/session-BHGCCLfQ.d.ts +24 -0
- package/dist/tool-contract-CsGqg_0P.d.ts +30 -0
- package/dist/wrapper/client.d.ts +26 -24
- package/dist/wrapper/client.js +90 -93
- package/dist/wrapper/client.js.map +1 -1
- package/dist/wrapper/stdio-wrapper.d.ts +1 -1
- package/dist/wrapper/stdio-wrapper.js +166 -664
- package/dist/wrapper/stdio-wrapper.js.map +1 -1
- package/docs/CONCEPTUAL-SCHEMA.md +168 -0
- package/docs/CONSTITUENTA.md +46 -23
- package/docs/DIAGNOSTICS.md +79 -74
- package/docs/DOMAIN.md +32 -30
- package/docs/GRAMMAR-REF.md +55 -55
- package/docs/PORTAL-API.md +7 -10
- package/docs/README.md +1 -0
- package/docs/SYNTAX.md +32 -32
- package/docs/TYPIFICATION.md +14 -9
- package/package.json +8 -7
- package/skills/INSTALL.md +35 -0
- package/skills/README.md +17 -9
- package/skills/rstool-helper/EXAMPLES.md +51 -10
- package/skills/rstool-helper/GUIDE.md +141 -0
- package/skills/rstool-helper/REFERENCE.md +5 -3
- package/skills/rstool-helper/SKILL.md +23 -134
- package/dist/index.js.map +0 -1
- package/dist/models/analysis.js.map +0 -1
- package/dist/models/common.js.map +0 -1
- package/dist/models/constituenta.js.map +0 -1
- package/dist/models/diagnostic.js.map +0 -1
- package/dist/models/evaluation.js.map +0 -1
- package/dist/models/index.js.map +0 -1
- package/dist/models/model-value.js.map +0 -1
- package/dist/models/session.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,585 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function toPublicAnalysis(analysis) {
|
|
11
|
-
return {
|
|
12
|
-
success: analysis.success,
|
|
13
|
-
type: analysis.type,
|
|
14
|
-
valueClass: analysis.valueClass,
|
|
15
|
-
diagnostics: analysis.errors.map(toPublicError)
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/models/common.ts
|
|
20
|
-
import { CstType } from "@rsconcept/domain/library/rsform";
|
|
21
|
-
import { EvalStatus } from "@rsconcept/domain/library/rsmodel";
|
|
22
|
-
import { ValueClass } from "@rsconcept/domain/rslang";
|
|
23
|
-
import { RSErrorCode } from "@rsconcept/domain/rslang/error";
|
|
24
|
-
|
|
25
|
-
// src/mappers/model-adapter.ts
|
|
26
|
-
import { Graph } from "@rsconcept/domain/graph/graph";
|
|
27
|
-
import { extractGlobals } from "@rsconcept/domain/rslang/api";
|
|
28
|
-
import { RSLangAnalyzer } from "@rsconcept/domain/rslang";
|
|
29
|
-
import { isBaseSet } from "@rsconcept/domain/library/rsform-api";
|
|
30
|
-
import { CstType as CstType2 } from "@rsconcept/domain/library/rsform";
|
|
31
|
-
import { RSEngine } from "@rsconcept/domain/library/rsengine";
|
|
32
|
-
import { EvalStatus as EvalStatus2 } from "@rsconcept/domain/library/rsmodel";
|
|
33
|
-
import {
|
|
34
|
-
isInferrable,
|
|
35
|
-
isInterpretable,
|
|
36
|
-
toBasicBinding,
|
|
37
|
-
validateBasicBindingData,
|
|
38
|
-
validateValueData
|
|
39
|
-
} from "@rsconcept/domain/library/rsmodel-api";
|
|
40
|
-
var SESSION_MODEL_ID = 0;
|
|
41
|
-
var ModelAdapter = class {
|
|
42
|
-
async setConstituentaValue(session, input) {
|
|
43
|
-
this.validateSetInput(session, input);
|
|
44
|
-
const engine = this.createEngine(session);
|
|
45
|
-
const cst = session.items.find((item) => item.id === input.target);
|
|
46
|
-
const frontendType = cst.cstType;
|
|
47
|
-
if (isBaseSet(frontendType)) {
|
|
48
|
-
const binding = toBasicBinding(input.value);
|
|
49
|
-
await engine.setBasicValue(input.target, binding);
|
|
50
|
-
} else {
|
|
51
|
-
await engine.setStructureValue(input.target, input.value);
|
|
52
|
-
}
|
|
53
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
54
|
-
return structuredClone(session.model);
|
|
55
|
-
}
|
|
56
|
-
async setConstituentaValues(session, input) {
|
|
57
|
-
for (const item of input.items) {
|
|
58
|
-
await this.setConstituentaValue(session, item);
|
|
59
|
-
}
|
|
60
|
-
return structuredClone(session.model);
|
|
61
|
-
}
|
|
62
|
-
async clearConstituentaValues(session, ids) {
|
|
63
|
-
const engine = this.createEngine(session);
|
|
64
|
-
for (const id of ids) {
|
|
65
|
-
await engine.resetValue(id);
|
|
66
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
67
|
-
}
|
|
68
|
-
return structuredClone(session.model);
|
|
69
|
-
}
|
|
70
|
-
evaluateExpression(session, expression, cstType) {
|
|
71
|
-
const engine = this.createEngine(session);
|
|
72
|
-
const result = engine.evaluateExpression(expression, cstType);
|
|
73
|
-
const status = result.value === null ? result.errors.length > 0 ? EvalStatus2.EVAL_FAIL : EvalStatus2.EMPTY : EvalStatus2.HAS_DATA;
|
|
74
|
-
return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);
|
|
75
|
-
}
|
|
76
|
-
evaluateConstituenta(session, constituentId) {
|
|
77
|
-
const cst = session.items.find((item) => item.id === constituentId);
|
|
78
|
-
if (!cst) {
|
|
79
|
-
throw new Error(`Unknown constituent: ${constituentId}`);
|
|
80
|
-
}
|
|
81
|
-
const engine = this.createEngine(session);
|
|
82
|
-
const result = engine.calculateCst(constituentId);
|
|
83
|
-
const status = engine.getCstStatus(constituentId);
|
|
84
|
-
return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);
|
|
85
|
-
}
|
|
86
|
-
recalculateModel(session) {
|
|
87
|
-
const engine = this.createEngine(session);
|
|
88
|
-
engine.recalculateAll();
|
|
89
|
-
const items = session.items.map((item) => ({
|
|
90
|
-
id: item.id,
|
|
91
|
-
alias: item.alias,
|
|
92
|
-
value: engine.getCstValue(item.id),
|
|
93
|
-
status: engine.getCstStatus(item.id)
|
|
94
|
-
}));
|
|
95
|
-
return { items };
|
|
96
|
-
}
|
|
97
|
-
createEngine(session) {
|
|
98
|
-
const schema = buildRSFormFromSession(session);
|
|
99
|
-
const model = buildRSModelFromSession(session);
|
|
100
|
-
const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));
|
|
101
|
-
engine.loadData(schema, model);
|
|
102
|
-
return engine;
|
|
103
|
-
}
|
|
104
|
-
validateSetInput(session, input) {
|
|
105
|
-
const cst = session.items.find((item) => item.id === input.target);
|
|
106
|
-
if (!cst) {
|
|
107
|
-
throw new Error(`Unknown constituent: ${input.target}`);
|
|
108
|
-
}
|
|
109
|
-
const frontendType = cst.cstType;
|
|
110
|
-
if (!isInterpretable(frontendType)) {
|
|
111
|
-
throw new Error(`Constituent ${cst.alias} is not interpretable`);
|
|
112
|
-
}
|
|
113
|
-
if (isInferrable(frontendType)) {
|
|
114
|
-
throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);
|
|
115
|
-
}
|
|
116
|
-
if (isBaseSet(frontendType)) {
|
|
117
|
-
if (!validateBasicBindingData(input.value)) {
|
|
118
|
-
throw new Error(`Invalid basic binding for ${cst.alias}`);
|
|
119
|
-
}
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (!validateValueData(input.value)) {
|
|
123
|
-
throw new Error(`Invalid structured value for ${cst.alias}`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
function createInMemoryServices(session) {
|
|
128
|
-
return {
|
|
129
|
-
setCstValue: async ({ data }) => {
|
|
130
|
-
for (const item of data) {
|
|
131
|
-
const entry = {
|
|
132
|
-
id: item.target,
|
|
133
|
-
type: item.type,
|
|
134
|
-
value: item.data
|
|
135
|
-
};
|
|
136
|
-
const index = session.model.items.findIndex((existing) => existing.id === item.target);
|
|
137
|
-
if (index === -1) {
|
|
138
|
-
session.model.items.push(entry);
|
|
139
|
-
} else {
|
|
140
|
-
session.model.items[index] = entry;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
clearValues: async ({ data }) => {
|
|
145
|
-
const ids = new Set(data.items);
|
|
146
|
-
session.model.items = session.model.items.filter((item) => !ids.has(item.id));
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function buildRSFormFromSession(session) {
|
|
151
|
-
const graph = new Graph();
|
|
152
|
-
const cstByAlias = /* @__PURE__ */ new Map();
|
|
153
|
-
const cstByID = /* @__PURE__ */ new Map();
|
|
154
|
-
const analyzer = new RSLangAnalyzer();
|
|
155
|
-
const items = session.items.map((item) => {
|
|
156
|
-
const cst = toFrontendConstituenta(item);
|
|
157
|
-
cstByAlias.set(cst.alias, cst);
|
|
158
|
-
cstByID.set(cst.id, cst);
|
|
159
|
-
graph.addNode(cst.id);
|
|
160
|
-
if (item.cstType === CstType2.BASE) {
|
|
161
|
-
analyzer.addBase(cst.alias);
|
|
162
|
-
}
|
|
163
|
-
if (cst.effectiveType) {
|
|
164
|
-
analyzer.setGlobal(cst.alias, cst.effectiveType, cst.analysis.valueClass);
|
|
165
|
-
}
|
|
166
|
-
return cst;
|
|
167
|
-
});
|
|
168
|
-
for (const cst of items) {
|
|
169
|
-
for (const alias of extractGlobals(cst.definition_formal)) {
|
|
170
|
-
const source = cstByAlias.get(alias);
|
|
171
|
-
if (source) {
|
|
172
|
-
graph.addEdge(source.id, cst.id);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
id: 0,
|
|
178
|
-
items,
|
|
179
|
-
cstByAlias,
|
|
180
|
-
cstByID,
|
|
181
|
-
graph,
|
|
182
|
-
analyzer,
|
|
183
|
-
inheritance: [],
|
|
184
|
-
attribution: [],
|
|
185
|
-
attribution_graph: graph.clone(),
|
|
186
|
-
oss: [],
|
|
187
|
-
models: [],
|
|
188
|
-
editors: [],
|
|
189
|
-
versions: [],
|
|
190
|
-
is_produced: false,
|
|
191
|
-
is_attributive: false,
|
|
192
|
-
version: "latest"
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
function buildRSModelFromSession(session) {
|
|
196
|
-
return {
|
|
197
|
-
id: SESSION_MODEL_ID,
|
|
198
|
-
schema: 0,
|
|
199
|
-
editors: [],
|
|
200
|
-
items: session.model.items.map((item) => ({
|
|
201
|
-
id: item.id,
|
|
202
|
-
type: item.type,
|
|
203
|
-
value: item.value
|
|
204
|
-
}))
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function toFrontendConstituenta(item) {
|
|
208
|
-
const effectiveType = item.analysis.type ?? null;
|
|
209
|
-
return {
|
|
210
|
-
id: item.id,
|
|
211
|
-
alias: item.alias,
|
|
212
|
-
cst_type: item.cstType,
|
|
213
|
-
definition_formal: item.definitionFormal,
|
|
214
|
-
definition_raw: item.definitionFormal,
|
|
215
|
-
definition_resolved: item.definitionFormal,
|
|
216
|
-
term_raw: item.term,
|
|
217
|
-
term_resolved: item.term,
|
|
218
|
-
term_forms: [],
|
|
219
|
-
convention: item.convention,
|
|
220
|
-
typification_manual: "",
|
|
221
|
-
value_is_property: false,
|
|
222
|
-
crucial: false,
|
|
223
|
-
attributes: [],
|
|
224
|
-
homonyms: [],
|
|
225
|
-
formalDuplicates: [],
|
|
226
|
-
analysis: {
|
|
227
|
-
success: item.analysis.success,
|
|
228
|
-
type: effectiveType,
|
|
229
|
-
valueClass: item.analysis.valueClass
|
|
230
|
-
},
|
|
231
|
-
effectiveType,
|
|
232
|
-
is_type_mismatch: false,
|
|
233
|
-
schema: 0,
|
|
234
|
-
cst_class: "derived",
|
|
235
|
-
status: item.analysis.success ? "verified" : "incorrect",
|
|
236
|
-
is_template: false,
|
|
237
|
-
is_simple_expression: true,
|
|
238
|
-
parent_schema_index: 0,
|
|
239
|
-
parent_schema: null,
|
|
240
|
-
is_inherited: false,
|
|
241
|
-
has_inherited_children: false,
|
|
242
|
-
spawn: [],
|
|
243
|
-
spawn_alias: []
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
function toPublicEvaluationResult(value, errors, iterations, cacheHits, status) {
|
|
247
|
-
const diagnostics = errors.map(toPublicError);
|
|
248
|
-
return {
|
|
249
|
-
success: diagnostics.length === 0 && value !== null,
|
|
250
|
-
value,
|
|
251
|
-
status,
|
|
252
|
-
iterations,
|
|
253
|
-
cacheHits,
|
|
254
|
-
diagnostics
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// src/mappers/schema-adapter.ts
|
|
259
|
-
import { RSLangAnalyzer as RSLangAnalyzer2 } from "@rsconcept/domain/rslang";
|
|
260
|
-
import { getAnalysisFor } from "@rsconcept/domain/library/rsform-api";
|
|
261
|
-
import { CstType as CstType3 } from "@rsconcept/domain/library/rsform";
|
|
262
|
-
var SchemaAdapter = class {
|
|
263
|
-
analyzeAgainstSession(session, draft) {
|
|
264
|
-
const analyzer = this.buildAnalyzer(session);
|
|
265
|
-
const schema = this.toPseudoRSFormState(session, analyzer);
|
|
266
|
-
const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema, draft.alias);
|
|
267
|
-
const result = toPublicAnalysis({
|
|
268
|
-
success: analysis.success,
|
|
269
|
-
type: analysis.type,
|
|
270
|
-
valueClass: analysis.valueClass,
|
|
271
|
-
errors: analysis.errors
|
|
272
|
-
});
|
|
273
|
-
return {
|
|
274
|
-
result,
|
|
275
|
-
diagnostics: analysis.errors.map((error) => ({
|
|
276
|
-
sessionId: session.sessionId,
|
|
277
|
-
constituentId: draft.id,
|
|
278
|
-
expression: draft.definitionFormal,
|
|
279
|
-
error: toPublicError(error)
|
|
280
|
-
}))
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
mergeStateWithDraft(session, draft, analysis) {
|
|
284
|
-
const state = {
|
|
285
|
-
...draft,
|
|
286
|
-
term: draft.term ?? "",
|
|
287
|
-
definitionText: draft.definitionText ?? "",
|
|
288
|
-
convention: draft.convention ?? "",
|
|
289
|
-
analysis
|
|
290
|
-
};
|
|
291
|
-
const index = session.items.findIndex((item) => item.id === draft.id);
|
|
292
|
-
if (index === -1) {
|
|
293
|
-
session.items.push(state);
|
|
294
|
-
} else {
|
|
295
|
-
session.items[index] = state;
|
|
296
|
-
}
|
|
297
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
298
|
-
return state;
|
|
299
|
-
}
|
|
300
|
-
toPseudoRSFormState(session, analyzer) {
|
|
301
|
-
const cstByAlias = new Map(session.items.map((item) => [item.alias, item]));
|
|
302
|
-
return {
|
|
303
|
-
items: session.items,
|
|
304
|
-
cstByAlias,
|
|
305
|
-
analyzer
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
buildAnalyzer(session) {
|
|
309
|
-
const analyzer = new RSLangAnalyzer2();
|
|
310
|
-
for (const item of session.items) {
|
|
311
|
-
if (item.cstType === CstType3.BASE) {
|
|
312
|
-
analyzer.addBase(item.alias);
|
|
313
|
-
}
|
|
314
|
-
analyzer.setGlobal(
|
|
315
|
-
item.alias,
|
|
316
|
-
item.analysis.type,
|
|
317
|
-
item.analysis.valueClass
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
return analyzer;
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
// src/session/session-store.ts
|
|
325
|
-
import { randomUUID } from "crypto";
|
|
326
|
-
var SessionStore = class {
|
|
327
|
-
sessions = /* @__PURE__ */ new Map();
|
|
328
|
-
create(initial, contractVersion) {
|
|
329
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
330
|
-
const sessionId = initial?.sessionId ?? randomUUID();
|
|
331
|
-
const state = {
|
|
332
|
-
sessionId,
|
|
333
|
-
createdAt: initial?.createdAt ?? now,
|
|
334
|
-
updatedAt: now,
|
|
335
|
-
revisions: initial?.revisions ?? [],
|
|
336
|
-
items: initial?.items ?? [],
|
|
337
|
-
model: initial?.model ?? { items: [] }
|
|
338
|
-
};
|
|
339
|
-
this.sessions.set(sessionId, {
|
|
340
|
-
state,
|
|
341
|
-
diagnostics: []
|
|
342
|
-
});
|
|
343
|
-
return {
|
|
344
|
-
sessionId,
|
|
345
|
-
contractVersion: contractVersion ?? "1.0.0"
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
get(sessionId) {
|
|
349
|
-
const found = this.sessions.get(sessionId);
|
|
350
|
-
if (!found) {
|
|
351
|
-
throw new Error(`Unknown session: ${sessionId}`);
|
|
352
|
-
}
|
|
353
|
-
return found;
|
|
354
|
-
}
|
|
355
|
-
replaceState(sessionId, nextState) {
|
|
356
|
-
const found = this.get(sessionId);
|
|
357
|
-
found.state = {
|
|
358
|
-
...nextState,
|
|
359
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
addRevision(sessionId, message) {
|
|
363
|
-
const found = this.get(sessionId);
|
|
364
|
-
const revision = {
|
|
365
|
-
revisionId: randomUUID(),
|
|
366
|
-
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
367
|
-
message
|
|
368
|
-
};
|
|
369
|
-
found.state.revisions.push(revision);
|
|
370
|
-
found.state.updatedAt = revision.at;
|
|
371
|
-
return revision;
|
|
372
|
-
}
|
|
373
|
-
appendDiagnostics(sessionId, records) {
|
|
374
|
-
const found = this.get(sessionId);
|
|
375
|
-
found.diagnostics.push(...records);
|
|
376
|
-
found.state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
377
|
-
}
|
|
378
|
-
listDiagnostics(sessionId, filters) {
|
|
379
|
-
const found = this.get(sessionId);
|
|
380
|
-
if (!filters?.constituentId) {
|
|
381
|
-
return [...found.diagnostics];
|
|
382
|
-
}
|
|
383
|
-
return found.diagnostics.filter((record) => record.constituentId === filters.constituentId);
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
// src/models/tool-contract.ts
|
|
388
|
-
var CONTRACT_VERSION = "1.2.0";
|
|
389
|
-
|
|
390
|
-
// src/models/rstool-agent.ts
|
|
391
|
-
var RSToolAgent = class {
|
|
392
|
-
contractVersion = CONTRACT_VERSION;
|
|
393
|
-
sessions = new SessionStore();
|
|
394
|
-
adapter = new SchemaAdapter();
|
|
395
|
-
evaluation = new ModelAdapter();
|
|
396
|
-
createSession(initial) {
|
|
397
|
-
return this.sessions.create(initial, this.contractVersion);
|
|
398
|
-
}
|
|
399
|
-
addOrUpdateConstituenta(sessionId, input) {
|
|
400
|
-
const envelope = this.sessions.get(sessionId);
|
|
401
|
-
const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, input.draft);
|
|
402
|
-
const state = this.adapter.mergeStateWithDraft(envelope.state, input.draft, result);
|
|
403
|
-
this.sessions.appendDiagnostics(sessionId, diagnostics);
|
|
404
|
-
return {
|
|
405
|
-
state,
|
|
406
|
-
diagnostics
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
analyzeExpression(sessionId, input) {
|
|
410
|
-
const envelope = this.sessions.get(sessionId);
|
|
411
|
-
const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, {
|
|
412
|
-
id: -1,
|
|
413
|
-
alias: "_analysis",
|
|
414
|
-
cstType: input.cstType,
|
|
415
|
-
definitionFormal: input.expression
|
|
416
|
-
});
|
|
417
|
-
this.sessions.appendDiagnostics(
|
|
418
|
-
sessionId,
|
|
419
|
-
diagnostics.map((item) => ({ ...item, constituentId: void 0 }))
|
|
420
|
-
);
|
|
421
|
-
return result;
|
|
422
|
-
}
|
|
423
|
-
getFormState(sessionId) {
|
|
424
|
-
const envelope = this.sessions.get(sessionId);
|
|
425
|
-
return structuredClone(envelope.state);
|
|
426
|
-
}
|
|
427
|
-
listDiagnostics(sessionId, filters) {
|
|
428
|
-
return this.sessions.listDiagnostics(sessionId, filters);
|
|
429
|
-
}
|
|
430
|
-
commitStep(sessionId, message) {
|
|
431
|
-
return this.sessions.addRevision(sessionId, message);
|
|
432
|
-
}
|
|
433
|
-
exportSession(sessionId) {
|
|
434
|
-
const envelope = this.sessions.get(sessionId);
|
|
435
|
-
return JSON.stringify(
|
|
436
|
-
{
|
|
437
|
-
contractVersion: this.contractVersion,
|
|
438
|
-
state: envelope.state,
|
|
439
|
-
diagnostics: envelope.diagnostics
|
|
440
|
-
},
|
|
441
|
-
null,
|
|
442
|
-
2
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
importSession(payload) {
|
|
446
|
-
const parsed = JSON.parse(payload);
|
|
447
|
-
if (!parsed.state.model) {
|
|
448
|
-
parsed.state.model = { items: [] };
|
|
449
|
-
}
|
|
450
|
-
return this.sessions.create(parsed.state, this.contractVersion);
|
|
451
|
-
}
|
|
452
|
-
async setConstituentaValue(sessionId, input) {
|
|
453
|
-
const envelope = this.sessions.get(sessionId);
|
|
454
|
-
return this.evaluation.setConstituentaValue(envelope.state, input);
|
|
455
|
-
}
|
|
456
|
-
async setConstituentaValues(sessionId, input) {
|
|
457
|
-
const envelope = this.sessions.get(sessionId);
|
|
458
|
-
return this.evaluation.setConstituentaValues(envelope.state, input);
|
|
459
|
-
}
|
|
460
|
-
async clearConstituentaValues(sessionId, input) {
|
|
461
|
-
const envelope = this.sessions.get(sessionId);
|
|
462
|
-
return this.evaluation.clearConstituentaValues(envelope.state, input.items);
|
|
463
|
-
}
|
|
464
|
-
getModelState(sessionId) {
|
|
465
|
-
const envelope = this.sessions.get(sessionId);
|
|
466
|
-
return structuredClone(envelope.state.model);
|
|
467
|
-
}
|
|
468
|
-
evaluateExpression(sessionId, input) {
|
|
469
|
-
const envelope = this.sessions.get(sessionId);
|
|
470
|
-
return this.evaluation.evaluateExpression(envelope.state, input.expression, input.cstType);
|
|
471
|
-
}
|
|
472
|
-
evaluateConstituenta(sessionId, input) {
|
|
473
|
-
const envelope = this.sessions.get(sessionId);
|
|
474
|
-
return this.evaluation.evaluateConstituenta(envelope.state, input.constituentId);
|
|
475
|
-
}
|
|
476
|
-
recalculateModel(sessionId) {
|
|
477
|
-
const envelope = this.sessions.get(sessionId);
|
|
478
|
-
return this.evaluation.recalculateModel(envelope.state);
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
// src/wrapper/client.ts
|
|
483
|
-
import { spawn } from "child_process";
|
|
484
|
-
import readline from "readline";
|
|
485
|
-
var RSToolWrapperClient = class {
|
|
486
|
-
process;
|
|
487
|
-
input;
|
|
488
|
-
pending = /* @__PURE__ */ new Map();
|
|
489
|
-
requestCounter = 1;
|
|
490
|
-
constructor(options = {}) {
|
|
491
|
-
this.process = spawn(options.command ?? "npm", options.args ?? ["run", "wrapper"], {
|
|
492
|
-
cwd: options.cwd ?? process.cwd(),
|
|
493
|
-
shell: options.shell ?? true,
|
|
494
|
-
stdio: ["pipe", "pipe", "inherit"]
|
|
495
|
-
});
|
|
496
|
-
this.input = readline.createInterface({
|
|
497
|
-
input: this.process.stdout,
|
|
498
|
-
crlfDelay: Infinity
|
|
499
|
-
});
|
|
500
|
-
this.input.on("line", (line) => this.handleLine(line));
|
|
501
|
-
}
|
|
502
|
-
async waitUntilReady() {
|
|
503
|
-
for (; ; ) {
|
|
504
|
-
const line = await this.readOneEvent();
|
|
505
|
-
let response = null;
|
|
506
|
-
try {
|
|
507
|
-
response = JSON.parse(line);
|
|
508
|
-
} catch {
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
if (response.ok && response.result?.ready) {
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
async call(method, params = {}) {
|
|
517
|
-
const id = String(this.requestCounter++);
|
|
518
|
-
const payload = JSON.stringify({ id, method, params });
|
|
519
|
-
const responsePromise = new Promise((resolve) => {
|
|
520
|
-
this.pending.set(id, resolve);
|
|
521
|
-
});
|
|
522
|
-
this.process.stdin.write(`${payload}
|
|
523
|
-
`);
|
|
524
|
-
const response = await responsePromise;
|
|
525
|
-
if (!response.ok) {
|
|
526
|
-
throw new Error(`${response.error?.code ?? "UNKNOWN"}: ${response.error?.message ?? "Request failed"}`);
|
|
527
|
-
}
|
|
528
|
-
return response.result;
|
|
529
|
-
}
|
|
530
|
-
async close() {
|
|
531
|
-
this.input.close();
|
|
532
|
-
this.process.stdin.end();
|
|
533
|
-
if (!this.process.killed) {
|
|
534
|
-
this.process.kill();
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
async readOneEvent() {
|
|
538
|
-
return new Promise((resolve, reject) => {
|
|
539
|
-
const onLine = (line) => {
|
|
540
|
-
cleanup();
|
|
541
|
-
resolve(line);
|
|
542
|
-
};
|
|
543
|
-
const onExit = () => {
|
|
544
|
-
cleanup();
|
|
545
|
-
reject(new Error("Wrapper exited before ready"));
|
|
546
|
-
};
|
|
547
|
-
const cleanup = () => {
|
|
548
|
-
this.input.off("line", onLine);
|
|
549
|
-
this.process.off("exit", onExit);
|
|
550
|
-
};
|
|
551
|
-
this.input.on("line", onLine);
|
|
552
|
-
this.process.on("exit", onExit);
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
handleLine(line) {
|
|
556
|
-
let parsed;
|
|
557
|
-
try {
|
|
558
|
-
parsed = JSON.parse(line);
|
|
559
|
-
} catch {
|
|
560
|
-
return;
|
|
561
|
-
}
|
|
562
|
-
if (parsed.id === null || parsed.id === void 0) {
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
const id = String(parsed.id);
|
|
566
|
-
const resolver = this.pending.get(id);
|
|
567
|
-
if (!resolver) {
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
this.pending.delete(id);
|
|
571
|
-
resolver(parsed);
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
export {
|
|
575
|
-
CONTRACT_VERSION,
|
|
576
|
-
CstType,
|
|
577
|
-
EvalStatus,
|
|
578
|
-
RSErrorCode,
|
|
579
|
-
RSToolAgent,
|
|
580
|
-
RSToolWrapperClient,
|
|
581
|
-
ValueClass,
|
|
582
|
-
toPublicAnalysis,
|
|
583
|
-
toPublicError
|
|
584
|
-
};
|
|
585
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { toPublicAnalysis, toPublicError } from "./mappers/types.js";
|
|
2
|
+
import { CstType, EvalStatus, RSErrorCode, ValueClass } from "./models/common.js";
|
|
3
|
+
import { CONTRACT_VERSION } from "./models/tool-contract.js";
|
|
4
|
+
import { RSToolAgent } from "./models/rstool-agent.js";
|
|
5
|
+
import "./models/index.js";
|
|
6
|
+
import { RSToolWrapperClient } from "./wrapper/client.js";
|
|
7
|
+
export { CONTRACT_VERSION, CstType, EvalStatus, RSErrorCode, RSToolAgent, RSToolWrapperClient, ValueClass, toPublicAnalysis, toPublicError };
|
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import '../models/common.js';
|
|
7
|
-
import '@rsconcept/domain/library/rsmodel';
|
|
8
|
-
import '@rsconcept/domain/rslang';
|
|
9
|
-
import '@rsconcept/domain/rslang/error';
|
|
10
|
-
import '../models/constituenta.js';
|
|
11
|
-
import '../models/analysis.js';
|
|
12
|
-
import '../models/diagnostic.js';
|
|
1
|
+
import { r as EvaluationResult } from "../evaluation-CCVYH0wA.js";
|
|
2
|
+
import { a as SetConstituentaValueInput, i as SessionModelState, r as RecalculateModelResult } from "../model-value-SFAVj0dw.js";
|
|
3
|
+
import { r as SessionState } from "../session-BHGCCLfQ.js";
|
|
4
|
+
import { CstType } from "@rsconcept/domain/library/rsform";
|
|
5
|
+
import { RSEngine } from "@rsconcept/domain/library/rsengine";
|
|
13
6
|
|
|
7
|
+
//#region src/mappers/model-adapter.d.ts
|
|
14
8
|
declare class ModelAdapter {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
setConstituentaValue(session: SessionState, input: SetConstituentaValueInput): Promise<SessionModelState>;
|
|
10
|
+
setConstituentaValues(session: SessionState, input: {
|
|
11
|
+
items: SetConstituentaValueInput[];
|
|
12
|
+
}): Promise<SessionModelState>;
|
|
13
|
+
clearConstituentaValues(session: SessionState, ids: number[]): Promise<SessionModelState>;
|
|
14
|
+
evaluateExpression(session: SessionState, expression: string, cstType: CstType): EvaluationResult;
|
|
15
|
+
evaluateConstituenta(session: SessionState, constituentId: number): EvaluationResult;
|
|
16
|
+
recalculateModel(session: SessionState): RecalculateModelResult;
|
|
17
|
+
createEngine(session: SessionState): RSEngine;
|
|
18
|
+
private validateSetInput;
|
|
25
19
|
}
|
|
26
|
-
|
|
20
|
+
//#endregion
|
|
27
21
|
export { ModelAdapter };
|
|
22
|
+
//# sourceMappingURL=model-adapter.d.ts.map
|