@syntrologie/runtime-sdk 1.0.1-canary.3 → 2.0.0-canary.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/CAPABILITIES.md +630 -463
- package/README.md +285 -62
- package/dist/RuntimeProvider.d.ts +51 -0
- package/dist/RuntimeProvider.js +114 -0
- package/dist/RuntimeProvider.js.map +1 -0
- package/dist/SmartCanvasApp.d.ts +9 -3
- package/dist/SmartCanvasApp.js +36 -38
- package/dist/SmartCanvasApp.js.map +1 -1
- package/dist/actions/ActionEngine.d.ts +11 -0
- package/dist/actions/ActionEngine.js +274 -0
- package/dist/actions/ActionEngine.js.map +1 -0
- package/dist/actions/executors/index.d.ts +118 -0
- package/dist/actions/executors/index.js +242 -0
- package/dist/actions/executors/index.js.map +1 -0
- package/dist/actions/executors/tour.d.ts +18 -0
- package/dist/actions/executors/tour.js +332 -0
- package/dist/actions/executors/tour.js.map +1 -0
- package/dist/actions/index.d.ts +10 -0
- package/dist/actions/index.js +12 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/types.d.ts +399 -0
- package/dist/actions/types.js +8 -0
- package/dist/actions/types.js.map +1 -0
- package/dist/actions/validation.d.ts +14 -0
- package/dist/actions/validation.js +603 -0
- package/dist/actions/validation.js.map +1 -0
- package/dist/api.d.ts +32 -18
- package/dist/api.js +56 -39
- package/dist/api.js.map +1 -1
- package/dist/apps/AppContext.d.ts +31 -0
- package/dist/apps/AppContext.js +93 -0
- package/dist/apps/AppContext.js.map +1 -0
- package/dist/apps/AppLoader.d.ts +84 -0
- package/dist/apps/AppLoader.js +250 -0
- package/dist/apps/AppLoader.js.map +1 -0
- package/dist/apps/AppRegistry.d.ts +102 -0
- package/dist/apps/AppRegistry.js +317 -0
- package/dist/apps/AppRegistry.js.map +1 -0
- package/dist/apps/examples/gamification-app.example.d.ts +305 -0
- package/dist/apps/examples/gamification-app.example.js +329 -0
- package/dist/apps/examples/gamification-app.example.js.map +1 -0
- package/dist/apps/index.d.ts +18 -0
- package/dist/apps/index.js +26 -0
- package/dist/apps/index.js.map +1 -0
- package/dist/apps/types.d.ts +231 -0
- package/dist/apps/types.js +8 -0
- package/dist/apps/types.js.map +1 -0
- package/dist/bootstrap.d.ts +24 -0
- package/dist/bootstrap.js +133 -33
- package/dist/bootstrap.js.map +1 -1
- package/dist/components/ShadowCanvasOverlay.js +36 -9
- package/dist/components/ShadowCanvasOverlay.js.map +1 -1
- package/dist/components/TileCard.js +37 -18
- package/dist/components/TileCard.js.map +1 -1
- package/dist/context/schema.d.ts +16 -16
- package/dist/decisions/schema.d.ts +96 -96
- package/dist/earlyPatcher.d.ts +8 -20
- package/dist/earlyPatcher.js +13 -62
- package/dist/earlyPatcher.js.map +1 -1
- package/dist/editorLoader.d.ts +2 -0
- package/dist/editorLoader.js +46 -7
- package/dist/editorLoader.js.map +1 -1
- package/dist/events/normalizers/posthog.d.ts +24 -0
- package/dist/events/normalizers/posthog.js.map +1 -1
- package/dist/events/schema.d.ts +8 -8
- package/dist/events/types.d.ts +6 -0
- package/dist/events/types.js +8 -0
- package/dist/events/types.js.map +1 -1
- package/dist/hooks/useCanvasOverlays.d.ts +4 -1
- package/dist/hooks/useCanvasOverlays.js +53 -6
- package/dist/hooks/useCanvasOverlays.js.map +1 -1
- package/dist/hooks/useShadowCanvasConfig.d.ts +3 -7
- package/dist/hooks/useShadowCanvasConfig.js +2 -3
- package/dist/hooks/useShadowCanvasConfig.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/overlays/schema.d.ts +153 -153
- package/dist/runtime.d.ts +24 -0
- package/dist/runtime.js +75 -1
- package/dist/runtime.js.map +1 -1
- package/dist/smart-canvas.esm.js +162 -55
- package/dist/smart-canvas.esm.js.map +4 -4
- package/dist/smart-canvas.js +21133 -17957
- package/dist/smart-canvas.js.map +4 -4
- package/dist/smart-canvas.min.js +162 -55
- package/dist/smart-canvas.min.js.map +4 -4
- package/dist/store/example.d.ts +1 -0
- package/dist/store/example.js +43 -0
- package/dist/store/example.js.map +1 -0
- package/dist/store/mini-effector.d.ts +46 -0
- package/dist/store/mini-effector.js +90 -0
- package/dist/store/mini-effector.js.map +1 -0
- package/dist/surfaces/Surfaces.d.ts +11 -0
- package/dist/surfaces/Surfaces.js +361 -0
- package/dist/surfaces/Surfaces.js.map +1 -0
- package/dist/surfaces/index.d.ts +9 -0
- package/dist/surfaces/index.js +12 -0
- package/dist/surfaces/index.js.map +1 -0
- package/dist/surfaces/positioning.d.ts +50 -0
- package/dist/surfaces/positioning.js +231 -0
- package/dist/surfaces/positioning.js.map +1 -0
- package/dist/surfaces/types.d.ts +167 -0
- package/dist/surfaces/types.js +23 -0
- package/dist/surfaces/types.js.map +1 -0
- package/dist/telemetry/adapters/posthog.d.ts +6 -0
- package/dist/telemetry/adapters/posthog.js +9 -0
- package/dist/telemetry/adapters/posthog.js.map +1 -1
- package/dist/types-only.d.ts +32 -0
- package/dist/types-only.js +11 -0
- package/dist/types-only.js.map +1 -0
- package/dist/types.d.ts +26 -14
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/widgets/WidgetRegistry.d.ts +139 -0
- package/dist/widgets/WidgetRegistry.js +182 -0
- package/dist/widgets/WidgetRegistry.js.map +1 -0
- package/dist/widgets/index.d.ts +7 -0
- package/dist/widgets/index.js +7 -0
- package/dist/widgets/index.js.map +1 -0
- package/package.json +13 -3
- package/schema/canvas-config.schema.json +444 -254
package/dist/SmartCanvasApp.js
CHANGED
|
@@ -3,8 +3,7 @@ import { useEffect, useMemo, useState } from "react";
|
|
|
3
3
|
import { ShadowCanvasOverlay } from "./components/ShadowCanvasOverlay";
|
|
4
4
|
import { useShadowCanvasConfig } from "./hooks/useShadowCanvasConfig";
|
|
5
5
|
import { createCanvasConfigFetcher } from "./configFetcher";
|
|
6
|
-
import {
|
|
7
|
-
import { useHostPatches } from "./hooks/useHostPatches";
|
|
6
|
+
import { RuntimeProvider, usePageContext } from "./RuntimeProvider";
|
|
8
7
|
/**
|
|
9
8
|
* Check if current route is allowed based on routes config
|
|
10
9
|
*/
|
|
@@ -33,15 +32,36 @@ function matchRoute(pattern, pathname) {
|
|
|
33
32
|
}
|
|
34
33
|
return pathname === pattern;
|
|
35
34
|
}
|
|
36
|
-
export function SmartCanvasApp({ controller, fetcher, configUri, configUriFeatureKey = "smart-canvas-config-uri", configFeatureKey = "smart-canvas-config", fetchCredentials = "include", pollIntervalMs, experiments, telemetry, overlayFetcher, overlayConfigUri, overlayConfigFeatureKey = "smart-canvas-overlay-uri", overlayFetchCredentials = "include", footerSlot, launcherLabel, canvasHost, customRenderers, theme, }) {
|
|
35
|
+
export function SmartCanvasApp({ controller, fetcher, configUri, configUriFeatureKey = "smart-canvas-config-uri", configFeatureKey = "smart-canvas-config", fetchCredentials = "include", pollIntervalMs, experiments, telemetry, runtime, overlayFetcher, overlayConfigUri, overlayConfigFeatureKey = "smart-canvas-overlay-uri", overlayFetchCredentials = "include", footerSlot, launcherLabel, canvasHost, customRenderers, theme, }) {
|
|
36
|
+
// Wrap the app with RuntimeProvider if runtime is available
|
|
37
|
+
if (runtime) {
|
|
38
|
+
return (_jsx(RuntimeProvider, { runtime: runtime, children: _jsx(SmartCanvasAppInner, { controller: controller, fetcher: fetcher, configUri: configUri, configUriFeatureKey: configUriFeatureKey, configFeatureKey: configFeatureKey, fetchCredentials: fetchCredentials, pollIntervalMs: pollIntervalMs, experiments: experiments, telemetry: telemetry, runtime: runtime, overlayFetcher: overlayFetcher, overlayConfigUri: overlayConfigUri, overlayConfigFeatureKey: overlayConfigFeatureKey, overlayFetchCredentials: overlayFetchCredentials, footerSlot: footerSlot, launcherLabel: launcherLabel, canvasHost: canvasHost, customRenderers: customRenderers, theme: theme }) }));
|
|
39
|
+
}
|
|
40
|
+
// No runtime - render directly (legacy mode)
|
|
41
|
+
return (_jsx(SmartCanvasAppInner, { controller: controller, fetcher: fetcher, configUri: configUri, configUriFeatureKey: configUriFeatureKey, configFeatureKey: configFeatureKey, fetchCredentials: fetchCredentials, pollIntervalMs: pollIntervalMs, experiments: experiments, telemetry: telemetry, overlayFetcher: overlayFetcher, overlayConfigUri: overlayConfigUri, overlayConfigFeatureKey: overlayConfigFeatureKey, overlayFetchCredentials: overlayFetchCredentials, footerSlot: footerSlot, launcherLabel: launcherLabel, canvasHost: canvasHost, customRenderers: customRenderers, theme: theme }));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Inner component that handles the actual rendering logic.
|
|
45
|
+
* Separated to allow RuntimeProvider to wrap it when runtime is available.
|
|
46
|
+
*/
|
|
47
|
+
function SmartCanvasAppInner({ controller, fetcher, configUri, configUriFeatureKey = "smart-canvas-config-uri", configFeatureKey = "smart-canvas-config", fetchCredentials = "include", pollIntervalMs, experiments, telemetry, runtime, overlayFetcher, overlayConfigUri, overlayConfigFeatureKey = "smart-canvas-overlay-uri", overlayFetchCredentials = "include", footerSlot, launcherLabel, canvasHost, customRenderers, theme, }) {
|
|
37
48
|
var _a, _b, _c;
|
|
38
49
|
const [open, setOpen] = useState(controller.getState().open);
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
// Use runtime context for pathname if available, otherwise track locally
|
|
51
|
+
const pageContext = usePageContext();
|
|
52
|
+
const [localPathname, setLocalPathname] = useState(() => typeof window !== "undefined" ? window.location.pathname : "/");
|
|
53
|
+
// If runtime is available, use its context for pathname (it already handles SPA navigation)
|
|
54
|
+
// Otherwise, track pathname locally (legacy mode)
|
|
55
|
+
const pathname = (pageContext === null || pageContext === void 0 ? void 0 : pageContext.url)
|
|
56
|
+
? new URL(pageContext.url).pathname
|
|
57
|
+
: localPathname;
|
|
58
|
+
// Track route changes locally only when runtime is not available (legacy mode)
|
|
41
59
|
useEffect(() => {
|
|
60
|
+
if (runtime)
|
|
61
|
+
return; // Runtime handles this via ContextManager
|
|
42
62
|
if (typeof window === "undefined")
|
|
43
63
|
return;
|
|
44
|
-
const updatePathname = () =>
|
|
64
|
+
const updatePathname = () => setLocalPathname(window.location.pathname);
|
|
45
65
|
// Listen for popstate (back/forward navigation)
|
|
46
66
|
window.addEventListener("popstate", updatePathname);
|
|
47
67
|
// Intercept pushState/replaceState for SPA navigation
|
|
@@ -60,7 +80,7 @@ export function SmartCanvasApp({ controller, fetcher, configUri, configUriFeatur
|
|
|
60
80
|
history.pushState = originalPushState;
|
|
61
81
|
history.replaceState = originalReplaceState;
|
|
62
82
|
};
|
|
63
|
-
}, []);
|
|
83
|
+
}, [runtime]);
|
|
64
84
|
const derivedFetcher = useMemo(() => {
|
|
65
85
|
if (fetcher)
|
|
66
86
|
return fetcher;
|
|
@@ -76,6 +96,7 @@ export function SmartCanvasApp({ controller, fetcher, configUri, configUriFeatur
|
|
|
76
96
|
fetcher: derivedFetcher,
|
|
77
97
|
pollIntervalMs,
|
|
78
98
|
experiments,
|
|
99
|
+
runtime,
|
|
79
100
|
});
|
|
80
101
|
const hasContent = configState.tiles.length > 0 && !configState.error;
|
|
81
102
|
useEffect(() => controller.subscribe((state) => setOpen(state.open)), [controller]);
|
|
@@ -84,38 +105,15 @@ export function SmartCanvasApp({ controller, fetcher, configUri, configUriFeatur
|
|
|
84
105
|
controller.setOpen(false);
|
|
85
106
|
}
|
|
86
107
|
}, [controller, hasContent]);
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return async () => configState.overlayRecipes;
|
|
95
|
-
}
|
|
96
|
-
if (configState.overlayRecipe) {
|
|
97
|
-
return async () => configState.overlayRecipe;
|
|
98
|
-
}
|
|
99
|
-
// Don't create a fetcher if there's no URI and we're still loading config
|
|
100
|
-
if (!overlayConfigUri && configState.isLoading) {
|
|
101
|
-
return undefined;
|
|
108
|
+
// Apply actions when config loads
|
|
109
|
+
// Actions are processed by ActionEngine through the runtime
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if ((runtime === null || runtime === void 0 ? void 0 : runtime.actions) && configState.actions.length > 0) {
|
|
112
|
+
runtime.actions.applyBatch(configState.actions).catch((err) => {
|
|
113
|
+
console.error('[SmartCanvas] Failed to apply actions:', err);
|
|
114
|
+
});
|
|
102
115
|
}
|
|
103
|
-
|
|
104
|
-
}, [overlayFetcher, configState.overlayRecipes, configState.overlayRecipe, configState.isLoading, overlayConfigUri]);
|
|
105
|
-
useCanvasOverlays({
|
|
106
|
-
recipesFetcher: derivedOverlayRecipesFetcher,
|
|
107
|
-
configUri: !derivedOverlayRecipesFetcher && !configState.isLoading ? overlayConfigUri : undefined,
|
|
108
|
-
featureKey: overlayConfigFeatureKey,
|
|
109
|
-
credentials: overlayFetchCredentials,
|
|
110
|
-
experiments,
|
|
111
|
-
telemetry,
|
|
112
|
-
canvasHost,
|
|
113
|
-
});
|
|
114
|
-
useHostPatches({
|
|
115
|
-
patches: configState.patches,
|
|
116
|
-
telemetry,
|
|
117
|
-
canvasHost,
|
|
118
|
-
});
|
|
116
|
+
}, [runtime, configState.actions]);
|
|
119
117
|
// Merge theme from config (workspace settings) with any direct theme prop
|
|
120
118
|
// Config theme takes precedence for workspace-set values, but theme prop can override
|
|
121
119
|
// NOTE: This must be called BEFORE any early returns to maintain consistent hook order
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartCanvasApp.js","sourceRoot":"","sources":["../src/SmartCanvasApp.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAa,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAGvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"SmartCanvasApp.js","sourceRoot":"","sources":["../src/SmartCanvasApp.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAa,SAAS,E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execution layer for interventions. Provides a high-level API for
|
|
5
|
+
* applying, reverting, and managing action steps.
|
|
6
|
+
*/
|
|
7
|
+
import type { ActionEngine, ActionEngineOptions } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Create an ActionEngine instance.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createActionEngine(options: ActionEngineOptions): ActionEngine;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ActionEngine
|
|
3
|
+
*
|
|
4
|
+
* Unified execution layer for interventions. Provides a high-level API for
|
|
5
|
+
* applying, reverting, and managing action steps.
|
|
6
|
+
*/
|
|
7
|
+
import { validateAction, validateActions } from "./validation";
|
|
8
|
+
import { executorRegistry as defaultExecutorRegistry } from "./executors";
|
|
9
|
+
/** Counter for generating unique action IDs */
|
|
10
|
+
let actionIdCounter = 0;
|
|
11
|
+
/**
|
|
12
|
+
* Create an ActionEngine instance.
|
|
13
|
+
*/
|
|
14
|
+
export function createActionEngine(options) {
|
|
15
|
+
const { overlayRoot, eventBus, surfaces, anchorResolver, adaptiveId, executorRegistry = defaultExecutorRegistry, } = options;
|
|
16
|
+
/** Map of active actions by ID */
|
|
17
|
+
const activeActions = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Generate a unique action ID.
|
|
20
|
+
*/
|
|
21
|
+
function generateId() {
|
|
22
|
+
return `action-${++actionIdCounter}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Publish an event to the EventBus if available.
|
|
26
|
+
*/
|
|
27
|
+
function publishEvent(name, props) {
|
|
28
|
+
if (eventBus) {
|
|
29
|
+
eventBus.publish(name, props);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create the executor context.
|
|
34
|
+
*/
|
|
35
|
+
function createExecutorContext() {
|
|
36
|
+
return {
|
|
37
|
+
overlayRoot,
|
|
38
|
+
resolveAnchor: anchorResolver,
|
|
39
|
+
generateId,
|
|
40
|
+
publishEvent,
|
|
41
|
+
adaptiveId,
|
|
42
|
+
// Allow composite executors (like tours) to execute nested actions
|
|
43
|
+
applyAction: apply,
|
|
44
|
+
// Allow composite executors to subscribe to events
|
|
45
|
+
subscribeEvent: eventBus
|
|
46
|
+
? (name, callback) => {
|
|
47
|
+
return eventBus.subscribe({ names: [name] }, (event) => callback(event.props));
|
|
48
|
+
}
|
|
49
|
+
: undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Execute a mountWidget action via Surfaces.
|
|
54
|
+
*/
|
|
55
|
+
async function executeMountWidget(action, context) {
|
|
56
|
+
if (!surfaces) {
|
|
57
|
+
throw new Error("Surfaces provider required for core:mountWidget actions");
|
|
58
|
+
}
|
|
59
|
+
const handle = surfaces.mount(action.slot, {
|
|
60
|
+
type: "widget",
|
|
61
|
+
widgetId: action.widget.widgetId,
|
|
62
|
+
config: action.widget.props,
|
|
63
|
+
}, {
|
|
64
|
+
priority: action.widget.priority,
|
|
65
|
+
});
|
|
66
|
+
context.publishEvent("action.applied", {
|
|
67
|
+
id: context.generateId(),
|
|
68
|
+
kind: "core:mountWidget",
|
|
69
|
+
slot: action.slot,
|
|
70
|
+
widgetId: action.widget.widgetId,
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
cleanup: () => {
|
|
74
|
+
handle.unmount();
|
|
75
|
+
},
|
|
76
|
+
updateFn: (changes) => {
|
|
77
|
+
if ("widget" in changes && changes.widget) {
|
|
78
|
+
const w = changes.widget;
|
|
79
|
+
if (w.props) {
|
|
80
|
+
handle.update({
|
|
81
|
+
type: "widget",
|
|
82
|
+
widgetId: action.widget.widgetId,
|
|
83
|
+
config: w.props,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Apply a single action.
|
|
92
|
+
*/
|
|
93
|
+
async function apply(action) {
|
|
94
|
+
const validation = validateAction(action);
|
|
95
|
+
if (!validation.valid) {
|
|
96
|
+
const errorMessages = validation.errors.map((e) => e.message).join("; ");
|
|
97
|
+
throw new Error(`Action validation failed: ${errorMessages}`);
|
|
98
|
+
}
|
|
99
|
+
const id = generateId();
|
|
100
|
+
const context = createExecutorContext();
|
|
101
|
+
let result;
|
|
102
|
+
// Special handling for mountWidget
|
|
103
|
+
if (action.kind === "core:mountWidget") {
|
|
104
|
+
result = await executeMountWidget(action, context);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const executor = executorRegistry.get(action.kind);
|
|
108
|
+
if (!executor) {
|
|
109
|
+
throw new Error(`No executor for action kind: ${action.kind}`);
|
|
110
|
+
}
|
|
111
|
+
result = await executor(action, context);
|
|
112
|
+
}
|
|
113
|
+
// Track active action
|
|
114
|
+
const entry = {
|
|
115
|
+
id,
|
|
116
|
+
action,
|
|
117
|
+
adaptiveId,
|
|
118
|
+
appliedTs: Date.now(),
|
|
119
|
+
state: "applied",
|
|
120
|
+
cleanup: result.cleanup,
|
|
121
|
+
updateFn: result.updateFn,
|
|
122
|
+
};
|
|
123
|
+
activeActions.set(id, entry);
|
|
124
|
+
// Publish applied event
|
|
125
|
+
publishEvent("action.applied", {
|
|
126
|
+
id,
|
|
127
|
+
kind: action.kind,
|
|
128
|
+
anchorId: "anchorId" in action ? action.anchorId : undefined,
|
|
129
|
+
});
|
|
130
|
+
// Create and return handle
|
|
131
|
+
const handle = {
|
|
132
|
+
id,
|
|
133
|
+
action,
|
|
134
|
+
async revert() {
|
|
135
|
+
const entry = activeActions.get(id);
|
|
136
|
+
if (!entry || entry.state !== "applied")
|
|
137
|
+
return;
|
|
138
|
+
try {
|
|
139
|
+
await entry.cleanup();
|
|
140
|
+
entry.state = "reverted";
|
|
141
|
+
publishEvent("action.reverted", { id, kind: action.kind });
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
entry.state = "failed";
|
|
145
|
+
publishEvent("action.failed", {
|
|
146
|
+
id,
|
|
147
|
+
kind: action.kind,
|
|
148
|
+
error: String(error),
|
|
149
|
+
});
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
activeActions.delete(id);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
isApplied() {
|
|
157
|
+
const entry = activeActions.get(id);
|
|
158
|
+
return (entry === null || entry === void 0 ? void 0 : entry.state) === "applied";
|
|
159
|
+
},
|
|
160
|
+
async update(changes) {
|
|
161
|
+
const entry = activeActions.get(id);
|
|
162
|
+
if (!entry || entry.state !== "applied") {
|
|
163
|
+
throw new Error("Cannot update action that is not applied");
|
|
164
|
+
}
|
|
165
|
+
if (entry.updateFn) {
|
|
166
|
+
await entry.updateFn(changes);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
throw new Error(`Action kind ${action.kind} does not support updates`);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
getState() {
|
|
173
|
+
var _a;
|
|
174
|
+
const entry = activeActions.get(id);
|
|
175
|
+
return (_a = entry === null || entry === void 0 ? void 0 : entry.state) !== null && _a !== void 0 ? _a : "reverted";
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
return handle;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Apply multiple actions as a batch.
|
|
182
|
+
*/
|
|
183
|
+
async function applyBatch(actions) {
|
|
184
|
+
const validation = validateActions(actions);
|
|
185
|
+
if (!validation.valid) {
|
|
186
|
+
const errorMessages = validation.errors.map((e) => e.message).join("; ");
|
|
187
|
+
throw new Error(`Batch validation failed: ${errorMessages}`);
|
|
188
|
+
}
|
|
189
|
+
const batchId = generateId();
|
|
190
|
+
const handles = [];
|
|
191
|
+
const appliedHandles = [];
|
|
192
|
+
try {
|
|
193
|
+
for (const action of actions) {
|
|
194
|
+
const handle = await apply(action);
|
|
195
|
+
handles.push(handle);
|
|
196
|
+
appliedHandles.push(handle);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
// Rollback on failure
|
|
201
|
+
for (const handle of appliedHandles) {
|
|
202
|
+
try {
|
|
203
|
+
await handle.revert();
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
// Ignore cleanup errors during rollback
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
const batchHandle = {
|
|
212
|
+
id: batchId,
|
|
213
|
+
handles,
|
|
214
|
+
async revertAll() {
|
|
215
|
+
// Revert in reverse order
|
|
216
|
+
for (let i = handles.length - 1; i >= 0; i--) {
|
|
217
|
+
try {
|
|
218
|
+
await handles[i].revert();
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
console.error(`[ActionEngine] Error reverting action ${handles[i].id}:`, error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
isApplied() {
|
|
226
|
+
return handles.every((h) => h.isApplied());
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
return batchHandle;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Validate an action without applying it.
|
|
233
|
+
*/
|
|
234
|
+
function validate(action) {
|
|
235
|
+
return validateAction(action);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get all currently active actions.
|
|
239
|
+
*/
|
|
240
|
+
function getActive() {
|
|
241
|
+
return Array.from(activeActions.values()).map((entry) => ({
|
|
242
|
+
id: entry.id,
|
|
243
|
+
action: entry.action,
|
|
244
|
+
adaptiveId: entry.adaptiveId,
|
|
245
|
+
appliedTs: entry.appliedTs,
|
|
246
|
+
state: entry.state,
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Clean up all active actions.
|
|
251
|
+
*/
|
|
252
|
+
function destroy() {
|
|
253
|
+
// Revert all active actions
|
|
254
|
+
for (const entry of activeActions.values()) {
|
|
255
|
+
if (entry.state === "applied") {
|
|
256
|
+
try {
|
|
257
|
+
entry.cleanup();
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
console.error(`[ActionEngine] Error during cleanup:`, error);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
activeActions.clear();
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
apply,
|
|
268
|
+
applyBatch,
|
|
269
|
+
validate,
|
|
270
|
+
getActive,
|
|
271
|
+
destroy,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=ActionEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActionEngine.js","sourceRoot":"","sources":["../../src/actions/ActionEngine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,gBAAgB,IAAI,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE1E,+CAA+C;AAC/C,IAAI,eAAe,GAAG,CAAC,CAAC;AAExB;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA4B;IAC7D,MAAM,EACJ,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,UAAU,EACV,gBAAgB,GAAG,uBAAuB,GAC3C,GAAG,OAAO,CAAC;IAEZ,kCAAkC;IAClC,MAAM,aAAa,GAAG,IAAI,GAAG,EAA+B,CAAC;IAE7D;;OAEG;IACH,SAAS,UAAU;QACjB,OAAO,UAAU,EAAE,eAAe,EAAE,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,SAAS,YAAY,CAAC,IAAY,EAAE,KAA+B;QACjE,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS,qBAAqB;QAC5B,OAAO;YACL,WAAW;YACX,aAAa,EAAE,cAAc;Y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their executor functions.
|
|
5
|
+
* Apps can register custom executors at runtime.
|
|
6
|
+
*
|
|
7
|
+
* Core app executors are imported from their respective app packages.
|
|
8
|
+
*/
|
|
9
|
+
import type { ActionStep, ActionKind, ActionExecutor, ValidationResult } from "../types";
|
|
10
|
+
import type { ZodSchema } from "zod";
|
|
11
|
+
/**
|
|
12
|
+
* Registration entry for an executor.
|
|
13
|
+
*/
|
|
14
|
+
export interface ExecutorRegistration {
|
|
15
|
+
kind: string;
|
|
16
|
+
executor: ActionExecutor<any>;
|
|
17
|
+
schema?: ZodSchema;
|
|
18
|
+
source: string;
|
|
19
|
+
isBuiltIn: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extensible registry for action executors.
|
|
23
|
+
*
|
|
24
|
+
* Core executors (setText, highlight, etc.) are registered synchronously
|
|
25
|
+
* at construction time for immediate availability - no async loading.
|
|
26
|
+
*
|
|
27
|
+
* External app executors are registered when apps activate.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ExecutorRegistry {
|
|
30
|
+
private executors;
|
|
31
|
+
/**
|
|
32
|
+
* Constructor - registers core executors synchronously.
|
|
33
|
+
* These are available IMMEDIATELY when the module loads,
|
|
34
|
+
* enabling instant action execution without waiting for app activation.
|
|
35
|
+
*/
|
|
36
|
+
constructor();
|
|
37
|
+
/**
|
|
38
|
+
* Register a core executor (synchronous, built-in, cannot be overridden).
|
|
39
|
+
*/
|
|
40
|
+
private registerCore;
|
|
41
|
+
/**
|
|
42
|
+
* Register an executor for an action kind.
|
|
43
|
+
*
|
|
44
|
+
* @param kind - The action kind (e.g., "gamification:awardBadge")
|
|
45
|
+
* @param executor - The executor function
|
|
46
|
+
* @param schema - Optional Zod schema for validation
|
|
47
|
+
* @param source - The source app ID (for tracking)
|
|
48
|
+
* @param isBuiltIn - Whether this is from a built-in app (prevents override)
|
|
49
|
+
*/
|
|
50
|
+
register(kind: string, executor: ActionExecutor<any>, schema?: ZodSchema, source?: string, isBuiltIn?: boolean): void;
|
|
51
|
+
/**
|
|
52
|
+
* Unregister an executor.
|
|
53
|
+
*
|
|
54
|
+
* @param kind - The action kind to unregister
|
|
55
|
+
* @returns true if the executor was unregistered, false if not found or built-in
|
|
56
|
+
*/
|
|
57
|
+
unregister(kind: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Unregister all executors from a specific source.
|
|
60
|
+
*
|
|
61
|
+
* @param source - The source app ID
|
|
62
|
+
*/
|
|
63
|
+
unregisterBySource(source: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Get the executor for an action kind.
|
|
66
|
+
*/
|
|
67
|
+
get(kind: string): ActionExecutor<ActionStep> | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Get the full registration for an action kind.
|
|
70
|
+
*/
|
|
71
|
+
getRegistration(kind: string): ExecutorRegistration | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Check if an executor exists for a given action kind.
|
|
74
|
+
*/
|
|
75
|
+
has(kind: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Validate an action using its registered schema.
|
|
78
|
+
*
|
|
79
|
+
* @param action - The action to validate
|
|
80
|
+
* @returns Validation result
|
|
81
|
+
*/
|
|
82
|
+
validate(action: unknown): ValidationResult;
|
|
83
|
+
/**
|
|
84
|
+
* List all registered action kinds.
|
|
85
|
+
*/
|
|
86
|
+
list(): string[];
|
|
87
|
+
/**
|
|
88
|
+
* List all registrations.
|
|
89
|
+
*/
|
|
90
|
+
listRegistrations(): ExecutorRegistration[];
|
|
91
|
+
/**
|
|
92
|
+
* Get all built-in action kinds.
|
|
93
|
+
*/
|
|
94
|
+
getBuiltInKinds(): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Get all custom action kinds.
|
|
97
|
+
*/
|
|
98
|
+
getCustomKinds(): string[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Default singleton instance of ExecutorRegistry.
|
|
102
|
+
*/
|
|
103
|
+
export declare const executorRegistry: ExecutorRegistry;
|
|
104
|
+
/**
|
|
105
|
+
* Get the executor for an action kind.
|
|
106
|
+
* @deprecated Use executorRegistry.get() instead
|
|
107
|
+
*/
|
|
108
|
+
export declare function getExecutor(kind: ActionKind | string): ActionExecutor<ActionStep> | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Check if an executor exists for a given action kind.
|
|
111
|
+
* @deprecated Use executorRegistry.has() instead
|
|
112
|
+
*/
|
|
113
|
+
export declare function hasExecutor(kind: ActionKind | string): boolean;
|
|
114
|
+
export { executeInsertHtml, executeSetText, executeSetAttr, executeAddClass, executeRemoveClass, executeSetStyle, } from "@syntrologie/app-content/runtime";
|
|
115
|
+
export { executeHighlight, executePulse, executeBadge, executeTooltip, executeModal, } from "@syntrologie/app-overlays/runtime";
|
|
116
|
+
export { executeScrollTo, executeNavigate, } from "@syntrologie/app-navigation/runtime";
|
|
117
|
+
export { executeAwardBadge, executeAddPoints, } from "@syntrologie/app-gamification/runtime";
|
|
118
|
+
export { executeTour } from "./tour";
|