@alexein/n8n-nodes-alexein 0.0.0-stage → 0.3.1
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/LICENSE +21 -0
- package/README.md +136 -2
- package/dist/credentials/AlexeinApi.credentials.js +47 -0
- package/dist/icons/alexein.dark.svg +1 -0
- package/dist/icons/alexein.svg +1 -0
- package/dist/nodes/Alexein/Alexein.node.js +159 -0
- package/dist/nodes/Alexein/Alexein.node.json +10 -0
- package/dist/nodes/Alexein/fields.js +617 -0
- package/dist/nodes/Alexein/requests.js +209 -0
- package/package.json +61 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexein AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @alexein/n8n-nodes-alexein
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An [n8n](https://n8n.io) community node for [Alexein](https://alexein.ai): long-term memory for your users and
|
|
4
|
+
AI agents. Add what people say; search it later in plain words. Each app user has a memory of their own.
|
|
5
|
+
|
|
6
|
+
Documentation: [docs.alexein.ai/integrations/n8n](https://docs.alexein.ai/integrations/n8n).
|
|
7
|
+
|
|
8
|
+
[Installation](#installation) · [Credential](#credential) · [Operations](#operations) ·
|
|
9
|
+
[As an AI Agent tool](#as-an-ai-agent-tool) · [Template](#template) · [MCP instead](#mcp-instead) ·
|
|
10
|
+
[Compatibility](#compatibility)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
In n8n, open **Settings > Community Nodes > Install**, enter `@alexein/n8n-nodes-alexein`, and install. See n8n's
|
|
15
|
+
[community node installation guide](https://docs.n8n.io/integrations/community-nodes/installation/).
|
|
16
|
+
|
|
17
|
+
On n8n Cloud, the node appears once n8n has verified it.
|
|
18
|
+
|
|
19
|
+
## Credential
|
|
20
|
+
|
|
21
|
+
Create an **Alexein API** credential:
|
|
22
|
+
|
|
23
|
+
| Field | Value |
|
|
24
|
+
| -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| API Key | a key from the Alexein console, under **API keys** (`tm_...`). Use one that writes to add, forget, correct, get versions or delete |
|
|
26
|
+
| Base URL | `https://api.alexein.ai`. The node adds `/v2` itself; a trailing `/` or `/v2` is ignored |
|
|
27
|
+
|
|
28
|
+
**Test** checks the key against `GET /v2/me`.
|
|
29
|
+
|
|
30
|
+
## Operations
|
|
31
|
+
|
|
32
|
+
Every operation but **List App Users** has an **App User** field: your ID for the person whose memory it is,
|
|
33
|
+
usually an expression from the trigger, such as `{{ $json.message.from.id }}`. Each app user's memory is kept
|
|
34
|
+
apart. See [App users](https://docs.alexein.ai/concepts/app-users).
|
|
35
|
+
|
|
36
|
+
| Operation | What it does | Route |
|
|
37
|
+
| ------------------------ | ----------------------------------------------------------------------------- | -------------- |
|
|
38
|
+
| Add | Save a message, note or document | `add` |
|
|
39
|
+
| Search | What memory holds for a question, with a ready-to-paste `context` | `search` |
|
|
40
|
+
| Open | One memory whole, by its ref: an excerpt in full, or a fact with its excerpts | `open` |
|
|
41
|
+
| Find Phrase | Excerpts holding an exact phrase | `grep` |
|
|
42
|
+
| Get Latest | The most recent excerpts, or every excerpt between two dates | `latest` |
|
|
43
|
+
| Get Surrounding Excerpts | The excerpts just before and after one, by its ref | `around` |
|
|
44
|
+
| Get History | Every value a subject was stated to have, and since when | `history` |
|
|
45
|
+
| Get Summary | What this memory holds, in brief | `summary` |
|
|
46
|
+
| List Facts | The facts memory learned, newest first | `facts` |
|
|
47
|
+
| Get Open Items | Issues and pull requests still open, and follow-ups nobody answered | `open_items` |
|
|
48
|
+
| Get Sources | What each connected app delivered | `sources` |
|
|
49
|
+
| List Items | The items added, newest first, as they were given | `items` |
|
|
50
|
+
| Get Item | One added item by its ID | `item` |
|
|
51
|
+
| Get Status | How far each added item has got: queued, stored, processed or unknown | `status` |
|
|
52
|
+
| Get Versions | An added item's versions, and when and why each went | `versions` |
|
|
53
|
+
| Forget | Erase items, sessions, or memories by ref, with a receipt | `forget` |
|
|
54
|
+
| Correct | Retract one fact by its ref, optionally saying what is true instead | `correct` |
|
|
55
|
+
| Export | Everything memory holds for this app user | `export` |
|
|
56
|
+
| List App Users | Every app user of the key's project with memory, and their counts | `users` |
|
|
57
|
+
| Delete App User | Erase this app user's whole memory. Not undone | `users/delete` |
|
|
58
|
+
|
|
59
|
+
Every request is `POST https://api.alexein.ai/v2/memory/<route>`. See the
|
|
60
|
+
[API reference](https://docs.alexein.ai/api) for what each takes and answers.
|
|
61
|
+
|
|
62
|
+
**Add** takes the text, a kind (message, note or document), and optional fields: item ID (the same ID again
|
|
63
|
+
is an edit of that item), session, role, author, title, about, when, expires and metadata. Input items for
|
|
64
|
+
the same app user are sent together, up to 500 per request, each request with an `Idempotency-Key`, and each
|
|
65
|
+
item comes back as its own output item: `{ id, status, waiting }`. Turn on **Wait Until Searchable** to wait,
|
|
66
|
+
briefly, until they can be found; **Redact** replaces phone numbers, card numbers, keys and the like before
|
|
67
|
+
memory keeps any copy.
|
|
68
|
+
|
|
69
|
+
**Search** returns `context`, ready to paste into a prompt (the notes, then the memories in order: known lines,
|
|
70
|
+
facts and excerpts, up to 4,000 characters, which you can change), beside the full answer: `query`,
|
|
71
|
+
`answerable`, `notes` and `memories`. Each fact and excerpt has a `ref` for **Open**, **Get Surrounding
|
|
72
|
+
Excerpts**, **Correct** and **Forget**. **Fast** skips the relevance check: free and quicker, a little less
|
|
73
|
+
precise. **After**, **Before**, **Filters**, **Provider**, **Source** and **Kind** narrow a search; **Get
|
|
74
|
+
Latest** takes the same, and **Find Phrase** takes Provider, Source and Kind.
|
|
75
|
+
|
|
76
|
+
**List Facts**, **List Items**, **Export** and **List App Users** return one page, with `next` for the
|
|
77
|
+
**Cursor** of the page after; turn on **Return All** to get every page as one output item.
|
|
78
|
+
|
|
79
|
+
Every other operation returns the API's answer as one item. Errors carry the API's own message. A `429` means
|
|
80
|
+
too many requests in flight, or reads too fast; a `503`, that the service is busy or briefly unavailable. For
|
|
81
|
+
either, turn on **Retry On Fail** in the node's settings: a retried Add sends the same `Idempotency-Key`, so it
|
|
82
|
+
never saves an item twice.
|
|
83
|
+
|
|
84
|
+
### Example: remember a form submission, then answer from memory
|
|
85
|
+
|
|
86
|
+
1. **Webhook** receives `{ "user": "user_42", "text": "I just moved to Lisbon." }`.
|
|
87
|
+
2. **Alexein: Add** with App User `{{ $json.body.user }}` and Text `{{ $json.body.text }}`.
|
|
88
|
+
3. Later, **Alexein: Search** with the same App User and Query `Where does this person live?`. Its `context`
|
|
89
|
+
goes straight into a prompt.
|
|
90
|
+
|
|
91
|
+
## As an AI Agent tool
|
|
92
|
+
|
|
93
|
+
The node is usable as a tool: in an **AI Agent**, add a tool and choose **Alexein Tool**. Give the agent two:
|
|
94
|
+
one with **Search**, one with **Add**. **Open** is a good third, so the agent can read a memory a search
|
|
95
|
+
pointed to, by its ref.
|
|
96
|
+
|
|
97
|
+
- **App User:** set it from the trigger, such as `{{ $('Telegram Trigger').item.json.message.from.id }}`, and
|
|
98
|
+
never leave it to the model, so a model can't reach another person's memory.
|
|
99
|
+
- **Query and Text:** let the model fill them with `$fromAI()`, for example
|
|
100
|
+
`{{ $fromAI('query', 'A plain-words question about this person', 'string') }}`.
|
|
101
|
+
- **What the model is told:** n8n describes a tool by its operation unless you set **Tool Description** to
|
|
102
|
+
**Set Manually**. For the Add tool, paste this, so the agent saves without being asked:
|
|
103
|
+
|
|
104
|
+
> Save to this person's long-term memory (Alexein), which their other apps read too. Call this on your own,
|
|
105
|
+
> without being asked, on every turn where they say anything new: about themselves, their work, or the
|
|
106
|
+
> people, places, projects and things around them - preferences, facts, opinions, decisions, plans, dates,
|
|
107
|
+
> names and numbers, small details and passing remarks. Also save what was asked, tried, decided or built
|
|
108
|
+
> together, and why. When in doubt, save.
|
|
109
|
+
>
|
|
110
|
+
> One fact per call, as a note, in their words. Never save secrets, passwords, keys or payment details, or
|
|
111
|
+
> your own suggestions as facts about them.
|
|
112
|
+
|
|
113
|
+
## Template
|
|
114
|
+
|
|
115
|
+
[A Telegram assistant with long-term memory](https://docs.alexein.ai/templates/n8n-telegram-assistant-memory.json):
|
|
116
|
+
a Telegram bot that remembers what each person tells it. Simple Memory keeps the last few messages; Alexein keeps
|
|
117
|
+
everything else, per Telegram user. Import it with **Workflows > Import from File**, then add your Telegram,
|
|
118
|
+
OpenAI and Alexein API credentials.
|
|
119
|
+
|
|
120
|
+
## MCP instead
|
|
121
|
+
|
|
122
|
+
n8n's own **MCP Client Tool** can reach Alexein's hosted MCP server, `https://api.alexein.ai/v1/mcp`, with
|
|
123
|
+
**HTTP Streamable** transport. Either:
|
|
124
|
+
|
|
125
|
+
- **Multiple Headers Auth**, with `Authorization: Bearer tm_...` and `X-Alexein-User: <app user>`: one app
|
|
126
|
+
user per credential.
|
|
127
|
+
- **MCP OAuth2**: sign in to Alexein. This reaches your own personal memory, never an app user.
|
|
128
|
+
|
|
129
|
+
Use this node when the app user changes per item, and MCP for one person's agent.
|
|
130
|
+
|
|
131
|
+
## Compatibility
|
|
132
|
+
|
|
133
|
+
Tested with n8n 2.44.6.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AlexeinApi = void 0;
|
|
4
|
+
class AlexeinApi {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'alexeinApi';
|
|
7
|
+
this.displayName = 'Alexein API';
|
|
8
|
+
this.icon = { light: 'file:../icons/alexein.svg', dark: 'file:../icons/alexein.dark.svg' };
|
|
9
|
+
this.documentationUrl = 'https://docs.alexein.ai/integrations/n8n';
|
|
10
|
+
this.properties = [
|
|
11
|
+
{
|
|
12
|
+
displayName: 'API Key',
|
|
13
|
+
name: 'apiKey',
|
|
14
|
+
type: 'string',
|
|
15
|
+
typeOptions: { password: true },
|
|
16
|
+
required: true,
|
|
17
|
+
default: '',
|
|
18
|
+
description: 'A key from the Alexein console, under API keys. A key that writes, to add, forget, correct or delete.',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
displayName: 'Base URL',
|
|
22
|
+
name: 'baseUrl',
|
|
23
|
+
type: 'string',
|
|
24
|
+
required: true,
|
|
25
|
+
default: 'https://api.alexein.ai',
|
|
26
|
+
description: 'The address of the Alexein API. The node adds /v2 itself.',
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
this.authenticate = {
|
|
30
|
+
type: 'generic',
|
|
31
|
+
properties: {
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: '=Bearer {{$credentials.apiKey}}',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
this.test = {
|
|
38
|
+
request: {
|
|
39
|
+
baseURL: '={{$credentials.baseUrl.replace(/(?:\\/v2)?\\/*$/, "")}}',
|
|
40
|
+
url: '/v2/me',
|
|
41
|
+
method: 'GET',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.AlexeinApi = AlexeinApi;
|
|
47
|
+
//# sourceMappingURL=AlexeinApi.credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-200 -200 400 400"><circle r="200" fill="#E4E4E1"/><ellipse cx="-90.71" cy="-64.81" rx="20" ry="37" fill="#17171A"/><ellipse cx="90.71" cy="-64.81" rx="20" ry="37" fill="#17171A"/><path d="M-66.61 10L-58.62 2.97L-50.44 -3.12L-42.14 -8.28L-33.77 -12.49L-25.35 -15.76L-16.91 -18.1L-8.46 -19.5L0 -19.97L0 112L-8.61 103.5L-16.66 95L-24.15 86.5L-31.09 78L-37.48 69.5L-43.31 61L-48.58 52.5L-53.3 44L-57.46 35.5L-61.07 27L-64.12 18.5Z M0 -19.97L8.46 -19.5L16.91 -18.1L25.35 -15.76L33.77 -12.49L42.14 -8.28L50.44 -3.12L58.62 2.97L66.61 10L64.12 18.5L61.07 27L57.46 35.5L53.3 44L48.58 52.5L43.31 61L37.48 69.5L31.09 78L24.15 86.5L16.66 95L8.61 103.5L0 112Z" fill="#141416" stroke="#141416" stroke-width="1.2" stroke-linejoin="round"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-200 -200 400 400"><circle r="200" fill="#232325"/><ellipse cx="-90.71" cy="-64.81" rx="20" ry="37" fill="#FDFDFD"/><ellipse cx="90.71" cy="-64.81" rx="20" ry="37" fill="#FDFDFD"/><path d="M-66.61 10L-58.62 2.97L-50.44 -3.12L-42.14 -8.28L-33.77 -12.49L-25.35 -15.76L-16.91 -18.1L-8.46 -19.5L0 -19.97L0 112L-8.61 103.5L-16.66 95L-24.15 86.5L-31.09 78L-37.48 69.5L-43.31 61L-48.58 52.5L-53.3 44L-57.46 35.5L-61.07 27L-64.12 18.5Z M0 -19.97L8.46 -19.5L16.91 -18.1L25.35 -15.76L33.77 -12.49L42.14 -8.28L50.44 -3.12L58.62 2.97L66.61 10L64.12 18.5L61.07 27L57.46 35.5L53.3 44L48.58 52.5L43.31 61L37.48 69.5L31.09 78L24.15 86.5L16.66 95L8.61 103.5L0 112Z" fill="#FDFDFE" stroke="#FDFDFE" stroke-width="1.2" stroke-linejoin="round"/></svg>
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Alexein = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
6
|
+
const fields_1 = require("./fields");
|
|
7
|
+
const requests_1 = require("./requests");
|
|
8
|
+
class Alexein {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.description = {
|
|
11
|
+
displayName: 'Alexein',
|
|
12
|
+
name: 'alexein',
|
|
13
|
+
icon: {
|
|
14
|
+
light: 'file:../../icons/alexein.svg',
|
|
15
|
+
dark: 'file:../../icons/alexein.dark.svg',
|
|
16
|
+
},
|
|
17
|
+
group: ['transform'],
|
|
18
|
+
version: 1,
|
|
19
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
20
|
+
description: 'Long-term memory for your users and agents: add what they say, search it later',
|
|
21
|
+
defaults: { name: 'Alexein' },
|
|
22
|
+
usableAsTool: true,
|
|
23
|
+
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
24
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
25
|
+
credentials: [{ name: 'alexeinApi', required: true }],
|
|
26
|
+
properties: [...fields_1.operations, ...fields_1.fields],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async execute() {
|
|
30
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
31
|
+
const answers = operation === 'add' ? await added(this) : await answered(this, operation);
|
|
32
|
+
return [answers];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Alexein = Alexein;
|
|
36
|
+
const getter = (context, index) => (name, fallback) => context.getNodeParameter(name, index, fallback);
|
|
37
|
+
async function send(context, sent, index) {
|
|
38
|
+
const credentials = await context.getCredentials('alexeinApi');
|
|
39
|
+
const headers = {};
|
|
40
|
+
if (sent.user !== undefined)
|
|
41
|
+
headers['X-Alexein-User'] = sent.user;
|
|
42
|
+
if (sent.key !== undefined)
|
|
43
|
+
headers['Idempotency-Key'] = sent.key;
|
|
44
|
+
const options = {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
url: `${(0, requests_1.host)(credentials.baseUrl)}/v2/memory/${sent.path}`,
|
|
47
|
+
headers,
|
|
48
|
+
body: sent.body,
|
|
49
|
+
json: true,
|
|
50
|
+
returnFullResponse: true,
|
|
51
|
+
ignoreHttpStatusErrors: true,
|
|
52
|
+
};
|
|
53
|
+
const response = (await context.helpers.httpRequestWithAuthentication.call(context, 'alexeinApi', options));
|
|
54
|
+
const { statusCode: status, body: answer } = response;
|
|
55
|
+
if (status < 400)
|
|
56
|
+
return answer;
|
|
57
|
+
const refused = (answer !== null && answer !== void 0 ? answer : {});
|
|
58
|
+
const errors = Array.isArray(refused.errors) ? refused.errors : [];
|
|
59
|
+
const said = typeof refused.detail === 'string' ? refused.detail : String(answer !== null && answer !== void 0 ? answer : '');
|
|
60
|
+
throw new n8n_workflow_1.NodeApiError(context.getNode(), refused, {
|
|
61
|
+
httpCode: String(status),
|
|
62
|
+
message: said || `The Alexein API answered ${status}`,
|
|
63
|
+
description: status === 429 || status === 503
|
|
64
|
+
? 'Turn on Retry On Fail in the node settings to try again.'
|
|
65
|
+
: errors.map((e) => `${e.field}: ${e.message}`).join('; ') || undefined,
|
|
66
|
+
itemIndex: index,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function failed(context, error, index) {
|
|
70
|
+
if (error instanceof n8n_workflow_1.NodeApiError || error instanceof n8n_workflow_1.NodeOperationError)
|
|
71
|
+
return error;
|
|
72
|
+
return new n8n_workflow_1.NodeOperationError(context.getNode(), error, { itemIndex: index });
|
|
73
|
+
}
|
|
74
|
+
async function answer(context, operation, get, index) {
|
|
75
|
+
const user = requests_1.UNNAMED.has(operation) ? undefined : (0, requests_1.checkedUser)(get('user'));
|
|
76
|
+
if (!(operation in requests_1.PAGED && get('returnAll', false))) {
|
|
77
|
+
return await send(context, { ...(0, requests_1.request)(operation, get), user }, index);
|
|
78
|
+
}
|
|
79
|
+
const pages = [];
|
|
80
|
+
let cursor = null;
|
|
81
|
+
do {
|
|
82
|
+
const got = await send(context, { ...(0, requests_1.page)(operation, get, cursor), user }, index);
|
|
83
|
+
pages.push(got);
|
|
84
|
+
cursor = typeof got.next === 'string' && got.next ? got.next : null;
|
|
85
|
+
} while (cursor);
|
|
86
|
+
return (0, requests_1.merged)(operation, pages);
|
|
87
|
+
}
|
|
88
|
+
async function answered(context, operation) {
|
|
89
|
+
const out = [];
|
|
90
|
+
const items = context.getInputData();
|
|
91
|
+
for (let index = 0; index < items.length; index++) {
|
|
92
|
+
try {
|
|
93
|
+
const get = getter(context, index);
|
|
94
|
+
const json = (0, requests_1.shaped)(operation, await answer(context, operation, get, index), get);
|
|
95
|
+
out.push({ json, pairedItem: { item: index } });
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (!context.continueOnFail())
|
|
99
|
+
throw failed(context, error, index);
|
|
100
|
+
out.push({ json: { error: error.message }, pairedItem: { item: index } });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function idempotencyKey(context, sent, batch) {
|
|
106
|
+
const node = context.getNode();
|
|
107
|
+
const named = JSON.stringify([context.getExecutionId(), node.id, node.name, sent]);
|
|
108
|
+
return `${(0, crypto_1.createHash)('sha256').update(named).digest('hex')}-${batch}`;
|
|
109
|
+
}
|
|
110
|
+
async function added(context) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
const items = context.getInputData();
|
|
113
|
+
const out = new Array(items.length);
|
|
114
|
+
const failure = (index, error) => {
|
|
115
|
+
if (!context.continueOnFail())
|
|
116
|
+
throw failed(context, error, index);
|
|
117
|
+
out[index] = { json: { error: error.message }, pairedItem: { item: index } };
|
|
118
|
+
};
|
|
119
|
+
const groups = new Map();
|
|
120
|
+
for (let index = 0; index < items.length; index++) {
|
|
121
|
+
try {
|
|
122
|
+
const get = getter(context, index);
|
|
123
|
+
const key = JSON.stringify([
|
|
124
|
+
(0, requests_1.checkedUser)(get('user')),
|
|
125
|
+
Boolean(get('wait', false)),
|
|
126
|
+
Boolean(get('redact', false)),
|
|
127
|
+
]);
|
|
128
|
+
groups.set(key, [...((_a = groups.get(key)) !== null && _a !== void 0 ? _a : []), { index, item: (0, requests_1.item)(get) }]);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
failure(index, error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const [group, members] of groups) {
|
|
135
|
+
const [user, wait, redact] = JSON.parse(group);
|
|
136
|
+
for (let at = 0; at < members.length; at += requests_1.BATCH) {
|
|
137
|
+
const batch = members.slice(at, at + requests_1.BATCH);
|
|
138
|
+
try {
|
|
139
|
+
const body = { items: batch.map((m) => m.item), wait };
|
|
140
|
+
if (redact)
|
|
141
|
+
body.redact = true;
|
|
142
|
+
const key = idempotencyKey(context, [user, body], at / requests_1.BATCH);
|
|
143
|
+
const answer = await send(context, { path: 'add', body, user, key }, batch[0].index);
|
|
144
|
+
const each = (_b = answer.items) !== null && _b !== void 0 ? _b : [];
|
|
145
|
+
batch.forEach((member, k) => {
|
|
146
|
+
var _a;
|
|
147
|
+
const json = { ...((_a = each[k]) !== null && _a !== void 0 ? _a : {}), waiting: answer.waiting };
|
|
148
|
+
out[member.index] = { json, pairedItem: { item: member.index } };
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
for (const member of batch)
|
|
153
|
+
failure(member.index, error);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return out.filter((entry) => entry !== undefined);
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=Alexein.node.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"node": "@alexein/n8n-nodes-alexein.alexein",
|
|
3
|
+
"nodeVersion": "1.0",
|
|
4
|
+
"codexVersion": "1.0",
|
|
5
|
+
"categories": ["Data & Storage", "Development"],
|
|
6
|
+
"resources": {
|
|
7
|
+
"credentialDocumentation": [{ "url": "https://docs.alexein.ai/integrations/n8n#credential" }],
|
|
8
|
+
"primaryDocumentation": [{ "url": "https://docs.alexein.ai/integrations/n8n" }]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fields = exports.operations = void 0;
|
|
4
|
+
const show = (...operation) => ({
|
|
5
|
+
displayOptions: { show: { resource: ['memory'], operation } },
|
|
6
|
+
});
|
|
7
|
+
const onePage = (operation) => ({
|
|
8
|
+
displayOptions: { show: { resource: ['memory'], operation: [operation], returnAll: [false] } },
|
|
9
|
+
});
|
|
10
|
+
exports.operations = [
|
|
11
|
+
{
|
|
12
|
+
displayName: 'Resource',
|
|
13
|
+
name: 'resource',
|
|
14
|
+
type: 'options',
|
|
15
|
+
noDataExpression: true,
|
|
16
|
+
options: [{ name: 'Memory', value: 'memory' }],
|
|
17
|
+
default: 'memory',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
displayName: 'Operation',
|
|
21
|
+
name: 'operation',
|
|
22
|
+
type: 'options',
|
|
23
|
+
noDataExpression: true,
|
|
24
|
+
displayOptions: { show: { resource: ['memory'] } },
|
|
25
|
+
options: [
|
|
26
|
+
{
|
|
27
|
+
name: 'Add',
|
|
28
|
+
value: 'add',
|
|
29
|
+
description: "Save a message, note or document to this app user's memory",
|
|
30
|
+
action: 'Add to memory',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'Correct',
|
|
34
|
+
value: 'correct',
|
|
35
|
+
description: 'Retract one fact for good, by its ref, optionally saying what is true instead',
|
|
36
|
+
action: 'Correct a fact',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'Delete App User',
|
|
40
|
+
value: 'deleteUser',
|
|
41
|
+
description: "Erase this app user's whole memory: every item, fact and version. Not undone.",
|
|
42
|
+
action: 'Delete an app user',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'Export',
|
|
46
|
+
value: 'export',
|
|
47
|
+
description: 'Everything memory holds for this app user: items as added, what connected apps delivered, and the facts learned',
|
|
48
|
+
action: 'Export memory',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'Find Phrase',
|
|
52
|
+
value: 'grep',
|
|
53
|
+
description: 'Excerpts holding an exact phrase, ignoring case: for a name, an ID or an error code a search would blur',
|
|
54
|
+
action: 'Find an exact phrase in memory',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'Forget',
|
|
58
|
+
value: 'forget',
|
|
59
|
+
description: 'Erase items, sessions, or memories by ref, with every copy and everything learned from them',
|
|
60
|
+
action: 'Forget from memory',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'Get History',
|
|
64
|
+
value: 'history',
|
|
65
|
+
description: 'Every value a subject was stated to have, oldest first, with when each was said: what was true, and what changed',
|
|
66
|
+
action: 'Get the history of a subject',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'Get Item',
|
|
70
|
+
value: 'item',
|
|
71
|
+
description: 'One added item by its ID, as it was given, and whether it is searchable yet',
|
|
72
|
+
action: 'Get an added item',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'Get Latest',
|
|
76
|
+
value: 'latest',
|
|
77
|
+
description: 'The most recent excerpts, newest first: what just happened, everywhere or in one place, or between two dates',
|
|
78
|
+
action: 'Get the latest excerpts',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'Get Open Items',
|
|
82
|
+
value: 'openItems',
|
|
83
|
+
description: 'Issues and pull requests still open, newest first, and follow-ups: open asks nobody answered',
|
|
84
|
+
action: 'Get open items',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'Get Sources',
|
|
88
|
+
value: 'sources',
|
|
89
|
+
description: 'What each connected app delivered to this memory, and the newest',
|
|
90
|
+
action: 'Get connected sources',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'Get Status',
|
|
94
|
+
value: 'status',
|
|
95
|
+
description: 'How far each added item has got: queued, stored (searchable), processed or unknown',
|
|
96
|
+
action: 'Get the status of added items',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'Get Summary',
|
|
100
|
+
value: 'summary',
|
|
101
|
+
description: 'What this memory holds, in brief: how many items, the span they cover, connected sources and the known lines',
|
|
102
|
+
action: 'Get a summary of memory',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'Get Surrounding Excerpts',
|
|
106
|
+
value: 'around',
|
|
107
|
+
description: 'The excerpts just before and after one, from the same conversation, in order',
|
|
108
|
+
action: 'Get excerpts around an excerpt',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'Get Versions',
|
|
112
|
+
value: 'versions',
|
|
113
|
+
description: 'Every version of one added item, oldest first, and when and why it went',
|
|
114
|
+
action: 'Get the versions of an item',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'List App Users',
|
|
118
|
+
value: 'users',
|
|
119
|
+
description: "Every app user of this key's project with memory, with how many items and facts each holds",
|
|
120
|
+
action: 'List app users',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'List Facts',
|
|
124
|
+
value: 'facts',
|
|
125
|
+
description: 'The facts memory learned, newest first: each in words, dated, with its ref',
|
|
126
|
+
action: 'List facts',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'List Items',
|
|
130
|
+
value: 'items',
|
|
131
|
+
description: 'The items added to this memory, newest first, as they were given',
|
|
132
|
+
action: 'List added items',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'Open',
|
|
136
|
+
value: 'open',
|
|
137
|
+
description: 'One memory whole, by the ref a result gave: an excerpt in full, or a fact with the excerpts it was learned from',
|
|
138
|
+
action: 'Open a memory by its ref',
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'Search',
|
|
142
|
+
value: 'search',
|
|
143
|
+
description: 'What memory holds for a plain-words question: known lines, facts and excerpts, each with a ref',
|
|
144
|
+
action: 'Search memory',
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
default: 'search',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
displayName: 'App User',
|
|
151
|
+
name: 'user',
|
|
152
|
+
type: 'string',
|
|
153
|
+
required: true,
|
|
154
|
+
default: '',
|
|
155
|
+
placeholder: 'e.g. user_42',
|
|
156
|
+
displayOptions: { hide: { operation: ['users'] } },
|
|
157
|
+
description: "Your ID for the person whose memory this is, usually an expression from the trigger, such as the Telegram user. Each app user has a memory of their own. 1 to 35 letters, digits, '.', '_' and '-', beginning with a letter or digit.",
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
const origin = [
|
|
161
|
+
{
|
|
162
|
+
displayName: 'Kind',
|
|
163
|
+
name: 'kind',
|
|
164
|
+
type: 'string',
|
|
165
|
+
default: '',
|
|
166
|
+
placeholder: 'note, pull_request',
|
|
167
|
+
description: "Only these kinds, separated by commas: message, document or note for items you added, or a connected app's own, such as pull_request. Up to 8.",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
displayName: 'Provider',
|
|
171
|
+
name: 'provider',
|
|
172
|
+
type: 'string',
|
|
173
|
+
default: '',
|
|
174
|
+
placeholder: 'github',
|
|
175
|
+
description: 'Only what came from this connected app, such as github or slack',
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
displayName: 'Source',
|
|
179
|
+
name: 'source',
|
|
180
|
+
type: 'string',
|
|
181
|
+
default: '',
|
|
182
|
+
description: "Only this source within a connected app, as the excerpt's first line names it. With Provider.",
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
const filters = {
|
|
186
|
+
displayName: 'Filters',
|
|
187
|
+
name: 'filters',
|
|
188
|
+
type: 'json',
|
|
189
|
+
default: '{}',
|
|
190
|
+
description: 'Only items that match, by author, mentions or metadata keys, combined with AND, OR and NOT, such as {"metadata": {"priority": {"gte": 3}}}. See docs.alexein.ai/concepts/filters.',
|
|
191
|
+
};
|
|
192
|
+
const after = (description) => ({
|
|
193
|
+
displayName: 'After',
|
|
194
|
+
name: 'after',
|
|
195
|
+
type: 'dateTime',
|
|
196
|
+
default: '',
|
|
197
|
+
description,
|
|
198
|
+
});
|
|
199
|
+
const before = (description) => ({
|
|
200
|
+
displayName: 'Before',
|
|
201
|
+
name: 'before',
|
|
202
|
+
type: 'dateTime',
|
|
203
|
+
default: '',
|
|
204
|
+
description,
|
|
205
|
+
});
|
|
206
|
+
function paged(operation, max) {
|
|
207
|
+
return [
|
|
208
|
+
{
|
|
209
|
+
displayName: 'Return All',
|
|
210
|
+
name: 'returnAll',
|
|
211
|
+
type: 'boolean',
|
|
212
|
+
default: false,
|
|
213
|
+
...show(operation),
|
|
214
|
+
description: 'Whether to return all results or only up to a given limit',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
displayName: 'Limit',
|
|
218
|
+
name: 'limit',
|
|
219
|
+
type: 'number',
|
|
220
|
+
typeOptions: { minValue: 1, maxValue: max },
|
|
221
|
+
default: 50,
|
|
222
|
+
...onePage(operation),
|
|
223
|
+
description: 'Max number of results to return',
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
displayName: 'Cursor',
|
|
227
|
+
name: 'cursor',
|
|
228
|
+
type: 'string',
|
|
229
|
+
default: '',
|
|
230
|
+
...onePage(operation),
|
|
231
|
+
description: 'The next of the page before, for the page after it. The first page when empty.',
|
|
232
|
+
},
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
exports.fields = [
|
|
236
|
+
{
|
|
237
|
+
displayName: 'Text',
|
|
238
|
+
name: 'text',
|
|
239
|
+
type: 'string',
|
|
240
|
+
typeOptions: { rows: 4 },
|
|
241
|
+
required: true,
|
|
242
|
+
default: '',
|
|
243
|
+
...show('add'),
|
|
244
|
+
description: 'What to remember: a message, a note, or a whole document',
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
displayName: 'Kind',
|
|
248
|
+
name: 'kind',
|
|
249
|
+
type: 'options',
|
|
250
|
+
options: [
|
|
251
|
+
{
|
|
252
|
+
name: 'Document',
|
|
253
|
+
value: 'document',
|
|
254
|
+
description: 'A whole text, such as a file or a page',
|
|
255
|
+
},
|
|
256
|
+
{ name: 'Message', value: 'message', description: 'One turn of a conversation' },
|
|
257
|
+
{ name: 'Note', value: 'note', description: 'A fact on its own' },
|
|
258
|
+
],
|
|
259
|
+
default: 'message',
|
|
260
|
+
...show('add'),
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
displayName: 'Wait Until Searchable',
|
|
264
|
+
name: 'wait',
|
|
265
|
+
type: 'boolean',
|
|
266
|
+
default: false,
|
|
267
|
+
...show('add'),
|
|
268
|
+
description: "Whether to wait, briefly, until the items can be found; the output's waiting counts any not yet searchable. Off, an add is accepted at once and searchable a moment later.",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
displayName: 'Redact',
|
|
272
|
+
name: 'redact',
|
|
273
|
+
type: 'boolean',
|
|
274
|
+
default: false,
|
|
275
|
+
...show('add'),
|
|
276
|
+
description: 'Whether to replace phone numbers, payment cards, IBANs, API keys, passwords and the like in the text, title and metadata with their kind, such as [PHONE], before memory keeps any copy',
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
displayName: 'Additional Fields',
|
|
280
|
+
name: 'additionalFields',
|
|
281
|
+
type: 'collection',
|
|
282
|
+
placeholder: 'Add Field',
|
|
283
|
+
default: {},
|
|
284
|
+
...show('add'),
|
|
285
|
+
options: [
|
|
286
|
+
{
|
|
287
|
+
displayName: 'About',
|
|
288
|
+
name: 'about',
|
|
289
|
+
type: 'string',
|
|
290
|
+
default: '',
|
|
291
|
+
placeholder: 'project:atlas, customer:acme',
|
|
292
|
+
description: 'What this item is about, as kind:name, separated by commas',
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
displayName: 'Author',
|
|
296
|
+
name: 'author',
|
|
297
|
+
type: 'string',
|
|
298
|
+
default: '',
|
|
299
|
+
description: 'Who said or wrote it: your ID for them, a name, an email or a handle',
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
displayName: 'Expires',
|
|
303
|
+
name: 'expires',
|
|
304
|
+
type: 'dateTime',
|
|
305
|
+
default: '',
|
|
306
|
+
description: 'When it stops being true. It is forgotten then.',
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
displayName: 'Item ID',
|
|
310
|
+
name: 'id',
|
|
311
|
+
type: 'string',
|
|
312
|
+
default: '',
|
|
313
|
+
description: 'Your ID for this item. The same ID again is an edit of it: use it to fix the same statement, and a new ID when something changes.',
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
displayName: 'Metadata',
|
|
317
|
+
name: 'metadata',
|
|
318
|
+
type: 'json',
|
|
319
|
+
default: '{}',
|
|
320
|
+
description: 'Your own JSON, kept with the item, and what Filters can match',
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
displayName: 'Role',
|
|
324
|
+
name: 'role',
|
|
325
|
+
type: 'string',
|
|
326
|
+
default: '',
|
|
327
|
+
placeholder: 'user',
|
|
328
|
+
description: "The speaker's role in a conversation, such as user or assistant",
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
displayName: 'Session',
|
|
332
|
+
name: 'session',
|
|
333
|
+
type: 'string',
|
|
334
|
+
default: '',
|
|
335
|
+
description: 'Groups messages into one conversation',
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
displayName: 'Title',
|
|
339
|
+
name: 'title',
|
|
340
|
+
type: 'string',
|
|
341
|
+
default: '',
|
|
342
|
+
description: "A document's title",
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
displayName: 'When',
|
|
346
|
+
name: 'at',
|
|
347
|
+
type: 'dateTime',
|
|
348
|
+
default: '',
|
|
349
|
+
description: 'When it was said or written. Now when empty.',
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
displayName: 'Query',
|
|
355
|
+
name: 'query',
|
|
356
|
+
type: 'string',
|
|
357
|
+
required: true,
|
|
358
|
+
default: '',
|
|
359
|
+
...show('search'),
|
|
360
|
+
description: 'The question, in plain words',
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
displayName: 'Fast',
|
|
364
|
+
name: 'fast',
|
|
365
|
+
type: 'boolean',
|
|
366
|
+
default: false,
|
|
367
|
+
...show('search'),
|
|
368
|
+
description: 'Whether to skip the relevance check: free and quicker, a little less precise. For replies that cannot wait.',
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
displayName: 'Options',
|
|
372
|
+
name: 'searchOptions',
|
|
373
|
+
type: 'collection',
|
|
374
|
+
placeholder: 'Add Option',
|
|
375
|
+
default: {},
|
|
376
|
+
...show('search'),
|
|
377
|
+
options: [
|
|
378
|
+
after('Only memories from this day on'),
|
|
379
|
+
before('Only memories from before this day'),
|
|
380
|
+
{
|
|
381
|
+
displayName: 'Context Length',
|
|
382
|
+
name: 'contextLength',
|
|
383
|
+
type: 'number',
|
|
384
|
+
typeOptions: { minValue: 200 },
|
|
385
|
+
default: 4000,
|
|
386
|
+
description: 'The longest the context output may be, in characters',
|
|
387
|
+
},
|
|
388
|
+
filters,
|
|
389
|
+
...origin,
|
|
390
|
+
],
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
displayName: 'Subject',
|
|
394
|
+
name: 'subject',
|
|
395
|
+
type: 'string',
|
|
396
|
+
required: true,
|
|
397
|
+
default: '',
|
|
398
|
+
...show('history'),
|
|
399
|
+
description: 'Who or what to get the history of, such as a person or a project',
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
displayName: 'Attribute',
|
|
403
|
+
name: 'attribute',
|
|
404
|
+
type: 'string',
|
|
405
|
+
default: '',
|
|
406
|
+
...show('history'),
|
|
407
|
+
placeholder: 'home city',
|
|
408
|
+
description: 'Only this attribute of the subject. Every attribute when empty.',
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
displayName: 'Limit',
|
|
412
|
+
name: 'k',
|
|
413
|
+
type: 'number',
|
|
414
|
+
typeOptions: { minValue: 1, maxValue: 50 },
|
|
415
|
+
default: 10,
|
|
416
|
+
...show('latest'),
|
|
417
|
+
description: 'Max number of results to return',
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
displayName: 'Options',
|
|
421
|
+
name: 'latestOptions',
|
|
422
|
+
type: 'collection',
|
|
423
|
+
placeholder: 'Add Option',
|
|
424
|
+
default: {},
|
|
425
|
+
...show('latest'),
|
|
426
|
+
options: [
|
|
427
|
+
after('Every excerpt from this day on, rather than the newest few'),
|
|
428
|
+
before('Every excerpt from before this day'),
|
|
429
|
+
filters,
|
|
430
|
+
...origin,
|
|
431
|
+
{
|
|
432
|
+
displayName: 'Place',
|
|
433
|
+
name: 'place',
|
|
434
|
+
type: 'string',
|
|
435
|
+
default: '',
|
|
436
|
+
description: 'Where to look, such as messages, documents, notes, or a connected app such as slack. Everywhere when empty.',
|
|
437
|
+
},
|
|
438
|
+
],
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
displayName: 'Phrase',
|
|
442
|
+
name: 'pattern',
|
|
443
|
+
type: 'string',
|
|
444
|
+
required: true,
|
|
445
|
+
default: '',
|
|
446
|
+
...show('grep'),
|
|
447
|
+
description: 'The exact phrase to find, ignoring case',
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
displayName: 'Limit',
|
|
451
|
+
name: 'limit',
|
|
452
|
+
type: 'number',
|
|
453
|
+
typeOptions: { minValue: 1, maxValue: 50 },
|
|
454
|
+
default: 50,
|
|
455
|
+
...show('grep'),
|
|
456
|
+
description: 'Max number of results to return',
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
displayName: 'Options',
|
|
460
|
+
name: 'grepOptions',
|
|
461
|
+
type: 'collection',
|
|
462
|
+
placeholder: 'Add Option',
|
|
463
|
+
default: {},
|
|
464
|
+
...show('grep'),
|
|
465
|
+
options: origin,
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
displayName: 'Ref',
|
|
469
|
+
name: 'ref',
|
|
470
|
+
type: 'string',
|
|
471
|
+
required: true,
|
|
472
|
+
default: '',
|
|
473
|
+
...show('open', 'around'),
|
|
474
|
+
placeholder: 'mem_…',
|
|
475
|
+
description: "A fact's or an excerpt's ref, from another result",
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
displayName: 'Width',
|
|
479
|
+
name: 'width',
|
|
480
|
+
type: 'number',
|
|
481
|
+
typeOptions: { minValue: 1, maxValue: 5 },
|
|
482
|
+
default: 2,
|
|
483
|
+
...show('around'),
|
|
484
|
+
description: 'How many excerpts to get on each side',
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
displayName: 'Limit',
|
|
488
|
+
name: 'limit',
|
|
489
|
+
type: 'number',
|
|
490
|
+
typeOptions: { minValue: 1, maxValue: 50 },
|
|
491
|
+
default: 50,
|
|
492
|
+
...show('openItems'),
|
|
493
|
+
description: 'Max number of results to return',
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
displayName: 'Options',
|
|
497
|
+
name: 'openItemsOptions',
|
|
498
|
+
type: 'collection',
|
|
499
|
+
placeholder: 'Add Option',
|
|
500
|
+
default: {},
|
|
501
|
+
...show('openItems'),
|
|
502
|
+
options: [
|
|
503
|
+
{
|
|
504
|
+
displayName: 'Kind',
|
|
505
|
+
name: 'kind',
|
|
506
|
+
type: 'string',
|
|
507
|
+
default: '',
|
|
508
|
+
placeholder: 'issue, pull_request',
|
|
509
|
+
description: 'Only these kinds, separated by commas, such as issue or pull_request',
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
displayName: 'Mine Only',
|
|
513
|
+
name: 'mine',
|
|
514
|
+
type: 'boolean',
|
|
515
|
+
default: true,
|
|
516
|
+
description: "Whether to return only the app user's own: what they wrote, are assigned or review",
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
displayName: 'Place',
|
|
520
|
+
name: 'place',
|
|
521
|
+
type: 'string',
|
|
522
|
+
default: '',
|
|
523
|
+
description: 'Only this place, such as one repository',
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
displayName: 'Provider',
|
|
527
|
+
name: 'provider',
|
|
528
|
+
type: 'string',
|
|
529
|
+
default: '',
|
|
530
|
+
placeholder: 'github',
|
|
531
|
+
description: 'Only what came from this connected app, such as github',
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
displayName: 'Within Days',
|
|
535
|
+
name: 'withinDays',
|
|
536
|
+
type: 'number',
|
|
537
|
+
typeOptions: { minValue: 0, maxValue: 3650 },
|
|
538
|
+
default: 0,
|
|
539
|
+
description: 'Only what changed in this many days. Any time when 0.',
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
},
|
|
543
|
+
...paged('facts', 100),
|
|
544
|
+
...paged('items', 200),
|
|
545
|
+
{
|
|
546
|
+
displayName: 'Options',
|
|
547
|
+
name: 'itemsOptions',
|
|
548
|
+
type: 'collection',
|
|
549
|
+
placeholder: 'Add Option',
|
|
550
|
+
default: {},
|
|
551
|
+
...show('items'),
|
|
552
|
+
options: [filters],
|
|
553
|
+
},
|
|
554
|
+
...paged('export', 500),
|
|
555
|
+
...paged('users', 500),
|
|
556
|
+
{
|
|
557
|
+
displayName: 'Item ID',
|
|
558
|
+
name: 'itemId',
|
|
559
|
+
type: 'string',
|
|
560
|
+
required: true,
|
|
561
|
+
default: '',
|
|
562
|
+
...show('item', 'versions'),
|
|
563
|
+
description: 'The ID the item was added with',
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
displayName: 'Item IDs',
|
|
567
|
+
name: 'ids',
|
|
568
|
+
type: 'string',
|
|
569
|
+
required: true,
|
|
570
|
+
default: '',
|
|
571
|
+
...show('status'),
|
|
572
|
+
description: 'The IDs items were added with, or that Add answered, separated by commas. Up to 500.',
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
displayName: 'Item IDs',
|
|
576
|
+
name: 'items',
|
|
577
|
+
type: 'string',
|
|
578
|
+
default: '',
|
|
579
|
+
...show('forget'),
|
|
580
|
+
description: 'Items to forget, by the IDs they were added with, separated by commas',
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
displayName: 'Sessions',
|
|
584
|
+
name: 'sessions',
|
|
585
|
+
type: 'string',
|
|
586
|
+
default: '',
|
|
587
|
+
...show('forget'),
|
|
588
|
+
description: 'Whole sessions to forget, as items named them, separated by commas',
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
displayName: 'Refs',
|
|
592
|
+
name: 'refs',
|
|
593
|
+
type: 'string',
|
|
594
|
+
default: '',
|
|
595
|
+
...show('forget'),
|
|
596
|
+
description: "Refs to forget, separated by commas: a fact's forgets the messages it came from and all learned from them; an excerpt's, its whole conversation",
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
displayName: 'Ref',
|
|
600
|
+
name: 'ref',
|
|
601
|
+
type: 'string',
|
|
602
|
+
required: true,
|
|
603
|
+
default: '',
|
|
604
|
+
...show('correct'),
|
|
605
|
+
placeholder: 'mem_…',
|
|
606
|
+
description: "The fact's ref, from a search or List Facts",
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
displayName: 'Replacement',
|
|
610
|
+
name: 'replacement',
|
|
611
|
+
type: 'string',
|
|
612
|
+
default: '',
|
|
613
|
+
...show('correct'),
|
|
614
|
+
description: 'What is true instead, kept as a note. Nothing when empty.',
|
|
615
|
+
},
|
|
616
|
+
];
|
|
617
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.host = exports.PAGED = exports.UNNAMED = exports.route = exports.BATCH = void 0;
|
|
4
|
+
exports.checkedUser = checkedUser;
|
|
5
|
+
exports.item = item;
|
|
6
|
+
exports.page = page;
|
|
7
|
+
exports.request = request;
|
|
8
|
+
exports.merged = merged;
|
|
9
|
+
exports.context = context;
|
|
10
|
+
exports.shaped = shaped;
|
|
11
|
+
exports.BATCH = 500;
|
|
12
|
+
const ROUTES = { openItems: 'open_items', deleteUser: 'users/delete' };
|
|
13
|
+
const route = (operation) => { var _a; return (_a = ROUTES[operation]) !== null && _a !== void 0 ? _a : operation; };
|
|
14
|
+
exports.route = route;
|
|
15
|
+
exports.UNNAMED = new Set(['users']);
|
|
16
|
+
exports.PAGED = {
|
|
17
|
+
facts: { key: 'facts', max: 100 },
|
|
18
|
+
items: { key: 'items', max: 200 },
|
|
19
|
+
export: { key: 'records', max: 500 },
|
|
20
|
+
users: { key: 'users', max: 500 },
|
|
21
|
+
};
|
|
22
|
+
const host = (baseUrl) => String(baseUrl !== null && baseUrl !== void 0 ? baseUrl : '').replace(/(?:\/v2)?\/*$/, '');
|
|
23
|
+
exports.host = host;
|
|
24
|
+
const USER_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,34}$/;
|
|
25
|
+
function checkedUser(value) {
|
|
26
|
+
const user = String(value !== null && value !== void 0 ? value : '').trim();
|
|
27
|
+
if (!USER_ID.test(user)) {
|
|
28
|
+
throw new Error(`App User "${user}" is not a usable ID: 1 to 35 letters, digits, '.', '_' and '-', beginning with a letter or digit`);
|
|
29
|
+
}
|
|
30
|
+
return user;
|
|
31
|
+
}
|
|
32
|
+
const text = (value) => String(value !== null && value !== void 0 ? value : '').trim();
|
|
33
|
+
const list = (value) => (Array.isArray(value) ? value.map(String) : text(value).split(','))
|
|
34
|
+
.map((part) => part.trim())
|
|
35
|
+
.filter(Boolean);
|
|
36
|
+
function present(body) {
|
|
37
|
+
return Object.fromEntries(Object.entries(body).filter(([, v]) => v !== undefined && v !== '' && !(Array.isArray(v) && v.length === 0)));
|
|
38
|
+
}
|
|
39
|
+
function parsedJson(value) {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(value);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function object(value, field) {
|
|
48
|
+
if (value === undefined || value === null || value === '')
|
|
49
|
+
return undefined;
|
|
50
|
+
const parsed = typeof value === 'string' ? parsedJson(value) : value;
|
|
51
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
52
|
+
throw new Error(`${field} must be a JSON object`);
|
|
53
|
+
}
|
|
54
|
+
return Object.keys(parsed).length ? parsed : undefined;
|
|
55
|
+
}
|
|
56
|
+
function item(get) {
|
|
57
|
+
var _a;
|
|
58
|
+
const extra = ((_a = get('additionalFields', {})) !== null && _a !== void 0 ? _a : {});
|
|
59
|
+
const said = text(get('text'));
|
|
60
|
+
if (!said)
|
|
61
|
+
throw new Error('Text is empty: there is nothing to remember');
|
|
62
|
+
return present({
|
|
63
|
+
text: said,
|
|
64
|
+
kind: get('kind', 'message'),
|
|
65
|
+
id: text(extra.id),
|
|
66
|
+
session: text(extra.session),
|
|
67
|
+
role: text(extra.role),
|
|
68
|
+
author: text(extra.author),
|
|
69
|
+
title: text(extra.title),
|
|
70
|
+
about: list(extra.about),
|
|
71
|
+
at: text(extra.at),
|
|
72
|
+
expires: text(extra.expires),
|
|
73
|
+
metadata: object(extra.metadata, 'Metadata'),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function narrowed(options) {
|
|
77
|
+
return {
|
|
78
|
+
provider: text(options.provider),
|
|
79
|
+
source: text(options.source),
|
|
80
|
+
kind: list(options.kind),
|
|
81
|
+
filters: object(options.filters, 'Filters'),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function page(operation, get, cursor) {
|
|
85
|
+
var _a;
|
|
86
|
+
const returnAll = Boolean(get('returnAll', false));
|
|
87
|
+
const options = ((_a = get('itemsOptions', {})) !== null && _a !== void 0 ? _a : {});
|
|
88
|
+
return {
|
|
89
|
+
path: (0, exports.route)(operation),
|
|
90
|
+
body: present({
|
|
91
|
+
limit: returnAll ? exports.PAGED[operation].max : get('limit', 50),
|
|
92
|
+
cursor: returnAll ? (cursor !== null && cursor !== void 0 ? cursor : '') : text(get('cursor', '')),
|
|
93
|
+
filters: operation === 'items' ? object(options.filters, 'Filters') : undefined,
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function request(operation, get) {
|
|
98
|
+
var _a, _b, _c, _d;
|
|
99
|
+
if (operation in exports.PAGED)
|
|
100
|
+
return page(operation, get);
|
|
101
|
+
const post = (body) => ({ path: (0, exports.route)(operation), body: present(body) });
|
|
102
|
+
switch (operation) {
|
|
103
|
+
case 'search': {
|
|
104
|
+
const options = ((_a = get('searchOptions', {})) !== null && _a !== void 0 ? _a : {});
|
|
105
|
+
return post({
|
|
106
|
+
query: text(get('query')),
|
|
107
|
+
fast: Boolean(get('fast', false)),
|
|
108
|
+
before: text(options.before),
|
|
109
|
+
after: text(options.after),
|
|
110
|
+
...narrowed(options),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
case 'latest': {
|
|
114
|
+
const options = ((_b = get('latestOptions', {})) !== null && _b !== void 0 ? _b : {});
|
|
115
|
+
return post({
|
|
116
|
+
k: get('k', 10),
|
|
117
|
+
place: text(options.place),
|
|
118
|
+
after: text(options.after),
|
|
119
|
+
before: text(options.before),
|
|
120
|
+
...narrowed(options),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
case 'grep': {
|
|
124
|
+
const { provider, source, kind } = narrowed(((_c = get('grepOptions', {})) !== null && _c !== void 0 ? _c : {}));
|
|
125
|
+
return post({
|
|
126
|
+
pattern: text(get('pattern')),
|
|
127
|
+
limit: get('limit', 50),
|
|
128
|
+
provider,
|
|
129
|
+
source,
|
|
130
|
+
kind,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
case 'open':
|
|
134
|
+
return post({ ref: text(get('ref')) });
|
|
135
|
+
case 'around':
|
|
136
|
+
return post({ ref: text(get('ref')), width: get('width', 2) });
|
|
137
|
+
case 'history':
|
|
138
|
+
return post({ subject: text(get('subject')), attribute: text(get('attribute')) });
|
|
139
|
+
case 'openItems': {
|
|
140
|
+
const options = ((_d = get('openItemsOptions', {})) !== null && _d !== void 0 ? _d : {});
|
|
141
|
+
return post({
|
|
142
|
+
limit: get('limit', 50),
|
|
143
|
+
mine: options.mine,
|
|
144
|
+
within_days: options.withinDays,
|
|
145
|
+
place: text(options.place),
|
|
146
|
+
provider: text(options.provider),
|
|
147
|
+
kind: list(options.kind),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
case 'item':
|
|
151
|
+
case 'versions':
|
|
152
|
+
return post({ id: text(get('itemId')) });
|
|
153
|
+
case 'status': {
|
|
154
|
+
const items = list(get('ids'));
|
|
155
|
+
if (!items.length)
|
|
156
|
+
throw new Error('Item IDs is empty: name at least one item');
|
|
157
|
+
return post({ items });
|
|
158
|
+
}
|
|
159
|
+
case 'forget': {
|
|
160
|
+
const named = present({
|
|
161
|
+
items: list(get('items', '')),
|
|
162
|
+
sessions: list(get('sessions', '')),
|
|
163
|
+
refs: list(get('refs', '')),
|
|
164
|
+
});
|
|
165
|
+
if (!Object.keys(named).length) {
|
|
166
|
+
throw new Error('Nothing to forget: name at least one item, session or ref');
|
|
167
|
+
}
|
|
168
|
+
return post(named);
|
|
169
|
+
}
|
|
170
|
+
case 'correct':
|
|
171
|
+
return post({ ref: text(get('ref')), replacement: text(get('replacement')) });
|
|
172
|
+
case 'summary':
|
|
173
|
+
case 'sources':
|
|
174
|
+
case 'deleteUser':
|
|
175
|
+
return post({});
|
|
176
|
+
default:
|
|
177
|
+
throw new Error(`Unknown operation "${operation}"`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function merged(operation, pages) {
|
|
181
|
+
const { key } = exports.PAGED[operation];
|
|
182
|
+
const all = pages.flatMap((p) => (Array.isArray(p[key]) ? p[key] : []));
|
|
183
|
+
return { ...pages[0], [key]: all, next: null };
|
|
184
|
+
}
|
|
185
|
+
function context(answer, maxChars) {
|
|
186
|
+
var _a;
|
|
187
|
+
const memories = Array.isArray(answer.memories) ? answer.memories : [];
|
|
188
|
+
const notes = Array.isArray(answer.notes) ? answer.notes.map(String) : [];
|
|
189
|
+
const head = notes.length ? `${notes.join('\n')}\n\n` : '';
|
|
190
|
+
let out = '';
|
|
191
|
+
for (const memory of memories) {
|
|
192
|
+
const date = memory.type === 'excerpt' && memory.date ? String(memory.date).slice(0, 10) : '';
|
|
193
|
+
const line = `- ${date ? `${date}: ` : ''}${String((_a = memory.text) !== null && _a !== void 0 ? _a : '')}`;
|
|
194
|
+
const grown = `${out || head}${out ? '\n' : ''}${line}`;
|
|
195
|
+
if (grown.length > maxChars)
|
|
196
|
+
break;
|
|
197
|
+
out = grown;
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
function shaped(operation, answer, get) {
|
|
202
|
+
var _a, _b;
|
|
203
|
+
if (operation !== 'search')
|
|
204
|
+
return answer;
|
|
205
|
+
const options = ((_a = get('searchOptions', {})) !== null && _a !== void 0 ? _a : {});
|
|
206
|
+
const length = Number((_b = options.contextLength) !== null && _b !== void 0 ? _b : 4000) || 4000;
|
|
207
|
+
return { context: context(answer, length), ...answer };
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=requests.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@alexein/n8n-nodes-alexein",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "n8n node for Alexein: long-term memory for your users and AI agents.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://docs.alexein.ai/integrations/n8n",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"n8n-community-node-package",
|
|
9
|
+
"n8n",
|
|
10
|
+
"alexein",
|
|
11
|
+
"memory",
|
|
12
|
+
"ai-agent",
|
|
13
|
+
"llm"
|
|
14
|
+
],
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Alexein AI",
|
|
17
|
+
"email": "abdulrehman@alexein.ai"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/Alexein-AI/sdk.git",
|
|
22
|
+
"directory": "integrations/n8n"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "n8n-node build",
|
|
26
|
+
"build:watch": "tsc --watch",
|
|
27
|
+
"dev": "n8n-node dev",
|
|
28
|
+
"lint": "n8n-node lint",
|
|
29
|
+
"lint:fix": "n8n-node lint --fix",
|
|
30
|
+
"release": "n8n-node release",
|
|
31
|
+
"prepublishOnly": "n8n-node prerelease",
|
|
32
|
+
"test": "n8n-node build && node --test \"test/*.test.mjs\""
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"!dist/**/*.map",
|
|
37
|
+
"!dist/package.json"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"n8n": {
|
|
43
|
+
"n8nNodesApiVersion": 1,
|
|
44
|
+
"strict": true,
|
|
45
|
+
"credentials": [
|
|
46
|
+
"dist/credentials/AlexeinApi.credentials.js"
|
|
47
|
+
],
|
|
48
|
+
"nodes": [
|
|
49
|
+
"dist/nodes/Alexein/Alexein.node.js"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@n8n/node-cli": "*",
|
|
54
|
+
"eslint": "9.32.0",
|
|
55
|
+
"prettier": "3.6.2",
|
|
56
|
+
"release-it": "^21.1.0",
|
|
57
|
+
"typescript": "5.9.2"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"n8n-workflow": "*"
|
|
61
|
+
}
|
|
62
|
+
}
|