Skip to content

Commit 384f342

Browse files
committed
chore: console -> elizaLogger
1 parent 118b53b commit 384f342

File tree

1 file changed

+66
-33
lines changed

1 file changed

+66
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,57 @@
1-
import { Provider, IAgentRuntime, Memory, State, elizaLogger } from "@elizaos/core";
2-
import { GitBookResponse, GitBookClientConfig } from '../types';
1+
import {
2+
Provider,
3+
IAgentRuntime,
4+
Memory,
5+
State,
6+
elizaLogger,
7+
} from "@elizaos/core";
8+
import { GitBookResponse, GitBookClientConfig } from "../types";
39

410
function cleanText(text: string): string {
511
const cleaned = text
6-
.replace(/<@!?\d+>/g, '') // Discord mentions
7-
.replace(/<#\d+>/g, '') // Discord channels
8-
.replace(/<@&\d+>/g, '') // Discord roles
9-
.replace(/(?:^|\s)@[\w_]+/g, '') // Platform mentions
12+
.replace(/<@!?\d+>/g, "") // Discord mentions
13+
.replace(/<#\d+>/g, "") // Discord channels
14+
.replace(/<@&\d+>/g, "") // Discord roles
15+
.replace(/(?:^|\s)@[\w_]+/g, "") // Platform mentions
1016
.trim();
1117

1218
return cleaned;
1319
}
1420

15-
async function validateQuery(runtime: IAgentRuntime, text: string): Promise<boolean> {
21+
async function validateQuery(
22+
runtime: IAgentRuntime,
23+
text: string
24+
): Promise<boolean> {
1625
// Default general queries - everything else comes from config
1726
const keywords = {
1827
generalQueries: [
19-
'how', 'what', 'where', 'explain', 'show', 'tell',
20-
'can', 'does', 'is', 'are', 'will', 'why',
21-
'benefits', 'features', 'cost', 'price',
22-
'use', 'using', 'work', 'access', 'get'
23-
]
28+
"how",
29+
"what",
30+
"where",
31+
"explain",
32+
"show",
33+
"tell",
34+
"can",
35+
"does",
36+
"is",
37+
"are",
38+
"will",
39+
"why",
40+
"benefits",
41+
"features",
42+
"cost",
43+
"price",
44+
"use",
45+
"using",
46+
"work",
47+
"access",
48+
"get",
49+
],
2450
};
2551

2652
try {
27-
const gitbookConfig = runtime.character.clientConfig?.gitbook as GitBookClientConfig;
53+
const gitbookConfig = runtime.character.clientConfig
54+
?.gitbook as GitBookClientConfig;
2855

2956
// Get project terms and document triggers from config
3057
const projectTerms = gitbookConfig?.keywords?.projectTerms || [];
@@ -34,18 +61,21 @@ async function validateQuery(runtime: IAgentRuntime, text: string): Promise<bool
3461
if (gitbookConfig?.keywords?.generalQueries) {
3562
keywords.generalQueries = [
3663
...keywords.generalQueries,
37-
...gitbookConfig.keywords.generalQueries
64+
...gitbookConfig.keywords.generalQueries,
3865
];
3966
}
4067

4168
const containsAnyWord = (text: string, words: string[] = []) => {
42-
return words.length === 0 || words.some(word => {
43-
if (word.includes(' ')) {
44-
return text.includes(word.toLowerCase());
45-
}
46-
const regex = new RegExp(`\\b${word}\\b`, 'i');
47-
return regex.test(text);
48-
});
69+
return (
70+
words.length === 0 ||
71+
words.some((word) => {
72+
if (word.includes(" ")) {
73+
return text.includes(word.toLowerCase());
74+
}
75+
const regex = new RegExp(`\\b${word}\\b`, "i");
76+
return regex.test(text);
77+
})
78+
);
4979
};
5080

5181
const hasProjectTerm = containsAnyWord(text, projectTerms);
@@ -54,29 +84,32 @@ async function validateQuery(runtime: IAgentRuntime, text: string): Promise<bool
5484

5585
const isValid = hasProjectTerm || hasDocTrigger || hasGeneralQuery;
5686

57-
elizaLogger.info(`✅ Is GitBook Validation Result: ${isValid}`)
87+
elizaLogger.info(`✅ Is GitBook Validation Result: ${isValid}`);
5888
return isValid;
59-
6089
} catch (error) {
61-
elizaLogger.warn(`❌ Error in GitBook validation:\n${error}`)
90+
elizaLogger.warn(`❌ Error in GitBook validation:\n${error}`);
6291
return false;
6392
}
6493
}
6594

6695
export const gitbookProvider: Provider = {
67-
get: async (runtime: IAgentRuntime, message: Memory, _state?: State): Promise<string> => {
96+
get: async (
97+
runtime: IAgentRuntime,
98+
message: Memory,
99+
_state?: State
100+
): Promise<string> => {
68101
try {
69102
const spaceId = runtime.getSetting("GITBOOK_SPACE_ID");
70103
if (!spaceId) {
71-
elizaLogger.error('⚠️ GitBook Space ID not configured')
104+
elizaLogger.error("⚠️ GitBook Space ID not configured");
72105
return "";
73106
}
74107

75108
const text = message.content.text.toLowerCase().trim();
76109
const isValidQuery = await validateQuery(runtime, text);
77110

78111
if (!isValidQuery) {
79-
elizaLogger.info('⚠️ GitBook Query validation failed')
112+
elizaLogger.info("⚠️ GitBook Query validation failed");
80113
return "";
81114
}
82115

@@ -87,26 +120,26 @@ export const gitbookProvider: Provider = {
87120
{
88121
method: "POST",
89122
headers: {
90-
"Content-Type": "application/json"
123+
"Content-Type": "application/json",
91124
},
92125
body: JSON.stringify({
93126
query: cleanedQuery,
94-
variables: {}
95-
})
127+
variables: {},
128+
}),
96129
}
97130
);
98131

99132
if (!response.ok) {
100-
console.error('❌ GitBook API error:', response.status);
133+
elizaLogger.error("❌ GitBook API error:", response.status);
101134
return "";
102135
}
103136

104137
const result: GitBookResponse = await response.json();
105138

106139
return result.answer?.text || "";
107140
} catch (error) {
108-
console.error("❌ Error in GitBook provider:", error);
141+
elizaLogger.error("❌ Error in GitBook provider:", error);
109142
return "";
110143
}
111-
}
144+
},
112145
};

0 commit comments

Comments
 (0)