mihailik commited on
Commit
9f3e6d3
·
1 Parent(s): bca7b90

Basic prompt reply.

Browse files
src/app/boot-app.js CHANGED
@@ -14,7 +14,6 @@ export var chatLogEditor;
14
  export var chatInputEditor;
15
 
16
 
17
-
18
  export async function bootApp() {
19
  const { chatLog, chatInput } = initHTML();
20
  const { chatLogEditor: chatLogEditorInstance, chatInputEditor: chatInputEditorInstance } = await initMilkdown({
 
14
  export var chatInputEditor;
15
 
16
 
 
17
  export async function bootApp() {
18
  const { chatLog, chatInput } = initHTML();
19
  const { chatLogEditor: chatLogEditorInstance, chatInputEditor: chatInputEditorInstance } = await initMilkdown({
src/app/enter-key.js CHANGED
@@ -1,8 +1,15 @@
1
  // @ts-check
2
 
3
- import { editorViewCtx, parserCtx, serializerCtx, commandsCtx } from '@milkdown/core';
 
 
 
 
 
4
  import { $command, $useKeymap } from '@milkdown/utils';
 
5
  import { outputMessage } from './output-message';
 
6
 
7
  export function makeEnterPlugins() {
8
  // Create a command that sends the current input content to the chat log
@@ -12,10 +19,11 @@ export function makeEnterPlugins() {
12
  const toMarkdown = ctx.get(serializerCtx);
13
  const fromMarkdown = ctx.get(parserCtx);
14
  const markdown = (toMarkdown(view.state.doc) || '').trim();
 
15
  if (markdown) {
16
- const formatted = `user typed:\n> ${markdown.replaceAll('\n', '\n> ')}`;
17
- outputMessage(formatted);
18
  }
 
19
  // Clear input
20
  const emptyDoc = fromMarkdown('');
21
  const tr = view.state.tr.replaceWith(0, view.state.doc.content.size, emptyDoc.content);
@@ -35,5 +43,8 @@ export function makeEnterPlugins() {
35
  },
36
  });
37
 
38
- return [myEnterCommand, myEnterKeymap];
 
 
 
39
  }
 
1
  // @ts-check
2
 
3
+ import {
4
+ commandsCtx,
5
+ editorViewCtx,
6
+ parserCtx,
7
+ serializerCtx
8
+ } from '@milkdown/core';
9
  import { $command, $useKeymap } from '@milkdown/utils';
10
+
11
  import { outputMessage } from './output-message';
12
+ import { handlePrompt } from './handle-prompt';
13
 
14
  export function makeEnterPlugins() {
15
  // Create a command that sends the current input content to the chat log
 
19
  const toMarkdown = ctx.get(serializerCtx);
20
  const fromMarkdown = ctx.get(parserCtx);
21
  const markdown = (toMarkdown(view.state.doc) || '').trim();
22
+
23
  if (markdown) {
24
+ handlePrompt(markdown);
 
25
  }
26
+
27
  // Clear input
28
  const emptyDoc = fromMarkdown('');
29
  const tr = view.state.tr.replaceWith(0, view.state.doc.content.size, emptyDoc.content);
 
43
  },
44
  });
45
 
46
+ return [
47
+ myEnterCommand,
48
+ myEnterKeymap
49
+ ];
50
  }
src/app/handle-prompt.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @ts-check
2
+
3
+ import { outputMessage } from './output-message';
4
+
5
+ export async function handlePrompt(promptMarkdown) {
6
+ const formatted = `user typed:\n> ${promptMarkdown.replaceAll('\n', '\n> ')}`;
7
+ outputMessage(formatted);
8
+
9
+ await new Promise(resolve => setTimeout(resolve, 100));
10
+
11
+ outputMessage('Processing your request...');
12
+
13
+ await new Promise(resolve => setTimeout(resolve, 1000));
14
+ outputMessage(`This is a simulated response to your prompt [${promptMarkdown.length}].`);
15
+ }