@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
package/src/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Public API for `@rsconcept/rstool`.
|
|
3
|
+
*
|
|
4
|
+
* Primary entry points: {@link RSToolAgent} (in-process) and {@link RSToolWrapperClient}
|
|
5
|
+
* (stdio child process). Types describe the v2 agent contract.
|
|
6
|
+
*/
|
|
7
|
+
export { toPublicAnalysis, toPublicError, type DomainAnalysisLike, type DomainErrorLike } from './mappers/types';
|
|
7
8
|
export {
|
|
8
9
|
CONTRACT_VERSION,
|
|
9
10
|
CstType,
|
|
@@ -11,39 +12,45 @@ export {
|
|
|
11
12
|
RSErrorCode,
|
|
12
13
|
RSToolAgent,
|
|
13
14
|
ValueClass,
|
|
14
|
-
type
|
|
15
|
-
type AddOrUpdateConstituentaResult,
|
|
15
|
+
type AgentConstituentaPatch,
|
|
16
16
|
type AnalysisResult,
|
|
17
17
|
type AnalyzeExpressionInput,
|
|
18
|
+
type ApplySchemaPatchInput,
|
|
19
|
+
type ApplySchemaPatchResult,
|
|
18
20
|
type BasicBinding,
|
|
19
|
-
type ClearConstituentaValuesInput,
|
|
20
21
|
type ConstituentaDraft,
|
|
21
22
|
type ConstituentaState,
|
|
22
23
|
type DiagnosticRecord,
|
|
23
|
-
type
|
|
24
|
-
type EvaluateExpressionInput,
|
|
24
|
+
type EvaluateInput,
|
|
25
25
|
type EvaluationResult,
|
|
26
|
+
type ExportFormat,
|
|
27
|
+
type ExportPortalInput,
|
|
28
|
+
type ExportPortalResult,
|
|
29
|
+
type ImportDataKind,
|
|
26
30
|
type ListDiagnosticsFilters,
|
|
27
31
|
type ModelValueState,
|
|
28
32
|
PORTAL_JSON_CONTRACT_VERSION,
|
|
33
|
+
type PortalExportKind,
|
|
29
34
|
type PortalImportMetadata,
|
|
30
35
|
type PortalModelImportData,
|
|
36
|
+
type PortalRsformDetails,
|
|
31
37
|
type PortalSchemaConstituenta,
|
|
32
38
|
type PortalSchemaImportData,
|
|
33
39
|
type PortalTermForm,
|
|
34
40
|
type RecalculateModelResult,
|
|
35
41
|
type RSToolAgentContract,
|
|
42
|
+
type RSToolAgentOptions,
|
|
36
43
|
type RSToolErrorDescription,
|
|
37
44
|
type RSToolValue,
|
|
38
45
|
type SessionHandle,
|
|
39
46
|
type SessionModelState,
|
|
40
47
|
type SessionRevision,
|
|
48
|
+
type SessionStateDetail,
|
|
49
|
+
type SessionStateResult,
|
|
50
|
+
type SessionSummary,
|
|
51
|
+
type SessionSummaryItem,
|
|
41
52
|
type SessionState,
|
|
42
53
|
type SetConstituentaValueInput,
|
|
43
|
-
type
|
|
54
|
+
type SetModelValuesInput
|
|
44
55
|
} from './models';
|
|
45
|
-
export {
|
|
46
|
-
RSToolWrapperClient,
|
|
47
|
-
type RSToolWrapperClientOptions,
|
|
48
|
-
type WrapperResponse
|
|
49
|
-
} from './wrapper/client';
|
|
56
|
+
export { RSToolWrapperClient, type RSToolWrapperClientOptions, type WrapperResponse } from './wrapper/client';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ConstituentaDraft } from '../models/constituenta';
|
|
2
|
+
import {
|
|
3
|
+
type PortalImportMetadata,
|
|
4
|
+
type PortalRsformDetails,
|
|
5
|
+
type PortalSchemaImportData,
|
|
6
|
+
portalItemToDraft
|
|
7
|
+
} from '../models/portal-json';
|
|
8
|
+
import { type SessionState } from '../models/session';
|
|
9
|
+
|
|
10
|
+
type PortalSessionSeedInput = Partial<Pick<PortalImportMetadata, 'alias' | 'title' | 'description'>>;
|
|
11
|
+
|
|
12
|
+
function portalMetadataToSessionSeed(data: PortalSessionSeedInput): Partial<SessionState> {
|
|
13
|
+
return {
|
|
14
|
+
alias: data.alias ?? '',
|
|
15
|
+
title: data.title ?? '',
|
|
16
|
+
comment: data.description ?? '',
|
|
17
|
+
items: []
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function portalSchemaToSessionSeed(data: PortalSchemaImportData): Partial<SessionState> {
|
|
22
|
+
return portalMetadataToSessionSeed(data);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function portalDetailsToSessionSeed(data: PortalRsformDetails): Partial<SessionState> {
|
|
26
|
+
return portalMetadataToSessionSeed(data);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function portalItemsToDrafts(
|
|
30
|
+
items: Array<{
|
|
31
|
+
id: number;
|
|
32
|
+
alias: string;
|
|
33
|
+
cst_type: string;
|
|
34
|
+
definition_formal?: string;
|
|
35
|
+
term_raw?: string;
|
|
36
|
+
definition_raw?: string;
|
|
37
|
+
convention?: string;
|
|
38
|
+
}>
|
|
39
|
+
): ConstituentaDraft[] {
|
|
40
|
+
return items.map(item => portalItemToDraft(item));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function portalSchemaToDrafts(data: PortalSchemaImportData): ConstituentaDraft[] {
|
|
44
|
+
return portalItemsToDrafts(data.items);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function portalDetailsToDrafts(data: PortalRsformDetails): ConstituentaDraft[] {
|
|
48
|
+
return portalItemsToDrafts(data.items);
|
|
49
|
+
}
|
package/src/mappers/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type ValueClass } from '@rsconcept/domain/rslang';
|
|
|
2
2
|
|
|
3
3
|
import { type AnalysisResult, type RSToolErrorDescription } from '../models';
|
|
4
4
|
|
|
5
|
+
/** Minimal domain error shape before mapping to {@link RSToolErrorDescription}. */
|
|
5
6
|
export interface DomainErrorLike {
|
|
6
7
|
code: number;
|
|
7
8
|
from: number;
|
|
@@ -9,6 +10,7 @@ export interface DomainErrorLike {
|
|
|
9
10
|
params?: readonly string[];
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
/** Minimal domain analysis shape before mapping to {@link AnalysisResult}. */
|
|
12
14
|
export interface DomainAnalysisLike {
|
|
13
15
|
success: boolean;
|
|
14
16
|
type: Record<string, unknown> | null;
|
|
@@ -16,6 +18,7 @@ export interface DomainAnalysisLike {
|
|
|
16
18
|
errors: DomainErrorLike[];
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
/** Map a domain parser/semantic error to the public diagnostic shape. */
|
|
19
22
|
export function toPublicError(error: DomainErrorLike): RSToolErrorDescription {
|
|
20
23
|
return {
|
|
21
24
|
code: error.code,
|
|
@@ -25,6 +28,7 @@ export function toPublicError(error: DomainErrorLike): RSToolErrorDescription {
|
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
/** Map a domain analysis result to the public {@link AnalysisResult} shape. */
|
|
28
32
|
export function toPublicAnalysis(analysis: DomainAnalysisLike): AnalysisResult {
|
|
29
33
|
return {
|
|
30
34
|
success: analysis.success,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type CstType } from './common';
|
|
2
|
+
import { type ApplyConstituentsMode, type ApplyConstituentsResult, type ConstituentaDraft } from './constituenta';
|
|
3
|
+
import { type DiagnosticRecord } from './diagnostic';
|
|
4
|
+
import { type SessionHandle, type SessionRevision, type SessionState } from './session';
|
|
5
|
+
|
|
6
|
+
/** Level of detail returned by {@link RSToolAgent.getSessionState}. */
|
|
7
|
+
export type SessionStateDetail = 'summary' | 'full';
|
|
8
|
+
|
|
9
|
+
/** Result of `getSessionState`: compact summary or full cloned session state. */
|
|
10
|
+
export type SessionStateResult = SessionSummary | SessionState;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Partial constituent update used in {@link ApplySchemaPatchInput}.
|
|
14
|
+
*
|
|
15
|
+
* `alias` is required; other fields are merged with any existing constituent
|
|
16
|
+
* or inferred from the alias prefix when omitted.
|
|
17
|
+
*/
|
|
18
|
+
export interface AgentConstituentaPatch extends Omit<Partial<ConstituentaDraft>, 'alias'> {
|
|
19
|
+
alias: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Input for {@link RSToolAgent.applySchemaPatch}. */
|
|
23
|
+
export interface ApplySchemaPatchInput {
|
|
24
|
+
/** Metadata used only when a new session is created for this patch. */
|
|
25
|
+
initial?: {
|
|
26
|
+
alias?: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
comment?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Constituent patches to apply in dependency order. */
|
|
31
|
+
items: AgentConstituentaPatch[];
|
|
32
|
+
/** atomic: rollback on first failure; best_effort applies valid drafts. Default: atomic. */
|
|
33
|
+
mode?: ApplyConstituentsMode;
|
|
34
|
+
/** When set, a revision is recorded after a successful patch. */
|
|
35
|
+
commitMessage?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Compact view of one constituent in a session summary. */
|
|
39
|
+
export interface SessionSummaryItem {
|
|
40
|
+
id: number;
|
|
41
|
+
alias: string;
|
|
42
|
+
cstType: CstType;
|
|
43
|
+
analysisSuccess: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Compact session overview returned by default from `getSessionState`. */
|
|
47
|
+
export interface SessionSummary {
|
|
48
|
+
sessionId: string;
|
|
49
|
+
contractVersion: string;
|
|
50
|
+
alias: string;
|
|
51
|
+
title: string;
|
|
52
|
+
comment: string;
|
|
53
|
+
itemCount: number;
|
|
54
|
+
modelItemCount: number;
|
|
55
|
+
diagnosticsCount: number;
|
|
56
|
+
items: SessionSummaryItem[];
|
|
57
|
+
diagnostics: DiagnosticRecord[];
|
|
58
|
+
lastRevision?: SessionRevision;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Result of {@link RSToolAgent.applySchemaPatch}. */
|
|
62
|
+
export interface ApplySchemaPatchResult extends ApplyConstituentsResult {
|
|
63
|
+
session: SessionHandle;
|
|
64
|
+
summary: SessionSummary;
|
|
65
|
+
revision?: SessionRevision;
|
|
66
|
+
}
|
package/src/models/analysis.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { type CstType, type RSToolErrorDescription, type ValueClass } from './common';
|
|
2
2
|
|
|
3
|
+
/** Input for {@link RSToolAgent.analyzeExpression}. */
|
|
3
4
|
export interface AnalyzeExpressionInput {
|
|
5
|
+
/** RSLang expression to parse and type-check. */
|
|
4
6
|
expression: string;
|
|
7
|
+
/** Expected constituent type context for the expression. */
|
|
5
8
|
cstType: CstType;
|
|
9
|
+
/** When true, append diagnostics to the session log. Default: false. */
|
|
10
|
+
recordDiagnostics?: boolean;
|
|
6
11
|
}
|
|
7
12
|
|
|
13
|
+
/** Outcome of parsing and semantic analysis for one expression. */
|
|
8
14
|
export interface AnalysisResult {
|
|
9
15
|
success: boolean;
|
|
16
|
+
/** Inferred RS type AST as a plain object, or `null` on failure. */
|
|
10
17
|
type: Record<string, unknown> | null;
|
|
11
18
|
valueClass: ValueClass | null;
|
|
12
19
|
diagnostics: RSToolErrorDescription[];
|
package/src/models/common.ts
CHANGED
|
@@ -3,15 +3,22 @@ import { EvalStatus, type BasicBinding } from '@rsconcept/domain/library/rsmodel
|
|
|
3
3
|
import { ValueClass } from '@rsconcept/domain/rslang';
|
|
4
4
|
import { RSErrorCode } from '@rsconcept/domain/rslang/error';
|
|
5
5
|
|
|
6
|
+
/** Constituent type enum (X, D, C, …). Re-exported from `@rsconcept/domain`. */
|
|
6
7
|
export { CstType, EvalStatus, RSErrorCode, ValueClass };
|
|
8
|
+
/** Named binding used in model evaluation. Re-exported from `@rsconcept/domain`. */
|
|
7
9
|
export type { BasicBinding };
|
|
8
10
|
|
|
9
11
|
/** Runtime evaluation value: number, nested array (set/tuple), or boolean 0/1. */
|
|
10
12
|
export type RSToolValue = number | RSToolValue[];
|
|
11
13
|
|
|
14
|
+
/** Language or validation error with source span and optional format parameters. */
|
|
12
15
|
export interface RSToolErrorDescription {
|
|
16
|
+
/** Numeric error code (see {@link RSErrorCode}). */
|
|
13
17
|
code: number;
|
|
18
|
+
/** Start offset in the analyzed expression. */
|
|
14
19
|
from: number;
|
|
20
|
+
/** End offset in the analyzed expression. */
|
|
15
21
|
to: number;
|
|
22
|
+
/** Interpolation values for localized error messages. */
|
|
16
23
|
params?: readonly string[];
|
|
17
24
|
}
|
|
@@ -2,22 +2,24 @@ import { type AnalysisResult } from './analysis';
|
|
|
2
2
|
import { type CstType } from './common';
|
|
3
3
|
import { type DiagnosticRecord } from './diagnostic';
|
|
4
4
|
|
|
5
|
+
/** Constituent payload before analysis and merge into session state. */
|
|
5
6
|
export interface ConstituentaDraft {
|
|
6
7
|
id: number;
|
|
7
|
-
/**
|
|
8
|
+
/** Unique alias (e.g. `X1`, `D2`). */
|
|
8
9
|
alias: string;
|
|
9
|
-
/**
|
|
10
|
+
/** Constituent type. */
|
|
10
11
|
cstType: CstType;
|
|
11
|
-
/** Formal definition */
|
|
12
|
+
/** Formal RSLang definition. */
|
|
12
13
|
definitionFormal: string;
|
|
13
|
-
/** Natural-language term */
|
|
14
|
+
/** Natural-language term. */
|
|
14
15
|
term?: string;
|
|
15
|
-
/** Natural-language definition */
|
|
16
|
+
/** Natural-language definition. */
|
|
16
17
|
definitionText?: string;
|
|
17
|
-
/** Convention or comment */
|
|
18
|
+
/** Convention or comment. */
|
|
18
19
|
convention?: string;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
/** Constituent stored in session state after analysis. */
|
|
21
23
|
export interface ConstituentaState extends Omit<ConstituentaDraft, 'term' | 'definitionText' | 'convention'> {
|
|
22
24
|
term: string;
|
|
23
25
|
definitionText: string;
|
|
@@ -33,3 +35,19 @@ export interface AddOrUpdateConstituentaResult {
|
|
|
33
35
|
state: ConstituentaState;
|
|
34
36
|
diagnostics: DiagnosticRecord[];
|
|
35
37
|
}
|
|
38
|
+
|
|
39
|
+
/** How a multi-draft apply handles partial failures. */
|
|
40
|
+
export type ApplyConstituentsMode = 'atomic' | 'best_effort';
|
|
41
|
+
|
|
42
|
+
export interface ApplyConstituentsInput {
|
|
43
|
+
drafts: ConstituentaDraft[];
|
|
44
|
+
/** atomic: rollback on first failure; best_effort: apply valid drafts. Default: atomic. */
|
|
45
|
+
mode?: ApplyConstituentsMode;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ApplyConstituentsResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
applied: ConstituentaState[];
|
|
51
|
+
failed: Array<{ draft: ConstituentaDraft; diagnostics: DiagnosticRecord[] }>;
|
|
52
|
+
diagnostics: DiagnosticRecord[];
|
|
53
|
+
}
|
package/src/models/diagnostic.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { type RSToolErrorDescription } from './common';
|
|
2
2
|
|
|
3
|
+
/** Persisted diagnostic for a failed or warned expression in a session. */
|
|
3
4
|
export interface DiagnosticRecord {
|
|
4
5
|
sessionId: string;
|
|
6
|
+
/** Constituent id when the diagnostic is tied to a stored item; omitted for scratch analysis. */
|
|
5
7
|
constituentId?: number;
|
|
8
|
+
/** Expression text that was analyzed. */
|
|
6
9
|
expression: string;
|
|
7
10
|
error: RSToolErrorDescription;
|
|
8
11
|
}
|
|
9
12
|
|
|
13
|
+
/** Filters for {@link RSToolAgent.listDiagnostics}. */
|
|
10
14
|
export interface ListDiagnosticsFilters {
|
|
11
15
|
constituentId?: number;
|
|
12
16
|
}
|
package/src/models/evaluation.ts
CHANGED
|
@@ -15,6 +15,17 @@ export interface EvaluateConstituentaInput {
|
|
|
15
15
|
constituentId: number;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/** Evaluate a scratch expression or a stored constituent (provide one variant). */
|
|
19
|
+
export interface EvaluateInput {
|
|
20
|
+
/** Scratch expression; requires `cstType`. */
|
|
21
|
+
expression?: string;
|
|
22
|
+
/** Type context when evaluating `expression`. */
|
|
23
|
+
cstType?: CstType;
|
|
24
|
+
/** Stored constituent id to evaluate. */
|
|
25
|
+
constituentId?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Outcome of model evaluation for one expression or constituent. */
|
|
18
29
|
export interface EvaluationResult {
|
|
19
30
|
success: boolean;
|
|
20
31
|
value: RSToolValue | BasicBinding | null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { CstType } from './common';
|
|
4
|
+
import { detectImportKind, parseImportPayload } from './import-detect';
|
|
5
|
+
|
|
6
|
+
describe('parseImportPayload', () => {
|
|
7
|
+
it('parses JSON strings', () => {
|
|
8
|
+
expect(parseImportPayload('{"title":"x"}')).toEqual({ title: 'x' });
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('returns objects unchanged', () => {
|
|
12
|
+
const payload = { title: 'x' };
|
|
13
|
+
expect(parseImportPayload(payload)).toBe(payload);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('detectImportKind', () => {
|
|
18
|
+
it('detects session exports', () => {
|
|
19
|
+
expect(detectImportKind({ contractVersion: '2.0.0', state: { items: [] } })).toBe('session');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('detects portal schema JSON', () => {
|
|
23
|
+
expect(
|
|
24
|
+
detectImportKind({
|
|
25
|
+
contract_version: '1.0.0',
|
|
26
|
+
items: [{ id: 1, alias: 'X1', cst_type: CstType.BASE }]
|
|
27
|
+
})
|
|
28
|
+
).toBe('portal-schema');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('detects portal details JSON', () => {
|
|
32
|
+
expect(
|
|
33
|
+
detectImportKind({
|
|
34
|
+
title: 'Schema',
|
|
35
|
+
items: [{ id: 1, alias: 'X1', cst_type: CstType.BASE }]
|
|
36
|
+
})
|
|
37
|
+
).toBe('portal-details');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('rejects model JSON as schema session', () => {
|
|
41
|
+
expect(() =>
|
|
42
|
+
detectImportKind({
|
|
43
|
+
contract_version: '1.0.0',
|
|
44
|
+
items: [{ id: 1, type: 'basic', value: { 0: 'a' } }]
|
|
45
|
+
})
|
|
46
|
+
).toThrow(/Portal model JSON cannot be imported/);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('treats empty contract_version items as undetectable', () => {
|
|
50
|
+
expect(() =>
|
|
51
|
+
detectImportKind({
|
|
52
|
+
contract_version: '1.0.0',
|
|
53
|
+
items: []
|
|
54
|
+
})
|
|
55
|
+
).toThrow(/Cannot detect import kind/);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('rejects non-objects', () => {
|
|
59
|
+
expect(() => detectImportKind(null)).toThrow(/Invalid import payload/);
|
|
60
|
+
expect(() => detectImportKind('string')).toThrow(/Invalid import payload/);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('rejects undetectable payloads', () => {
|
|
64
|
+
expect(() => detectImportKind({ title: 'orphan' })).toThrow(/Cannot detect import kind/);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ImportDataKind } from './import-export';
|
|
2
|
+
|
|
3
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
4
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function parseImportPayload(payload: string | object): unknown {
|
|
8
|
+
if (typeof payload === 'string') {
|
|
9
|
+
return JSON.parse(payload) as unknown;
|
|
10
|
+
}
|
|
11
|
+
return payload;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function detectImportKind(data: unknown): Exclude<ImportDataKind, 'auto'> {
|
|
15
|
+
if (!isRecord(data)) {
|
|
16
|
+
throw new Error('Invalid import payload');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if ('contractVersion' in data && 'state' in data) {
|
|
20
|
+
return 'session';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if ('contract_version' in data && Array.isArray(data.items)) {
|
|
24
|
+
const items = data.items as unknown[];
|
|
25
|
+
if (items.length > 0) {
|
|
26
|
+
const first = items[0];
|
|
27
|
+
if (isRecord(first) && 'cst_type' in first) {
|
|
28
|
+
return 'portal-schema';
|
|
29
|
+
}
|
|
30
|
+
throw new Error('Portal model JSON cannot be imported as a schema session');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (Array.isArray(data.items) && data.items.length > 0) {
|
|
35
|
+
const first = data.items[0];
|
|
36
|
+
if (isRecord(first) && 'cst_type' in first) {
|
|
37
|
+
return 'portal-details';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw new Error('Cannot detect import kind; pass kind explicitly');
|
|
42
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type PortalModelImportData, type PortalSchemaImportData } from './portal-json';
|
|
2
|
+
|
|
3
|
+
/** Portal export target: conceptual schema or model values. */
|
|
4
|
+
export type PortalExportKind = 'schema' | 'model';
|
|
5
|
+
|
|
6
|
+
/** Serialized JSON string or parsed object for export helpers. */
|
|
7
|
+
export type ExportFormat = 'json' | 'object';
|
|
8
|
+
|
|
9
|
+
/** Input for {@link RSToolAgent.exportPortal}. */
|
|
10
|
+
export interface ExportPortalInput {
|
|
11
|
+
kind: PortalExportKind;
|
|
12
|
+
/** Default: `json` (string). Use `object` for structured data. */
|
|
13
|
+
format?: ExportFormat;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Import payload discriminator.
|
|
18
|
+
*
|
|
19
|
+
* Use `'auto'` to detect from JSON shape, or pass an explicit kind when ambiguous.
|
|
20
|
+
*/
|
|
21
|
+
export type ImportDataKind = 'auto' | 'session' | 'portal-schema' | 'portal-details';
|
|
22
|
+
|
|
23
|
+
/** JSON string or Portal import object, depending on {@link ExportFormat}. */
|
|
24
|
+
export type ExportPortalResult = string | PortalSchemaImportData | PortalModelImportData;
|
package/src/models/index.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
export {
|
|
2
|
+
type AgentConstituentaPatch,
|
|
3
|
+
type ApplySchemaPatchInput,
|
|
4
|
+
type ApplySchemaPatchResult,
|
|
5
|
+
type SessionStateDetail,
|
|
6
|
+
type SessionStateResult,
|
|
7
|
+
type SessionSummary,
|
|
8
|
+
type SessionSummaryItem
|
|
9
|
+
} from './agent-workflow';
|
|
1
10
|
export { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';
|
|
2
11
|
export {
|
|
3
12
|
CstType,
|
|
@@ -8,34 +17,33 @@ export {
|
|
|
8
17
|
type RSToolErrorDescription,
|
|
9
18
|
type RSToolValue
|
|
10
19
|
} from './common';
|
|
11
|
-
export {
|
|
12
|
-
type AddOrUpdateConstituentaInput,
|
|
13
|
-
type AddOrUpdateConstituentaResult,
|
|
14
|
-
type ConstituentaDraft,
|
|
15
|
-
type ConstituentaState
|
|
16
|
-
} from './constituenta';
|
|
20
|
+
export { type ApplyConstituentsMode, type ConstituentaDraft, type ConstituentaState } from './constituenta';
|
|
17
21
|
export { type DiagnosticRecord, type ListDiagnosticsFilters } from './diagnostic';
|
|
22
|
+
export { type EvaluateInput, type EvaluationResult } from './evaluation';
|
|
18
23
|
export {
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
type
|
|
22
|
-
|
|
24
|
+
type ExportFormat,
|
|
25
|
+
type ExportPortalInput,
|
|
26
|
+
type ExportPortalResult,
|
|
27
|
+
type ImportDataKind,
|
|
28
|
+
type PortalExportKind
|
|
29
|
+
} from './import-export';
|
|
23
30
|
export {
|
|
24
|
-
type ClearConstituentaValuesInput,
|
|
25
31
|
type ModelValueState,
|
|
26
32
|
type RecalculateModelResult,
|
|
27
33
|
type SessionModelState,
|
|
28
34
|
type SetConstituentaValueInput,
|
|
29
|
-
type
|
|
35
|
+
type SetModelValuesInput
|
|
30
36
|
} from './model-value';
|
|
31
37
|
export {
|
|
32
38
|
PORTAL_JSON_CONTRACT_VERSION,
|
|
33
39
|
type PortalImportMetadata,
|
|
34
40
|
type PortalModelImportData,
|
|
41
|
+
type PortalRsformDetails,
|
|
35
42
|
type PortalSchemaConstituenta,
|
|
36
43
|
type PortalSchemaImportData,
|
|
37
|
-
type PortalTermForm
|
|
44
|
+
type PortalTermForm,
|
|
45
|
+
portalItemToDraft
|
|
38
46
|
} from './portal-json';
|
|
39
47
|
export { RSToolAgent } from './rstool-agent';
|
|
40
48
|
export { type SessionHandle, type SessionRevision, type SessionState } from './session';
|
|
41
|
-
export { CONTRACT_VERSION, type RSToolAgentContract } from './tool-contract';
|
|
49
|
+
export { CONTRACT_VERSION, type RSToolAgentContract, type RSToolAgentOptions } from './tool-contract';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type BasicBinding, type EvalStatus, type RSToolValue } from './common';
|
|
2
2
|
|
|
3
|
+
/** Model value for one constituent. */
|
|
3
4
|
export interface ModelValueState {
|
|
4
5
|
id: number;
|
|
5
6
|
/** Frontend type string: `basic` or normalized effective typification. */
|
|
@@ -7,11 +8,14 @@ export interface ModelValueState {
|
|
|
7
8
|
value: RSToolValue | BasicBinding;
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
/** All model values in a session. */
|
|
10
12
|
export interface SessionModelState {
|
|
11
13
|
items: ModelValueState[];
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
/** Set or replace the model value for one constituent. */
|
|
14
17
|
export interface SetConstituentaValueInput {
|
|
18
|
+
/** Target constituent id. */
|
|
15
19
|
target: number;
|
|
16
20
|
/** Optional type override; inferred from schema when omitted. */
|
|
17
21
|
type?: string;
|
|
@@ -26,6 +30,14 @@ export interface ClearConstituentaValuesInput {
|
|
|
26
30
|
items: number[];
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
/** Input for {@link RSToolAgent.setModelValues}. */
|
|
34
|
+
export interface SetModelValuesInput {
|
|
35
|
+
set?: SetConstituentaValueInput[];
|
|
36
|
+
/** Constituent ids whose model values should be cleared. */
|
|
37
|
+
clear?: number[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Per-constituent outcome after {@link RSToolAgent.recalculateModel}. */
|
|
29
41
|
export interface RecalculateModelResult {
|
|
30
42
|
items: Array<{ id: number; alias: string; value: RSToolValue | null; status: EvalStatus }>;
|
|
31
43
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { CstType } from './common';
|
|
4
|
+
import { portalItemToDraft } from './portal-json';
|
|
5
|
+
|
|
6
|
+
describe('portalItemToDraft', () => {
|
|
7
|
+
it('maps valid portal items', () => {
|
|
8
|
+
expect(
|
|
9
|
+
portalItemToDraft({
|
|
10
|
+
id: 1,
|
|
11
|
+
alias: 'D1',
|
|
12
|
+
cst_type: CstType.TERM,
|
|
13
|
+
definition_formal: '1+2',
|
|
14
|
+
term_raw: 'term',
|
|
15
|
+
definition_raw: 'def',
|
|
16
|
+
convention: 'conv'
|
|
17
|
+
})
|
|
18
|
+
).toEqual({
|
|
19
|
+
id: 1,
|
|
20
|
+
alias: 'D1',
|
|
21
|
+
cstType: CstType.TERM,
|
|
22
|
+
definitionFormal: '1+2',
|
|
23
|
+
term: 'term',
|
|
24
|
+
definitionText: 'def',
|
|
25
|
+
convention: 'conv'
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('rejects unknown cst_type values', () => {
|
|
30
|
+
expect(() =>
|
|
31
|
+
portalItemToDraft({
|
|
32
|
+
id: 1,
|
|
33
|
+
alias: 'X1',
|
|
34
|
+
cst_type: 'not-a-cst-type'
|
|
35
|
+
})
|
|
36
|
+
).toThrow(/Invalid cst_type "not-a-cst-type" for constituent "X1"/);
|
|
37
|
+
});
|
|
38
|
+
});
|