Skip to content

Commit 97f195d

Browse files
committed
Changes timestamp to latest hash
1 parent a56ffad commit 97f195d

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"last_commit": "0000"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

packages/ethernaut-ai/src/internal/assistants/utils/build-hub-docs.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ const openai = require('../../openai')
44
const USE_VECTOR_STORE = true // my flag to test both solutions
55
const VECTOR_STORE_ID = 'OP_5'
66

7-
// Keywords associated with each document
8-
const documentKeywords = require('../docs/kb-files/output/keywords.json')
9-
107
function extractKeywords(query) {
118
// TBD DEPRECATED
129
// Convert query to lowercase and split into words
@@ -47,9 +44,13 @@ function calculateRelevance(query, keywords) {
4744

4845
// Original keyword-based implementation
4946
// DEPRECATED
47+
// Keywords associated with each document
48+
const documentKeywords = require('../docs/kb-files/output/keywords.json')
49+
5050
function buildHubDocsWithKeywords(query) {
5151
const docs = []
5252
const docsDir = path.join(__dirname, '../docs/kb-files/output/chapters')
53+
5354
// Calculate relevance for each document
5455
const relevanceScores = Object.entries(documentKeywords).map(
5556
([file, keywords]) => ({

packages/ethernaut-cli/hardhat.config.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require('ethernaut-oso')
3232
require('ethernaut-ai-ui')
3333
require('ethernaut-optigov')
3434

35-
const OPTIMISM_TIMESTAMP =
35+
const OP_REMOTE_FILE =
3636
'https://github.com/raiseerco/ethernaut-app-kb/releases/download/daily/last-update.json'
3737
const ZIP_URL_OPTIMISM =
3838
'https://github.com/raiseerco/ethernaut-app-kb/releases/download/daily/kb.zip'
@@ -41,7 +41,7 @@ const FILES_DIR = path.join(
4141
'../../packages/ethernaut-ai/src/internal/assistants/docs/kb-files',
4242
)
4343

44-
const TIMESTAMP_FILE = path.join(FILES_DIR, 'last-update.json')
44+
const OP_LOCAL_FILE = path.join(FILES_DIR, 'last-update.json')
4545

4646
async function downloadFile(url) {
4747
const response = await fetch(url)
@@ -53,17 +53,17 @@ async function downloadFile(url) {
5353
return response.text()
5454
}
5555

56-
let localTimestamp = null
56+
let localHash = null
5757

5858
async function checkKB() {
5959
try {
60-
if (fs.existsSync(TIMESTAMP_FILE)) {
60+
if (fs.existsSync(OP_LOCAL_FILE)) {
6161
try {
62-
const timestampData = fs.readFileSync(TIMESTAMP_FILE, 'utf8')
63-
localTimestamp = JSON.parse(timestampData)
64-
const timestampRepo = await downloadFile(OPTIMISM_TIMESTAMP)
65-
const parsedData = JSON.parse(timestampRepo)
66-
if (parsedData.last_update === localTimestamp.last_update) {
62+
const localOpFile = fs.readFileSync(OP_LOCAL_FILE, 'utf8')
63+
localHash = JSON.parse(localOpFile)
64+
const remoteOpFile = await downloadFile(OP_REMOTE_FILE)
65+
const remoteHash = JSON.parse(remoteOpFile)
66+
if (remoteHash.last_commit === localHash.last_commit) {
6767
// spinner.success('--- KB already up to date')
6868
return
6969
} else {
@@ -105,9 +105,9 @@ async function downloadKB() {
105105
fs.unlinkSync(tempZipPath)
106106

107107
try {
108-
const timestampData = await downloadFile(OPTIMISM_TIMESTAMP)
108+
const timestampData = await downloadFile(OP_REMOTE_FILE)
109109
const parsedData = JSON.parse(timestampData)
110-
fs.writeFileSync(TIMESTAMP_FILE, JSON.stringify(parsedData, null, 2))
110+
fs.writeFileSync(OP_LOCAL_FILE, JSON.stringify(parsedData, null, 2))
111111
} catch (error) {
112112
console.error('Error downloading or parsing timestamp file:', error)
113113
}

0 commit comments

Comments
 (0)