@istar-ts/actions 0.15.0-beta.8 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +139 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +137 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -730,6 +730,70 @@ export declare function diagnosticToMarker(diagnostic: GoalDiagnostic): Marker;
|
|
|
730
730
|
*/
|
|
731
731
|
export declare function markerToDiagnostic(marker: Marker): GoalDiagnostic;
|
|
732
732
|
//#endregion
|
|
733
|
+
//#region src/metamodel-context.d.ts
|
|
734
|
+
export interface MetamodelPropertyContext {
|
|
735
|
+
readonly key: string;
|
|
736
|
+
readonly type: string;
|
|
737
|
+
readonly values?: readonly string[];
|
|
738
|
+
readonly optional?: boolean;
|
|
739
|
+
readonly description?: string;
|
|
740
|
+
}
|
|
741
|
+
export interface MetamodelElementContext {
|
|
742
|
+
readonly kind: string;
|
|
743
|
+
readonly label: string;
|
|
744
|
+
readonly description?: string;
|
|
745
|
+
readonly category: "actor" | "node";
|
|
746
|
+
readonly canBeOnPaper?: boolean;
|
|
747
|
+
readonly canBeInnerElement?: boolean;
|
|
748
|
+
readonly properties?: readonly MetamodelPropertyContext[];
|
|
749
|
+
}
|
|
750
|
+
export interface MetamodelLinkContext {
|
|
751
|
+
readonly kind: string;
|
|
752
|
+
readonly label: string;
|
|
753
|
+
readonly description?: string;
|
|
754
|
+
readonly category: "actor" | "node" | "dependency";
|
|
755
|
+
readonly sources: readonly string[];
|
|
756
|
+
readonly targets: readonly string[];
|
|
757
|
+
/** `'n'` for a link joining several sources at a hub (see `Metamodel`'s `arity`). */
|
|
758
|
+
readonly arity?: "n";
|
|
759
|
+
/** The link's declared value set (e.g. a Contribution link's make/help/hurt/break). */
|
|
760
|
+
readonly values?: readonly string[];
|
|
761
|
+
readonly properties?: readonly MetamodelPropertyContext[];
|
|
762
|
+
}
|
|
763
|
+
/** A `Metamodel`, described for an LLM: JSON-serializable, derived only from the metamodel. */
|
|
764
|
+
export interface MetamodelContext {
|
|
765
|
+
readonly framework: string;
|
|
766
|
+
readonly elements: readonly MetamodelElementContext[];
|
|
767
|
+
readonly links: readonly MetamodelLinkContext[];
|
|
768
|
+
}
|
|
769
|
+
export interface MetamodelContextOptions {
|
|
770
|
+
/**
|
|
771
|
+
* Typed custom-property schemas (`@istar-ts/core`'s `defineProperties`), keyed by kind, e.g.
|
|
772
|
+
* a dialect's own or a contribution's (`IstarGlspContribution.schemas`). Properties a kind has
|
|
773
|
+
* no schema for are left out: `customProperties` values stay strings the metamodel itself
|
|
774
|
+
* knows nothing about.
|
|
775
|
+
*/
|
|
776
|
+
readonly schemas?: readonly PropertySchema<PropertyShape, string>[];
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* `metamodel`, as a typed, JSON-serializable description: every element and link kind a
|
|
780
|
+
* modeller declares directly (kinds generated for an n-ary link's hub, leg or end are left out,
|
|
781
|
+
* as a hand-written palette hides them too), its containment, and each link kind's source and
|
|
782
|
+
* target kinds in words, resolved the same way `canLink` does (`union`/`ofCategory`).
|
|
783
|
+
*/
|
|
784
|
+
export declare function metamodelContext(metamodel: AnyMetamodel, options?: MetamodelContextOptions): MetamodelContext;
|
|
785
|
+
/**
|
|
786
|
+
* `context`, rendered as compact, deterministic markdown for an LLM: one section each for actor
|
|
787
|
+
* kinds, node kinds and link kinds, in the metamodel's own declaration order.
|
|
788
|
+
*/
|
|
789
|
+
export declare function metamodelContextText(context: MetamodelContext): string;
|
|
790
|
+
/**
|
|
791
|
+
* The built-in `HostContextProvider` (#240): its text is always read from the model at hand
|
|
792
|
+
* (`metamodelOf(model)`), so one instance works for every dialect a host serves. `options`
|
|
793
|
+
* (`schemas`, mainly from a dialect's `IstarGlspContribution`) are fixed at creation time.
|
|
794
|
+
*/
|
|
795
|
+
export declare function metamodelContextProvider(options?: MetamodelContextOptions): HostContextProvider;
|
|
796
|
+
//#endregion
|
|
733
797
|
//#region src/mirror.d.ts
|
|
734
798
|
export interface MirrorStoreOptions<EK extends string = ElementKind, LK extends string = LinkKind> {
|
|
735
799
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -730,6 +730,70 @@ export declare function diagnosticToMarker(diagnostic: GoalDiagnostic): Marker;
|
|
|
730
730
|
*/
|
|
731
731
|
export declare function markerToDiagnostic(marker: Marker): GoalDiagnostic;
|
|
732
732
|
//#endregion
|
|
733
|
+
//#region src/metamodel-context.d.ts
|
|
734
|
+
export interface MetamodelPropertyContext {
|
|
735
|
+
readonly key: string;
|
|
736
|
+
readonly type: string;
|
|
737
|
+
readonly values?: readonly string[];
|
|
738
|
+
readonly optional?: boolean;
|
|
739
|
+
readonly description?: string;
|
|
740
|
+
}
|
|
741
|
+
export interface MetamodelElementContext {
|
|
742
|
+
readonly kind: string;
|
|
743
|
+
readonly label: string;
|
|
744
|
+
readonly description?: string;
|
|
745
|
+
readonly category: "actor" | "node";
|
|
746
|
+
readonly canBeOnPaper?: boolean;
|
|
747
|
+
readonly canBeInnerElement?: boolean;
|
|
748
|
+
readonly properties?: readonly MetamodelPropertyContext[];
|
|
749
|
+
}
|
|
750
|
+
export interface MetamodelLinkContext {
|
|
751
|
+
readonly kind: string;
|
|
752
|
+
readonly label: string;
|
|
753
|
+
readonly description?: string;
|
|
754
|
+
readonly category: "actor" | "node" | "dependency";
|
|
755
|
+
readonly sources: readonly string[];
|
|
756
|
+
readonly targets: readonly string[];
|
|
757
|
+
/** `'n'` for a link joining several sources at a hub (see `Metamodel`'s `arity`). */
|
|
758
|
+
readonly arity?: "n";
|
|
759
|
+
/** The link's declared value set (e.g. a Contribution link's make/help/hurt/break). */
|
|
760
|
+
readonly values?: readonly string[];
|
|
761
|
+
readonly properties?: readonly MetamodelPropertyContext[];
|
|
762
|
+
}
|
|
763
|
+
/** A `Metamodel`, described for an LLM: JSON-serializable, derived only from the metamodel. */
|
|
764
|
+
export interface MetamodelContext {
|
|
765
|
+
readonly framework: string;
|
|
766
|
+
readonly elements: readonly MetamodelElementContext[];
|
|
767
|
+
readonly links: readonly MetamodelLinkContext[];
|
|
768
|
+
}
|
|
769
|
+
export interface MetamodelContextOptions {
|
|
770
|
+
/**
|
|
771
|
+
* Typed custom-property schemas (`@istar-ts/core`'s `defineProperties`), keyed by kind, e.g.
|
|
772
|
+
* a dialect's own or a contribution's (`IstarGlspContribution.schemas`). Properties a kind has
|
|
773
|
+
* no schema for are left out: `customProperties` values stay strings the metamodel itself
|
|
774
|
+
* knows nothing about.
|
|
775
|
+
*/
|
|
776
|
+
readonly schemas?: readonly PropertySchema<PropertyShape, string>[];
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* `metamodel`, as a typed, JSON-serializable description: every element and link kind a
|
|
780
|
+
* modeller declares directly (kinds generated for an n-ary link's hub, leg or end are left out,
|
|
781
|
+
* as a hand-written palette hides them too), its containment, and each link kind's source and
|
|
782
|
+
* target kinds in words, resolved the same way `canLink` does (`union`/`ofCategory`).
|
|
783
|
+
*/
|
|
784
|
+
export declare function metamodelContext(metamodel: AnyMetamodel, options?: MetamodelContextOptions): MetamodelContext;
|
|
785
|
+
/**
|
|
786
|
+
* `context`, rendered as compact, deterministic markdown for an LLM: one section each for actor
|
|
787
|
+
* kinds, node kinds and link kinds, in the metamodel's own declaration order.
|
|
788
|
+
*/
|
|
789
|
+
export declare function metamodelContextText(context: MetamodelContext): string;
|
|
790
|
+
/**
|
|
791
|
+
* The built-in `HostContextProvider` (#240): its text is always read from the model at hand
|
|
792
|
+
* (`metamodelOf(model)`), so one instance works for every dialect a host serves. `options`
|
|
793
|
+
* (`schemas`, mainly from a dialect's `IstarGlspContribution`) are fixed at creation time.
|
|
794
|
+
*/
|
|
795
|
+
export declare function metamodelContextProvider(options?: MetamodelContextOptions): HostContextProvider;
|
|
796
|
+
//#endregion
|
|
733
797
|
//#region src/mirror.d.ts
|
|
734
798
|
export interface MirrorStoreOptions<EK extends string = ElementKind, LK extends string = LinkKind> {
|
|
735
799
|
/**
|
package/dist/index.js
CHANGED
|
@@ -200,12 +200,13 @@ function injectCreatedIds(operation, createdIds, model) {
|
|
|
200
200
|
return withCreatedIds(operation, [...elementIds], [...linkIds], model);
|
|
201
201
|
}
|
|
202
202
|
//#endregion
|
|
203
|
-
//#region src/
|
|
203
|
+
//#region src/kind-selectors.ts
|
|
204
204
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
205
|
+
* Internal: which element and link kinds a rule selector matches, the same way `canLink` does.
|
|
206
|
+
* Shared by `hints.ts` (GLSP type hints) and `metamodel-context.ts` (#240), not part of this
|
|
207
|
+
* package's public API — `index.ts` doesn't re-export this module.
|
|
208
208
|
*/
|
|
209
|
+
/** A generated kind (a hub, leg or end) that an n-ary link's declaration adds on its own. */
|
|
209
210
|
function isHub(definition) {
|
|
210
211
|
return definition.role === "hub";
|
|
211
212
|
}
|
|
@@ -226,6 +227,13 @@ function union(metamodel, selectors) {
|
|
|
226
227
|
function ofCategory(metamodel, category) {
|
|
227
228
|
return [...metamodel.elements.values()].filter((d) => !isHub(d) && (category === void 0 || d.category === category)).map((d) => d.kind);
|
|
228
229
|
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/hints.ts
|
|
232
|
+
/**
|
|
233
|
+
* What a client can know before it asks: type hints from the metamodel, and the palette as
|
|
234
|
+
* GLSP context actions. Both are derived from data (`Metamodel`, `PaletteDescription`), so they
|
|
235
|
+
* work for any root or extension.
|
|
236
|
+
*/
|
|
229
237
|
/**
|
|
230
238
|
* GLSP type hints of a metamodel. Shapes: every element kind (hubs can't be resized or
|
|
231
239
|
* reparented; actors contain the node kinds that can be inner elements). Edges: every link kind,
|
|
@@ -1046,6 +1054,130 @@ function contextText(provider, model) {
|
|
|
1046
1054
|
return Promise.resolve(typeof text === "string" ? text : text(model));
|
|
1047
1055
|
}
|
|
1048
1056
|
//#endregion
|
|
1057
|
+
//#region src/metamodel-context.ts
|
|
1058
|
+
/**
|
|
1059
|
+
* A built-in context provider (#240): what an agent needs to know about a model's own
|
|
1060
|
+
* vocabulary — its element and link kinds, containment, link rules and value sets — derived
|
|
1061
|
+
* only from the `Metamodel`, so it works unchanged for iStar 2.0, KAOS, NFR, an
|
|
1062
|
+
* `extendMetamodel` result or a file metamodel (pistarExt). No dialect names in this file.
|
|
1063
|
+
*
|
|
1064
|
+
* `metamodelContextProvider` is the `HostContextProvider` every launcher and agent session
|
|
1065
|
+
* includes by default (opt-out: `metamodelContext: false`); a host's own providers are appended
|
|
1066
|
+
* after it.
|
|
1067
|
+
*/
|
|
1068
|
+
function propertiesOf(kind, byKind) {
|
|
1069
|
+
const schemas = byKind.get(kind);
|
|
1070
|
+
if (!schemas || schemas.length === 0) return void 0;
|
|
1071
|
+
const properties = [];
|
|
1072
|
+
for (const schema of schemas) for (const [key, field] of Object.entries(schema.shape)) properties.push({
|
|
1073
|
+
key,
|
|
1074
|
+
type: field.type,
|
|
1075
|
+
...field.values ? { values: field.values } : {},
|
|
1076
|
+
...field.options.optional ? { optional: true } : {},
|
|
1077
|
+
...field.options.description ? { description: field.options.description } : {}
|
|
1078
|
+
});
|
|
1079
|
+
return properties;
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* `metamodel`, as a typed, JSON-serializable description: every element and link kind a
|
|
1083
|
+
* modeller declares directly (kinds generated for an n-ary link's hub, leg or end are left out,
|
|
1084
|
+
* as a hand-written palette hides them too), its containment, and each link kind's source and
|
|
1085
|
+
* target kinds in words, resolved the same way `canLink` does (`union`/`ofCategory`).
|
|
1086
|
+
*/
|
|
1087
|
+
function metamodelContext(metamodel, options = {}) {
|
|
1088
|
+
const schemasByKind = /* @__PURE__ */ new Map();
|
|
1089
|
+
for (const schema of options.schemas ?? []) {
|
|
1090
|
+
const list = schemasByKind.get(schema.kind) ?? [];
|
|
1091
|
+
list.push(schema);
|
|
1092
|
+
schemasByKind.set(schema.kind, list);
|
|
1093
|
+
}
|
|
1094
|
+
const elements = [];
|
|
1095
|
+
for (const definition of metamodel.elements.values()) {
|
|
1096
|
+
if (isHub(definition)) continue;
|
|
1097
|
+
elements.push({
|
|
1098
|
+
kind: definition.kind,
|
|
1099
|
+
label: definition.label,
|
|
1100
|
+
...definition.description !== void 0 ? { description: definition.description } : {},
|
|
1101
|
+
category: definition.category,
|
|
1102
|
+
...definition.info ? {
|
|
1103
|
+
canBeOnPaper: definition.info.canBeOnPaper,
|
|
1104
|
+
canBeInnerElement: definition.info.canBeInnerElement
|
|
1105
|
+
} : {},
|
|
1106
|
+
...propertiesOf(definition.kind, schemasByKind) ? { properties: propertiesOf(definition.kind, schemasByKind) } : {}
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
const links = [];
|
|
1110
|
+
for (const definition of metamodel.links.values()) {
|
|
1111
|
+
if (definition.role !== void 0) continue;
|
|
1112
|
+
const rules = metamodel.links.get(effectiveLinkKind(metamodel, definition.kind))?.rules;
|
|
1113
|
+
const builtIn = definition.category === "dependency" ? ofCategory(metamodel) : ofCategory(metamodel, definition.category);
|
|
1114
|
+
links.push({
|
|
1115
|
+
kind: definition.kind,
|
|
1116
|
+
label: definition.label,
|
|
1117
|
+
...definition.description !== void 0 ? { description: definition.description } : {},
|
|
1118
|
+
category: definition.category,
|
|
1119
|
+
sources: rules ? union(metamodel, rules.sources) : builtIn,
|
|
1120
|
+
targets: rules ? union(metamodel, rules.targets) : builtIn,
|
|
1121
|
+
...definition.arity === "n" ? { arity: definition.arity } : {},
|
|
1122
|
+
...definition.info.possibleLabels ? { values: definition.info.possibleLabels } : {},
|
|
1123
|
+
...propertiesOf(definition.kind, schemasByKind) ? { properties: propertiesOf(definition.kind, schemasByKind) } : {}
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
return {
|
|
1127
|
+
framework: metamodel.framework,
|
|
1128
|
+
elements,
|
|
1129
|
+
links
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
function propertiesLine(properties) {
|
|
1133
|
+
if (!properties || properties.length === 0) return [];
|
|
1134
|
+
return [` properties: ${properties.map((p) => {
|
|
1135
|
+
const bits = [p.type, ...p.values ? [`values: ${p.values.join("/")}`] : []];
|
|
1136
|
+
return `${p.key} (${bits.join(", ")})${p.optional ? "?" : ""}`;
|
|
1137
|
+
}).join(", ")}`];
|
|
1138
|
+
}
|
|
1139
|
+
function flags(element) {
|
|
1140
|
+
const bits = [];
|
|
1141
|
+
if (element.canBeOnPaper) bits.push("on paper");
|
|
1142
|
+
if (element.canBeInnerElement) bits.push("inner");
|
|
1143
|
+
return bits.length > 0 ? ` [${bits.join(", ")}]` : "";
|
|
1144
|
+
}
|
|
1145
|
+
function elementLine(element) {
|
|
1146
|
+
const description = element.description ? ` — ${element.description}` : "";
|
|
1147
|
+
return [`- ${element.kind} (${element.label})${flags(element)}${description}`, ...propertiesLine(element.properties)];
|
|
1148
|
+
}
|
|
1149
|
+
function linkLine(link) {
|
|
1150
|
+
const arity = link.arity === "n" ? " [n-ary, via a hub]" : "";
|
|
1151
|
+
const values = link.values ? `; values: ${link.values.join(", ")}` : "";
|
|
1152
|
+
const description = link.description ? ` — ${link.description}` : "";
|
|
1153
|
+
return [`- ${link.kind} (${link.label})${arity}: ${link.category} link, ${link.sources.join(", ")} → ${link.targets.join(", ")}${values}${description}`, ...propertiesLine(link.properties)];
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* `context`, rendered as compact, deterministic markdown for an LLM: one section each for actor
|
|
1157
|
+
* kinds, node kinds and link kinds, in the metamodel's own declaration order.
|
|
1158
|
+
*/
|
|
1159
|
+
function metamodelContextText(context) {
|
|
1160
|
+
const actors = context.elements.filter((e) => e.category === "actor");
|
|
1161
|
+
const nodes = context.elements.filter((e) => e.category === "node");
|
|
1162
|
+
const sections = [`# ${context.framework} metamodel`];
|
|
1163
|
+
if (actors.length > 0) sections.push(["## Actor kinds", ...actors.flatMap(elementLine)].join("\n"));
|
|
1164
|
+
if (nodes.length > 0) sections.push(["## Node kinds", ...nodes.flatMap(elementLine)].join("\n"));
|
|
1165
|
+
if (context.links.length > 0) sections.push(["## Link kinds", ...context.links.flatMap(linkLine)].join("\n"));
|
|
1166
|
+
return sections.join("\n\n");
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* The built-in `HostContextProvider` (#240): its text is always read from the model at hand
|
|
1170
|
+
* (`metamodelOf(model)`), so one instance works for every dialect a host serves. `options`
|
|
1171
|
+
* (`schemas`, mainly from a dialect's `IstarGlspContribution`) are fixed at creation time.
|
|
1172
|
+
*/
|
|
1173
|
+
function metamodelContextProvider(options = {}) {
|
|
1174
|
+
return {
|
|
1175
|
+
name: "metamodel",
|
|
1176
|
+
title: "This model's language",
|
|
1177
|
+
text: (model) => metamodelContextText(metamodelContext(metamodelOf(model), options))
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
//#endregion
|
|
1049
1181
|
//#region src/mirror.ts
|
|
1050
1182
|
/**
|
|
1051
1183
|
* A mirror store: a read-only `ModelStore` in this process whose model follows a dispatcher that
|
|
@@ -1391,6 +1523,6 @@ function createRemoteDispatcher(port) {
|
|
|
1391
1523
|
/** Version of the action protocol this package speaks. */
|
|
1392
1524
|
const ACTIONS_PROTOCOL_VERSION = "0.0.0";
|
|
1393
1525
|
//#endregion
|
|
1394
|
-
export { ACTIONS_PROTOCOL_VERSION, HANDLED_ACTION_KINDS, connectDispatcher, contextActionsFor, contextText, createActionDispatcher, createMirrorStore, createRemoteDispatcher, diagnosticToMarker, hostToolContext, injectCreatedIds, isOperation, isRequestAction, markerToDiagnostic, paletteFromMetamodel, readOnlyDispatcher, typeHintsFor };
|
|
1526
|
+
export { ACTIONS_PROTOCOL_VERSION, HANDLED_ACTION_KINDS, connectDispatcher, contextActionsFor, contextText, createActionDispatcher, createMirrorStore, createRemoteDispatcher, diagnosticToMarker, hostToolContext, injectCreatedIds, isOperation, isRequestAction, markerToDiagnostic, metamodelContext, metamodelContextProvider, metamodelContextText, paletteFromMetamodel, readOnlyDispatcher, typeHintsFor };
|
|
1395
1527
|
|
|
1396
1528
|
//# sourceMappingURL=index.js.map
|