@aigne/core 1.17.0 → 1.18.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/CHANGELOG.md +33 -19
- package/lib/cjs/agents/agent.d.ts +27 -11
- package/lib/cjs/agents/agent.js +36 -12
- package/lib/cjs/agents/ai-agent.d.ts +1 -3
- package/lib/cjs/agents/ai-agent.js +2 -11
- package/lib/cjs/agents/mcp-agent.d.ts +1 -1
- package/lib/cjs/agents/mcp-agent.js +5 -11
- package/lib/cjs/agents/user-agent.d.ts +0 -1
- package/lib/cjs/agents/user-agent.js +1 -2
- package/lib/cjs/aigne/context.d.ts +2 -3
- package/lib/cjs/aigne/context.js +3 -5
- package/lib/cjs/aigne/message-queue.d.ts +6 -2
- package/lib/cjs/aigne/message-queue.js +2 -2
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/loader/agent-js.d.ts +1 -1
- package/lib/cjs/loader/agent-yaml.d.ts +2 -1
- package/lib/cjs/loader/agent-yaml.js +3 -2
- package/lib/cjs/loader/index.d.ts +5 -1
- package/lib/cjs/loader/index.js +25 -16
- package/lib/cjs/memory/retriever.d.ts +2 -2
- package/lib/cjs/prompt/prompt-builder.d.ts +2 -6
- package/lib/cjs/prompt/prompt-builder.js +10 -6
- package/lib/cjs/prompt/template.js +1 -3
- package/lib/cjs/utils/logger.js +3 -3
- package/lib/cjs/utils/nodejs.d.ts +8 -0
- package/lib/cjs/utils/nodejs.js +24 -0
- package/lib/dts/agents/agent.d.ts +27 -11
- package/lib/dts/agents/ai-agent.d.ts +1 -3
- package/lib/dts/agents/mcp-agent.d.ts +1 -1
- package/lib/dts/agents/user-agent.d.ts +0 -1
- package/lib/dts/aigne/context.d.ts +2 -3
- package/lib/dts/aigne/message-queue.d.ts +6 -2
- package/lib/dts/index.d.ts +1 -0
- package/lib/dts/loader/agent-js.d.ts +1 -1
- package/lib/dts/loader/agent-yaml.d.ts +2 -1
- package/lib/dts/loader/index.d.ts +5 -1
- package/lib/dts/memory/retriever.d.ts +2 -2
- package/lib/dts/prompt/prompt-builder.d.ts +2 -6
- package/lib/dts/utils/nodejs.d.ts +8 -0
- package/lib/esm/agents/agent.d.ts +27 -11
- package/lib/esm/agents/agent.js +37 -13
- package/lib/esm/agents/ai-agent.d.ts +1 -3
- package/lib/esm/agents/ai-agent.js +2 -11
- package/lib/esm/agents/mcp-agent.d.ts +1 -1
- package/lib/esm/agents/mcp-agent.js +5 -11
- package/lib/esm/agents/user-agent.d.ts +0 -1
- package/lib/esm/agents/user-agent.js +0 -1
- package/lib/esm/aigne/context.d.ts +2 -3
- package/lib/esm/aigne/context.js +3 -2
- package/lib/esm/aigne/message-queue.d.ts +6 -2
- package/lib/esm/aigne/message-queue.js +2 -2
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/loader/agent-js.d.ts +1 -1
- package/lib/esm/loader/agent-yaml.d.ts +2 -1
- package/lib/esm/loader/agent-yaml.js +3 -2
- package/lib/esm/loader/index.d.ts +5 -1
- package/lib/esm/loader/index.js +25 -16
- package/lib/esm/memory/retriever.d.ts +2 -2
- package/lib/esm/prompt/prompt-builder.d.ts +2 -6
- package/lib/esm/prompt/prompt-builder.js +11 -7
- package/lib/esm/prompt/template.js +1 -3
- package/lib/esm/utils/logger.js +3 -3
- package/lib/esm/utils/nodejs.d.ts +8 -0
- package/lib/esm/utils/nodejs.js +21 -0
- package/package.json +4 -6
- package/lib/cjs/memory/default-memory/default-memory-storage/index.d.ts +0 -30
- package/lib/cjs/memory/default-memory/default-memory-storage/index.js +0 -69
- package/lib/cjs/memory/default-memory/default-memory-storage/migrate.d.ts +0 -7
- package/lib/cjs/memory/default-memory/default-memory-storage/migrate.js +0 -53
- package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +0 -7
- package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js +0 -33
- package/lib/cjs/memory/default-memory/default-memory-storage/models/memory.d.ts +0 -10
- package/lib/cjs/memory/default-memory/default-memory-storage/models/memory.js +0 -32
- package/lib/cjs/memory/default-memory/index.d.ts +0 -10
- package/lib/cjs/memory/default-memory/index.js +0 -61
- package/lib/cjs/memory/default-memory/storage.d.ts +0 -13
- package/lib/cjs/memory/default-memory/storage.js +0 -6
- package/lib/cjs/utils/fs.d.ts +0 -2
- package/lib/cjs/utils/fs.js +0 -25
- package/lib/dts/memory/default-memory/default-memory-storage/index.d.ts +0 -30
- package/lib/dts/memory/default-memory/default-memory-storage/migrate.d.ts +0 -7
- package/lib/dts/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +0 -7
- package/lib/dts/memory/default-memory/default-memory-storage/models/memory.d.ts +0 -10
- package/lib/dts/memory/default-memory/index.d.ts +0 -10
- package/lib/dts/memory/default-memory/storage.d.ts +0 -13
- package/lib/dts/utils/fs.d.ts +0 -2
- package/lib/esm/memory/default-memory/default-memory-storage/index.d.ts +0 -30
- package/lib/esm/memory/default-memory/default-memory-storage/index.js +0 -64
- package/lib/esm/memory/default-memory/default-memory-storage/migrate.d.ts +0 -7
- package/lib/esm/memory/default-memory/default-memory-storage/migrate.js +0 -16
- package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +0 -7
- package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js +0 -28
- package/lib/esm/memory/default-memory/default-memory-storage/models/memory.d.ts +0 -10
- package/lib/esm/memory/default-memory/default-memory-storage/models/memory.js +0 -29
- package/lib/esm/memory/default-memory/index.d.ts +0 -10
- package/lib/esm/memory/default-memory/index.js +0 -54
- package/lib/esm/memory/default-memory/storage.d.ts +0 -13
- package/lib/esm/memory/default-memory/storage.js +0 -2
- package/lib/esm/utils/fs.d.ts +0 -2
- package/lib/esm/utils/fs.js +0 -21
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const nodejs = {
|
|
2
|
+
customInspect: isNodejsEnvironment() ? require("node:util").inspect.custom : Symbol("inspect"),
|
|
3
|
+
isStdoutATTY: isNodejsEnvironment() && process.stdout?.isTTY,
|
|
4
|
+
isStderrATTY: isNodejsEnvironment() && process.stderr?.isTTY,
|
|
5
|
+
env: isNodejsEnvironment() ? process.env : {},
|
|
6
|
+
get fs() {
|
|
7
|
+
ensureNodejsEnvironment();
|
|
8
|
+
return require("node:fs/promises");
|
|
9
|
+
},
|
|
10
|
+
get path() {
|
|
11
|
+
ensureNodejsEnvironment();
|
|
12
|
+
return require("node:path");
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
function isNodejsEnvironment() {
|
|
16
|
+
return typeof process !== "undefined";
|
|
17
|
+
}
|
|
18
|
+
function ensureNodejsEnvironment() {
|
|
19
|
+
if (!isNodejsEnvironment())
|
|
20
|
+
throw new Error("This code must run in a Node.js environment.");
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "AIGNE core library for building AI-powered applications",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -71,19 +71,17 @@
|
|
|
71
71
|
"eventsource-parser": "^3.0.1",
|
|
72
72
|
"fast-deep-equal": "^3.1.3",
|
|
73
73
|
"immer": "^10.1.1",
|
|
74
|
-
"inquirer": "^12.6.0",
|
|
75
74
|
"mustache": "^4.2.0",
|
|
76
75
|
"nanoid": "^5.1.5",
|
|
77
76
|
"p-retry": "^6.2.1",
|
|
78
77
|
"raw-body": "^3.0.0",
|
|
79
|
-
"
|
|
80
|
-
"sqlite3": "^5.1.7",
|
|
78
|
+
"strict-event-emitter": "^0.5.1",
|
|
81
79
|
"ufo": "^1.6.1",
|
|
82
|
-
"umzug": "^3.8.2",
|
|
83
80
|
"uuid": "^11.1.0",
|
|
84
81
|
"yaml": "^2.7.1",
|
|
85
82
|
"zod": "^3.24.4",
|
|
86
|
-
"zod-to-json-schema": "^3.24.5"
|
|
83
|
+
"zod-to-json-schema": "^3.24.5",
|
|
84
|
+
"@aigne/platform-helpers": "^0.1.0"
|
|
87
85
|
},
|
|
88
86
|
"devDependencies": {
|
|
89
87
|
"@types/bun": "^1.2.12",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { AgentInvokeOptions } from "../../../agents/agent.js";
|
|
2
|
-
import "sqlite3";
|
|
3
|
-
import { Sequelize } from "sequelize";
|
|
4
|
-
import type { Context } from "../../../aigne/context.js";
|
|
5
|
-
import type { PromiseOrValue } from "../../../utils/type-utils.js";
|
|
6
|
-
import type { Memory } from "../../memory.js";
|
|
7
|
-
import { MemoryStorage } from "../storage.js";
|
|
8
|
-
export interface DefaultMemoryStorageOptions {
|
|
9
|
-
path?: string;
|
|
10
|
-
getSessionId?: (context: Context) => PromiseOrValue<string>;
|
|
11
|
-
}
|
|
12
|
-
export declare class DefaultMemoryStorage extends MemoryStorage {
|
|
13
|
-
options?: DefaultMemoryStorageOptions | undefined;
|
|
14
|
-
memories: {
|
|
15
|
-
[groupId: string]: Memory[];
|
|
16
|
-
};
|
|
17
|
-
constructor(options?: DefaultMemoryStorageOptions | undefined);
|
|
18
|
-
private _models?;
|
|
19
|
-
private get models();
|
|
20
|
-
private convertMemory;
|
|
21
|
-
search(query: {
|
|
22
|
-
limit?: number;
|
|
23
|
-
}, { context }: AgentInvokeOptions): Promise<{
|
|
24
|
-
result: Memory[];
|
|
25
|
-
}>;
|
|
26
|
-
create(memory: Pick<Memory, "content">, { context }: AgentInvokeOptions): Promise<{
|
|
27
|
-
result: Memory;
|
|
28
|
-
}>;
|
|
29
|
-
}
|
|
30
|
-
export declare function initSequelize(path?: string): Sequelize;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultMemoryStorage = void 0;
|
|
4
|
-
exports.initSequelize = initSequelize;
|
|
5
|
-
require("sqlite3");
|
|
6
|
-
const sequelize_1 = require("sequelize");
|
|
7
|
-
const logger_js_1 = require("../../../utils/logger.js");
|
|
8
|
-
const storage_js_1 = require("../storage.js");
|
|
9
|
-
const migrate_js_1 = require("./migrate.js");
|
|
10
|
-
const memory_js_1 = require("./models/memory.js");
|
|
11
|
-
const DEFAULT_MAX_MEMORY_COUNT = 10;
|
|
12
|
-
class DefaultMemoryStorage extends storage_js_1.MemoryStorage {
|
|
13
|
-
options;
|
|
14
|
-
memories = {};
|
|
15
|
-
constructor(options) {
|
|
16
|
-
super();
|
|
17
|
-
this.options = options;
|
|
18
|
-
}
|
|
19
|
-
_models;
|
|
20
|
-
get models() {
|
|
21
|
-
this._models ??= (async () => {
|
|
22
|
-
const sequelize = initSequelize(this.options?.path);
|
|
23
|
-
await (0, migrate_js_1.migrate)(sequelize);
|
|
24
|
-
return {
|
|
25
|
-
Memory: (0, memory_js_1.initMemoryModel)(sequelize),
|
|
26
|
-
};
|
|
27
|
-
})();
|
|
28
|
-
return this._models;
|
|
29
|
-
}
|
|
30
|
-
convertMemory(m) {
|
|
31
|
-
return {
|
|
32
|
-
id: m.id,
|
|
33
|
-
sessionId: m.sessionId,
|
|
34
|
-
content: m.content,
|
|
35
|
-
createdAt: m.createdAt.toISOString(),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
async search(query, { context }) {
|
|
39
|
-
const { limit = DEFAULT_MAX_MEMORY_COUNT } = query;
|
|
40
|
-
const sessionId = (await this.options?.getSessionId?.(context)) ?? null;
|
|
41
|
-
const { Memory } = await this.models;
|
|
42
|
-
const memories = await Memory.findAll({
|
|
43
|
-
where: { sessionId },
|
|
44
|
-
order: [["id", "DESC"]],
|
|
45
|
-
limit,
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
result: memories.reverse().map(this.convertMemory),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
async create(memory, { context }) {
|
|
52
|
-
const sessionId = (await this.options?.getSessionId?.(context)) ?? null;
|
|
53
|
-
const { Memory } = await this.models;
|
|
54
|
-
const m = await Memory.create({
|
|
55
|
-
...memory,
|
|
56
|
-
sessionId,
|
|
57
|
-
});
|
|
58
|
-
return { result: this.convertMemory(m) };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.DefaultMemoryStorage = DefaultMemoryStorage;
|
|
62
|
-
function initSequelize(path) {
|
|
63
|
-
const sequelize = new sequelize_1.Sequelize({
|
|
64
|
-
logging: (sql) => logger_js_1.logger.debug(sql),
|
|
65
|
-
storage: path,
|
|
66
|
-
dialect: "sqlite",
|
|
67
|
-
});
|
|
68
|
-
return sequelize;
|
|
69
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Sequelize } from "sequelize";
|
|
2
|
-
import { type MigrateDownOptions, type MigrateUpOptions } from "umzug";
|
|
3
|
-
export declare const migrate: (sequelize: Sequelize, { type, upOptions, downOptions, }?: {
|
|
4
|
-
type?: "up" | "down";
|
|
5
|
-
upOptions?: MigrateUpOptions;
|
|
6
|
-
downOptions?: MigrateDownOptions;
|
|
7
|
-
}) => Promise<void>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.migrate = void 0;
|
|
37
|
-
const umzug_1 = require("umzug");
|
|
38
|
-
const init = __importStar(require("./migrations/20250523165801-init.js"));
|
|
39
|
-
const migrate = async (sequelize, { type = "up", upOptions, downOptions, } = {}) => {
|
|
40
|
-
const umzug = new umzug_1.Umzug({
|
|
41
|
-
migrations: [{ ...init, name: "20241224202701-init" }],
|
|
42
|
-
context: sequelize.getQueryInterface(),
|
|
43
|
-
storage: new umzug_1.SequelizeStorage({ sequelize }),
|
|
44
|
-
logger: console,
|
|
45
|
-
});
|
|
46
|
-
if (type === "down") {
|
|
47
|
-
await umzug.down(downOptions);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
await umzug.up(upOptions);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
exports.migrate = migrate;
|
package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type QueryInterface } from "sequelize";
|
|
2
|
-
export declare const up: ({ context: queryInterface }: {
|
|
3
|
-
context: QueryInterface;
|
|
4
|
-
}) => Promise<void>;
|
|
5
|
-
export declare const down: ({ context: queryInterface }: {
|
|
6
|
-
context: QueryInterface;
|
|
7
|
-
}) => Promise<void>;
|
package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.down = exports.up = void 0;
|
|
4
|
-
const sequelize_1 = require("sequelize");
|
|
5
|
-
const up = async ({ context: queryInterface }) => {
|
|
6
|
-
await queryInterface.createTable("Memories", {
|
|
7
|
-
id: {
|
|
8
|
-
type: sequelize_1.DataTypes.STRING,
|
|
9
|
-
primaryKey: true,
|
|
10
|
-
allowNull: false,
|
|
11
|
-
},
|
|
12
|
-
createdAt: {
|
|
13
|
-
type: sequelize_1.DataTypes.DATE,
|
|
14
|
-
allowNull: false,
|
|
15
|
-
},
|
|
16
|
-
updatedAt: {
|
|
17
|
-
type: sequelize_1.DataTypes.DATE,
|
|
18
|
-
allowNull: false,
|
|
19
|
-
},
|
|
20
|
-
sessionId: {
|
|
21
|
-
type: sequelize_1.DataTypes.STRING,
|
|
22
|
-
},
|
|
23
|
-
content: {
|
|
24
|
-
type: sequelize_1.DataTypes.JSON,
|
|
25
|
-
allowNull: false,
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
exports.up = up;
|
|
30
|
-
const down = async ({ context: queryInterface }) => {
|
|
31
|
-
await queryInterface.dropTable("Memories");
|
|
32
|
-
};
|
|
33
|
-
exports.down = down;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type CreationOptional, type InferAttributes, type InferCreationAttributes, Model } from "sequelize";
|
|
2
|
-
import type { ModelStatic, Sequelize } from "sequelize";
|
|
3
|
-
export interface Memory extends Model<InferAttributes<Memory>, InferCreationAttributes<Memory>> {
|
|
4
|
-
id: CreationOptional<string>;
|
|
5
|
-
createdAt: CreationOptional<Date>;
|
|
6
|
-
updatedAt: CreationOptional<Date>;
|
|
7
|
-
sessionId?: string | null;
|
|
8
|
-
content: unknown;
|
|
9
|
-
}
|
|
10
|
-
export declare function initMemoryModel(sequelize: Sequelize): ModelStatic<Memory>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initMemoryModel = initMemoryModel;
|
|
4
|
-
const sequelize_1 = require("sequelize");
|
|
5
|
-
const uuid_1 = require("uuid");
|
|
6
|
-
const nextId = () => (0, uuid_1.v7)();
|
|
7
|
-
function initMemoryModel(sequelize) {
|
|
8
|
-
return class Memory extends sequelize_1.Model {
|
|
9
|
-
}.init({
|
|
10
|
-
id: {
|
|
11
|
-
type: sequelize_1.DataTypes.STRING,
|
|
12
|
-
primaryKey: true,
|
|
13
|
-
allowNull: false,
|
|
14
|
-
defaultValue: nextId,
|
|
15
|
-
},
|
|
16
|
-
createdAt: {
|
|
17
|
-
type: sequelize_1.DataTypes.DATE,
|
|
18
|
-
allowNull: false,
|
|
19
|
-
},
|
|
20
|
-
updatedAt: {
|
|
21
|
-
type: sequelize_1.DataTypes.DATE,
|
|
22
|
-
allowNull: false,
|
|
23
|
-
},
|
|
24
|
-
sessionId: {
|
|
25
|
-
type: sequelize_1.DataTypes.STRING,
|
|
26
|
-
},
|
|
27
|
-
content: {
|
|
28
|
-
type: sequelize_1.DataTypes.JSON,
|
|
29
|
-
allowNull: false,
|
|
30
|
-
},
|
|
31
|
-
}, { sequelize });
|
|
32
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { MemoryAgent, type MemoryAgentOptions } from "../memory.js";
|
|
2
|
-
import { type DefaultMemoryStorageOptions } from "./default-memory-storage/index.js";
|
|
3
|
-
import { MemoryStorage } from "./storage.js";
|
|
4
|
-
export interface DefaultMemoryOptions extends Partial<MemoryAgentOptions> {
|
|
5
|
-
storage?: MemoryStorage | DefaultMemoryStorageOptions;
|
|
6
|
-
}
|
|
7
|
-
export declare class DefaultMemory extends MemoryAgent {
|
|
8
|
-
constructor(options?: DefaultMemoryOptions);
|
|
9
|
-
storage: MemoryStorage;
|
|
10
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DefaultMemory = void 0;
|
|
7
|
-
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
8
|
-
const memory_js_1 = require("../memory.js");
|
|
9
|
-
const recorder_js_1 = require("../recorder.js");
|
|
10
|
-
const retriever_js_1 = require("../retriever.js");
|
|
11
|
-
const index_js_1 = require("./default-memory-storage/index.js");
|
|
12
|
-
const storage_js_1 = require("./storage.js");
|
|
13
|
-
class DefaultMemory extends memory_js_1.MemoryAgent {
|
|
14
|
-
constructor(options = {}) {
|
|
15
|
-
super({
|
|
16
|
-
...options,
|
|
17
|
-
autoUpdate: options.autoUpdate ?? true,
|
|
18
|
-
});
|
|
19
|
-
this.storage =
|
|
20
|
-
options.storage instanceof storage_js_1.MemoryStorage
|
|
21
|
-
? options.storage
|
|
22
|
-
: new index_js_1.DefaultMemoryStorage(options.storage);
|
|
23
|
-
if (!this.recorder)
|
|
24
|
-
this.recorder = new DefaultMemoryRecorder(this);
|
|
25
|
-
if (!this.retriever)
|
|
26
|
-
this.retriever = new DefaultMemoryRetriever(this);
|
|
27
|
-
}
|
|
28
|
-
storage;
|
|
29
|
-
}
|
|
30
|
-
exports.DefaultMemory = DefaultMemory;
|
|
31
|
-
class DefaultMemoryRetriever extends retriever_js_1.MemoryRetriever {
|
|
32
|
-
memory;
|
|
33
|
-
constructor(memory) {
|
|
34
|
-
super({});
|
|
35
|
-
this.memory = memory;
|
|
36
|
-
}
|
|
37
|
-
async process(input, options) {
|
|
38
|
-
const { result } = await this.memory.storage.search(input, options);
|
|
39
|
-
return { memories: result };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
class DefaultMemoryRecorder extends recorder_js_1.MemoryRecorder {
|
|
43
|
-
memory;
|
|
44
|
-
constructor(memory) {
|
|
45
|
-
super({});
|
|
46
|
-
this.memory = memory;
|
|
47
|
-
}
|
|
48
|
-
async process(input, options) {
|
|
49
|
-
const newMemories = [];
|
|
50
|
-
for (const content of input.content) {
|
|
51
|
-
const { result: [last], } = await this.memory.storage.search({ limit: 1 }, options);
|
|
52
|
-
if (!(0, fast_deep_equal_1.default)(last?.content, content)) {
|
|
53
|
-
const { result } = await this.memory.storage.create({ content }, options);
|
|
54
|
-
newMemories.push(result);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
memories: newMemories,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AgentInvokeOptions } from "../../agents/agent.js";
|
|
2
|
-
import type { Memory } from "../memory.js";
|
|
3
|
-
export declare abstract class MemoryStorage {
|
|
4
|
-
abstract create(memory: Pick<Memory, "content">, options: AgentInvokeOptions): Promise<{
|
|
5
|
-
result: Memory;
|
|
6
|
-
}>;
|
|
7
|
-
abstract search(query: {
|
|
8
|
-
search?: string;
|
|
9
|
-
limit?: number;
|
|
10
|
-
}, options: AgentInvokeOptions): Promise<{
|
|
11
|
-
result: Memory[];
|
|
12
|
-
}>;
|
|
13
|
-
}
|
package/lib/cjs/utils/fs.d.ts
DELETED
package/lib/cjs/utils/fs.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exists = exists;
|
|
4
|
-
exports.expandHome = expandHome;
|
|
5
|
-
const promises_1 = require("node:fs/promises");
|
|
6
|
-
const node_os_1 = require("node:os");
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
|
-
async function exists(path) {
|
|
9
|
-
try {
|
|
10
|
-
await (0, promises_1.stat)(path);
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
if (e.code === "ENOENT") {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
throw e;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function expandHome(filepath) {
|
|
21
|
-
if (filepath.startsWith("~/") || filepath === "~") {
|
|
22
|
-
return (0, node_path_1.join)((0, node_os_1.homedir)(), filepath.slice(1));
|
|
23
|
-
}
|
|
24
|
-
return filepath;
|
|
25
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { AgentInvokeOptions } from "../../../agents/agent.js";
|
|
2
|
-
import "sqlite3";
|
|
3
|
-
import { Sequelize } from "sequelize";
|
|
4
|
-
import type { Context } from "../../../aigne/context.js";
|
|
5
|
-
import type { PromiseOrValue } from "../../../utils/type-utils.js";
|
|
6
|
-
import type { Memory } from "../../memory.js";
|
|
7
|
-
import { MemoryStorage } from "../storage.js";
|
|
8
|
-
export interface DefaultMemoryStorageOptions {
|
|
9
|
-
path?: string;
|
|
10
|
-
getSessionId?: (context: Context) => PromiseOrValue<string>;
|
|
11
|
-
}
|
|
12
|
-
export declare class DefaultMemoryStorage extends MemoryStorage {
|
|
13
|
-
options?: DefaultMemoryStorageOptions | undefined;
|
|
14
|
-
memories: {
|
|
15
|
-
[groupId: string]: Memory[];
|
|
16
|
-
};
|
|
17
|
-
constructor(options?: DefaultMemoryStorageOptions | undefined);
|
|
18
|
-
private _models?;
|
|
19
|
-
private get models();
|
|
20
|
-
private convertMemory;
|
|
21
|
-
search(query: {
|
|
22
|
-
limit?: number;
|
|
23
|
-
}, { context }: AgentInvokeOptions): Promise<{
|
|
24
|
-
result: Memory[];
|
|
25
|
-
}>;
|
|
26
|
-
create(memory: Pick<Memory, "content">, { context }: AgentInvokeOptions): Promise<{
|
|
27
|
-
result: Memory;
|
|
28
|
-
}>;
|
|
29
|
-
}
|
|
30
|
-
export declare function initSequelize(path?: string): Sequelize;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Sequelize } from "sequelize";
|
|
2
|
-
import { type MigrateDownOptions, type MigrateUpOptions } from "umzug";
|
|
3
|
-
export declare const migrate: (sequelize: Sequelize, { type, upOptions, downOptions, }?: {
|
|
4
|
-
type?: "up" | "down";
|
|
5
|
-
upOptions?: MigrateUpOptions;
|
|
6
|
-
downOptions?: MigrateDownOptions;
|
|
7
|
-
}) => Promise<void>;
|
package/lib/dts/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type QueryInterface } from "sequelize";
|
|
2
|
-
export declare const up: ({ context: queryInterface }: {
|
|
3
|
-
context: QueryInterface;
|
|
4
|
-
}) => Promise<void>;
|
|
5
|
-
export declare const down: ({ context: queryInterface }: {
|
|
6
|
-
context: QueryInterface;
|
|
7
|
-
}) => Promise<void>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type CreationOptional, type InferAttributes, type InferCreationAttributes, Model } from "sequelize";
|
|
2
|
-
import type { ModelStatic, Sequelize } from "sequelize";
|
|
3
|
-
export interface Memory extends Model<InferAttributes<Memory>, InferCreationAttributes<Memory>> {
|
|
4
|
-
id: CreationOptional<string>;
|
|
5
|
-
createdAt: CreationOptional<Date>;
|
|
6
|
-
updatedAt: CreationOptional<Date>;
|
|
7
|
-
sessionId?: string | null;
|
|
8
|
-
content: unknown;
|
|
9
|
-
}
|
|
10
|
-
export declare function initMemoryModel(sequelize: Sequelize): ModelStatic<Memory>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { MemoryAgent, type MemoryAgentOptions } from "../memory.js";
|
|
2
|
-
import { type DefaultMemoryStorageOptions } from "./default-memory-storage/index.js";
|
|
3
|
-
import { MemoryStorage } from "./storage.js";
|
|
4
|
-
export interface DefaultMemoryOptions extends Partial<MemoryAgentOptions> {
|
|
5
|
-
storage?: MemoryStorage | DefaultMemoryStorageOptions;
|
|
6
|
-
}
|
|
7
|
-
export declare class DefaultMemory extends MemoryAgent {
|
|
8
|
-
constructor(options?: DefaultMemoryOptions);
|
|
9
|
-
storage: MemoryStorage;
|
|
10
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AgentInvokeOptions } from "../../agents/agent.js";
|
|
2
|
-
import type { Memory } from "../memory.js";
|
|
3
|
-
export declare abstract class MemoryStorage {
|
|
4
|
-
abstract create(memory: Pick<Memory, "content">, options: AgentInvokeOptions): Promise<{
|
|
5
|
-
result: Memory;
|
|
6
|
-
}>;
|
|
7
|
-
abstract search(query: {
|
|
8
|
-
search?: string;
|
|
9
|
-
limit?: number;
|
|
10
|
-
}, options: AgentInvokeOptions): Promise<{
|
|
11
|
-
result: Memory[];
|
|
12
|
-
}>;
|
|
13
|
-
}
|
package/lib/dts/utils/fs.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { AgentInvokeOptions } from "../../../agents/agent.js";
|
|
2
|
-
import "sqlite3";
|
|
3
|
-
import { Sequelize } from "sequelize";
|
|
4
|
-
import type { Context } from "../../../aigne/context.js";
|
|
5
|
-
import type { PromiseOrValue } from "../../../utils/type-utils.js";
|
|
6
|
-
import type { Memory } from "../../memory.js";
|
|
7
|
-
import { MemoryStorage } from "../storage.js";
|
|
8
|
-
export interface DefaultMemoryStorageOptions {
|
|
9
|
-
path?: string;
|
|
10
|
-
getSessionId?: (context: Context) => PromiseOrValue<string>;
|
|
11
|
-
}
|
|
12
|
-
export declare class DefaultMemoryStorage extends MemoryStorage {
|
|
13
|
-
options?: DefaultMemoryStorageOptions | undefined;
|
|
14
|
-
memories: {
|
|
15
|
-
[groupId: string]: Memory[];
|
|
16
|
-
};
|
|
17
|
-
constructor(options?: DefaultMemoryStorageOptions | undefined);
|
|
18
|
-
private _models?;
|
|
19
|
-
private get models();
|
|
20
|
-
private convertMemory;
|
|
21
|
-
search(query: {
|
|
22
|
-
limit?: number;
|
|
23
|
-
}, { context }: AgentInvokeOptions): Promise<{
|
|
24
|
-
result: Memory[];
|
|
25
|
-
}>;
|
|
26
|
-
create(memory: Pick<Memory, "content">, { context }: AgentInvokeOptions): Promise<{
|
|
27
|
-
result: Memory;
|
|
28
|
-
}>;
|
|
29
|
-
}
|
|
30
|
-
export declare function initSequelize(path?: string): Sequelize;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import "sqlite3";
|
|
2
|
-
import { Sequelize } from "sequelize";
|
|
3
|
-
import { logger } from "../../../utils/logger.js";
|
|
4
|
-
import { MemoryStorage } from "../storage.js";
|
|
5
|
-
import { migrate } from "./migrate.js";
|
|
6
|
-
import { initMemoryModel } from "./models/memory.js";
|
|
7
|
-
const DEFAULT_MAX_MEMORY_COUNT = 10;
|
|
8
|
-
export class DefaultMemoryStorage extends MemoryStorage {
|
|
9
|
-
options;
|
|
10
|
-
memories = {};
|
|
11
|
-
constructor(options) {
|
|
12
|
-
super();
|
|
13
|
-
this.options = options;
|
|
14
|
-
}
|
|
15
|
-
_models;
|
|
16
|
-
get models() {
|
|
17
|
-
this._models ??= (async () => {
|
|
18
|
-
const sequelize = initSequelize(this.options?.path);
|
|
19
|
-
await migrate(sequelize);
|
|
20
|
-
return {
|
|
21
|
-
Memory: initMemoryModel(sequelize),
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
return this._models;
|
|
25
|
-
}
|
|
26
|
-
convertMemory(m) {
|
|
27
|
-
return {
|
|
28
|
-
id: m.id,
|
|
29
|
-
sessionId: m.sessionId,
|
|
30
|
-
content: m.content,
|
|
31
|
-
createdAt: m.createdAt.toISOString(),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
async search(query, { context }) {
|
|
35
|
-
const { limit = DEFAULT_MAX_MEMORY_COUNT } = query;
|
|
36
|
-
const sessionId = (await this.options?.getSessionId?.(context)) ?? null;
|
|
37
|
-
const { Memory } = await this.models;
|
|
38
|
-
const memories = await Memory.findAll({
|
|
39
|
-
where: { sessionId },
|
|
40
|
-
order: [["id", "DESC"]],
|
|
41
|
-
limit,
|
|
42
|
-
});
|
|
43
|
-
return {
|
|
44
|
-
result: memories.reverse().map(this.convertMemory),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async create(memory, { context }) {
|
|
48
|
-
const sessionId = (await this.options?.getSessionId?.(context)) ?? null;
|
|
49
|
-
const { Memory } = await this.models;
|
|
50
|
-
const m = await Memory.create({
|
|
51
|
-
...memory,
|
|
52
|
-
sessionId,
|
|
53
|
-
});
|
|
54
|
-
return { result: this.convertMemory(m) };
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export function initSequelize(path) {
|
|
58
|
-
const sequelize = new Sequelize({
|
|
59
|
-
logging: (sql) => logger.debug(sql),
|
|
60
|
-
storage: path,
|
|
61
|
-
dialect: "sqlite",
|
|
62
|
-
});
|
|
63
|
-
return sequelize;
|
|
64
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Sequelize } from "sequelize";
|
|
2
|
-
import { type MigrateDownOptions, type MigrateUpOptions } from "umzug";
|
|
3
|
-
export declare const migrate: (sequelize: Sequelize, { type, upOptions, downOptions, }?: {
|
|
4
|
-
type?: "up" | "down";
|
|
5
|
-
upOptions?: MigrateUpOptions;
|
|
6
|
-
downOptions?: MigrateDownOptions;
|
|
7
|
-
}) => Promise<void>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SequelizeStorage, Umzug } from "umzug";
|
|
2
|
-
import * as init from "./migrations/20250523165801-init.js";
|
|
3
|
-
export const migrate = async (sequelize, { type = "up", upOptions, downOptions, } = {}) => {
|
|
4
|
-
const umzug = new Umzug({
|
|
5
|
-
migrations: [{ ...init, name: "20241224202701-init" }],
|
|
6
|
-
context: sequelize.getQueryInterface(),
|
|
7
|
-
storage: new SequelizeStorage({ sequelize }),
|
|
8
|
-
logger: console,
|
|
9
|
-
});
|
|
10
|
-
if (type === "down") {
|
|
11
|
-
await umzug.down(downOptions);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
await umzug.up(upOptions);
|
|
15
|
-
}
|
|
16
|
-
};
|
package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type QueryInterface } from "sequelize";
|
|
2
|
-
export declare const up: ({ context: queryInterface }: {
|
|
3
|
-
context: QueryInterface;
|
|
4
|
-
}) => Promise<void>;
|
|
5
|
-
export declare const down: ({ context: queryInterface }: {
|
|
6
|
-
context: QueryInterface;
|
|
7
|
-
}) => Promise<void>;
|