MCPcopy Create free account
hub / github.com/Stevenic/codepilot / respond

Method respond

lib/Codepilot.js:97–152  ·  view source on GitHub ↗
(botMessage)

Source from the content-addressed store, hash-verified

95 // Define main chat loop
96 const _that = this;
97 function respond(botMessage) {
98 return __awaiter(this, void 0, void 0, function* () {
99 function completePrompt(input) {
100 return __awaiter(this, void 0, void 0, function* () {
101 // Route users message to wave
102 const result = yield wave.completePrompt(input);
103 switch (result.status) {
104 case 'success':
105 const message = result.message;
106 if (message.function_call) {
107 // Call function and add result to history
108 const entry = _that._functions.get(message.function_call.name);
109 if (entry) {
110 const args = message.function_call.arguments ? JSON.parse(message.function_call.arguments) : {};
111 const result = yield entry.fn(args);
112 wave.addFunctionResultToHistory(message.function_call.name, result);
113 // Call back in with the function result
114 yield completePrompt('');
115 }
116 else {
117 respond(internals_1.Colorize.error(`Function '${message.function_call.name}' was not found.`));
118 }
119 }
120 else {
121 // Call respond to display response and wait for user input
122 yield respond(internals_1.Colorize.output(message.content));
123 }
124 break;
125 default:
126 if (result.message) {
127 yield respond(internals_1.Colorize.error(`${result.status}: ${result.message}`));
128 }
129 else {
130 yield respond(internals_1.Colorize.error(`A result status of '${result.status}' was returned.`));
131 }
132 break;
133 }
134 });
135 }
136 // Show the bots message
137 console.log(botMessage);
138 // Prompt the user for input
139 rl.question('User: ', (input) => __awaiter(this, void 0, void 0, function* () {
140 // Check if the user wants to exit the chat
141 if (input.toLowerCase() === 'exit') {
142 // Close the readline interface and exit the process
143 rl.close();
144 process.exit();
145 }
146 else {
147 // Complete the prompt using the user's input
148 completePrompt(input);
149 }
150 }));
151 });
152 }
153 // Start chat session
154 respond(internals_1.Colorize.output(`Hello, how can I help you?`));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected