@rsconcept/rstool 0.10.3 → 1.0.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 +61 -33
- package/dist/agent-workflow-Gk0Vfnv1.d.ts +64 -0
- package/dist/analysis-LLnPhmGa.d.ts +23 -0
- package/dist/{common-DxLg3eXX.d.ts → common-DHJalS-Q.d.ts} +6 -1
- package/dist/constituenta-DnGR6bnM.d.ts +54 -0
- package/dist/diagnostic-D9yl_mEL.d.ts +19 -0
- package/dist/evaluation-Cns8BFm4.d.ts +31 -0
- package/dist/index.d.ts +11 -11
- package/dist/index.js +1 -2
- package/dist/mappers/model-adapter.d.ts +3 -3
- package/dist/mappers/schema-adapter.d.ts +4 -4
- package/dist/mappers/types.d.ts +6 -2
- package/dist/mappers/types.js +2 -0
- package/dist/mappers/types.js.map +1 -1
- package/dist/{model-value-SFAVj0dw.d.ts → model-value-BbonPzMz.d.ts} +14 -3
- package/dist/models/agent-workflow.d.ts +2 -0
- package/dist/models/agent-workflow.js +1 -0
- package/dist/models/analysis.d.ts +1 -1
- package/dist/models/common.d.ts +1 -1
- package/dist/models/constituenta.d.ts +2 -2
- package/dist/models/diagnostic.d.ts +1 -1
- package/dist/models/evaluation.d.ts +2 -2
- package/dist/models/index.d.ts +11 -11
- package/dist/models/index.js +2 -2
- package/dist/models/model-value.d.ts +2 -2
- package/dist/models/rstool-agent.d.ts +1 -1
- package/dist/models/rstool-agent.js +1 -1
- package/dist/models/session.d.ts +1 -1
- package/dist/models/tool-contract.d.ts +2 -2
- package/dist/models/tool-contract.js +2 -1
- package/dist/models/tool-contract.js.map +1 -1
- package/dist/models-Bw6Uum8i.js +685 -0
- package/dist/models-Bw6Uum8i.js.map +1 -0
- package/dist/rstool-agent-D2cQze_b.d.ts +71 -0
- package/dist/session/session-store.d.ts +18 -5
- package/dist/session/session-store.js +1 -64
- package/dist/{session-BPgsE80c.d.ts → session-ChexW8i7.d.ts} +11 -8
- package/dist/tool-contract-0uRGhEfW.d.ts +164 -0
- package/dist/wrapper/client.d.ts +23 -0
- package/dist/wrapper/client.js +17 -0
- package/dist/wrapper/client.js.map +1 -1
- package/dist/wrapper/stdio-wrapper.js +75 -63
- package/dist/wrapper/stdio-wrapper.js.map +1 -1
- package/docs/CONSTITUENTA.md +2 -2
- package/docs/DIAGNOSTICS.md +6 -5
- package/docs/MODEL-TESTING.md +3 -3
- package/docs/PORTAL-API.md +24 -18
- package/examples/README.md +1 -1
- package/examples/agent-client.ts +11 -41
- package/examples/build-chocolate-nim-rsform.ts +21 -70
- package/examples/chocolate-nim/build-rsform.ts +23 -18
- package/examples/chocolate-nim/build-rsmodel.ts +10 -12
- package/examples/chocolate-nim/rsform-session.json +290 -290
- package/examples/chocolate-nim/rsmodel-session.json +291 -291
- package/examples/expression-bank/bank-constituents.ts +304 -53
- package/examples/expression-bank/build-rsform.ts +19 -16
- package/examples/expression-bank/rsform-session.json +1551 -1551
- package/examples/kinship/build-rsform.ts +23 -18
- package/examples/kinship/build-rsmodel.ts +16 -16
- package/examples/kinship/rsform-session.json +219 -219
- package/examples/kinship/rsmodel-session.json +221 -221
- package/examples/kinship/session.ts +19 -21
- package/examples/movd/build-rsform.ts +23 -18
- package/examples/movd/build-rsmodel.ts +18 -20
- package/examples/movd/rsform-session.json +262 -262
- package/examples/movd/rsmodel-session.json +264 -264
- package/examples/sample/build-rsform.ts +18 -51
- package/examples/sample/build-rsmodel.ts +25 -44
- package/examples/sample/rsform-session.json +10 -7
- package/examples/sample/rsmodel-session.json +36 -33
- package/examples/template-apply/build-rsform.ts +27 -24
- package/examples/template-apply/rsform-session.json +48 -48
- package/package.json +4 -2
- package/skills/rstool-helper/EXAMPLES.md +44 -116
- package/skills/rstool-helper/GUIDE.md +40 -25
- package/skills/rstool-helper/REFERENCE.md +40 -177
- package/src/index.ts +24 -17
- package/src/mappers/portal-adapter.ts +49 -0
- package/src/mappers/types.ts +4 -0
- package/src/models/agent-workflow.ts +66 -0
- package/src/models/analysis.ts +7 -0
- package/src/models/common.ts +7 -0
- package/src/models/constituenta.ts +24 -6
- package/src/models/diagnostic.ts +4 -0
- package/src/models/evaluation.ts +11 -0
- package/src/models/import-detect.test.ts +66 -0
- package/src/models/import-detect.ts +42 -0
- package/src/models/import-export.ts +24 -0
- package/src/models/index.ts +22 -14
- package/src/models/model-value.ts +12 -0
- package/src/models/portal-json.test.ts +38 -0
- package/src/models/portal-json.ts +54 -1
- package/src/models/rstool-agent.test.ts +698 -146
- package/src/models/rstool-agent.ts +392 -92
- package/src/models/session.ts +8 -5
- package/src/models/tool-contract.ts +81 -42
- package/src/session/batch-apply.test.ts +123 -0
- package/src/session/batch-apply.ts +82 -0
- package/src/session/persistence.test.ts +63 -0
- package/src/session/persistence.ts +69 -0
- package/src/session/session-store.ts +76 -6
- package/src/wrapper/client.test.ts +58 -0
- package/src/wrapper/client.ts +23 -0
- package/src/wrapper/stdio-handler.test.ts +101 -0
- package/src/wrapper/stdio-handler.ts +195 -0
- package/src/wrapper/stdio-wrapper.ts +4 -187
- package/dist/analysis-JiwOYDKx.d.ts +0 -16
- package/dist/constituenta-Dnd6iToB.d.ts +0 -36
- package/dist/diagnostic-BMYvciz8.d.ts +0 -15
- package/dist/evaluation-CCVYH0wA.d.ts +0 -21
- package/dist/index-uhkmwruf.d.ts +0 -46
- package/dist/rstool-agent-BZi5jO1y.js +0 -158
- package/dist/rstool-agent-BZi5jO1y.js.map +0 -1
- package/dist/rstool-agent-pRaPnZay.d.ts +0 -35
- package/dist/session/session-store.js.map +0 -1
- package/dist/tool-contract-n1ghUOrK.d.ts +0 -32
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as RSToolAgent } from "../
|
|
2
|
+
import { t as RSToolAgent } from "../models-Bw6Uum8i.js";
|
|
3
3
|
import readline from "node:readline";
|
|
4
|
-
//#region src/wrapper/stdio-
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
//#region src/wrapper/stdio-handler.ts
|
|
5
|
+
const STDIO_METHODS = [
|
|
6
|
+
"ensureSession",
|
|
7
7
|
"createSession",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
8
|
+
"getCurrentSession",
|
|
9
|
+
"setCurrentSession",
|
|
10
|
+
"applySchemaPatch",
|
|
11
|
+
"getSessionState",
|
|
11
12
|
"listDiagnostics",
|
|
13
|
+
"analyzeExpression",
|
|
12
14
|
"commitStep",
|
|
13
15
|
"exportSession",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"setConstituentaValue",
|
|
18
|
-
"setConstituentaValues",
|
|
19
|
-
"clearConstituentaValues",
|
|
16
|
+
"exportPortal",
|
|
17
|
+
"importData",
|
|
18
|
+
"setModelValues",
|
|
20
19
|
"getModelState",
|
|
21
|
-
"
|
|
22
|
-
"evaluateConstituenta",
|
|
20
|
+
"evaluate",
|
|
23
21
|
"recalculateModel"
|
|
24
22
|
];
|
|
25
|
-
function writeResponse(response) {
|
|
26
|
-
if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) return;
|
|
27
|
-
try {
|
|
28
|
-
process.stdout.write(`${JSON.stringify(response)}\n`);
|
|
29
|
-
} catch {}
|
|
30
|
-
}
|
|
31
23
|
function asObject(value) {
|
|
32
24
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
33
25
|
return value;
|
|
@@ -37,104 +29,114 @@ function requiredString(input, key) {
|
|
|
37
29
|
if (typeof value !== "string" || value.length === 0) throw new Error(`Missing or invalid "${key}"`);
|
|
38
30
|
return value;
|
|
39
31
|
}
|
|
40
|
-
|
|
32
|
+
function optionalSessionId(input) {
|
|
33
|
+
const value = input.sessionId;
|
|
34
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
35
|
+
}
|
|
36
|
+
function omitSessionId(input) {
|
|
37
|
+
const { sessionId: _sessionId, ...rest } = input;
|
|
38
|
+
return rest;
|
|
39
|
+
}
|
|
40
|
+
async function handleStdioRequest(tool, request) {
|
|
41
41
|
try {
|
|
42
42
|
const params = asObject(request.params);
|
|
43
43
|
switch (request.method) {
|
|
44
44
|
case "ping": return {
|
|
45
45
|
id: request.id,
|
|
46
46
|
ok: true,
|
|
47
|
-
result: {
|
|
47
|
+
result: {
|
|
48
|
+
pong: true,
|
|
49
|
+
contractVersion: tool.contractVersion
|
|
50
|
+
}
|
|
48
51
|
};
|
|
49
52
|
case "methods": return {
|
|
50
53
|
id: request.id,
|
|
51
54
|
ok: true,
|
|
52
|
-
result:
|
|
55
|
+
result: STDIO_METHODS
|
|
53
56
|
};
|
|
54
|
-
case "
|
|
57
|
+
case "ensureSession": return {
|
|
55
58
|
id: request.id,
|
|
56
59
|
ok: true,
|
|
57
|
-
result: tool.
|
|
60
|
+
result: tool.ensureSession(params.initial)
|
|
58
61
|
};
|
|
59
|
-
case "
|
|
60
|
-
id: request.id,
|
|
61
|
-
ok: true,
|
|
62
|
-
result: tool.addOrUpdateConstituenta(requiredString(params, "sessionId"), params.input)
|
|
63
|
-
};
|
|
64
|
-
case "analyzeExpression": return {
|
|
62
|
+
case "createSession": return {
|
|
65
63
|
id: request.id,
|
|
66
64
|
ok: true,
|
|
67
|
-
result: tool.
|
|
65
|
+
result: tool.createSession(params.initial)
|
|
68
66
|
};
|
|
69
|
-
case "
|
|
67
|
+
case "getCurrentSession": return {
|
|
70
68
|
id: request.id,
|
|
71
69
|
ok: true,
|
|
72
|
-
result: tool.
|
|
70
|
+
result: tool.getCurrentSession()
|
|
73
71
|
};
|
|
74
|
-
case "
|
|
72
|
+
case "setCurrentSession": return {
|
|
75
73
|
id: request.id,
|
|
76
74
|
ok: true,
|
|
77
|
-
result: tool.
|
|
75
|
+
result: tool.setCurrentSession(requiredString(params, "sessionId"))
|
|
78
76
|
};
|
|
79
|
-
case "
|
|
77
|
+
case "applySchemaPatch": return {
|
|
80
78
|
id: request.id,
|
|
81
79
|
ok: true,
|
|
82
|
-
result: tool.
|
|
80
|
+
result: tool.applySchemaPatch(omitSessionId(params), optionalSessionId(params))
|
|
83
81
|
};
|
|
84
|
-
case "
|
|
82
|
+
case "getSessionState": return {
|
|
85
83
|
id: request.id,
|
|
86
84
|
ok: true,
|
|
87
|
-
result: tool.
|
|
85
|
+
result: tool.getSessionState(params.detail ?? "summary", optionalSessionId(params))
|
|
88
86
|
};
|
|
89
|
-
case "
|
|
87
|
+
case "listDiagnostics": {
|
|
88
|
+
const constituentId = params.constituentId;
|
|
89
|
+
const filters = typeof constituentId === "number" ? { constituentId } : params.filters;
|
|
90
|
+
return {
|
|
91
|
+
id: request.id,
|
|
92
|
+
ok: true,
|
|
93
|
+
result: tool.listDiagnostics(filters, optionalSessionId(params))
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
case "analyzeExpression": return {
|
|
90
97
|
id: request.id,
|
|
91
98
|
ok: true,
|
|
92
|
-
result: tool.
|
|
99
|
+
result: tool.analyzeExpression(omitSessionId(params), optionalSessionId(params))
|
|
93
100
|
};
|
|
94
|
-
case "
|
|
101
|
+
case "commitStep": return {
|
|
95
102
|
id: request.id,
|
|
96
103
|
ok: true,
|
|
97
|
-
result: tool.
|
|
104
|
+
result: tool.commitStep(params.message, optionalSessionId(params))
|
|
98
105
|
};
|
|
99
|
-
case "
|
|
106
|
+
case "exportSession": return {
|
|
100
107
|
id: request.id,
|
|
101
108
|
ok: true,
|
|
102
|
-
result: tool.
|
|
109
|
+
result: tool.exportSession(optionalSessionId(params))
|
|
103
110
|
};
|
|
104
|
-
case "
|
|
111
|
+
case "exportPortal": return {
|
|
105
112
|
id: request.id,
|
|
106
113
|
ok: true,
|
|
107
|
-
result:
|
|
114
|
+
result: tool.exportPortal(omitSessionId(params), optionalSessionId(params))
|
|
108
115
|
};
|
|
109
|
-
case "
|
|
116
|
+
case "importData": return {
|
|
110
117
|
id: request.id,
|
|
111
118
|
ok: true,
|
|
112
|
-
result:
|
|
119
|
+
result: tool.importData(params.payload, params.kind)
|
|
113
120
|
};
|
|
114
|
-
case "
|
|
121
|
+
case "setModelValues": return {
|
|
115
122
|
id: request.id,
|
|
116
123
|
ok: true,
|
|
117
|
-
result: await tool.
|
|
124
|
+
result: await tool.setModelValues(omitSessionId(params), optionalSessionId(params))
|
|
118
125
|
};
|
|
119
126
|
case "getModelState": return {
|
|
120
127
|
id: request.id,
|
|
121
128
|
ok: true,
|
|
122
|
-
result: tool.getModelState(
|
|
123
|
-
};
|
|
124
|
-
case "evaluateExpression": return {
|
|
125
|
-
id: request.id,
|
|
126
|
-
ok: true,
|
|
127
|
-
result: tool.evaluateExpression(requiredString(params, "sessionId"), params.input)
|
|
129
|
+
result: tool.getModelState(optionalSessionId(params))
|
|
128
130
|
};
|
|
129
|
-
case "
|
|
131
|
+
case "evaluate": return {
|
|
130
132
|
id: request.id,
|
|
131
133
|
ok: true,
|
|
132
|
-
result: tool.
|
|
134
|
+
result: tool.evaluate(omitSessionId(params), optionalSessionId(params))
|
|
133
135
|
};
|
|
134
136
|
case "recalculateModel": return {
|
|
135
137
|
id: request.id,
|
|
136
138
|
ok: true,
|
|
137
|
-
result: tool.recalculateModel(
|
|
139
|
+
result: tool.recalculateModel(optionalSessionId(params))
|
|
138
140
|
};
|
|
139
141
|
default: return {
|
|
140
142
|
id: request.id ?? null,
|
|
@@ -157,6 +159,16 @@ async function handleRequest(request) {
|
|
|
157
159
|
};
|
|
158
160
|
}
|
|
159
161
|
}
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/wrapper/stdio-wrapper.ts
|
|
164
|
+
const persistenceDir = process.env.RSTOOL_PERSISTENCE_DIR;
|
|
165
|
+
const tool = new RSToolAgent(persistenceDir ? { persistenceDir } : {});
|
|
166
|
+
function writeResponse(response) {
|
|
167
|
+
if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) return;
|
|
168
|
+
try {
|
|
169
|
+
process.stdout.write(`${JSON.stringify(response)}\n`);
|
|
170
|
+
} catch {}
|
|
171
|
+
}
|
|
160
172
|
const input = readline.createInterface({
|
|
161
173
|
input: process.stdin,
|
|
162
174
|
crlfDelay: Infinity
|
|
@@ -175,7 +187,7 @@ input.on("line", (line) => {
|
|
|
175
187
|
try {
|
|
176
188
|
const request = JSON.parse(line);
|
|
177
189
|
if (!("id" in request) || !("method" in request)) throw new Error("Request must include \"id\" and \"method\"");
|
|
178
|
-
|
|
190
|
+
handleStdioRequest(tool, request).then(writeResponse);
|
|
179
191
|
} catch (error) {
|
|
180
192
|
writeResponse({
|
|
181
193
|
id: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio-wrapper.js","names":[],"sources":["../../src/wrapper/stdio-wrapper.ts"],"sourcesContent":["#!/usr/bin/env node\nimport readline from 'node:readline';\n\nimport { RSToolAgent } from '../models/rstool-agent';\n\ninterface StdioRequest {\n id: string | number;\n method: string;\n params?: unknown;\n}\n\ninterface StdioResponse {\n id: string | number | null;\n ok: boolean;\n result?: unknown;\n error?: {\n code: string;\n message: string;\n details?: unknown;\n };\n}\n\nconst tool = new RSToolAgent();\n\nconst METHODS = [\n 'createSession',\n 'addOrUpdateConstituenta',\n 'analyzeExpression',\n 'getFormState',\n 'listDiagnostics',\n 'commitStep',\n 'exportSession',\n 'exportPortalSchema',\n 'exportPortalModel',\n 'importSession',\n 'setConstituentaValue',\n 'setConstituentaValues',\n 'clearConstituentaValues',\n 'getModelState',\n 'evaluateExpression',\n 'evaluateConstituenta',\n 'recalculateModel'\n] as const;\n\nfunction writeResponse(response: StdioResponse): void {\n if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) {\n return;\n }\n try {\n process.stdout.write(`${JSON.stringify(response)}\\n`);\n } catch {\n // The client might have already closed stdout (EPIPE). Safe to ignore.\n }\n}\n\nfunction asObject(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return {};\n }\n return value as Record<string, unknown>;\n}\n\nfunction requiredString(input: Record<string, unknown>, key: string): string {\n const value = input[key];\n if (typeof value !== 'string' || value.length === 0) {\n throw new Error(`Missing or invalid \"${key}\"`);\n }\n return value;\n}\n\nasync function handleRequest(request: StdioRequest): Promise<StdioResponse> {\n try {\n const params = asObject(request.params);\n switch (request.method) {\n case 'ping':\n return { id: request.id, ok: true, result: { pong: true } };\n case 'methods':\n return { id: request.id, ok: true, result: METHODS };\n case 'createSession':\n return {\n id: request.id,\n ok: true,\n result: tool.createSession(params.initial as never)\n };\n case 'addOrUpdateConstituenta':\n return {\n id: request.id,\n ok: true,\n result: tool.addOrUpdateConstituenta(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'analyzeExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.analyzeExpression(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'getFormState':\n return {\n id: request.id,\n ok: true,\n result: tool.getFormState(requiredString(params, 'sessionId'))\n };\n case 'listDiagnostics':\n return {\n id: request.id,\n ok: true,\n result: tool.listDiagnostics(requiredString(params, 'sessionId'), params.filters as never)\n };\n case 'commitStep':\n return {\n id: request.id,\n ok: true,\n result: tool.commitStep(requiredString(params, 'sessionId'), params.message as string | undefined)\n };\n case 'exportSession':\n return {\n id: request.id,\n ok: true,\n result: tool.exportSession(requiredString(params, 'sessionId'))\n };\n case 'exportPortalSchema':\n return {\n id: request.id,\n ok: true,\n result: tool.exportPortalSchema(requiredString(params, 'sessionId'))\n };\n case 'exportPortalModel':\n return {\n id: request.id,\n ok: true,\n result: tool.exportPortalModel(requiredString(params, 'sessionId'))\n };\n case 'importSession':\n return {\n id: request.id,\n ok: true,\n result: tool.importSession(requiredString(params, 'payload'))\n };\n case 'setConstituentaValue':\n return {\n id: request.id,\n ok: true,\n result: await tool.setConstituentaValue(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'setConstituentaValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.setConstituentaValues(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'clearConstituentaValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.clearConstituentaValues(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'getModelState':\n return {\n id: request.id,\n ok: true,\n result: tool.getModelState(requiredString(params, 'sessionId'))\n };\n case 'evaluateExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluateExpression(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'evaluateConstituenta':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluateConstituenta(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'recalculateModel':\n return {\n id: request.id,\n ok: true,\n result: tool.recalculateModel(requiredString(params, 'sessionId'))\n };\n default:\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'METHOD_NOT_FOUND',\n message: `Unknown method: ${request.method}`\n }\n };\n }\n } catch (error) {\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'INTERNAL_ERROR',\n message: error instanceof Error ? error.message : 'Unknown error',\n details: error\n }\n };\n }\n}\n\nconst input = readline.createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nwriteResponse({\n id: null,\n ok: true,\n result: {\n ready: true,\n wrapper: 'rstool-stdio',\n contractVersion: tool.contractVersion\n }\n});\n\ninput.on('line', line => {\n if (!line.trim()) {\n return;\n }\n try {\n const request = JSON.parse(line) as StdioRequest;\n if (!('id' in request) || !('method' in request)) {\n throw new Error('Request must include \"id\" and \"method\"');\n }\n void handleRequest(request).then(writeResponse);\n } catch (error) {\n writeResponse({\n id: null,\n ok: false,\n error: {\n code: 'BAD_REQUEST',\n message: error instanceof Error ? error.message : 'Invalid JSON'\n }\n });\n }\n});\n"],"mappings":";;;;AAsBA,MAAM,OAAO,IAAI,YAAY;AAE7B,MAAM,UAAU;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,cAAc,UAA+B;CACpD,IAAI,CAAC,QAAQ,OAAO,YAAY,QAAQ,OAAO,aAAa,QAAQ,OAAO,eACzE;CAEF,IAAI;EACF,QAAQ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AAQ,KAAK,qBAAqB,eAAe,QAAQ,WAAW,GAAG,OAAO,KAAc;GAC9F;GACF,KAAK,oBACH,OAAO;IACL,IAAI,QAAQ;IACZ,IAAI;IACJ,QAAQ,KAAK,iBAAiB,eAAe,QAAQ,WAAW,CAAC;GACnE;GACF,SACE,OAAO;IACL,IAAI,QAAQ,MAAM;IAClB,IAAI;IACJ,OAAO;KACL,MAAM;KACN,SAAS,mBAAmB,QAAQ;IACtC;GACF;EACJ;CACF,SAAS,OAAO;EACd,OAAO;GACL,IAAI,QAAQ,MAAM;GAClB,IAAI;GACJ,OAAO;IACL,MAAM;IACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;IAClD,SAAS;GACX;EACF;CACF;AACF;AAEA,MAAM,QAAQ,SAAS,gBAAgB;CACrC,OAAO,QAAQ;CACf,WAAW;AACb,CAAC;AAED,cAAc;CACZ,IAAI;CACJ,IAAI;CACJ,QAAQ;EACN,OAAO;EACP,SAAS;EACT,iBAAiB,KAAK;CACxB;AACF,CAAC;AAED,MAAM,GAAG,SAAQ,SAAQ;CACvB,IAAI,CAAC,KAAK,KAAK,GACb;CAEF,IAAI;EACF,MAAM,UAAU,KAAK,MAAM,IAAI;EAC/B,IAAI,EAAE,QAAQ,YAAY,EAAE,YAAY,UACtC,MAAM,IAAI,MAAM,4CAAwC;EAE1D,AAAK,cAAc,OAAO,CAAC,CAAC,KAAK,aAAa;CAChD,SAAS,OAAO;EACd,cAAc;GACZ,IAAI;GACJ,IAAI;GACJ,OAAO;IACL,MAAM;IACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACpD;EACF,CAAC;CACH;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"stdio-wrapper.js","names":[],"sources":["../../src/wrapper/stdio-handler.ts","../../src/wrapper/stdio-wrapper.ts"],"sourcesContent":["import type { RSToolAgent } from '../models/rstool-agent';\n\nexport interface StdioRequest {\n id: string | number;\n method: string;\n params?: unknown;\n}\n\nexport interface StdioResponse {\n id: string | number | null;\n ok: boolean;\n result?: unknown;\n error?: {\n code: string;\n message: string;\n details?: unknown;\n };\n}\n\nexport const STDIO_METHODS = [\n 'ensureSession',\n 'createSession',\n 'getCurrentSession',\n 'setCurrentSession',\n 'applySchemaPatch',\n 'getSessionState',\n 'listDiagnostics',\n 'analyzeExpression',\n 'commitStep',\n 'exportSession',\n 'exportPortal',\n 'importData',\n 'setModelValues',\n 'getModelState',\n 'evaluate',\n 'recalculateModel'\n] as const;\n\nfunction asObject(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return {};\n }\n return value as Record<string, unknown>;\n}\n\nfunction requiredString(input: Record<string, unknown>, key: string): string {\n const value = input[key];\n if (typeof value !== 'string' || value.length === 0) {\n throw new Error(`Missing or invalid \"${key}\"`);\n }\n return value;\n}\n\nfunction optionalSessionId(input: Record<string, unknown>): string | undefined {\n const value = input.sessionId;\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction omitSessionId(input: Record<string, unknown>): Record<string, unknown> {\n const { sessionId: _sessionId, ...rest } = input;\n return rest;\n}\n\nexport async function handleStdioRequest(tool: RSToolAgent, request: StdioRequest): Promise<StdioResponse> {\n try {\n const params = asObject(request.params);\n switch (request.method) {\n case 'ping':\n return { id: request.id, ok: true, result: { pong: true, contractVersion: tool.contractVersion } };\n case 'methods':\n return { id: request.id, ok: true, result: STDIO_METHODS };\n case 'ensureSession':\n return {\n id: request.id,\n ok: true,\n result: tool.ensureSession(params.initial as never)\n };\n case 'createSession':\n return {\n id: request.id,\n ok: true,\n result: tool.createSession(params.initial as never)\n };\n case 'getCurrentSession':\n return {\n id: request.id,\n ok: true,\n result: tool.getCurrentSession()\n };\n case 'setCurrentSession':\n return {\n id: request.id,\n ok: true,\n result: tool.setCurrentSession(requiredString(params, 'sessionId'))\n };\n case 'applySchemaPatch':\n return {\n id: request.id,\n ok: true,\n result: tool.applySchemaPatch(omitSessionId(params) as never, optionalSessionId(params))\n };\n case 'getSessionState':\n return {\n id: request.id,\n ok: true,\n result: tool.getSessionState(\n (params.detail as 'summary' | 'full' | undefined) ?? 'summary',\n optionalSessionId(params)\n )\n };\n case 'listDiagnostics': {\n const constituentId = params.constituentId;\n const filters = typeof constituentId === 'number' ? { constituentId } : (params.filters as never);\n return {\n id: request.id,\n ok: true,\n result: tool.listDiagnostics(filters, optionalSessionId(params))\n };\n }\n case 'analyzeExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.analyzeExpression(omitSessionId(params) as never, optionalSessionId(params))\n };\n case 'commitStep':\n return {\n id: request.id,\n ok: true,\n result: tool.commitStep(params.message as string | undefined, optionalSessionId(params))\n };\n case 'exportSession':\n return {\n id: request.id,\n ok: true,\n result: tool.exportSession(optionalSessionId(params))\n };\n case 'exportPortal':\n return {\n id: request.id,\n ok: true,\n result: tool.exportPortal(omitSessionId(params) as never, optionalSessionId(params))\n };\n case 'importData':\n return {\n id: request.id,\n ok: true,\n result: tool.importData(params.payload as string | object, params.kind as never)\n };\n case 'setModelValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.setModelValues(omitSessionId(params) as never, optionalSessionId(params))\n };\n case 'getModelState':\n return {\n id: request.id,\n ok: true,\n result: tool.getModelState(optionalSessionId(params))\n };\n case 'evaluate':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluate(omitSessionId(params) as never, optionalSessionId(params))\n };\n case 'recalculateModel':\n return {\n id: request.id,\n ok: true,\n result: tool.recalculateModel(optionalSessionId(params))\n };\n default:\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'METHOD_NOT_FOUND',\n message: `Unknown method: ${request.method}`\n }\n };\n }\n } catch (error) {\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'INTERNAL_ERROR',\n message: error instanceof Error ? error.message : 'Unknown error',\n details: error\n }\n };\n }\n}\n","#!/usr/bin/env node\nimport readline from 'node:readline';\n\nimport { RSToolAgent } from '../models/rstool-agent';\nimport { handleStdioRequest, type StdioRequest, type StdioResponse } from './stdio-handler';\n\nconst persistenceDir = process.env.RSTOOL_PERSISTENCE_DIR;\nconst tool = new RSToolAgent(persistenceDir ? { persistenceDir } : {});\n\nfunction writeResponse(response: StdioResponse): void {\n if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) {\n return;\n }\n try {\n process.stdout.write(`${JSON.stringify(response)}\\n`);\n } catch {\n // The client might have already closed stdout (EPIPE). Safe to ignore.\n }\n}\n\nconst input = readline.createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nwriteResponse({\n id: null,\n ok: true,\n result: {\n ready: true,\n wrapper: 'rstool-stdio',\n contractVersion: tool.contractVersion\n }\n});\n\ninput.on('line', line => {\n if (!line.trim()) {\n return;\n }\n try {\n const request = JSON.parse(line) as StdioRequest;\n if (!('id' in request) || !('method' in request)) {\n throw new Error('Request must include \"id\" and \"method\"');\n }\n void handleStdioRequest(tool, request).then(writeResponse);\n } catch (error) {\n writeResponse({\n id: null,\n ok: false,\n error: {\n code: 'BAD_REQUEST',\n message: error instanceof Error ? error.message : 'Invalid JSON'\n }\n });\n }\n});\n"],"mappings":";;;;AAmBA,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,SAAS,OAAyC;CACzD,IAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAC5D,OAAO,CAAC;CAEV,OAAO;AACT;AAEA,SAAS,eAAe,OAAgC,KAAqB;CAC3E,MAAM,QAAQ,MAAM;CACpB,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAChD,MAAM,IAAI,MAAM,uBAAuB,IAAI,EAAE;CAE/C,OAAO;AACT;AAEA,SAAS,kBAAkB,OAAoD;CAC7E,MAAM,QAAQ,MAAM;CACpB,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAS,cAAc,OAAyD;CAC9E,MAAM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,iBAAiB,QAAQ,MAAM,UAAU;IAClD,SAAS;GACX;EACF;CACF;AACF;;;AC5LA,MAAM,iBAAiB,QAAQ,IAAI;AACnC,MAAM,OAAO,IAAI,YAAY,iBAAiB,EAAE,eAAe,IAAI,CAAC,CAAC;AAErE,SAAS,cAAc,UAA+B;CACpD,IAAI,CAAC,QAAQ,OAAO,YAAY,QAAQ,OAAO,aAAa,QAAQ,OAAO,eACzE;CAEF,IAAI;EACF,QAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,QAAQ,EAAE,GAAG;CACtD,QAAQ,CAER;AACF;AAEA,MAAM,QAAQ,SAAS,gBAAgB;CACrC,OAAO,QAAQ;CACf,WAAW;AACb,CAAC;AAED,cAAc;CACZ,IAAI;CACJ,IAAI;CACJ,QAAQ;EACN,OAAO;EACP,SAAS;EACT,iBAAiB,KAAK;CACxB;AACF,CAAC;AAED,MAAM,GAAG,SAAQ,SAAQ;CACvB,IAAI,CAAC,KAAK,KAAK,GACb;CAEF,IAAI;EACF,MAAM,UAAU,KAAK,MAAM,IAAI;EAC/B,IAAI,EAAE,QAAQ,YAAY,EAAE,YAAY,UACtC,MAAM,IAAI,MAAM,4CAAwC;EAE1D,AAAK,mBAAmB,MAAM,OAAO,CAAC,CAAC,KAAK,aAAa;CAC3D,SAAS,OAAO;EACd,cAAc;GACZ,IAAI;GACJ,IAAI;GACJ,OAAO;IACL,MAAM;IACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACpD;EACF,CAAC;CACH;AACF,CAAC"}
|
package/docs/CONSTITUENTA.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Конституенты
|
|
2
2
|
|
|
3
|
-
Читай перед `
|
|
3
|
+
Читай перед `applySchemaPatch`.
|
|
4
4
|
|
|
5
5
|
## Поля
|
|
6
6
|
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
- `axiom` / `A#` — аксиома; нужна типизация `Logic`.
|
|
29
29
|
- `statement` / `T#` — высказывание; нужна типизация `Logic`.
|
|
30
30
|
|
|
31
|
-
В модели `basic`, `constant`, `structure` можно интерпретировать через `
|
|
31
|
+
В модели `basic`, `constant`, `structure` можно интерпретировать через `setModelValues`. `term`, `function`, `predicate`, `axiom`, `statement` вычисляются и напрямую не задаются.
|
|
32
32
|
|
|
33
33
|
## Различие родовой структуры и терма
|
|
34
34
|
|
package/docs/DIAGNOSTICS.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Диагностика
|
|
2
2
|
|
|
3
|
-
Читай, когда `analyzeExpression`, `
|
|
3
|
+
Читай, когда `analyzeExpression`, `applySchemaPatch`, `listDiagnostics` или `evaluate`
|
|
4
4
|
вернули диагностику. Источник истины по кодам — `@rsconcept/domain/src/rslang/error.ts`.
|
|
5
5
|
|
|
6
6
|
## Где лежит диагностика
|
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
У rstool два представления одной и той же ошибки.
|
|
9
9
|
|
|
10
10
|
- **Плоское** `RSToolErrorDescription` — в `AnalysisResult.diagnostics` (из `analyzeExpression`
|
|
11
|
-
и `
|
|
11
|
+
и анализа конституент после `applySchemaPatch`) и в `EvaluationResult.diagnostics`:
|
|
12
12
|
- `code` — числовой `RSErrorCode`.
|
|
13
13
|
- `from`, `to` — полуинтервал `[from, to)` в `definitionFormal` (или в выражении вычисления).
|
|
14
14
|
- `params?` — позиционный массив строк-аргументов сообщения (см. таблицы ниже).
|
|
15
15
|
- **Обёрнутое** `DiagnosticRecord` — только из `listDiagnostics`:
|
|
16
16
|
- `sessionId`, `expression` — исходное выражение.
|
|
17
17
|
- `error` — то же `RSToolErrorDescription` (`code`/`from`/`to`/`params`) **вложено**, читай `record.error.code`.
|
|
18
|
-
- `constituentId?` — id конституенты. У диагностик
|
|
19
|
-
у черновиков `analyzeExpression` он `undefined`. Фильтруй `listDiagnostics(
|
|
18
|
+
- `constituentId?` — id конституенты. У диагностик сохранённых конституент он есть;
|
|
19
|
+
у черновиков `analyzeExpression` он `undefined`. Фильтруй `listDiagnostics({ constituentId })`
|
|
20
|
+
или `listDiagnostics({ constituentId }, sessionId)`.
|
|
20
21
|
|
|
21
22
|
## Класс и префикс кода
|
|
22
23
|
|
|
@@ -128,7 +129,7 @@
|
|
|
128
129
|
| `0x8100` | `calcUnknownError` | — | Непредвиденная ошибка вычисления. |
|
|
129
130
|
| `0x8101` | `setOverflow` | `[limit]` | Превышен предел числа элементов `limit`: упрости выражение или данные. |
|
|
130
131
|
| `0x8102` | `booleanBaseLimit` | `[limit]` | Превышен предел базы степенного множества `limit`. |
|
|
131
|
-
| `0x8103` | `calcGlobalMissing` | `[name]` | Нет значения для `name`: задай `
|
|
132
|
+
| `0x8103` | `calcGlobalMissing` | `[name]` | Нет значения для `name`: задай через `setModelValues`. |
|
|
132
133
|
| `0x8104` | `iterationsLimit` | `[limit]` | Превышен предел итераций `limit`. |
|
|
133
134
|
| `0x8105` | `calcInvalidDebool` | — | `debool` получил не синглетон. |
|
|
134
135
|
| `0x8106` | `iterateInfinity` | — | Итерация по бесконечному множеству. |
|
package/docs/MODEL-TESTING.md
CHANGED
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
|
|
16
16
|
`basic`, `constant`, `structure` можно интерпретировать напрямую. `term`, `function`, `predicate`, `axiom`, `statement` должны вычисляться из формулы, поэтому их напрямую не задавай.
|
|
17
17
|
|
|
18
|
-
Пример формы
|
|
18
|
+
Пример формы данных (`setModelValues` — асинхронный, нужен `await`):
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
21
|
import { TUPLE_ID } from '@rsconcept/domain';
|
|
22
22
|
|
|
23
|
-
tool.
|
|
24
|
-
|
|
23
|
+
await tool.setModelValues({
|
|
24
|
+
set: [
|
|
25
25
|
{ target: 1, value: { 0: 'ann', 1: 'bob', 2: 'cat' } },
|
|
26
26
|
{
|
|
27
27
|
target: 2,
|
package/docs/PORTAL-API.md
CHANGED
|
@@ -224,19 +224,24 @@ curl.exe -s "https://api.portal.acconcept.ru/api/rsforms/856/details"
|
|
|
224
224
|
## Как перенести КС в rstool
|
|
225
225
|
|
|
226
226
|
1. Получи `GET /api/rsforms/:id/details`.
|
|
227
|
-
2.
|
|
228
|
-
3.
|
|
229
|
-
4.
|
|
230
|
-
5.
|
|
231
|
-
6.
|
|
232
|
-
7. Для сохранения рабочей сессии используй `exportSession`.
|
|
233
|
-
8. Для загрузки схемы обратно в Portal используй `exportPortalSchema`.
|
|
227
|
+
2. Вызови `importData(JSON.stringify(payload))` — auto определит `portal-details`; для Load from JSON — `importData(payload, 'portal-schema')`.
|
|
228
|
+
3. Проверь `listDiagnostics()` (после `importData` сессия уже текущая).
|
|
229
|
+
4. Работай локально: анализ, правки, вычисления, маленькая КМ.
|
|
230
|
+
5. Для сохранения рабочей сессии используй `exportSession`.
|
|
231
|
+
6. Для загрузки схемы обратно в Portal используй `exportPortal({ kind: 'schema' })`.
|
|
234
232
|
|
|
235
|
-
|
|
236
|
-
в `importSession` напрямую. Его нужно перенести через `addOrUpdateConstituenta`
|
|
237
|
-
или через отдельный адаптер, если он появится в контракте.
|
|
233
|
+
Альтернатива: `createSession` + `applySchemaPatch` с массивом `items`.
|
|
238
234
|
|
|
239
|
-
|
|
235
|
+
Portal JSON из `/details` **не является** форматом `exportSession`; используй `importData`, не передавай его как session export.
|
|
236
|
+
|
|
237
|
+
Минимальный импорт:
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
const session = tool.importData(JSON.stringify(portal));
|
|
241
|
+
tool.listDiagnostics();
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Пакетный маппинг через `applySchemaPatch`:
|
|
240
245
|
|
|
241
246
|
```ts
|
|
242
247
|
const session = tool.createSession({
|
|
@@ -245,9 +250,9 @@ const session = tool.createSession({
|
|
|
245
250
|
comment: portal.description
|
|
246
251
|
});
|
|
247
252
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
253
|
+
tool.applySchemaPatch(
|
|
254
|
+
{
|
|
255
|
+
items: portal.items.map(item => ({
|
|
251
256
|
id: item.id,
|
|
252
257
|
alias: item.alias,
|
|
253
258
|
cstType: item.cst_type,
|
|
@@ -255,9 +260,10 @@ for (const item of portal.items) {
|
|
|
255
260
|
term: item.term_raw ?? '',
|
|
256
261
|
definitionText: item.definition_raw ?? '',
|
|
257
262
|
convention: item.convention ?? ''
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
263
|
+
}))
|
|
264
|
+
},
|
|
265
|
+
session.sessionId
|
|
266
|
+
);
|
|
261
267
|
```
|
|
262
268
|
|
|
263
269
|
## Практика для агентов
|
|
@@ -294,5 +300,5 @@ path.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding='utf
|
|
|
294
300
|
- Не парси HTML SPA.
|
|
295
301
|
- Не запрашивай UI напрямую, используй преобразованные API запросы.
|
|
296
302
|
- Не предлагай авторизацию через session cookie или `sessionid` в curl.
|
|
297
|
-
- Не передавай `/details` JSON в `
|
|
303
|
+
- Не передавай `/details` JSON в `importData` с `kind: 'session'`.
|
|
298
304
|
- Не запрашивай `/details`, если нужны только метаданные.
|
package/examples/README.md
CHANGED
|
@@ -30,7 +30,7 @@ npx tsx node_modules/@rsconcept/rstool/examples/agent-client.ts
|
|
|
30
30
|
| `build-rsform.ts` | Сборка RSForm → `rsform-session.json` |
|
|
31
31
|
| `build-rsmodel.ts` | Демо-модель и проверки → `rsmodel-session.json` |
|
|
32
32
|
|
|
33
|
-
Готовые `*-session.json` — снимки `exportSession` для `
|
|
33
|
+
Готовые `*-session.json` — снимки `exportSession` для `importData` и тестов. Пересобрать: соответствующий `build-*.ts` перезапишет файл рядом с собой.
|
|
34
34
|
|
|
35
35
|
## Темы и npm-скрипты
|
|
36
36
|
|
package/examples/agent-client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CstType, RSToolWrapperClient, type
|
|
1
|
+
import { CstType, RSToolWrapperClient, type AnalyzeExpressionInput } from '../src';
|
|
2
2
|
|
|
3
3
|
interface CreateSessionResult {
|
|
4
4
|
sessionId: string;
|
|
@@ -13,41 +13,16 @@ async function runExample() {
|
|
|
13
13
|
const session = await client.call<CreateSessionResult>('createSession');
|
|
14
14
|
console.log('Session created:', session);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
id: 1,
|
|
19
|
-
alias: 'X1',
|
|
20
|
-
cstType: CstType.BASE,
|
|
21
|
-
definitionFormal: ''
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
await client.call('addOrUpdateConstituenta', {
|
|
25
|
-
sessionId: session.sessionId,
|
|
26
|
-
input: baseInput
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const upsertInput: AddOrUpdateConstituentaInput = {
|
|
30
|
-
draft: {
|
|
31
|
-
id: 2,
|
|
32
|
-
alias: 'D1',
|
|
33
|
-
cstType: CstType.TERM,
|
|
34
|
-
definitionFormal: '1+2'
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const upsert = await client.call('addOrUpdateConstituenta', {
|
|
38
|
-
sessionId: session.sessionId,
|
|
39
|
-
input: upsertInput
|
|
16
|
+
await client.call('applySchemaPatch', {
|
|
17
|
+
items: [{ alias: 'X1' }, { alias: 'D1', definitionFormal: '1+2' }]
|
|
40
18
|
});
|
|
41
|
-
console.log('Upsert result:', upsert);
|
|
42
19
|
|
|
43
|
-
await client.call('
|
|
44
|
-
|
|
45
|
-
input: { target: 1, value: { 0: 'zero', 1: 'one' } }
|
|
20
|
+
await client.call('setModelValues', {
|
|
21
|
+
set: [{ target: 1, value: { 0: 'zero', 1: 'one' } }]
|
|
46
22
|
});
|
|
47
23
|
|
|
48
|
-
const evalResult = await client.call('
|
|
49
|
-
|
|
50
|
-
input: { constituentId: 2 }
|
|
24
|
+
const evalResult = await client.call('evaluate', {
|
|
25
|
+
constituentId: 2
|
|
51
26
|
});
|
|
52
27
|
console.log('Evaluation result:', evalResult);
|
|
53
28
|
|
|
@@ -55,16 +30,11 @@ async function runExample() {
|
|
|
55
30
|
expression: '(',
|
|
56
31
|
cstType: CstType.TERM
|
|
57
32
|
};
|
|
58
|
-
const analysis = await client.call('analyzeExpression',
|
|
59
|
-
|
|
60
|
-
input: analyzeInput
|
|
61
|
-
});
|
|
62
|
-
console.log('Analysis result:', analysis);
|
|
33
|
+
const analysis = await client.call<{ diagnostics: unknown[] }>('analyzeExpression', analyzeInput);
|
|
34
|
+
console.log('Scratch analysis diagnostics:', analysis.diagnostics.length);
|
|
63
35
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
console.log('Diagnostics count:', Array.isArray(diagnostics) ? diagnostics.length : diagnostics);
|
|
36
|
+
const sessionDiagnostics = await client.call<unknown[]>('listDiagnostics', {});
|
|
37
|
+
console.log('Session diagnostics count:', sessionDiagnostics.length);
|
|
68
38
|
} finally {
|
|
69
39
|
await client.close();
|
|
70
40
|
}
|