Skip to content

Commit ee6bf77

Browse files
committed
feat(memory): add base types
1 parent 3bf76d3 commit ee6bf77

File tree

9 files changed

+108
-43
lines changed

9 files changed

+108
-43
lines changed

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,42 @@
1818
"test:c8": "shx rm -rf coverage && c8 yarn test"
1919
},
2020
"devDependencies": {
21-
"@langchain/core": "^0.1.25",
21+
"@langchain/core": "^0.1.30",
2222
"@types/chai": "^4.3.11",
2323
"@types/chai-as-promised": "^7.1.8",
2424
"@types/mocha": "^10.0.6",
25-
"@types/node": "^20.11.17",
25+
"@types/node": "^20.11.19",
2626
"@typescript-eslint/eslint-plugin": "^6.21.0",
2727
"@typescript-eslint/parser": "^6.21.0",
2828
"c8": "^9.1.0",
29-
"chai": "^5.0.3",
29+
"chai": "^5.1.0",
3030
"chai-as-promised": "^7.1.1",
3131
"cross-env": "^7.0.3",
32-
"esbuild": "^0.20.0",
32+
"esbuild": "^0.20.1",
3333
"eslint": "^8.56.0",
3434
"eslint-config-prettier": "^9.1.0",
3535
"eslint-config-standard": "^17.1.0",
3636
"eslint-plugin-import": "^2.29.1",
37-
"eslint-plugin-mocha": "^10.2.0",
37+
"eslint-plugin-mocha": "^10.3.0",
3838
"eslint-plugin-n": "^16.6.2",
3939
"eslint-plugin-prettier": "^5.1.3",
4040
"eslint-plugin-promise": "^6.1.1",
4141
"faiss-node": "^0.5.1",
4242
"fetch-socks": "^1.2.0",
43-
"https-proxy-agent": "^7.0.2",
43+
"https-proxy-agent": "^7.0.4",
4444
"js-tiktoken": "^1.0.10",
4545
"js-yaml": "^4.1.0",
4646
"mocha": "^10.3.0",
4747
"prettier": "^3.2.5",
4848
"shx": "^0.3.4",
4949
"socks-proxy-agent": "^8.0.2",
50-
"tsx": "^4.7.0",
50+
"tsx": "^4.7.1",
5151
"typescript": "^5.3.3",
5252
"undici": "^6.6.2",
5353
"uuid": "^9.0.1",
5454
"ws": "^8.16.0",
55-
"yakumo": "^1.0.0-beta.6",
56-
"yakumo-esbuild": "^1.0.0-beta.2",
55+
"yakumo": "^1.0.0-beta.7",
56+
"yakumo-esbuild": "^1.0.0-beta.4",
5757
"yakumo-mocha": "^1.0.0-beta.2",
5858
"yakumo-tsc": "^1.0.0-beta.3",
5959
"zod": "^3.22.4",

packages/core/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@
9494
"chatluna"
9595
],
9696
"dependencies": {
97-
"@cordisjs/core": "^3.9.2",
98-
"@cordisjs/logger": "^0.2.0",
99-
"@langchain/core": "^0.1.25",
97+
"@cordisjs/core": "^3.11.0",
98+
"@cordisjs/logger": "^0.3.1",
99+
"@langchain/core": "^0.1.30",
100100
"fetch-socks": "^1.2.0",
101-
"https-proxy-agent": "^7.0.2",
101+
"https-proxy-agent": "^7.0.4",
102102
"js-tiktoken": "^1.0.10",
103103
"js-yaml": "^4.1.0",
104104
"ml-distance": "^4.0.1",
105105
"socks-proxy-agent": "^8.0.2",
106106
"undici": "^6.6.2",
107-
"user-agents": "^2.0.0-alpha.107",
107+
"user-agents": "^2.0.0-alpha.118",
108108
"useragent": "^2.3.0",
109109
"ws": "^8.16.0",
110110
"zod": "^3.22.4",
@@ -115,4 +115,4 @@
115115
"@types/useragent": "^2",
116116
"proxy": "^2.1.1"
117117
}
118-
}
118+
}

packages/core/src/platform/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export interface ModelInfo {
7070
maxTokens?: number
7171

7272
functionCall?: boolean
73+
74+
costPerToken?: number
7375
}
7476

