Skip to content

Commit

Permalink
Revert "merge work from responses to sessions into"
Browse files Browse the repository at this point in the history
This reverts commit 48f41ca.
  • Loading branch information
blackforestboi committed May 13, 2024
1 parent 48f41ca commit a72d97f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 42 deletions.
10 changes: 10 additions & 0 deletions src/sidebar/annotations-sidebar/components/AnnotationsSidebar.tsx
Expand Up @@ -2011,6 +2011,16 @@ export class AnnotationsSidebar extends React.Component<
createNewNoteFromAISummary={
this.props.createNewNoteFromAISummary
}
isAIChatAllowed={async () => {
const isAllowed = await AIActionAllowed(
this.props.browserAPIs,
this.props.analyticsBG,
this.props.hasKey,
false,
)

return isAllowed
}}
getYoutubePlayer={this.props.getYoutubePlayer}
sidebarEvents={this.props.events}
aiChatStateExternal={{
Expand Down
29 changes: 29 additions & 0 deletions src/sidebar/annotations-sidebar/containers/logic.ts
Expand Up @@ -52,8 +52,10 @@ import {
import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types'
import type {
PageAnnotationsCacheEvents,
RGBAColor,
UnifiedAnnotation,
UnifiedList,
UnifiedListForCache,
} from 'src/annotations/cache/types'
import * as cacheUtils from 'src/annotations/cache/utils'
import {
Expand Down Expand Up @@ -102,6 +104,8 @@ import { HIGHLIGHT_COLORS_DEFAULT } from '@worldbrain/memex-common/lib/common-ui
import { RGBAobjectToString } from '@worldbrain/memex-common/lib/common-ui/components/highlightColorPicker/utils'
import type { PDFDocumentProxy } from 'pdfjs-dist/types/display/api'
import { extractDataFromPDFDocument } from '@worldbrain/memex-common/lib/page-indexing/content-extraction/extract-pdf-content'
import type { PkmSyncInterface } from 'src/pkm-integrations/background/types'
import { RemoteCopyPasterInterface } from 'src/copy-paster/background/types'
import { defaultOrderableSorter } from '@worldbrain/memex-common/lib/utils/item-ordering'
import { copyToClipboard } from 'src/annotations/content_script/utils'
import Raven from 'raven-js'
Expand Down Expand Up @@ -3276,6 +3280,31 @@ export class SidebarContainerLogic extends UILogic<
return response
}

// removeAISuggestion: EventHandler<'removeAISuggestion'> = async ({
// event,
// previousState,
// }) => {
// let suggestions = this.AIpromptSuggestions

// const suggestionToRemove = event.suggestion
// const newSuggestions = suggestions.filter(
// (item) => item.prompt !== suggestionToRemove,
// )

// const newSuggestionsToSave = newSuggestions.map((item) => item.prompt)

// await this.syncSettings.openAI.set(
// 'promptSuggestions',
// newSuggestionsToSave,
// )

// this.emitMutation({
// AIsuggestions: { $set: newSuggestions },
// })

// this.AIpromptSuggestions = newSuggestions
// }

addedKey: EventHandler<'addedKey'> = ({ event, previousState }) => {
this.emitMutation({
hasKey: {
Expand Down
59 changes: 20 additions & 39 deletions src/summarization-llm/background/index.ts
Expand Up @@ -58,7 +58,6 @@ export interface summarizePageBackgroundOptions {

export default class SummarizeBackground {
remoteFunctions: SummarizationInterface<'provider'>
tabIDsWithRunningAISessions: Set<number> = new Set()

private summarizationService = new SummarizationService({
serviceURL:
Expand All @@ -79,46 +78,28 @@ export default class SummarizeBackground {
makeRemotelyCallable(this.remoteFunctions, { insertExtraArg: true })
}

async saveActiveTabId() {
this.options.browserAPIs.tabs.onRemoved.removeListener(this.onTabClosed)
const tabs = await this.options.browserAPIs.tabs.query({
active: true,
currentWindow: true,
})
if (tabs.length > 0) {
const activeTabId = tabs[0].id
console.log(`Active tab ID: ${activeTabId}`)
if (activeTabId !== undefined) {
this.tabIDsWithRunningAISessions.add(activeTabId)
this.options.browserAPIs.tabs.onRemoved.addListener(
this.onTabClosed,
)
}
}
}
async saveActiveTabId(hasKey: boolean, AImodel: AImodels) {
const isAlreadySaved = await updateTabAISessions(
this.options.browserAPIs,
)

onTabClosed = (tabId, removeInfo) => {
if (this.tabIDsWithRunningAISessions.has(tabId)) {
this.tabIDsWithRunningAISessions.delete(tabId)
this.onTabClosedTriggerFunction(tabId) // Assuming this function exists
if (isAlreadySaved) {
return
} else {
await AIActionAllowed(
this.options.browserAPIs,
this.options.analyticsBG,
hasKey,
true,
AImodel,
)
}
}

// Example of a function triggered when a tab from the set is closed
async onTabClosedTriggerFunction(tabId: number) {
console.log(
`Tab with ID ${tabId} was closed and had an active AI session.`,
)

await AIActionAllowed(
this.options.browserAPIs,
this.options.analyticsBG,
false,
true,
'gpt-3',
)
this.options.browserAPIs.tabs.onRemoved.addListener(this.onTabClosed)
}

// Additional logic here
onTabClosed = (tabId, removeInfo) => {
updateTabAISessions(this.options.browserAPIs, tabId)
}

startPageSummaryStream: SummarizationInterface<
Expand All @@ -136,15 +117,15 @@ export default class SummarizeBackground {
promptData,
},
) => {
await this.saveActiveTabId()
await this.saveActiveTabId(apiKey?.length > 0, AImodel)

let isAllowed = null

isAllowed = await AIActionAllowed(
this.options.browserAPIs,
this.options.analyticsBG,
apiKey?.length > 0,
false,
true,
AImodel,
)

Expand Down
7 changes: 4 additions & 3 deletions src/util/subscriptions/pageCountIndicator.tsx
Expand Up @@ -7,7 +7,8 @@ import styled, { css } from 'styled-components'
import browser from 'webextension-polyfill'
import {
COUNTER_STORAGE_KEY,
DEFAULT_POWERUP_LIMITS,
DEFAULT_COUNTER_STORAGE_KEY,
FREE_PLAN_LIMIT,
} from '@worldbrain/memex-common/lib/subscriptions/constants'
import { AnnotationsSidebarInPageEventEmitter } from 'src/sidebar/annotations-sidebar/types'

Expand Down Expand Up @@ -36,7 +37,7 @@ export class BlockCounterIndicator extends React.Component<Props> {
if (!result[COUNTER_STORAGE_KEY].pU.bookmarksPowerUp) {
this.setState({
shouldShow: true,
totalCount: DEFAULT_POWERUP_LIMITS.bookmarksPowerUp,
totalCount: FREE_PLAN_LIMIT,
currentCount: result[COUNTER_STORAGE_KEY].c,
})
browser.storage.onChanged.addListener((changes) =>
Expand All @@ -57,7 +58,7 @@ export class BlockCounterIndicator extends React.Component<Props> {
if (changes[COUNTER_STORAGE_KEY]?.newValue != null) {
this.setState({
currentCount: changes[COUNTER_STORAGE_KEY].newValue.c,
totalCount: DEFAULT_POWERUP_LIMITS.bookmarksPowerUp,
totalCount: FREE_PLAN_LIMIT,
})
}

Expand Down

0 comments on commit a72d97f

Please sign in to comment.