@istar-ts/actions 0.15.0-beta.1 → 0.15.0-beta.2

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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyIstarModel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
1
+ import { AnyIstarModel, AnyMetamodel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
2
2
  //#region src/actions.d.ts
3
3
  /** GLSP's custom arguments: a flat map of primitives. */
4
4
  export type Args = Readonly<Record<string, string | number | boolean>>;
@@ -518,8 +518,14 @@ export interface ActionDispatcherOptions<EK extends string = ElementKind, LK ext
518
518
  readonly guards?: readonly ActionGuard<EK, LK>[];
519
519
  /** Run after each operation is applied; see `ActionPostGuard`. */
520
520
  readonly postGuards?: readonly ActionPostGuard<EK, LK>[];
521
- /** What `RequestContextActions` offers. Default: `DEFAULT_PALETTE` (iStar 2.0's). */
522
- readonly palette?: AnyPaletteDescription;
521
+ /**
522
+ * What `RequestContextActions` offers: a fixed description, or a function evaluated on each
523
+ * request (so a host can track a registry or extensions that change after this dispatcher was
524
+ * created — a plain `AnyPaletteDescription` is read once, at creation). Default: derived from
525
+ * the model's current metamodel (`paletteFromMetamodel`), the same fallback `contributionFor`
526
+ * (`@istar-ts/glsp`) uses — not iStar 2.0's palette regardless of dialect.
527
+ */
528
+ readonly palette?: AnyPaletteDescription | (() => AnyPaletteDescription);
523
529
  /**
524
530
  * Property schemas an operation must not break: an operation that adds an issue
525
531
  * (`validateModelProperties`) is rejected. Their issues are also markers.
@@ -566,6 +572,15 @@ export declare function typeHintsFor<EK extends string, LK extends string>(metam
566
572
  * lacks are left out.
567
573
  */
568
574
  export declare function contextActionsFor<EK extends string, LK extends string>(palette: AnyPaletteDescription, metamodel: Metamodel<EK, LK>): Pick<SetContextActions, "actions" | "groups">;
575
+ /**
576
+ * A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
577
+ * (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
578
+ * an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
579
+ * hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
580
+ * `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
581
+ * was given.
582
+ */
583
+ export declare function paletteFromMetamodel(metamodel: AnyMetamodel): AnyPaletteDescription;
569
584
  //#endregion
570
585
  //#region src/host.d.ts
571
586
  /** A host's knowledge for the model: a system-prompt section and/or an MCP resource. */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyIstarModel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
1
+ import { AnyIstarModel, AnyMetamodel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
2
2
  //#region src/actions.d.ts
3
3
  /** GLSP's custom arguments: a flat map of primitives. */
4
4
  export type Args = Readonly<Record<string, string | number | boolean>>;
@@ -518,8 +518,14 @@ export interface ActionDispatcherOptions<EK extends string = ElementKind, LK ext
518
518
  readonly guards?: readonly ActionGuard<EK, LK>[];
519
519
  /** Run after each operation is applied; see `ActionPostGuard`. */
520
520
  readonly postGuards?: readonly ActionPostGuard<EK, LK>[];
521
- /** What `RequestContextActions` offers. Default: `DEFAULT_PALETTE` (iStar 2.0's). */
522
- readonly palette?: AnyPaletteDescription;
521
+ /**
522
+ * What `RequestContextActions` offers: a fixed description, or a function evaluated on each
523
+ * request (so a host can track a registry or extensions that change after this dispatcher was
524
+ * created — a plain `AnyPaletteDescription` is read once, at creation). Default: derived from
525
+ * the model's current metamodel (`paletteFromMetamodel`), the same fallback `contributionFor`
526
+ * (`@istar-ts/glsp`) uses — not iStar 2.0's palette regardless of dialect.
527
+ */
528
+ readonly palette?: AnyPaletteDescription | (() => AnyPaletteDescription);
523
529
  /**
524
530
  * Property schemas an operation must not break: an operation that adds an issue
525
531
  * (`validateModelProperties`) is rejected. Their issues are also markers.
@@ -566,6 +572,15 @@ export declare function typeHintsFor<EK extends string, LK extends string>(metam
566
572
  * lacks are left out.
567
573
  */
568
574
  export declare function contextActionsFor<EK extends string, LK extends string>(palette: AnyPaletteDescription, metamodel: Metamodel<EK, LK>): Pick<SetContextActions, "actions" | "groups">;
575
+ /**
576
+ * A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
577
+ * (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
578
+ * an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
579
+ * hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
580
+ * `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
581
+ * was given.
582
+ */
583
+ export declare function paletteFromMetamodel(metamodel: AnyMetamodel): AnyPaletteDescription;
569
584
  //#endregion
570
585
  //#region src/host.d.ts
571
586
  /** A host's knowledge for the model: a system-prompt section and/or an MCP resource. */
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEFAULT_PALETTE, DIAGNOSTIC_SEVERITIES, FILE_METAMODEL_KEY, LINK_SELECTOR, MetamodelError, ModelOperationError, canLink, connectResultToDiagnostic, createEmptyModel, dependencyEnds, effectiveLinkKind, elementBehavesLike, inheritMetamodel, inheritSourceLayout, linkBehavesLike, metamodelOf, parsePistar, toPistarObject, validateModel, validateModelProperties, withFileMetamodel } from "@istar-ts/core";
1
+ import { DIAGNOSTIC_SEVERITIES, FILE_METAMODEL_KEY, LINK_SELECTOR, MetamodelError, ModelOperationError, canLink, connectResultToDiagnostic, createEmptyModel, dependencyEnds, effectiveLinkKind, elementBehavesLike, inheritMetamodel, inheritSourceLayout, linkBehavesLike, metamodelOf, parsePistar, toPistarObject, validateModel, validateModelProperties, withFileMetamodel } from "@istar-ts/core";
2
2
  //#region src/actions.ts
3
3
  const OPERATION_KIND_LIST = [
4
4
  "createNode",
@@ -185,6 +185,36 @@ function contextActionsFor(palette, metamodel) {
185
185
  groups: palette.groups
186
186
  };
187
187
  }
188
+ /**
189
+ * A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
190
+ * (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
191
+ * an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
192
+ * hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
193
+ * `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
194
+ * was given.
195
+ */
196
+ function paletteFromMetamodel(metamodel) {
197
+ const elements = {};
198
+ let order = 0;
199
+ for (const definition of metamodel.elements.values()) elements[definition.kind] = definition.role !== void 0 ? false : {
200
+ label: definition.label,
201
+ order: order++,
202
+ section: definition.category === "actor" ? "actors" : "elements",
203
+ ...definition.category === "actor" ? { group: "actors" } : {}
204
+ };
205
+ const links = {};
206
+ order = 0;
207
+ for (const definition of metamodel.links.values()) links[definition.kind] = definition.role !== void 0 ? false : [{
208
+ label: definition.label,
209
+ order: order++,
210
+ section: "elements"
211
+ }];
212
+ return {
213
+ elements,
214
+ links,
215
+ groups: { actors: { label: "Actor" } }
216
+ };
217
+ }
188
218
  //#endregion
189
219
  //#region src/markers.ts
190
220
  /** A `GoalDiagnostic` as a GLSP marker: `kind` is its severity, `label` its message. */
@@ -276,7 +306,11 @@ function createActionDispatcher(store, options = {}) {
276
306
  const s = store;
277
307
  const guards = options.guards ?? [];
278
308
  const postGuards = options.postGuards ?? [];
279
- const palette = options.palette ?? DEFAULT_PALETTE;
309
+ const resolvePalette = (meta) => {
310
+ const option = options.palette;
311
+ if (typeof option === "function") return option();
312
+ return option ?? paletteFromMetamodel(meta);
313
+ };
280
314
  const sourceModelName = options.sourceModelName ?? "";
281
315
  const listeners = /* @__PURE__ */ new Set();
282
316
  let saved = s.getModel();
@@ -698,11 +732,14 @@ function createActionDispatcher(store, options = {}) {
698
732
  ...typeHintsFor(metaOf(model))
699
733
  };
700
734
  case "requestCheckEdge": return checkEdge(action);
701
- case "requestContextActions": return {
702
- kind: "setContextActions",
703
- responseId: action.requestId,
704
- ...contextActionsFor(palette, metaOf(model))
705
- };
735
+ case "requestContextActions": {
736
+ const meta = metaOf(model);
737
+ return {
738
+ kind: "setContextActions",
739
+ responseId: action.requestId,
740
+ ...contextActionsFor(resolvePalette(meta), meta)
741
+ };
742
+ }
706
743
  case "requestMarkers": return markers(action);
707
744
  default: return;
708
745
  }
@@ -1150,6 +1187,6 @@ function createRemoteDispatcher(port) {
1150
1187
  /** Version of the action protocol this package speaks. */
1151
1188
  const ACTIONS_PROTOCOL_VERSION = "0.0.0";
1152
1189
  //#endregion
1153
- export { ACTIONS_PROTOCOL_VERSION, HANDLED_ACTION_KINDS, connectDispatcher, contextActionsFor, contextText, createActionDispatcher, createMirrorStore, createRemoteDispatcher, diagnosticToMarker, hostToolContext, isOperation, isRequestAction, markerToDiagnostic, readOnlyDispatcher, typeHintsFor };
1190
+ export { ACTIONS_PROTOCOL_VERSION, HANDLED_ACTION_KINDS, connectDispatcher, contextActionsFor, contextText, createActionDispatcher, createMirrorStore, createRemoteDispatcher, diagnosticToMarker, hostToolContext, isOperation, isRequestAction, markerToDiagnostic, paletteFromMetamodel, readOnlyDispatcher, typeHintsFor };
1154
1191
 
1155
1192
  //# sourceMappingURL=index.js.map