Skip to content

Commit 74187af

Browse files
committed
refine
1 parent 335c293 commit 74187af

File tree

1 file changed

+28
-14
lines changed
  • packages/tiny-agents/src

1 file changed

+28
-14
lines changed

packages/tiny-agents/src/cli.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,16 @@ async function main() {
114114

115115
const { configJson, prompt } = await loadConfigFrom(loadFrom);
116116

117-
const ConfigSchema = z.object({
118-
model: z.string(),
119-
provider: z.enum(PROVIDERS_OR_POLICIES).optional(),
120-
endpointUrl: z.string().optional(),
121-
servers: z.array(ServerConfigSchema),
122-
});
117+
const ConfigSchema = z
118+
.object({
119+
model: z.string(),
120+
provider: z.enum(PROVIDERS_OR_POLICIES).optional(),
121+
endpointUrl: z.string().optional(),
122+
servers: z.array(ServerConfigSchema),
123+
})
124+
.refine((data) => data.provider !== undefined || data.endpointUrl !== undefined, {
125+
message: "At least one of 'provider' or 'endpointUrl' is required",
126+
});
123127

124128
let config: z.infer<typeof ConfigSchema>;
125129
try {
@@ -130,14 +134,24 @@ async function main() {
130134
process.exit(1);
131135
}
132136

133-
const agent = new Agent({
134-
provider: config.provider,
135-
endpointUrl: config.endpointUrl,
136-
model: config.model,
137-
apiKey: process.env.HF_TOKEN,
138-
servers: config.servers,
139-
prompt,
140-
});
137+
const agent = new Agent(
138+
config.endpointUrl
139+
? {
140+
endpointUrl: config.endpointUrl,
141+
model: config.model,
142+
apiKey: process.env.HF_TOKEN,
143+
servers: config.servers,
144+
prompt,
145+
}
146+
: {
147+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
148+
provider: config.provider!,
149+
model: config.model,
150+
apiKey: process.env.HF_TOKEN,
151+
servers: config.servers,
152+
prompt,
153+
}
154+
);
141155

142156
if (command === "serve") {
143157
error(`Serve is not implemented yet, coming soon!`);

0 commit comments

Comments
 (0)