Merge pull request #97 from devchat-ai/feat/add-event-operation-data
feat: Add message tracking and event operation data
This commit is contained in:
commit
da327b8add
@ -85,6 +85,15 @@ class APIUtil {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateCurrentMessageId() {
|
||||||
|
this.currentMessageId = `msg-${uuidv4()}`;
|
||||||
|
return this.currentMessageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentMessageId() {
|
||||||
|
return this.currentMessageId;
|
||||||
|
}
|
||||||
|
|
||||||
async createMessage(message: MessageData, messageId?: string) {
|
async createMessage(message: MessageData, messageId?: string) {
|
||||||
// 如果 messageId 为空,则使用 uuid 生成新的 ID
|
// 如果 messageId 为空,则使用 uuid 生成新的 ID
|
||||||
var newMessageId = messageId || `msg-${uuidv4()}`;
|
var newMessageId = messageId || `msg-${uuidv4()}`;
|
||||||
|
@ -101,7 +101,7 @@ const ChatMark = ({
|
|||||||
value: JSON.stringify(formData),
|
value: JSON.stringify(formData),
|
||||||
ide: platform,
|
ide: platform,
|
||||||
language: info?.extension || info?.path?.split('.').pop()
|
language: info?.extension || info?.path?.split('.').pop()
|
||||||
}))
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
@ -112,7 +112,7 @@ const ChatMark = ({
|
|||||||
name: "cancel",
|
name: "cancel",
|
||||||
ide: platform,
|
ide: platform,
|
||||||
language: info?.extension || info?.path?.split('.').pop()
|
language: info?.extension || info?.path?.split('.').pop()
|
||||||
}))
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleButtonClick = ({ event, index }) => {
|
const handleButtonClick = ({ event, index }) => {
|
||||||
|
@ -21,7 +21,10 @@ const CodeCopyButton = ({ code, language, platform }) => {
|
|||||||
{({ copied, copy }) => (
|
{({ copied, copy }) => (
|
||||||
<IconButton label={copied ? 'Copied' : 'Copy'} color={copied ? 'teal' : 'gray'} onClick={() => {
|
<IconButton label={copied ? 'Copied' : 'Copy'} color={copied ? 'teal' : 'gray'} onClick={() => {
|
||||||
copy();
|
copy();
|
||||||
APIUtil.createEvent({name: 'copy', value: 'copy', language: language, ide: platform})
|
APIUtil.createEvent(
|
||||||
|
{name: 'copy', value: code, language: language, ide: platform},
|
||||||
|
APIUtil.getCurrentMessageId()
|
||||||
|
);
|
||||||
}}>
|
}}>
|
||||||
{copied ? <IconCheck size="1rem" /> : <IconCopy size="1rem" />}
|
{copied ? <IconCheck size="1rem" /> : <IconCopy size="1rem" />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@ -48,7 +51,10 @@ const DiffButton = ({ code, language, platform }) => {
|
|||||||
command: e,
|
command: e,
|
||||||
content: selectedCode
|
content: selectedCode
|
||||||
});
|
});
|
||||||
APIUtil.createEvent({name: e, value: e, language: language, ide: platform});
|
APIUtil.createEvent(
|
||||||
|
{name: e, value: selectedCode, language: language, ide: platform},
|
||||||
|
APIUtil.getCurrentMessageId()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -65,7 +71,10 @@ const EditApplyButton = ({ code, language, platform }) => {
|
|||||||
content: code,
|
content: code,
|
||||||
autoedit: true
|
autoedit: true
|
||||||
});
|
});
|
||||||
APIUtil.createEvent({name: "edit_apply", value: "edit_apply", language: language, ide: platform});
|
APIUtil.createEvent(
|
||||||
|
{name: "edit_apply", value: code, language: language, ide: platform},
|
||||||
|
APIUtil.getCurrentMessageId()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<IconButton label='Apply Code' onClick={handleClick}>
|
<IconButton label='Apply Code' onClick={handleClick}>
|
||||||
@ -81,7 +90,10 @@ const CodeApplyButton = ({ code, language, platform }) => {
|
|||||||
command: e,
|
command: e,
|
||||||
content: code
|
content: code
|
||||||
});
|
});
|
||||||
APIUtil.createEvent({name: e, value: e, language: language, ide: platform});
|
APIUtil.createEvent(
|
||||||
|
{name: e, value: code, language: language, ide: platform},
|
||||||
|
APIUtil.getCurrentMessageId()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<IconButton label='Insert Code' onClick={handleClick}>
|
<IconButton label='Insert Code' onClick={handleClick}>
|
||||||
@ -97,7 +109,10 @@ const FileApplyButton = ({ code, language, platform }) => {
|
|||||||
command: e,
|
command: e,
|
||||||
content: code
|
content: code
|
||||||
});
|
});
|
||||||
APIUtil.createEvent({name: e, value: e, language: language, ide: platform});
|
APIUtil.createEvent(
|
||||||
|
{name: e, value: code, language: language, ide: platform},
|
||||||
|
APIUtil.getCurrentMessageId()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<IconButton label='Replace File' onClick={handleClick}>
|
<IconButton label='Replace File' onClick={handleClick}>
|
||||||
@ -115,7 +130,10 @@ const NewFileButton = ({ code, language, platform }) => {
|
|||||||
language: language,
|
language: language,
|
||||||
content: code
|
content: code
|
||||||
});
|
});
|
||||||
APIUtil.createEvent({name: e, value: e, language: language, ide: platform});
|
APIUtil.createEvent(
|
||||||
|
{name: e, value: code, language: language, ide: platform},
|
||||||
|
APIUtil.getCurrentMessageId()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<IconButton label='Create New File' onClick={handleClick}>
|
<IconButton label='Create New File' onClick={handleClick}>
|
||||||
|
@ -113,8 +113,11 @@ const MessageMarkdown = observer((props: MessageMarkdownProps) => {
|
|||||||
const selection = window.getSelection()?.toString();
|
const selection = window.getSelection()?.toString();
|
||||||
console.log("Copied: ", selection);
|
console.log("Copied: ", selection);
|
||||||
const e = 'manual_copy';
|
const e = 'manual_copy';
|
||||||
APIUtil.createEvent({name: e, value: selection, language: language, ide: platform})
|
APIUtil.createEvent(
|
||||||
}
|
{name: e, value: selection, language: language, ide: platform},
|
||||||
|
APIUtil.getCurrentMessageId()
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let previousNode: any = null;
|
let previousNode: any = null;
|
||||||
|
@ -7,6 +7,7 @@ import i18next from "i18next";
|
|||||||
import APIUtil from "@/util/APIUtil";
|
import APIUtil from "@/util/APIUtil";
|
||||||
import IDEServiceUtil from "@/util/IDEServiceUtil";
|
import IDEServiceUtil from "@/util/IDEServiceUtil";
|
||||||
import { ASSISTANT_DISPLAY_NAME } from "@/util/constants";
|
import { ASSISTANT_DISPLAY_NAME } from "@/util/constants";
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
interface Context {
|
interface Context {
|
||||||
content: string;
|
content: string;
|
||||||
@ -186,13 +187,14 @@ export const ChatStore = types
|
|||||||
const supportedCommands = new Set(rootStore.input.commandMenus.map(x => x.name));
|
const supportedCommands = new Set(rootStore.input.commandMenus.map(x => x.name));
|
||||||
let command = text.startsWith("/") ? text.split(" ", 1)[0] : null;
|
let command = text.startsWith("/") ? text.split(" ", 1)[0] : null;
|
||||||
command = command && supportedCommands.has(command.slice(1)) ? command : null;
|
command = command && supportedCommands.has(command.slice(1)) ? command : null;
|
||||||
|
|
||||||
IDEServiceUtil.getCurrentFileInfo().then(info => APIUtil.createMessage({
|
IDEServiceUtil.getCurrentFileInfo().then(info => APIUtil.createMessage({
|
||||||
content: text,
|
content: text,
|
||||||
command: command,
|
command: command,
|
||||||
model: chatModel,
|
model: chatModel,
|
||||||
language: info?.extension || info?.path?.split(".").pop(),
|
language: info?.extension || info?.path?.split(".").pop(),
|
||||||
ide: platform === "idea" ? "intellij" : platform
|
ide: platform === "idea" ? "intellij" : platform
|
||||||
}));
|
}, APIUtil.updateCurrentMessageId()));
|
||||||
};
|
};
|
||||||
|
|
||||||
const helpMessage = (originalMessage = false) => {
|
const helpMessage = (originalMessage = false) => {
|
||||||
@ -392,6 +394,13 @@ Thinking...
|
|||||||
} else {
|
} else {
|
||||||
self.messages[messagesLength - 1].message = message;
|
self.messages[messagesLength - 1].message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send event to server
|
||||||
|
const platform = process.env.platform === "idea" ? "intellij" : process.env.platform;
|
||||||
|
APIUtil.createEvent(
|
||||||
|
{name: 'stopGenerating', value: message, language: "unknow", ide: platform},
|
||||||
|
APIUtil.getCurrentMessageId()
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
newMessage: (message: IMessage) => {
|
newMessage: (message: IMessage) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user