@ppagent/memory 0.1.0 → 0.1.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/dist/index.d.ts +86 -19
- package/dist/index.js +292 -211
- package/package.json +49 -50
- package/llms.txt +0 -845
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,27 @@ type MessageType = "text" | "image" | "file";
|
|
|
2
2
|
type FactLevel = "user" | "chat";
|
|
3
3
|
type SearchMode = "fast" | "auto" | "all";
|
|
4
4
|
type SearchScope = "session" | "chat" | "user" | "all";
|
|
5
|
+
/**
|
|
6
|
+
* 分页参数(可选)。
|
|
7
|
+
* - offset:起始偏移,从 0 开始(负数按 0 处理)。
|
|
8
|
+
* - limit:本页最大条数;省略或 <=0 表示「从 offset 起取全部」。
|
|
9
|
+
*/
|
|
10
|
+
interface PageParams {
|
|
11
|
+
offset?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 分页结果信封。仅当调用方传入 PageParams 时返回;不传则保持返回纯数组(向后兼容)。
|
|
16
|
+
* - items:当前页数据。
|
|
17
|
+
* - total:过滤后、分页前的总条数(供前端计算总页数)。
|
|
18
|
+
* - offset / limit:实际生效的分页参数(limit 为 0 表示未限制)。
|
|
19
|
+
*/
|
|
20
|
+
interface Paginated<T> {
|
|
21
|
+
items: T[];
|
|
22
|
+
total: number;
|
|
23
|
+
offset: number;
|
|
24
|
+
limit: number;
|
|
25
|
+
}
|
|
5
26
|
/**
|
|
6
27
|
* 多模态消息的单个内容块,与 OpenAI content part 对齐
|
|
7
28
|
*/
|
|
@@ -249,10 +270,8 @@ interface AddDocumentOptions {
|
|
|
249
270
|
metadata?: Record<string, unknown>;
|
|
250
271
|
/** 默认取 config.buildGraphDefault(默认 "auto")*/
|
|
251
272
|
buildGraph?: BuildGraphMode;
|
|
252
|
-
/** 默认 false:document 落库即返回;true
|
|
273
|
+
/** 默认 false:document 落库即返回;true 则等切块/图谱全部完成 */
|
|
253
274
|
wait?: boolean;
|
|
254
|
-
/** 默认 false:true 时在 wait 的基础上额外等待知识图谱构建完成 */
|
|
255
|
-
waitGraph?: boolean;
|
|
256
275
|
}
|
|
257
276
|
interface KnowledgeSearchOptions {
|
|
258
277
|
query: string;
|
|
@@ -299,8 +318,6 @@ interface MemoryConfig {
|
|
|
299
318
|
httpMaxRetries?: number;
|
|
300
319
|
/** embedding 单次请求最多包含的文本条数,超出自动分批(默认 20)。*/
|
|
301
320
|
embeddingBatchSize?: number;
|
|
302
|
-
/** embedding 批次并发数(默认 2)。*/
|
|
303
|
-
embeddingConcurrency?: number;
|
|
304
321
|
sessionTokenLimit?: number;
|
|
305
322
|
historyWindowTokenLimit?: number;
|
|
306
323
|
topicRatio?: [number, number, number];
|
|
@@ -341,10 +358,6 @@ interface MemoryConfig {
|
|
|
341
358
|
knowledgeGraphAnchorTopK?: number;
|
|
342
359
|
/** 每个锚点实体一跳扩展的最大关系数(默认 10)*/
|
|
343
360
|
knowledgeGraphHopLimit?: number;
|
|
344
|
-
/** 文档图谱构建时并发抽取片段数(默认 2)*/
|
|
345
|
-
graphExtractConcurrency?: number;
|
|
346
|
-
/** waitGraph=true 时等待图谱构建的整体超时(毫秒,默认 120000)*/
|
|
347
|
-
graphBuildTimeoutMs?: number;
|
|
348
361
|
}
|
|
349
362
|
interface ResolvedConfig extends Required<MemoryConfig> {
|
|
350
363
|
}
|
|
@@ -366,7 +379,6 @@ declare class MemoryManager {
|
|
|
366
379
|
updateChat(messages: RawMessage[], opts?: UpdateChatOptions): Promise<void>;
|
|
367
380
|
flushChat(sessionId?: string, opts?: {
|
|
368
381
|
wait?: boolean;
|
|
369
|
-
waitGraph?: boolean;
|
|
370
382
|
}): Promise<void>;
|
|
371
383
|
updateFacts(content: string, level: FactLevel, userId: string, chatId: string, sessionId?: string): Promise<void>;
|
|
372
384
|
updateEntity(entities: Entity[], relations: Relation[], context?: UpdateEntityOptions): Promise<void>;
|
|
@@ -417,19 +429,39 @@ declare class MemoryManager {
|
|
|
417
429
|
messages: number;
|
|
418
430
|
facts: number;
|
|
419
431
|
}[]>;
|
|
420
|
-
/**
|
|
432
|
+
/**
|
|
433
|
+
* 列出会话,可选按 userId / chatId 过滤,按更新时间倒序。
|
|
434
|
+
* 传入 page 时返回分页信封 {items,total,offset,limit},不传则返回全量数组(向后兼容)。
|
|
435
|
+
*/
|
|
421
436
|
listSessions(filter?: {
|
|
422
437
|
userId?: string;
|
|
423
438
|
chatId?: string;
|
|
424
439
|
}): SessionView[];
|
|
425
|
-
|
|
440
|
+
listSessions(filter: {
|
|
441
|
+
userId?: string;
|
|
442
|
+
chatId?: string;
|
|
443
|
+
} | undefined, page: PageParams): Paginated<SessionView>;
|
|
444
|
+
/**
|
|
445
|
+
* 列出会话内的消息(按时间正序)。
|
|
446
|
+
* 传入 page 时返回分页信封(offset/limit 基于全量消息切片);
|
|
447
|
+
* 仅传 limit(number)时保持旧行为:返回最新 limit 条。
|
|
448
|
+
*/
|
|
426
449
|
listMessages(sessionId: string, limit?: number): Promise<StoredMessage[]>;
|
|
427
|
-
|
|
450
|
+
listMessages(sessionId: string, page: PageParams): Promise<Paginated<StoredMessage>>;
|
|
451
|
+
/**
|
|
452
|
+
* 列出主题/摘要,可选按 sessionId / userId / chatId 过滤。
|
|
453
|
+
* 传入 page 时返回分页信封,不传则返回全量数组(向后兼容)。
|
|
454
|
+
*/
|
|
428
455
|
listTopics(filter?: {
|
|
429
456
|
sessionId?: string;
|
|
430
457
|
userId?: string;
|
|
431
458
|
chatId?: string;
|
|
432
459
|
}): Promise<Topic[]>;
|
|
460
|
+
listTopics(filter: {
|
|
461
|
+
sessionId?: string;
|
|
462
|
+
userId?: string;
|
|
463
|
+
chatId?: string;
|
|
464
|
+
} | undefined, page: PageParams): Promise<Paginated<Topic>>;
|
|
433
465
|
/**
|
|
434
466
|
* 列出事实,按创建时间倒序。过滤遵循 scope 层级包含语义:
|
|
435
467
|
* - 按 chatId 过滤时,除该 chat 级 facts 外,还包含该 chat 所属 user 的 user 级 facts
|
|
@@ -442,16 +474,41 @@ declare class MemoryManager {
|
|
|
442
474
|
userId?: string;
|
|
443
475
|
chatId?: string;
|
|
444
476
|
}): Fact[];
|
|
477
|
+
listFacts(filter: {
|
|
478
|
+
level?: FactLevel;
|
|
479
|
+
userId?: string;
|
|
480
|
+
chatId?: string;
|
|
481
|
+
} | undefined, page: PageParams): Paginated<Fact>;
|
|
445
482
|
/** 由 chatId 反查所属 userId:优先用会话表映射,兜底用 chat 级 fact 自身。 */
|
|
446
483
|
private resolveChatOwner;
|
|
447
484
|
/** 手动新增一条事实 */
|
|
448
485
|
addFact(content: string, level: FactLevel, userId: string, chatId: string, sessionId?: string): Promise<void>;
|
|
449
486
|
/** 删除单条事实,返回是否命中 */
|
|
450
487
|
deleteFact(factId: string): Promise<boolean>;
|
|
451
|
-
/**
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
488
|
+
/**
|
|
489
|
+
* 列出实体(知识图谱节点),可选按 userId / chatId 过滤。
|
|
490
|
+
* 传入 page 时返回分页信封,不传则返回数组(向后兼容)。
|
|
491
|
+
*/
|
|
492
|
+
listEntities(filter?: {
|
|
493
|
+
userId?: string;
|
|
494
|
+
chatId?: string;
|
|
495
|
+
}): Promise<Entity[]>;
|
|
496
|
+
listEntities(filter: {
|
|
497
|
+
userId?: string;
|
|
498
|
+
chatId?: string;
|
|
499
|
+
} | undefined, page: PageParams): Promise<Paginated<Entity>>;
|
|
500
|
+
/**
|
|
501
|
+
* 列出关系(知识图谱边),可选按 userId / chatId 过滤。
|
|
502
|
+
* 传入 page 时返回分页信封,不传则返回数组(向后兼容)。
|
|
503
|
+
*/
|
|
504
|
+
listRelations(filter?: {
|
|
505
|
+
userId?: string;
|
|
506
|
+
chatId?: string;
|
|
507
|
+
}): Promise<Relation[]>;
|
|
508
|
+
listRelations(filter: {
|
|
509
|
+
userId?: string;
|
|
510
|
+
chatId?: string;
|
|
511
|
+
} | undefined, page: PageParams): Promise<Paginated<Relation>>;
|
|
455
512
|
/** 摄入一个文档(markdown)。document 落库即返回,切块/embedding/图谱后台执行(wait=true 可等待)。*/
|
|
456
513
|
addDocument(opts: AddDocumentOptions): Promise<{
|
|
457
514
|
docId: string;
|
|
@@ -462,12 +519,20 @@ declare class MemoryManager {
|
|
|
462
519
|
getDocument(docId: string): Promise<Document | null>;
|
|
463
520
|
/** 删除文档(级联删除其片段与知识图谱痕迹),返回是否命中。*/
|
|
464
521
|
deleteDocument(docId: string): Promise<boolean>;
|
|
465
|
-
/**
|
|
522
|
+
/**
|
|
523
|
+
* 列出文档,可选按 userId / chatId / sessionId 过滤,按更新时间倒序。
|
|
524
|
+
* 传入 page 时返回分页信封,不传则返回数组(向后兼容)。
|
|
525
|
+
*/
|
|
466
526
|
listDocuments(filter?: {
|
|
467
527
|
userId?: string;
|
|
468
528
|
chatId?: string;
|
|
469
529
|
sessionId?: string;
|
|
470
530
|
}): Promise<Document[]>;
|
|
531
|
+
listDocuments(filter: {
|
|
532
|
+
userId?: string;
|
|
533
|
+
chatId?: string;
|
|
534
|
+
sessionId?: string;
|
|
535
|
+
} | undefined, page: PageParams): Promise<Paginated<Document>>;
|
|
471
536
|
destroy(): void;
|
|
472
537
|
}
|
|
473
538
|
|
|
@@ -508,6 +573,8 @@ declare class LanceService {
|
|
|
508
573
|
}>;
|
|
509
574
|
getMessagesSince(sessionId: string, since: number, limit?: number): Promise<StoredMessage[]>;
|
|
510
575
|
getLatestMessages(sessionId: string, limit: number): Promise<StoredMessage[]>;
|
|
576
|
+
/** 取某会话的全部消息(按 createdAt 升序),供管理面板分页切片使用 */
|
|
577
|
+
getAllMessagesBySession(sessionId: string): Promise<StoredMessage[]>;
|
|
511
578
|
searchMessages(vector: number[], filter?: string, limit?: number): Promise<Array<StoredMessage & {
|
|
512
579
|
_distance: number;
|
|
513
580
|
}>>;
|
|
@@ -591,4 +658,4 @@ type RelationType = (typeof DEFAULT_RELATION_TYPES)[number];
|
|
|
591
658
|
declare const KIND_CONVERSATION = "conversation";
|
|
592
659
|
declare const KIND_KNOWLEDGE = "knowledge";
|
|
593
660
|
|
|
594
|
-
export { type AddDocumentOptions, type BuildGraphMode, type Chunk, type ChunkHit, type ChunkPiece, type CompressOutput, type ContentPart, DEFAULT_NODE_TYPES, DEFAULT_RELATION_TYPES, type Document, type DomainIds, type Entity, type EntityMeta, type Fact, type FactLevel, KIND_CONVERSATION, KIND_KNOWLEDGE, type KnowledgeSearchOptions, type KnowledgeSearchResult, LanceService, type MemoryConfig, MemoryManager, type MessageType, type NodeType, type RawMessage, type Relation, type RelationType, type SearchMode, type SearchOptions, type SearchResult, type SearchScope, type Session, type SessionEntry, type SessionSearchOptions, type SessionView, type StoredMessage, type Topic, type UpdateChatOptions, type UpdateEntityOptions, type UpdateSessionOptions };
|
|
661
|
+
export { type AddDocumentOptions, type BuildGraphMode, type Chunk, type ChunkHit, type ChunkPiece, type CompressOutput, type ContentPart, DEFAULT_NODE_TYPES, DEFAULT_RELATION_TYPES, type Document, type DomainIds, type Entity, type EntityMeta, type Fact, type FactLevel, KIND_CONVERSATION, KIND_KNOWLEDGE, type KnowledgeSearchOptions, type KnowledgeSearchResult, LanceService, type MemoryConfig, MemoryManager, type MessageType, type NodeType, type PageParams, type Paginated, type RawMessage, type Relation, type RelationType, type SearchMode, type SearchOptions, type SearchResult, type SearchScope, type Session, type SessionEntry, type SessionSearchOptions, type SessionView, type StoredMessage, type Topic, type UpdateChatOptions, type UpdateEntityOptions, type UpdateSessionOptions };
|