@memberjunction/interactive-component-types 2.92.0 → 2.94.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/README.md ADDED
@@ -0,0 +1,461 @@
1
+ # @memberjunction/interactive-component-types
2
+
3
+ Type definitions and interfaces for MemberJunction's Interactive Components system, enabling dynamic, data-driven UI components with AI capabilities.
4
+
5
+ ## Overview
6
+
7
+ The `@memberjunction/interactive-component-types` package provides the foundational types and interfaces for building interactive components in MemberJunction. These components are designed to be dynamically generated, data-aware, and AI-enhanced, allowing for rich user experiences with minimal configuration.
8
+
9
+ ## Key Features
10
+
11
+ - **Dynamic Component Generation**: Type-safe specifications for runtime component creation
12
+ - **Data Context Management**: Support for both static and dynamic data loading
13
+ - **AI Tool Integration**: Built-in interfaces for AI operations within components
14
+ - **Framework Agnostic**: Core types that work across React, Angular, and other frameworks
15
+ - **Vector Operations**: Support for similarity calculations and vector-based data operations
16
+ - **Metadata Access**: Direct access to MemberJunction's metadata system
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @memberjunction/interactive-component-types
22
+ ```
23
+
24
+ ## Core Interfaces
25
+
26
+ ### SimpleAITools
27
+
28
+ Provides AI capabilities to interactive components:
29
+
30
+ ```typescript
31
+ interface SimpleAITools {
32
+ // Execute LLM prompts for qualitative analysis
33
+ ExecutePrompt: (params: SimpleExecutePromptParams) => Promise<SimpleExecutePromptResult>
34
+
35
+ // Generate vector embeddings for similarity calculations
36
+ EmbedText: (params: SimpleEmbedTextParams) => Promise<SimpleEmbedTextResult>
37
+
38
+ // Vector operations service for KNN, similarity scoring, etc.
39
+ VectorService: SimpleVectorService
40
+ }
41
+ ```
42
+
43
+ ### SimpleExecutePromptParams
44
+
45
+ Parameters for executing AI prompts within components:
46
+
47
+ ```typescript
48
+ interface SimpleExecutePromptParams {
49
+ // System prompt to set context
50
+ systemPrompt: string;
51
+
52
+ // Optional conversation history
53
+ messages?: Array<{message: string, role: 'user' | 'assistant'}>;
54
+
55
+ // Preferred models in order of preference
56
+ preferredModels?: string[];
57
+
58
+ // Model power selection: 'lowest' | 'medium' | 'highest'
59
+ modelPower?: 'lowest' | 'medium' | 'highest';
60
+
61
+ // Optional user context
62
+ contextUser?: UserInfo;
63
+ }
64
+ ```
65
+
66
+ ### SimpleEmbedTextParams
67
+
68
+ Parameters for generating text embeddings:
69
+
70
+ ```typescript
71
+ interface SimpleEmbedTextParams {
72
+ // Single string or array of strings to embed
73
+ textToEmbed: string | string[];
74
+
75
+ // Model size selection
76
+ modelSize: 'small' | 'medium';
77
+
78
+ // Optional user context
79
+ contextUser?: UserInfo;
80
+ }
81
+ ```
82
+
83
+ ### SimpleMetadata
84
+
85
+ Access to MemberJunction's metadata system:
86
+
87
+ ```typescript
88
+ interface SimpleMetadata {
89
+ // Array of all entity metadata
90
+ Entities: EntityInfo[];
91
+
92
+ // Get entity object for CRUD operations
93
+ GetEntityObject(entityName: string, contextUser?: UserInfo): Promise<BaseEntity>;
94
+ }
95
+ ```
96
+
97
+ ### SimpleRunView
98
+
99
+ Execute database views dynamically:
100
+
101
+ ```typescript
102
+ interface SimpleRunView {
103
+ // Run a single view
104
+ RunView: (params: RunViewParams, contextUser?: UserInfo) => Promise<RunViewResult>
105
+
106
+ // Run multiple views in parallel
107
+ RunViews: (params: RunViewParams[], contextUser?: UserInfo) => Promise<RunViewResult[]>
108
+ }
109
+ ```
110
+
111
+ ### SimpleRunQuery
112
+
113
+ Execute predefined queries:
114
+
115
+ ```typescript
116
+ interface SimpleRunQuery {
117
+ // Run a predefined query with parameters
118
+ RunQuery: (params: RunQueryParams, contextUser?: UserInfo) => Promise<RunQueryResult>
119
+ }
120
+ ```
121
+
122
+ ## Component Initialization
123
+
124
+ Interactive components receive initialization functions with access to all tools:
125
+
126
+ ```typescript
127
+ type ComponentInitFunction = (
128
+ props: ComponentInitProps,
129
+ events: ComponentEvents,
130
+ data: SimpleDataContext,
131
+ metadata: SimpleMetadata,
132
+ runView: SimpleRunView,
133
+ runQuery: SimpleRunQuery,
134
+ ai: SimpleAITools
135
+ ) => Promise<void>;
136
+ ```
137
+
138
+ ## Usage Examples
139
+
140
+ ### Using AI Tools in a Component
141
+
142
+ ```typescript
143
+ // In your interactive component initialization
144
+ async function initComponent(props, events, data, metadata, runView, runQuery, ai) {
145
+ // Execute a prompt for data analysis
146
+ const analysisResult = await ai.ExecutePrompt({
147
+ systemPrompt: 'You are a data analyst. Analyze the provided dataset.',
148
+ messages: [
149
+ { message: 'What are the key trends?', role: 'user' }
150
+ ],
151
+ modelPower: 'medium'
152
+ });
153
+
154
+ if (analysisResult.success) {
155
+ console.log('Analysis:', analysisResult.result);
156
+
157
+ // Parse JSON if available
158
+ if (analysisResult.resultObject) {
159
+ const insights = analysisResult.resultObject;
160
+ // Use insights in your component
161
+ }
162
+ }
163
+
164
+ // Generate embeddings for similarity matching
165
+ const embedResult = await ai.EmbedText({
166
+ textToEmbed: ['Product A description', 'Product B description'],
167
+ modelSize: 'small'
168
+ });
169
+
170
+ // Use vector service for similarity calculations
171
+ const similarity = ai.VectorService.cosineSimilarity(
172
+ embedResult.result[0],
173
+ embedResult.result[1]
174
+ );
175
+
176
+ console.log('Product similarity:', similarity);
177
+ }
178
+ ```
179
+
180
+ ### Accessing Metadata and Running Views
181
+
182
+ ```typescript
183
+ async function loadComponentData(props, events, data, metadata, runView) {
184
+ // Get entity metadata
185
+ const userEntity = metadata.Entities.find(e => e.Name === 'Users');
186
+
187
+ // Run a view to get data
188
+ const viewResult = await runView.RunView({
189
+ EntityName: 'Users',
190
+ ExtraFilter: "Status = 'Active'",
191
+ OrderBy: 'LastName, FirstName',
192
+ MaxRows: 100
193
+ });
194
+
195
+ if (viewResult.Success) {
196
+ const users = viewResult.Results;
197
+ // Process users data
198
+ }
199
+
200
+ // Create/update an entity
201
+ const newUser = await metadata.GetEntityObject('Users');
202
+ newUser.NewRecord();
203
+ newUser.Set('FirstName', 'John');
204
+ newUser.Set('LastName', 'Doe');
205
+ await newUser.Save();
206
+ }
207
+ ```
208
+
209
+ ### Running Multiple Operations in Parallel
210
+
211
+ ```typescript
212
+ async function loadDashboardData(props, events, data, metadata, runView) {
213
+ // Run multiple views in parallel for better performance
214
+ const [salesData, customerData, productData] = await runView.RunViews([
215
+ { EntityName: 'Sales', ExtraFilter: "Date >= '2024-01-01'" },
216
+ { EntityName: 'Customers', ExtraFilter: "Active = 1" },
217
+ { EntityName: 'Products', OrderBy: 'Name' }
218
+ ]);
219
+
220
+ // All data loaded in parallel
221
+ console.log('Sales:', salesData.Results);
222
+ console.log('Customers:', customerData.Results);
223
+ console.log('Products:', productData.Results);
224
+ }
225
+ ```
226
+
227
+ ## Component Methods System
228
+
229
+ ### ComponentObject Interface
230
+
231
+ The `ComponentObject` interface defines the structure returned by compiled components, providing both the React component and method accessors:
232
+
233
+ ```typescript
234
+ interface ComponentObject {
235
+ // The React component function
236
+ component: Function;
237
+
238
+ // Standard methods (all optional)
239
+ print?: () => void;
240
+ refresh?: () => void;
241
+ getCurrentDataState?: () => any;
242
+ getDataStateHistory?: () => Array<{ timestamp: Date; state: any }>;
243
+ validate?: () => boolean | { valid: boolean; errors?: string[] };
244
+ isDirty?: () => boolean;
245
+ reset?: () => void;
246
+ scrollTo?: (target: string | HTMLElement | { top?: number; left?: number }) => void;
247
+ focus?: (target?: string | HTMLElement) => void;
248
+
249
+ // Dynamic method access
250
+ invokeMethod?: (methodName: string, ...args: any[]) => any;
251
+ hasMethod?: (methodName: string) => boolean;
252
+ }
253
+ ```
254
+
255
+ ### ComponentCallbacks Interface
256
+
257
+ Components receive callbacks that enable interaction with their container:
258
+
259
+ ```typescript
260
+ interface ComponentCallbacks {
261
+ // Open an entity record in the container
262
+ OpenEntityRecord: (entityName: string, key: CompositeKey) => void;
263
+
264
+ // Register a method that can be called by the container
265
+ RegisterMethod: (methodName: string, handler: Function) => void;
266
+ }
267
+ ```
268
+
269
+ ### How Method Registration Works
270
+
271
+ 1. **Component registers methods** during initialization using the `RegisterMethod` callback
272
+ 2. **Runtime stores methods** in an internal registry Map
273
+ 3. **ComponentObject exposes methods** with type-safe accessors for standard methods
274
+ 4. **Containers call methods** directly or via `invokeMethod()` for custom methods
275
+
276
+ ### Example: Component Registering Methods
277
+
278
+ ```typescript
279
+ function DataTableComponent({ callbacks, data, userState }) {
280
+ const [tableData, setTableData] = React.useState(data);
281
+ const [hasChanges, setHasChanges] = React.useState(false);
282
+ const [selectedRows, setSelectedRows] = React.useState([]);
283
+
284
+ React.useEffect(() => {
285
+ if (callbacks?.RegisterMethod) {
286
+ // Register standard methods
287
+ callbacks.RegisterMethod('getCurrentDataState', () => ({
288
+ data: tableData,
289
+ selectedRows: selectedRows,
290
+ totalCount: tableData.length
291
+ }));
292
+
293
+ callbacks.RegisterMethod('isDirty', () => hasChanges);
294
+
295
+ callbacks.RegisterMethod('validate', () => {
296
+ if (tableData.length === 0) {
297
+ return { valid: false, errors: ['Table cannot be empty'] };
298
+ }
299
+ return true;
300
+ });
301
+
302
+ callbacks.RegisterMethod('reset', () => {
303
+ setTableData(data);
304
+ setSelectedRows([]);
305
+ setHasChanges(false);
306
+ });
307
+
308
+ // Register custom business logic methods
309
+ callbacks.RegisterMethod('exportSelectedRows', () => {
310
+ return selectedRows.map(idx => tableData[idx]);
311
+ });
312
+
313
+ callbacks.RegisterMethod('deleteSelected', () => {
314
+ const newData = tableData.filter((_, idx) => !selectedRows.includes(idx));
315
+ setTableData(newData);
316
+ setHasChanges(true);
317
+ setSelectedRows([]);
318
+ });
319
+ }
320
+ }, [callbacks, tableData, selectedRows, hasChanges]);
321
+
322
+ return <div>{/* Table UI */}</div>;
323
+ }
324
+ ```
325
+
326
+ ### Example: Container Using Methods
327
+
328
+ ```typescript
329
+ // After component compilation
330
+ const componentObject = compiledComponent as ComponentObject;
331
+
332
+ // Use standard methods with type safety
333
+ if (componentObject.isDirty && componentObject.isDirty()) {
334
+ console.log('Component has unsaved changes');
335
+
336
+ const validation = componentObject.validate?.();
337
+ if (validation === true || validation?.valid) {
338
+ // Safe to proceed
339
+ const currentState = componentObject.getCurrentDataState?.();
340
+ await saveData(currentState);
341
+ } else {
342
+ console.error('Validation failed:', validation?.errors);
343
+ }
344
+ }
345
+
346
+ // Use custom methods via invokeMethod
347
+ if (componentObject.hasMethod?.('exportSelectedRows')) {
348
+ const selectedData = componentObject.invokeMethod('exportSelectedRows');
349
+ await exportToFile(selectedData);
350
+ }
351
+
352
+ // Reset the component
353
+ componentObject.reset?.();
354
+ ```
355
+
356
+ ### Method Declaration in ComponentSpec
357
+
358
+ Components can declare their supported methods in the spec for static discovery:
359
+
360
+ ```typescript
361
+ interface ComponentSpec {
362
+ name: string;
363
+ code: string;
364
+
365
+ // Optional method declarations for discovery/documentation
366
+ methods?: Array<{
367
+ name: string;
368
+ category?: 'standard' | 'custom';
369
+ description?: string;
370
+ parameters?: Array<{
371
+ name: string;
372
+ type: string; // Free-form type description
373
+ required?: boolean;
374
+ description?: string;
375
+ }>;
376
+ returnType?: string; // Free-form type description
377
+ }>;
378
+ }
379
+ ```
380
+
381
+ Example declaration:
382
+
383
+ ```typescript
384
+ const spec: ComponentSpec = {
385
+ name: 'DataTable',
386
+ code: '...',
387
+ methods: [
388
+ {
389
+ name: 'getCurrentDataState',
390
+ category: 'standard',
391
+ description: 'Returns current table data and selection state',
392
+ returnType: '{data: any[], selectedRows: number[], totalCount: number}'
393
+ },
394
+ {
395
+ name: 'exportSelectedRows',
396
+ category: 'custom',
397
+ description: 'Exports currently selected rows',
398
+ returnType: 'any[]'
399
+ },
400
+ {
401
+ name: 'deleteSelected',
402
+ category: 'custom',
403
+ description: 'Deletes selected rows from the table'
404
+ }
405
+ ]
406
+ };
407
+ ```
408
+
409
+ ### Benefits of the Method System
410
+
411
+ 1. **AI Agent Integration**: AI agents can introspect component state for analysis
412
+ 2. **Validation & State Management**: Containers can check dirty state and validate before saving
413
+ 3. **Custom Business Logic**: Components can expose domain-specific operations
414
+ 4. **Framework Agnostic**: Works across Angular, React, and other frameworks
415
+ 5. **Type Safety**: Standard methods have full TypeScript support
416
+ 6. **Discoverability**: Method declarations enable static analysis without runtime
417
+
418
+ ## Component Specifications
419
+
420
+ The package includes comprehensive types for component specifications:
421
+
422
+ - `InteractiveComponentSpec`: Full component specification including metadata, props, and initialization
423
+ - `ComponentDataRequirement`: Defines data loading requirements
424
+ - `ComponentOption`: Configuration options for components
425
+ - `ComponentLibraryDependency`: External library dependencies
426
+ - `ComponentSpecCategory`: Component categorization and metadata
427
+
428
+ ## Vector Service Capabilities
429
+
430
+ The included `SimpleVectorService` provides:
431
+
432
+ - **Cosine Similarity**: Calculate similarity between vectors
433
+ - **Euclidean Distance**: Measure distance between points
434
+ - **K-Nearest Neighbors (KNN)**: Find similar items
435
+ - **Clustering**: Group similar items together
436
+ - **Dimensionality Reduction**: PCA and t-SNE support
437
+
438
+ ## Best Practices
439
+
440
+ 1. **Model Selection**: Use `modelPower` parameter wisely - 'lowest' for simple tasks, 'highest' for complex analysis
441
+ 2. **Batch Operations**: Use `RunViews` for parallel data loading instead of sequential `RunView` calls
442
+ 3. **Embedding Caching**: Cache embeddings when possible as they're deterministic for the same input
443
+ 4. **Error Handling**: Always check `success` flags in AI operation results
444
+ 5. **JSON Parsing**: Use `resultObject` when expecting structured data from AI prompts
445
+
446
+ ## Type Safety
447
+
448
+ All interfaces are fully typed with TypeScript, providing:
449
+ - IntelliSense support in IDEs
450
+ - Compile-time type checking
451
+ - Better code documentation
452
+ - Reduced runtime errors
453
+
454
+ ## Dependencies
455
+
456
+ - `@memberjunction/core`: Core MemberJunction types and interfaces
457
+ - `@memberjunction/ai-vectors-memory`: Vector operations and similarity calculations
458
+
459
+ ## License
460
+
461
+ ISC
@@ -26,6 +26,11 @@ export declare class ComponentSpec {
26
26
  * Follows conventions documented here: https://semver.org/ and https://docs.npmjs.com/about-semantic-versioning
27
27
  */
28
28
  version?: string;
29
+ /**
30
+ * Only used when location === 'registry', logic explaining why this component is being selected
31
+ * to serve a specific use case or requirement
32
+ */
33
+ selectionReasoning?: string;
29
34
  /**
30
35
  * When an architect decides to use an existing component as a base for a new version,
31
36
  * they can set this flag to true. This indicates that the new version will be created
@@ -74,6 +79,10 @@ export declare class ComponentSpec {
74
79
  * Events that the component emits, if any
75
80
  */
76
81
  events?: ComponentEvent[];
82
+ /**
83
+ * Metadata about methods the component supports, if any
84
+ */
85
+ methods?: ComponentMethodInfo;
77
86
  /**
78
87
  * Example of the component being used in JSX format. This is used to provide a clear example on the properties and
79
88
  * event handling that the component supports.
@@ -90,7 +99,39 @@ export declare class ComponentSpec {
90
99
  /**
91
100
  * Relevant examples of components intended to inspire this component's creation
92
101
  */
93
- relevantExamples?: Array<ComponentExample[]>;
102
+ relevantExamples?: ComponentExample[];
103
+ }
104
+ /**
105
+ * Defines standard and custom methods a component implements
106
+ */
107
+ export interface ComponentMethodInfo {
108
+ standardMethodsSupported: {
109
+ print?: boolean;
110
+ refresh?: boolean;
111
+ getCurrentDataState?: boolean;
112
+ getDataStateHistory?: boolean;
113
+ validate?: boolean;
114
+ isDirty?: boolean;
115
+ reset?: boolean;
116
+ scrollTo?: boolean;
117
+ focus?: boolean;
118
+ invokeMethod?: boolean;
119
+ hasMethod?: boolean;
120
+ };
121
+ customMethods: CustomComponentMethod[];
122
+ }
123
+ /**
124
+ * Defines a single custom component method
125
+ */
126
+ export interface CustomComponentMethod {
127
+ name: string;
128
+ description: string;
129
+ parameters: Array<{
130
+ name: string;
131
+ type: string;
132
+ description?: string;
133
+ }>;
134
+ returnType: string;
94
135
  }
95
136
  /**
96
137
  * Type that defines an example component used to inspire the creation
@@ -1 +1 @@
1
- {"version":3,"file":"component-spec.d.ts","sourceRoot":"","sources":["../src/component-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CA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M,CAAA;KAAE,CAAC,CAAC;IACvE,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B;;OAEG;IACH,4BAA4B,CAAC,EAAE,MAAM,EAAE,CAAC;IACxC;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjC;;OAEG;IACH,KAAK,CAAC,EAAE,GAAG,CAAC;CACf,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"component-spec.js","sourceRoot":"","sources":["../src/component-spec.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACH,MAAa,aAAa;CAwGzB;AAxGD,sCAwGC;AAAA,CAAC"}
1
+ {"version":3,"file":"component-spec.js","sourceRoot":"","sources":["../src/component-spec.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACH,MAAa,aAAa;CAmHzB;AAnHD,sCAmHC;AAAA,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { CompositeKey } from "@memberjunction/core";
2
- import { SimpleMetadata, SimpleRunQuery, SimpleRunView } from "./shared";
2
+ import { SimpleAITools, SimpleMetadata, SimpleRunQuery, SimpleRunView } from "./shared";
3
3
  /**
4
4
  * Callbacks a component can use.
5
5
  */
@@ -11,6 +11,12 @@ export interface ComponentCallbacks {
11
11
  * @param key - this is an array of key/value pairs representing the primary key. The format of a Composite Key is an array of KeyValuePair objects and KeyValuePair objects simply have FieldName and Value properties. In most cases entities have single-valued primary keys but this structure is here for complex entity types that have composite primary keys
12
12
  */
13
13
  OpenEntityRecord: (entityName: string, key: CompositeKey) => void;
14
+ /**
15
+ * Allows a component to register methods that can be called by the container.
16
+ * @param methodName - Name of the method being registered
17
+ * @param handler - The method implementation
18
+ */
19
+ RegisterMethod: (methodName: string, handler: Function) => void;
14
20
  }
15
21
  /**
16
22
  * Defines styles for the component. Container can provide styles to a top level component. The top level component
@@ -130,9 +136,9 @@ export type ComponentRefreshFunction = () => void;
130
136
  */
131
137
  export interface ComponentObject {
132
138
  /**
133
- * This component receives props including data, userState, callbacks, utilities, and styles.
139
+ * The React component function that receives props including data, userState, callbacks, utilities, and styles.
134
140
  */
135
- component: any;
141
+ component: Function;
136
142
  /**
137
143
  * The optional print function that is called when the user clicks on the print button in the parent of the component. This function will never be called by the parent before the init function so the print function
138
144
  * can assume the component has been initialized;
@@ -142,6 +148,61 @@ export interface ComponentObject {
142
148
  * The optional refresh function that is called when the user clicks on the refresh button in the parent of the component. This function will never be called by the parent before the init function so the refresh function
143
149
  */
144
150
  refresh?: ComponentRefreshFunction;
151
+ /**
152
+ * Gets the current data state of the component.
153
+ * Used by AI agents to understand what data is currently displayed.
154
+ */
155
+ getCurrentDataState?: () => any;
156
+ /**
157
+ * Gets the history of data state changes in the component.
158
+ * Returns an array of timestamped state snapshots.
159
+ */
160
+ getDataStateHistory?: () => Array<{
161
+ timestamp: Date;
162
+ state: any;
163
+ }>;
164
+ /**
165
+ * Validates the current state of the component.
166
+ * Returns true if valid, false or validation errors otherwise.
167
+ */
168
+ validate?: () => boolean | {
169
+ valid: boolean;
170
+ errors?: string[];
171
+ };
172
+ /**
173
+ * Checks if the component has unsaved changes.
174
+ */
175
+ isDirty?: () => boolean;
176
+ /**
177
+ * Resets the component to its initial state.
178
+ */
179
+ reset?: () => void;
180
+ /**
181
+ * Scrolls to a specific element or position within the component.
182
+ * @param target - Element selector, element reference, or scroll options
183
+ */
184
+ scrollTo?: (target: string | HTMLElement | {
185
+ top?: number;
186
+ left?: number;
187
+ }) => void;
188
+ /**
189
+ * Sets focus to a specific element within the component.
190
+ * @param target - Element selector or element reference
191
+ */
192
+ focus?: (target?: string | HTMLElement) => void;
193
+ /**
194
+ * Generic method invoker for custom methods
195
+ * @param methodName - Name of the method to invoke
196
+ * @param args - Arguments to pass to the method
197
+ * @returns The result of the method call, or undefined if method doesn't exist
198
+ */
199
+ invokeMethod?: (methodName: string, ...args: any[]) => any;
200
+ /**
201
+ * Check if a method is registered on the component
202
+ * @param methodName - Name of the method to check
203
+ * @returns true if the method exists
204
+ */
205
+ hasMethod?: (methodName: string) => boolean;
145
206
  }
146
207
  /**
147
208
  * This interface defines the utilities that are available to the component at runtime. These utilities are used to interact with the host MJ system to
@@ -151,5 +212,10 @@ export interface ComponentUtilities {
151
212
  md: SimpleMetadata;
152
213
  rv: SimpleRunView;
153
214
  rq: SimpleRunQuery;
215
+ /**
216
+ * Access to AI tools. This will not always be available in all environments and security contexts, ensure
217
+ * component code has fallbacks when this property is undefined
218
+ */
219
+ ai?: SimpleAITools;
154
220
  }
155
221
  //# sourceMappingURL=runtime-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-types.d.ts","sourceRoot":"","sources":["../src/runtime-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAqB,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE5F;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,KAAK,IAAI,CAAC;CACrE;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE;QAEJ,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;QACpB,YAAY,CAAC,EAAE,MAAM,CAAA;QAGrB,SAAS,EA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ViewResult } from "@memberjunction/core";
1
+ import { SimpleVectorService } from "@memberjunction/ai-vectors-memory";
2
+ import { BaseEntity, EntityInfo, RunQueryParams, RunQueryResult, RunViewParams, RunViewResult, UserInfo } from "@memberjunction/core";
2
3
  /**
3
4
  * This is a simple data context object that is passed into the ComponentInitFunction containing any required `static` data. This object is empty when the mode is `dynamic`
4
5
  */
@@ -17,7 +18,7 @@ export interface SimpleMetadata {
17
18
  * Retrieves a single BaseEntity derived class for the specified entity
18
19
  * @param entityName
19
20
  */
20
- GetEntityObject(entityName: string): Promise<BaseEntity>;
21
+ GetEntityObject(entityName: string, contextUser?: UserInfo): Promise<BaseEntity>;
21
22
  }
22
23
  /**
23
24
  * Simple interface for running views in MJ
@@ -28,13 +29,13 @@ export interface SimpleRunView {
28
29
  * @param params
29
30
  * @returns
30
31
  */
31
- RunView: (params: RunViewParams) => Promise<RunViewResult>;
32
+ RunView: (params: RunViewParams, contextUser?: UserInfo) => Promise<RunViewResult>;
32
33
  /**
33
34
  * Runs multiple views and returns the results. This is efficient for running views in **parallel**.
34
35
  * @param params
35
36
  * @returns
36
37
  */
37
- RunViews: (params: RunViewParams[]) => Promise<RunViewResult[]>;
38
+ RunViews: (params: RunViewParams[], contextUser?: UserInfo) => Promise<RunViewResult[]>;
38
39
  }
39
40
  /**
40
41
  * Simple interface for running predefined queries in MJ
@@ -45,6 +46,114 @@ export interface SimpleRunQuery {
45
46
  * @param params
46
47
  * @returns
47
48
  */
48
- RunQuery: (params: RunQueryParams) => Promise<RunQueryResult>;
49
+ RunQuery: (params: RunQueryParams, contextUser?: UserInfo) => Promise<RunQueryResult>;
50
+ }
51
+ /**
52
+ * Params for an Interactive Component to execute a prompt
53
+ */
54
+ export interface SimpleExecutePromptParams {
55
+ /**
56
+ * Text for the prompt, will be sent in as the system message
57
+ */
58
+ systemPrompt: string;
59
+ /**
60
+ * Optional, message history to append to the conversation after the system prompt
61
+ */
62
+ messages?: Array<{
63
+ message: string;
64
+ role: 'user' | 'assistant';
65
+ }>;
66
+ /**
67
+ * An ordered array of model names that are preferred for this prompt. This is not guaranteed but the preferences
68
+ * are taken into account
69
+ */
70
+ preferredModels?: string[];
71
+ /**
72
+ * Optional power level for model selection when preferredModels is not provided.
73
+ * 'lowest' = least powerful/cheapest model
74
+ * 'medium' = balanced power/cost (default)
75
+ * 'highest' = most powerful model
76
+ */
77
+ modelPower?: 'lowest' | 'medium' | 'highest';
78
+ /**
79
+ * Optional context user information
80
+ */
81
+ contextUser?: UserInfo;
82
+ }
83
+ /**
84
+ * Simple return structure for prompt execution
85
+ */
86
+ export interface SimpleExecutePromptResult {
87
+ success: boolean;
88
+ /**
89
+ * Raw string result
90
+ */
91
+ result: string;
92
+ /**
93
+ * If the result was JSON or contained JSON anywhere within it that could be parsed, this will contain
94
+ * the JSON object
95
+ */
96
+ resultObject?: any;
97
+ /**
98
+ * The model that was used for the response
99
+ */
100
+ modelName: string;
101
+ }
102
+ /**
103
+ *
104
+ */
105
+ export interface SimpleEmbedTextParams {
106
+ /**
107
+ * Either a single string or an array of strings to calculate embeddings for
108
+ */
109
+ textToEmbed: string | string[];
110
+ modelSize: 'small' | 'medium';
111
+ contextUser?: UserInfo;
112
+ }
113
+ /**
114
+ * Results of a call to EmbedText
115
+ */
116
+ export interface SimpleEmbedTextResult {
117
+ /**
118
+ * Either a single vector if a single string was provided in params, or an array of vectors if an array of strings was provided to the method
119
+ */
120
+ result: number[] | Array<number[]>;
121
+ /**
122
+ * Name of the model used for embedding calculation
123
+ */
124
+ modelName: string;
125
+ /**
126
+ * Number of dimensions in each vector
127
+ */
128
+ vectorDimensions: number;
129
+ }
130
+ /**
131
+ * Provides a simple interface for InteractiveComponents to perform a wide variety of common AI operations
132
+ * such as prompt execution with LLMs, calculating embeddings on strings, and using vector search for small to mediun
133
+ * sized datasets in memory.
134
+ */
135
+ export interface SimpleAITools {
136
+ /**
137
+ * Uses an LLM to respond to a provided prompt. Often used by interactive components to provide rich analysis of data within a component that a user
138
+ * is interested in gaining qualitative insights on
139
+ * @param params
140
+ * @returns
141
+ */
142
+ ExecutePrompt: (params: SimpleExecutePromptParams) => Promise<SimpleExecutePromptResult>;
143
+ /**
144
+ * Used to calculate vector embeddings for one or more strings. Uses very fast small/medium sized
145
+ * local models so the embeddings can be rapidly calculated for hundreds or even thousands of pieces of text.
146
+ * This allows interactive components to dynamically compute similarity/distance between any kinds of data
147
+ * and generate very interesting interactive experiences for users
148
+ * @param params
149
+ * @returns
150
+ */
151
+ EmbedText: (params: SimpleEmbedTextParams) => Promise<SimpleEmbedTextResult>;
152
+ /**
153
+ * Instance of the SimpleVectorService that can be used by Interactive Components
154
+ * @see SimpleVectorService for more details on this. This object can perform a wide array
155
+ * of vector data operations such as KNN, Similarity Scoring, and more.
156
+ */
157
+ VectorService: SimpleVectorService;
49
158
  }
50
159
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE5H;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB;;;OAGG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC5D;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;;;OAIG;IACH,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,aAAa,CAAC,CAAA;IAC1D;;;;OAIG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,OAAO,CAAC,aAAa,E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IG;IACH,aAAa,EAAE,mBAAmB,CAAA;CACrC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/interactive-component-types",
3
- "version": "2.92.0",
3
+ "version": "2.94.0",
4
4
  "description": "MemberJunction: Interactive Component - Type specifications for MJ Interactive UI Componentry",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,6 +19,7 @@
19
19
  "typescript": "^5.4.5"
20
20
  },
21
21
  "dependencies": {
22
- "@memberjunction/core": "2.92.0"
22
+ "@memberjunction/core": "2.94.0",
23
+ "@memberjunction/ai-vectors-memory": "2.94.0"
23
24
  }
24
25
  }