@aigne/afs-history 1.2.0-beta.3 → 1.2.0-beta.4
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 +14 -0
- package/lib/cjs/index.d.ts +1 -2
- package/lib/cjs/index.js +5 -6
- package/lib/cjs/storage/index.js +1 -1
- package/lib/cjs/storage/migrate.js +2 -1
- package/lib/cjs/storage/migrations/002-add-agent-id.d.ts +2 -0
- package/lib/cjs/storage/migrations/002-add-agent-id.js +13 -0
- package/lib/cjs/storage/models/entries.d.ts +19 -0
- package/lib/cjs/storage/models/entries.js +1 -0
- package/lib/cjs/storage/type.d.ts +1 -0
- package/lib/dts/index.d.ts +1 -2
- package/lib/dts/storage/migrations/002-add-agent-id.d.ts +2 -0
- package/lib/dts/storage/models/entries.d.ts +19 -0
- package/lib/dts/storage/type.d.ts +1 -0
- package/lib/esm/index.d.ts +1 -2
- package/lib/esm/index.js +5 -6
- package/lib/esm/storage/index.js +1 -1
- package/lib/esm/storage/migrate.js +2 -1
- package/lib/esm/storage/migrations/002-add-agent-id.d.ts +2 -0
- package/lib/esm/storage/migrations/002-add-agent-id.js +10 -0
- package/lib/esm/storage/models/entries.d.ts +19 -0
- package/lib/esm/storage/models/entries.js +1 -0
- package/lib/esm/storage/type.d.ts +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,20 @@
|
|
|
6
6
|
* dependencies
|
|
7
7
|
* @aigne/afs bumped to 1.2.0
|
|
8
8
|
|
|
9
|
+
## [1.2.0-beta.4](https://github.com/AIGNE-io/aigne-framework/compare/afs-history-v1.2.0-beta.3...afs-history-v1.2.0-beta.4) (2025-12-26)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **core:** add session history support ([#858](https://github.com/AIGNE-io/aigne-framework/issues/858)) ([28a070e](https://github.com/AIGNE-io/aigne-framework/commit/28a070ed33b821d1fd344b899706d817ca992b9f))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Dependencies
|
|
18
|
+
|
|
19
|
+
* The following workspace dependencies were updated
|
|
20
|
+
* dependencies
|
|
21
|
+
* @aigne/afs bumped to 1.4.0-beta.4
|
|
22
|
+
|
|
9
23
|
## [1.2.0-beta.3](https://github.com/AIGNE-io/aigne-framework/compare/afs-history-v1.2.0-beta.2...afs-history-v1.2.0-beta.3) (2025-12-24)
|
|
10
24
|
|
|
11
25
|
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot
|
|
1
|
+
import type { AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot } from "@aigne/afs";
|
|
2
2
|
import { SharedAFSStorage, type SharedAFSStorageOptions } from "./storage/index.js";
|
|
3
3
|
export * from "./storage/index.js";
|
|
4
4
|
export interface AFSHistoryOptions {
|
|
@@ -11,5 +11,4 @@ export declare class AFSHistory implements AFSModule {
|
|
|
11
11
|
onMount(afs: AFSRoot): void;
|
|
12
12
|
list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
|
|
13
13
|
read(path: string): Promise<AFSReadResult>;
|
|
14
|
-
write(path: string, content: AFSWriteEntryPayload): Promise<AFSWriteResult>;
|
|
15
14
|
}
|
package/lib/cjs/index.js
CHANGED
|
@@ -29,11 +29,14 @@ class AFSHistory {
|
|
|
29
29
|
storage;
|
|
30
30
|
name = "history";
|
|
31
31
|
onMount(afs) {
|
|
32
|
-
afs.on("agentSucceed", ({ input, output }) => {
|
|
32
|
+
afs.on("agentSucceed", ({ agentId, userId, sessionId, input, output, messages }) => {
|
|
33
33
|
this.storage
|
|
34
34
|
.create({
|
|
35
35
|
path: (0, ufo_1.joinURL)("/", (0, uuid_1.v7)()),
|
|
36
|
-
|
|
36
|
+
agentId,
|
|
37
|
+
userId,
|
|
38
|
+
sessionId,
|
|
39
|
+
content: { input, output, messages },
|
|
37
40
|
})
|
|
38
41
|
.then((entry) => {
|
|
39
42
|
afs.emit("historyCreated", { entry });
|
|
@@ -52,9 +55,5 @@ class AFSHistory {
|
|
|
52
55
|
const data = await this.storage.read(path);
|
|
53
56
|
return { data };
|
|
54
57
|
}
|
|
55
|
-
async write(path, content) {
|
|
56
|
-
const data = await this.storage.create({ ...content, path });
|
|
57
|
-
return { data };
|
|
58
|
-
}
|
|
59
58
|
}
|
|
60
59
|
exports.AFSHistory = AFSHistory;
|
package/lib/cjs/storage/index.js
CHANGED
|
@@ -49,7 +49,7 @@ class AFSStorageWithModule {
|
|
|
49
49
|
const data = await db
|
|
50
50
|
.select()
|
|
51
51
|
.from(table)
|
|
52
|
-
.where((0, sqlite_1.and)(filter?.userId ? (0, sqlite_1.eq)(table.userId, filter.userId) : undefined, filter?.sessionId ? (0, sqlite_1.eq)(table.sessionId, filter.sessionId) : undefined))
|
|
52
|
+
.where((0, sqlite_1.and)(filter?.agentId ? (0, sqlite_1.eq)(table.agentId, filter.agentId) : undefined, filter?.userId ? (0, sqlite_1.eq)(table.userId, filter.userId) : undefined, filter?.sessionId ? (0, sqlite_1.eq)(table.sessionId, filter.sessionId) : undefined))
|
|
53
53
|
.orderBy(...(options.orderBy ?? []).map((item) => (item[1] === "asc" ? sqlite_1.asc : sqlite_1.desc)(sqlite_1.sql.identifier(item[0]))))
|
|
54
54
|
.limit(limit)
|
|
55
55
|
.execute();
|
|
@@ -4,8 +4,9 @@ exports.migrate = migrate;
|
|
|
4
4
|
const sqlite_1 = require("@aigne/sqlite");
|
|
5
5
|
const uuid_1 = require("@aigne/uuid");
|
|
6
6
|
const _001_init_js_1 = require("./migrations/001-init.js");
|
|
7
|
+
const _002_add_agent_id_js_1 = require("./migrations/002-add-agent-id.js");
|
|
7
8
|
async function migrate(db, module) {
|
|
8
|
-
const migrations = [_001_init_js_1.init];
|
|
9
|
+
const migrations = [_001_init_js_1.init, _002_add_agent_id_js_1.addAgentId];
|
|
9
10
|
const migrationsTable = "__drizzle_migrations";
|
|
10
11
|
const migrationTableCreate = (0, sqlite_1.sql) `
|
|
11
12
|
CREATE TABLE IF NOT EXISTS ${sqlite_1.sql.identifier(migrationsTable)} (
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addAgentId = void 0;
|
|
4
|
+
const sqlite_1 = require("@aigne/sqlite");
|
|
5
|
+
const entries_js_1 = require("../models/entries.js");
|
|
6
|
+
exports.addAgentId = {
|
|
7
|
+
hash: "002-add-agent-id",
|
|
8
|
+
sql: (module) => [
|
|
9
|
+
(0, sqlite_1.sql) `\
|
|
10
|
+
ALTER TABLE ${sqlite_1.sql.identifier((0, entries_js_1.entriesTableName)(module))} ADD COLUMN "agentId" TEXT;
|
|
11
|
+
`,
|
|
12
|
+
],
|
|
13
|
+
};
|
|
@@ -80,6 +80,25 @@ export declare const entriesTable: (module: AFSModule) => import("@aigne/sqlite"
|
|
|
80
80
|
}, {}, {
|
|
81
81
|
length: number | undefined;
|
|
82
82
|
}>;
|
|
83
|
+
agentId: import("@aigne/sqlite").SQLiteColumn<{
|
|
84
|
+
name: "agentId";
|
|
85
|
+
tableName: string;
|
|
86
|
+
dataType: "string";
|
|
87
|
+
columnType: "SQLiteText";
|
|
88
|
+
data: string;
|
|
89
|
+
driverParam: string;
|
|
90
|
+
notNull: false;
|
|
91
|
+
hasDefault: false;
|
|
92
|
+
isPrimaryKey: false;
|
|
93
|
+
isAutoincrement: false;
|
|
94
|
+
hasRuntimeDefault: false;
|
|
95
|
+
enumValues: [string, ...string[]];
|
|
96
|
+
baseColumn: never;
|
|
97
|
+
identity: undefined;
|
|
98
|
+
generated: undefined;
|
|
99
|
+
}, {}, {
|
|
100
|
+
length: number | undefined;
|
|
101
|
+
}>;
|
|
83
102
|
userId: import("@aigne/sqlite").SQLiteColumn<{
|
|
84
103
|
name: "userId";
|
|
85
104
|
tableName: string;
|
|
@@ -18,6 +18,7 @@ const entriesTable = (module) => (0, sqlite_1.sqliteTable)((0, exports.entriesTa
|
|
|
18
18
|
.$defaultFn(() => new Date())
|
|
19
19
|
.$onUpdateFn(() => new Date()),
|
|
20
20
|
path: (0, sqlite_1.text)("path").notNull(),
|
|
21
|
+
agentId: (0, sqlite_1.text)("agentId"),
|
|
21
22
|
userId: (0, sqlite_1.text)("userId"),
|
|
22
23
|
sessionId: (0, sqlite_1.text)("sessionId"),
|
|
23
24
|
summary: (0, sqlite_1.text)("summary"),
|
package/lib/dts/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot
|
|
1
|
+
import type { AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot } from "@aigne/afs";
|
|
2
2
|
import { SharedAFSStorage, type SharedAFSStorageOptions } from "./storage/index.js";
|
|
3
3
|
export * from "./storage/index.js";
|
|
4
4
|
export interface AFSHistoryOptions {
|
|
@@ -11,5 +11,4 @@ export declare class AFSHistory implements AFSModule {
|
|
|
11
11
|
onMount(afs: AFSRoot): void;
|
|
12
12
|
list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
|
|
13
13
|
read(path: string): Promise<AFSReadResult>;
|
|
14
|
-
write(path: string, content: AFSWriteEntryPayload): Promise<AFSWriteResult>;
|
|
15
14
|
}
|
|
@@ -80,6 +80,25 @@ export declare const entriesTable: (module: AFSModule) => import("@aigne/sqlite"
|
|
|
80
80
|
}, {}, {
|
|
81
81
|
length: number | undefined;
|
|
82
82
|
}>;
|
|
83
|
+
agentId: import("@aigne/sqlite").SQLiteColumn<{
|
|
84
|
+
name: "agentId";
|
|
85
|
+
tableName: string;
|
|
86
|
+
dataType: "string";
|
|
87
|
+
columnType: "SQLiteText";
|
|
88
|
+
data: string;
|
|
89
|
+
driverParam: string;
|
|
90
|
+
notNull: false;
|
|
91
|
+
hasDefault: false;
|
|
92
|
+
isPrimaryKey: false;
|
|
93
|
+
isAutoincrement: false;
|
|
94
|
+
hasRuntimeDefault: false;
|
|
95
|
+
enumValues: [string, ...string[]];
|
|
96
|
+
baseColumn: never;
|
|
97
|
+
identity: undefined;
|
|
98
|
+
generated: undefined;
|
|
99
|
+
}, {}, {
|
|
100
|
+
length: number | undefined;
|
|
101
|
+
}>;
|
|
83
102
|
userId: import("@aigne/sqlite").SQLiteColumn<{
|
|
84
103
|
name: "userId";
|
|
85
104
|
tableName: string;
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot
|
|
1
|
+
import type { AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot } from "@aigne/afs";
|
|
2
2
|
import { SharedAFSStorage, type SharedAFSStorageOptions } from "./storage/index.js";
|
|
3
3
|
export * from "./storage/index.js";
|
|
4
4
|
export interface AFSHistoryOptions {
|
|
@@ -11,5 +11,4 @@ export declare class AFSHistory implements AFSModule {
|
|
|
11
11
|
onMount(afs: AFSRoot): void;
|
|
12
12
|
list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
|
|
13
13
|
read(path: string): Promise<AFSReadResult>;
|
|
14
|
-
write(path: string, content: AFSWriteEntryPayload): Promise<AFSWriteResult>;
|
|
15
14
|
}
|
package/lib/esm/index.js
CHANGED
|
@@ -12,11 +12,14 @@ export class AFSHistory {
|
|
|
12
12
|
storage;
|
|
13
13
|
name = "history";
|
|
14
14
|
onMount(afs) {
|
|
15
|
-
afs.on("agentSucceed", ({ input, output }) => {
|
|
15
|
+
afs.on("agentSucceed", ({ agentId, userId, sessionId, input, output, messages }) => {
|
|
16
16
|
this.storage
|
|
17
17
|
.create({
|
|
18
18
|
path: joinURL("/", v7()),
|
|
19
|
-
|
|
19
|
+
agentId,
|
|
20
|
+
userId,
|
|
21
|
+
sessionId,
|
|
22
|
+
content: { input, output, messages },
|
|
20
23
|
})
|
|
21
24
|
.then((entry) => {
|
|
22
25
|
afs.emit("historyCreated", { entry });
|
|
@@ -35,8 +38,4 @@ export class AFSHistory {
|
|
|
35
38
|
const data = await this.storage.read(path);
|
|
36
39
|
return { data };
|
|
37
40
|
}
|
|
38
|
-
async write(path, content) {
|
|
39
|
-
const data = await this.storage.create({ ...content, path });
|
|
40
|
-
return { data };
|
|
41
|
-
}
|
|
42
41
|
}
|
package/lib/esm/storage/index.js
CHANGED
|
@@ -31,7 +31,7 @@ export class AFSStorageWithModule {
|
|
|
31
31
|
const data = await db
|
|
32
32
|
.select()
|
|
33
33
|
.from(table)
|
|
34
|
-
.where(and(filter?.userId ? eq(table.userId, filter.userId) : undefined, filter?.sessionId ? eq(table.sessionId, filter.sessionId) : undefined))
|
|
34
|
+
.where(and(filter?.agentId ? eq(table.agentId, filter.agentId) : undefined, filter?.userId ? eq(table.userId, filter.userId) : undefined, filter?.sessionId ? eq(table.sessionId, filter.sessionId) : undefined))
|
|
35
35
|
.orderBy(...(options.orderBy ?? []).map((item) => (item[1] === "asc" ? asc : desc)(sql.identifier(item[0]))))
|
|
36
36
|
.limit(limit)
|
|
37
37
|
.execute();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { sql } from "@aigne/sqlite";
|
|
2
2
|
import { v7 } from "@aigne/uuid";
|
|
3
3
|
import { init } from "./migrations/001-init.js";
|
|
4
|
+
import { addAgentId } from "./migrations/002-add-agent-id.js";
|
|
4
5
|
export async function migrate(db, module) {
|
|
5
|
-
const migrations = [init];
|
|
6
|
+
const migrations = [init, addAgentId];
|
|
6
7
|
const migrationsTable = "__drizzle_migrations";
|
|
7
8
|
const migrationTableCreate = sql `
|
|
8
9
|
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { sql } from "@aigne/sqlite";
|
|
2
|
+
import { entriesTableName } from "../models/entries.js";
|
|
3
|
+
export const addAgentId = {
|
|
4
|
+
hash: "002-add-agent-id",
|
|
5
|
+
sql: (module) => [
|
|
6
|
+
sql `\
|
|
7
|
+
ALTER TABLE ${sql.identifier(entriesTableName(module))} ADD COLUMN "agentId" TEXT;
|
|
8
|
+
`,
|
|
9
|
+
],
|
|
10
|
+
};
|
|
@@ -80,6 +80,25 @@ export declare const entriesTable: (module: AFSModule) => import("@aigne/sqlite"
|
|
|
80
80
|
}, {}, {
|
|
81
81
|
length: number | undefined;
|
|
82
82
|
}>;
|
|
83
|
+
agentId: import("@aigne/sqlite").SQLiteColumn<{
|
|
84
|
+
name: "agentId";
|
|
85
|
+
tableName: string;
|
|
86
|
+
dataType: "string";
|
|
87
|
+
columnType: "SQLiteText";
|
|
88
|
+
data: string;
|
|
89
|
+
driverParam: string;
|
|
90
|
+
notNull: false;
|
|
91
|
+
hasDefault: false;
|
|
92
|
+
isPrimaryKey: false;
|
|
93
|
+
isAutoincrement: false;
|
|
94
|
+
hasRuntimeDefault: false;
|
|
95
|
+
enumValues: [string, ...string[]];
|
|
96
|
+
baseColumn: never;
|
|
97
|
+
identity: undefined;
|
|
98
|
+
generated: undefined;
|
|
99
|
+
}, {}, {
|
|
100
|
+
length: number | undefined;
|
|
101
|
+
}>;
|
|
83
102
|
userId: import("@aigne/sqlite").SQLiteColumn<{
|
|
84
103
|
name: "userId";
|
|
85
104
|
tableName: string;
|
|
@@ -14,6 +14,7 @@ export const entriesTable = (module) => sqliteTable(entriesTableName(module), {
|
|
|
14
14
|
.$defaultFn(() => new Date())
|
|
15
15
|
.$onUpdateFn(() => new Date()),
|
|
16
16
|
path: text("path").notNull(),
|
|
17
|
+
agentId: text("agentId"),
|
|
17
18
|
userId: text("userId"),
|
|
18
19
|
sessionId: text("sessionId"),
|
|
19
20
|
summary: text("summary"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/afs-history",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.4",
|
|
4
4
|
"description": "AIGNE AFS module for managing chat history",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@aigne/uuid": "^13.0.1",
|
|
51
51
|
"ufo": "^1.6.1",
|
|
52
|
-
"@aigne/
|
|
53
|
-
"@aigne/
|
|
52
|
+
"@aigne/afs": "^1.4.0-beta.4",
|
|
53
|
+
"@aigne/sqlite": "^0.4.9-beta"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/bun": "^1.2.22",
|