@rsconcept/rstool 0.1.0 → 0.2.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 +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/CONSTITUENTA.md +39 -23
- package/docs/DIAGNOSTICS.md +79 -74
- package/docs/DOMAIN.md +5 -3
- package/docs/GRAMMAR-REF.md +55 -55
- package/docs/PORTAL-API.md +7 -10
- 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 +133 -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
|
@@ -1,480 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { CstType } from "@rsconcept/domain/library/rsform";
|
|
7
|
-
import { RSEngine } from "@rsconcept/domain/library/rsengine";
|
|
8
|
-
import { EvalStatus } from "@rsconcept/domain/library/rsmodel";
|
|
9
|
-
import {
|
|
10
|
-
isInferrable,
|
|
11
|
-
isInterpretable,
|
|
12
|
-
toBasicBinding,
|
|
13
|
-
validateBasicBindingData,
|
|
14
|
-
validateValueData
|
|
15
|
-
} from "@rsconcept/domain/library/rsmodel-api";
|
|
16
|
-
|
|
17
|
-
// src/mappers/types.ts
|
|
18
|
-
function toPublicError(error) {
|
|
19
|
-
return {
|
|
20
|
-
code: error.code,
|
|
21
|
-
from: error.from,
|
|
22
|
-
to: error.to,
|
|
23
|
-
params: error.params
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function toPublicAnalysis(analysis) {
|
|
27
|
-
return {
|
|
28
|
-
success: analysis.success,
|
|
29
|
-
type: analysis.type,
|
|
30
|
-
valueClass: analysis.valueClass,
|
|
31
|
-
diagnostics: analysis.errors.map(toPublicError)
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/mappers/model-adapter.ts
|
|
36
|
-
var SESSION_MODEL_ID = 0;
|
|
37
|
-
var ModelAdapter = class {
|
|
38
|
-
async setConstituentaValue(session, input) {
|
|
39
|
-
this.validateSetInput(session, input);
|
|
40
|
-
const engine = this.createEngine(session);
|
|
41
|
-
const cst = session.items.find((item) => item.id === input.target);
|
|
42
|
-
const frontendType = cst.cstType;
|
|
43
|
-
if (isBaseSet(frontendType)) {
|
|
44
|
-
const binding = toBasicBinding(input.value);
|
|
45
|
-
await engine.setBasicValue(input.target, binding);
|
|
46
|
-
} else {
|
|
47
|
-
await engine.setStructureValue(input.target, input.value);
|
|
48
|
-
}
|
|
49
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
50
|
-
return structuredClone(session.model);
|
|
51
|
-
}
|
|
52
|
-
async setConstituentaValues(session, input) {
|
|
53
|
-
for (const item of input.items) {
|
|
54
|
-
await this.setConstituentaValue(session, item);
|
|
55
|
-
}
|
|
56
|
-
return structuredClone(session.model);
|
|
57
|
-
}
|
|
58
|
-
async clearConstituentaValues(session, ids) {
|
|
59
|
-
const engine = this.createEngine(session);
|
|
60
|
-
for (const id of ids) {
|
|
61
|
-
await engine.resetValue(id);
|
|
62
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
63
|
-
}
|
|
64
|
-
return structuredClone(session.model);
|
|
65
|
-
}
|
|
66
|
-
evaluateExpression(session, expression, cstType) {
|
|
67
|
-
const engine = this.createEngine(session);
|
|
68
|
-
const result = engine.evaluateExpression(expression, cstType);
|
|
69
|
-
const status = result.value === null ? result.errors.length > 0 ? EvalStatus.EVAL_FAIL : EvalStatus.EMPTY : EvalStatus.HAS_DATA;
|
|
70
|
-
return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);
|
|
71
|
-
}
|
|
72
|
-
evaluateConstituenta(session, constituentId) {
|
|
73
|
-
const cst = session.items.find((item) => item.id === constituentId);
|
|
74
|
-
if (!cst) {
|
|
75
|
-
throw new Error(`Unknown constituent: ${constituentId}`);
|
|
76
|
-
}
|
|
77
|
-
const engine = this.createEngine(session);
|
|
78
|
-
const result = engine.calculateCst(constituentId);
|
|
79
|
-
const status = engine.getCstStatus(constituentId);
|
|
80
|
-
return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);
|
|
81
|
-
}
|
|
82
|
-
recalculateModel(session) {
|
|
83
|
-
const engine = this.createEngine(session);
|
|
84
|
-
engine.recalculateAll();
|
|
85
|
-
const items = session.items.map((item) => ({
|
|
86
|
-
id: item.id,
|
|
87
|
-
alias: item.alias,
|
|
88
|
-
value: engine.getCstValue(item.id),
|
|
89
|
-
status: engine.getCstStatus(item.id)
|
|
90
|
-
}));
|
|
91
|
-
return { items };
|
|
92
|
-
}
|
|
93
|
-
createEngine(session) {
|
|
94
|
-
const schema = buildRSFormFromSession(session);
|
|
95
|
-
const model = buildRSModelFromSession(session);
|
|
96
|
-
const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));
|
|
97
|
-
engine.loadData(schema, model);
|
|
98
|
-
return engine;
|
|
99
|
-
}
|
|
100
|
-
validateSetInput(session, input) {
|
|
101
|
-
const cst = session.items.find((item) => item.id === input.target);
|
|
102
|
-
if (!cst) {
|
|
103
|
-
throw new Error(`Unknown constituent: ${input.target}`);
|
|
104
|
-
}
|
|
105
|
-
const frontendType = cst.cstType;
|
|
106
|
-
if (!isInterpretable(frontendType)) {
|
|
107
|
-
throw new Error(`Constituent ${cst.alias} is not interpretable`);
|
|
108
|
-
}
|
|
109
|
-
if (isInferrable(frontendType)) {
|
|
110
|
-
throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);
|
|
111
|
-
}
|
|
112
|
-
if (isBaseSet(frontendType)) {
|
|
113
|
-
if (!validateBasicBindingData(input.value)) {
|
|
114
|
-
throw new Error(`Invalid basic binding for ${cst.alias}`);
|
|
115
|
-
}
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (!validateValueData(input.value)) {
|
|
119
|
-
throw new Error(`Invalid structured value for ${cst.alias}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
function createInMemoryServices(session) {
|
|
124
|
-
return {
|
|
125
|
-
setCstValue: async ({ data }) => {
|
|
126
|
-
for (const item of data) {
|
|
127
|
-
const entry = {
|
|
128
|
-
id: item.target,
|
|
129
|
-
type: item.type,
|
|
130
|
-
value: item.data
|
|
131
|
-
};
|
|
132
|
-
const index = session.model.items.findIndex((existing) => existing.id === item.target);
|
|
133
|
-
if (index === -1) {
|
|
134
|
-
session.model.items.push(entry);
|
|
135
|
-
} else {
|
|
136
|
-
session.model.items[index] = entry;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
clearValues: async ({ data }) => {
|
|
141
|
-
const ids = new Set(data.items);
|
|
142
|
-
session.model.items = session.model.items.filter((item) => !ids.has(item.id));
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function buildRSFormFromSession(session) {
|
|
147
|
-
const graph = new Graph();
|
|
148
|
-
const cstByAlias = /* @__PURE__ */ new Map();
|
|
149
|
-
const cstByID = /* @__PURE__ */ new Map();
|
|
150
|
-
const analyzer = new RSLangAnalyzer();
|
|
151
|
-
const items = session.items.map((item) => {
|
|
152
|
-
const cst = toFrontendConstituenta(item);
|
|
153
|
-
cstByAlias.set(cst.alias, cst);
|
|
154
|
-
cstByID.set(cst.id, cst);
|
|
155
|
-
graph.addNode(cst.id);
|
|
156
|
-
if (item.cstType === CstType.BASE) {
|
|
157
|
-
analyzer.addBase(cst.alias);
|
|
158
|
-
}
|
|
159
|
-
if (cst.effectiveType) {
|
|
160
|
-
analyzer.setGlobal(cst.alias, cst.effectiveType, cst.analysis.valueClass);
|
|
161
|
-
}
|
|
162
|
-
return cst;
|
|
163
|
-
});
|
|
164
|
-
for (const cst of items) {
|
|
165
|
-
for (const alias of extractGlobals(cst.definition_formal)) {
|
|
166
|
-
const source = cstByAlias.get(alias);
|
|
167
|
-
if (source) {
|
|
168
|
-
graph.addEdge(source.id, cst.id);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
id: 0,
|
|
174
|
-
items,
|
|
175
|
-
cstByAlias,
|
|
176
|
-
cstByID,
|
|
177
|
-
graph,
|
|
178
|
-
analyzer,
|
|
179
|
-
inheritance: [],
|
|
180
|
-
attribution: [],
|
|
181
|
-
attribution_graph: graph.clone(),
|
|
182
|
-
oss: [],
|
|
183
|
-
models: [],
|
|
184
|
-
editors: [],
|
|
185
|
-
versions: [],
|
|
186
|
-
is_produced: false,
|
|
187
|
-
is_attributive: false,
|
|
188
|
-
version: "latest"
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
function buildRSModelFromSession(session) {
|
|
192
|
-
return {
|
|
193
|
-
id: SESSION_MODEL_ID,
|
|
194
|
-
schema: 0,
|
|
195
|
-
editors: [],
|
|
196
|
-
items: session.model.items.map((item) => ({
|
|
197
|
-
id: item.id,
|
|
198
|
-
type: item.type,
|
|
199
|
-
value: item.value
|
|
200
|
-
}))
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
function toFrontendConstituenta(item) {
|
|
204
|
-
const effectiveType = item.analysis.type ?? null;
|
|
205
|
-
return {
|
|
206
|
-
id: item.id,
|
|
207
|
-
alias: item.alias,
|
|
208
|
-
cst_type: item.cstType,
|
|
209
|
-
definition_formal: item.definitionFormal,
|
|
210
|
-
definition_raw: item.definitionFormal,
|
|
211
|
-
definition_resolved: item.definitionFormal,
|
|
212
|
-
term_raw: item.term,
|
|
213
|
-
term_resolved: item.term,
|
|
214
|
-
term_forms: [],
|
|
215
|
-
convention: item.convention,
|
|
216
|
-
typification_manual: "",
|
|
217
|
-
value_is_property: false,
|
|
218
|
-
crucial: false,
|
|
219
|
-
attributes: [],
|
|
220
|
-
homonyms: [],
|
|
221
|
-
formalDuplicates: [],
|
|
222
|
-
analysis: {
|
|
223
|
-
success: item.analysis.success,
|
|
224
|
-
type: effectiveType,
|
|
225
|
-
valueClass: item.analysis.valueClass
|
|
226
|
-
},
|
|
227
|
-
effectiveType,
|
|
228
|
-
is_type_mismatch: false,
|
|
229
|
-
schema: 0,
|
|
230
|
-
cst_class: "derived",
|
|
231
|
-
status: item.analysis.success ? "verified" : "incorrect",
|
|
232
|
-
is_template: false,
|
|
233
|
-
is_simple_expression: true,
|
|
234
|
-
parent_schema_index: 0,
|
|
235
|
-
parent_schema: null,
|
|
236
|
-
is_inherited: false,
|
|
237
|
-
has_inherited_children: false,
|
|
238
|
-
spawn: [],
|
|
239
|
-
spawn_alias: []
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function toPublicEvaluationResult(value, errors, iterations, cacheHits, status) {
|
|
243
|
-
const diagnostics = errors.map(toPublicError);
|
|
244
|
-
return {
|
|
245
|
-
success: diagnostics.length === 0 && value !== null,
|
|
246
|
-
value,
|
|
247
|
-
status,
|
|
248
|
-
iterations,
|
|
249
|
-
cacheHits,
|
|
250
|
-
diagnostics
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// src/mappers/schema-adapter.ts
|
|
255
|
-
import { RSLangAnalyzer as RSLangAnalyzer2 } from "@rsconcept/domain/rslang";
|
|
256
|
-
import { getAnalysisFor } from "@rsconcept/domain/library/rsform-api";
|
|
257
|
-
import { CstType as CstType2 } from "@rsconcept/domain/library/rsform";
|
|
258
|
-
var SchemaAdapter = class {
|
|
259
|
-
analyzeAgainstSession(session, draft) {
|
|
260
|
-
const analyzer = this.buildAnalyzer(session);
|
|
261
|
-
const schema = this.toPseudoRSFormState(session, analyzer);
|
|
262
|
-
const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema, draft.alias);
|
|
263
|
-
const result = toPublicAnalysis({
|
|
264
|
-
success: analysis.success,
|
|
265
|
-
type: analysis.type,
|
|
266
|
-
valueClass: analysis.valueClass,
|
|
267
|
-
errors: analysis.errors
|
|
268
|
-
});
|
|
269
|
-
return {
|
|
270
|
-
result,
|
|
271
|
-
diagnostics: analysis.errors.map((error) => ({
|
|
272
|
-
sessionId: session.sessionId,
|
|
273
|
-
constituentId: draft.id,
|
|
274
|
-
expression: draft.definitionFormal,
|
|
275
|
-
error: toPublicError(error)
|
|
276
|
-
}))
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
mergeStateWithDraft(session, draft, analysis) {
|
|
280
|
-
const state = {
|
|
281
|
-
...draft,
|
|
282
|
-
term: draft.term ?? "",
|
|
283
|
-
definitionText: draft.definitionText ?? "",
|
|
284
|
-
convention: draft.convention ?? "",
|
|
285
|
-
analysis
|
|
286
|
-
};
|
|
287
|
-
const index = session.items.findIndex((item) => item.id === draft.id);
|
|
288
|
-
if (index === -1) {
|
|
289
|
-
session.items.push(state);
|
|
290
|
-
} else {
|
|
291
|
-
session.items[index] = state;
|
|
292
|
-
}
|
|
293
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
294
|
-
return state;
|
|
295
|
-
}
|
|
296
|
-
toPseudoRSFormState(session, analyzer) {
|
|
297
|
-
const cstByAlias = new Map(session.items.map((item) => [item.alias, item]));
|
|
298
|
-
return {
|
|
299
|
-
items: session.items,
|
|
300
|
-
cstByAlias,
|
|
301
|
-
analyzer
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
buildAnalyzer(session) {
|
|
305
|
-
const analyzer = new RSLangAnalyzer2();
|
|
306
|
-
for (const item of session.items) {
|
|
307
|
-
if (item.cstType === CstType2.BASE) {
|
|
308
|
-
analyzer.addBase(item.alias);
|
|
309
|
-
}
|
|
310
|
-
analyzer.setGlobal(
|
|
311
|
-
item.alias,
|
|
312
|
-
item.analysis.type,
|
|
313
|
-
item.analysis.valueClass
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
return analyzer;
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
// src/session/session-store.ts
|
|
321
|
-
import { randomUUID } from "crypto";
|
|
322
|
-
var SessionStore = class {
|
|
323
|
-
sessions = /* @__PURE__ */ new Map();
|
|
324
|
-
create(initial, contractVersion) {
|
|
325
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
326
|
-
const sessionId = initial?.sessionId ?? randomUUID();
|
|
327
|
-
const state = {
|
|
328
|
-
sessionId,
|
|
329
|
-
createdAt: initial?.createdAt ?? now,
|
|
330
|
-
updatedAt: now,
|
|
331
|
-
revisions: initial?.revisions ?? [],
|
|
332
|
-
items: initial?.items ?? [],
|
|
333
|
-
model: initial?.model ?? { items: [] }
|
|
334
|
-
};
|
|
335
|
-
this.sessions.set(sessionId, {
|
|
336
|
-
state,
|
|
337
|
-
diagnostics: []
|
|
338
|
-
});
|
|
339
|
-
return {
|
|
340
|
-
sessionId,
|
|
341
|
-
contractVersion: contractVersion ?? "1.0.0"
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
get(sessionId) {
|
|
345
|
-
const found = this.sessions.get(sessionId);
|
|
346
|
-
if (!found) {
|
|
347
|
-
throw new Error(`Unknown session: ${sessionId}`);
|
|
348
|
-
}
|
|
349
|
-
return found;
|
|
350
|
-
}
|
|
351
|
-
replaceState(sessionId, nextState) {
|
|
352
|
-
const found = this.get(sessionId);
|
|
353
|
-
found.state = {
|
|
354
|
-
...nextState,
|
|
355
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
addRevision(sessionId, message) {
|
|
359
|
-
const found = this.get(sessionId);
|
|
360
|
-
const revision = {
|
|
361
|
-
revisionId: randomUUID(),
|
|
362
|
-
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
363
|
-
message
|
|
364
|
-
};
|
|
365
|
-
found.state.revisions.push(revision);
|
|
366
|
-
found.state.updatedAt = revision.at;
|
|
367
|
-
return revision;
|
|
368
|
-
}
|
|
369
|
-
appendDiagnostics(sessionId, records) {
|
|
370
|
-
const found = this.get(sessionId);
|
|
371
|
-
found.diagnostics.push(...records);
|
|
372
|
-
found.state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
373
|
-
}
|
|
374
|
-
listDiagnostics(sessionId, filters) {
|
|
375
|
-
const found = this.get(sessionId);
|
|
376
|
-
if (!filters?.constituentId) {
|
|
377
|
-
return [...found.diagnostics];
|
|
378
|
-
}
|
|
379
|
-
return found.diagnostics.filter((record) => record.constituentId === filters.constituentId);
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
// src/models/tool-contract.ts
|
|
384
|
-
var CONTRACT_VERSION = "1.2.0";
|
|
385
|
-
|
|
386
|
-
// src/models/rstool-agent.ts
|
|
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 "./tool-contract.js";
|
|
5
|
+
//#region src/models/rstool-agent.ts
|
|
387
6
|
var RSToolAgent = class {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
return this.evaluation.evaluateConstituenta(envelope.state, input.constituentId);
|
|
471
|
-
}
|
|
472
|
-
recalculateModel(sessionId) {
|
|
473
|
-
const envelope = this.sessions.get(sessionId);
|
|
474
|
-
return this.evaluation.recalculateModel(envelope.state);
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
export {
|
|
478
|
-
RSToolAgent
|
|
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
|
+
}
|
|
479
89
|
};
|
|
90
|
+
//#endregion
|
|
91
|
+
export { RSToolAgent };
|
|
92
|
+
|
|
480
93
|
//# sourceMappingURL=rstool-agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mappers/model-adapter.ts","../../src/mappers/types.ts","../../src/mappers/schema-adapter.ts","../../src/session/session-store.ts","../../src/models/tool-contract.ts","../../src/models/rstool-agent.ts"],"sourcesContent":["import { Graph } from '@rsconcept/domain/graph/graph';\nimport { extractGlobals } from '@rsconcept/domain/rslang/api';\nimport { type ExpressionType, RSLangAnalyzer, type Value, type ValueClass } from '@rsconcept/domain/rslang';\nimport { isBaseSet } from '@rsconcept/domain/library/rsform-api';\nimport { type Constituenta, CstType, type RSForm } from '@rsconcept/domain/library/rsform';\nimport { RSEngine, type RSEngineServices } from '@rsconcept/domain/library/rsengine';\nimport { type BasicBinding, EvalStatus, type RSModel } from '@rsconcept/domain/library/rsmodel';\nimport {\n isInferrable,\n isInterpretable,\n toBasicBinding,\n validateBasicBindingData,\n validateValueData\n} from '@rsconcept/domain/library/rsmodel-api';\n\nimport {\n type ConstituentaState,\n type EvaluationResult,\n type RecalculateModelResult,\n type SessionModelState,\n type SessionState,\n type SetConstituentaValueInput\n} from '../models';\nimport { toPublicError } from './types';\n\nconst SESSION_MODEL_ID = 0;\n\nexport class ModelAdapter {\n public async setConstituentaValue(\n session: SessionState,\n input: SetConstituentaValueInput\n ): Promise<SessionModelState> {\n this.validateSetInput(session, input);\n const engine = this.createEngine(session);\n const cst = session.items.find(item => item.id === input.target)!;\n const frontendType = cst.cstType;\n\n if (isBaseSet(frontendType)) {\n const binding = toBasicBinding(input.value as Record<string | number, string>);\n await engine.setBasicValue(input.target, binding);\n } else {\n await engine.setStructureValue(input.target, input.value as Value);\n }\n session.updatedAt = new Date().toISOString();\n return structuredClone(session.model);\n }\n\n public async setConstituentaValues(\n session: SessionState,\n input: { items: SetConstituentaValueInput[] }\n ): Promise<SessionModelState> {\n for (const item of input.items) {\n await this.setConstituentaValue(session, item);\n }\n return structuredClone(session.model);\n }\n\n public async clearConstituentaValues(session: SessionState, ids: number[]): Promise<SessionModelState> {\n const engine = this.createEngine(session);\n for (const id of ids) {\n await engine.resetValue(id);\n session.updatedAt = new Date().toISOString();\n }\n return structuredClone(session.model);\n }\n\n public evaluateExpression(session: SessionState, expression: string, cstType: CstType): EvaluationResult {\n const engine = this.createEngine(session);\n const result = engine.evaluateExpression(expression, cstType);\n const status =\n result.value === null\n ? result.errors.length > 0\n ? EvalStatus.EVAL_FAIL\n : EvalStatus.EMPTY\n : EvalStatus.HAS_DATA;\n return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);\n }\n\n public evaluateConstituenta(session: SessionState, constituentId: number): EvaluationResult {\n const cst = session.items.find(item => item.id === constituentId);\n if (!cst) {\n throw new Error(`Unknown constituent: ${constituentId}`);\n }\n const engine = this.createEngine(session);\n const result = engine.calculateCst(constituentId);\n const status = engine.getCstStatus(constituentId);\n return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);\n }\n\n public recalculateModel(session: SessionState): RecalculateModelResult {\n const engine = this.createEngine(session);\n engine.recalculateAll();\n const items = session.items.map(item => ({\n id: item.id,\n alias: item.alias,\n value: engine.getCstValue(item.id) as number | number[] | null,\n status: engine.getCstStatus(item.id)\n }));\n return { items };\n }\n\n public createEngine(session: SessionState): RSEngine {\n const schema = buildRSFormFromSession(session);\n const model = buildRSModelFromSession(session);\n const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));\n engine.loadData(schema, model);\n return engine;\n }\n\n private validateSetInput(session: SessionState, input: SetConstituentaValueInput): void {\n const cst = session.items.find(item => item.id === input.target);\n if (!cst) {\n throw new Error(`Unknown constituent: ${input.target}`);\n }\n const frontendType = cst.cstType;\n if (!isInterpretable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is not interpretable`);\n }\n if (isInferrable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);\n }\n if (isBaseSet(frontendType)) {\n if (!validateBasicBindingData(input.value)) {\n throw new Error(`Invalid basic binding for ${cst.alias}`);\n }\n return;\n }\n if (!validateValueData(input.value)) {\n throw new Error(`Invalid structured value for ${cst.alias}`);\n }\n }\n}\n\nfunction createInMemoryServices(session: SessionState): RSEngineServices {\n return {\n setCstValue: async ({ data }) => {\n for (const item of data) {\n const entry = {\n id: item.target,\n type: item.type,\n value: item.data as Value | BasicBinding\n };\n const index = session.model.items.findIndex(existing => existing.id === item.target);\n if (index === -1) {\n session.model.items.push(entry);\n } else {\n session.model.items[index] = entry;\n }\n }\n },\n clearValues: async ({ data }) => {\n const ids = new Set(data.items);\n session.model.items = session.model.items.filter(item => !ids.has(item.id));\n }\n };\n}\n\nfunction buildRSFormFromSession(session: SessionState): RSForm {\n const graph = new Graph<number>();\n const cstByAlias = new Map<string, Constituenta>();\n const cstByID = new Map<number, Constituenta>();\n const analyzer = new RSLangAnalyzer();\n\n const items = session.items.map(item => {\n const cst = toFrontendConstituenta(item);\n cstByAlias.set(cst.alias, cst);\n cstByID.set(cst.id, cst);\n graph.addNode(cst.id);\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(cst.alias);\n }\n if (cst.effectiveType) {\n analyzer.setGlobal(cst.alias, cst.effectiveType, cst.analysis.valueClass as ValueClass | null);\n }\n return cst;\n });\n\n for (const cst of items) {\n for (const alias of extractGlobals(cst.definition_formal)) {\n const source = cstByAlias.get(alias);\n if (source) {\n graph.addEdge(source.id, cst.id);\n }\n }\n }\n\n return {\n id: 0,\n items,\n cstByAlias,\n cstByID,\n graph,\n analyzer,\n inheritance: [],\n attribution: [],\n attribution_graph: graph.clone(),\n oss: [],\n models: [],\n editors: [],\n versions: [],\n is_produced: false,\n is_attributive: false,\n version: 'latest'\n } as unknown as RSForm;\n}\n\nfunction buildRSModelFromSession(session: SessionState): RSModel {\n return {\n id: SESSION_MODEL_ID,\n schema: 0,\n editors: [],\n items: session.model.items.map(item => ({\n id: item.id,\n type: item.type,\n value: item.value as Value | BasicBinding\n }))\n } as unknown as RSModel;\n}\n\nfunction toFrontendConstituenta(item: ConstituentaState): Constituenta {\n const effectiveType = (item.analysis.type ?? null) as ExpressionType | null;\n return {\n id: item.id,\n alias: item.alias,\n cst_type: item.cstType,\n definition_formal: item.definitionFormal,\n definition_raw: item.definitionFormal,\n definition_resolved: item.definitionFormal,\n term_raw: item.term,\n term_resolved: item.term,\n term_forms: [],\n convention: item.convention,\n typification_manual: '',\n value_is_property: false,\n crucial: false,\n attributes: [],\n homonyms: [],\n formalDuplicates: [],\n analysis: {\n success: item.analysis.success,\n type: effectiveType,\n valueClass: item.analysis.valueClass\n },\n effectiveType,\n is_type_mismatch: false,\n schema: 0,\n cst_class: 'derived',\n status: item.analysis.success ? 'verified' : 'incorrect',\n is_template: false,\n is_simple_expression: true,\n parent_schema_index: 0,\n parent_schema: null,\n is_inherited: false,\n has_inherited_children: false,\n spawn: [],\n spawn_alias: []\n } as unknown as Constituenta;\n}\n\nfunction toPublicEvaluationResult(\n value: Value | null,\n errors: { code: number; from: number; to: number; params?: readonly string[] }[],\n iterations: number,\n cacheHits: number,\n status: EvalStatus\n): EvaluationResult {\n const diagnostics = errors.map(toPublicError);\n return {\n success: diagnostics.length === 0 && value !== null,\n value: value as EvaluationResult['value'],\n status,\n iterations,\n cacheHits,\n diagnostics\n };\n}\n","import { type ValueClass } from '@rsconcept/domain/rslang';\n\nimport { type AnalysisResult, type RSToolErrorDescription } from '../models';\n\nexport interface DomainErrorLike {\n code: number;\n from: number;\n to: number;\n params?: readonly string[];\n}\n\nexport interface DomainAnalysisLike {\n success: boolean;\n type: Record<string, unknown> | null;\n valueClass: ValueClass | null;\n errors: DomainErrorLike[];\n}\n\nexport function toPublicError(error: DomainErrorLike): RSToolErrorDescription {\n return {\n code: error.code,\n from: error.from,\n to: error.to,\n params: error.params\n };\n}\n\nexport function toPublicAnalysis(analysis: DomainAnalysisLike): AnalysisResult {\n return {\n success: analysis.success,\n type: analysis.type,\n valueClass: analysis.valueClass,\n diagnostics: analysis.errors.map(toPublicError)\n };\n}\n","import { RSLangAnalyzer, type AnalysisFull, type ValueClass } from '@rsconcept/domain/rslang';\nimport { getAnalysisFor } from '@rsconcept/domain/library/rsform-api';\nimport { CstType, type RSForm } from '@rsconcept/domain/library/rsform';\n\nimport {\n type AnalysisResult,\n type ConstituentaDraft,\n type ConstituentaState,\n type DiagnosticRecord,\n type SessionState\n} from '../models';\nimport { toPublicAnalysis, toPublicError } from './types';\n\nexport class SchemaAdapter {\n public analyzeAgainstSession(\n session: SessionState,\n draft: ConstituentaDraft\n ): { result: AnalysisResult; diagnostics: DiagnosticRecord[] } {\n const analyzer = this.buildAnalyzer(session);\n const schema = this.toPseudoRSFormState(session, analyzer);\n const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema as unknown as RSForm, draft.alias);\n const result = toPublicAnalysis({\n success: analysis.success,\n type: analysis.type as Record<string, unknown> | null,\n valueClass: analysis.valueClass,\n errors: analysis.errors\n });\n return {\n result,\n diagnostics: analysis.errors.map(error => ({\n sessionId: session.sessionId,\n constituentId: draft.id,\n expression: draft.definitionFormal,\n error: toPublicError(error)\n }))\n };\n }\n\n public mergeStateWithDraft(\n session: SessionState,\n draft: ConstituentaDraft,\n analysis: AnalysisResult\n ): ConstituentaState {\n const state: ConstituentaState = {\n ...draft,\n term: draft.term ?? '',\n definitionText: draft.definitionText ?? '',\n convention: draft.convention ?? '',\n analysis\n };\n const index = session.items.findIndex(item => item.id === draft.id);\n if (index === -1) {\n session.items.push(state);\n } else {\n session.items[index] = state;\n }\n session.updatedAt = new Date().toISOString();\n return state;\n }\n\n public toPseudoRSFormState(\n session: SessionState,\n analyzer: RSLangAnalyzer\n ): Pick<RSForm, 'items' | 'cstByAlias' | 'analyzer'> {\n const cstByAlias = new Map(session.items.map(item => [item.alias, item]));\n return {\n items: session.items as unknown as RSForm['items'],\n cstByAlias: cstByAlias as unknown as RSForm['cstByAlias'],\n analyzer\n };\n }\n\n private buildAnalyzer(session: SessionState): RSLangAnalyzer {\n const analyzer = new RSLangAnalyzer();\n for (const item of session.items) {\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(item.alias);\n }\n analyzer.setGlobal(\n item.alias,\n item.analysis.type as AnalysisFull['type'],\n item.analysis.valueClass as ValueClass | null\n );\n }\n return analyzer;\n }\n}\n","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","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.2.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 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","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":";AAAA,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAC/B,SAA8B,sBAAmD;AACjF,SAAS,iBAAiB;AAC1B,SAA4B,eAA4B;AACxD,SAAS,gBAAuC;AAChD,SAA4B,kBAAgC;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,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OAC4B;AAC5B,UAAM,WAAW,KAAK,SAAS,IAAI,SAAS;AAC5C,WAAO,KAAK,WAAW,qBAAqB,SAAS,OAAO,KAAK;AAAA,EACnE;AAAA,EAEA,MAAa,sBACX,WACA,OAC4B;AAC5B,UAAM,WAAW,KAAK,SAAS,IAAI,SAAS;AAC5C,WAAO,KAAK,WAAW,sBAAsB,SAAS,OAAO,KAAK;AAAA,EACpE;AAAA,EAEA,MAAa,wBACX,WACA,OAC4B;AAC5B,UAAM,WAAW,KAAK,SAAS,IAAI,SAAS;AAC5C,WAAO,KAAK,WAAW,wBAAwB,SAAS,OAAO,MAAM,KAAK;AAAA,EAC5E;AAAA,EAEO,cAAc,WAAsC;AACzD,UAAM,WAAW,KAAK,SAAS,IAAI,SAAS;AAC5C,WAAO,gBAAgB,SAAS,MAAM,KAAK;AAAA,EAC7C;AAAA,EAEO,mBAAmB,WAAmB,OAAkD;AAC7F,UAAM,WAAW,KAAK,SAAS,IAAI,SAAS;AAC5C,WAAO,KAAK,WAAW,mBAAmB,SAAS,OAAO,MAAM,YAAY,MAAM,OAAO;AAAA,EAC3F;AAAA,EAEO,qBAAqB,WAAmB,OAAoD;AACjG,UAAM,WAAW,KAAK,SAAS,IAAI,SAAS;AAC5C,WAAO,KAAK,WAAW,qBAAqB,SAAS,OAAO,MAAM,aAAa;AAAA,EACjF;AAAA,EAEO,iBAAiB,WAA2C;AACjE,UAAM,WAAW,KAAK,SAAS,IAAI,SAAS;AAC5C,WAAO,KAAK,WAAW,iBAAiB,SAAS,KAAK;AAAA,EACxD;AACF;","names":["RSLangAnalyzer","CstType","RSLangAnalyzer","CstType"]}
|
|
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,cAA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