@mydatavalue/polter 0.1.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/LICENSE +21 -0
- package/README.md +330 -0
- package/dist/index.d.mts +220 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.js +1274 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1263 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +68 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React$1 from 'react';
|
|
3
|
+
|
|
4
|
+
type ExecutionMode = 'guided' | 'instant';
|
|
5
|
+
interface ExecutionTarget {
|
|
6
|
+
label: string;
|
|
7
|
+
element: HTMLElement | null;
|
|
8
|
+
/** Resolve element from AgentTarget registry by matching this param's value. */
|
|
9
|
+
fromParam?: string;
|
|
10
|
+
/** Resolve element from AgentTarget registry by matching a named target. */
|
|
11
|
+
fromTarget?: string;
|
|
12
|
+
/** Simulate typing the value of this param into the element. */
|
|
13
|
+
setParam?: string;
|
|
14
|
+
/** Set a value programmatically via onSetValue callback. */
|
|
15
|
+
setValue?: string;
|
|
16
|
+
onSetValue?: (value: unknown) => void;
|
|
17
|
+
/** Run a callback to prepare the DOM (e.g. scroll virtualized list) before resolving. */
|
|
18
|
+
prepareView?: (params: Record<string, unknown>) => void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
interface AgentTargetEntry {
|
|
21
|
+
/** Action name — when omitted, the target is shared and matches any action. */
|
|
22
|
+
action?: string;
|
|
23
|
+
element: HTMLElement;
|
|
24
|
+
/** Parameter key — used with `value` for param-based resolution. */
|
|
25
|
+
param?: string;
|
|
26
|
+
/** Parameter value — matched against the agent's param value. */
|
|
27
|
+
value?: string;
|
|
28
|
+
/** Named target key — used for static lazy resolution via `fromTarget`. */
|
|
29
|
+
name?: string;
|
|
30
|
+
}
|
|
31
|
+
interface RegisteredAction {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
parameters?: unknown;
|
|
35
|
+
onExecute?: (params: Record<string, unknown>) => void | Promise<void>;
|
|
36
|
+
disabled: boolean;
|
|
37
|
+
disabledReason?: string;
|
|
38
|
+
getExecutionTargets: () => ExecutionTarget[];
|
|
39
|
+
}
|
|
40
|
+
interface ToolSchema {
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
parameters: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
interface ExecutionResult {
|
|
46
|
+
success: boolean;
|
|
47
|
+
actionName: string;
|
|
48
|
+
error?: string;
|
|
49
|
+
}
|
|
50
|
+
interface AvailableAction {
|
|
51
|
+
name: string;
|
|
52
|
+
description: string;
|
|
53
|
+
disabled: boolean;
|
|
54
|
+
disabledReason?: string;
|
|
55
|
+
hasParameters: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface ExecutorConfig {
|
|
58
|
+
mode: ExecutionMode;
|
|
59
|
+
stepDelay: number;
|
|
60
|
+
overlayOpacity: number;
|
|
61
|
+
spotlightPadding: number;
|
|
62
|
+
tooltipEnabled: boolean;
|
|
63
|
+
cursorEnabled: boolean;
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
/** Resolve an element from the AgentTarget registry. Used by fromParam steps. */
|
|
66
|
+
resolveTarget?: (actionName: string, param: string, value: string, signal?: AbortSignal) => Promise<HTMLElement | null>;
|
|
67
|
+
/** Resolve a named target from the AgentTarget registry. Used by fromTarget steps. */
|
|
68
|
+
resolveNamedTarget?: (actionName: string, name: string, signal?: AbortSignal) => Promise<HTMLElement | null>;
|
|
69
|
+
}
|
|
70
|
+
interface AgentActionProviderProps {
|
|
71
|
+
mode?: ExecutionMode;
|
|
72
|
+
stepDelay?: number;
|
|
73
|
+
overlayOpacity?: number;
|
|
74
|
+
spotlightPadding?: number;
|
|
75
|
+
tooltipEnabled?: boolean;
|
|
76
|
+
cursorEnabled?: boolean;
|
|
77
|
+
children: React.ReactNode;
|
|
78
|
+
onExecutionStart?: (actionName: string) => void;
|
|
79
|
+
onExecutionComplete?: (result: ExecutionResult) => void;
|
|
80
|
+
}
|
|
81
|
+
interface AgentActionContextValue {
|
|
82
|
+
registerAction: (action: RegisteredAction) => void;
|
|
83
|
+
unregisterAction: (name: string) => void;
|
|
84
|
+
registerTarget: (id: string, entry: AgentTargetEntry) => void;
|
|
85
|
+
unregisterTarget: (id: string) => void;
|
|
86
|
+
execute: (actionName: string, params?: Record<string, unknown>) => Promise<ExecutionResult>;
|
|
87
|
+
availableActions: AvailableAction[];
|
|
88
|
+
schemas: ToolSchema[];
|
|
89
|
+
isExecuting: boolean;
|
|
90
|
+
mode: ExecutionMode;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare function AgentActionProvider({ mode, stepDelay, overlayOpacity, spotlightPadding, tooltipEnabled, cursorEnabled, children, onExecutionStart, onExecutionComplete, }: AgentActionProviderProps): react_jsx_runtime.JSX.Element;
|
|
94
|
+
|
|
95
|
+
interface AgentActionProps {
|
|
96
|
+
name: string;
|
|
97
|
+
description: string;
|
|
98
|
+
parameters?: unknown;
|
|
99
|
+
onExecute?: (params: Record<string, unknown>) => void | Promise<void>;
|
|
100
|
+
disabled?: boolean;
|
|
101
|
+
disabledReason?: string;
|
|
102
|
+
children?: React$1.ReactNode;
|
|
103
|
+
}
|
|
104
|
+
declare function AgentAction({ name, description, parameters, onExecute, disabled, disabledReason, children, }: AgentActionProps): react_jsx_runtime.JSX.Element | null;
|
|
105
|
+
|
|
106
|
+
interface AgentStepProps {
|
|
107
|
+
label: string;
|
|
108
|
+
children?: React$1.ReactNode;
|
|
109
|
+
/** Resolve the target element from the AgentTarget registry by matching this param's value. */
|
|
110
|
+
fromParam?: string;
|
|
111
|
+
/** Resolve a named target from the AgentTarget registry (for static elements inside popovers/dropdowns). */
|
|
112
|
+
fromTarget?: string;
|
|
113
|
+
/** Simulate typing the value of this param into the element. */
|
|
114
|
+
setParam?: string;
|
|
115
|
+
/** Set a value programmatically via onSetValue callback. */
|
|
116
|
+
setValue?: string;
|
|
117
|
+
/** Callback for setValue — receives the param value and sets it on the component. */
|
|
118
|
+
onSetValue?: (value: unknown) => void;
|
|
119
|
+
/** Run a callback to prepare the DOM (e.g. scroll a virtualized list) before resolving the target. */
|
|
120
|
+
prepareView?: (params: Record<string, unknown>) => void | Promise<void>;
|
|
121
|
+
}
|
|
122
|
+
declare function AgentStep({ label, children, fromParam, fromTarget, setParam, setValue, onSetValue, prepareView, }: AgentStepProps): react_jsx_runtime.JSX.Element | null;
|
|
123
|
+
|
|
124
|
+
interface AgentTargetProps {
|
|
125
|
+
/** The action name this target belongs to. Omit to make a shared target that any action can resolve. */
|
|
126
|
+
action?: string;
|
|
127
|
+
children: React$1.ReactNode;
|
|
128
|
+
/** The parameter key this target maps to (for fromParam resolution). */
|
|
129
|
+
param?: string;
|
|
130
|
+
/** The parameter value this target represents (for fromParam resolution). */
|
|
131
|
+
value?: string;
|
|
132
|
+
/** Named target key (for fromTarget resolution — static elements inside popovers/dropdowns). */
|
|
133
|
+
name?: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Register a DOM element as a selectable target for an agent action step.
|
|
137
|
+
*
|
|
138
|
+
* Use this to wrap lazily-rendered elements (dropdown options, search results, etc.)
|
|
139
|
+
* so that `AgentStep fromParam` or `AgentStep fromTarget` can find and interact
|
|
140
|
+
* with them after they mount.
|
|
141
|
+
*
|
|
142
|
+
* Works through React portals — context flows regardless of DOM position.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```tsx
|
|
146
|
+
* // Dynamic: match by param value (inside a dropdown's renderOption):
|
|
147
|
+
* <AgentTarget action="filter_by_tag" param="tag_name" value={option.label}>
|
|
148
|
+
* <DropdownOption>{option.label}</DropdownOption>
|
|
149
|
+
* </AgentTarget>
|
|
150
|
+
*
|
|
151
|
+
* // Static: match by name (inside a popover that mounts lazily):
|
|
152
|
+
* <AgentTarget action="toggle_frozen_columns" name="freeze-btn">
|
|
153
|
+
* <button>Freeze columns</button>
|
|
154
|
+
* </AgentTarget>
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function AgentTarget({ action, param, value, name, children }: AgentTargetProps): react_jsx_runtime.JSX.Element;
|
|
158
|
+
|
|
159
|
+
interface AgentDevToolsProps {
|
|
160
|
+
/** Default open state. */
|
|
161
|
+
defaultOpen?: boolean;
|
|
162
|
+
}
|
|
163
|
+
declare function AgentDevTools({ defaultOpen }: AgentDevToolsProps): react_jsx_runtime.JSX.Element;
|
|
164
|
+
|
|
165
|
+
interface StepConfig {
|
|
166
|
+
label: string;
|
|
167
|
+
fromParam?: string;
|
|
168
|
+
fromTarget?: string;
|
|
169
|
+
setParam?: string;
|
|
170
|
+
setValue?: string;
|
|
171
|
+
onSetValue?: (value: unknown) => void;
|
|
172
|
+
prepareView?: (params: Record<string, unknown>) => void | Promise<void>;
|
|
173
|
+
}
|
|
174
|
+
interface AgentActionConfig {
|
|
175
|
+
name: string;
|
|
176
|
+
description: string;
|
|
177
|
+
parameters?: unknown;
|
|
178
|
+
onExecute?: (params: Record<string, unknown>) => void | Promise<void>;
|
|
179
|
+
disabled?: boolean;
|
|
180
|
+
disabledReason?: string;
|
|
181
|
+
steps?: StepConfig[];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Hook-based action registration for actions that don't wrap a single element.
|
|
185
|
+
* Use this for per-row actions where AgentTargets are on scattered elements
|
|
186
|
+
* and the action resolves to them via fromParam/fromTarget.
|
|
187
|
+
*
|
|
188
|
+
* Accepts a single config or an array to batch-register multiple actions.
|
|
189
|
+
*
|
|
190
|
+
* For actions that wrap a visible element, prefer the <AgentAction> component.
|
|
191
|
+
*/
|
|
192
|
+
declare function useAgentAction(config: AgentActionConfig | AgentActionConfig[]): void;
|
|
193
|
+
|
|
194
|
+
declare function useAgentActions(): AgentActionContextValue;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Wraps an existing command handler with agent action routing.
|
|
198
|
+
*
|
|
199
|
+
* When a command arrives, if a matching `<AgentAction>` is mounted and enabled,
|
|
200
|
+
* it routes through `execute()` for visual guided execution. Otherwise it falls
|
|
201
|
+
* through to the original handler.
|
|
202
|
+
*
|
|
203
|
+
* Works with any command shape — you provide `getActionName` to extract the
|
|
204
|
+
* action name from your command object.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```tsx
|
|
208
|
+
* const handleCommand = useAgentCommandRouter(
|
|
209
|
+
* existingHandler,
|
|
210
|
+
* (cmd) => cmd.action,
|
|
211
|
+
* );
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare function useAgentCommandRouter<T>(fallback: ((command: T) => void | Promise<void>) | null, getActionName: (command: T) => string): (command: T) => Promise<void>;
|
|
215
|
+
|
|
216
|
+
type JsonSchema = Record<string, unknown>;
|
|
217
|
+
declare function zodToJsonSchema(schema: unknown): JsonSchema;
|
|
218
|
+
declare function generateToolSchemas(actions: RegisteredAction[]): ToolSchema[];
|
|
219
|
+
|
|
220
|
+
export { AgentAction, type AgentActionContextValue, AgentActionProvider, type AgentActionProviderProps, AgentDevTools, AgentStep, AgentTarget, type AgentTargetEntry, type AvailableAction, type ExecutionMode, type ExecutionResult, type ExecutionTarget, type ExecutorConfig, type RegisteredAction, type ToolSchema, generateToolSchemas, useAgentAction, useAgentActions, useAgentCommandRouter, zodToJsonSchema };
|