Skip to content

Commit 9ebc685

Browse files
committed
Fix vibe coding errors...
1 parent 2c4bb34 commit 9ebc685

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

packages/tiny-agents/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"node": ">=18"
2525
},
2626
"source": "index.ts",
27-
"type": "module",
2827
"scripts": {
2928
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
3029
"lint:check": "eslint --ext .cjs,.ts .",

packages/tiny-agents/src/cli.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#!/usr/bin/env node
2-
import * as readline from "node:readline/promises";
3-
import { stdin, stdout } from "node:process";
42
import { dirname, join } from "node:path";
5-
import { fileURLToPath } from "node:url";
63
import { parseArgs } from "node:util";
4+
import { readFile } from "node:fs/promises";
75
import { z } from "zod";
8-
import type { InferenceProviderOrPolicy } from "@huggingface/inference";
96
import { PROVIDERS_OR_POLICIES } from "@huggingface/inference";
10-
import { version as packageVersion } from "../package.json";
11-
import { readFile } from "node:fs/promises";
7+
import { Agent } from "@huggingface/mcp-client";
128
import type { ServerConfig } from "@huggingface/mcp-client";
9+
import { version as packageVersion } from "../package.json";
1310

1411
const USAGE_HELP = `
1512
Usage:
@@ -35,6 +32,22 @@ const FILENAME_CONFIG = "agent.json";
3532
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3633
const FILENAME_PROMPT = "PROMPT.md";
3734

35+
async function loadConfigFrom(loadFrom: string): Promise<string> {
36+
try {
37+
/// First try it as a local directory path, then we will try as a path inside the repo itself
38+
return await readFile(loadFrom, { encoding: "utf8" });
39+
} catch {
40+
const srcDir = dirname(__filename);
41+
const configPath = join(srcDir, "agents", loadFrom, FILENAME_CONFIG);
42+
try {
43+
return await readFile(configPath, { encoding: "utf8" });
44+
} catch {
45+
console.error(`Config file not found! Loading from the HF Hub is not implemented yet`);
46+
process.exit(1);
47+
}
48+
}
49+
}
50+
3851
async function main() {
3952
const {
4053
values: { help, version },
@@ -72,18 +85,11 @@ async function main() {
7285
console.error(`Serve is not implemented yet, coming soon!`);
7386
process.exit(1);
7487
} else {
75-
const srcDir = dirname(fileURLToPath(import.meta.url));
76-
const configPath = join(srcDir, "agents", loadFrom, FILENAME_CONFIG);
77-
let configJson: string;
78-
try {
79-
configJson = await readFile(configPath, { encoding: "utf8" });
80-
} catch {
81-
console.error(`Config file not found!`);
82-
process.exit(1);
83-
}
88+
const configJson = await loadConfigFrom(loadFrom);
89+
8490
const ConfigSchema = z.object({
8591
model: z.string(),
86-
provider: z.enum<InferenceProviderOrPolicy>(PROVIDERS_OR_POLICIES),
92+
provider: z.enum(PROVIDERS_OR_POLICIES),
8793
servers: z.array(z.custom<ServerConfig>()),
8894
});
8995

@@ -98,10 +104,12 @@ async function main() {
98104
const agent = new Agent({
99105
provider: config.provider,
100106
model: config.model,
101-
apiKey: process.env.HF_TOKEN,
107+
apiKey: process.env.HF_TOKEN ?? "",
102108
servers: config.servers,
103109
});
110+
104111
console.log(agent);
112+
105113
// TODO: hook main loop from mcp-client/cli.ts
106114
}
107115
}

0 commit comments

Comments
 (0)