Skip to content

Commit 0d6fb13

Browse files
authored
feat: remove suppressConfigWarnings from scout (#88)
1 parent 7f00ea6 commit 0d6fb13

File tree

3 files changed

+51
-52
lines changed

3 files changed

+51
-52
lines changed

packages/scout-agent/lib/core.test.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ const newPromise = <T>(timeoutMs: number = 5000) => {
174174
};
175175
};
176176

177-
test("core class name", () => {
178-
// biome-ignore lint/complexity/useLiteralKeys: accessing a private field
179-
expect(Scout["CLASS_NAME"]).toBe(Scout.name);
180-
});
181-
182177
describe("config", async () => {
183178
const findWarningLog = (logs: unknown[]) => {
184179
return logs.find(
@@ -191,23 +186,9 @@ describe("config", async () => {
191186
name: "empty config",
192187
config: {},
193188
assertion: ({ logs }) => {
189+
// No warnings when config is not provided at all
194190
const log = findWarningLog(logs);
195-
expect(log).toBeDefined();
196-
expect(log).toInclude(
197-
"GitHub is not configured. The `appID`, `privateKey`, and `webhookSecret` config fields are undefined."
198-
);
199-
expect(log).toInclude(
200-
"Slack is not configured. The `botToken` and `signingSecret` config fields are undefined."
201-
);
202-
expect(log).toInclude(
203-
"Web search is not configured. The `exaApiKey` config field is undefined."
204-
);
205-
expect(log).toInclude(
206-
"Did you provide all required environment variables?"
207-
);
208-
expect(log).toInclude(
209-
`Alternatively, you can suppress this message by setting \`suppressConfigWarnings\` to \`true\` on \`${Scout.name}\`.`
210-
);
191+
expect(log).toBeUndefined();
211192
},
212193
},
213194
{
@@ -223,27 +204,47 @@ describe("config", async () => {
223204
const log = findWarningLog(logs);
224205
expect(log).toBeDefined();
225206
expect(log).toInclude(
226-
"GitHub is not configured. The `privateKey` and `webhookSecret` config fields are undefined."
207+
"GitHub is not configured. The `privateKey` and `webhookSecret` config fields are undefined. You may remove the `github` config object to suppress this warning."
227208
);
228209
},
229210
},
230211
{
231-
name: "full slack config",
232-
config: { slack: { botToken: "test", signingSecret: "set" } },
212+
name: "multiple partial configs",
213+
config: {
214+
github: {
215+
appID: "set",
216+
privateKey: undefined,
217+
webhookSecret: undefined,
218+
},
219+
slack: {
220+
botToken: undefined,
221+
signingSecret: "set",
222+
},
223+
webSearch: {
224+
exaApiKey: undefined,
225+
},
226+
},
233227
assertion: ({ logs }) => {
234228
const log = findWarningLog(logs);
235229
expect(log).toBeDefined();
236-
expect(log).not.toInclude("Slack is not configured");
230+
expect(log).toInclude(
231+
"GitHub is not configured. The `privateKey` and `webhookSecret` config fields are undefined. You may remove the `github` config object to suppress this warning."
232+
);
233+
expect(log).toInclude(
234+
"Slack is not configured. The `botToken` config field is undefined. You may remove the `slack` config object to suppress this warning."
235+
);
236+
expect(log).toInclude(
237+
"Web search is not configured. The `exaApiKey` config field is undefined. You may remove the `webSearch` config object to suppress this warning."
238+
);
237239
},
238240
},
239241
{
240-
name: "suppress config warnings",
241-
config: {
242-
suppressConfigWarnings: true,
243-
},
242+
name: "full slack config",
243+
config: { slack: { botToken: "test", signingSecret: "set" } },
244244
assertion: ({ logs }) => {
245+
// No warnings when slack config is fully provided
245246
const log = findWarningLog(logs);
246-
expect(log).toBeUndefined();
247+
expect(log).not.toInclude("Slack is not configured");
247248
},
248249
},
249250
],

packages/scout-agent/lib/core.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ const loadConfig = <K extends readonly string[]>(
8888
}
8989
| {
9090
config?: undefined;
91-
warningMessage: string;
91+
warningMessage?: string;
9292
} => {
93+
// If no config provided at all, return without warning
94+
if (input === undefined) {
95+
return {};
96+
}
9397
const missingFields = [];
9498
for (const field of fields) {
9599
if (input?.[field as K[number]] === undefined) {
@@ -131,18 +135,13 @@ export interface ScoutOptions {
131135
webSearch?: ConfigFields<WebSearchConfig>;
132136
compute?: ComputeConfig;
133137
logger?: Logger;
134-
suppressConfigWarnings?: boolean;
135138
}
136139

137140
export class Scout {
138-
// we declare the class name here instead of using the `name` property
139-
// because the latter may be overridden by the bundler
140-
private static CLASS_NAME = "Scout";
141-
private readonly suppressConfigWarnings: boolean;
142141
private readonly agent: blink.Agent<Message>;
143142
private readonly github:
144143
| { config: GitHubConfig; warningMessage?: undefined }
145-
| { config?: undefined; warningMessage: string };
144+
| { config?: undefined; warningMessage?: string };
146145
private readonly slack:
147146
| {
148147
config: SlackConfig;
@@ -154,14 +153,14 @@ export class Scout {
154153
config?: undefined;
155154
app?: undefined;
156155
receiver?: undefined;
157-
warningMessage: string;
156+
warningMessage?: string;
158157
};
159158
private readonly webSearch:
160159
| { config: WebSearchConfig; warningMessage?: undefined }
161-
| { config?: undefined; warningMessage: string };
160+
| { config?: undefined; warningMessage?: string };
162161
private readonly compute:
163162
| { config: ComputeConfig; warningMessage?: undefined }
164-
| { config?: undefined; warningMessage: string };
163+
| { config?: undefined; warningMessage?: string };
165164

166165
private readonly logger: Logger;
167166

@@ -202,11 +201,8 @@ export class Scout {
202201
this.slack = { warningMessage: slackConfigResult.warningMessage };
203202
}
204203
this.webSearch = loadConfig(options.webSearch, ["exaApiKey"] as const);
205-
this.compute = options.compute
206-
? { config: options.compute }
207-
: { warningMessage: "Compute is not configured" };
204+
this.compute = options.compute ? { config: options.compute } : {};
208205
this.logger = options.logger ?? console;
209-
this.suppressConfigWarnings = options.suppressConfigWarnings ?? false;
210206
}
211207

212208
async handleSlackWebhook(request: Request): Promise<Response> {
@@ -237,19 +233,23 @@ export class Scout {
237233
private printConfigWarnings() {
238234
const warnings = [];
239235
if (this.github.warningMessage !== undefined) {
240-
warnings.push(`GitHub is not configured. ${this.github.warningMessage}`);
236+
warnings.push(
237+
`GitHub is not configured. ${this.github.warningMessage} You may remove the \`github\` config object to suppress this warning.`
238+
);
241239
}
242240
if (this.slack.warningMessage !== undefined) {
243-
warnings.push(`Slack is not configured. ${this.slack.warningMessage}`);
241+
warnings.push(
242+
`Slack is not configured. ${this.slack.warningMessage} You may remove the \`slack\` config object to suppress this warning.`
243+
);
244244
}
245245
if (this.webSearch.warningMessage !== undefined) {
246246
warnings.push(
247-
`Web search is not configured. ${this.webSearch.warningMessage}`
247+
`Web search is not configured. ${this.webSearch.warningMessage} You may remove the \`webSearch\` config object to suppress this warning.`
248248
);
249249
}
250250
if (warnings.length > 0) {
251251
this.logger.warn(
252-
`${warnings.join("\n")}\n\nDid you provide all required environment variables?\nAlternatively, you can suppress this message by setting \`suppressConfigWarnings\` to \`true\` on \`${Scout.CLASS_NAME}\`.`
252+
`${warnings.join("\n")}\n\nDid you provide all required environment variables?`
253253
);
254254
}
255255
}
@@ -268,9 +268,7 @@ export class Scout {
268268
providerOptions?: ProviderOptions;
269269
tools: Tools;
270270
} {
271-
if (!this.suppressConfigWarnings) {
272-
this.printConfigWarnings();
273-
}
271+
this.printConfigWarnings();
274272

275273
const slackMetadata = getSlackMetadata(messages);
276274
const respondingInSlack =

packages/scout-agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@blink-sdk/scout-agent",
33
"description": "A general-purpose AI agent with GitHub, Slack, web search, and compute capabilities built on Blink SDK.",
4-
"version": "0.0.3",
4+
"version": "0.0.4",
55
"type": "module",
66
"keywords": [
77
"blink",

0 commit comments

Comments
 (0)