@memberjunction/ai 2.39.0 → 2.41.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/dist/generic/chat.types.d.ts +30 -4
- package/dist/generic/chat.types.d.ts.map +1 -1
- package/dist/generic/chat.types.js +1 -0
- package/dist/generic/chat.types.js.map +1 -1
- package/dist/generic/summarize.types.d.ts +4 -3
- package/dist/generic/summarize.types.d.ts.map +1 -1
- package/dist/generic/summarize.types.js +7 -1
- package/dist/generic/summarize.types.js.map +1 -1
- package/package.json +2 -2
- package/readme.md +61 -68
|
@@ -5,8 +5,17 @@ export declare const ChatMessageRole: {
|
|
|
5
5
|
readonly assistant: "assistant";
|
|
6
6
|
};
|
|
7
7
|
export type ChatMessageRole = typeof ChatMessageRole[keyof typeof ChatMessageRole];
|
|
8
|
+
export type ChatMessageContentBlock = {
|
|
9
|
+
type: 'text' | 'image_url' | 'video_url' | 'audio_url' | 'file_url';
|
|
10
|
+
content: string;
|
|
11
|
+
};
|
|
12
|
+
export type ChatMessageContent = string | ChatMessageContentBlock[];
|
|
8
13
|
export type ChatMessage = {
|
|
9
14
|
role: ChatMessageRole;
|
|
15
|
+
content: ChatMessageContent;
|
|
16
|
+
};
|
|
17
|
+
export type ChatCompletionMessage = {
|
|
18
|
+
role: 'assistant';
|
|
10
19
|
content: string;
|
|
11
20
|
};
|
|
12
21
|
export interface StreamingChatCallbacks {
|
|
@@ -25,17 +34,34 @@ export declare class ChatParams extends BaseParams {
|
|
|
25
34
|
streamingCallbacks?: StreamingChatCallbacks;
|
|
26
35
|
effortLevel?: string;
|
|
27
36
|
enableCaching?: boolean;
|
|
37
|
+
includeLogProbs?: boolean;
|
|
28
38
|
}
|
|
29
|
-
export declare function GetUserMessageFromChatParams(p: ChatParams):
|
|
30
|
-
export declare function GetSystemPromptFromChatParams(p: ChatParams):
|
|
39
|
+
export declare function GetUserMessageFromChatParams(p: ChatParams): ChatMessageContent | undefined;
|
|
40
|
+
export declare function GetSystemPromptFromChatParams(p: ChatParams): ChatMessageContent | undefined;
|
|
41
|
+
export type ChatResultSingleLogProb = {
|
|
42
|
+
bytes: Array<number> | null;
|
|
43
|
+
logprob: number;
|
|
44
|
+
token: string;
|
|
45
|
+
top_logprobs: Array<{
|
|
46
|
+
token: string;
|
|
47
|
+
logprob: number;
|
|
48
|
+
bytes: Array<number> | null;
|
|
49
|
+
}> | null;
|
|
50
|
+
};
|
|
51
|
+
export type ChatResultLogProbs = {
|
|
52
|
+
content: Array<ChatResultSingleLogProb> | null;
|
|
53
|
+
refusal: Array<ChatResultSingleLogProb> | null;
|
|
54
|
+
};
|
|
31
55
|
export type ChatResultChoice = {
|
|
32
|
-
message:
|
|
56
|
+
message: ChatCompletionMessage;
|
|
33
57
|
finish_reason: string;
|
|
34
58
|
index: number;
|
|
59
|
+
logprobs?: ChatResultLogProbs | null;
|
|
35
60
|
};
|
|
36
61
|
export type ChatResultData = {
|
|
37
62
|
choices: ChatResultChoice[];
|
|
38
|
-
|
|
63
|
+
model?: string;
|
|
64
|
+
usage?: ModelUsage;
|
|
39
65
|
};
|
|
40
66
|
export interface CacheMetadata {
|
|
41
67
|
cacheHit?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.types.d.ts","sourceRoot":"","sources":["../../src/generic/chat.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAOhE,eAAO,MAAM,eAAe;;;;CAIlB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAOnF,MAAM,MAAM,WAAW,GAAG;IAItB,IAAI,EAAE,eAAe,CAAC;IAItB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAKD,MAAM,WAAW,sBAAsB;IAMnC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,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IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;CAChB,CAAC;
|
|
1
|
+
{"version":3,"file":"chat.types.js","sourceRoot":"","sources":["../../src/generic/chat.types.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAOnD,QAAA,eAAe,GAAG;IAC3B,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;CAChB,CAAC;AA0GX,MAAa,UAAW,SAAQ,sBAAU;IAA1C;;QAII,aAAQ,GAAkB,EAAE,CAAC;QAO7B,cAAS,GAAa,KAAK,CAAC;QAsB5B,kBAAa,GAAa,IAAI,CAAC;QAQ/B,oBAAe,GAAa,KAAK,CAAC;IACtC,CAAC;CAAA;AA1CD,gCA0CC;AAMD,SAAgB,4BAA4B,CAAC,CAAa;IACtD,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,uBAAe,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;AAC1E,CAAC;AAFD,oEAEC;AAMD,SAAgB,6BAA6B,CAAC,CAAa;IACvD,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,uBAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;AAC5E,CAAC;AAFD,sEAEC;AAqGD,MAAa,UAAW,SAAQ,sBAAU;CASzC;AATD,gCASC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { BaseResult } from "./baseModel";
|
|
2
|
-
import { ChatParams } from "./chat.types";
|
|
2
|
+
import { ChatMessageContent, ChatParams } from "./chat.types";
|
|
3
3
|
export declare class SummarizeParams extends ChatParams {
|
|
4
4
|
}
|
|
5
5
|
export declare class SummarizeResult extends BaseResult {
|
|
6
|
-
text: string;
|
|
6
|
+
get text(): string;
|
|
7
|
+
private _text;
|
|
7
8
|
summaryText: string;
|
|
8
|
-
constructor(text:
|
|
9
|
+
constructor(text: ChatMessageContent, summaryText: string, success: boolean, startTime: Date, endTime: Date);
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=summarize.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.types.d.ts","sourceRoot":"","sources":["../../src/generic/summarize.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"summarize.types.d.ts","sourceRoot":"","sources":["../../src/generic/summarize.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,kBAAkB,EAA2B,UAAU,EAAE,MAAM,cAAc,CAAC;AAMvF,qBAAa,eAAgB,SAAQ,UAAU;CAC9C;AAED,qBAAa,eAAgB,SAAQ,UAAU;IAC3C,IAAW,IAAI,IAAI,MAAM,CAExB;IACD,OAAO,CAAC,KAAK,CAAS;IAEtB,WAAW,EAAE,MAAM,CAAA;gBACN,IAAI,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI;CAU/G"}
|
|
@@ -7,9 +7,15 @@ class SummarizeParams extends chat_types_1.ChatParams {
|
|
|
7
7
|
}
|
|
8
8
|
exports.SummarizeParams = SummarizeParams;
|
|
9
9
|
class SummarizeResult extends baseModel_1.BaseResult {
|
|
10
|
+
get text() {
|
|
11
|
+
return this._text;
|
|
12
|
+
}
|
|
10
13
|
constructor(text, summaryText, success, startTime, endTime) {
|
|
11
14
|
super(success, startTime, endTime);
|
|
12
|
-
|
|
15
|
+
if (Array.isArray(text)) {
|
|
16
|
+
text = text.filter((block) => block.type === 'text').map((block) => block.content).join('\n\n');
|
|
17
|
+
}
|
|
18
|
+
this._text = text;
|
|
13
19
|
this.summaryText = summaryText;
|
|
14
20
|
}
|
|
15
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.types.js","sourceRoot":"","sources":["../../src/generic/summarize.types.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"summarize.types.js","sourceRoot":"","sources":["../../src/generic/summarize.types.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AACpD,6CAAuF;AAMvF,MAAa,eAAgB,SAAQ,uBAAU;CAC9C;AADD,0CACC;AAED,MAAa,eAAgB,SAAQ,sBAAU;IAC3C,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAID,YAAa,IAAwB,EAAE,WAAmB,EAAE,OAAgB,EAAE,SAAe,EAAE,OAAa;QACxG,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAGnC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpG,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;CACJ;AAjBD,0CAiBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.41.0",
|
|
4
4
|
"description": "MemberJunction: AI Module - LLMs and other AI services wrapped and abstracted for use in MemberJunction",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"author": "MemberJunction.com",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@memberjunction/global": "2.
|
|
18
|
+
"@memberjunction/global": "2.41.0",
|
|
19
19
|
"dotenv": "^16.4.1",
|
|
20
20
|
"rxjs": "^7.8.1",
|
|
21
21
|
"typeorm": "^0.3.20"
|
package/readme.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# @memberjunction/ai
|
|
2
2
|
|
|
3
|
-
The MemberJunction AI Core package provides a comprehensive abstraction layer for working with various AI models (LLMs, embedding models, etc.) in a provider-agnostic way, allowing your application to easily switch between different AI providers without refactoring your code.
|
|
3
|
+
The MemberJunction AI Core package provides a comprehensive abstraction layer for working with various AI models (LLMs, Video and Audio Generation, Text-To-Speech (TTS), embedding models, etc.) in a provider-agnostic way, allowing your application to easily switch between different AI providers without refactoring your code.
|
|
4
|
+
|
|
5
|
+
## Standalone Usage
|
|
6
|
+
|
|
7
|
+
**IMPORTANT**: This package can be used completely independently from the rest of the MemberJunction framework:
|
|
8
|
+
|
|
9
|
+
- **Zero** database setup required
|
|
10
|
+
- No environment variables or other settings expected (you are responsible for this and pass in API keys to the constructors)
|
|
11
|
+
- Works in any TypeScript environment that can safely make API calls (e.g. don't use in browsers)
|
|
12
|
+
- Perfect for server-side applications, backend services, and CLI tools
|
|
13
|
+
|
|
14
|
+
The `@memberjunction/ai` package and all provider packages in `@memberjunction/ai-*` are designed to be lightweight, standalone modules that can be used in any TypeScript project.
|
|
4
15
|
|
|
5
16
|
## Features
|
|
6
17
|
|
|
@@ -30,29 +41,7 @@ npm install @memberjunction/ai-mistral
|
|
|
30
41
|
|
|
31
42
|
## Usage
|
|
32
43
|
|
|
33
|
-
###
|
|
34
|
-
|
|
35
|
-
Directly use a specific AI provider when you know which one you need:
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
import { OpenAILLM } from '@memberjunction/ai-openai';
|
|
39
|
-
|
|
40
|
-
// Create an instance with your API key
|
|
41
|
-
const llm = new OpenAILLM('your-openai-api-key');
|
|
42
|
-
|
|
43
|
-
// Use the provider-specific implementation
|
|
44
|
-
const result = await llm.ChatCompletion({
|
|
45
|
-
model: 'gpt-4',
|
|
46
|
-
messages: [
|
|
47
|
-
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
48
|
-
{ role: 'user', content: 'What is AI abstraction?' }
|
|
49
|
-
]
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
console.log(result.data.choices[0].message.content);
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Provider-Agnostic Usage
|
|
44
|
+
### Provider-Agnostic Usage (Recommended)
|
|
56
45
|
|
|
57
46
|
For maximum flexibility, use the class factory approach to select the provider at runtime:
|
|
58
47
|
|
|
@@ -60,7 +49,11 @@ For maximum flexibility, use the class factory approach to select the provider a
|
|
|
60
49
|
import { BaseLLM, ChatParams } from '@memberjunction/ai';
|
|
61
50
|
import { MJGlobal } from '@memberjunction/global';
|
|
62
51
|
|
|
63
|
-
//
|
|
52
|
+
// Required to stop tree-shaking of the MistralLLM - since there's no static code path to this class when using Class Factory pattern, you need this to prevent some bundlers from tree-shaking optimization on this class.
|
|
53
|
+
import { LoadMistralLLM } from '@memberjunction/ai-mistral';
|
|
54
|
+
LoadMistralLLM();
|
|
55
|
+
|
|
56
|
+
// Get an implementation of BaseLLM by provider name
|
|
64
57
|
const llm = MJGlobal.Instance.ClassFactory.CreateInstance<BaseLLM>(
|
|
65
58
|
BaseLLM,
|
|
66
59
|
'MistralLLM', // Provider class name
|
|
@@ -88,6 +81,10 @@ import { BaseLLM } from '@memberjunction/ai';
|
|
|
88
81
|
import { MJGlobal } from '@memberjunction/global';
|
|
89
82
|
import dotenv from 'dotenv';
|
|
90
83
|
|
|
84
|
+
// Required to stop tree-shaking of the OpenAILLM - since there's no static code path to this class when using Class Factory pattern, you need this to prevent some bundlers from tree-shaking optimization on this class.
|
|
85
|
+
import { LoadOpenAILLM } from '@memberjunction/ai-openai';
|
|
86
|
+
LoadOpenAILLM();
|
|
87
|
+
|
|
91
88
|
dotenv.config();
|
|
92
89
|
|
|
93
90
|
const providerName = process.env.AI_PROVIDER || 'OpenAILLM';
|
|
@@ -100,6 +97,29 @@ const llm = MJGlobal.Instance.ClassFactory.CreateInstance<BaseLLM>(
|
|
|
100
97
|
);
|
|
101
98
|
```
|
|
102
99
|
|
|
100
|
+
### Direct Provider Usage
|
|
101
|
+
|
|
102
|
+
When necessary, you can directly use a specific AI provider:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { OpenAILLM } from '@memberjunction/ai-openai';
|
|
106
|
+
|
|
107
|
+
// Note with direct use of the OpenAILLM class no need for the LoadOpenAILLM call to prevent tree shaking since there is a static code path to the class
|
|
108
|
+
// Create an instance with your API key
|
|
109
|
+
const llm = new OpenAILLM('your-openai-api-key');
|
|
110
|
+
|
|
111
|
+
// Use the provider-specific implementation
|
|
112
|
+
const result = await llm.ChatCompletion({
|
|
113
|
+
model: 'gpt-4',
|
|
114
|
+
messages: [
|
|
115
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
116
|
+
{ role: 'user', content: 'What is AI abstraction?' }
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
console.log(result.data.choices[0].message.content);
|
|
121
|
+
```
|
|
122
|
+
|
|
103
123
|
## Core Abstractions
|
|
104
124
|
|
|
105
125
|
### Base Models
|
|
@@ -136,7 +156,7 @@ const result: ChatResult = await llm.ChatCompletion(params);
|
|
|
136
156
|
|
|
137
157
|
### Streaming Chat Completion
|
|
138
158
|
|
|
139
|
-
For real-time streaming of responses
|
|
159
|
+
For real-time streaming of responses:
|
|
140
160
|
|
|
141
161
|
```typescript
|
|
142
162
|
import { ChatParams, ChatResult, ChatMessage, StreamingChatCallbacks } from '@memberjunction/ai';
|
|
@@ -180,26 +200,6 @@ const params: ChatParams = {
|
|
|
180
200
|
await llm.ChatCompletion(params);
|
|
181
201
|
```
|
|
182
202
|
|
|
183
|
-
### Checking Streaming Support
|
|
184
|
-
|
|
185
|
-
Check if a provider supports streaming before enabling it:
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
// Check if the provider supports streaming
|
|
189
|
-
if (llm.SupportsStreaming) {
|
|
190
|
-
console.log("Provider supports streaming!");
|
|
191
|
-
params.streaming = true;
|
|
192
|
-
params.streamingCallbacks = callbacks;
|
|
193
|
-
} else {
|
|
194
|
-
console.log("Provider doesn't support streaming, using standard request");
|
|
195
|
-
params.streaming = false;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// The call automatically handles both streaming and non-streaming paths
|
|
199
|
-
await llm.ChatCompletion(params);
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
|
|
203
203
|
### Text Summarization
|
|
204
204
|
|
|
205
205
|
For summarizing longer text content:
|
|
@@ -282,29 +282,24 @@ console.log('Completion Tokens:', result.data.usage.completionTokens);
|
|
|
282
282
|
console.log('Total Tokens:', result.data.usage.totalTokens);
|
|
283
283
|
```
|
|
284
284
|
|
|
285
|
-
## Provider Streaming Support
|
|
286
|
-
|
|
287
|
-
The following providers support streaming in the current implementation:
|
|
288
|
-
|
|
289
|
-
| Provider | Streaming Support |
|
|
290
|
-
|----------|------------------|
|
|
291
|
-
| OpenAI | ✅ Full support |
|
|
292
|
-
| Anthropic | ✅ Full support |
|
|
293
|
-
| Mistral | ✅ Full support |
|
|
294
|
-
| Groq | ✅ Full support |
|
|
295
|
-
| Gemini | ✅ Full support |
|
|
296
|
-
| BettyBot | ❌ Not supported |
|
|
297
|
-
|
|
298
285
|
## Available Providers
|
|
299
286
|
|
|
300
287
|
The following provider packages implement the MemberJunction AI abstractions:
|
|
301
288
|
|
|
302
|
-
- `@memberjunction/ai-openai` - OpenAI (GPT models)
|
|
303
|
-
- `@memberjunction/ai-anthropic` - Anthropic (Claude models)
|
|
304
|
-
- `@memberjunction/ai-mistral` - Mistral AI
|
|
305
|
-
- `@memberjunction/ai-gemini` - Google's Gemini models
|
|
306
|
-
- `@memberjunction/ai-
|
|
307
|
-
- `@memberjunction/ai-
|
|
289
|
+
- [`@memberjunction/ai-openai`](../Providers/OpenAI/readme.md) - OpenAI (GPT models)
|
|
290
|
+
- [`@memberjunction/ai-anthropic`](../Providers/Anthropic/readme.md) - Anthropic (Claude models)
|
|
291
|
+
- [`@memberjunction/ai-mistral`](../Providers/Mistral/readme.md) - Mistral AI
|
|
292
|
+
- [`@memberjunction/ai-gemini`](../Providers/Gemini/readme.md) - Google's Gemini models
|
|
293
|
+
- [`@memberjunction/ai-vertex`](../Providers/Vertex/readme.md) - Google Vertex AI (various models including Gemini, others)
|
|
294
|
+
- [`@memberjunction/ai-bedrock`](../Providers/Bedrock/readme.md) - Amazon Bedrock (Claude, Llama, Titan, etc.)
|
|
295
|
+
- [`@memberjunction/ai-groq`](../Providers/Groq/readme.md) - Groq's optimized inference (https://www.groq.com)
|
|
296
|
+
- [`@memberjunction/ai-bettybot`](../Providers/BettyBot/readme.md) - Betty AI (https://www.meetbetty.ai)
|
|
297
|
+
- [`@memberjunction/ai-azure`](../Providers/Azure/readme.md) - Azure AI Foundry with support for OpenAI, Mistral, Phi, more
|
|
298
|
+
- [`@memberjunction/ai-cerebras`](../Providers/Cerebras/readme.md) - Cerebras models
|
|
299
|
+
- [`@memberjunction/ai-elevenlabs`](../Providers/ElevenLabs/readme.md) - ElevenLabs audio models
|
|
300
|
+
- [`@memberjunction/ai-heygen`](../Providers/HeyGen/readme.md) - HeyGen video models
|
|
301
|
+
|
|
302
|
+
Note: Each provider implements the features they support. See individual provider documentation for specific capabilities.
|
|
308
303
|
|
|
309
304
|
## Implementation Details
|
|
310
305
|
|
|
@@ -325,8 +320,6 @@ This architecture allows for a clean separation between common streaming logic a
|
|
|
325
320
|
|
|
326
321
|
- `@memberjunction/global` - MemberJunction global utilities including class factory
|
|
327
322
|
- `rxjs` - Reactive extensions for JavaScript
|
|
328
|
-
- `typeorm` - ORM for database operations
|
|
329
323
|
|
|
330
324
|
## License
|
|
331
|
-
|
|
332
|
-
ISC
|
|
325
|
+
See the [repository root](../../../LICENSE) for license information.
|