mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-25 07:09:11 +00:00
Merge pull request #4760 from HeyPuter/fix/ai-model-monitor-alert-presentation
fix(ai): make model monitor alerts easier to read
This commit is contained in:
7 files changed
+106
-6
No files matched your search
@@ -62,6 +62,11 @@ there, not as a way to quiet an alarm you haven't diagnosed
|
||||
An extension whose signals are all one tier and channel can fix both in its
|
||||
own local alarm helper instead of repeating them at every call site.
|
||||
|
||||
A call can pass a plain-language `summary` in its options. Slack shows it instead
|
||||
of the diagnostic field grid and keeps only the short reference and region in
|
||||
the footer. The alarm record and other transports retain the diagnostic fields
|
||||
and full alarm id.
|
||||
|
||||
## Channel keys
|
||||
|
||||
`{ channel: '<key>' }` names the area that owns an alarm. Config maps each key
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import { AlarmClient } from '../src/backend/clients/alarm/AlarmClient';
|
||||
import { buildSlackMessage } from '../src/backend/clients/alarm/slack';
|
||||
import { JobScheduler } from '../src/backend/services/jobs/JobScheduler';
|
||||
import { createServer, type Server } from 'node:http';
|
||||
import { afterAll, beforeAll, beforeEach, expect, it, vi } from 'vitest';
|
||||
@@ -94,6 +95,14 @@ it('baselines quietly, persists across instances, and reports additions and remo
|
||||
alert.channel === 'ai_providers' && alert.severity === 'info',
|
||||
),
|
||||
).toBe(true);
|
||||
expect(alerts.map((alert) => alert.summary)).toEqual([
|
||||
'New OpenAI model: new',
|
||||
'Removed OpenAI model: old',
|
||||
]);
|
||||
const message = buildSlackMessage(alerts[0], { serverId: 'sydney' });
|
||||
expect(message.text).toBe(':information_source: New OpenAI model: new');
|
||||
expect(message.attachments[0].fields).toEqual([]);
|
||||
expect(message.attachments[0].footer).not.toContain(alerts[0].id);
|
||||
const restarted = new AIModelMonitorService(
|
||||
{
|
||||
providers: {
|
||||
@@ -138,10 +147,31 @@ it('keeps failures isolated and never includes upstream error text or credential
|
||||
body = { error: 'secret-response' };
|
||||
await monitor.scan(ctx());
|
||||
expect(alerts).toHaveLength(1);
|
||||
expect(alerts[0].summary).toBe('OpenAI model catalog could not be fetched');
|
||||
expect(JSON.stringify(alerts)).not.toContain('secret-response');
|
||||
expect(JSON.stringify(alerts)).not.toContain(`fixture-${seq}`);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'openrouter',
|
||||
'together-ai',
|
||||
'together-image-generation',
|
||||
'together-video-generation',
|
||||
'infron',
|
||||
'neuralwatt',
|
||||
'alibaba',
|
||||
'xai',
|
||||
'xai-image-generation',
|
||||
'cloudflare-image-generation',
|
||||
])(
|
||||
'skips %s because its model catalog includes pricing automatically',
|
||||
async (configKey) => {
|
||||
await service(configKey).scan(ctx());
|
||||
expect(requests).toHaveLength(0);
|
||||
expect(alerts).toHaveLength(0);
|
||||
},
|
||||
);
|
||||
|
||||
it('follows Claude pagination with the correct authentication', async () => {
|
||||
responder = (url) =>
|
||||
url.includes('after_id=first')
|
||||
|
||||
@@ -13,6 +13,7 @@ const MAX_MODELS = 20_000;
|
||||
type Format = 'openai' | 'claude' | 'gemini' | 'elevenlabs' | 'replicate';
|
||||
interface ModelEndpoint {
|
||||
provider: string;
|
||||
name: string;
|
||||
configKeys: string[];
|
||||
baseUrl: string;
|
||||
format?: Format;
|
||||
@@ -21,6 +22,7 @@ interface ModelEndpoint {
|
||||
const ENDPOINTS: ModelEndpoint[] = [
|
||||
{
|
||||
provider: 'openai',
|
||||
name: 'OpenAI',
|
||||
configKeys: [
|
||||
'openai-completion',
|
||||
'openai',
|
||||
@@ -30,15 +32,22 @@ const ENDPOINTS: ModelEndpoint[] = [
|
||||
],
|
||||
baseUrl: 'https://api.openai.com/v1',
|
||||
},
|
||||
{ provider: 'azure', configKeys: ['azure-openai'], baseUrl: '' },
|
||||
{
|
||||
provider: 'azure',
|
||||
name: 'Azure',
|
||||
configKeys: ['azure-openai'],
|
||||
baseUrl: '',
|
||||
},
|
||||
{
|
||||
provider: 'claude',
|
||||
name: 'Anthropic',
|
||||
configKeys: ['claude'],
|
||||
baseUrl: 'https://api.anthropic.com/v1',
|
||||
format: 'claude',
|
||||
},
|
||||
{
|
||||
provider: 'gemini',
|
||||
name: 'Google Gemini',
|
||||
configKeys: [
|
||||
'gemini',
|
||||
'gemini-image-generation',
|
||||
@@ -50,57 +59,68 @@ const ENDPOINTS: ModelEndpoint[] = [
|
||||
},
|
||||
{
|
||||
provider: 'groq',
|
||||
name: 'Groq',
|
||||
configKeys: ['groq'],
|
||||
baseUrl: 'https://api.groq.com/openai/v1',
|
||||
},
|
||||
{
|
||||
provider: 'deepseek',
|
||||
name: 'DeepSeek',
|
||||
configKeys: ['deepseek'],
|
||||
baseUrl: 'https://api.deepseek.com',
|
||||
},
|
||||
{
|
||||
provider: 'mistral',
|
||||
name: 'Mistral',
|
||||
configKeys: ['mistral'],
|
||||
baseUrl: 'https://api.mistral.ai/v1',
|
||||
},
|
||||
{
|
||||
provider: 'moonshot',
|
||||
name: 'Moonshot',
|
||||
configKeys: ['moonshot'],
|
||||
baseUrl: 'https://api.moonshot.ai/v1',
|
||||
},
|
||||
{
|
||||
provider: 'minimax',
|
||||
name: 'MiniMax',
|
||||
configKeys: ['minimax', 'minimax-video-generation'],
|
||||
baseUrl: 'https://api.minimax.io/v1',
|
||||
},
|
||||
{
|
||||
provider: 'zai',
|
||||
name: 'Z.ai',
|
||||
configKeys: ['zai'],
|
||||
baseUrl: 'https://api.z.ai/api/paas/v4',
|
||||
},
|
||||
{
|
||||
provider: 'byteplus',
|
||||
name: 'BytePlus',
|
||||
configKeys: ['byteplus'],
|
||||
baseUrl: 'https://ark.ap-southeast.bytepluses.com/api/v3',
|
||||
},
|
||||
{
|
||||
provider: 'hoonify',
|
||||
name: 'Hoonify',
|
||||
configKeys: ['hoonify'],
|
||||
baseUrl: 'https://api.hoonify.ai/v1',
|
||||
},
|
||||
{
|
||||
provider: 'meta',
|
||||
name: 'Meta',
|
||||
configKeys: ['meta'],
|
||||
baseUrl: 'https://api.meta.ai/v1',
|
||||
},
|
||||
{
|
||||
provider: 'elevenlabs',
|
||||
name: 'ElevenLabs',
|
||||
configKeys: ['elevenlabs'],
|
||||
baseUrl: 'https://api.elevenlabs.io/v1',
|
||||
format: 'elevenlabs',
|
||||
},
|
||||
{
|
||||
provider: 'replicate',
|
||||
name: 'Replicate',
|
||||
configKeys: ['replicate-image-generation'],
|
||||
baseUrl: 'https://api.replicate.com/v1',
|
||||
format: 'replicate',
|
||||
@@ -192,7 +212,10 @@ export class AIModelMonitorService extends PuterService {
|
||||
: {}),
|
||||
},
|
||||
'info',
|
||||
{ channel: 'ai_providers' },
|
||||
{
|
||||
channel: 'ai_providers',
|
||||
summary: `${endpoint.name} model catalog ${fetchFailed ? 'could not be fetched' : 'snapshot could not be updated'}`,
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -221,7 +244,10 @@ export class AIModelMonitorService extends PuterService {
|
||||
change,
|
||||
},
|
||||
'info',
|
||||
{ channel: 'ai_providers' },
|
||||
{
|
||||
channel: 'ai_providers',
|
||||
summary: `${change === 'added' ? 'New' : 'Removed'} ${endpoint.name} model: ${model}`,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,6 +346,7 @@ export class AlarmClient extends PuterClient {
|
||||
severity,
|
||||
dedup: opts.dedup,
|
||||
channel: opts.channel,
|
||||
summary: opts.summary,
|
||||
started: Date.now(),
|
||||
// `recordOccurrence` below stamps the first occurrence; seeding one
|
||||
// here too would report every alarm as one occurrence ahead.
|
||||
@@ -526,6 +527,7 @@ export class AlarmClient extends PuterClient {
|
||||
repeatCount,
|
||||
isRepeat: repeatCount > 1,
|
||||
...(alarm.channel ? { channel: alarm.channel } : {}),
|
||||
...(alarm.summary ? { summary: alarm.summary } : {}),
|
||||
...(callGroup ? { callGroup } : {}),
|
||||
custom: {
|
||||
fields: fieldsClean,
|
||||
|
||||
@@ -20,6 +20,30 @@ const alert = (over: Partial<AlertPayload> = {}): AlertPayload => ({
|
||||
});
|
||||
|
||||
describe('buildSlackMessage', () => {
|
||||
it('shows a plain-language summary without the diagnostic field grid or full alarm id', () => {
|
||||
const msg = buildSlackMessage(
|
||||
alert({
|
||||
summary: 'New Replicate model: vendor/image',
|
||||
severity: 'info',
|
||||
}),
|
||||
{ serverId: 'sydney' },
|
||||
);
|
||||
expect(msg.text).toBe(
|
||||
':information_source: New Replicate model: vendor/image',
|
||||
);
|
||||
expect(msg.attachments[0].fields).toEqual([]);
|
||||
expect(msg.attachments[0].footer).toBe('amber-delta-fox • sydney');
|
||||
});
|
||||
|
||||
it('escapes Slack mentions and links in upstream model summaries', () => {
|
||||
const msg = buildSlackMessage(
|
||||
alert({ summary: 'New model: <!channel> & <https://example.com>' }),
|
||||
);
|
||||
expect(msg.text).toContain(
|
||||
'<!channel> & <https://example.com>',
|
||||
);
|
||||
});
|
||||
|
||||
it('renders severity, message and fields', () => {
|
||||
const msg = buildSlackMessage(alert(), {
|
||||
channel: '#alerts',
|
||||
|
||||
@@ -80,10 +80,16 @@ export function buildSlackMessage(
|
||||
const call = alert.callGroup
|
||||
? ` :telephone_receiver: calling \`${alert.callGroup}\``
|
||||
: '';
|
||||
const headline = `${style.emoji} *[${alert.severity.toUpperCase()}]* ${alert.message}${repeat}${call}`;
|
||||
const summary = alert.summary
|
||||
?.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>');
|
||||
const headline = summary
|
||||
? `${style.emoji} ${summary}${repeat}${call}`
|
||||
: `${style.emoji} *[${alert.severity.toUpperCase()}]* ${alert.message}${repeat}${call}`;
|
||||
|
||||
const fields: SlackField[] = [];
|
||||
for (const [key, value] of Object.entries(alert.fields)) {
|
||||
for (const [key, value] of Object.entries(summary ? {} : alert.fields)) {
|
||||
if (fields.length >= MAX_FIELDS) break;
|
||||
// `error` is already rendered as the trace block below.
|
||||
if (key === 'error') continue;
|
||||
@@ -95,7 +101,7 @@ export function buildSlackMessage(
|
||||
});
|
||||
}
|
||||
|
||||
const footerParts = [alert.shortId, alert.id];
|
||||
const footerParts = summary ? [alert.shortId] : [alert.shortId, alert.id];
|
||||
if (opts.serverId) footerParts.push(opts.serverId);
|
||||
|
||||
return {
|
||||
|
||||
@@ -25,6 +25,8 @@ export interface AlarmFields {
|
||||
}
|
||||
|
||||
export interface AlarmOptions {
|
||||
/** Plain-language chat summary shown in place of the diagnostic field grid. */
|
||||
summary?: string;
|
||||
/**
|
||||
* Collapse repeats of this alarm id into a single incident on transports
|
||||
* that de-duplicate (PagerDuty). Only right when the id already pins down
|
||||
@@ -62,6 +64,11 @@ export interface Alarm extends AlarmOptions {
|
||||
}
|
||||
|
||||
export interface AlertPayload {
|
||||
/**
|
||||
* Plain-language chat summary; diagnostic fields remain available to other
|
||||
* transports.
|
||||
*/
|
||||
summary?: string;
|
||||
id: string;
|
||||
/**
|
||||
* Key a de-duplicating transport groups by. Equal to `id` for alarms raised
|
||||
|
||||
Reference in new issue
Block a user