Skip to content

Commit

Permalink
fix(app): user config structure
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu committed Jul 17, 2023
1 parent 7e70504 commit 0ec9f38
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
26 changes: 19 additions & 7 deletions app/extension/chrome/src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { EmbeddingsInfo, VectorMetaData, SavedNotion } from '@stargram/core
import { storageInfo } from '@stargram/core/storage'
import type { TLLM } from '@stargram/core/llm'
import { llmInfo } from '@stargram/core/llm'
import type { ContentRequest, ListenerSendResponse, PageInfo, SwResponse } from '~/types'
import type { ContentRequest, ListenerSendResponse, PageInfo, SwResponse, IConfig } from '~/types'

const DEFAULT_STARGRAM_HUB = 'https://stargram.cc'
let stopSyncMarks = false
Expand All @@ -29,6 +29,15 @@ let fetchGithubStarredEnd = true
const maxConcurrent = 3 // openai rate limit
const maxGithubPerPage = 100

function getConfigKV(config: Record<string, IConfig>) {
const _obj: Record<string, any> = {}
Object.keys(config).forEach((x) => {
_obj[x] = config[x].value
})

return Object.keys(_obj).length ? _obj : null
}

async function sendSavedStatus(res: SwResponse) {
chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => {
if (tabs.length && res.tabId && tabs[0].id && res.tabId !== tabs[0].id) {
Expand Down Expand Up @@ -325,15 +334,16 @@ async function saveToDB(pageInfo: PageInfo): Promise<SwResponse> {
const url = pageInfo.webUrl
const webInfo = new WebInfoByApi({
stargramHub,
browserlessToken: config.webInfo.config.browserlessToken,
browserlessToken: config.webInfo.config?.browserlessToken?.value,
})

const webCard = new WebCardByApi({ stargramHub })

const llmConfig = getConfigKV(config.llm.config)
const llm = new (llmInfo[config.llm.select as TLLM])(llmConfig)

const llm = new (llmInfo[config.llm.select as TLLM])(config.llm.config)

const dataStorage = new (storageInfo.DataStorage[config.dataStorage.select])(config.dataStorage.config)
const dataStorageConfig = getConfigKV(config.dataStorage.config)
const dataStorage = new (storageInfo.DataStorage[config.dataStorage.select])(dataStorageConfig)

const embeddingsInfo: EmbeddingsInfo = llm.embeddingsInfo()
const metaData: VectorMetaData = {
Expand All @@ -342,7 +352,8 @@ async function saveToDB(pageInfo: PageInfo): Promise<SwResponse> {
botId: config.app.botId,
userId: config.app.userId,
}
const vectorStorage = new (storageInfo.VectorStorage[config.vectorStorage.select])({ ...config.vectorStorage.config, embeddingsInfo, metaData })
const vectorStorageConfig = getConfigKV(config.vectorStorage.config)
const vectorStorage = new (storageInfo.VectorStorage[config.vectorStorage.select])({ ...vectorStorageConfig, embeddingsInfo, metaData })

const chain = new SaveWebInfoChain({
webInfo,
Expand Down Expand Up @@ -427,7 +438,8 @@ async function checkStarredStatus(url: string, tabId: number): Promise<SwRespons
let storageId = ''
if (userConfig) {
const config = JSON.parse(userConfig)
const dataStorage = new (storageInfo.DataStorage[config.dataStorage.select])(config.dataStorage.config)
const dataStorageConfig = getConfigKV(config.dataStorage.config)
const dataStorage = new (storageInfo.DataStorage[config.dataStorage.select])(dataStorageConfig)
try {
const res = await dataStorage.query(url)
if (res) {
Expand Down
3 changes: 2 additions & 1 deletion app/extension/chrome/src/components/SelectConfig.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import type { IConfig } from '../types'
interface Props {
data: {
select: string
config: Record<string, { label: string; require: boolean; value: any }>
config: Record<string, IConfig>
}
}
const props = defineProps<Props>()
Expand Down
1 change: 0 additions & 1 deletion app/extension/chrome/src/popup/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ async function onSaveClick() {
function saveSettings() {
if (userConfig.value) {
console.log(userConfig.value)
chrome.storage.sync.set(
{
userConfig: JSON.stringify(userConfig.value)
Expand Down
7 changes: 7 additions & 0 deletions app/extension/chrome/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ interface ContentRequest {

type ListenerSendResponse = (response: ListenerResponse) => void

interface IConfig {
label: string
value: string
require: boolean
}

export type {
PageData,
ListenerResponse,
Expand All @@ -67,4 +73,5 @@ export type {
GithubRepoMeta,
WebLoaderUrls,
PageInfo,
IConfig,
}

1 comment on commit 0ec9f38

@vercel
Copy link

@vercel vercel bot commented on 0ec9f38 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

star-nexus – ./

star-nexus.vercel.app
star-nexus-larchliu.vercel.app
star-nexus-git-main-larchliu.vercel.app

Please sign in to comment.