Log view / select event in admin monaco editor (#17)

* Add view event

* Trigger view event and select event in monaco editor

* Set view / select event in tabby server
add-more-languages
Meng Zhang 2023-03-26 23:31:47 +08:00 committed by GitHub
parent 1c3ec20f93
commit d209e89b72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 20 deletions

View File

@ -1,9 +1,9 @@
{ {
"files": { "files": {
"main.js": "./static/js/main.c86c579e.js", "main.js": "./static/js/main.15818978.js",
"index.html": "./index.html" "index.html": "./index.html"
}, },
"entrypoints": [ "entrypoints": [
"static/js/main.c86c579e.js" "static/js/main.15818978.js"
] ]
} }

View File

@ -1 +1 @@
<!doctype html><html lang="en"><head><title>Streamlit Component</title><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Streamlit Component"/><link rel="stylesheet" href="bootstrap.min.css"/><script defer="defer" src="./static/js/main.c86c579e.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html> <!doctype html><html lang="en"><head><title>Streamlit Component</title><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Streamlit Component"/><link rel="stylesheet" href="bootstrap.min.css"/><script defer="defer" src="./static/js/main.15818978.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

View File

@ -23,6 +23,12 @@ export default function MonacoEditor() {
{ pattern: "**" }, { pattern: "**" },
new CompletionProvider(monaco) new CompletionProvider(monaco)
) )
monaco.editor.registerCommand(
"acceptTabbyCompletion",
(accessor, id, index) => {
logAction(id, index, "select")
}
)
}, [monaco]) }, [monaco])
return ( return (
@ -82,7 +88,11 @@ class CompletionProvider {
position.column position.column
) )
const items = this.toInlineCompletions(response.data, replaceRange) const items = this.toInlineCompletions(response.data, replaceRange)
return Promise.resolve({ items }) return Promise.resolve({ data: response.data, items })
}
handleItemDidShow(completions, item) {
logAction(completions.data.id, item.choice.index, "view")
} }
freeInlineCompletions() {} freeInlineCompletions() {}
@ -121,12 +131,15 @@ class CompletionProvider {
toInlineCompletions(value, range) { toInlineCompletions(value, range) {
return ( return (
value.choices value.choices.map((choice) => ({
.map((choice) => choice.text) range,
.map((text: string) => ({ text: choice.text,
range, choice,
text, command: {
})) || [] id: "acceptTabbyCompletion",
arguments: [value.id, choice.index],
},
})) || []
) )
} }
@ -142,3 +155,7 @@ class CompletionProvider {
return ")]}".indexOf(suffix) > -1 return ")]}".indexOf(suffix) > -1
} }
} }
function logAction(id, index, event) {
axios.post(`${TabbyServerURL}/v1/completions/${id}/choices/${index}/${event}`)
}

View File

@ -45,7 +45,13 @@ async def completions(request: CompletionRequest) -> CompletionResponse:
return response return response
@app.post("/v1/completions/{id}/choices/{index}/selection") @app.post("/v1/completions/{id}/choices/{index}/view")
async def selection(id: str, index: int) -> JSONResponse: async def view(id: str, index: int) -> JSONResponse:
events.log_selection(id, index) events.log_view(id, index)
return JSONResponse(content="ok")
@app.post("/v1/completions/{id}/choices/{index}/select")
async def select(id: str, index: int) -> JSONResponse:
events.log_select(id, index)
return JSONResponse(content="ok") return JSONResponse(content="ok")

View File

@ -41,6 +41,11 @@ def log_completions(
logger.info(event.json()) logger.info(event.json())
def log_selection(id: str, index: int) -> None: def log_view(id: str, index: int) -> None:
event = models.SelectionEvent.build(id, index) event = models.ChoiceEvent.build_view(id, index)
logger.info(event.json())
def log_select(id: str, index: int) -> None:
event = models.ChoiceEvent.build_select(id, index)
logger.info(event.json()) logger.info(event.json())

View File

@ -43,10 +43,14 @@ class CompletionEvent(Event):
) )
class SelectionEvent(Event): class ChoiceEvent(Event):
completion_id: str completion_id: str
choice_index: int choice_index: int
@classmethod @classmethod
def build(cls, id, index): def build_view(cls, id, index):
return cls(type="selection", completion_id=id, choice_index=index) return cls(type="view", completion_id=id, choice_index=index)
@classmethod
def build_select(cls, id, index):
return cls(type="select", completion_id=id, choice_index=index)