🚧 abort streams
This commit is contained in:
parent
45271211be
commit
e231abb095
3 changed files with 84 additions and 14 deletions
|
|
@ -27,14 +27,14 @@ class CoreMessenger(continueCorePath: String, ideProtocolClient: IdeProtocolClie
|
|||
println("Subprocess exited with code: $exitCode")
|
||||
}
|
||||
|
||||
fun request(messageType: String, data: Any?, onResponse: (String) -> Unit) {
|
||||
val messageId = uuid();
|
||||
fun request(messageType: String, data: Any?, messageId: String?, onResponse: (String) -> Unit) {
|
||||
val id = messageId ?: uuid()
|
||||
val message = gson.toJson(mapOf(
|
||||
"messageId" to messageId,
|
||||
"messageId" to id,
|
||||
"messageType" to messageType,
|
||||
"data" to data
|
||||
))
|
||||
responseListeners[messageId] = onResponse
|
||||
responseListeners[id] = onResponse
|
||||
write(message)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
}
|
||||
|
||||
if (PASS_THROUGH_TO_CORE.contains(messageType)) {
|
||||
continuePluginService.coreMessenger?.request(messageType, data, respond)
|
||||
continuePluginService.coreMessenger?.request(messageType, data, messageId, respond)
|
||||
return@addHandler null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ export class Core {
|
|||
|
||||
// Special
|
||||
on("abort", (msg) => {
|
||||
// TODO
|
||||
this.abortedMessageIds.add(msg.messageId);
|
||||
});
|
||||
|
||||
on("ping", (msg) => {
|
||||
|
|
@ -157,6 +157,84 @@ export class Core {
|
|||
on("llm/streamChat", (msg) =>
|
||||
llmStreamChat(this.configHandler, this.abortedMessageIds, msg)
|
||||
);
|
||||
|
||||
async function* llmStreamComplete(
|
||||
configHandler: ConfigHandler,
|
||||
abortedMessageIds: Set<string>,
|
||||
|
||||
msg: Message<Protocol["llm/streamComplete"][0]>
|
||||
) {
|
||||
const model = await configHandler.llmFromTitle(msg.data.title);
|
||||
const gen = model.streamComplete(
|
||||
msg.data.prompt,
|
||||
msg.data.completionOptions
|
||||
);
|
||||
let next = await gen.next();
|
||||
while (!next.done) {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
next = await gen.return({ completion: "", prompt: "" });
|
||||
break;
|
||||
}
|
||||
yield { content: next.value };
|
||||
next = await gen.next();
|
||||
}
|
||||
|
||||
return { done: true, content: next.value };
|
||||
}
|
||||
|
||||
on("llm/streamComplete", (msg) =>
|
||||
llmStreamComplete(this.configHandler, this.abortedMessageIds, msg)
|
||||
);
|
||||
|
||||
async function* runNodeJsSlashCommand(
|
||||
configHandler: ConfigHandler,
|
||||
abortedMessageIds: Set<string>,
|
||||
msg: Message<Protocol["command/run"][0]>
|
||||
) {
|
||||
const {
|
||||
input,
|
||||
history,
|
||||
modelTitle,
|
||||
slashCommandName,
|
||||
contextItems,
|
||||
params,
|
||||
historyIndex,
|
||||
} = msg.data;
|
||||
|
||||
const config = await configHandler.loadConfig();
|
||||
const llm = await configHandler.llmFromTitle(modelTitle);
|
||||
const slashCommand = config.slashCommands?.find(
|
||||
(sc) => sc.name === slashCommandName
|
||||
);
|
||||
if (!slashCommand) {
|
||||
throw new Error(`Unknown slash command ${slashCommandName}`);
|
||||
}
|
||||
|
||||
for await (const content of slashCommand.run({
|
||||
input,
|
||||
history,
|
||||
llm,
|
||||
contextItems,
|
||||
params,
|
||||
ide,
|
||||
addContextItem: (item) => {
|
||||
// TODO
|
||||
// protocol.request("addContextItem", {
|
||||
// item,
|
||||
// historyIndex,
|
||||
// });
|
||||
},
|
||||
})) {
|
||||
if (content) {
|
||||
yield { content };
|
||||
}
|
||||
}
|
||||
yield { done: true, content: "" };
|
||||
}
|
||||
on("command/run", (msg) =>
|
||||
runNodeJsSlashCommand(this.configHandler, this.abortedMessageIds, msg)
|
||||
);
|
||||
}
|
||||
|
||||
public invoke<T extends keyof Protocol>(
|
||||
|
|
@ -167,11 +245,3 @@ export class Core {
|
|||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* configHandler should be in core? Probably everything should be in core?
|
||||
* - get rc files (define in IpcIde)
|
||||
* - override anonymous telemetry (telemetryAllowed)
|
||||
* - send config to browser whenever it loads (triggers come from IDE so that should happen there)
|
||||
* - access to a "readFile" function (ide.readFile)
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue