File tree Expand file tree Collapse file tree 4 files changed +32
-36
lines changed
Expand file tree Collapse file tree 4 files changed +32
-36
lines changed Original file line number Diff line number Diff line change @@ -36,3 +36,4 @@ export * from './utils/errorToString.js';
3636export * from './utils/logger.js' ;
3737export * from './utils/mockLogger.js' ;
3838export * from './utils/stringifyLimited.js' ;
39+ export * from './utils/userPrompt.js' ;
Original file line number Diff line number Diff line change 1- import * as readline from 'readline' ;
2-
3- import chalk from 'chalk' ;
41import { z } from 'zod' ;
52import { zodToJsonSchema } from 'zod-to-json-schema' ;
63
74import { Tool } from '../../core/types.js' ;
5+ import { userPrompt } from '../../utils/userPrompt.js' ;
86
97const parameterSchema = z . object ( {
108 prompt : z . string ( ) . describe ( 'The prompt message to display to the user' ) ,
@@ -23,26 +21,10 @@ export const userPromptTool: Tool<Parameters, ReturnType> = {
2321 execute : async ( { prompt } , { logger } ) => {
2422 logger . verbose ( `Prompting user with: ${ prompt } ` ) ;
2523
26- const rl = readline . createInterface ( {
27- input : process . stdin ,
28- output : process . stdout ,
29- terminal : true ,
30- } ) ;
31-
32- // Disable the readline interface's internal input processing
33- if ( rl . terminal ) {
34- process . stdin . setRawMode ( false ) ;
35- }
36-
37- const response = await new Promise < string > ( ( resolve ) => {
38- rl . question ( chalk . green ( prompt + ' ' ) , ( answer ) => {
39- resolve ( answer ) ;
40- } ) ;
41- } ) ;
24+ const response = await userPrompt ( prompt ) ;
4225
4326 logger . verbose ( `Received user response: ${ response } ` ) ;
4427
45- rl . close ( ) ;
4628 return response ;
4729 } ,
4830 logParameters : ( ) => { } ,
Original file line number Diff line number Diff line change 1+ import * as readline from 'readline' ;
2+
3+ import chalk from 'chalk' ;
4+
5+ export const userPrompt = async ( prompt : string ) : Promise < string > => {
6+ const rl = readline . createInterface ( {
7+ input : process . stdin ,
8+ output : process . stdout ,
9+ terminal : true ,
10+ } ) ;
11+
12+ try {
13+ // Disable the readline interface's internal input processing
14+ if ( rl . terminal ) {
15+ process . stdin . setRawMode ( false ) ;
16+ }
17+ return await new Promise < string > ( ( resolve ) => {
18+ rl . question ( chalk . green ( '\n' + prompt + '\n' ) + '\n> ' , ( answer ) => {
19+ resolve ( answer ) ;
20+ } ) ;
21+ } ) ;
22+ } finally {
23+ rl . close ( ) ;
24+ }
25+ } ;
Original file line number Diff line number Diff line change 11import * as fs from 'fs/promises' ;
22import { createInterface } from 'readline/promises' ;
33
4- import chalk from 'chalk' ;
54import {
65 toolAgent ,
76 Logger ,
87 getTools ,
98 getAnthropicApiKeyError ,
109 TokenLevel ,
10+ userPrompt ,
1111} from 'mycoder-agent' ;
1212
1313import { SharedOptions } from '../options.js' ;
@@ -85,21 +85,9 @@ export const command: CommandModule<object, DefaultArgs> = {
8585
8686 // If interactive mode
8787 if ( argv . interactive ) {
88- const readline = createInterface ( {
89- input : process . stdin ,
90- output : process . stdout ,
91- } ) ;
92-
93- try {
94- console . log (
95- chalk . green (
96- "Type your request below or 'help' for usage information. Use Ctrl+C to exit." ,
97- ) ,
98- ) ;
99- prompt = await readline . question ( '\n> ' ) ;
100- } finally {
101- readline . close ( ) ;
102- }
88+ prompt = await userPrompt (
89+ "Type your request below or 'help' for usage information. Use Ctrl+C to exit." ,
90+ ) ;
10391 } else if ( ! prompt ) {
10492 // Use command line prompt if provided
10593 prompt = argv . prompt ;
You can’t perform that action at this time.
0 commit comments