7577
export interface CreateVectorStoreParams {

packages/core/src/service/platform.ts

+7-17
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class PlatformService extends Service {
6666

6767
const disposable = () => this._unregisterClient(platform)
6868

69-
return this[Context.current].effect(() => disposable)
69+
return this[Context.trace].effect(() => disposable)
7070
}
7171

7272
registerConfigs(
@@ -103,7 +103,7 @@ export class PlatformService extends Service {
103103

104104
const disposable = () => this._unregisterTool(name)
105105

106-
return this[Context.current].effect(() => disposable)
106+
return this[Context.trace].effect(() => disposable)
107107
}
108108

109109
private _unregisterTool(name: string) {
@@ -168,7 +168,7 @@ export class PlatformService extends Service {
168168
this._vectorStore[name] = vectorStoreCreator
169169
this.ctx.emit('chatluna/vector-store-added', this, name)
170170
const disposable = () => this._unregisterVectorStore(name)
171-
return this[Context.current].effect(() => disposable)
171+
return this[Context.trace].effect(() => disposable)
172172
}
173173

174174
async registerChatChain(
@@ -185,7 +185,7 @@ export class PlatformService extends Service {
185185
}
186186
this.ctx.emit('chatluna/chat-chain-added', this, this._chatChains[name])
187187
const disposable = () => this._unregisterChatChain(name)
188-
return this[Context.current].effect(() => disposable)
188+
return this[Context.trace].effect(() => disposable)
189189
}
190190

191191
private _unregisterChatChain(name: string) {
@@ -221,19 +221,9 @@ export class PlatformService extends Service {
221221
}
222222

223223
getAllModels(type: ModelType) {
224-
const allModel: ModelInfo[] = []
225-
226-
for (const platform in this._models) {
227-
const models = this._models[platform]
228-
229-
for (const model of models) {
230-
if (type === ModelType.all || model.type === type) {
231-
allModel.push(model)
232-
}
233-
}
234-
}
235-
236-
return allModel
224+
return Object.values(this._models)
225+
.flatMap((f) => f)
226+
.filter((m) => m.type === ModelType.all || m.type === type)
237227
}
238228

239229
get vectorStores() {

packages/memory/package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
"import": "./lib/index.mjs",
1616
"types": "./lib/index.d.ts"
1717
},
18-
18+
"./types": {
19+
"require": "./lib/types/index.cjs",
20+
"import": "./lib/types/index.mjs",
21+
"types": "./lib/types/index.d.ts"
22+
},
1923
"./package.json": "./package.json"
2024
},
2125
"engines": {
@@ -45,13 +49,9 @@
4549
"chatluna"
4650
],
4751
"dependencies": {
48-
"@cordisjs/core": "^3.9.2",
49-
"@cordisjs/logger": "^0.2.0",
50-
"minato": "^3.0.0-alpha.0"
51-
},
52-
"devDependencies": {
53-
"@types/js-yaml": "^4.0.9",
54-
"@types/useragent": "^2",
55-
"proxy": "^2.1.1"
52+
"@cordisjs/core": "^3.11.0",
53+
"@cordisjs/logger": "^0.3.1",
54+
"minato": "^3.0.0-alpha.0",
55+
"@langchain/core": "^0.1.30"
5656
}
57-
}
57+
}

packages/memory/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import { Context } from '@cordisjs/core'
1+
22

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { MessageContent, MessageType } from '@langchain/core/messages'
2+
3+
export interface ChatLunaMessage {
4+
content: MessageContent
5+
6+
conversationId?: string
7+
8+
role: ChatLunaMessageRole
9+
10+
name?: string
11+
12+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13+
additional_kwargs?: Record<string, any>
14+
15+
parentId?: string
16+
17+
id: string
18+
}
19+
20+
export interface ChatLunaConversation {
21+
id: string
22+
latestMessageId?: string
23+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24+
additional_kwargs?: Record<string, any>
25+
26+
preset: string
27+
model: string
28+
chatMode: string
29+
30+
createdTime: number
31+
lastUpdatedTime: number
32+
}
33+
34+
export interface ChatLunaUser {
35+
userId: string
36+
defaultConversationId?: string
37+
38+
muteConversations: string[]
39+
ownerConversations: string[]
40+
joinedConversations: string[]
41+
42+
excludeModels?: string[]
43+
userGroupId?: string[]
44+
45+
balance?: number
46+
47+
// userGroup or chat limit
48+
chatTimeLimitPerMin?: number
49+
lastChatTime?: number
50+
}
51+
52+
export type ChatLunaMessageRole = MessageType

packages/memory/src/types/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './conversation.ts'
2+
export * from './user_group.ts'
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface ChatLunaUserGroup {
2+
name: string
3+
4+
id: number
5+
limitPerMin: number
6+
limitPerDay: number
7+
8+
costPerToken: number
9+
10+
supportModels: string[]
11+
}
12+
13+
export interface ChatLunaJoinedUserGroup {
14+
userId: string
15+
16+
lastLimitPerMin: number
17+
18+
lastLimitPerDay: number
19+
}

0 commit comments

Comments
 (0)