@rsconcept/rstool 0.6.0 → 0.7.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.
@@ -1 +1 @@
1
- {"version":3,"file":"model-adapter.js","names":[],"sources":["../../src/mappers/model-adapter.ts"],"sourcesContent":["import { Graph } from '@rsconcept/domain/graph/graph';\nimport { extractGlobals } from '@rsconcept/domain/rslang/api';\nimport { type ExpressionType, RSLangAnalyzer, type Value, type ValueClass } from '@rsconcept/domain/rslang';\nimport { isBaseSet } from '@rsconcept/domain/library/rsform-api';\nimport { type Constituenta, CstType, type RSForm } from '@rsconcept/domain/library/rsform';\nimport { RSEngine, type RSEngineServices } from '@rsconcept/domain/library/rsengine';\nimport { type BasicBinding, EvalStatus, type RSModel } from '@rsconcept/domain/library/rsmodel';\nimport {\n isInferrable,\n isInterpretable,\n toBasicBinding,\n validateBasicBindingData,\n validateValueData\n} from '@rsconcept/domain/library/rsmodel-api';\n\nimport {\n type ConstituentaState,\n type EvaluationResult,\n type RecalculateModelResult,\n type SessionModelState,\n type SessionState,\n type SetConstituentaValueInput\n} from '../models';\nimport { toPublicError } from './types';\n\nconst SESSION_MODEL_ID = 0;\n\nexport class ModelAdapter {\n public async setConstituentaValue(\n session: SessionState,\n input: SetConstituentaValueInput\n ): Promise<SessionModelState> {\n this.validateSetInput(session, input);\n const engine = this.createEngine(session);\n const cst = session.items.find(item => item.id === input.target)!;\n const frontendType = cst.cstType;\n\n if (isBaseSet(frontendType)) {\n const binding = toBasicBinding(input.value as Record<string | number, string>);\n await engine.setBasicValue(input.target, binding);\n } else {\n await engine.setStructureValue(input.target, input.value as Value);\n }\n session.updatedAt = new Date().toISOString();\n return structuredClone(session.model);\n }\n\n public async setConstituentaValues(\n session: SessionState,\n input: { items: SetConstituentaValueInput[] }\n ): Promise<SessionModelState> {\n for (const item of input.items) {\n await this.setConstituentaValue(session, item);\n }\n return structuredClone(session.model);\n }\n\n public async clearConstituentaValues(session: SessionState, ids: number[]): Promise<SessionModelState> {\n const engine = this.createEngine(session);\n for (const id of ids) {\n await engine.resetValue(id);\n session.updatedAt = new Date().toISOString();\n }\n return structuredClone(session.model);\n }\n\n public evaluateExpression(session: SessionState, expression: string, cstType: CstType): EvaluationResult {\n const engine = this.createEngine(session);\n const result = engine.evaluateExpression(expression, cstType);\n const status =\n result.value === null\n ? result.errors.length > 0\n ? EvalStatus.EVAL_FAIL\n : EvalStatus.EMPTY\n : EvalStatus.HAS_DATA;\n return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);\n }\n\n public evaluateConstituenta(session: SessionState, constituentId: number): EvaluationResult {\n const cst = session.items.find(item => item.id === constituentId);\n if (!cst) {\n throw new Error(`Unknown constituent: ${constituentId}`);\n }\n const engine = this.createEngine(session);\n const result = engine.calculateCst(constituentId);\n const status = engine.getCstStatus(constituentId);\n return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);\n }\n\n public recalculateModel(session: SessionState): RecalculateModelResult {\n const engine = this.createEngine(session);\n engine.recalculateAll();\n const items = session.items.map(item => ({\n id: item.id,\n alias: item.alias,\n value: engine.getCstValue(item.id) as number | number[] | null,\n status: engine.getCstStatus(item.id)\n }));\n return { items };\n }\n\n public createEngine(session: SessionState): RSEngine {\n const schema = buildRSFormFromSession(session);\n const model = buildRSModelFromSession(session);\n const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));\n engine.loadData(schema, model);\n return engine;\n }\n\n private validateSetInput(session: SessionState, input: SetConstituentaValueInput): void {\n const cst = session.items.find(item => item.id === input.target);\n if (!cst) {\n throw new Error(`Unknown constituent: ${input.target}`);\n }\n const frontendType = cst.cstType;\n if (!isInterpretable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is not interpretable`);\n }\n if (isInferrable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);\n }\n if (isBaseSet(frontendType)) {\n if (!validateBasicBindingData(input.value)) {\n throw new Error(`Invalid basic binding for ${cst.alias}`);\n }\n return;\n }\n if (!validateValueData(input.value)) {\n throw new Error(`Invalid structured value for ${cst.alias}`);\n }\n }\n}\n\nfunction createInMemoryServices(session: SessionState): RSEngineServices {\n return {\n setCstValue: async ({ data }) => {\n for (const item of data) {\n const entry = {\n id: item.target,\n type: item.type,\n value: item.data as Value | BasicBinding\n };\n const index = session.model.items.findIndex(existing => existing.id === item.target);\n if (index === -1) {\n session.model.items.push(entry);\n } else {\n session.model.items[index] = entry;\n }\n }\n },\n clearValues: async ({ data }) => {\n const ids = new Set(data.items);\n session.model.items = session.model.items.filter(item => !ids.has(item.id));\n }\n };\n}\n\nfunction buildRSFormFromSession(session: SessionState): RSForm {\n const graph = new Graph<number>();\n const cstByAlias = new Map<string, Constituenta>();\n const cstByID = new Map<number, Constituenta>();\n const analyzer = new RSLangAnalyzer();\n\n const items = session.items.map(item => {\n const cst = toFrontendConstituenta(item);\n cstByAlias.set(cst.alias, cst);\n cstByID.set(cst.id, cst);\n graph.addNode(cst.id);\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(cst.alias);\n }\n if (cst.effectiveType) {\n analyzer.setGlobal(cst.alias, cst.effectiveType, cst.analysis.valueClass as ValueClass | null);\n }\n return cst;\n });\n\n for (const cst of items) {\n for (const alias of extractGlobals(cst.definition_formal)) {\n const source = cstByAlias.get(alias);\n if (source) {\n graph.addEdge(source.id, cst.id);\n }\n }\n }\n\n return {\n id: 0,\n items,\n cstByAlias,\n cstByID,\n graph,\n analyzer,\n inheritance: [],\n attribution: [],\n attribution_graph: graph.clone(),\n oss: [],\n models: [],\n editors: [],\n versions: [],\n is_produced: false,\n is_attributive: false,\n version: 'latest'\n } as unknown as RSForm;\n}\n\nfunction buildRSModelFromSession(session: SessionState): RSModel {\n return {\n id: SESSION_MODEL_ID,\n schema: 0,\n editors: [],\n items: session.model.items.map(item => ({\n id: item.id,\n type: item.type,\n value: item.value as Value | BasicBinding\n }))\n } as unknown as RSModel;\n}\n\nfunction toFrontendConstituenta(item: ConstituentaState): Constituenta {\n const effectiveType = (item.analysis.type ?? null) as ExpressionType | null;\n return {\n id: item.id,\n alias: item.alias,\n cst_type: item.cstType,\n definition_formal: item.definitionFormal,\n definition_raw: item.definitionFormal,\n definition_resolved: item.definitionFormal,\n term_raw: item.term,\n term_resolved: item.term,\n term_forms: [],\n convention: item.convention,\n typification_manual: '',\n value_is_property: false,\n crucial: false,\n attributes: [],\n homonyms: [],\n formalDuplicates: [],\n analysis: {\n success: item.analysis.success,\n type: effectiveType,\n valueClass: item.analysis.valueClass\n },\n effectiveType,\n is_type_mismatch: false,\n schema: 0,\n cst_class: 'derived',\n status: item.analysis.success ? 'verified' : 'incorrect',\n is_template: false,\n is_simple_expression: true,\n parent_schema_index: 0,\n parent_schema: null,\n is_inherited: false,\n has_inherited_children: false,\n spawn: [],\n spawn_alias: []\n } as unknown as Constituenta;\n}\n\nfunction toPublicEvaluationResult(\n value: Value | null,\n errors: { code: number; from: number; to: number; params?: readonly string[] }[],\n iterations: number,\n cacheHits: number,\n status: EvalStatus\n): EvaluationResult {\n const diagnostics = errors.map(toPublicError);\n return {\n success: diagnostics.length === 0 && value !== null,\n value: value as EvaluationResult['value'],\n status,\n iterations,\n cacheHits,\n diagnostics\n };\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,mBAAmB;AAEzB,IAAa,eAAb,MAA0B;CACxB,MAAa,qBACX,SACA,OAC4B;EAC5B,KAAK,iBAAiB,SAAS,KAAK;EACpC,MAAM,SAAS,KAAK,aAAa,OAAO;EAExC,MAAM,eADM,QAAQ,MAAM,MAAK,SAAQ,KAAK,OAAO,MAAM,MACpC,EAAI;EAEzB,IAAI,UAAU,YAAY,GAAG;GAC3B,MAAM,UAAU,eAAe,MAAM,KAAwC;GAC7E,MAAM,OAAO,cAAc,MAAM,QAAQ,OAAO;EAClD,OACE,MAAM,OAAO,kBAAkB,MAAM,QAAQ,MAAM,KAAc;EAEnE,QAAQ,6BAAY,IAAI,KAAK,GAA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E,MAAM,gBAAiB,KAAK,SAAS,QAAQ;CAC7C,OAAO;EACL,IAAI,KAAK;EACT,OAAO,KAAK;EACZ,UAAU,KAAK;EACf,mBAAmB,KAAK;EACxB,gBAAgB,KAAK;EACrB,qBAAqB,KAAK;EAC1B,UAAU,KAAK;EACf,eAAe,KAAK;EACpB,YAAY,CAAC;EACb,YAAY,KAAK;EACjB,qBAAqB;EACrB,mBAAmB;EACnB,SAAS;EACT,YAAY,CAAC;EACb,UAAU,CAAC;EACX,kBAAkB,CAAC;EACnB,UAAU;GACR,SAAS,KAAK,SAAS;GACvB,MAAM;GACN,YAAY,KAAK,SAAS;EAC5B;EACA;EACA,kBAAkB;EAClB,QAAQ;EACR,WAAW;EACX,QAAQ,KAAK,SAAS,UAAU,aAAa;EAC7C,aAAa;EACb,sBAAsB;EACtB,qBAAqB;EACrB,eAAe;EACf,cAAc;EACd,wBAAwB;EACxB,OAAO,CAAC;EACR,aAAa,CAAC;CAChB;AACF;AAEA,SAAS,yBACP,OACA,QACA,YACA,WACA,QACkB;CAClB,MAAM,cAAc,OAAO,IAAI,aAAa;CAC5C,OAAO;EACL,SAAS,YAAY,WAAW,KAAK,UAAU;EACxC;EACP;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"model-adapter.js","names":[],"sources":["../../src/mappers/model-adapter.ts"],"sourcesContent":["import { Graph } from '@rsconcept/domain/graph/graph';\nimport { extractGlobals } from '@rsconcept/domain/rslang/api';\nimport { type ExpressionType, RSLangAnalyzer, type Value, type ValueClass } from '@rsconcept/domain/rslang';\nimport { isBaseSet } from '@rsconcept/domain/library/rsform-api';\nimport { type Constituenta, CstType, type RSForm } from '@rsconcept/domain/library/rsform';\nimport { RSEngine, type RSEngineServices } from '@rsconcept/domain/library/rsengine';\nimport { type BasicBinding, EvalStatus, type RSModel } from '@rsconcept/domain/library/rsmodel';\nimport {\n isInferrable,\n isInterpretable,\n toBasicBinding,\n validateBasicBindingData,\n validateValueData\n} from '@rsconcept/domain/library/rsmodel-api';\n\nimport {\n type ConstituentaState,\n type EvaluationResult,\n type RecalculateModelResult,\n type SessionModelState,\n type SessionState,\n type SetConstituentaValueInput\n} from '../models';\nimport { toPublicError } from './types';\n\nconst SESSION_MODEL_ID = 0;\n\nexport class ModelAdapter {\n public async setConstituentaValue(\n session: SessionState,\n input: SetConstituentaValueInput\n ): Promise<SessionModelState> {\n this.validateSetInput(session, input);\n const engine = this.createEngine(session);\n const cst = session.items.find(item => item.id === input.target)!;\n const frontendType = cst.cstType;\n\n if (isBaseSet(frontendType)) {\n const binding = toBasicBinding(input.value as Record<string | number, string>);\n await engine.setBasicValue(input.target, binding);\n } else {\n await engine.setStructureValue(input.target, input.value as Value);\n }\n session.updatedAt = new Date().toISOString();\n return structuredClone(session.model);\n }\n\n public async setConstituentaValues(\n session: SessionState,\n input: { items: SetConstituentaValueInput[] }\n ): Promise<SessionModelState> {\n for (const item of input.items) {\n await this.setConstituentaValue(session, item);\n }\n return structuredClone(session.model);\n }\n\n public async clearConstituentaValues(session: SessionState, ids: number[]): Promise<SessionModelState> {\n const engine = this.createEngine(session);\n for (const id of ids) {\n await engine.resetValue(id);\n session.updatedAt = new Date().toISOString();\n }\n return structuredClone(session.model);\n }\n\n public evaluateExpression(session: SessionState, expression: string, cstType: CstType): EvaluationResult {\n const engine = this.createEngine(session);\n const result = engine.evaluateExpression(expression, cstType);\n const status =\n result.value === null\n ? result.errors.length > 0\n ? EvalStatus.EVAL_FAIL\n : EvalStatus.EMPTY\n : EvalStatus.HAS_DATA;\n return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);\n }\n\n public evaluateConstituenta(session: SessionState, constituentId: number): EvaluationResult {\n const cst = session.items.find(item => item.id === constituentId);\n if (!cst) {\n throw new Error(`Unknown constituent: ${constituentId}`);\n }\n const engine = this.createEngine(session);\n const result = engine.calculateCst(constituentId);\n const status = engine.getCstStatus(constituentId);\n return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);\n }\n\n public recalculateModel(session: SessionState): RecalculateModelResult {\n const engine = this.createEngine(session);\n engine.recalculateAll();\n const items = session.items.map(item => ({\n id: item.id,\n alias: item.alias,\n value: engine.getCstValue(item.id) as number | number[] | null,\n status: engine.getCstStatus(item.id)\n }));\n return { items };\n }\n\n public createEngine(session: SessionState): RSEngine {\n const schema = buildRSFormFromSession(session);\n const model = buildRSModelFromSession(session);\n const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));\n engine.loadData(schema, model);\n return engine;\n }\n\n private validateSetInput(session: SessionState, input: SetConstituentaValueInput): void {\n const cst = session.items.find(item => item.id === input.target);\n if (!cst) {\n throw new Error(`Unknown constituent: ${input.target}`);\n }\n const frontendType = cst.cstType;\n if (!isInterpretable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is not interpretable`);\n }\n if (isInferrable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);\n }\n if (isBaseSet(frontendType)) {\n if (!validateBasicBindingData(input.value)) {\n throw new Error(`Invalid basic binding for ${cst.alias}`);\n }\n return;\n }\n if (!validateValueData(input.value)) {\n throw new Error(`Invalid structured value for ${cst.alias}`);\n }\n }\n}\n\nfunction createInMemoryServices(session: SessionState): RSEngineServices {\n return {\n setCstValue: async ({ data }) => {\n for (const item of data) {\n const entry = {\n id: item.target,\n type: item.type,\n value: item.data as Value | BasicBinding\n };\n const index = session.model.items.findIndex(existing => existing.id === item.target);\n if (index === -1) {\n session.model.items.push(entry);\n } else {\n session.model.items[index] = entry;\n }\n }\n },\n clearValues: async ({ data }) => {\n const ids = new Set(data.items);\n session.model.items = session.model.items.filter(item => !ids.has(item.id));\n }\n };\n}\n\nfunction buildRSFormFromSession(session: SessionState): RSForm {\n const graph = new Graph<number>();\n const cstByAlias = new Map<string, Constituenta>();\n const cstByID = new Map<number, Constituenta>();\n const analyzer = new RSLangAnalyzer();\n\n const items = session.items.map(item => {\n const cst = toFrontendConstituenta(item);\n cstByAlias.set(cst.alias, cst);\n cstByID.set(cst.id, cst);\n graph.addNode(cst.id);\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(cst.alias);\n }\n if (cst.effectiveType) {\n analyzer.setGlobal(cst.alias, cst.effectiveType, cst.analysis.valueClass as ValueClass | null);\n }\n return cst;\n });\n\n for (const cst of items) {\n for (const alias of extractGlobals(cst.definition_formal)) {\n const source = cstByAlias.get(alias);\n if (source) {\n graph.addEdge(source.id, cst.id);\n }\n }\n }\n\n return {\n id: 0,\n items,\n cstByAlias,\n cstByID,\n graph,\n analyzer,\n inheritance: [],\n attribution: [],\n attribution_graph: graph.clone(),\n oss: [],\n models: [],\n editors: [],\n versions: [],\n is_produced: false,\n is_attributive: false,\n version: 'latest'\n } as unknown as RSForm;\n}\n\nfunction buildRSModelFromSession(session: SessionState): RSModel {\n return {\n id: SESSION_MODEL_ID,\n schema: 0,\n editors: [],\n items: session.model.items.map(item => ({\n id: item.id,\n type: item.type,\n value: item.value as Value | BasicBinding\n }))\n } as unknown as RSModel;\n}\n\nfunction toFrontendConstituenta(item: ConstituentaState): Constituenta {\n const effectiveType = (item.analysis.type ?? null) as ExpressionType | null;\n return {\n id: item.id,\n alias: item.alias,\n cst_type: item.cstType,\n definition_formal: item.definitionFormal,\n definition_raw: item.definitionFormal,\n definition_resolved: item.definitionFormal,\n term_raw: item.term,\n term_resolved: item.term,\n term_forms: [],\n convention: item.convention,\n typification_manual: '',\n value_is_property: false,\n crucial: false,\n attributes: [],\n homonyms: [],\n formalDuplicates: [],\n analysis: {\n success: item.analysis.success,\n type: effectiveType,\n valueClass: item.analysis.valueClass\n },\n effectiveType,\n is_type_mismatch: false,\n schema: 0,\n cst_class: 'derived',\n status: item.analysis.success ? 'verified' : 'incorrect',\n is_template: false,\n is_simple_expression: true,\n parent_schema_index: 0,\n parent_schema: null,\n is_inherited: false,\n has_inherited_children: false,\n spawn: [],\n spawn_alias: []\n } as unknown as Constituenta;\n}\n\nfunction toPublicEvaluationResult(\n value: Value | null,\n errors: { code: number; from: number; to: number; params?: readonly string[] }[],\n iterations: number,\n cacheHits: number,\n status: EvalStatus\n): EvaluationResult {\n const diagnostics = errors.map(toPublicError);\n return {\n success: diagnostics.length === 0 && value !== null,\n value: value as EvaluationResult['value'],\n status,\n iterations,\n cacheHits,\n diagnostics\n };\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,mBAAmB;AAEzB,IAAa,eAAb,MAA0B;CACxB,MAAa,qBACX,SACA,OAC4B;EAC5B,KAAK,iBAAiB,SAAS,KAAK;EACpC,MAAM,SAAS,KAAK,aAAa,OAAO;EAExC,MAAM,eADM,QAAQ,MAAM,MAAK,SAAQ,KAAK,OAAO,MAAM,MACpC,CAAA,CAAI;EAEzB,IAAI,UAAU,YAAY,GAAG;GAC3B,MAAM,UAAU,eAAe,MAAM,KAAwC;GAC7E,MAAM,OAAO,cAAc,MAAM,QAAQ,OAAO;EAClD,OACE,MAAM,OAAO,kBAAkB,MAAM,QAAQ,MAAM,KAAc;EAEnE,QAAQ,6BAAY,IAAI,KAAK,EAAC,CAAC,YAAY;EAC3C,OAAO,gBAAgB,QAAQ,KAAK;CACtC;CAEA,MAAa,sBACX,SACA,OAC4B;EAC5B,KAAK,MAAM,QAAQ,MAAM,OACvB,MAAM,KAAK,qBAAqB,SAAS,IAAI;EAE/C,OAAO,gBAAgB,QAAQ,KAAK;CACtC;CAEA,MAAa,wBAAwB,SAAuB,KAA2C;EACrG,MAAM,SAAS,KAAK,aAAa,OAAO;EACxC,KAAK,MAAM,MAAM,KAAK;GACpB,MAAM,OAAO,WAAW,EAAE;GAC1B,QAAQ,6BAAY,IAAI,KAAK,EAAC,CAAC,YAAY;EAC7C;EACA,OAAO,gBAAgB,QAAQ,KAAK;CACtC;CAEA,mBAA0B,SAAuB,YAAoB,SAAoC;EAEvG,MAAM,SADS,KAAK,aAAa,OAClB,CAAA,CAAO,mBAAmB,YAAY,OAAO;EAC5D,MAAM,SACJ,OAAO,UAAU,OACb,OAAO,OAAO,SAAS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AAO,CAAC;EACR,aAAa,CAAC;CAChB;AACF;AAEA,SAAS,yBACP,OACA,QACA,YACA,WACA,QACkB;CAClB,MAAM,cAAc,OAAO,IAAI,aAAa;CAC5C,OAAO;EACL,SAAS,YAAY,WAAW,KAAK,UAAU;EACxC;EACP;EACA;EACA;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"schema-adapter.js","names":[],"sources":["../../src/mappers/schema-adapter.ts"],"sourcesContent":["import { RSLangAnalyzer, type AnalysisFull, type ValueClass } from '@rsconcept/domain/rslang';\nimport { getAnalysisFor } from '@rsconcept/domain/library/rsform-api';\nimport { CstType, type RSForm } from '@rsconcept/domain/library/rsform';\n\nimport {\n type AnalysisResult,\n type ConstituentaDraft,\n type ConstituentaState,\n type DiagnosticRecord,\n type SessionState\n} from '../models';\nimport { toPublicAnalysis, toPublicError } from './types';\n\nexport class SchemaAdapter {\n public analyzeAgainstSession(\n session: SessionState,\n draft: ConstituentaDraft\n ): { result: AnalysisResult; diagnostics: DiagnosticRecord[] } {\n const analyzer = this.buildAnalyzer(session);\n const schema = this.toPseudoRSFormState(session, analyzer);\n const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema as unknown as RSForm, draft.alias);\n const result = toPublicAnalysis({\n success: analysis.success,\n type: analysis.type as Record<string, unknown> | null,\n valueClass: analysis.valueClass,\n errors: analysis.errors\n });\n return {\n result,\n diagnostics: analysis.errors.map(error => ({\n sessionId: session.sessionId,\n constituentId: draft.id,\n expression: draft.definitionFormal,\n error: toPublicError(error)\n }))\n };\n }\n\n public mergeStateWithDraft(\n session: SessionState,\n draft: ConstituentaDraft,\n analysis: AnalysisResult\n ): ConstituentaState {\n const state: ConstituentaState = {\n ...draft,\n term: draft.term ?? '',\n definitionText: draft.definitionText ?? '',\n convention: draft.convention ?? '',\n analysis\n };\n const index = session.items.findIndex(item => item.id === draft.id);\n if (index === -1) {\n session.items.push(state);\n } else {\n session.items[index] = state;\n }\n session.updatedAt = new Date().toISOString();\n return state;\n }\n\n public toPseudoRSFormState(\n session: SessionState,\n analyzer: RSLangAnalyzer\n ): Pick<RSForm, 'items' | 'cstByAlias' | 'analyzer'> {\n const cstByAlias = new Map(session.items.map(item => [item.alias, item]));\n return {\n items: session.items as unknown as RSForm['items'],\n cstByAlias: cstByAlias as unknown as RSForm['cstByAlias'],\n analyzer\n };\n }\n\n private buildAnalyzer(session: SessionState): RSLangAnalyzer {\n const analyzer = new RSLangAnalyzer();\n for (const item of session.items) {\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(item.alias);\n }\n analyzer.setGlobal(\n item.alias,\n item.analysis.type as AnalysisFull['type'],\n item.analysis.valueClass as ValueClass | null\n );\n }\n return analyzer;\n }\n}\n"],"mappings":";;;;;AAaA,IAAa,gBAAb,MAA2B;CACzB,sBACE,SACA,OAC6D;EAC7D,MAAM,WAAW,KAAK,cAAc,OAAO;EAC3C,MAAM,SAAS,KAAK,oBAAoB,SAAS,QAAQ;EACzD,MAAM,WAAW,eAAe,MAAM,kBAAkB,MAAM,SAAS,QAA6B,MAAM,KAAK;EAO/G,OAAO;GACL,QAPa,iBAAiB;IAC9B,SAAS,SAAS;IAClB,MAAM,SAAS;IACf,YAAY,SAAS;IACrB,QAAQ,SAAS;GACnB,CAEE;GACA,aAAa,SAAS,OAAO,KAAI,WAAU;IACzC,WAAW,QAAQ;IACnB,eAAe,MAAM;IACrB,YAAY,MAAM;IAClB,OAAO,cAAc,KAAK;GAC5B,EAAE;EACJ;CACF;CAEA,oBACE,SACA,OACA,UACmB;EACnB,MAAM,QAA2B;GAC/B,GAAG;GACH,MAAM,MAAM,QAAQ;GACpB,gBAAgB,MAAM,kBAAkB;GACxC,YAAY,MAAM,cAAc;GAChC;EACF;EACA,MAAM,QAAQ,QAAQ,MAAM,WAAU,SAAQ,KAAK,OAAO,MAAM,EAAE;EAClE,IAAI,UAAU,IACZ,QAAQ,MAAM,KAAK,KAAK;OAExB,QAAQ,MAAM,SAAS;EAEzB,QAAQ,6BAAY,IAAI,KAAK,GAAE,YAAY;EAC3C,OAAO;CACT;CAEA,oBACE,SACA,UACmD;EACnD,MAAM,aAAa,IAAI,IAAI,QAAQ,MAAM,KAAI,SAAQ,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC;EACxE,OAAO;GACL,OAAO,QAAQ;GACH;GACZ;EACF;CACF;CAEA,cAAsB,SAAuC;EAC3D,MAAM,WAAW,IAAI,eAAe;EACpC,KAAK,MAAM,QAAQ,QAAQ,OAAO;GAChC,IAAI,KAAK,YAAY,QAAQ,MAC3B,SAAS,QAAQ,KAAK,KAAK;GAE7B,SAAS,UACP,KAAK,OACL,KAAK,SAAS,MACd,KAAK,SAAS,UAChB;EACF;EACA,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"schema-adapter.js","names":[],"sources":["../../src/mappers/schema-adapter.ts"],"sourcesContent":["import { RSLangAnalyzer, type AnalysisFull, type ValueClass } from '@rsconcept/domain/rslang';\nimport { getAnalysisFor } from '@rsconcept/domain/library/rsform-api';\nimport { CstType, type RSForm } from '@rsconcept/domain/library/rsform';\n\nimport {\n type AnalysisResult,\n type ConstituentaDraft,\n type ConstituentaState,\n type DiagnosticRecord,\n type SessionState\n} from '../models';\nimport { toPublicAnalysis, toPublicError } from './types';\n\nexport class SchemaAdapter {\n public analyzeAgainstSession(\n session: SessionState,\n draft: ConstituentaDraft\n ): { result: AnalysisResult; diagnostics: DiagnosticRecord[] } {\n const analyzer = this.buildAnalyzer(session);\n const schema = this.toPseudoRSFormState(session, analyzer);\n const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema as unknown as RSForm, draft.alias);\n const result = toPublicAnalysis({\n success: analysis.success,\n type: analysis.type as Record<string, unknown> | null,\n valueClass: analysis.valueClass,\n errors: analysis.errors\n });\n return {\n result,\n diagnostics: analysis.errors.map(error => ({\n sessionId: session.sessionId,\n constituentId: draft.id,\n expression: draft.definitionFormal,\n error: toPublicError(error)\n }))\n };\n }\n\n public mergeStateWithDraft(\n session: SessionState,\n draft: ConstituentaDraft,\n analysis: AnalysisResult\n ): ConstituentaState {\n const state: ConstituentaState = {\n ...draft,\n term: draft.term ?? '',\n definitionText: draft.definitionText ?? '',\n convention: draft.convention ?? '',\n analysis\n };\n const index = session.items.findIndex(item => item.id === draft.id);\n if (index === -1) {\n session.items.push(state);\n } else {\n session.items[index] = state;\n }\n session.updatedAt = new Date().toISOString();\n return state;\n }\n\n public toPseudoRSFormState(\n session: SessionState,\n analyzer: RSLangAnalyzer\n ): Pick<RSForm, 'items' | 'cstByAlias' | 'analyzer'> {\n const cstByAlias = new Map(session.items.map(item => [item.alias, item]));\n return {\n items: session.items as unknown as RSForm['items'],\n cstByAlias: cstByAlias as unknown as RSForm['cstByAlias'],\n analyzer\n };\n }\n\n private buildAnalyzer(session: SessionState): RSLangAnalyzer {\n const analyzer = new RSLangAnalyzer();\n for (const item of session.items) {\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(item.alias);\n }\n analyzer.setGlobal(\n item.alias,\n item.analysis.type as AnalysisFull['type'],\n item.analysis.valueClass as ValueClass | null\n );\n }\n return analyzer;\n }\n}\n"],"mappings":";;;;;AAaA,IAAa,gBAAb,MAA2B;CACzB,sBACE,SACA,OAC6D;EAC7D,MAAM,WAAW,KAAK,cAAc,OAAO;EAC3C,MAAM,SAAS,KAAK,oBAAoB,SAAS,QAAQ;EACzD,MAAM,WAAW,eAAe,MAAM,kBAAkB,MAAM,SAAS,QAA6B,MAAM,KAAK;EAO/G,OAAO;GACL,QAPa,iBAAiB;IAC9B,SAAS,SAAS;IAClB,MAAM,SAAS;IACf,YAAY,SAAS;IACrB,QAAQ,SAAS;GACnB,CAEE;GACA,aAAa,SAAS,OAAO,KAAI,WAAU;IACzC,WAAW,QAAQ;IACnB,eAAe,MAAM;IACrB,YAAY,MAAM;IAClB,OAAO,cAAc,KAAK;GAC5B,EAAE;EACJ;CACF;CAEA,oBACE,SACA,OACA,UACmB;EACnB,MAAM,QAA2B;GAC/B,GAAG;GACH,MAAM,MAAM,QAAQ;GACpB,gBAAgB,MAAM,kBAAkB;GACxC,YAAY,MAAM,cAAc;GAChC;EACF;EACA,MAAM,QAAQ,QAAQ,MAAM,WAAU,SAAQ,KAAK,OAAO,MAAM,EAAE;EAClE,IAAI,UAAU,IACZ,QAAQ,MAAM,KAAK,KAAK;OAExB,QAAQ,MAAM,SAAS;EAEzB,QAAQ,6BAAY,IAAI,KAAK,EAAC,CAAC,YAAY;EAC3C,OAAO;CACT;CAEA,oBACE,SACA,UACmD;EACnD,MAAM,aAAa,IAAI,IAAI,QAAQ,MAAM,KAAI,SAAQ,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC;EACxE,OAAO;GACL,OAAO,QAAQ;GACH;GACZ;EACF;CACF;CAEA,cAAsB,SAAuC;EAC3D,MAAM,WAAW,IAAI,eAAe;EACpC,KAAK,MAAM,QAAQ,QAAQ,OAAO;GAChC,IAAI,KAAK,YAAY,QAAQ,MAC3B,SAAS,QAAQ,KAAK,KAAK;GAE7B,SAAS,UACP,KAAK,OACL,KAAK,SAAS,MACd,KAAK,SAAS,UAChB;EACF;EACA,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"session-store.js","names":[],"sources":["../../src/session/session-store.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport {\n type DiagnosticRecord,\n type ListDiagnosticsFilters,\n type SessionHandle,\n type SessionRevision,\n type SessionState\n} from '../models';\n\ninterface SessionEnvelope {\n state: SessionState;\n diagnostics: DiagnosticRecord[];\n}\n\nexport class SessionStore {\n private sessions = new Map<string, SessionEnvelope>();\n\n public create(initial?: Partial<SessionState>, contractVersion?: string): SessionHandle {\n const now = new Date().toISOString();\n const sessionId = initial?.sessionId ?? randomUUID();\n const state: SessionState = {\n sessionId,\n alias: initial?.alias ?? '',\n title: initial?.title ?? '',\n comment: initial?.comment ?? '',\n createdAt: initial?.createdAt ?? now,\n updatedAt: now,\n revisions: initial?.revisions ?? [],\n items: initial?.items ?? [],\n model: initial?.model ?? { items: [] }\n };\n this.sessions.set(sessionId, {\n state,\n diagnostics: []\n });\n return {\n sessionId,\n contractVersion: contractVersion ?? '1.0.0'\n };\n }\n\n public get(sessionId: string): SessionEnvelope {\n const found = this.sessions.get(sessionId);\n if (!found) {\n throw new Error(`Unknown session: ${sessionId}`);\n }\n return found;\n }\n\n public replaceState(sessionId: string, nextState: SessionState): void {\n const found = this.get(sessionId);\n found.state = {\n ...nextState,\n updatedAt: new Date().toISOString()\n };\n }\n\n public addRevision(sessionId: string, message?: string): SessionRevision {\n const found = this.get(sessionId);\n const revision: SessionRevision = {\n revisionId: randomUUID(),\n at: new Date().toISOString(),\n message\n };\n found.state.revisions.push(revision);\n found.state.updatedAt = revision.at;\n return revision;\n }\n\n public appendDiagnostics(sessionId: string, records: DiagnosticRecord[]): void {\n const found = this.get(sessionId);\n found.diagnostics.push(...records);\n found.state.updatedAt = new Date().toISOString();\n }\n\n public listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[] {\n const found = this.get(sessionId);\n if (!filters?.constituentId) {\n return [...found.diagnostics];\n }\n return found.diagnostics.filter(record => record.constituentId === filters.constituentId);\n }\n}\n"],"mappings":";;AAeA,IAAa,eAAb,MAA0B;CACxB,2BAAmB,IAAI,IAA6B;CAEpD,OAAc,SAAiC,iBAAyC;EACtF,MAAM,uBAAM,IAAI,KAAK,GAAE,YAAY;EACnC,MAAM,YAAY,SAAS,aAAa,WAAW;EACnD,MAAM,QAAsB;GAC1B;GACA,OAAO,SAAS,SAAS;GACzB,OAAO,SAAS,SAAS;GACzB,SAAS,SAAS,WAAW;GAC7B,WAAW,SAAS,aAAa;GACjC,WAAW;GACX,WAAW,SAAS,aAAa,CAAC;GAClC,OAAO,SAAS,SAAS,CAAC;GAC1B,OAAO,SAAS,SAAS,EAAE,OAAO,CAAC,EAAE;EACvC;EACA,KAAK,SAAS,IAAI,WAAW;GAC3B;GACA,aAAa,CAAC;EAChB,CAAC;EACD,OAAO;GACL;GACA,iBAAiB,mBAAmB;EACtC;CACF;CAEA,IAAW,WAAoC;EAC7C,MAAM,QAAQ,KAAK,SAAS,IAAI,SAAS;EACzC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,oBAAoB,WAAW;EAEjD,OAAO;CACT;CAEA,aAAoB,WAAmB,WAA+B;EACpE,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,QAAQ;GACZ,GAAG;GACH,4BAAW,IAAI,KAAK,GAAE,YAAY;EACpC;CACF;CAEA,YAAmB,WAAmB,SAAmC;EACvE,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,WAA4B;GAChC,YAAY,WAAW;GACvB,qBAAI,IAAI,KAAK,GAAE,YAAY;GAC3B;EACF;EACA,MAAM,MAAM,UAAU,KAAK,QAAQ;EACnC,MAAM,MAAM,YAAY,SAAS;EACjC,OAAO;CACT;CAEA,kBAAyB,WAAmB,SAAmC;EAC7E,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,MAAM,YAAY,KAAK,GAAG,OAAO;EACjC,MAAM,MAAM,6BAAY,IAAI,KAAK,GAAE,YAAY;CACjD;CAEA,gBAAuB,WAAmB,SAAsD;EAC9F,MAAM,QAAQ,KAAK,IAAI,SAAS;EAChC,IAAI,CAAC,SAAS,eACZ,OAAO,CAAC,GAAG,MAAM,WAAW;EAE9B,OAAO,MAAM,YAAY,QAAO,WAAU,OAAO,kBAAkB,QAAQ,aAAa;CAC1F;AACF"}
1
+ {"version":3,"file":"session-store.js","names":[],"sources":["../../src/session/session-store.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport {\n type DiagnosticRecord,\n type ListDiagnosticsFilters,\n type SessionHandle,\n type SessionRevision,\n type SessionState\n} from '../models';\n\ninterface SessionEnvelope {\n state: SessionState;\n diagnostics: DiagnosticRecord[];\n}\n\nexport class SessionStore {\n private sessions = new Map<string, SessionEnvelope>();\n\n public create(initial?: Partial<SessionState>, contractVersion?: string): SessionHandle {\n const now = new Date().toISOString();\n const sessionId = initial?.sessionId ?? randomUUID();\n const state: SessionState = {\n sessionId,\n alias: initial?.alias ?? '',\n title: initial?.title ?? '',\n comment: initial?.comment ?? '',\n createdAt: initial?.createdAt ?? now,\n updatedAt: now,\n revisions: initial?.revisions ?? [],\n items: initial?.items ?? [],\n model: initial?.model ?? { items: [] }\n };\n this.sessions.set(sessionId, {\n state,\n diagnostics: []\n });\n return {\n sessionId,\n contractVersion: contractVersion ?? '1.0.0'\n };\n }\n\n public get(sessionId: string): SessionEnvelope {\n const found = this.sessions.get(sessionId);\n if (!found) {\n throw new Error(`Unknown session: ${sessionId}`);\n }\n return found;\n }\n\n public replaceState(sessionId: string, nextState: SessionState): void {\n const found = this.get(sessionId);\n found.state = {\n ...nextState,\n updatedAt: new Date().toISOString()\n };\n }\n\n public addRevision(sessionId: string, message?: string): SessionRevision {\n const found = this.get(sessionId);\n const revision: SessionRevision = {\n revisionId: randomUUID(),\n at: new Date().toISOString(),\n message\n };\n found.state.revisions.push(revision);\n found.state.updatedAt = revision.at;\n return revision;\n }\n\n public appendDiagnostics(sessionId: string, records: DiagnosticRecord[]): void {\n const found = this.get(sessionId);\n found.diagnostics.push(...records);\n found.state.updatedAt = new Date().toISOString();\n }\n\n public listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[] {\n const found = this.get(sessionId);\n if (!filters?.constituentId) {\n return [...found.diagnostics];\n }\n return found.diagnostics.filter(record => record.constituentId === filters.constituentId);\n }\n}\n"],"mappings":";;AAeA,IAAa,eAAb,MAA0B;CACxB,2BAAmB,IAAI,IAA6B;CAEpD,OAAc,SAAiC,iBAAyC;EACtF,MAAM,uBAAM,IAAI,KAAK,EAAC,CAAC,YAAY;EACnC,MAAM,YAAY,SAAS,aAAa,WAAW;EACnD,MAAM,QAAsB;GAC1B;GACA,OAAO,SAAS,SAAS;GACzB,OAAO,SAAS,SAAS;GACzB,SAAS,SAAS,WAAW;GAC7B,WAAW,SAAS,aAA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#!/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,OAAO,MAAM,GAAG,KAAK,UAAU,QAAQ,EAAE,GAAG;CACtD,QAAQ,CAER;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,eAAe,cAAc,SAA+C;CAC1E,IAAI;EACF,MAAM,SAAS,SAAS,QA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,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,EAAE,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-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,OAA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D;EACF,CAAC;CACH;AACF,CAAC"}
@@ -1,6 +1,8 @@
1
1
  # Portal REST API
2
2
 
3
- Справка только для чтения существующих КС, ОСС и RSModel. `rstool` сам не ходит в REST API: он работает с in-memory сессиями.
3
+ Справка для чтения существующих КС, ОСС и RSModel из Portal и переноса КС в `rstool`.
4
+ `rstool` сам не ходит в REST API: он работает с in-memory сессиями.
5
+ Агент получает JSON Portal отдельно, затем переносит конституенты через контракт `rstool`.
4
6
 
5
7
  ## Хосты
6
8
 
@@ -16,17 +18,93 @@
16
18
  - Модель → `GET /api/models/:id`.
17
19
  - OpenAPI JSON → `GET https://api.portal.acconcept.ru/schema`.
18
20
 
21
+ Для UI-ссылки `https://portal.acconcept.ru/rsforms/856` агент должен ходить на:
22
+
23
+ ```text
24
+ GET https://api.portal.acconcept.ru/api/rsforms/856
25
+ GET https://api.portal.acconcept.ru/api/rsforms/856/details
26
+ ```
27
+
28
+ Не переноси UI query/hash вроде `?tab=editor`.
29
+
30
+ ## Доступ
31
+
32
+ - `access_policy: "public"` читается без авторизации.
33
+ - Приватная схема или модель вернёт `403` и не предназначена для агентов.
34
+ - Если нужны только `title`, `alias`, `description`, `owner`, `access_policy`, не запрашивай `/details`.
35
+
36
+ ## Формат `GET /api/rsforms/:id/details`
37
+
38
+ Ответ содержит метаданные объекта библиотеки и массив `items[]` с конституентами.
39
+ Для анализа КС обычно нужны только корневые `title`, `alias`, `description` и поля каждой конституенты.
40
+
41
+ | Portal JSON | `rstool` | Примечание |
42
+ | --------------------- | ------------------------ | ----------------------------------------------------- |
43
+ | `id` | `draft.id` | Стабильный id внутри сессии |
44
+ | `alias` | `draft.alias` | `X1`, `C1`, `S1`, `D1`, `F1`, `P1`, `A1`, `T1` |
45
+ | `cst_type` | `draft.cstType` | Значения совпадают с `CstType` |
46
+ | `definition_formal` | `draft.definitionFormal` | Пустая строка допустима только для `basic`/`constant` |
47
+ | `term_raw` | `draft.term` | Для редактирования сохраняй raw, не resolved |
48
+ | `definition_raw` | `draft.definitionText` | Для редактирования сохраняй raw, не resolved |
49
+ | `convention` | `draft.convention` | Соглашение, не формальная проверка |
50
+ | `term_resolved` | не переносить | Только отображение после resolver |
51
+ | `definition_resolved` | не переносить | Только отображение после resolver |
52
+ | `typification_manual` | обычно не переносить | Переопределение типизации |
53
+ | `term_forms` | обычно не переносить | Словоформы термина |
54
+ | `crucial` | обычно не переносить | UI/Portal-флаг |
55
+ | `value_is_property` | обычно не переносить | Переопределение класса интерпретируемости |
56
+
57
+ `inheritance`, `attribution`, `oss`, `models`, `versions`, `editors` полезны для контекста Portal, но не нужны для базовой проверки RSLang в `rstool`.
58
+
19
59
  ## Как перенести КС в rstool
20
60
 
21
61
  1. Получи `GET /api/rsforms/:id/details`.
22
- 2. Создай `createSession`.
23
- 3. Перенеси конституенты через `addOrUpdateConstituenta`: `alias`, `cstType`, `definitionFormal`, `term`, `definitionText`, `convention`.
24
- 4. Работай локально: анализ, правки, вычисления.
25
- 5. Для передачи результата используй `exportSession`.
62
+ 2. Создай `createSession({ title, alias, comment: description })`.
63
+ 3. Иди по `items[]` в порядке ответа API.
64
+ 4. Для каждого элемента вызови `addOrUpdateConstituenta(sessionId, { draft })`.
65
+ 5. Проверь `listDiagnostics(sessionId)`.
66
+ 6. Работай локально: анализ, правки, вычисления, маленькая КМ.
67
+ 7. Для сохранения рабочей сессии используй `exportSession`.
68
+ 8. Для загрузки схемы обратно в Portal используй `exportPortalSchema`.
69
+
70
+ Portal JSON из `/details` **не является** форматом `exportSession` и не передаётся
71
+ в `importSession` напрямую. Его нужно перенести через `addOrUpdateConstituenta`
72
+ или через отдельный адаптер, если он появится в контракте.
73
+
74
+ Минимальный маппинг:
75
+
76
+ ```ts
77
+ const session = tool.createSession({
78
+ title: portal.title,
79
+ alias: portal.alias,
80
+ comment: portal.description
81
+ });
82
+
83
+ for (const item of portal.items) {
84
+ tool.addOrUpdateConstituenta(session.sessionId, {
85
+ draft: {
86
+ id: item.id,
87
+ alias: item.alias,
88
+ cstType: item.cst_type,
89
+ definitionFormal: item.definition_formal ?? '',
90
+ term: item.term_raw ?? '',
91
+ definitionText: item.definition_raw ?? '',
92
+ convention: item.convention ?? ''
93
+ }
94
+ });
95
+ }
96
+ ```
97
+
98
+ ## Практика для агентов
99
+
100
+ - Запрашивай API host, а не UI host: `https://api.portal.acconcept.ru/api/...`.
101
+ - Для больших схем используй увеличенный таймаут. В PowerShell вызывай `curl.exe`,
102
+ а не alias `curl` (`Invoke-WebRequest`), если нужен CLI-синтаксис curl.
103
+ - Сначала бери метаданные, если нужно только название или доступность схемы.
26
104
 
27
105
  ## Не делай
28
106
 
29
107
  - Не парси HTML SPA.
30
- - Не переноси UI query/hash вроде `?tab=editor` в REST.
31
108
  - Не запрашивай UI напрямую, используй преобразованные API запросы.
109
+ - Не передавай `/details` JSON в `importSession`.
32
110
  - Не запрашивай `/details`, если нужны только метаданные.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsconcept/rstool",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Agent-facing library for incremental RSForm construction, RSLang analysis, diagnostics, modeling, and evaluation. Wraps @rsconcept/domain with a deterministic session contract and stdio wrapper.",
5
5
  "license": "MIT",
6
6
  "author": "IRBorisov",
@@ -64,14 +64,14 @@
64
64
  "prepublishOnly": "npm run build"
65
65
  },
66
66
  "dependencies": {
67
- "@rsconcept/domain": "^1.0.0"
67
+ "@rsconcept/domain": "^1.2.0"
68
68
  },
69
69
  "devDependencies": {
70
- "@types/node": "^25.9.1",
71
- "tsdown": "^0.22.0",
72
- "tsx": "^4.21.0",
70
+ "@types/node": "^25.9.3",
71
+ "tsdown": "^0.22.2",
72
+ "tsx": "^4.22.4",
73
73
  "typescript": "^6.0.3",
74
- "vitest": "^4.1.5"
74
+ "vitest": "^4.1.9"
75
75
  },
76
76
  "publishConfig": {
77
77
  "access": "public"
@@ -46,6 +46,21 @@
46
46
  9. Сохрани: `exportSession` / `importSession`.
47
47
  10. Для загрузки в Portal: `exportPortalSchema` (схема) или `exportPortalModel` (модель).
48
48
 
49
+ ### Оценка или правка КС из Portal
50
+
51
+ Когда пользователь даёт UI-ссылку вида `https://portal.acconcept.ru/rsforms/:id`,
52
+ не открывай SPA и не парси HTML. Преобразуй ссылку в REST API по правилам
53
+ [PORTAL-API.md](../../docs/PORTAL-API.md): метаданные `GET /api/rsforms/:id`,
54
+ полная КС `GET /api/rsforms/:id/details`, версия `GET /api/library/:id/versions/:version`.
55
+
56
+ Portal JSON из `/details` не является форматом `exportSession` и не передаётся в
57
+ `importSession` напрямую. Создай `createSession({ title, alias, comment: description })`
58
+ и перенеси `items[]` через `addOrUpdateConstituenta`, сохраняя raw-поля:
59
+ `cst_type → cstType`, `definition_formal → definitionFormal`,
60
+ `term_raw → term`, `definition_raw → definitionText`, `convention → convention`.
61
+ После переноса запусти `listDiagnostics`; для результата в Portal используй
62
+ `exportPortalSchema`, а для локального снапшота — `exportSession`.
63
+
49
64
  ### Концептуализация (КС из содержания источника)
50
65
 
51
66
  Когда нужно построить или существенно развить КС по тексту ПО, требованиям или предметному описанию. Правила редукции, слоёв и паттернов — [CONCEPTUAL-SCHEMA.md](../../docs/CONCEPTUAL-SCHEMA.md).
@@ -186,6 +186,10 @@ interface AnalysisResult {
186
186
  - `state.model.items[]` — присутствует, если заданы значения интерпретации.
187
187
  - `diagnostics[]` — накопленные диагностики со смещениями и кодами.
188
188
 
189
+ `importSession(payload)` принимает только этот формат `exportSession`. JSON Portal из
190
+ `GET /api/rsforms/:id/details` сначала переноси в сессию через `createSession` и
191
+ `addOrUpdateConstituenta`; поля и REST-пути описаны в `docs/PORTAL-API.md`.
192
+
189
193
  ## JSON импорта Portal
190
194
 
191
195
  Для **Load from JSON** на существующей схеме или модели Portal: