@memberjunction/ai-engine-base 4.0.0 → 4.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/README.md +216 -0
- package/package.json +7 -7
package/README.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# @memberjunction/ai-engine-base
|
|
2
|
+
|
|
3
|
+
Base AI Engine package for MemberJunction. Provides a comprehensive metadata cache for all AI-related entities -- models, vendors, prompts, agents, configurations, modalities, permissions, and more. This package extends `BaseEngine` to load and cache AI metadata in a single batch, making it available on both server and client without duplicating data loading logic.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
graph TD
|
|
9
|
+
subgraph Dependencies
|
|
10
|
+
CORE["@memberjunction/core<br/>BaseEngine"]
|
|
11
|
+
style CORE fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
12
|
+
|
|
13
|
+
CE["@memberjunction/core-entities"]
|
|
14
|
+
style CE fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
15
|
+
|
|
16
|
+
ACP["@memberjunction/ai-core-plus<br/>Extended Entities"]
|
|
17
|
+
style ACP fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
AIB["AIEngineBase<br/>Singleton Metadata Cache"]
|
|
21
|
+
style AIB fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
22
|
+
|
|
23
|
+
subgraph "Cached Metadata"
|
|
24
|
+
M["Models & Model Types"]
|
|
25
|
+
style M fill:#7c5295,stroke:#563a6b,color:#fff
|
|
26
|
+
|
|
27
|
+
V["Vendors & Model Vendors"]
|
|
28
|
+
style V fill:#7c5295,stroke:#563a6b,color:#fff
|
|
29
|
+
|
|
30
|
+
P["Prompts, Categories & Types"]
|
|
31
|
+
style P fill:#7c5295,stroke:#563a6b,color:#fff
|
|
32
|
+
|
|
33
|
+
A["Agents, Types & Relationships"]
|
|
34
|
+
style A fill:#7c5295,stroke:#563a6b,color:#fff
|
|
35
|
+
|
|
36
|
+
CFG["Configurations & Params"]
|
|
37
|
+
style CFG fill:#b8762f,stroke:#8a5722,color:#fff
|
|
38
|
+
|
|
39
|
+
MOD["Modalities & Limits"]
|
|
40
|
+
style MOD fill:#b8762f,stroke:#8a5722,color:#fff
|
|
41
|
+
|
|
42
|
+
PERM["Permissions & Credentials"]
|
|
43
|
+
style PERM fill:#b8762f,stroke:#8a5722,color:#fff
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
CORE --> AIB
|
|
47
|
+
CE --> AIB
|
|
48
|
+
ACP --> AIB
|
|
49
|
+
AIB --> M
|
|
50
|
+
AIB --> V
|
|
51
|
+
AIB --> P
|
|
52
|
+
AIB --> A
|
|
53
|
+
AIB --> CFG
|
|
54
|
+
AIB --> MOD
|
|
55
|
+
AIB --> PERM
|
|
56
|
+
|
|
57
|
+
SRV["AIEngine (Server)"]
|
|
58
|
+
style SRV fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
59
|
+
|
|
60
|
+
AIB --> SRV
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install @memberjunction/ai-engine-base
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Key Exports
|
|
70
|
+
|
|
71
|
+
### AIEngineBase (Singleton)
|
|
72
|
+
|
|
73
|
+
The core class that loads and caches all AI metadata. Access via `AIEngineBase.Instance`.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { AIEngineBase } from '@memberjunction/ai-engine-base';
|
|
77
|
+
|
|
78
|
+
// Initialize (typically at app startup)
|
|
79
|
+
await AIEngineBase.Instance.Config(false, contextUser);
|
|
80
|
+
|
|
81
|
+
// Access cached metadata
|
|
82
|
+
const models = AIEngineBase.Instance.Models;
|
|
83
|
+
const agents = AIEngineBase.Instance.Agents;
|
|
84
|
+
const prompts = AIEngineBase.Instance.Prompts;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Cached Entity Collections
|
|
88
|
+
|
|
89
|
+
| Property | Entity | Description |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `Models` | AI Models | All registered AI models with extended properties |
|
|
92
|
+
| `ModelTypes` | AI Model Types | Model type categories (LLM, Embeddings, etc.) |
|
|
93
|
+
| `Vendors` | MJ: AI Vendors | AI service providers |
|
|
94
|
+
| `ModelVendors` | MJ: AI Model Vendors | Model-vendor associations |
|
|
95
|
+
| `Prompts` | AI Prompts | All prompt definitions with category associations |
|
|
96
|
+
| `PromptModels` | MJ: AI Prompt Models | Prompt-model associations |
|
|
97
|
+
| `PromptTypes` | AI Prompt Types | Prompt type categories |
|
|
98
|
+
| `PromptCategories` | AI Prompt Categories | Hierarchical prompt organization |
|
|
99
|
+
| `Agents` | AI Agents | All agent definitions with actions and notes |
|
|
100
|
+
| `AgentTypes` | MJ: AI Agent Types | Agent type definitions |
|
|
101
|
+
| `AgentActions` | AI Agent Actions | Actions associated with agents |
|
|
102
|
+
| `AgentPrompts` | MJ: AI Agent Prompts | Prompts associated with agents |
|
|
103
|
+
| `AgentSteps` | MJ: AI Agent Steps | Flow agent step definitions |
|
|
104
|
+
| `AgentStepPaths` | MJ: AI Agent Step Paths | Transitions between flow steps |
|
|
105
|
+
| `AgentRelationships` | MJ: AI Agent Relationships | Sub-agent relationships |
|
|
106
|
+
| `AgentPermissions` | MJ: AI Agent Permissions | User/role permission grants |
|
|
107
|
+
| `AgentConfigurations` | MJ: AI Agent Configurations | Semantic presets (Fast, High Quality) |
|
|
108
|
+
| `Configurations` | MJ: AI Configurations | Global AI configurations with inheritance |
|
|
109
|
+
| `ConfigurationParams` | MJ: AI Configuration Params | Key-value parameters for configurations |
|
|
110
|
+
| `ModelCosts` | MJ: AI Model Costs | Cost tracking per model/vendor |
|
|
111
|
+
| `ModelPriceTypes` | MJ: AI Model Price Types | Price type definitions |
|
|
112
|
+
| `ModelPriceUnitTypes` | MJ: AI Model Price Unit Types | Unit type definitions |
|
|
113
|
+
| `CredentialBindings` | MJ: AI Credential Bindings | Credential bindings for vendors/models |
|
|
114
|
+
| `Modalities` | MJ: AI Modalities | Input/output modality definitions |
|
|
115
|
+
| `AgentModalities` | MJ: AI Agent Modalities | Agent modality support |
|
|
116
|
+
| `ModelModalities` | MJ: AI Model Modalities | Model modality support |
|
|
117
|
+
| `VectorDatabases` | Vector Databases | Vector database configurations |
|
|
118
|
+
| `ArtifactTypes` | MJ: Artifact Types | Artifact type definitions |
|
|
119
|
+
|
|
120
|
+
#### Convenience Methods
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// Get the highest-power model of a given type
|
|
124
|
+
const bestLLM = await AIEngineBase.Instance.GetHighestPowerLLM('OpenAI', contextUser);
|
|
125
|
+
const bestEmbedding = await AIEngineBase.Instance.GetHighestPowerModel('OpenAI', 'Embeddings', contextUser);
|
|
126
|
+
|
|
127
|
+
// Get agent by name
|
|
128
|
+
const agent = AIEngineBase.Instance.GetAgentByName('Customer Support Agent');
|
|
129
|
+
|
|
130
|
+
// Get sub-agents (children + relationships)
|
|
131
|
+
const subAgents = AIEngineBase.Instance.GetSubAgents(agentId, 'Active');
|
|
132
|
+
|
|
133
|
+
// Configuration presets
|
|
134
|
+
const presets = AIEngineBase.Instance.GetAgentConfigurationPresets(agentId);
|
|
135
|
+
const defaultPreset = AIEngineBase.Instance.GetDefaultAgentConfigurationPreset(agentId);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Configuration Inheritance
|
|
139
|
+
|
|
140
|
+
Configurations support parent-child inheritance chains:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// Get the full inheritance chain (child -> parent -> grandparent)
|
|
144
|
+
const chain = AIEngineBase.Instance.GetConfigurationChain(configId);
|
|
145
|
+
|
|
146
|
+
// Get parameters with inheritance (child overrides parent)
|
|
147
|
+
const params = AIEngineBase.Instance.GetConfigurationParamsWithInheritance(configId);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Model Cost Tracking
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// Get active cost for a model/vendor combination
|
|
154
|
+
const cost = AIEngineBase.Instance.GetActiveModelCost(modelId, vendorId, 'Realtime');
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### Credential Bindings
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Get credential bindings for a vendor
|
|
161
|
+
const bindings = AIEngineBase.Instance.GetCredentialBindingsForTarget('Vendor', vendorId);
|
|
162
|
+
|
|
163
|
+
// Check if bindings exist
|
|
164
|
+
const hasBindings = AIEngineBase.Instance.HasCredentialBindings('ModelVendor', modelVendorId);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Modality System
|
|
168
|
+
|
|
169
|
+
The modality system tracks which input/output types (Text, Image, Audio, Video, File) agents and models support.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// Check if an agent supports image input
|
|
173
|
+
const supportsImages = AIEngineBase.Instance.AgentSupportsModality(agentId, 'Image', 'Input');
|
|
174
|
+
|
|
175
|
+
// Check if agent accepts any attachments
|
|
176
|
+
const supportsAttachments = AIEngineBase.Instance.AgentSupportsAttachments(agentId);
|
|
177
|
+
|
|
178
|
+
// Get aggregated attachment limits for UI configuration
|
|
179
|
+
const limits = AIEngineBase.Instance.GetAgentAttachmentLimits(agentId, modelId);
|
|
180
|
+
// limits.enabled, limits.maxAttachments, limits.maxAttachmentSizeBytes, limits.acceptedFileTypes
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Agent Permission Helper
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// Check individual permissions
|
|
187
|
+
const canView = await AIEngineBase.Instance.CanUserViewAgent(agentId, user);
|
|
188
|
+
const canRun = await AIEngineBase.Instance.CanUserRunAgent(agentId, user);
|
|
189
|
+
|
|
190
|
+
// Get all permissions at once
|
|
191
|
+
const perms = await AIEngineBase.Instance.GetUserAgentPermissions(agentId, user);
|
|
192
|
+
// perms.canView, perms.canRun, perms.canEdit, perms.canDelete, perms.isOwner
|
|
193
|
+
|
|
194
|
+
// Get all accessible agents for a user
|
|
195
|
+
const agents = await AIEngineBase.Instance.GetAccessibleAgents(user, 'run');
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Additional Exports
|
|
199
|
+
|
|
200
|
+
| Export | Purpose |
|
|
201
|
+
|---|---|
|
|
202
|
+
| `ModalityLimits` | Resolved limits for a specific modality (size, count, dimension, formats) |
|
|
203
|
+
| `AgentAttachmentLimits` | Aggregated attachment limits for UI components |
|
|
204
|
+
| `PriceUnitTypes` | Price unit type utilities |
|
|
205
|
+
| `AIAgentPermissionHelper` | Static helper for agent permission checks |
|
|
206
|
+
| `EffectiveAgentPermissions` | Complete permission set for a user/agent combination |
|
|
207
|
+
| `AICredentialBindingEntityExtended` | Extended credential binding entity |
|
|
208
|
+
|
|
209
|
+
## Dependencies
|
|
210
|
+
|
|
211
|
+
- `@memberjunction/core` -- BaseEngine, Metadata, RunView
|
|
212
|
+
- `@memberjunction/core-entities` -- Generated entity classes
|
|
213
|
+
- `@memberjunction/ai` -- Core AI abstractions
|
|
214
|
+
- `@memberjunction/ai-core-plus` -- Extended entity classes
|
|
215
|
+
- `@memberjunction/global` -- Class factory
|
|
216
|
+
- `@memberjunction/templates-base-types` -- Template engine integration
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-engine-base",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"description": "MemberJunction: Base AI Engine Package - does extended types and data caching, can be used anywhere.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"author": "MemberJunction.com",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@memberjunction/core": "4.
|
|
20
|
-
"@memberjunction/global": "4.
|
|
21
|
-
"@memberjunction/core-entities": "4.
|
|
22
|
-
"@memberjunction/ai": "4.
|
|
23
|
-
"@memberjunction/ai-core-plus": "4.
|
|
24
|
-
"@memberjunction/templates-base-types": "4.
|
|
19
|
+
"@memberjunction/core": "4.1.0",
|
|
20
|
+
"@memberjunction/global": "4.1.0",
|
|
21
|
+
"@memberjunction/core-entities": "4.1.0",
|
|
22
|
+
"@memberjunction/ai": "4.1.0",
|
|
23
|
+
"@memberjunction/ai-core-plus": "4.1.0",
|
|
24
|
+
"@memberjunction/templates-base-types": "4.1.0",
|
|
25
25
|
"dotenv": "^17.2.4",
|
|
26
26
|
"rxjs": "^7.8.2"
|
|
27
27
|
},
|