@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.
Files changed (116) hide show
  1. package/README.md +61 -33
  2. package/dist/agent-workflow-Gk0Vfnv1.d.ts +64 -0
  3. package/dist/analysis-LLnPhmGa.d.ts +23 -0
  4. package/dist/{common-DxLg3eXX.d.ts → common-DHJalS-Q.d.ts} +6 -1
  5. package/dist/constituenta-DnGR6bnM.d.ts +54 -0
  6. package/dist/diagnostic-D9yl_mEL.d.ts +19 -0
  7. package/dist/evaluation-Cns8BFm4.d.ts +31 -0
  8. package/dist/index.d.ts +11 -11
  9. package/dist/index.js +1 -2
  10. package/dist/mappers/model-adapter.d.ts +3 -3
  11. package/dist/mappers/schema-adapter.d.ts +4 -4
  12. package/dist/mappers/types.d.ts +6 -2
  13. package/dist/mappers/types.js +2 -0
  14. package/dist/mappers/types.js.map +1 -1
  15. package/dist/{model-value-SFAVj0dw.d.ts → model-value-BbonPzMz.d.ts} +14 -3
  16. package/dist/models/agent-workflow.d.ts +2 -0
  17. package/dist/models/agent-workflow.js +1 -0
  18. package/dist/models/analysis.d.ts +1 -1
  19. package/dist/models/common.d.ts +1 -1
  20. package/dist/models/constituenta.d.ts +2 -2
  21. package/dist/models/diagnostic.d.ts +1 -1
  22. package/dist/models/evaluation.d.ts +2 -2
  23. package/dist/models/index.d.ts +11 -11
  24. package/dist/models/index.js +2 -2
  25. package/dist/models/model-value.d.ts +2 -2
  26. package/dist/models/rstool-agent.d.ts +1 -1
  27. package/dist/models/rstool-agent.js +1 -1
  28. package/dist/models/session.d.ts +1 -1
  29. package/dist/models/tool-contract.d.ts +2 -2
  30. package/dist/models/tool-contract.js +2 -1
  31. package/dist/models/tool-contract.js.map +1 -1
  32. package/dist/models-Bw6Uum8i.js +685 -0
  33. package/dist/models-Bw6Uum8i.js.map +1 -0
  34. package/dist/rstool-agent-D2cQze_b.d.ts +71 -0
  35. package/dist/session/session-store.d.ts +18 -5
  36. package/dist/session/session-store.js +1 -64
  37. package/dist/{session-BPgsE80c.d.ts → session-ChexW8i7.d.ts} +11 -8
  38. package/dist/tool-contract-0uRGhEfW.d.ts +164 -0
  39. package/dist/wrapper/client.d.ts +23 -0
  40. package/dist/wrapper/client.js +17 -0
  41. package/dist/wrapper/client.js.map +1 -1
  42. package/dist/wrapper/stdio-wrapper.js +75 -63
  43. package/dist/wrapper/stdio-wrapper.js.map +1 -1
  44. package/docs/CONSTITUENTA.md +2 -2
  45. package/docs/DIAGNOSTICS.md +6 -5
  46. package/docs/MODEL-TESTING.md +3 -3
  47. package/docs/PORTAL-API.md +24 -18
  48. package/examples/README.md +1 -1
  49. package/examples/agent-client.ts +11 -41
  50. package/examples/build-chocolate-nim-rsform.ts +21 -70
  51. package/examples/chocolate-nim/build-rsform.ts +23 -18
  52. package/examples/chocolate-nim/build-rsmodel.ts +10 -12
  53. package/examples/chocolate-nim/rsform-session.json +290 -290
  54. package/examples/chocolate-nim/rsmodel-session.json +291 -291
  55. package/examples/expression-bank/bank-constituents.ts +304 -53
  56. package/examples/expression-bank/build-rsform.ts +19 -16
  57. package/examples/expression-bank/rsform-session.json +1551 -1551
  58. package/examples/kinship/build-rsform.ts +23 -18
  59. package/examples/kinship/build-rsmodel.ts +16 -16
  60. package/examples/kinship/rsform-session.json +219 -219
  61. package/examples/kinship/rsmodel-session.json +221 -221
  62. package/examples/kinship/session.ts +19 -21
  63. package/examples/movd/build-rsform.ts +23 -18
  64. package/examples/movd/build-rsmodel.ts +18 -20
  65. package/examples/movd/rsform-session.json +262 -262
  66. package/examples/movd/rsmodel-session.json +264 -264
  67. package/examples/sample/build-rsform.ts +18 -51
  68. package/examples/sample/build-rsmodel.ts +25 -44
  69. package/examples/sample/rsform-session.json +10 -7
  70. package/examples/sample/rsmodel-session.json +36 -33
  71. package/examples/template-apply/build-rsform.ts +27 -24
  72. package/examples/template-apply/rsform-session.json +48 -48
  73. package/package.json +4 -2
  74. package/skills/rstool-helper/EXAMPLES.md +44 -116
  75. package/skills/rstool-helper/GUIDE.md +40 -25
  76. package/skills/rstool-helper/REFERENCE.md +40 -177
  77. package/src/index.ts +24 -17
  78. package/src/mappers/portal-adapter.ts +49 -0
  79. package/src/mappers/types.ts +4 -0
  80. package/src/models/agent-workflow.ts +66 -0
  81. package/src/models/analysis.ts +7 -0
  82. package/src/models/common.ts +7 -0
  83. package/src/models/constituenta.ts +24 -6
  84. package/src/models/diagnostic.ts +4 -0
  85. package/src/models/evaluation.ts +11 -0
  86. package/src/models/import-detect.test.ts +66 -0
  87. package/src/models/import-detect.ts +42 -0
  88. package/src/models/import-export.ts +24 -0
  89. package/src/models/index.ts +22 -14
  90. package/src/models/model-value.ts +12 -0
  91. package/src/models/portal-json.test.ts +38 -0
  92. package/src/models/portal-json.ts +54 -1
  93. package/src/models/rstool-agent.test.ts +698 -146
  94. package/src/models/rstool-agent.ts +392 -92
  95. package/src/models/session.ts +8 -5
  96. package/src/models/tool-contract.ts +81 -42
  97. package/src/session/batch-apply.test.ts +123 -0
  98. package/src/session/batch-apply.ts +82 -0
  99. package/src/session/persistence.test.ts +63 -0
  100. package/src/session/persistence.ts +69 -0
  101. package/src/session/session-store.ts +76 -6
  102. package/src/wrapper/client.test.ts +58 -0
  103. package/src/wrapper/client.ts +23 -0
  104. package/src/wrapper/stdio-handler.test.ts +101 -0
  105. package/src/wrapper/stdio-handler.ts +195 -0
  106. package/src/wrapper/stdio-wrapper.ts +4 -187
  107. package/dist/analysis-JiwOYDKx.d.ts +0 -16
  108. package/dist/constituenta-Dnd6iToB.d.ts +0 -36
  109. package/dist/diagnostic-BMYvciz8.d.ts +0 -15
  110. package/dist/evaluation-CCVYH0wA.d.ts +0 -21
  111. package/dist/index-uhkmwruf.d.ts +0 -46
  112. package/dist/rstool-agent-BZi5jO1y.js +0 -158
  113. package/dist/rstool-agent-BZi5jO1y.js.map +0 -1
  114. package/dist/rstool-agent-pRaPnZay.d.ts +0 -35
  115. package/dist/session/session-store.js.map +0 -1
  116. package/dist/tool-contract-n1ghUOrK.d.ts +0 -32
