@memorilabs/memori 0.0.1 → 0.0.3
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 +194 -0
- package/dist/core/config.d.ts +42 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +70 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.d.ts +32 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +57 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/network.d.ts +24 -0
- package/dist/core/network.d.ts.map +1 -0
- package/dist/core/network.js +136 -0
- package/dist/core/network.js.map +1 -0
- package/dist/core/session.d.ts +25 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +36 -0
- package/dist/core/session.js.map +1 -0
- package/dist/engines/augmentation.d.ts +13 -0
- package/dist/engines/augmentation.d.ts.map +1 -0
- package/dist/engines/augmentation.js +57 -0
- package/dist/engines/augmentation.js.map +1 -0
- package/dist/engines/persistence.d.ts +12 -0
- package/dist/engines/persistence.d.ts.map +1 -0
- package/dist/engines/persistence.js +38 -0
- package/dist/engines/persistence.js.map +1 -0
- package/dist/engines/recall.d.ts +14 -0
- package/dist/engines/recall.d.ts.map +1 -0
- package/dist/engines/recall.js +89 -0
- package/dist/engines/recall.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/base.d.ts +34 -0
- package/dist/integrations/base.d.ts.map +1 -0
- package/dist/integrations/base.js +77 -0
- package/dist/integrations/base.js.map +1 -0
- package/dist/integrations/index.d.ts +3 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +2 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/openclaw.d.ts +42 -0
- package/dist/integrations/openclaw.d.ts.map +1 -0
- package/dist/integrations/openclaw.js +53 -0
- package/dist/integrations/openclaw.js.map +1 -0
- package/dist/memori.d.ts +84 -0
- package/dist/memori.d.ts.map +1 -0
- package/dist/memori.js +127 -0
- package/dist/memori.js.map +1 -0
- package/dist/types/api.d.ts +51 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/integrations.d.ts +83 -0
- package/dist/types/integrations.d.ts.map +1 -0
- package/dist/types/integrations.js +2 -0
- package/dist/types/integrations.js.map +1 -0
- package/dist/utils/utils.d.ts +17 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +84 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +93 -4
- package/.npmrc.bak +0 -3
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
[](https://memorilabs.ai/)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>The memory fabric for enterprise AI</strong>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<i>Memori plugs into the software and infrastructure you already use. It is LLM and framework agnostic and seamlessly integrates into the architecture you've already designed.</i>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@memorilabs/memori">
|
|
13
|
+
<img src="https://img.shields.io/npm/v/@memorilabs/memori.svg" alt="NPM version">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/@memorilabs/memori">
|
|
16
|
+
<img src="https://img.shields.io/npm/dm/@memorilabs/memori.svg" alt="NPM Downloads">
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://opensource.org/license/apache-2-0">
|
|
19
|
+
<img src="https://img.shields.io/badge/license-Apache%202.0-blue" alt="License">
|
|
20
|
+
</a>
|
|
21
|
+
<a href="https://discord.gg/abD4eGym6v">
|
|
22
|
+
<img src="https://img.shields.io/discord/1042405378304004156?logo=discord" alt="Discord">
|
|
23
|
+
</a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Getting Started
|
|
29
|
+
|
|
30
|
+
Install the Memori SDK and your preferred LLM client using your package manager of choice:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @memorilabs/memori
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
_(Note: Memori currently supports `openai` and `@anthropic-ai/sdk` as peer dependencies)._
|
|
37
|
+
|
|
38
|
+
## Quickstart Example
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import 'dotenv/config';
|
|
42
|
+
import { OpenAI } from 'openai';
|
|
43
|
+
import { Memori } from '@memorilabs/memori';
|
|
44
|
+
|
|
45
|
+
// Environment check
|
|
46
|
+
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
|
47
|
+
if (!OPENAI_API_KEY) {
|
|
48
|
+
console.error('Error: OPENAI_API_KEY must be set in .env');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 1. Initialize the LLM Client
|
|
53
|
+
const client = new OpenAI({ apiKey: OPENAI_API_KEY });
|
|
54
|
+
|
|
55
|
+
// 2. Initialize Memori and Register the Client
|
|
56
|
+
const memori = new Memori().llm
|
|
57
|
+
.register(client)
|
|
58
|
+
.attribution('typescript-sdk-test-user', 'test-process-1');
|
|
59
|
+
|
|
60
|
+
async function main() {
|
|
61
|
+
console.log('--- Step 1: Teaching the AI ---');
|
|
62
|
+
const factPrompt = 'My favorite color is blue and I live in Paris.';
|
|
63
|
+
console.log(`User: ${factPrompt}`);
|
|
64
|
+
|
|
65
|
+
// This call automatically triggers Persistence and Augmentation in the background.
|
|
66
|
+
const response1 = await client.chat.completions.create({
|
|
67
|
+
model: 'gpt-4o-mini',
|
|
68
|
+
messages: [{ role: 'user', content: factPrompt }],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.log(`AI: ${response1.choices[0].message.content}`);
|
|
72
|
+
|
|
73
|
+
console.log('\n(Waiting 5 seconds for backend processing...)\n');
|
|
74
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
75
|
+
|
|
76
|
+
console.log('--- Step 2: Testing Recall ---');
|
|
77
|
+
const questionPrompt = 'What is my favorite color?';
|
|
78
|
+
console.log(`User: ${questionPrompt}`);
|
|
79
|
+
|
|
80
|
+
// This call automatically triggers Recall, injecting the Paris/Blue facts into the prompt.
|
|
81
|
+
const response2 = await client.chat.completions.create({
|
|
82
|
+
model: 'gpt-4o-mini',
|
|
83
|
+
messages: [{ role: 'user', content: questionPrompt }],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
console.log(`AI: ${response2.choices[0].message.content}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
main().catch(console.error);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Key Features
|
|
93
|
+
|
|
94
|
+
- **Zero-Latency Memory:** Background processing ensures your LLM calls are never slowed down.
|
|
95
|
+
- **Advanced Augmentation:** Automatically extracts and structures facts, preferences, and relationships.
|
|
96
|
+
- **Cloud-Hosted:** Fully managed infrastructure via the Memori Cloud API.
|
|
97
|
+
- **LLM Agnostic:** Native support for the official OpenAI and Anthropic SDKs via interceptors.
|
|
98
|
+
- **Automatic Prompt Injection:** Seamlessly fetches relevant memories and injects them into the system context.
|
|
99
|
+
|
|
100
|
+
## Attribution
|
|
101
|
+
|
|
102
|
+
To get the most out of Memori, you want to attribute your LLM interactions to an entity (think person, place or thing; like a user) and a process (think your agent, LLM interaction or program).
|
|
103
|
+
|
|
104
|
+
If you do not provide any attribution, Memori cannot make memories for you.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
memori.attribution('user-123', 'my-app');
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Session Management
|
|
111
|
+
|
|
112
|
+
Memori uses sessions to group your LLM interactions together. For example, if you have an agent that executes multiple steps you want those to be recorded in a single session.
|
|
113
|
+
|
|
114
|
+
By default, Memori handles setting the session for you but you can start a new session or override the session by executing the following:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
memori.resetSession();
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
or
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const sessionId = memori.session.id;
|
|
124
|
+
|
|
125
|
+
// ... Later ...
|
|
126
|
+
|
|
127
|
+
memori.setSession(sessionId);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Supported LLMs
|
|
131
|
+
|
|
132
|
+
- Anthropic Claude (`@anthropic-ai/sdk`)
|
|
133
|
+
- OpenAI (`openai`)
|
|
134
|
+
- Gemini (`@google/genai`)
|
|
135
|
+
|
|
136
|
+
## Memori Advanced Augmentation
|
|
137
|
+
|
|
138
|
+
Memories are tracked at several different levels:
|
|
139
|
+
|
|
140
|
+
- **entity**: think person, place, or thing; like a user
|
|
141
|
+
- **process**: think your agent, LLM interaction or program
|
|
142
|
+
- **session**: the current interactions between the entity, process and the LLM
|
|
143
|
+
|
|
144
|
+
[Memori's Advanced Augmentation](https://github.com/MemoriLabs/Memori/blob/main/docs/advanced-augmentation.md) enhances memories at each of these levels with:
|
|
145
|
+
|
|
146
|
+
- attributes
|
|
147
|
+
- events
|
|
148
|
+
- facts
|
|
149
|
+
- people
|
|
150
|
+
- preferences
|
|
151
|
+
- relationships
|
|
152
|
+
- rules
|
|
153
|
+
- skills
|
|
154
|
+
|
|
155
|
+
Memori knows who your user is, what tasks your agent handles and creates unparalleled context between the two. Augmentation occurs asynchronously in the background incurring no latency.
|
|
156
|
+
|
|
157
|
+
By default, Memori Advanced Augmentation is available without an account but is rate limited. When you need increased limits, [sign up for Memori Advanced Augmentation](https://app.memorilabs.ai/signup).
|
|
158
|
+
|
|
159
|
+
Memori Advanced Augmentation is always free for developers!
|
|
160
|
+
|
|
161
|
+
Once you've obtained an API key, simply set the following environment variable:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
export MEMORI_API_KEY=[api_key]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Managing Your Quota
|
|
168
|
+
|
|
169
|
+
You can check your quota and manage your account by logging in at [https://memorilabs.ai/](https://memorilabs.ai/). If you have reached your IP address quota, sign up and get an API key for increased limits.
|
|
170
|
+
|
|
171
|
+
If your API key exceeds its quota limits we will email you and let you know.
|
|
172
|
+
|
|
173
|
+
## Contributing
|
|
174
|
+
|
|
175
|
+
We welcome contributions from the community! Please see our [Contributing Guidelines](https://github.com/MemoriLabs/Memori/blob/main/CONTRIBUTING.md) for details on:
|
|
176
|
+
|
|
177
|
+
- Setting up your development environment
|
|
178
|
+
- Code style and standards
|
|
179
|
+
- Submitting pull requests
|
|
180
|
+
- Reporting issues
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Support
|
|
185
|
+
|
|
186
|
+
- **Documentation**: [https://memorilabs.ai/docs](https://memorilabs.ai/docs)
|
|
187
|
+
- **Discord**: [https://discord.gg/abD4eGym6v](https://discord.gg/abD4eGym6v)
|
|
188
|
+
- **Issues**: [GitHub Issues](https://github.com/MemoriLabs/Memori/issues)
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
Apache 2.0 - see [LICENSE](https://github.com/MemoriLabs/Memori/blob/main/LICENSE)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare class Config {
|
|
2
|
+
/**
|
|
3
|
+
* The API Key used for authentication.
|
|
4
|
+
* Defaults to `MEMORI_API_KEY` environment variable.
|
|
5
|
+
*/
|
|
6
|
+
apiKey: string | null;
|
|
7
|
+
/**
|
|
8
|
+
* The base URL for the Memori API.
|
|
9
|
+
* Automatically switches between production and staging based on `testMode`.
|
|
10
|
+
*/
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the SDK is running in test/staging mode.
|
|
14
|
+
* Defaults to `true` if `MEMORI_TEST_MODE` is set to '1'.
|
|
15
|
+
*/
|
|
16
|
+
testMode: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The unique identifier for the end-user associated with the current memories.
|
|
19
|
+
*/
|
|
20
|
+
entityId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The unique identifier for the specific process or workflow.
|
|
23
|
+
*/
|
|
24
|
+
processId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The current conversation session ID.
|
|
27
|
+
* Included in all requests to track conversation history.
|
|
28
|
+
*/
|
|
29
|
+
sessionId: string;
|
|
30
|
+
/**
|
|
31
|
+
* The minimum relevance score (0.0 to 1.0) required for a memory to be included in the context.
|
|
32
|
+
* Defaults to 0.1.
|
|
33
|
+
*/
|
|
34
|
+
recallRelevanceThreshold: number;
|
|
35
|
+
/**
|
|
36
|
+
* Request timeout in milliseconds.
|
|
37
|
+
* Defaults to 5000ms (5 seconds).
|
|
38
|
+
*/
|
|
39
|
+
timeout: number;
|
|
40
|
+
constructor();
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAYA,qBAAa,MAAM;IACjB;;;OAGG;IACI,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7B;;;OAGG;IACI,OAAO,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACI,QAAQ,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACI,QAAQ,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACI,SAAS,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACI,SAAS,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACI,wBAAwB,EAAE,MAAM,CAAC;IAExC;;;OAGG;IACI,OAAO,EAAE,MAAM,CAAC;;CAuBxB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Utility to safely retrieve environment variables across Node.js and other runtimes.
|
|
4
|
+
*/
|
|
5
|
+
function getEnv(key) {
|
|
6
|
+
if (typeof process !== 'undefined') {
|
|
7
|
+
return process.env[key];
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
export class Config {
|
|
12
|
+
/**
|
|
13
|
+
* The API Key used for authentication.
|
|
14
|
+
* Defaults to `MEMORI_API_KEY` environment variable.
|
|
15
|
+
*/
|
|
16
|
+
apiKey;
|
|
17
|
+
/**
|
|
18
|
+
* The base URL for the Memori API.
|
|
19
|
+
* Automatically switches between production and staging based on `testMode`.
|
|
20
|
+
*/
|
|
21
|
+
baseUrl;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the SDK is running in test/staging mode.
|
|
24
|
+
* Defaults to `true` if `MEMORI_TEST_MODE` is set to '1'.
|
|
25
|
+
*/
|
|
26
|
+
testMode;
|
|
27
|
+
/**
|
|
28
|
+
* The unique identifier for the end-user associated with the current memories.
|
|
29
|
+
*/
|
|
30
|
+
entityId;
|
|
31
|
+
/**
|
|
32
|
+
* The unique identifier for the specific process or workflow.
|
|
33
|
+
*/
|
|
34
|
+
processId;
|
|
35
|
+
/**
|
|
36
|
+
* The current conversation session ID.
|
|
37
|
+
* Included in all requests to track conversation history.
|
|
38
|
+
*/
|
|
39
|
+
sessionId;
|
|
40
|
+
/**
|
|
41
|
+
* The minimum relevance score (0.0 to 1.0) required for a memory to be included in the context.
|
|
42
|
+
* Defaults to 0.1.
|
|
43
|
+
*/
|
|
44
|
+
recallRelevanceThreshold;
|
|
45
|
+
/**
|
|
46
|
+
* Request timeout in milliseconds.
|
|
47
|
+
* Defaults to 5000ms (5 seconds).
|
|
48
|
+
*/
|
|
49
|
+
timeout;
|
|
50
|
+
constructor() {
|
|
51
|
+
// 1. Environment and Base URL Logic
|
|
52
|
+
this.testMode = getEnv('MEMORI_TEST_MODE') === '1';
|
|
53
|
+
const envUrl = getEnv('MEMORI_API_URL_BASE');
|
|
54
|
+
if (envUrl) {
|
|
55
|
+
this.baseUrl = envUrl;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.baseUrl = this.testMode
|
|
59
|
+
? 'https://staging-api.memorilabs.ai'
|
|
60
|
+
: 'https://api.memorilabs.ai';
|
|
61
|
+
}
|
|
62
|
+
// 2. Authentication
|
|
63
|
+
this.apiKey = getEnv('MEMORI_API_KEY') ?? null;
|
|
64
|
+
// 3. Session and Defaults
|
|
65
|
+
this.sessionId = randomUUID();
|
|
66
|
+
this.recallRelevanceThreshold = 0.1;
|
|
67
|
+
this.timeout = 5000;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,SAAS,MAAM,CAAC,GAAW;IACzB,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,OAAO,MAAM;IACjB;;;OAGG;IACI,MAAM,CAAgB;IAE7B;;;OAGG;IACI,OAAO,CAAS;IAEvB;;;OAGG;IACI,QAAQ,CAAU;IAEzB;;OAEG;IACI,QAAQ,CAAU;IAEzB;;OAEG;IACI,SAAS,CAAU;IAE1B;;;OAGG;IACI,SAAS,CAAS;IAEzB;;;OAGG;IACI,wBAAwB,CAAS;IAExC;;;OAGG;IACI,OAAO,CAAS;IAEvB;QACE,oCAAoC;QACpC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,KAAK,GAAG,CAAC;QAEnD,MAAM,MAAM,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAC7C,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ;gBAC1B,CAAC,CAAC,mCAAmC;gBACrC,CAAC,CAAC,2BAA2B,CAAC;QAClC,CAAC;QAED,oBAAoB;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,IAAI,CAAC;QAE/C,0BAA0B;QAC1B,IAAI,CAAC,SAAS,GAAG,UAAU,EAAE,CAAC;QAC9B,IAAI,CAAC,wBAAwB,GAAG,GAAG,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { UnsupportedLLMProviderError } from '@memorilabs/axon';
|
|
2
|
+
/** Base class for all Memori SDK errors. */
|
|
3
|
+
export declare class MemoriError extends Error {
|
|
4
|
+
constructor(message: string);
|
|
5
|
+
}
|
|
6
|
+
/** Thrown when the Memori Cloud IP rate limit or account quota is exceeded. */
|
|
7
|
+
export declare class QuotaExceededError extends MemoriError {
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
|
10
|
+
/** Thrown when the Memori Cloud API returns a 4xx or 5xx status code. */
|
|
11
|
+
export declare class MemoriApiClientError extends MemoriError {
|
|
12
|
+
readonly statusCode: number;
|
|
13
|
+
readonly details?: unknown;
|
|
14
|
+
constructor(statusCode: number, message?: string, details?: unknown);
|
|
15
|
+
}
|
|
16
|
+
/** Thrown when the Memori Cloud API rejects a request due to validation errors (422). */
|
|
17
|
+
export declare class MemoriApiValidationError extends MemoriApiClientError {
|
|
18
|
+
constructor(statusCode: number, message: string, details?: unknown);
|
|
19
|
+
}
|
|
20
|
+
/** Thrown when the Memori Cloud API explicitly rejects a request (433). */
|
|
21
|
+
export declare class MemoriApiRequestRejectedError extends MemoriApiClientError {
|
|
22
|
+
constructor(statusCode: number, message: string, details?: unknown);
|
|
23
|
+
}
|
|
24
|
+
/** Thrown when a request requires an API key but none was found in the environment or config. */
|
|
25
|
+
export declare class MissingMemoriApiKeyError extends MemoriError {
|
|
26
|
+
constructor(envVar?: string);
|
|
27
|
+
}
|
|
28
|
+
/** Thrown when a network request to the Memori API exceeds the configured timeout duration. */
|
|
29
|
+
export declare class TimeoutError extends MemoriError {
|
|
30
|
+
constructor(timeout: number);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,4CAA4C;AAC5C,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAK5B;AAED,+EAA+E;AAC/E,qBAAa,kBAAmB,SAAQ,WAAW;gBACrC,OAAO,CAAC,EAAE,MAAM;CAO7B;AAED,yEAAyE;AACzE,qBAAa,oBAAqB,SAAQ,WAAW;IACnD,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEtB,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAMpE;AAED,yFAAyF;AACzF,qBAAa,wBAAyB,SAAQ,oBAAoB;gBACpD,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAInE;AAED,2EAA2E;AAC3E,qBAAa,6BAA8B,SAAQ,oBAAoB;gBACzD,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAInE;AAED,iGAAiG;AACjG,qBAAa,wBAAyB,SAAQ,WAAW;gBAC3C,MAAM,SAAmB;CAMtC;AAED,+FAA+F;AAC/F,qBAAa,YAAa,SAAQ,WAAW;gBAC/B,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export { UnsupportedLLMProviderError } from '@memorilabs/axon';
|
|
2
|
+
/** Base class for all Memori SDK errors. */
|
|
3
|
+
export class MemoriError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'MemoriError';
|
|
7
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Thrown when the Memori Cloud IP rate limit or account quota is exceeded. */
|
|
11
|
+
export class QuotaExceededError extends MemoriError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message ||
|
|
14
|
+
'Your IP address is over quota; register for an API key now: https://app.memorilabs.ai/signup');
|
|
15
|
+
this.name = 'QuotaExceededError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Thrown when the Memori Cloud API returns a 4xx or 5xx status code. */
|
|
19
|
+
export class MemoriApiClientError extends MemoriError {
|
|
20
|
+
statusCode;
|
|
21
|
+
details;
|
|
22
|
+
constructor(statusCode, message, details) {
|
|
23
|
+
super(message || `Memori API request failed with status ${statusCode}`);
|
|
24
|
+
this.name = 'MemoriApiClientError';
|
|
25
|
+
this.statusCode = statusCode;
|
|
26
|
+
this.details = details;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Thrown when the Memori Cloud API rejects a request due to validation errors (422). */
|
|
30
|
+
export class MemoriApiValidationError extends MemoriApiClientError {
|
|
31
|
+
constructor(statusCode, message, details) {
|
|
32
|
+
super(statusCode, message, details);
|
|
33
|
+
this.name = 'MemoriApiValidationError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Thrown when the Memori Cloud API explicitly rejects a request (433). */
|
|
37
|
+
export class MemoriApiRequestRejectedError extends MemoriApiClientError {
|
|
38
|
+
constructor(statusCode, message, details) {
|
|
39
|
+
super(statusCode, message, details);
|
|
40
|
+
this.name = 'MemoriApiRequestRejectedError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Thrown when a request requires an API key but none was found in the environment or config. */
|
|
44
|
+
export class MissingMemoriApiKeyError extends MemoriError {
|
|
45
|
+
constructor(envVar = 'MEMORI_API_KEY') {
|
|
46
|
+
super(`A ${envVar} is required to use the Memori cloud API. Sign up at https://app.memorilabs.ai/signup`);
|
|
47
|
+
this.name = 'MissingMemoriApiKeyError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Thrown when a network request to the Memori API exceeds the configured timeout duration. */
|
|
51
|
+
export class TimeoutError extends MemoriError {
|
|
52
|
+
constructor(timeout) {
|
|
53
|
+
super(`Request timed out after ${timeout}ms`);
|
|
54
|
+
this.name = 'TimeoutError';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,4CAA4C;AAC5C,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED,+EAA+E;AAC/E,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,YAAY,OAAgB;QAC1B,KAAK,CACH,OAAO;YACL,8FAA8F,CACjG,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,oBAAoB,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{ Config } from './config.js';
|
|
2
|
+
export declare enum ApiSubdomain {
|
|
3
|
+
DEFAULT = "api",
|
|
4
|
+
COLLECTOR = "collector"
|
|
5
|
+
}
|
|
6
|
+
export declare class Api {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly xApiKey;
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
constructor(config: Config, subdomain?: ApiSubdomain);
|
|
11
|
+
private getHeaders;
|
|
12
|
+
/**
|
|
13
|
+
* Performs a fetch request with exponential backoff and timeout handling.
|
|
14
|
+
* Retries on network errors, timeouts, and 5xx server errors.
|
|
15
|
+
*/
|
|
16
|
+
private request;
|
|
17
|
+
private executeAttempt;
|
|
18
|
+
private throwOnApiError;
|
|
19
|
+
get<T>(route: string): Promise<T>;
|
|
20
|
+
post<T>(route: string, body?: unknown): Promise<T>;
|
|
21
|
+
patch<T>(route: string, body?: unknown): Promise<T>;
|
|
22
|
+
delete<T>(route: string): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/core/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC,oBAAY,YAAY;IACtB,OAAO,QAAQ;IACf,SAAS,cAAc;CACxB;AAWD,qBAAa,GAAG;IACd,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,YAAmC;IAc1E,OAAO,CAAC,UAAU;IAalB;;;OAGG;YACW,OAAO;YA8CP,cAAc;YA4Bd,eAAe;IA8BtB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAIlD,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAInD,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAG5C"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { MemoriApiClientError, MemoriApiRequestRejectedError, MemoriApiValidationError, QuotaExceededError, TimeoutError, } from './errors.js';
|
|
2
|
+
export var ApiSubdomain;
|
|
3
|
+
(function (ApiSubdomain) {
|
|
4
|
+
ApiSubdomain["DEFAULT"] = "api";
|
|
5
|
+
ApiSubdomain["COLLECTOR"] = "collector";
|
|
6
|
+
})(ApiSubdomain || (ApiSubdomain = {}));
|
|
7
|
+
const PUBLIC_PROD_KEY = '96a7ea3e-11c2-428c-b9ae-5a168363dc80';
|
|
8
|
+
const PUBLIC_STAGING_KEY = 'c18b1022-7fe2-42af-ab01-b1f9139184f0';
|
|
9
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
export class Api {
|
|
11
|
+
config;
|
|
12
|
+
xApiKey;
|
|
13
|
+
baseUrl;
|
|
14
|
+
constructor(config, subdomain = ApiSubdomain.DEFAULT) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
if (subdomain === ApiSubdomain.COLLECTOR) {
|
|
17
|
+
this.baseUrl = this.config.baseUrl
|
|
18
|
+
.replace('://api.', '://collector.')
|
|
19
|
+
.replace('://staging-api.', '://staging-collector.');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.baseUrl = this.config.baseUrl;
|
|
23
|
+
}
|
|
24
|
+
this.xApiKey = this.config.testMode ? PUBLIC_STAGING_KEY : PUBLIC_PROD_KEY;
|
|
25
|
+
}
|
|
26
|
+
getHeaders() {
|
|
27
|
+
const headers = {
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
'X-Memori-API-Key': this.xApiKey,
|
|
30
|
+
};
|
|
31
|
+
if (this.config.apiKey) {
|
|
32
|
+
headers['Authorization'] = `Bearer ${this.config.apiKey}`;
|
|
33
|
+
}
|
|
34
|
+
return headers;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Performs a fetch request with exponential backoff and timeout handling.
|
|
38
|
+
* Retries on network errors, timeouts, and 5xx server errors.
|
|
39
|
+
*/
|
|
40
|
+
async request(method, route, body, options = {}) {
|
|
41
|
+
const url = `${this.baseUrl}/v1/${route}`;
|
|
42
|
+
const { maxRetries = 5, ...fetchInit } = options;
|
|
43
|
+
// Prepare the RequestInit once
|
|
44
|
+
const init = {
|
|
45
|
+
method,
|
|
46
|
+
headers: this.getHeaders(),
|
|
47
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
48
|
+
...fetchInit,
|
|
49
|
+
};
|
|
50
|
+
let attempt = 0;
|
|
51
|
+
let lastError = null;
|
|
52
|
+
while (attempt <= maxRetries) {
|
|
53
|
+
try {
|
|
54
|
+
return await this.executeAttempt(url, init);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
lastError = err;
|
|
58
|
+
// Determine if we should retry
|
|
59
|
+
const isNetworkError = err instanceof TypeError;
|
|
60
|
+
const isServer5xx = err instanceof MemoriApiClientError && err.statusCode >= 500 && err.statusCode <= 599;
|
|
61
|
+
const isTimeout = err instanceof TimeoutError;
|
|
62
|
+
if ((isNetworkError || isServer5xx || isTimeout) && attempt < maxRetries) {
|
|
63
|
+
const backoff = Math.pow(2, attempt) * 1000;
|
|
64
|
+
await delay(backoff);
|
|
65
|
+
attempt++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
throw lastError;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw lastError || new Error('Unknown network error');
|
|
72
|
+
}
|
|
73
|
+
async executeAttempt(url, init) {
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
const timeoutId = setTimeout(() => {
|
|
76
|
+
controller.abort();
|
|
77
|
+
}, this.config.timeout);
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
80
|
+
clearTimeout(timeoutId);
|
|
81
|
+
if (response.ok) {
|
|
82
|
+
if (response.status === 204)
|
|
83
|
+
return {};
|
|
84
|
+
return (await response.json());
|
|
85
|
+
}
|
|
86
|
+
await this.throwOnApiError(response);
|
|
87
|
+
throw new Error('Unreachable');
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
clearTimeout(timeoutId);
|
|
91
|
+
if (err.name === 'AbortError') {
|
|
92
|
+
throw new TimeoutError(this.config.timeout);
|
|
93
|
+
}
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async throwOnApiError(response) {
|
|
98
|
+
// Try to parse the error details safely
|
|
99
|
+
let errorData = {};
|
|
100
|
+
try {
|
|
101
|
+
errorData = (await response.json());
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// ignore parsing error
|
|
105
|
+
}
|
|
106
|
+
const message = errorData.message || errorData.detail;
|
|
107
|
+
const status = response.status;
|
|
108
|
+
// Map status codes to errors
|
|
109
|
+
if (status === 429)
|
|
110
|
+
throw new QuotaExceededError(message);
|
|
111
|
+
if (status === 422) {
|
|
112
|
+
throw new MemoriApiValidationError(status, message || 'Memori API rejected the request (422 validation error).');
|
|
113
|
+
}
|
|
114
|
+
if (status === 433) {
|
|
115
|
+
throw new MemoriApiRequestRejectedError(status, message || 'The request was rejected (433).');
|
|
116
|
+
}
|
|
117
|
+
if (status >= 500)
|
|
118
|
+
throw new MemoriApiClientError(status, message);
|
|
119
|
+
if (status >= 400)
|
|
120
|
+
throw new MemoriApiClientError(status, message);
|
|
121
|
+
throw new MemoriApiClientError(status, `Unknown error ${status}`);
|
|
122
|
+
}
|
|
123
|
+
get(route) {
|
|
124
|
+
return this.request('GET', route);
|
|
125
|
+
}
|
|
126
|
+
post(route, body) {
|
|
127
|
+
return this.request('POST', route, body);
|
|
128
|
+
}
|
|
129
|
+
patch(route, body) {
|
|
130
|
+
return this.request('PATCH', route, body);
|
|
131
|
+
}
|
|
132
|
+
delete(route) {
|
|
133
|
+
return this.request('DELETE', route);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/core/network.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAC7B,wBAAwB,EACxB,kBAAkB,EAClB,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,+BAAe,CAAA;IACf,uCAAuB,CAAA;AACzB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAED,MAAM,eAAe,GAAG,sCAAsC,CAAC;AAC/D,MAAM,kBAAkB,GAAG,sCAAsC,CAAC;AAMlE,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEhF,MAAM,OAAO,GAAG;IACG,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,OAAO,CAAS;IAEjC,YAAY,MAAc,EAAE,YAA0B,YAAY,CAAC,OAAO;QACxE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,SAAS,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO;iBAC/B,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC;iBACnC,OAAO,CAAC,iBAAiB,EAAE,uBAAuB,CAA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AAO,CAAC,CAAC;QACnE,IAAI,MAAM,IAAI,GAAG;YAAE,MAAM,IAAI,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEnE,MAAM,IAAI,oBAAoB,CAAC,MAAM,EAAE,iBAAiB,MAAM,EAAE,CAAC,CAAC;IACpE,CAAC;IAEM,GAAG,CAAI,KAAa;QACzB,OAAO,IAAI,CAAC,OAAO,CAAI,KAAK,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAEM,IAAI,CAAI,KAAa,EAAE,IAAc;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAI,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAI,KAAa,EAAE,IAAc;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAI,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAEM,MAAM,CAAI,KAAa;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAI,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages the conversation session lifecycle.
|
|
3
|
+
* Ensures consistent session IDs across requests to maintain conversation history.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SessionManager {
|
|
6
|
+
private _id;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* The current active session UUID.
|
|
10
|
+
*/
|
|
11
|
+
get id(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Generates a brand new random UUID for the session.
|
|
14
|
+
* Use this to clear context and start fresh.
|
|
15
|
+
*/
|
|
16
|
+
reset(): this;
|
|
17
|
+
/**
|
|
18
|
+
* Manually sets the session ID to a specific value.
|
|
19
|
+
* Useful for resuming a conversation from a database or frontend client.
|
|
20
|
+
*
|
|
21
|
+
* @param id - The UUID to reuse.
|
|
22
|
+
*/
|
|
23
|
+
set(id: string): this;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,GAAG,CAAS;;IAMpB;;OAEG;IACH,IAAW,EAAE,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACI,KAAK,IAAI,IAAI;IAKpB;;;;;OAKG;IACI,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAI7B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Manages the conversation session lifecycle.
|
|
4
|
+
* Ensures consistent session IDs across requests to maintain conversation history.
|
|
5
|
+
*/
|
|
6
|
+
export class SessionManager {
|
|
7
|
+
_id;
|
|
8
|
+
constructor() {
|
|
9
|
+
this._id = randomUUID();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The current active session UUID.
|
|
13
|
+
*/
|
|
14
|
+
get id() {
|
|
15
|
+
return this._id;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generates a brand new random UUID for the session.
|
|
19
|
+
* Use this to clear context and start fresh.
|
|
20
|
+
*/
|
|
21
|
+
reset() {
|
|
22
|
+
this._id = randomUUID();
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Manually sets the session ID to a specific value.
|
|
27
|
+
* Useful for resuming a conversation from a database or frontend client.
|
|
28
|
+
*
|
|
29
|
+
* @param id - The UUID to reuse.
|
|
30
|
+
*/
|
|
31
|
+
set(id) {
|
|
32
|
+
this._id = id;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,cAAc;IACjB,GAAG,CAAS;IAEpB;QACE,IAAI,CAAC,GAAG,GAAG,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,EAAE;QACX,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED;;;OAGG;IACI,KAAK;QACV,IAAI,CAAC,GAAG,GAAG,UAAU,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,EAAU;QACnB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|