Skip to content

Commit

Permalink
File context using @ and large code clean up (#307)
Browse files Browse the repository at this point in the history
* initial commit file mentions

* mention file context and large clean up

* 3.16.0
  • Loading branch information
rjmacarthy authored Sep 6, 2024
1 parent 7e0b3dd commit e8fa1f2
Show file tree
Hide file tree
Showing 47 changed files with 1,455 additions and 972 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twinny",
"displayName": "twinny - AI Code Completion and Chat",
"description": "Locally hosted AI code completion plugin for vscode",
"version": "3.15.13",
"version": "3.16.0",
"icon": "assets/icon.png",
"keywords": [
"code-inference",
Expand Down
18 changes: 0 additions & 18 deletions scripts/install_onyx_model.sh

This file was deleted.

7 changes: 5 additions & 2 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ export const EVENT_NAME = {
twinnyChatMessage: 'twinny-chat-message',
twinnyClickSuggestion: 'twinny-click-suggestion',
twinnyConnectedToSymmetry: 'twinny-connected-to-symmetry',
twinnySymmetryModeles: 'twinny-symmetry-models',
twinnyConnectSymmetry: 'twinny-connect-symmetry',
twinnyDisconnectedFromSymmetry: 'twinny-disconnected-from-symmetry',
twinnyDisconnectSymmetry: 'twinny-disconnect-symmetry',
twinnyEmbedDocuments: 'twinny-embed-documents',
twinnyEnableModelDownload: 'twinny-enable-model-download',
twinnyFetchOllamaModels: 'twinny-fetch-ollama-models',
twinnyFileListRequest: 'twinny-file-list-request',
twinnyFileListResponse: 'twinny-file-list-response',
twinnyGetConfigValue: 'twinny-get-config-value',
twinnyGetGitChanges: 'twinny-get-git-changes',
twinnyGlobalContext: 'twinny-global-context',
Expand All @@ -61,6 +62,7 @@ export const EVENT_NAME = {
twinnyOpenDiff: 'twinny-open-diff',
twinnyRerankThresholdChanged: 'twinny-rerank-threshold-changed',
twinnySendLanguage: 'twinny-send-language',
twinnySymmetryModeles: 'twinny-symmetry-models',
twinnySendLoader: 'twinny-send-loader',
twinnySendSymmetryMessage: 'twinny-send-symmetry-message',
twinnySendSystemMessage: 'twinny-send-system-message',
Expand All @@ -76,7 +78,7 @@ export const EVENT_NAME = {
twinnySetWorkspaceContext: 'twinny-set-workspace-context',
twinnyStopGeneration: 'twinny-stop-generation',
twinnyTextSelection: 'twinny-text-selection',
twinnyWorkspaceContext: 'twinny-workspace-context'
twinnyGetWorkspaceContext: 'twinny-workspace-context'
}

export const TWINNY_COMMAND_NAME = {
Expand All @@ -93,6 +95,7 @@ export const TWINNY_COMMAND_NAME = {
manageProviders: 'twinny.manageProviders',
manageTemplates: 'twinny.manageTemplates',
newConversation: 'twinny.newConversation',
openPanelChat: 'twinny.openPanelChat',
openChat: 'twinny.openChat',
refactor: 'twinny.refactor',
sendTerminalText: 'twinny.sendTerminalText',
Expand Down
70 changes: 39 additions & 31 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface StreamResponse {
prompt_eval_duration: number
eval_count: number
eval_duration: number
type? : string
type?: string
choices: [
{
text: string
Expand All @@ -59,8 +59,9 @@ export interface LanguageType {
languageId: string | undefined
}

export interface ClientMessage<T = string | boolean | Message[]> {
export interface ClientMessage<T = string | boolean | Message[], Y = unknown> {
data?: T
meta?: Y
type?: string
key?: string
}
Expand All @@ -78,9 +79,6 @@ export interface ServerMessage<T = LanguageType> {
export interface Message {
role: string
content: string | undefined
type?: string
language?: LanguageType
error?: boolean
}

export interface Conversation {
Expand Down Expand Up @@ -152,7 +150,7 @@ export interface StreamRequest {
onEnd?: () => void
onStart?: (controller: AbortController) => void
onError?: (error: Error) => void
onData: <T = StreamResponse>(streamResponse: T) => void
onData: <T = StreamResponse>(streamResponse: T) => void
}

export interface UiTabs {
Expand Down Expand Up @@ -218,47 +216,47 @@ export interface InferenceProvider {
}

export interface Peer {
publicKey: Buffer;
write: (value: string) => boolean;
on: (key: string, cb: (data: Buffer) => void) => void;
once: (key: string, cb: (data: Buffer) => void) => void;
writable: boolean;
key: string;
discovery_key: string;
publicKey: Buffer
write: (value: string) => boolean
on: (key: string, cb: (data: Buffer) => void) => void
once: (key: string, cb: (data: Buffer) => void) => void
writable: boolean
key: string
discovery_key: string
}

export interface SymmetryMessage<T> {
key: string;
data: T;
key: string
data: T
}

export type ServerMessageKey = keyof typeof SYMMETRY_DATA_MESSAGE;
export type ServerMessageKey = keyof typeof SYMMETRY_DATA_MESSAGE

export interface SymmetryConnection {
sessionToken?: string
discoveryKey?: string
modelName?: string
name: string;
provider: string;
id: string;
name: string
provider: string
id: string
}

export interface SymmetryModelProvider {
connections: number | null;
data_collection_enabled: number;
id: number;
last_seen: string;
max_connections: number;
model_name: string;
name: string;
online: number;
provider: string;
public: number;
connections: number | null
data_collection_enabled: number
id: number
last_seen: string
max_connections: number
model_name: string
name: string
online: number
provider: string
public: number
}

export interface InferenceRequest {
key: string;
messages: Message[];
key: string
messages: Message[]
}

export interface ChunkOptions {
Expand All @@ -276,3 +274,13 @@ export type EmbeddedDocument = {
vector: number[] | undefined
file: string
}

export interface FileItem {
name: string
path: string
}

export interface MentionType {
name: string
path: string
}
15 changes: 15 additions & 0 deletions src/extension.global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ declare module 'hypercore-crypto' {

export = hyperCoreCrypto
}

declare module '*.css'

declare module '*.css' {
const content: Record<string, string>
export default content
}

interface Window {
acquireVsCodeApi: <T = unknown>() => {
getState: () => T
setState: (data: T) => void
postMessage: (msg: unknown) => void
}
}
32 changes: 16 additions & 16 deletions src/extension/cache.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { PrefixSuffix } from '../common/types'

export class LRUCache<T = string> {
private capacity: number
private cache: Map<string, T | null>
private _capacity: number
private _cache: Map<string, T | null>

constructor(capacity: number) {
this.capacity = capacity
this.cache = new Map()
this._capacity = capacity
this._cache = new Map()
}

getAll(): Map<string, T | null> {
return this.cache
return this._cache
}

get(key: string): T | null | undefined {
if (!this.cache.has(key)) return undefined
if (!this._cache.has(key)) return undefined

const value = this.cache.get(key)
this.cache.delete(key)
const value = this._cache.get(key)
this._cache.delete(key)
if (value !== undefined) {
this.cache.set(key, value)
this._cache.set(key, value)
}
return value
}

delete(key: string): void {
this.cache.delete(key)
this._cache.delete(key)
}

set(key: string, value: T | null): void {
if (this.cache.has(key)) {
this.cache.delete(key)
} else if (this.cache.size === this.capacity) {
const firstKey = this.cache.keys().next().value
this.cache.delete(firstKey)
if (this._cache.has(key)) {
this._cache.delete(key)
} else if (this._cache.size === this._capacity) {
const firstKey = this._cache.keys().next().value
this._cache.delete(firstKey)
}
this.cache.set(key, value)
this._cache.set(key, value)
}

normalize(src: string): string {
Expand Down
Loading

0 comments on commit e8fa1f2

Please sign in to comment.