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 serveradd-more-languages
parent
1c3ec20f93
commit
d209e89b72
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"files": {
|
||||
"main.js": "./static/js/main.c86c579e.js",
|
||||
"main.js": "./static/js/main.15818978.js",
|
||||
"index.html": "./index.html"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/js/main.c86c579e.js"
|
||||
"static/js/main.15818978.js"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -23,6 +23,12 @@ export default function MonacoEditor() {
|
|||
{ pattern: "**" },
|
||||
new CompletionProvider(monaco)
|
||||
)
|
||||
monaco.editor.registerCommand(
|
||||
"acceptTabbyCompletion",
|
||||
(accessor, id, index) => {
|
||||
logAction(id, index, "select")
|
||||
}
|
||||
)
|
||||
}, [monaco])
|
||||
|
||||
return (
|
||||
|
|
@ -82,7 +88,11 @@ class CompletionProvider {
|
|||
position.column
|
||||
)
|
||||
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() {}
|
||||
|
|
@ -121,11 +131,14 @@ class CompletionProvider {
|
|||
|
||||
toInlineCompletions(value, range) {
|
||||
return (
|
||||
value.choices
|
||||
.map((choice) => choice.text)
|
||||
.map((text: string) => ({
|
||||
value.choices.map((choice) => ({
|
||||
range,
|
||||
text,
|
||||
text: choice.text,
|
||||
choice,
|
||||
command: {
|
||||
id: "acceptTabbyCompletion",
|
||||
arguments: [value.id, choice.index],
|
||||
},
|
||||
})) || []
|
||||
)
|
||||
}
|
||||
|
|
@ -142,3 +155,7 @@ class CompletionProvider {
|
|||
return ")]}".indexOf(suffix) > -1
|
||||
}
|
||||
}
|
||||
|
||||
function logAction(id, index, event) {
|
||||
axios.post(`${TabbyServerURL}/v1/completions/${id}/choices/${index}/${event}`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,13 @@ async def completions(request: CompletionRequest) -> CompletionResponse:
|
|||
return response
|
||||
|
||||
|
||||
@app.post("/v1/completions/{id}/choices/{index}/selection")
|
||||
async def selection(id: str, index: int) -> JSONResponse:
|
||||
events.log_selection(id, index)
|
||||
@app.post("/v1/completions/{id}/choices/{index}/view")
|
||||
async def view(id: str, index: int) -> JSONResponse:
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ def log_completions(
|
|||
logger.info(event.json())
|
||||
|
||||
|
||||
def log_selection(id: str, index: int) -> None:
|
||||
event = models.SelectionEvent.build(id, index)
|
||||
def log_view(id: str, index: int) -> None:
|
||||
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())
|
||||
|
|
|
|||
|
|
@ -43,10 +43,14 @@ class CompletionEvent(Event):
|
|||
)
|
||||
|
||||
|
||||
class SelectionEvent(Event):
|
||||
class ChoiceEvent(Event):
|
||||
completion_id: str
|
||||
choice_index: int
|
||||
|
||||
@classmethod
|
||||
def build(cls, id, index):
|
||||
return cls(type="selection", completion_id=id, choice_index=index)
|
||||
def build_view(cls, id, 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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue