@mydatavalue/polter 0.1.1 → 0.1.3
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.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -328,7 +328,7 @@ async function resolveStepElement(target, actionName, params, config) {
|
|
|
328
328
|
return config.resolveTarget(actionName, target.fromParam, paramValue, config.signal);
|
|
329
329
|
}
|
|
330
330
|
if (target.fromTarget && config.resolveNamedTarget) {
|
|
331
|
-
return config.resolveNamedTarget(actionName, target.fromTarget, config.signal);
|
|
331
|
+
return config.resolveNamedTarget(actionName, target.fromTarget, config.signal, params);
|
|
332
332
|
}
|
|
333
333
|
return target.element;
|
|
334
334
|
}
|
|
@@ -540,7 +540,7 @@ function AgentActionProvider({
|
|
|
540
540
|
[]
|
|
541
541
|
);
|
|
542
542
|
const resolveNamedTarget = useCallback(
|
|
543
|
-
async (actionName, name, signal) => {
|
|
543
|
+
async (actionName, name, signal, params) => {
|
|
544
544
|
const maxWait = 3e3;
|
|
545
545
|
const pollInterval = 50;
|
|
546
546
|
const start = Date.now();
|
|
@@ -548,6 +548,9 @@ function AgentActionProvider({
|
|
|
548
548
|
if (signal?.aborted) return null;
|
|
549
549
|
for (const entry of targetsRef.current.values()) {
|
|
550
550
|
if ((!entry.action || entry.action === actionName) && entry.name === name && entry.element.isConnected) {
|
|
551
|
+
if (entry.prepareView && params) {
|
|
552
|
+
await entry.prepareView(params);
|
|
553
|
+
}
|
|
551
554
|
return entry.element;
|
|
552
555
|
}
|
|
553
556
|
}
|
|
@@ -565,7 +568,7 @@ function AgentActionProvider({
|
|
|
565
568
|
while (Date.now() - start < maxWait) {
|
|
566
569
|
if (signal?.aborted) return null;
|
|
567
570
|
const current = actionsRef.current.get(name);
|
|
568
|
-
if (current && current.getExecutionTargets().length > 0) {
|
|
571
|
+
if (current && (current.componentBacked || current.getExecutionTargets().length > 0)) {
|
|
569
572
|
return current;
|
|
570
573
|
}
|
|
571
574
|
await new Promise((r) => setTimeout(r, pollInterval));
|
|
@@ -604,6 +607,15 @@ function AgentActionProvider({
|
|
|
604
607
|
resolveTarget,
|
|
605
608
|
resolveNamedTarget
|
|
606
609
|
};
|
|
610
|
+
const schema = action.parameters;
|
|
611
|
+
if (schema?.safeParse) {
|
|
612
|
+
const validation = schema.safeParse(params ?? {});
|
|
613
|
+
if (!validation.success) {
|
|
614
|
+
const missing = validation.error.issues.map((i) => i.path.join(".")).filter(Boolean);
|
|
615
|
+
const error = missing.length > 0 ? `Required parameters missing: ${missing.join(", ")}` : validation.error.issues.map((i) => i.message).join("; ");
|
|
616
|
+
return { success: false, actionName, error };
|
|
617
|
+
}
|
|
618
|
+
}
|
|
607
619
|
if (action.navigateVia && action.navigateVia.length > 0) {
|
|
608
620
|
for (const viaName of action.navigateVia) {
|
|
609
621
|
if (controller.signal.aborted) break;
|
|
@@ -627,7 +639,7 @@ function AgentActionProvider({
|
|
|
627
639
|
}
|
|
628
640
|
}
|
|
629
641
|
const mounted = await waitForActionMount(actionName, controller.signal, action.mountTimeout ?? 1e4);
|
|
630
|
-
if (!mounted || mounted.
|
|
642
|
+
if (!mounted || !mounted.componentBacked) {
|
|
631
643
|
return {
|
|
632
644
|
success: false,
|
|
633
645
|
actionName,
|
|
@@ -779,7 +791,8 @@ function AgentAction(props) {
|
|
|
779
791
|
onExecute: onExecuteRef.current ? stableOnExecute : void 0,
|
|
780
792
|
disabled,
|
|
781
793
|
disabledReason,
|
|
782
|
-
getExecutionTargets
|
|
794
|
+
getExecutionTargets,
|
|
795
|
+
componentBacked: true
|
|
783
796
|
});
|
|
784
797
|
return () => unregisterAction(name);
|
|
785
798
|
}, [name, description, disabled, disabledReason, stableOnExecute, getExecutionTargets, registerAction, unregisterAction]);
|
|
@@ -836,10 +849,12 @@ function AgentStep({
|
|
|
836
849
|
if (!children) return null;
|
|
837
850
|
return /* @__PURE__ */ jsx("div", { ref: wrapperRef, style: { display: "contents" }, children });
|
|
838
851
|
}
|
|
839
|
-
function AgentTarget({ action, param, value, name, children }) {
|
|
852
|
+
function AgentTarget({ action, param, value, name, prepareView, children }) {
|
|
840
853
|
const id = useId();
|
|
841
854
|
const wrapperRef = useRef(null);
|
|
842
855
|
const context = useContext(AgentActionContext);
|
|
856
|
+
const prepareViewRef = useRef(prepareView);
|
|
857
|
+
prepareViewRef.current = prepareView;
|
|
843
858
|
if (!context) {
|
|
844
859
|
throw new Error("AgentTarget must be used within an AgentActionProvider");
|
|
845
860
|
}
|
|
@@ -847,7 +862,7 @@ function AgentTarget({ action, param, value, name, children }) {
|
|
|
847
862
|
useEffect(() => {
|
|
848
863
|
const element = wrapperRef.current?.firstElementChild;
|
|
849
864
|
if (element) {
|
|
850
|
-
registerTarget(id, { action, param, value, name, element });
|
|
865
|
+
registerTarget(id, { action, param, value, name, element, prepareView: prepareViewRef.current });
|
|
851
866
|
}
|
|
852
867
|
return () => unregisterTarget(id);
|
|
853
868
|
}, [id, action, param, value, name, registerTarget, unregisterTarget]);
|