@memberjunction/interactive-component-types 2.92.0 → 2.93.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,270 @@
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 Specifications
228
+
229
+ The package includes comprehensive types for component specifications:
230
+
231
+ - `InteractiveComponentSpec`: Full component specification including metadata, props, and initialization
232
+ - `ComponentDataRequirement`: Defines data loading requirements
233
+ - `ComponentOption`: Configuration options for components
234
+ - `ComponentLibraryDependency`: External library dependencies
235
+ - `ComponentSpecCategory`: Component categorization and metadata
236
+
237
+ ## Vector Service Capabilities
238
+
239
+ The included `SimpleVectorService` provides:
240
+
241
+ - **Cosine Similarity**: Calculate similarity between vectors
242
+ - **Euclidean Distance**: Measure distance between points
243
+ - **K-Nearest Neighbors (KNN)**: Find similar items
244
+ - **Clustering**: Group similar items together
245
+ - **Dimensionality Reduction**: PCA and t-SNE support
246
+
247
+ ## Best Practices
248
+
249
+ 1. **Model Selection**: Use `modelPower` parameter wisely - 'lowest' for simple tasks, 'highest' for complex analysis
250
+ 2. **Batch Operations**: Use `RunViews` for parallel data loading instead of sequential `RunView` calls
251
+ 3. **Embedding Caching**: Cache embeddings when possible as they're deterministic for the same input
252
+ 4. **Error Handling**: Always check `success` flags in AI operation results
253
+ 5. **JSON Parsing**: Use `resultObject` when expecting structured data from AI prompts
254
+
255
+ ## Type Safety
256
+
257
+ All interfaces are fully typed with TypeScript, providing:
258
+ - IntelliSense support in IDEs
259
+ - Compile-time type checking
260
+ - Better code documentation
261
+ - Reduced runtime errors
262
+
263
+ ## Dependencies
264
+
265
+ - `@memberjunction/core`: Core MemberJunction types and interfaces
266
+ - `@memberjunction/ai-vectors-memory`: Vector operations and similarity calculations
267
+
268
+ ## License
269
+
270
+ ISC
@@ -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
  */
@@ -151,5 +151,10 @@ export interface ComponentUtilities {
151
151
  md: SimpleMetadata;
152
152
  rv: SimpleRunView;
153
153
  rq: SimpleRunQuery;
154
+ /**
155
+ * Access to AI tools. This will not always be available in all environments and security contexts, ensure
156
+ * component code has fallbacks when this property is undefined
157
+ */
158
+ ai?: SimpleAITools;
154
159
  }
155
160
  //# 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,EAAE,MAAM,CAAA;QACjB,cAAc,CAAC,EAAE,MAAM,CAAA;QAGvB,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,CAAC,EAAE,MAAM,C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ist/shared.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { BaseEntity, EntityInfo, RunQueryParams, RunQueryResult, RunViewParams, RunViewResult } 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;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SAAS,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAA;IAE5E;;;;OAIG;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.93.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.93.0",
23
+ "@memberjunction/ai-vectors-memory": "2.93.0"
23
24
  }
24
25
  }