@gitsense/gscb-git-tools 0.2.0 → 0.3.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/dist/cjs/common/logger.js +97 -0
- package/dist/cjs/common/logger.js.map +1 -0
- package/dist/cjs/common/metadata-manager.js +196 -0
- package/dist/cjs/common/metadata-manager.js.map +1 -0
- package/dist/cjs/importer/chat-manager/chat-creator.js +90 -0
- package/dist/cjs/importer/chat-manager/chat-creator.js.map +1 -0
- package/dist/cjs/importer/chat-manager/chat-manager.js +179 -0
- package/dist/cjs/importer/chat-manager/chat-manager.js.map +1 -0
- package/dist/cjs/importer/chat-manager/constants.js +66 -0
- package/dist/cjs/importer/chat-manager/constants.js.map +1 -0
- package/dist/cjs/importer/chat-manager/group-manager.js +56 -0
- package/dist/cjs/importer/chat-manager/group-manager.js.map +1 -0
- package/dist/cjs/importer/chat-manager/hierarchy-manager.js +115 -0
- package/dist/cjs/importer/chat-manager/hierarchy-manager.js.map +1 -0
- package/dist/cjs/importer/chat-manager/message-manager.js +126 -0
- package/dist/cjs/importer/chat-manager/message-manager.js.map +1 -0
- package/dist/cjs/importer/constants.js +30 -0
- package/dist/cjs/importer/constants.js.map +1 -0
- package/dist/cjs/importer/core/directory-processor.js +343 -0
- package/dist/cjs/importer/core/directory-processor.js.map +1 -0
- package/dist/cjs/importer/core/error-handler.js +64 -0
- package/dist/cjs/importer/core/error-handler.js.map +1 -0
- package/dist/cjs/importer/core/import-processor.js +167 -0
- package/dist/cjs/importer/core/import-processor.js.map +1 -0
- package/dist/cjs/importer/core/importer.js +135 -0
- package/dist/cjs/importer/core/importer.js.map +1 -0
- package/dist/cjs/importer/core/utils.js +66 -0
- package/dist/cjs/importer/core/utils.js.map +1 -0
- package/dist/cjs/importer/file-processor.js +199 -0
- package/dist/cjs/importer/file-processor.js.map +1 -0
- package/dist/cjs/importer/language-utils.js +286 -0
- package/dist/cjs/importer/language-utils.js.map +1 -0
- package/dist/cjs/importer/tree-processor.js +119 -0
- package/dist/cjs/importer/tree-processor.js.map +1 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/common/logger.js +95 -0
- package/dist/esm/common/logger.js.map +1 -0
- package/dist/esm/common/metadata-manager.js +194 -0
- package/dist/esm/common/metadata-manager.js.map +1 -0
- package/dist/esm/importer/chat-manager/chat-creator.js +88 -0
- package/dist/esm/importer/chat-manager/chat-creator.js.map +1 -0
- package/dist/esm/importer/chat-manager/chat-manager.js +177 -0
- package/dist/esm/importer/chat-manager/chat-manager.js.map +1 -0
- package/dist/esm/importer/chat-manager/constants.js +48 -0
- package/dist/esm/importer/chat-manager/constants.js.map +1 -0
- package/dist/esm/importer/chat-manager/group-manager.js +54 -0
- package/dist/esm/importer/chat-manager/group-manager.js.map +1 -0
- package/dist/esm/importer/chat-manager/hierarchy-manager.js +113 -0
- package/dist/esm/importer/chat-manager/hierarchy-manager.js.map +1 -0
- package/dist/esm/importer/chat-manager/message-manager.js +124 -0
- package/dist/esm/importer/chat-manager/message-manager.js.map +1 -0
- package/dist/esm/importer/constants.js +28 -0
- package/dist/esm/importer/constants.js.map +1 -0
- package/dist/esm/importer/core/directory-processor.js +337 -0
- package/dist/esm/importer/core/directory-processor.js.map +1 -0
- package/dist/esm/importer/core/error-handler.js +62 -0
- package/dist/esm/importer/core/error-handler.js.map +1 -0
- package/dist/esm/importer/core/import-processor.js +165 -0
- package/dist/esm/importer/core/import-processor.js.map +1 -0
- package/dist/esm/importer/core/importer.js +133 -0
- package/dist/esm/importer/core/importer.js.map +1 -0
- package/dist/esm/importer/core/utils.js +64 -0
- package/dist/esm/importer/core/utils.js.map +1 -0
- package/dist/esm/importer/file-processor.js +193 -0
- package/dist/esm/importer/file-processor.js.map +1 -0
- package/dist/esm/importer/language-utils.js +279 -0
- package/dist/esm/importer/language-utils.js.map +1 -0
- package/dist/esm/importer/tree-processor.js +113 -0
- package/dist/esm/importer/tree-processor.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +215 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Component: Group Manager
|
|
5
|
+
* Block-UUID: 1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d
|
|
6
|
+
* Parent-UUID: N/A
|
|
7
|
+
* Version: 1.0.0
|
|
8
|
+
* Purpose: Handles group creation and updates
|
|
9
|
+
* Language: TypeScript
|
|
10
|
+
* Created-at: 2025-03-15T02:09:59.275Z
|
|
11
|
+
* Authors: together.ai - DeepSeek v3 (v1.0.0)
|
|
12
|
+
*/
|
|
13
|
+
class GroupManager {
|
|
14
|
+
dbClient;
|
|
15
|
+
gitRepo;
|
|
16
|
+
logger;
|
|
17
|
+
constructor(dbClient, gitRepo, logger) {
|
|
18
|
+
this.dbClient = dbClient;
|
|
19
|
+
this.gitRepo = gitRepo;
|
|
20
|
+
this.logger = logger;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates or updates a group. Full name example "facebook/react".
|
|
24
|
+
*/
|
|
25
|
+
async createOrUpdateGroup(type, fullName) {
|
|
26
|
+
try {
|
|
27
|
+
const existingGroup = await this.dbClient.getGroupByName(fullName);
|
|
28
|
+
if (existingGroup) {
|
|
29
|
+
return existingGroup.id;
|
|
30
|
+
}
|
|
31
|
+
const meta = this.gitRepo ? await this.gitRepo.getInfo() : null;
|
|
32
|
+
return await this.dbClient.createGroup({
|
|
33
|
+
type,
|
|
34
|
+
name: fullName,
|
|
35
|
+
meta
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new Error(`Failed to create or update group '${fullName}': ${error instanceof Error ? error.message : String(error)}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves a group by its full name.
|
|
44
|
+
*/
|
|
45
|
+
async getGroupByFullName(fullName) {
|
|
46
|
+
try {
|
|
47
|
+
return await this.dbClient.getGroupByName(fullName) || null;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw new Error(`Failed to retrieve group '${fullName}': ${error instanceof Error ? error.message : String(error)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.GroupManager = GroupManager;
|
|
56
|
+
//# sourceMappingURL=group-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-manager.js","sources":["../../../../src/importer/chat-manager/group-manager.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;;;;;;AASG;MAQU,YAAY,CAAA;AAEA,IAAA,QAAA;AACA,IAAA,OAAA;AACA,IAAA,MAAA;AAHrB,IAAA,WAAA,CACqB,QAAwB,EACxB,OAAmB,EACnB,MAAc,EAAA;QAFd,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAM,CAAA,MAAA,GAAN,MAAM;;AAG3B;;AAEG;AACH,IAAA,MAAM,mBAAmB,CAAC,IAAe,EAAE,QAAgB,EAAA;AACvD,QAAA,IAAI;YACA,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC;YAElE,IAAI,aAAa,EAAE;gBACf,OAAO,aAAa,CAAC,EAAG;;AAG5B,YAAA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI;AAE/D,YAAA,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;gBACnC,IAAI;AACJ,gBAAA,IAAI,EAAE,QAAQ;gBACd;AACH,aAAA,CAAC;;QACJ,OAAO,KAAK,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,CAAqC,kCAAA,EAAA,QAAQ,MAAM,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAE,CAAA,CAAC;;;AAIpI;;AAEG;IACH,MAAM,kBAAkB,CAAC,QAAgB,EAAA;AACrC,QAAA,IAAI;YACA,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,IAAI;;QAC7D,OAAO,KAAK,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,CAA6B,0BAAA,EAAA,QAAQ,MAAM,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAE,CAAA,CAAC;;;AAG/H;;;;"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constants = require('./constants.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component: Hierarchy Manager
|
|
7
|
+
* Block-UUID: 4d5e6f7a-8b9c-0d1e-2f3a-4b5c6d7e8f9a
|
|
8
|
+
* Parent-UUID: N/A
|
|
9
|
+
* Version: 1.0.0
|
|
10
|
+
* Purpose: Handles chat hierarchy setup and management
|
|
11
|
+
* Language: TypeScript
|
|
12
|
+
* Created-at: 2025-03-15T02:12:20.075Z
|
|
13
|
+
* Authors: together.ai - DeepSeek v3 (v1.0.0)
|
|
14
|
+
*/
|
|
15
|
+
class HierarchyManager {
|
|
16
|
+
dbClient;
|
|
17
|
+
gitRepo;
|
|
18
|
+
chatCreator;
|
|
19
|
+
groupManager;
|
|
20
|
+
logger;
|
|
21
|
+
constructor(dbClient, gitRepo, chatCreator, groupManager, logger) {
|
|
22
|
+
this.dbClient = dbClient;
|
|
23
|
+
this.gitRepo = gitRepo;
|
|
24
|
+
this.chatCreator = chatCreator;
|
|
25
|
+
this.groupManager = groupManager;
|
|
26
|
+
this.logger = logger;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sets up the chat hierarchy for the repository.
|
|
30
|
+
* Creates or updates groups and chats for `git-repos`, `git-repo-owner`, `git-repo`, and `git-ref`.
|
|
31
|
+
* Returns the ID of the `git-ref` chat.
|
|
32
|
+
*/
|
|
33
|
+
async setupChatHierarchy(repoOwner, repoName, ref, refType) {
|
|
34
|
+
try {
|
|
35
|
+
// Step 1: Create or update groups
|
|
36
|
+
const reposGroupId = await this.groupManager.createOrUpdateGroup(constants.GROUP_TYPE_GIT_REPOS, constants.GROUP_TYPE_GIT_REPOS);
|
|
37
|
+
const repoOwnerGroupId = await this.groupManager.createOrUpdateGroup(constants.GROUP_TYPE_GIT_REPO_OWNER, repoOwner);
|
|
38
|
+
const repoGroupId = await this.groupManager.createOrUpdateGroup(constants.GROUP_TYPE_GIT_REPO, `${repoOwner}/${repoName}`);
|
|
39
|
+
// Step 2: Create or update chats
|
|
40
|
+
const reposChatId = await this.createOrUpdateReposChat(reposGroupId);
|
|
41
|
+
const repoOwnerChatId = await this.createOrUpdateRepoOwnerChat(reposChatId, repoOwnerGroupId, repoOwner);
|
|
42
|
+
const repoChatId = await this.createOrUpdateRepoChat(repoOwnerChatId, repoGroupId, repoOwner, repoName);
|
|
43
|
+
const refChatId = await this.createOrUpdateRefChat(repoChatId, repoGroupId, ref, refType);
|
|
44
|
+
return { refChatId, repoGroupId };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error(`Failed to setup chat hierarchy: ${error instanceof Error ? error.message : String(error)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates or updates the `git-repos` chat.
|
|
52
|
+
*/
|
|
53
|
+
async createOrUpdateReposChat(groupId) {
|
|
54
|
+
const existingChat = await this.dbClient.getChatByTypeAndName(constants.CHAT_TYPE_GIT_REPOS, constants.CHAT_NAME_GIT_REPOS, groupId);
|
|
55
|
+
if (existingChat) {
|
|
56
|
+
return existingChat.id;
|
|
57
|
+
}
|
|
58
|
+
const meta = {
|
|
59
|
+
type: constants.CHAT_TYPE_GIT_REPOS
|
|
60
|
+
};
|
|
61
|
+
return await this.chatCreator.createChat(constants.CHAT_TYPE_GIT_REPOS, constants.CHAT_NAME_GIT_REPOS, 0, groupId, meta);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates or updates the `git-repo-owner` chat.
|
|
65
|
+
*/
|
|
66
|
+
async createOrUpdateRepoOwnerChat(parentId, groupId, repoOwner) {
|
|
67
|
+
const chatName = constants.CHAT_NAME_GIT_REPO_OWNER(repoOwner);
|
|
68
|
+
const existingChat = await this.dbClient.getChatByTypeAndName(constants.CHAT_TYPE_GIT_REPO_OWNER, chatName, groupId);
|
|
69
|
+
const meta = {
|
|
70
|
+
type: constants.CHAT_TYPE_GIT_REPO_OWNER,
|
|
71
|
+
owner: repoOwner
|
|
72
|
+
};
|
|
73
|
+
if (existingChat) {
|
|
74
|
+
return existingChat.id;
|
|
75
|
+
}
|
|
76
|
+
return await this.chatCreator.createChat(constants.CHAT_TYPE_GIT_REPO_OWNER, chatName, parentId, groupId, meta, '', -1);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates or updates the `git-repo` chat.
|
|
80
|
+
*/
|
|
81
|
+
async createOrUpdateRepoChat(parentId, groupId, repoOwner, repoName) {
|
|
82
|
+
const chatName = repoName;
|
|
83
|
+
const existingChat = await this.dbClient.getChatByTypeAndName(constants.CHAT_TYPE_GIT_REPO, chatName, groupId);
|
|
84
|
+
const repo = await this.gitRepo.getInfo();
|
|
85
|
+
const meta = {
|
|
86
|
+
type: constants.CHAT_TYPE_GIT_REPO,
|
|
87
|
+
owner: repoOwner,
|
|
88
|
+
name: repoName,
|
|
89
|
+
path: repo.path
|
|
90
|
+
};
|
|
91
|
+
if (existingChat) {
|
|
92
|
+
return existingChat.id;
|
|
93
|
+
}
|
|
94
|
+
return await this.chatCreator.createChat(constants.CHAT_TYPE_GIT_REPO, chatName, parentId, groupId, meta);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates or updates the `git-branch`, `git-commit`, or `git-tag` chat.
|
|
98
|
+
*/
|
|
99
|
+
async createOrUpdateRefChat(parentId, groupId, name, type) {
|
|
100
|
+
const chatType = type.match(/(commit|branch|tag)/) ? constants.CHAT_TYPE_GIT_REF : null;
|
|
101
|
+
if (!chatType) {
|
|
102
|
+
throw new Error(`No chat type associated with ref type ${type}`);
|
|
103
|
+
}
|
|
104
|
+
const chatName = constants.CHAT_NAME_GIT_REF(name);
|
|
105
|
+
const existingChat = await this.dbClient.getChatByTypeAndName(chatType, chatName, groupId);
|
|
106
|
+
if (existingChat) {
|
|
107
|
+
return existingChat.id;
|
|
108
|
+
}
|
|
109
|
+
const meta = { type, name, status: '' };
|
|
110
|
+
return await this.chatCreator.createChat(chatType, chatName, parentId, groupId, meta);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exports.HierarchyManager = HierarchyManager;
|
|
115
|
+
//# sourceMappingURL=hierarchy-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchy-manager.js","sources":["../../../../src/importer/chat-manager/hierarchy-manager.ts"],"sourcesContent":[null],"names":["GROUP_TYPE_GIT_REPOS","GROUP_TYPE_GIT_REPO_OWNER","GROUP_TYPE_GIT_REPO","CHAT_TYPE_GIT_REPOS","CHAT_NAME_GIT_REPOS","CHAT_NAME_GIT_REPO_OWNER","CHAT_TYPE_GIT_REPO_OWNER","CHAT_TYPE_GIT_REPO","CHAT_TYPE_GIT_REF","CHAT_NAME_GIT_REF"],"mappings":";;;;AAAA;;;;;;;;;AASG;MAsBU,gBAAgB,CAAA;AAEJ,IAAA,QAAA;AACA,IAAA,OAAA;AACA,IAAA,WAAA;AACA,IAAA,YAAA;AACA,IAAA,MAAA;IALrB,WACqB,CAAA,QAAwB,EACxB,OAAmB,EACnB,WAAwB,EACxB,YAA0B,EAC1B,MAAc,EA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
+
|
|
5
|
+
/**
|
|
6
|
+
* Component: Message Manager
|
|
7
|
+
* Block-UUID: 9b8c7d6e-5f4a-3b2c-1d0e-9f8e7d6c5b4a
|
|
8
|
+
* Parent-UUID: N/A
|
|
9
|
+
* Version: 1.1.0
|
|
10
|
+
* Purpose: Handles message creation, retrieval, and updates, including markdown table generation
|
|
11
|
+
* Language: TypeScript
|
|
12
|
+
* Created-at: 2025-03-15T02:07:30.618Z
|
|
13
|
+
* Updated-at: 2025-03-16T02:16:32.958Z
|
|
14
|
+
* Authors: together.ai - DeepSeek v3 (v1.0.0), OpenRouter - DeepSeek v3 (v1.1.0)
|
|
15
|
+
*/
|
|
16
|
+
class MessageManager {
|
|
17
|
+
dbClient;
|
|
18
|
+
logger;
|
|
19
|
+
constructor(dbClient, logger) {
|
|
20
|
+
this.dbClient = dbClient;
|
|
21
|
+
this.logger = logger;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a system message for a chat.
|
|
25
|
+
*/
|
|
26
|
+
async createSystemMessage(chatId) {
|
|
27
|
+
try {
|
|
28
|
+
return await this.dbClient.createMessage({
|
|
29
|
+
type: constants.MESSAGE_TYPE_REGULAR,
|
|
30
|
+
visibility: constants.CHAT_VISIBILITY_PUBLIC,
|
|
31
|
+
chatId,
|
|
32
|
+
parentId: 0,
|
|
33
|
+
level: 0,
|
|
34
|
+
role: 'system',
|
|
35
|
+
message: '',
|
|
36
|
+
priority: 0
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`Failed to create system message for chat ${chatId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates the main message for a chat.
|
|
45
|
+
*/
|
|
46
|
+
async createMainMessage(chatId, parentId, chatType, message) {
|
|
47
|
+
if (!message) {
|
|
48
|
+
message = '';
|
|
49
|
+
}
|
|
50
|
+
return await this.dbClient.createMessage({
|
|
51
|
+
type: chatType,
|
|
52
|
+
visibility: constants.CHAT_VISIBILITY_PUBLIC,
|
|
53
|
+
chatId,
|
|
54
|
+
parentId,
|
|
55
|
+
level: 2,
|
|
56
|
+
role: 'assistant',
|
|
57
|
+
message,
|
|
58
|
+
priority: 0,
|
|
59
|
+
sample: 1,
|
|
60
|
+
model: constants.DEFAULT_MODEL,
|
|
61
|
+
temperature: constants.DEFAULT_TEMPERATURE
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates the main message for a chat.
|
|
66
|
+
*/
|
|
67
|
+
async createChatMetaMessage(chatId, parentId) {
|
|
68
|
+
return await this.dbClient.createMessage({
|
|
69
|
+
type: constants.MESSAGE_TYPE_CHAT_META,
|
|
70
|
+
visibility: constants.CHAT_VISIBILITY_PUBLIC,
|
|
71
|
+
chatId,
|
|
72
|
+
parentId,
|
|
73
|
+
level: 2,
|
|
74
|
+
role: 'assistant',
|
|
75
|
+
message: '',
|
|
76
|
+
priority: 0,
|
|
77
|
+
sample: 1,
|
|
78
|
+
model: constants.DEFAULT_MODEL,
|
|
79
|
+
temperature: constants.DEFAULT_TEMPERATURE,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves a message by its ID.
|
|
84
|
+
*/
|
|
85
|
+
async getMessageById(messageId) {
|
|
86
|
+
try {
|
|
87
|
+
const message = await this.dbClient.getMessageById(messageId);
|
|
88
|
+
if (!message) {
|
|
89
|
+
throw new Error(`Message with ID ${messageId} not found`);
|
|
90
|
+
}
|
|
91
|
+
return message;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new Error(`Failed to retrieve message ${messageId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves a message by chat ID and type.
|
|
99
|
+
*/
|
|
100
|
+
async getMessageByChatIdAndType(chatId, type) {
|
|
101
|
+
try {
|
|
102
|
+
const messages = await this.dbClient.getMessagesByChatIdAndType(chatId, type);
|
|
103
|
+
if (messages.length === 0) {
|
|
104
|
+
throw new Error(`No message of type '${type}' found for chat ${chatId}`);
|
|
105
|
+
}
|
|
106
|
+
return messages[0];
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
throw new Error(`Failed to retrieve message for chat ${chatId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Updates a message with new content.
|
|
114
|
+
*/
|
|
115
|
+
async updateMessage(messageId, updates) {
|
|
116
|
+
try {
|
|
117
|
+
await this.dbClient.updateMessage(messageId, updates);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new Error(`Failed to update message ${messageId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
exports.MessageManager = MessageManager;
|
|
126
|
+
//# sourceMappingURL=message-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-manager.js","sources":["../../../../src/importer/chat-manager/message-manager.ts"],"sourcesContent":[null],"names":["MESSAGE_TYPE_REGULAR","CHAT_VISIBILITY_PUBLIC","DEFAULT_MODEL","DEFAULT_TEMPERATURE","MESSAGE_TYPE_CHAT_META"],"mappings":";;;;AAAA;;;;;;;;;;AAUG;MAQU,cAAc,CAAA;AAEF,IAAA,QAAA;AACA,IAAA,MAAA;IAFrB,WACqB,CAAA,QAAwB,EACxB,MAAc,EAAA;QADd,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAM,CAAA,MAAA,GAAN,MAAM;;AAG3B;;AAEG;IACH,MAAM,mBAAmB,CAAC,MAAc,EAAA;AACpC,QAAA,IAAI;AACA,YAAA,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;AACrC,gBAAA,IAAI,EAA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C5D,QAAA,IAAI;YACA,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC;;QACvD,OAAO,KAAK,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,CAA4B,yBAAA,EAAA,SAAS,KAAK,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAE,CAAA,CAAC;;;AAG9H;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Component: Constants
|
|
5
|
+
* Block-UUID: 4c2d1e0f-1a3b-4c5d-6e7f-8a9b0c1d2e3f
|
|
6
|
+
* Parent-UUID: N/A
|
|
7
|
+
* Version: 2.0.0
|
|
8
|
+
* Description: Update this to provide a proper file description
|
|
9
|
+
* Language: TypeScript
|
|
10
|
+
* Created-at: 2025-02-22T07:25:50.819Z
|
|
11
|
+
* Authors: OpenRouter - DeepSeek v3 (v1.0.0), Claude 3.5 Sonnet (v2.0.0)
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_OPTIONS = {
|
|
14
|
+
maxFileSize: 256 * 1024, // 256KB
|
|
15
|
+
skipPatterns: [
|
|
16
|
+
/\.min\.(js|css)$/,
|
|
17
|
+
/\.log$/,
|
|
18
|
+
/\.map$/,
|
|
19
|
+
/\.bundle\./,
|
|
20
|
+
/dist\//,
|
|
21
|
+
/build\//,
|
|
22
|
+
/vendor\//,
|
|
23
|
+
/node_modules\//
|
|
24
|
+
],
|
|
25
|
+
verbose: false,
|
|
26
|
+
skipBinaryFiles: true
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
|
30
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../src/importer/constants.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;;;;;;AASG;AAIU,MAAA,eAAe,GAAG;AAC3B,IAAA,WAAW,EAAE,GAAG,GAAG,IAAI;AACvB,IAAA,YAAY,EAAE;QACV,kBAAkB;QAClB,QAAQ;QACR,QAAQ;QACR,YAAY;QACZ,QAAQ;QACR,SAAS;QACT,UAAU;QACV;AACH,KAAA;AACD,IAAA,OAAO,EAAE,KAAK;AACd,IAAA,eAAe,EAAE;;;;;"}
|