11#!/usr/bin/env node
22import { dirname , join } from "node:path" ;
33import { parseArgs } from "node:util" ;
4- import { readFile } from "node:fs/promises" ;
4+ import { lstat , readFile } from "node:fs/promises" ;
55import { z } from "zod" ;
66import { PROVIDERS_OR_POLICIES } from "@huggingface/inference" ;
77import { Agent } from "@huggingface/mcp-client" ;
@@ -36,11 +36,29 @@ const FILENAME_PROMPT = "PROMPT.md";
3636
3737async function loadConfigFrom ( loadFrom : string ) : Promise < { configJson: string ; prompt ? : string } > {
3838 try {
39- /// First try it as a local directory path, then we will try as a path inside the repo itself
39+ /// First try it as a local file path, then as a local directory , then we will try as a path inside the repo itself
4040 return {
4141 configJson : await readFile ( loadFrom , { encoding : "utf8" } ) ,
4242 } ;
4343 } catch {
44+ if ( ( await lstat ( loadFrom ) ) . isDirectory ( ) ) {
45+ /// local directory
46+ try {
47+ let prompt : string | undefined ;
48+ try {
49+ prompt = await readFile ( join ( loadFrom , FILENAME_PROMPT ) , { encoding : "utf8" } ) ;
50+ } catch {
51+ debug ( `PROMPT.md not found in ${ loadFrom } , continuing without prompt template` ) ;
52+ }
53+ return {
54+ configJson : await readFile ( join ( loadFrom , FILENAME_CONFIG ) , { encoding : "utf8" } ) ,
55+ prompt,
56+ } ;
57+ } catch {
58+ error ( `Config file not found in specified local directory.` ) ;
59+ process . exit ( 1 ) ;
60+ }
61+ }
4462 const srcDir = dirname ( __filename ) ;
4563 const configDir = join ( srcDir , "agents" , loadFrom ) ;
4664 try {
@@ -55,7 +73,7 @@ async function loadConfigFrom(loadFrom: string): Promise<{ configJson: string; p
5573 prompt,
5674 } ;
5775 } catch {
58- error ( `Config file not found! Loading from the HF Hub is not implemented yet` ) ;
76+ error ( `Config file not found in tiny-agents repo ! Loading from the HF Hub is not implemented yet` ) ;
5977 process . exit ( 1 ) ;
6078 }
6179 }
0 commit comments