@farukada/aws-langgraph-dynamodb-ts 0.0.7 → 0.0.9
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/README.md +195 -744
- package/dist/checkpointer/actions/get-tuple.d.ts.map +1 -1
- package/dist/checkpointer/actions/get-tuple.js.map +1 -1
- package/dist/checkpointer/actions/put.d.ts.map +1 -1
- package/dist/checkpointer/actions/put.js.map +1 -1
- package/dist/checkpointer/index.d.ts +3 -3
- package/dist/checkpointer/index.d.ts.map +1 -1
- package/dist/checkpointer/index.js +4 -4
- package/dist/checkpointer/index.js.map +1 -1
- package/dist/checkpointer/utils/validation.d.ts.map +1 -1
- package/dist/checkpointer/utils/validation.js +1 -0
- package/dist/checkpointer/utils/validation.js.map +1 -1
- package/dist/history/actions/add-message.d.ts +13 -0
- package/dist/history/actions/add-message.d.ts.map +1 -0
- package/dist/history/actions/add-message.js +64 -0
- package/dist/history/actions/add-message.js.map +1 -0
- package/dist/history/actions/add-messages.d.ts +14 -0
- package/dist/history/actions/add-messages.d.ts.map +1 -0
- package/dist/history/actions/add-messages.js +65 -0
- package/dist/history/actions/add-messages.js.map +1 -0
- package/dist/history/actions/clear.d.ts +13 -0
- package/dist/history/actions/clear.d.ts.map +1 -0
- package/dist/history/actions/clear.js +32 -0
- package/dist/history/actions/clear.js.map +1 -0
- package/dist/history/actions/get-messages.d.ts +15 -0
- package/dist/history/actions/get-messages.d.ts.map +1 -0
- package/dist/history/actions/get-messages.js +40 -0
- package/dist/history/actions/get-messages.js.map +1 -0
- package/dist/history/actions/index.d.ts +9 -0
- package/dist/history/actions/index.d.ts.map +1 -0
- package/dist/history/actions/index.js +17 -0
- package/dist/history/actions/index.js.map +1 -0
- package/dist/history/actions/list-sessions.d.ts +14 -0
- package/dist/history/actions/list-sessions.d.ts.map +1 -0
- package/dist/history/actions/list-sessions.js +56 -0
- package/dist/history/actions/list-sessions.js.map +1 -0
- package/dist/history/index.d.ts +74 -0
- package/dist/history/index.d.ts.map +1 -0
- package/dist/history/index.js +125 -0
- package/dist/history/index.js.map +1 -0
- package/dist/history/types/index.d.ts +131 -0
- package/dist/history/types/index.d.ts.map +1 -0
- package/dist/history/types/index.js +6 -0
- package/dist/history/types/index.js.map +1 -0
- package/dist/history/utils/index.d.ts +7 -0
- package/dist/history/utils/index.d.ts.map +1 -0
- package/dist/history/utils/index.js +25 -0
- package/dist/history/utils/index.js.map +1 -0
- package/dist/history/utils/title-generator.d.ts +12 -0
- package/dist/history/utils/title-generator.d.ts.map +1 -0
- package/dist/history/utils/title-generator.js +52 -0
- package/dist/history/utils/title-generator.js.map +1 -0
- package/dist/history/utils/validation.d.ts +60 -0
- package/dist/history/utils/validation.d.ts.map +1 -0
- package/dist/history/utils/validation.js +171 -0
- package/dist/history/utils/validation.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/shared/utils/retry.d.ts.map +1 -1
- package/dist/shared/utils/retry.js +2 -0
- package/dist/shared/utils/retry.js.map +1 -1
- package/dist/store/actions/get-operation.d.ts.map +1 -1
- package/dist/store/actions/get-operation.js.map +1 -1
- package/dist/store/actions/list-namespaces-operation.d.ts.map +1 -1
- package/dist/store/actions/list-namespaces-operation.js.map +1 -1
- package/dist/store/actions/put-operation.d.ts.map +1 -1
- package/dist/store/actions/put-operation.js.map +1 -1
- package/dist/store/actions/search-operation.d.ts.map +1 -1
- package/dist/store/actions/search-operation.js.map +1 -1
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +4 -4
- package/dist/store/index.js.map +1 -1
- package/dist/store/utils/validation.d.ts +1 -1
- package/dist/store/utils/validation.d.ts.map +1 -1
- package/dist/store/utils/validation.js +2 -1
- package/dist/store/utils/validation.js.map +1 -1
- package/package.json +10 -8
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DynamoDB-based chat message history implementation for LangChain
|
|
3
|
+
* Provides persistent storage for chat messages with automatic title generation
|
|
4
|
+
*/
|
|
5
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
6
|
+
import type { DynamoDBChatMessageHistoryOptions, SessionMetadata } from './types';
|
|
7
|
+
export declare class DynamoDBChatMessageHistory {
|
|
8
|
+
private readonly ddbClient;
|
|
9
|
+
private readonly client;
|
|
10
|
+
private readonly tableName;
|
|
11
|
+
private readonly ttlDays?;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new DynamoDB chat message history instance
|
|
14
|
+
*
|
|
15
|
+
* @param options - Configuration options for the chat message history
|
|
16
|
+
* @param options.tableName - Name of the DynamoDB table to use
|
|
17
|
+
* @param options.ttlDays - Optional TTL in days for automatic cleanup (1-1825 days)
|
|
18
|
+
* @param options.clientConfig - Optional DynamoDB client configuration
|
|
19
|
+
*/
|
|
20
|
+
constructor(options: DynamoDBChatMessageHistoryOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Get all messages for a session
|
|
23
|
+
* Messages are returned in chronological order
|
|
24
|
+
*
|
|
25
|
+
* @param userId - User identifier
|
|
26
|
+
* @param sessionId - Session identifier
|
|
27
|
+
* @returns Array of BaseMessage objects in chronological order
|
|
28
|
+
* @throws Error if the operation fails or validation fails
|
|
29
|
+
*/
|
|
30
|
+
getMessages(userId: string, sessionId: string): Promise<BaseMessage[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Add a single message to a session
|
|
33
|
+
* Generates title from the first message if this is a new session
|
|
34
|
+
*
|
|
35
|
+
* @param userId - User identifier
|
|
36
|
+
* @param sessionId - Session identifier
|
|
37
|
+
* @param message - The BaseMessage to add to the session
|
|
38
|
+
* @param title - Optional session title (auto-generated from the first message if not provided)
|
|
39
|
+
* @throws Error if the operation fails or validation fails
|
|
40
|
+
*/
|
|
41
|
+
addMessage(userId: string, sessionId: string, message: BaseMessage, title?: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Add multiple messages to a session
|
|
44
|
+
* Generates title from the first message if this is a new session
|
|
45
|
+
* Preferred over calling addMessage multiple times for performance
|
|
46
|
+
*
|
|
47
|
+
* @param userId - User identifier
|
|
48
|
+
* @param sessionId - Session identifier
|
|
49
|
+
* @param messages - Array of BaseMessage objects to add
|
|
50
|
+
* @param title - Optional session title (auto-generated from the first message if not provided)
|
|
51
|
+
* @throws Error if the operation fails or validation fails
|
|
52
|
+
*/
|
|
53
|
+
addMessages(userId: string, sessionId: string, messages: BaseMessage[], title?: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Clear all messages in a session
|
|
56
|
+
* Deletes the session item from DynamoDB
|
|
57
|
+
*
|
|
58
|
+
* @param userId - User identifier
|
|
59
|
+
* @param sessionId - Session identifier
|
|
60
|
+
* @throws Error if the operation fails or validation fails
|
|
61
|
+
*/
|
|
62
|
+
clear(userId: string, sessionId: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* List all sessions for a user, sorted by most recent
|
|
65
|
+
* Returns metadata only (excludes messages for performance)
|
|
66
|
+
*
|
|
67
|
+
* @param userId - User ID to list sessions for
|
|
68
|
+
* @param limit - Optional maximum number of sessions to return (default: no limit)
|
|
69
|
+
* @returns Array of session metadata, sorted by most recent first
|
|
70
|
+
* @throws Error if the operation fails or validation fails
|
|
71
|
+
*/
|
|
72
|
+
listSessions(userId: string, limit?: number): Promise<SessionMetadata[]>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,KAAK,EAAE,iCAAiC,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AASlF,qBAAa,0BAA0B;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAS;IAElC;;;;;;;OAOG;gBACS,OAAO,EAAE,iCAAiC;IAOtD;;;;;;;;OAQG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAS5E;;;;;;;;;OASG;IACG,UAAU,CACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;;;;OAUG;IACG,WAAW,CACf,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;OAOG;IACG,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7D;;;;;;;;OAQG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;CAQ/E"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DynamoDB-based chat message history implementation for LangChain
|
|
4
|
+
* Provides persistent storage for chat messages with automatic title generation
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DynamoDBChatMessageHistory = void 0;
|
|
8
|
+
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
9
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
10
|
+
const actions_1 = require("./actions");
|
|
11
|
+
class DynamoDBChatMessageHistory {
|
|
12
|
+
ddbClient;
|
|
13
|
+
client;
|
|
14
|
+
tableName;
|
|
15
|
+
ttlDays;
|
|
16
|
+
/**
|
|
17
|
+
* Create a new DynamoDB chat message history instance
|
|
18
|
+
*
|
|
19
|
+
* @param options - Configuration options for the chat message history
|
|
20
|
+
* @param options.tableName - Name of the DynamoDB table to use
|
|
21
|
+
* @param options.ttlDays - Optional TTL in days for automatic cleanup (1-1825 days)
|
|
22
|
+
* @param options.clientConfig - Optional DynamoDB client configuration
|
|
23
|
+
*/
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.ddbClient = new client_dynamodb_1.DynamoDBClient(options.clientConfig || {});
|
|
26
|
+
this.client = lib_dynamodb_1.DynamoDBDocument.from(this.ddbClient);
|
|
27
|
+
this.tableName = options.tableName;
|
|
28
|
+
this.ttlDays = options.ttlDays;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get all messages for a session
|
|
32
|
+
* Messages are returned in chronological order
|
|
33
|
+
*
|
|
34
|
+
* @param userId - User identifier
|
|
35
|
+
* @param sessionId - Session identifier
|
|
36
|
+
* @returns Array of BaseMessage objects in chronological order
|
|
37
|
+
* @throws Error if the operation fails or validation fails
|
|
38
|
+
*/
|
|
39
|
+
async getMessages(userId, sessionId) {
|
|
40
|
+
return await (0, actions_1.getMessagesAction)({
|
|
41
|
+
client: this.client,
|
|
42
|
+
tableName: this.tableName,
|
|
43
|
+
userId,
|
|
44
|
+
sessionId,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Add a single message to a session
|
|
49
|
+
* Generates title from the first message if this is a new session
|
|
50
|
+
*
|
|
51
|
+
* @param userId - User identifier
|
|
52
|
+
* @param sessionId - Session identifier
|
|
53
|
+
* @param message - The BaseMessage to add to the session
|
|
54
|
+
* @param title - Optional session title (auto-generated from the first message if not provided)
|
|
55
|
+
* @throws Error if the operation fails or validation fails
|
|
56
|
+
*/
|
|
57
|
+
async addMessage(userId, sessionId, message, title) {
|
|
58
|
+
await (0, actions_1.addMessageAction)({
|
|
59
|
+
client: this.client,
|
|
60
|
+
tableName: this.tableName,
|
|
61
|
+
userId,
|
|
62
|
+
sessionId,
|
|
63
|
+
message,
|
|
64
|
+
title,
|
|
65
|
+
ttlDays: this.ttlDays,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Add multiple messages to a session
|
|
70
|
+
* Generates title from the first message if this is a new session
|
|
71
|
+
* Preferred over calling addMessage multiple times for performance
|
|
72
|
+
*
|
|
73
|
+
* @param userId - User identifier
|
|
74
|
+
* @param sessionId - Session identifier
|
|
75
|
+
* @param messages - Array of BaseMessage objects to add
|
|
76
|
+
* @param title - Optional session title (auto-generated from the first message if not provided)
|
|
77
|
+
* @throws Error if the operation fails or validation fails
|
|
78
|
+
*/
|
|
79
|
+
async addMessages(userId, sessionId, messages, title) {
|
|
80
|
+
await (0, actions_1.addMessagesAction)({
|
|
81
|
+
client: this.client,
|
|
82
|
+
tableName: this.tableName,
|
|
83
|
+
userId,
|
|
84
|
+
sessionId,
|
|
85
|
+
messages,
|
|
86
|
+
title,
|
|
87
|
+
ttlDays: this.ttlDays,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Clear all messages in a session
|
|
92
|
+
* Deletes the session item from DynamoDB
|
|
93
|
+
*
|
|
94
|
+
* @param userId - User identifier
|
|
95
|
+
* @param sessionId - Session identifier
|
|
96
|
+
* @throws Error if the operation fails or validation fails
|
|
97
|
+
*/
|
|
98
|
+
async clear(userId, sessionId) {
|
|
99
|
+
await (0, actions_1.clearAction)({
|
|
100
|
+
client: this.client,
|
|
101
|
+
tableName: this.tableName,
|
|
102
|
+
userId,
|
|
103
|
+
sessionId,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* List all sessions for a user, sorted by most recent
|
|
108
|
+
* Returns metadata only (excludes messages for performance)
|
|
109
|
+
*
|
|
110
|
+
* @param userId - User ID to list sessions for
|
|
111
|
+
* @param limit - Optional maximum number of sessions to return (default: no limit)
|
|
112
|
+
* @returns Array of session metadata, sorted by most recent first
|
|
113
|
+
* @throws Error if the operation fails or validation fails
|
|
114
|
+
*/
|
|
115
|
+
async listSessions(userId, limit) {
|
|
116
|
+
return await (0, actions_1.listSessionsAction)({
|
|
117
|
+
client: this.client,
|
|
118
|
+
tableName: this.tableName,
|
|
119
|
+
userId,
|
|
120
|
+
limit,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.DynamoDBChatMessageHistory = DynamoDBChatMessageHistory;
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,8DAA0D;AAC1D,wDAAyD;AAIzD,uCAMmB;AAEnB,MAAa,0BAA0B;IACpB,SAAS,CAAiB;IAC1B,MAAM,CAAmB;IACzB,SAAS,CAAS;IAClB,OAAO,CAAU;IAElC;;;;;;;OAOG;IACH,YAAY,OAA0C;QACpD,IAAI,CAAC,SAAS,GAAG,IAAI,gCAAc,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,+BAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,SAAiB;QACjD,OAAO,MAAM,IAAA,2BAAiB,EAAC;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB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DBClientConfig } from '@aws-sdk/client-dynamodb';
|
|
5
|
+
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
|
|
6
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for DynamoDBChatMessageHistory
|
|
9
|
+
*/
|
|
10
|
+
export interface DynamoDBChatMessageHistoryOptions {
|
|
11
|
+
/** Name of the DynamoDB table to use for storage */
|
|
12
|
+
tableName: string;
|
|
13
|
+
/** Optional TTL in days for stored items (1-1825 days) */
|
|
14
|
+
ttlDays?: number;
|
|
15
|
+
/** Optional DynamoDB client configuration */
|
|
16
|
+
clientConfig?: DynamoDBClientConfig;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* DynamoDB item structure for a chat session
|
|
20
|
+
*/
|
|
21
|
+
export interface DynamoDBSessionItem {
|
|
22
|
+
/** User identifier (partition key) */
|
|
23
|
+
userId: string;
|
|
24
|
+
/** Session identifier (sort key) */
|
|
25
|
+
sessionId: string;
|
|
26
|
+
/** Array of messages in chronological order */
|
|
27
|
+
messages: BaseMessage[];
|
|
28
|
+
/** Session title (auto-generated from the first message) */
|
|
29
|
+
title: string;
|
|
30
|
+
/** Timestamp when session was created (milliseconds) */
|
|
31
|
+
createdAt: number;
|
|
32
|
+
/** Timestamp when the session was last updated (milliseconds) */
|
|
33
|
+
updatedAt: number;
|
|
34
|
+
/** Number of messages in the session */
|
|
35
|
+
messageCount: number;
|
|
36
|
+
/** Optional TTL timestamp (Unix timestamp in seconds) */
|
|
37
|
+
ttl?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Session metadata for listing (excludes messages)
|
|
41
|
+
*/
|
|
42
|
+
export interface SessionMetadata {
|
|
43
|
+
/** Session identifier */
|
|
44
|
+
sessionId: string;
|
|
45
|
+
/** Session title */
|
|
46
|
+
title: string;
|
|
47
|
+
/** Timestamp when session was created (milliseconds) */
|
|
48
|
+
createdAt: number;
|
|
49
|
+
/** Timestamp when the session was last updated (milliseconds) */
|
|
50
|
+
updatedAt: number;
|
|
51
|
+
/** Number of messages in the session */
|
|
52
|
+
messageCount: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parameters for get message action
|
|
56
|
+
*/
|
|
57
|
+
export interface GetMessagesActionParams {
|
|
58
|
+
/** DynamoDB document client */
|
|
59
|
+
client: DynamoDBDocument;
|
|
60
|
+
/** Name of the table */
|
|
61
|
+
tableName: string;
|
|
62
|
+
/** User identifier */
|
|
63
|
+
userId: string;
|
|
64
|
+
/** Session identifier */
|
|
65
|
+
sessionId: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Parameters for add message action
|
|
69
|
+
*/
|
|
70
|
+
export interface AddMessageActionParams {
|
|
71
|
+
/** DynamoDB document client */
|
|
72
|
+
client: DynamoDBDocument;
|
|
73
|
+
/** Name of the table */
|
|
74
|
+
tableName: string;
|
|
75
|
+
/** User identifier */
|
|
76
|
+
userId: string;
|
|
77
|
+
/** Session identifier */
|
|
78
|
+
sessionId: string;
|
|
79
|
+
/** Message to add */
|
|
80
|
+
message: BaseMessage;
|
|
81
|
+
/** Optional session title (auto-generated if not provided) */
|
|
82
|
+
title?: string;
|
|
83
|
+
/** Optional TTL in days */
|
|
84
|
+
ttlDays?: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parameters for add messages action
|
|
88
|
+
*/
|
|
89
|
+
export interface AddMessagesActionParams {
|
|
90
|
+
/** DynamoDB document client */
|
|
91
|
+
client: DynamoDBDocument;
|
|
92
|
+
/** Name of the table */
|
|
93
|
+
tableName: string;
|
|
94
|
+
/** User identifier */
|
|
95
|
+
userId: string;
|
|
96
|
+
/** Session identifier */
|
|
97
|
+
sessionId: string;
|
|
98
|
+
/** Messages to add */
|
|
99
|
+
messages: BaseMessage[];
|
|
100
|
+
/** Optional session title (auto-generated if not provided) */
|
|
101
|
+
title?: string;
|
|
102
|
+
/** Optional TTL in days */
|
|
103
|
+
ttlDays?: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parameters for clear action
|
|
107
|
+
*/
|
|
108
|
+
export interface ClearActionParams {
|
|
109
|
+
/** DynamoDB document client */
|
|
110
|
+
client: DynamoDBDocument;
|
|
111
|
+
/** Name of the table */
|
|
112
|
+
tableName: string;
|
|
113
|
+
/** User identifier */
|
|
114
|
+
userId: string;
|
|
115
|
+
/** Session identifier */
|
|
116
|
+
sessionId: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parameters for list sessions action
|
|
120
|
+
*/
|
|
121
|
+
export interface ListSessionsActionParams {
|
|
122
|
+
/** DynamoDB document client */
|
|
123
|
+
client: DynamoDBDocument;
|
|
124
|
+
/** Name of the table */
|
|
125
|
+
tableName: string;
|
|
126
|
+
/** User identifier */
|
|
127
|
+
userId: string;
|
|
128
|
+
/** Optional maximum number of sessions to return */
|
|
129
|
+
limit?: number;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/history/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC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ACzB,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B,MAAM,EAAE,gBAAgB,CAAC;IACzB,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,+BAA+B;IAC/B,MAAM,EAAE,gBAAgB,CAAC;IACzB,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/history/types/index.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/history/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for chat message history
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.withDynamoDBRetry = void 0;
|
|
21
|
+
__exportStar(require("./validation"), exports);
|
|
22
|
+
__exportStar(require("./title-generator"), exports);
|
|
23
|
+
var utils_1 = require("../../shared/utils");
|
|
24
|
+
Object.defineProperty(exports, "withDynamoDBRetry", { enumerable: true, get: function () { return utils_1.withDynamoDBRetry; } });
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/history/utils/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,+CAA6B;AAC7B,oDAAkC;AAClC,4CAAuD;AAA9C,0GAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Title generation utilities for chat sessions
|
|
3
|
+
*/
|
|
4
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
5
|
+
/**
|
|
6
|
+
* Generate a session title from the first message
|
|
7
|
+
*
|
|
8
|
+
* @param message - The first message in the session
|
|
9
|
+
* @returns A generated title string
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateTitle(message: BaseMessage): string;
|
|
12
|
+
//# sourceMappingURL=title-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"title-generator.d.ts","sourceRoot":"","sources":["../../../src/history/utils/title-generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAuC1D"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Title generation utilities for chat sessions
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateTitle = generateTitle;
|
|
7
|
+
const MAX_TITLE_LENGTH = 100;
|
|
8
|
+
const DEFAULT_TITLE = 'New Conversation';
|
|
9
|
+
/**
|
|
10
|
+
* Generate a session title from the first message
|
|
11
|
+
*
|
|
12
|
+
* @param message - The first message in the session
|
|
13
|
+
* @returns A generated title string
|
|
14
|
+
*/
|
|
15
|
+
function generateTitle(message) {
|
|
16
|
+
if (!message || !message.content) {
|
|
17
|
+
return DEFAULT_TITLE;
|
|
18
|
+
}
|
|
19
|
+
// Convert content to string (it can be string or array of content parts)
|
|
20
|
+
let contentText = '';
|
|
21
|
+
if (typeof message.content === 'string') {
|
|
22
|
+
contentText = message.content;
|
|
23
|
+
}
|
|
24
|
+
else if (Array.isArray(message.content)) {
|
|
25
|
+
// Extract text from content parts if it's an array
|
|
26
|
+
contentText = message.content
|
|
27
|
+
.map((part) => {
|
|
28
|
+
if (typeof part === 'string')
|
|
29
|
+
return part;
|
|
30
|
+
if (typeof part === 'object' && part !== null && 'text' in part) {
|
|
31
|
+
return part.text;
|
|
32
|
+
}
|
|
33
|
+
return '';
|
|
34
|
+
})
|
|
35
|
+
.join(' ');
|
|
36
|
+
}
|
|
37
|
+
// Clean and truncate the title
|
|
38
|
+
const cleaned = contentText
|
|
39
|
+
.replace(/\s+/g, ' ') // Replace multiple whitespace with a single space
|
|
40
|
+
.replace(/[\r\n]+/g, ' ') // Replace newlines with space
|
|
41
|
+
.trim();
|
|
42
|
+
if (!cleaned) {
|
|
43
|
+
return DEFAULT_TITLE;
|
|
44
|
+
}
|
|
45
|
+
// Truncate to max length
|
|
46
|
+
if (cleaned.length <= MAX_TITLE_LENGTH) {
|
|
47
|
+
return cleaned;
|
|
48
|
+
}
|
|
49
|
+
// Truncate and add ellipsis
|
|
50
|
+
return cleaned.substring(0, MAX_TITLE_LENGTH - 3) + '...';
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=title-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"title-generator.js","sourceRoot":"","sources":["../../../src/history/utils/title-generator.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAaH,sCAuCC;AAhDD,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAEzC;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,OAAoB;IAChD,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACjC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,yEAAyE;IACzE,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACxC,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAChC,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,mDAAmD;QACnD,WAAW,GAAG,OAAO,CAAC,OAAO;aAC1B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACZ,IAAI,OAAO,IAAI,KAAK,QAAQ;gBAAE,OAAO,IAAI,CAAC;YAC1C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBAChE,OAAQ,IAAY,CAAC,IAAI,CAAC;YAC5B,CAAC;YACD,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IAED,+BAA+B;IAC/B,MAAM,OAAO,GAAG,WAAW;SACxB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,kDAAkD;SACvE,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,8BAA8B;SACvD,IAAI,EAAE,CAAC;IAEV,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,yBAAyB;IACzB,IAAI,OAAO,CAAC,MAAM,IAAI,gBAAgB,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,4BAA4B;IAC5B,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for chat message history operations
|
|
3
|
+
*/
|
|
4
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
5
|
+
/**
|
|
6
|
+
* Custom error class for validation errors in chat message history
|
|
7
|
+
*/
|
|
8
|
+
export declare class HistoryValidationError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Validate user ID
|
|
13
|
+
*
|
|
14
|
+
* @param userId - User identifier to validate
|
|
15
|
+
* @throws HistoryValidationError if validation fails
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateUserId(userId: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Validate session ID
|
|
20
|
+
*
|
|
21
|
+
* @param sessionId - Session identifier to validate
|
|
22
|
+
* @throws HistoryValidationError if validation fails
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateSessionId(sessionId: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Validate a single message
|
|
27
|
+
*
|
|
28
|
+
* @param message - BaseMessage to validate
|
|
29
|
+
* @throws HistoryValidationError if validation fails
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateMessage(message: BaseMessage): void;
|
|
32
|
+
/**
|
|
33
|
+
* Validate messages array
|
|
34
|
+
*
|
|
35
|
+
* @param messages - Array of BaseMessage objects to validate
|
|
36
|
+
* @throws HistoryValidationError if validation fails
|
|
37
|
+
*/
|
|
38
|
+
export declare function validateMessages(messages: BaseMessage[]): void;
|
|
39
|
+
/**
|
|
40
|
+
* Validate title
|
|
41
|
+
*
|
|
42
|
+
* @param title - Optional title string to validate
|
|
43
|
+
* @throws HistoryValidationError if validation fails
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateTitle(title: string | undefined): void;
|
|
46
|
+
/**
|
|
47
|
+
* Validate list limit parameter
|
|
48
|
+
*
|
|
49
|
+
* @param limit - Optional maximum number of items to return
|
|
50
|
+
* @throws HistoryValidationError if validation fails
|
|
51
|
+
*/
|
|
52
|
+
export declare function validateLimit(limit: number | undefined): void;
|
|
53
|
+
/**
|
|
54
|
+
* Validate TTL days (wraps shared validation with a history-specific error type)
|
|
55
|
+
*
|
|
56
|
+
* @param ttlDays - Optional TTL in days
|
|
57
|
+
* @throws HistoryValidationError if validation fails
|
|
58
|
+
*/
|
|
59
|
+
export declare function validateTTLDays(ttlDays: number | undefined): void;
|
|
60
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/history/utils/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAUvD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAoBnD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAoBzD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAa1D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAyB9D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAc7D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAgB7D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAOjE"}
|