@@ -2,6 +2,7 @@ import { spawn, type ChildProcessByStdio } from 'node:child_process';
2
2
  import readline from 'node:readline';
3
3
  import { type Readable, type Writable } from 'node:stream';
4
4
 
5
+ /** One JSON line emitted by the stdio wrapper (request response or ready event). */
5
6
  export interface WrapperResponse<T = unknown> {
6
7
  id: string | number | null;
7
8
  ok: boolean;
@@ -13,19 +14,32 @@ export interface WrapperResponse<T = unknown> {
13
14
  };
14
15
  }
15
16
 
17
+ /** Options for spawning the `rstool-wrapper` child process. */
16
18
  export interface RSToolWrapperClientOptions {
19
+ /** Executable to spawn. Default: `npm`. */
17
20
  command?: string;
21
+ /** Arguments passed to `command`. Default: `['run', 'wrapper']`. */
18
22
  args?: string[];
23
+ /** Working directory for the child process. Default: `process.cwd()`. */
19
24
  cwd?: string;
25
+ /** Whether to run the command in a shell. Default: `true`. */
20
26
  shell?: boolean;
21
27
  }
22
28
 
29
+ /**
30
+ * JSON-RPC client for the `rstool-wrapper` stdio process.
31
+ *
32
+ * Sends one JSON request per line on stdin and reads one JSON response per line from stdout.
33
+ */
23
34
  export class RSToolWrapperClient {
24
35
  private process: ChildProcessByStdio<Writable, Readable, null>;
25
36
  private input: readline.Interface;
26
37
  private pending = new Map<string, (value: WrapperResponse) => void>();
27
38
  private requestCounter = 1;
28
39
 
40
+ /**
41
+ * @param options - Spawn configuration; defaults run `npm run wrapper` in the current directory.
42
+ */
29
43
  public constructor(options: RSToolWrapperClientOptions = {}) {
30
44
  this.process = spawn(options.command ?? 'npm', options.args ?? ['run', 'wrapper'], {
31
45
  cwd: options.cwd ?? process.cwd(),
@@ -39,6 +53,7 @@ export class RSToolWrapperClient {
39
53
  this.input.on('line', line => this.handleLine(line));
40
54
  }
41
55
 
56
+ /** Block until the wrapper emits its initial `{ ready: true }` event. */
42
57
  public async waitUntilReady(): Promise<void> {
43
58
  for (;;) {
44
59
  const line = await this.readOneEvent();
@@ -54,6 +69,13 @@ export class RSToolWrapperClient {
54
69
  }
55
70
  }
56
71
 
72
+ /**
73
+ * Invoke a wrapper method and return its `result` field.
74
+ *
75
+ * @param method - Stdio method name (matches {@link RSToolAgentContract} operations).
76
+ * @param params - Method parameters object.
77
+ * @throws When the wrapper responds with `ok: false`.
78
+ */
57
79
  public async call<T>(method: string, params: unknown = {}): Promise<T> {
58
80
  const id = String(this.requestCounter++);
59
81
  const payload = JSON.stringify({ id, method, params });
@@ -68,6 +90,7 @@ export class RSToolWrapperClient {
68
90
  return response.result as T;
69
91
  }
70
92
 
93
+ /** Close stdin and terminate the wrapper process. */
71
94
  public async close(): Promise<void> {
72
95
  this.input.close();
73
96
  this.process.stdin.end();
@@ -0,0 +1,101 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { CstType, CONTRACT_VERSION, RSToolAgent } from '../models';
5
+ import { handleStdioRequest, STDIO_METHODS } from './stdio-handler';
6
+
7
+ describe('handleStdioRequest', () => {
8
+ const tool = new RSToolAgent();
9
+
10
+ it('responds to ping with contract version', async () => {
11
+ const response = await handleStdioRequest(tool, { id: 1, method: 'ping' });
12
+ expect(response).toEqual({
13
+ id: 1,
14
+ ok: true,
15
+ result: { pong: true, contractVersion: CONTRACT_VERSION }
16
+ });
17
+ });
18
+
19
+ it('lists contract methods', async () => {
20
+ const response = await handleStdioRequest(tool, { id: 2, method: 'methods' });
21
+ expect(response.ok).toBe(true);
22
+ expect(response.result).toEqual(STDIO_METHODS);
23
+ });
24
+
25
+ it('applies schema patch through the wrapper', async () => {
26
+ const response = await handleStdioRequest(tool, {
27
+ id: 3,
28
+ method: 'applySchemaPatch',
29
+ params: { items: [{ alias: 'X1' }] }
30
+ });
31
+ expect(response.ok).toBe(true);
32
+ expect((response.result as { success: boolean }).success).toBe(true);
33
+ });
34
+
35
+ it('evaluates a constituent', async () => {
36
+ const sessionTool = new RSToolAgent();
37
+ await handleStdioRequest(sessionTool, {
38
+ id: 10,
39
+ method: 'applySchemaPatch',
40
+ params: {
41
+ items: [{ alias: 'X1' }, { alias: 'D1', definitionFormal: '1+2' }]
42
+ }
43
+ });
44
+ const response = await handleStdioRequest(sessionTool, {
45
+ id: 11,
46
+ method: 'evaluate',
47
+ params: { constituentId: 2 }
48
+ });
49
+ expect(response.ok).toBe(true);
50
+ expect((response.result as { value: number }).value).toBe(3);
51
+ });
52
+
53
+ it('returns METHOD_NOT_FOUND for unknown methods', async () => {
54
+ const response = await handleStdioRequest(tool, { id: 4, method: 'notReal' });
55
+ expect(response.ok).toBe(false);
56
+ expect(response.error?.code).toBe('METHOD_NOT_FOUND');
57
+ });
58
+
59
+ it('returns INTERNAL_ERROR when setCurrentSession lacks sessionId', async () => {
60
+ const response = await handleStdioRequest(tool, { id: 5, method: 'setCurrentSession', params: {} });
61
+ expect(response.ok).toBe(false);
62
+ expect(response.error?.code).toBe('INTERNAL_ERROR');
63
+ expect(response.error?.message).toMatch(/sessionId/);
64
+ });
65
+
66
+ it('returns INTERNAL_ERROR for unknown session id', async () => {
67
+ const sessionTool = new RSToolAgent();
68
+ const response = await handleStdioRequest(sessionTool, {
69
+ id: 6,
70
+ method: 'setCurrentSession',
71
+ params: { sessionId: randomUUID() }
72
+ });
73
+ expect(response.ok).toBe(false);
74
+ expect(response.error?.code).toBe('INTERNAL_ERROR');
75
+ expect(response.error?.message).toMatch(/Unknown session/);
76
+ });
77
+
78
+ it('filters diagnostics by constituentId param', async () => {
79
+ const sessionTool = new RSToolAgent();
80
+ const created = await handleStdioRequest(sessionTool, { id: 20, method: 'createSession' });
81
+ const sessionId = (created.result as { sessionId: string }).sessionId;
82
+ await handleStdioRequest(sessionTool, {
83
+ id: 21,
84
+ method: 'applySchemaPatch',
85
+ params: {
86
+ sessionId,
87
+ mode: 'best_effort',
88
+ items: [{ alias: 'X1', cstType: CstType.BASE, definitionFormal: 'Z' }]
89
+ }
90
+ });
91
+
92
+ const all = await handleStdioRequest(sessionTool, { id: 22, method: 'listDiagnostics', params: { sessionId } });
93
+ const filtered = await handleStdioRequest(sessionTool, {
94
+ id: 23,
95
+ method: 'listDiagnostics',
96
+ params: { sessionId, constituentId: 1 }
97
+ });
98
+ expect((all.result as unknown[]).length).toBeGreaterThan(0);
99
+ expect(filtered.result).toEqual(all.result);
100
+ });
101
+ });
@@ -0,0 +1,195 @@
1
+ import type { RSToolAgent } from '../models/rstool-agent';
2
+
3
+ export interface StdioRequest {
4
+ id: string | number;
5
+ method: string;
6
+ params?: unknown;
7
+ }
8
+
9
+ export interface StdioResponse {
10
+ id: string | number | null;
11
+ ok: boolean;
12
+ result?: unknown;
13
+ error?: {
14
+ code: string;
15
+ message: string;
16
+ details?: unknown;
17
+ };
18
+ }
19
+
20
+ export const STDIO_METHODS = [
21
+ 'ensureSession',
22
+ 'createSession',
23
+ 'getCurrentSession',
24
+ 'setCurrentSession',
25
+ 'applySchemaPatch',
26
+ 'getSessionState',
27
+ 'listDiagnostics',
28
+ 'analyzeExpression',
29
+ 'commitStep',
30
+ 'exportSession',
31
+ 'exportPortal',
32
+ 'importData',
33
+ 'setModelValues',
34
+ 'getModelState',
35
+ 'evaluate',
36
+ 'recalculateModel'
37
+ ] as const;
38
+
39
+ function asObject(value: unknown): Record<string, unknown> {
40
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
41
+ return {};
42
+ }
43
+ return value as Record<string, unknown>;
44
+ }
45
+
46
+ function requiredString(input: Record<string, unknown>, key: string): string {
47
+ const value = input[key];
48
+ if (typeof value !== 'string' || value.length === 0) {
49
+ throw new Error(`Missing or invalid "${key}"`);
50
+ }
51
+ return value;
52
+ }
53
+
54
+ function optionalSessionId(input: Record<string, unknown>): string | undefined {
55
+ const value = input.sessionId;
56
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
57
+ }
58
+
59
+ function omitSessionId(input: Record<string, unknown>): Record<string, unknown> {
60
+ const { sessionId: _sessionId, ...rest } = input;
61
+ return rest;
62
+ }
63
+
64
+ export async function handleStdioRequest(tool: RSToolAgent, request: StdioRequest): Promise<StdioResponse> {
65
+ try {
66
+ const params = asObject(request.params);
67
+ switch (request.method) {
68
+ case 'ping':
69
+ return { id: request.id, ok: true, result: { pong: true, contractVersion: tool.contractVersion } };
70
+ case 'methods':
71
+ return { id: request.id, ok: true, result: STDIO_METHODS };
72
+ case 'ensureSession':
73
+ return {
74
+ id: request.id,
75
+ ok: true,
76
+ result: tool.ensureSession(params.initial as never)
77
+ };
78
+ case 'createSession':
79
+ return {
80
+ id: request.id,
81
+ ok: true,
82
+ result: tool.createSession(params.initial as never)
83
+ };
84
+ case 'getCurrentSession':
85
+ return {
86
+ id: request.id,
87
+ ok: true,
88
+ result: tool.getCurrentSession()
89
+ };
90
+ case 'setCurrentSession':
91
+ return {
92
+ id: request.id,
93
+ ok: true,
94
+ result: tool.setCurrentSession(requiredString(params, 'sessionId'))
95
+ };
96
+ case 'applySchemaPatch':
97
+ return {
98
+ id: request.id,
99
+ ok: true,
100
+ result: tool.applySchemaPatch(omitSessionId(params) as never, optionalSessionId(params))
101
+ };
102
+ case 'getSessionState':
103
+ return {
104
+ id: request.id,
105
+ ok: true,
106
+ result: tool.getSessionState(
107
+ (params.detail as 'summary' | 'full' | undefined) ?? 'summary',
108
+ optionalSessionId(params)
109
+ )
110
+ };
111
+ case 'listDiagnostics': {
112
+ const constituentId = params.constituentId;
113
+ const filters = typeof constituentId === 'number' ? { constituentId } : (params.filters as never);
114
+ return {
115
+ id: request.id,
116
+ ok: true,
117
+ result: tool.listDiagnostics(filters, optionalSessionId(params))
118
+ };
119
+ }
120
+ case 'analyzeExpression':
121
+ return {
122
+ id: request.id,
123
+ ok: true,
124
+ result: tool.analyzeExpression(omitSessionId(params) as never, optionalSessionId(params))
125
+ };
126
+ case 'commitStep':
127
+ return {
128
+ id: request.id,
129
+ ok: true,
130
+ result: tool.commitStep(params.message as string | undefined, optionalSessionId(params))
131
+ };
132
+ case 'exportSession':
133
+ return {
134
+ id: request.id,
135
+ ok: true,
136
+ result: tool.exportSession(optionalSessionId(params))
137
+ };
138
+ case 'exportPortal':
139
+ return {
140
+ id: request.id,
141
+ ok: true,
142
+ result: tool.exportPortal(omitSessionId(params) as never, optionalSessionId(params))
143
+ };
144
+ case 'importData':
145
+ return {
146
+ id: request.id,
147
+ ok: true,
148
+ result: tool.importData(params.payload as string | object, params.kind as never)
149
+ };
150
+ case 'setModelValues':
151
+ return {
152
+ id: request.id,
153
+ ok: true,
154
+ result: await tool.setModelValues(omitSessionId(params) as never, optionalSessionId(params))
155
+ };
156
+ case 'getModelState':
157
+ return {
158
+ id: request.id,
159
+ ok: true,
160
+ result: tool.getModelState(optionalSessionId(params))
161
+ };
162
+ case 'evaluate':
163
+ return {
164
+ id: request.id,
165
+ ok: true,
166
+ result: tool.evaluate(omitSessionId(params) as never, optionalSessionId(params))
167
+ };
168
+ case 'recalculateModel':
169
+ return {
170
+ id: request.id,
171
+ ok: true,
172
+ result: tool.recalculateModel(optionalSessionId(params))
173
+ };
174
+ default:
175
+ return {
176
+ id: request.id ?? null,
177
+ ok: false,
178
+ error: {
179
+ code: 'METHOD_NOT_FOUND',
180
+ message: `Unknown method: ${request.method}`
181
+ }
182
+ };
183
+ }
184
+ } catch (error) {
185
+ return {
186
+ id: request.id ?? null,
187
+ ok: false,
188
+ error: {
189
+ code: 'INTERNAL_ERROR',
190
+ message: error instanceof Error ? error.message : 'Unknown error',
191
+ details: error
192
+ }
193
+ };
194
+ }
195
+ }
@@ -2,45 +2,10 @@
2
2
  import readline from 'node:readline';
3
3
 
4
4
  import { RSToolAgent } from '../models/rstool-agent';
5
+ import { handleStdioRequest, type StdioRequest, type StdioResponse } from './stdio-handler';
5
6
 
6
- interface StdioRequest {
7
- id: string | number;
8
- method: string;
9
- params?: unknown;
10
- }
11
-
12
- interface StdioResponse {
13
- id: string | number | null;
14
- ok: boolean;
15
- result?: unknown;
16
- error?: {
17
- code: string;
18
- message: string;
19
- details?: unknown;
20
- };
21
- }
22
-
23
- const tool = new RSToolAgent();
24
-
25
- const METHODS = [
26
- 'createSession',
27
- 'addOrUpdateConstituenta',
28
- 'analyzeExpression',
29
- 'getFormState',
30
- 'listDiagnostics',
31
- 'commitStep',
32
- 'exportSession',
33
- 'exportPortalSchema',
34
- 'exportPortalModel',
35
- 'importSession',
36
- 'setConstituentaValue',
37
- 'setConstituentaValues',
38
- 'clearConstituentaValues',
39
- 'getModelState',
40
- 'evaluateExpression',
41
- 'evaluateConstituenta',
42
- 'recalculateModel'
43
- ] as const;
7
+ const persistenceDir = process.env.RSTOOL_PERSISTENCE_DIR;
8
+ const tool = new RSToolAgent(persistenceDir ? { persistenceDir } : {});
44
9
 
45
10
  function writeResponse(response: StdioResponse): void {
46
11
  if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) {
@@ -53,154 +18,6 @@ function writeResponse(response: StdioResponse): void {
53
18
  }
54
19
  }
55
20
 
56
- function asObject(value: unknown): Record<string, unknown> {
57
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
58
- return {};
59
- }
60
- return value as Record<string, unknown>;
61
- }
62
-
63
- function requiredString(input: Record<string, unknown>, key: string): string {
64
- const value = input[key];
65
- if (typeof value !== 'string' || value.length === 0) {
66
- throw new Error(`Missing or invalid "${key}"`);
67
- }
68
- return value;
69
- }
70
-
71
- async function handleRequest(request: StdioRequest): Promise<StdioResponse> {
72
- try {
73
- const params = asObject(request.params);
74
- switch (request.method) {
75
- case 'ping':
76
- return { id: request.id, ok: true, result: { pong: true } };
77
- case 'methods':
78
- return { id: request.id, ok: true, result: METHODS };
79
- case 'createSession':
80
- return {
81
- id: request.id,
82
- ok: true,
83
- result: tool.createSession(params.initial as never)
84
- };
85
- case 'addOrUpdateConstituenta':
86
- return {
87
- id: request.id,
88
- ok: true,
89
- result: tool.addOrUpdateConstituenta(requiredString(params, 'sessionId'), params.input as never)
90
- };
91
- case 'analyzeExpression':
92
- return {
93
- id: request.id,
94
- ok: true,
95
- result: tool.analyzeExpression(requiredString(params, 'sessionId'), params.input as never)
96
- };
97
- case 'getFormState':
98
- return {
99
- id: request.id,
100
- ok: true,
101
- result: tool.getFormState(requiredString(params, 'sessionId'))
102
- };
103
- case 'listDiagnostics':
104
- return {
105
- id: request.id,
106
- ok: true,
107
- result: tool.listDiagnostics(requiredString(params, 'sessionId'), params.filters as never)
108
- };
109
- case 'commitStep':
110
- return {
111
- id: request.id,
112
- ok: true,
113
- result: tool.commitStep(requiredString(params, 'sessionId'), params.message as string | undefined)
114
- };
115
- case 'exportSession':
116
- return {
117
- id: request.id,
118
- ok: true,
119
- result: tool.exportSession(requiredString(params, 'sessionId'))
120
- };
121
- case 'exportPortalSchema':
122
- return {
123
- id: request.id,
124
- ok: true,
125
- result: tool.exportPortalSchema(requiredString(params, 'sessionId'))
126
- };
127
- case 'exportPortalModel':
128
- return {
129
- id: request.id,
130
- ok: true,
131
- result: tool.exportPortalModel(requiredString(params, 'sessionId'))
132
- };
133
- case 'importSession':
134
- return {
135
- id: request.id,
136
- ok: true,
137
- result: tool.importSession(requiredString(params, 'payload'))
138
- };
139
- case 'setConstituentaValue':
140
- return {
141
- id: request.id,
142
- ok: true,
143
- result: await tool.setConstituentaValue(requiredString(params, 'sessionId'), params.input as never)
144
- };
145
- case 'setConstituentaValues':
146
- return {
147
- id: request.id,
148
- ok: true,
149
- result: await tool.setConstituentaValues(requiredString(params, 'sessionId'), params.input as never)
150
- };
151
- case 'clearConstituentaValues':
152
- return {
153
- id: request.id,
154
- ok: true,
155
- result: await tool.clearConstituentaValues(requiredString(params, 'sessionId'), params.input as never)
156
- };
157
- case 'getModelState':
158
- return {
159
- id: request.id,
160
- ok: true,
161
- result: tool.getModelState(requiredString(params, 'sessionId'))
162
- };
163
- case 'evaluateExpression':
164
- return {
165
- id: request.id,
166
- ok: true,
167
- result: tool.evaluateExpression(requiredString(params, 'sessionId'), params.input as never)
168
- };
169
- case 'evaluateConstituenta':
170
- return {
171
- id: request.id,
172
- ok: true,
173
- result: tool.evaluateConstituenta(requiredString(params, 'sessionId'), params.input as never)
174
- };
175
- case 'recalculateModel':
176
- return {
177
- id: request.id,
178
- ok: true,
179
- result: tool.recalculateModel(requiredString(params, 'sessionId'))
180
- };
181
- default:
182
- return {
183
- id: request.id ?? null,
184
- ok: false,
185
- error: {
186
- code: 'METHOD_NOT_FOUND',
187
- message: `Unknown method: ${request.method}`
188
- }
189
- };
190
- }
191
- } catch (error) {
192
- return {
193
- id: request.id ?? null,
194
- ok: false,
195
- error: {
196
- code: 'INTERNAL_ERROR',
197
- message: error instanceof Error ? error.message : 'Unknown error',
198
- details: error
199
- }
200
- };
201
- }
202
- }
203
-
204
21
  const input = readline.createInterface({
205
22
  input: process.stdin,
206
23
  crlfDelay: Infinity
@@ -225,7 +42,7 @@ input.on('line', line => {
225
42
  if (!('id' in request) || !('method' in request)) {
226
43
  throw new Error('Request must include "id" and "method"');
227
44
  }
228
- void handleRequest(request).then(writeResponse);
45
+ void handleStdioRequest(tool, request).then(writeResponse);
229
46
  } catch (error) {
230
47
  writeResponse({
231
48
  id: null,
@@ -1,16 +0,0 @@
1
- import { a as RSToolErrorDescription, n as CstType, s as ValueClass } from "./common-DxLg3eXX.js";
2
-
3
- //#region src/models/analysis.d.ts
4
- interface AnalyzeExpressionInput {
5
- expression: string;
6
- cstType: CstType;
7
- }
8
- interface AnalysisResult {
9
- success: boolean;
10
- type: Record<string, unknown> | null;
11
- valueClass: ValueClass | null;
12
- diagnostics: RSToolErrorDescription[];
13
- }
14
- //#endregion
15
- export { AnalyzeExpressionInput as n, AnalysisResult as t };
16
- //# sourceMappingURL=analysis-JiwOYDKx.d.ts.map
@@ -1,36 +0,0 @@
1
- import { n as CstType } from "./common-DxLg3eXX.js";
2
- import { t as AnalysisResult } from "./analysis-JiwOYDKx.js";
3
- import { t as DiagnosticRecord } from "./diagnostic-BMYvciz8.js";
4
-
5
- //#region src/models/constituenta.d.ts
6
- interface ConstituentaDraft {
7
- id: number;
8
- /** Alias */
9
- alias: string;
10
- /** CST type */
11
- cstType: CstType;
12
- /** Formal definition */
13
- definitionFormal: string;
14
- /** Natural-language term */
15
- term?: string;
16
- /** Natural-language definition */
17
- definitionText?: string;
18
- /** Convention or comment */
19
- convention?: string;
20
- }
21
- interface ConstituentaState extends Omit<ConstituentaDraft, 'term' | 'definitionText' | 'convention'> {
22
- term: string;
23
- definitionText: string;
24
- convention: string;
25
- analysis: AnalysisResult;
26
- }
27
- interface AddOrUpdateConstituentaInput {
28
- draft: ConstituentaDraft;
29
- }
30
- interface AddOrUpdateConstituentaResult {
31
- state: ConstituentaState;
32
- diagnostics: DiagnosticRecord[];
33
- }
34
- //#endregion
35
- export { ConstituentaState as i, AddOrUpdateConstituentaResult as n, ConstituentaDraft as r, AddOrUpdateConstituentaInput as t };
36
- //# sourceMappingURL=constituenta-Dnd6iToB.d.ts.map
@@ -1,15 +0,0 @@
1
- import { a as RSToolErrorDescription } from "./common-DxLg3eXX.js";
2
-
3
- //#region src/models/diagnostic.d.ts
4
- interface DiagnosticRecord {
5
- sessionId: string;
6
- constituentId?: number;
7
- expression: string;
8
- error: RSToolErrorDescription;
9
- }
10
- interface ListDiagnosticsFilters {
11
- constituentId?: number;
12
- }
13
- //#endregion
14
- export { ListDiagnosticsFilters as n, DiagnosticRecord as t };
15
- //# sourceMappingURL=diagnostic-BMYvciz8.d.ts.map
@@ -1,21 +0,0 @@
1
- import { a as RSToolErrorDescription, n as CstType, o as RSToolValue, r as EvalStatus, t as BasicBinding } from "./common-DxLg3eXX.js";
2
-
3
- //#region src/models/evaluation.d.ts
4
- interface EvaluateExpressionInput {
5
- expression: string;
6
- cstType: CstType;
7
- }
8
- interface EvaluateConstituentaInput {
9
- constituentId: number;
10
- }
11
- interface EvaluationResult {
12
- success: boolean;
13
- value: RSToolValue | BasicBinding | null;
14
- status: EvalStatus;
15
- iterations: number;
16
- cacheHits: number;
17
- diagnostics: RSToolErrorDescription[];
18
- }
19
- //#endregion
20
- export { EvaluateExpressionInput as n, EvaluationResult as r, EvaluateConstituentaInput as t };
21
- //# sourceMappingURL=evaluation-CCVYH0wA.d.ts.map