@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,679 +1,181 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// src/mappers/types.ts
|
|
23
|
-
function toPublicError(error) {
|
|
24
|
-
return {
|
|
25
|
-
code: error.code,
|
|
26
|
-
from: error.from,
|
|
27
|
-
to: error.to,
|
|
28
|
-
params: error.params
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function toPublicAnalysis(analysis) {
|
|
32
|
-
return {
|
|
33
|
-
success: analysis.success,
|
|
34
|
-
type: analysis.type,
|
|
35
|
-
valueClass: analysis.valueClass,
|
|
36
|
-
diagnostics: analysis.errors.map(toPublicError)
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/mappers/model-adapter.ts
|
|
41
|
-
var SESSION_MODEL_ID = 0;
|
|
42
|
-
var ModelAdapter = class {
|
|
43
|
-
async setConstituentaValue(session, input2) {
|
|
44
|
-
this.validateSetInput(session, input2);
|
|
45
|
-
const engine = this.createEngine(session);
|
|
46
|
-
const cst = session.items.find((item) => item.id === input2.target);
|
|
47
|
-
const frontendType = cst.cstType;
|
|
48
|
-
if (isBaseSet(frontendType)) {
|
|
49
|
-
const binding = toBasicBinding(input2.value);
|
|
50
|
-
await engine.setBasicValue(input2.target, binding);
|
|
51
|
-
} else {
|
|
52
|
-
await engine.setStructureValue(input2.target, input2.value);
|
|
53
|
-
}
|
|
54
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
55
|
-
return structuredClone(session.model);
|
|
56
|
-
}
|
|
57
|
-
async setConstituentaValues(session, input2) {
|
|
58
|
-
for (const item of input2.items) {
|
|
59
|
-
await this.setConstituentaValue(session, item);
|
|
60
|
-
}
|
|
61
|
-
return structuredClone(session.model);
|
|
62
|
-
}
|
|
63
|
-
async clearConstituentaValues(session, ids) {
|
|
64
|
-
const engine = this.createEngine(session);
|
|
65
|
-
for (const id of ids) {
|
|
66
|
-
await engine.resetValue(id);
|
|
67
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
68
|
-
}
|
|
69
|
-
return structuredClone(session.model);
|
|
70
|
-
}
|
|
71
|
-
evaluateExpression(session, expression, cstType) {
|
|
72
|
-
const engine = this.createEngine(session);
|
|
73
|
-
const result = engine.evaluateExpression(expression, cstType);
|
|
74
|
-
const status = result.value === null ? result.errors.length > 0 ? EvalStatus.EVAL_FAIL : EvalStatus.EMPTY : EvalStatus.HAS_DATA;
|
|
75
|
-
return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);
|
|
76
|
-
}
|
|
77
|
-
evaluateConstituenta(session, constituentId) {
|
|
78
|
-
const cst = session.items.find((item) => item.id === constituentId);
|
|
79
|
-
if (!cst) {
|
|
80
|
-
throw new Error(`Unknown constituent: ${constituentId}`);
|
|
81
|
-
}
|
|
82
|
-
const engine = this.createEngine(session);
|
|
83
|
-
const result = engine.calculateCst(constituentId);
|
|
84
|
-
const status = engine.getCstStatus(constituentId);
|
|
85
|
-
return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);
|
|
86
|
-
}
|
|
87
|
-
recalculateModel(session) {
|
|
88
|
-
const engine = this.createEngine(session);
|
|
89
|
-
engine.recalculateAll();
|
|
90
|
-
const items = session.items.map((item) => ({
|
|
91
|
-
id: item.id,
|
|
92
|
-
alias: item.alias,
|
|
93
|
-
value: engine.getCstValue(item.id),
|
|
94
|
-
status: engine.getCstStatus(item.id)
|
|
95
|
-
}));
|
|
96
|
-
return { items };
|
|
97
|
-
}
|
|
98
|
-
createEngine(session) {
|
|
99
|
-
const schema = buildRSFormFromSession(session);
|
|
100
|
-
const model = buildRSModelFromSession(session);
|
|
101
|
-
const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));
|
|
102
|
-
engine.loadData(schema, model);
|
|
103
|
-
return engine;
|
|
104
|
-
}
|
|
105
|
-
validateSetInput(session, input2) {
|
|
106
|
-
const cst = session.items.find((item) => item.id === input2.target);
|
|
107
|
-
if (!cst) {
|
|
108
|
-
throw new Error(`Unknown constituent: ${input2.target}`);
|
|
109
|
-
}
|
|
110
|
-
const frontendType = cst.cstType;
|
|
111
|
-
if (!isInterpretable(frontendType)) {
|
|
112
|
-
throw new Error(`Constituent ${cst.alias} is not interpretable`);
|
|
113
|
-
}
|
|
114
|
-
if (isInferrable(frontendType)) {
|
|
115
|
-
throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);
|
|
116
|
-
}
|
|
117
|
-
if (isBaseSet(frontendType)) {
|
|
118
|
-
if (!validateBasicBindingData(input2.value)) {
|
|
119
|
-
throw new Error(`Invalid basic binding for ${cst.alias}`);
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (!validateValueData(input2.value)) {
|
|
124
|
-
throw new Error(`Invalid structured value for ${cst.alias}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
function createInMemoryServices(session) {
|
|
129
|
-
return {
|
|
130
|
-
setCstValue: async ({ data }) => {
|
|
131
|
-
for (const item of data) {
|
|
132
|
-
const entry = {
|
|
133
|
-
id: item.target,
|
|
134
|
-
type: item.type,
|
|
135
|
-
value: item.data
|
|
136
|
-
};
|
|
137
|
-
const index = session.model.items.findIndex((existing) => existing.id === item.target);
|
|
138
|
-
if (index === -1) {
|
|
139
|
-
session.model.items.push(entry);
|
|
140
|
-
} else {
|
|
141
|
-
session.model.items[index] = entry;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
clearValues: async ({ data }) => {
|
|
146
|
-
const ids = new Set(data.items);
|
|
147
|
-
session.model.items = session.model.items.filter((item) => !ids.has(item.id));
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function buildRSFormFromSession(session) {
|
|
152
|
-
const graph = new Graph();
|
|
153
|
-
const cstByAlias = /* @__PURE__ */ new Map();
|
|
154
|
-
const cstByID = /* @__PURE__ */ new Map();
|
|
155
|
-
const analyzer = new RSLangAnalyzer();
|
|
156
|
-
const items = session.items.map((item) => {
|
|
157
|
-
const cst = toFrontendConstituenta(item);
|
|
158
|
-
cstByAlias.set(cst.alias, cst);
|
|
159
|
-
cstByID.set(cst.id, cst);
|
|
160
|
-
graph.addNode(cst.id);
|
|
161
|
-
if (item.cstType === CstType.BASE) {
|
|
162
|
-
analyzer.addBase(cst.alias);
|
|
163
|
-
}
|
|
164
|
-
if (cst.effectiveType) {
|
|
165
|
-
analyzer.setGlobal(cst.alias, cst.effectiveType, cst.analysis.valueClass);
|
|
166
|
-
}
|
|
167
|
-
return cst;
|
|
168
|
-
});
|
|
169
|
-
for (const cst of items) {
|
|
170
|
-
for (const alias of extractGlobals(cst.definition_formal)) {
|
|
171
|
-
const source = cstByAlias.get(alias);
|
|
172
|
-
if (source) {
|
|
173
|
-
graph.addEdge(source.id, cst.id);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return {
|
|
178
|
-
id: 0,
|
|
179
|
-
items,
|
|
180
|
-
cstByAlias,
|
|
181
|
-
cstByID,
|
|
182
|
-
graph,
|
|
183
|
-
analyzer,
|
|
184
|
-
inheritance: [],
|
|
185
|
-
attribution: [],
|
|
186
|
-
attribution_graph: graph.clone(),
|
|
187
|
-
oss: [],
|
|
188
|
-
models: [],
|
|
189
|
-
editors: [],
|
|
190
|
-
versions: [],
|
|
191
|
-
is_produced: false,
|
|
192
|
-
is_attributive: false,
|
|
193
|
-
version: "latest"
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function buildRSModelFromSession(session) {
|
|
197
|
-
return {
|
|
198
|
-
id: SESSION_MODEL_ID,
|
|
199
|
-
schema: 0,
|
|
200
|
-
editors: [],
|
|
201
|
-
items: session.model.items.map((item) => ({
|
|
202
|
-
id: item.id,
|
|
203
|
-
type: item.type,
|
|
204
|
-
value: item.value
|
|
205
|
-
}))
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function toFrontendConstituenta(item) {
|
|
209
|
-
const effectiveType = item.analysis.type ?? null;
|
|
210
|
-
return {
|
|
211
|
-
id: item.id,
|
|
212
|
-
alias: item.alias,
|
|
213
|
-
cst_type: item.cstType,
|
|
214
|
-
definition_formal: item.definitionFormal,
|
|
215
|
-
definition_raw: item.definitionFormal,
|
|
216
|
-
definition_resolved: item.definitionFormal,
|
|
217
|
-
term_raw: item.term,
|
|
218
|
-
term_resolved: item.term,
|
|
219
|
-
term_forms: [],
|
|
220
|
-
convention: item.convention,
|
|
221
|
-
typification_manual: "",
|
|
222
|
-
value_is_property: false,
|
|
223
|
-
crucial: false,
|
|
224
|
-
attributes: [],
|
|
225
|
-
homonyms: [],
|
|
226
|
-
formalDuplicates: [],
|
|
227
|
-
analysis: {
|
|
228
|
-
success: item.analysis.success,
|
|
229
|
-
type: effectiveType,
|
|
230
|
-
valueClass: item.analysis.valueClass
|
|
231
|
-
},
|
|
232
|
-
effectiveType,
|
|
233
|
-
is_type_mismatch: false,
|
|
234
|
-
schema: 0,
|
|
235
|
-
cst_class: "derived",
|
|
236
|
-
status: item.analysis.success ? "verified" : "incorrect",
|
|
237
|
-
is_template: false,
|
|
238
|
-
is_simple_expression: true,
|
|
239
|
-
parent_schema_index: 0,
|
|
240
|
-
parent_schema: null,
|
|
241
|
-
is_inherited: false,
|
|
242
|
-
has_inherited_children: false,
|
|
243
|
-
spawn: [],
|
|
244
|
-
spawn_alias: []
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
function toPublicEvaluationResult(value, errors, iterations, cacheHits, status) {
|
|
248
|
-
const diagnostics = errors.map(toPublicError);
|
|
249
|
-
return {
|
|
250
|
-
success: diagnostics.length === 0 && value !== null,
|
|
251
|
-
value,
|
|
252
|
-
status,
|
|
253
|
-
iterations,
|
|
254
|
-
cacheHits,
|
|
255
|
-
diagnostics
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// src/mappers/schema-adapter.ts
|
|
260
|
-
import { RSLangAnalyzer as RSLangAnalyzer2 } from "@rsconcept/domain/rslang";
|
|
261
|
-
import { getAnalysisFor } from "@rsconcept/domain/library/rsform-api";
|
|
262
|
-
import { CstType as CstType2 } from "@rsconcept/domain/library/rsform";
|
|
263
|
-
var SchemaAdapter = class {
|
|
264
|
-
analyzeAgainstSession(session, draft) {
|
|
265
|
-
const analyzer = this.buildAnalyzer(session);
|
|
266
|
-
const schema = this.toPseudoRSFormState(session, analyzer);
|
|
267
|
-
const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema, draft.alias);
|
|
268
|
-
const result = toPublicAnalysis({
|
|
269
|
-
success: analysis.success,
|
|
270
|
-
type: analysis.type,
|
|
271
|
-
valueClass: analysis.valueClass,
|
|
272
|
-
errors: analysis.errors
|
|
273
|
-
});
|
|
274
|
-
return {
|
|
275
|
-
result,
|
|
276
|
-
diagnostics: analysis.errors.map((error) => ({
|
|
277
|
-
sessionId: session.sessionId,
|
|
278
|
-
constituentId: draft.id,
|
|
279
|
-
expression: draft.definitionFormal,
|
|
280
|
-
error: toPublicError(error)
|
|
281
|
-
}))
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
mergeStateWithDraft(session, draft, analysis) {
|
|
285
|
-
const state = {
|
|
286
|
-
...draft,
|
|
287
|
-
term: draft.term ?? "",
|
|
288
|
-
definitionText: draft.definitionText ?? "",
|
|
289
|
-
convention: draft.convention ?? "",
|
|
290
|
-
analysis
|
|
291
|
-
};
|
|
292
|
-
const index = session.items.findIndex((item) => item.id === draft.id);
|
|
293
|
-
if (index === -1) {
|
|
294
|
-
session.items.push(state);
|
|
295
|
-
} else {
|
|
296
|
-
session.items[index] = state;
|
|
297
|
-
}
|
|
298
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
299
|
-
return state;
|
|
300
|
-
}
|
|
301
|
-
toPseudoRSFormState(session, analyzer) {
|
|
302
|
-
const cstByAlias = new Map(session.items.map((item) => [item.alias, item]));
|
|
303
|
-
return {
|
|
304
|
-
items: session.items,
|
|
305
|
-
cstByAlias,
|
|
306
|
-
analyzer
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
buildAnalyzer(session) {
|
|
310
|
-
const analyzer = new RSLangAnalyzer2();
|
|
311
|
-
for (const item of session.items) {
|
|
312
|
-
if (item.cstType === CstType2.BASE) {
|
|
313
|
-
analyzer.addBase(item.alias);
|
|
314
|
-
}
|
|
315
|
-
analyzer.setGlobal(
|
|
316
|
-
item.alias,
|
|
317
|
-
item.analysis.type,
|
|
318
|
-
item.analysis.valueClass
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
return analyzer;
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
// src/session/session-store.ts
|
|
326
|
-
import { randomUUID } from "crypto";
|
|
327
|
-
var SessionStore = class {
|
|
328
|
-
sessions = /* @__PURE__ */ new Map();
|
|
329
|
-
create(initial, contractVersion) {
|
|
330
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
331
|
-
const sessionId = initial?.sessionId ?? randomUUID();
|
|
332
|
-
const state = {
|
|
333
|
-
sessionId,
|
|
334
|
-
createdAt: initial?.createdAt ?? now,
|
|
335
|
-
updatedAt: now,
|
|
336
|
-
revisions: initial?.revisions ?? [],
|
|
337
|
-
items: initial?.items ?? [],
|
|
338
|
-
model: initial?.model ?? { items: [] }
|
|
339
|
-
};
|
|
340
|
-
this.sessions.set(sessionId, {
|
|
341
|
-
state,
|
|
342
|
-
diagnostics: []
|
|
343
|
-
});
|
|
344
|
-
return {
|
|
345
|
-
sessionId,
|
|
346
|
-
contractVersion: contractVersion ?? "1.0.0"
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
get(sessionId) {
|
|
350
|
-
const found = this.sessions.get(sessionId);
|
|
351
|
-
if (!found) {
|
|
352
|
-
throw new Error(`Unknown session: ${sessionId}`);
|
|
353
|
-
}
|
|
354
|
-
return found;
|
|
355
|
-
}
|
|
356
|
-
replaceState(sessionId, nextState) {
|
|
357
|
-
const found = this.get(sessionId);
|
|
358
|
-
found.state = {
|
|
359
|
-
...nextState,
|
|
360
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
addRevision(sessionId, message) {
|
|
364
|
-
const found = this.get(sessionId);
|
|
365
|
-
const revision = {
|
|
366
|
-
revisionId: randomUUID(),
|
|
367
|
-
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
368
|
-
message
|
|
369
|
-
};
|
|
370
|
-
found.state.revisions.push(revision);
|
|
371
|
-
found.state.updatedAt = revision.at;
|
|
372
|
-
return revision;
|
|
373
|
-
}
|
|
374
|
-
appendDiagnostics(sessionId, records) {
|
|
375
|
-
const found = this.get(sessionId);
|
|
376
|
-
found.diagnostics.push(...records);
|
|
377
|
-
found.state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
378
|
-
}
|
|
379
|
-
listDiagnostics(sessionId, filters) {
|
|
380
|
-
const found = this.get(sessionId);
|
|
381
|
-
if (!filters?.constituentId) {
|
|
382
|
-
return [...found.diagnostics];
|
|
383
|
-
}
|
|
384
|
-
return found.diagnostics.filter((record) => record.constituentId === filters.constituentId);
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
// src/models/tool-contract.ts
|
|
389
|
-
var CONTRACT_VERSION = "1.2.0";
|
|
390
|
-
|
|
391
|
-
// src/models/rstool-agent.ts
|
|
392
|
-
var RSToolAgent = class {
|
|
393
|
-
contractVersion = CONTRACT_VERSION;
|
|
394
|
-
sessions = new SessionStore();
|
|
395
|
-
adapter = new SchemaAdapter();
|
|
396
|
-
evaluation = new ModelAdapter();
|
|
397
|
-
createSession(initial) {
|
|
398
|
-
return this.sessions.create(initial, this.contractVersion);
|
|
399
|
-
}
|
|
400
|
-
addOrUpdateConstituenta(sessionId, input2) {
|
|
401
|
-
const envelope = this.sessions.get(sessionId);
|
|
402
|
-
const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, input2.draft);
|
|
403
|
-
const state = this.adapter.mergeStateWithDraft(envelope.state, input2.draft, result);
|
|
404
|
-
this.sessions.appendDiagnostics(sessionId, diagnostics);
|
|
405
|
-
return {
|
|
406
|
-
state,
|
|
407
|
-
diagnostics
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
analyzeExpression(sessionId, input2) {
|
|
411
|
-
const envelope = this.sessions.get(sessionId);
|
|
412
|
-
const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, {
|
|
413
|
-
id: -1,
|
|
414
|
-
alias: "_analysis",
|
|
415
|
-
cstType: input2.cstType,
|
|
416
|
-
definitionFormal: input2.expression
|
|
417
|
-
});
|
|
418
|
-
this.sessions.appendDiagnostics(
|
|
419
|
-
sessionId,
|
|
420
|
-
diagnostics.map((item) => ({ ...item, constituentId: void 0 }))
|
|
421
|
-
);
|
|
422
|
-
return result;
|
|
423
|
-
}
|
|
424
|
-
getFormState(sessionId) {
|
|
425
|
-
const envelope = this.sessions.get(sessionId);
|
|
426
|
-
return structuredClone(envelope.state);
|
|
427
|
-
}
|
|
428
|
-
listDiagnostics(sessionId, filters) {
|
|
429
|
-
return this.sessions.listDiagnostics(sessionId, filters);
|
|
430
|
-
}
|
|
431
|
-
commitStep(sessionId, message) {
|
|
432
|
-
return this.sessions.addRevision(sessionId, message);
|
|
433
|
-
}
|
|
434
|
-
exportSession(sessionId) {
|
|
435
|
-
const envelope = this.sessions.get(sessionId);
|
|
436
|
-
return JSON.stringify(
|
|
437
|
-
{
|
|
438
|
-
contractVersion: this.contractVersion,
|
|
439
|
-
state: envelope.state,
|
|
440
|
-
diagnostics: envelope.diagnostics
|
|
441
|
-
},
|
|
442
|
-
null,
|
|
443
|
-
2
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
importSession(payload) {
|
|
447
|
-
const parsed = JSON.parse(payload);
|
|
448
|
-
if (!parsed.state.model) {
|
|
449
|
-
parsed.state.model = { items: [] };
|
|
450
|
-
}
|
|
451
|
-
return this.sessions.create(parsed.state, this.contractVersion);
|
|
452
|
-
}
|
|
453
|
-
async setConstituentaValue(sessionId, input2) {
|
|
454
|
-
const envelope = this.sessions.get(sessionId);
|
|
455
|
-
return this.evaluation.setConstituentaValue(envelope.state, input2);
|
|
456
|
-
}
|
|
457
|
-
async setConstituentaValues(sessionId, input2) {
|
|
458
|
-
const envelope = this.sessions.get(sessionId);
|
|
459
|
-
return this.evaluation.setConstituentaValues(envelope.state, input2);
|
|
460
|
-
}
|
|
461
|
-
async clearConstituentaValues(sessionId, input2) {
|
|
462
|
-
const envelope = this.sessions.get(sessionId);
|
|
463
|
-
return this.evaluation.clearConstituentaValues(envelope.state, input2.items);
|
|
464
|
-
}
|
|
465
|
-
getModelState(sessionId) {
|
|
466
|
-
const envelope = this.sessions.get(sessionId);
|
|
467
|
-
return structuredClone(envelope.state.model);
|
|
468
|
-
}
|
|
469
|
-
evaluateExpression(sessionId, input2) {
|
|
470
|
-
const envelope = this.sessions.get(sessionId);
|
|
471
|
-
return this.evaluation.evaluateExpression(envelope.state, input2.expression, input2.cstType);
|
|
472
|
-
}
|
|
473
|
-
evaluateConstituenta(sessionId, input2) {
|
|
474
|
-
const envelope = this.sessions.get(sessionId);
|
|
475
|
-
return this.evaluation.evaluateConstituenta(envelope.state, input2.constituentId);
|
|
476
|
-
}
|
|
477
|
-
recalculateModel(sessionId) {
|
|
478
|
-
const envelope = this.sessions.get(sessionId);
|
|
479
|
-
return this.evaluation.recalculateModel(envelope.state);
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
// src/wrapper/stdio-wrapper.ts
|
|
484
|
-
var tool = new RSToolAgent();
|
|
485
|
-
var METHODS = [
|
|
486
|
-
"createSession",
|
|
487
|
-
"addOrUpdateConstituenta",
|
|
488
|
-
"analyzeExpression",
|
|
489
|
-
"getFormState",
|
|
490
|
-
"listDiagnostics",
|
|
491
|
-
"commitStep",
|
|
492
|
-
"exportSession",
|
|
493
|
-
"importSession",
|
|
494
|
-
"setConstituentaValue",
|
|
495
|
-
"setConstituentaValues",
|
|
496
|
-
"clearConstituentaValues",
|
|
497
|
-
"getModelState",
|
|
498
|
-
"evaluateExpression",
|
|
499
|
-
"evaluateConstituenta",
|
|
500
|
-
"recalculateModel"
|
|
2
|
+
import { RSToolAgent } from "../models/rstool-agent.js";
|
|
3
|
+
import readline from "node:readline";
|
|
4
|
+
//#region src/wrapper/stdio-wrapper.ts
|
|
5
|
+
const tool = new RSToolAgent();
|
|
6
|
+
const METHODS = [
|
|
7
|
+
"createSession",
|
|
8
|
+
"addOrUpdateConstituenta",
|
|
9
|
+
"analyzeExpression",
|
|
10
|
+
"getFormState",
|
|
11
|
+
"listDiagnostics",
|
|
12
|
+
"commitStep",
|
|
13
|
+
"exportSession",
|
|
14
|
+
"importSession",
|
|
15
|
+
"setConstituentaValue",
|
|
16
|
+
"setConstituentaValues",
|
|
17
|
+
"clearConstituentaValues",
|
|
18
|
+
"getModelState",
|
|
19
|
+
"evaluateExpression",
|
|
20
|
+
"evaluateConstituenta",
|
|
21
|
+
"recalculateModel"
|
|
501
22
|
];
|
|
502
23
|
function writeResponse(response) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
process.stdout.write(`${JSON.stringify(response)}
|
|
508
|
-
`);
|
|
509
|
-
} catch {
|
|
510
|
-
}
|
|
24
|
+
if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) return;
|
|
25
|
+
try {
|
|
26
|
+
process.stdout.write(`${JSON.stringify(response)}\n`);
|
|
27
|
+
} catch {}
|
|
511
28
|
}
|
|
512
29
|
function asObject(value) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
return value;
|
|
30
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
31
|
+
return value;
|
|
517
32
|
}
|
|
518
|
-
function requiredString(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
return value;
|
|
33
|
+
function requiredString(input, key) {
|
|
34
|
+
const value = input[key];
|
|
35
|
+
if (typeof value !== "string" || value.length === 0) throw new Error(`Missing or invalid "${key}"`);
|
|
36
|
+
return value;
|
|
524
37
|
}
|
|
525
38
|
async function handleRequest(request) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
return {
|
|
635
|
-
id: request.id ?? null,
|
|
636
|
-
ok: false,
|
|
637
|
-
error: {
|
|
638
|
-
code: "INTERNAL_ERROR",
|
|
639
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
640
|
-
details: error
|
|
641
|
-
}
|
|
642
|
-
};
|
|
643
|
-
}
|
|
39
|
+
try {
|
|
40
|
+
const params = asObject(request.params);
|
|
41
|
+
switch (request.method) {
|
|
42
|
+
case "ping": return {
|
|
43
|
+
id: request.id,
|
|
44
|
+
ok: true,
|
|
45
|
+
result: { pong: true }
|
|
46
|
+
};
|
|
47
|
+
case "methods": return {
|
|
48
|
+
id: request.id,
|
|
49
|
+
ok: true,
|
|
50
|
+
result: METHODS
|
|
51
|
+
};
|
|
52
|
+
case "createSession": return {
|
|
53
|
+
id: request.id,
|
|
54
|
+
ok: true,
|
|
55
|
+
result: tool.createSession(params.initial)
|
|
56
|
+
};
|
|
57
|
+
case "addOrUpdateConstituenta": return {
|
|
58
|
+
id: request.id,
|
|
59
|
+
ok: true,
|
|
60
|
+
result: tool.addOrUpdateConstituenta(requiredString(params, "sessionId"), params.input)
|
|
61
|
+
};
|
|
62
|
+
case "analyzeExpression": return {
|
|
63
|
+
id: request.id,
|
|
64
|
+
ok: true,
|
|
65
|
+
result: tool.analyzeExpression(requiredString(params, "sessionId"), params.input)
|
|
66
|
+
};
|
|
67
|
+
case "getFormState": return {
|
|
68
|
+
id: request.id,
|
|
69
|
+
ok: true,
|
|
70
|
+
result: tool.getFormState(requiredString(params, "sessionId"))
|
|
71
|
+
};
|
|
72
|
+
case "listDiagnostics": return {
|
|
73
|
+
id: request.id,
|
|
74
|
+
ok: true,
|
|
75
|
+
result: tool.listDiagnostics(requiredString(params, "sessionId"), params.filters)
|
|
76
|
+
};
|
|
77
|
+
case "commitStep": return {
|
|
78
|
+
id: request.id,
|
|
79
|
+
ok: true,
|
|
80
|
+
result: tool.commitStep(requiredString(params, "sessionId"), params.message)
|
|
81
|
+
};
|
|
82
|
+
case "exportSession": return {
|
|
83
|
+
id: request.id,
|
|
84
|
+
ok: true,
|
|
85
|
+
result: tool.exportSession(requiredString(params, "sessionId"))
|
|
86
|
+
};
|
|
87
|
+
case "importSession": return {
|
|
88
|
+
id: request.id,
|
|
89
|
+
ok: true,
|
|
90
|
+
result: tool.importSession(requiredString(params, "payload"))
|
|
91
|
+
};
|
|
92
|
+
case "setConstituentaValue": return {
|
|
93
|
+
id: request.id,
|
|
94
|
+
ok: true,
|
|
95
|
+
result: await tool.setConstituentaValue(requiredString(params, "sessionId"), params.input)
|
|
96
|
+
};
|
|
97
|
+
case "setConstituentaValues": return {
|
|
98
|
+
id: request.id,
|
|
99
|
+
ok: true,
|
|
100
|
+
result: await tool.setConstituentaValues(requiredString(params, "sessionId"), params.input)
|
|
101
|
+
};
|
|
102
|
+
case "clearConstituentaValues": return {
|
|
103
|
+
id: request.id,
|
|
104
|
+
ok: true,
|
|
105
|
+
result: await tool.clearConstituentaValues(requiredString(params, "sessionId"), params.input)
|
|
106
|
+
};
|
|
107
|
+
case "getModelState": return {
|
|
108
|
+
id: request.id,
|
|
109
|
+
ok: true,
|
|
110
|
+
result: tool.getModelState(requiredString(params, "sessionId"))
|
|
111
|
+
};
|
|
112
|
+
case "evaluateExpression": return {
|
|
113
|
+
id: request.id,
|
|
114
|
+
ok: true,
|
|
115
|
+
result: tool.evaluateExpression(requiredString(params, "sessionId"), params.input)
|
|
116
|
+
};
|
|
117
|
+
case "evaluateConstituenta": return {
|
|
118
|
+
id: request.id,
|
|
119
|
+
ok: true,
|
|
120
|
+
result: tool.evaluateConstituenta(requiredString(params, "sessionId"), params.input)
|
|
121
|
+
};
|
|
122
|
+
case "recalculateModel": return {
|
|
123
|
+
id: request.id,
|
|
124
|
+
ok: true,
|
|
125
|
+
result: tool.recalculateModel(requiredString(params, "sessionId"))
|
|
126
|
+
};
|
|
127
|
+
default: return {
|
|
128
|
+
id: request.id ?? null,
|
|
129
|
+
ok: false,
|
|
130
|
+
error: {
|
|
131
|
+
code: "METHOD_NOT_FOUND",
|
|
132
|
+
message: `Unknown method: ${request.method}`
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return {
|
|
138
|
+
id: request.id ?? null,
|
|
139
|
+
ok: false,
|
|
140
|
+
error: {
|
|
141
|
+
code: "INTERNAL_ERROR",
|
|
142
|
+
message: error instanceof Error ? error.message : "Unknown error",
|
|
143
|
+
details: error
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
644
147
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
148
|
+
const input = readline.createInterface({
|
|
149
|
+
input: process.stdin,
|
|
150
|
+
crlfDelay: Infinity
|
|
648
151
|
});
|
|
649
152
|
writeResponse({
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
153
|
+
id: null,
|
|
154
|
+
ok: true,
|
|
155
|
+
result: {
|
|
156
|
+
ready: true,
|
|
157
|
+
wrapper: "rstool-stdio",
|
|
158
|
+
contractVersion: tool.contractVersion
|
|
159
|
+
}
|
|
657
160
|
});
|
|
658
161
|
input.on("line", (line) => {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
message: error instanceof Error ? error.message : "Invalid JSON"
|
|
675
|
-
}
|
|
676
|
-
});
|
|
677
|
-
}
|
|
162
|
+
if (!line.trim()) return;
|
|
163
|
+
try {
|
|
164
|
+
const request = JSON.parse(line);
|
|
165
|
+
if (!("id" in request) || !("method" in request)) throw new Error("Request must include \"id\" and \"method\"");
|
|
166
|
+
handleRequest(request).then(writeResponse);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
writeResponse({
|
|
169
|
+
id: null,
|
|
170
|
+
ok: false,
|
|
171
|
+
error: {
|
|
172
|
+
code: "BAD_REQUEST",
|
|
173
|
+
message: error instanceof Error ? error.message : "Invalid JSON"
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
678
177
|
});
|
|
178
|
+
//#endregion
|
|
179
|
+
export {};
|
|
180
|
+
|
|
679
181
|
//# sourceMappingURL=stdio-wrapper.js.map
|