monitai 0.0.1 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/actions-registry-B5JBDO5F.js +43 -0
- package/dist/chunk-63FHD5ZT.js +169 -0
- package/dist/chunk-JU76LRZA.js +623 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +984 -0
- package/dist/client-Dq7v7zCx.d.ts +91 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +26 -0
- package/dist/index.d.ts +163 -0
- package/dist/index.js +98 -0
- package/dist/internal/island-runtime.d.ts +3 -0
- package/dist/internal/island-runtime.js +19 -0
- package/package.json +63 -7
- package/template/.env.example +16 -0
- package/template/_gitignore +8 -0
- package/template/islands/counter/counter.view.tsx +18 -0
- package/template/islands/incident-simulator/incident-simulator.actions.ts +36 -0
- package/template/islands/incident-simulator/incident-simulator.view.tsx +50 -0
- package/template/islands/service-monitor/service-monitor.server.ts +24 -0
- package/template/islands/service-monitor/service-monitor.types.ts +20 -0
- package/template/islands/service-monitor/service-monitor.view.tsx +38 -0
- package/template/islands/summary-banner/summary-banner.view.tsx +51 -0
- package/template/islands/weather/weather.server.ts +66 -0
- package/template/islands/weather/weather.types.ts +14 -0
- package/template/islands/weather/weather.view.tsx +35 -0
- package/template/main.tsx +45 -0
- package/template/package.json +16 -0
- package/template/styles.css +1 -0
- package/template/tsconfig.json +17 -0
- package/index.js +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useSource, type WithSource } from 'monitai'
|
|
2
|
+
import type { ServiceMetricsData } from './service-monitor.types'
|
|
3
|
+
|
|
4
|
+
export default function ServiceMonitorView({
|
|
5
|
+
source,
|
|
6
|
+
}: WithSource<ServiceMetricsData, { serviceName: string }>) {
|
|
7
|
+
const { data, isPaused } = useSource(source)
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<div class="p-4 border rounded-lg shadow-sm space-y-2">
|
|
11
|
+
<div class="flex items-center justify-between">
|
|
12
|
+
<h3 class="font-bold m-0">{source.params.serviceName}</h3>
|
|
13
|
+
<div class="flex items-center gap-2">
|
|
14
|
+
{isPaused && (
|
|
15
|
+
<span class="px-2 py-0.5 text-xs bg-amber-100 text-amber-800 rounded">
|
|
16
|
+
Polling paused
|
|
17
|
+
</span>
|
|
18
|
+
)}
|
|
19
|
+
<span
|
|
20
|
+
class={`px-2 py-0.5 text-xs font-semibold rounded ${
|
|
21
|
+
data?.status === 'online'
|
|
22
|
+
? 'bg-green-100 text-green-800'
|
|
23
|
+
: 'bg-red-100 text-red-800'
|
|
24
|
+
}`}
|
|
25
|
+
>
|
|
26
|
+
{data?.status?.toUpperCase() ?? 'LOADING'}
|
|
27
|
+
</span>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
<p class="text-sm text-gray-700 m-0">
|
|
31
|
+
{data?.message ?? 'Waiting for metrics...'}
|
|
32
|
+
</p>
|
|
33
|
+
{data && (
|
|
34
|
+
<p class="text-xs text-gray-500 m-0">Latency: {data.latencyMs} ms</p>
|
|
35
|
+
)}
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useSummary } from 'monitai'
|
|
2
|
+
import type { SummaryResult } from 'monitai'
|
|
3
|
+
|
|
4
|
+
export default function SummaryBannerView() {
|
|
5
|
+
const { summary, isLoading, refresh } = useSummary(
|
|
6
|
+
null as SummaryResult | null,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
const severityClass =
|
|
10
|
+
summary?.severity === 'critical'
|
|
11
|
+
? 'border-red-500 bg-red-50'
|
|
12
|
+
: summary?.severity === 'warning'
|
|
13
|
+
? 'border-amber-500 bg-amber-50'
|
|
14
|
+
: 'border-gray-300 bg-gray-50'
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div class={`p-4 border rounded-lg ${severityClass}`}>
|
|
18
|
+
<div class="flex items-start justify-between gap-4">
|
|
19
|
+
<div>
|
|
20
|
+
<p class="m-0 mb-1 font-bold">Agent summary</p>
|
|
21
|
+
{!summary && !isLoading && (
|
|
22
|
+
<p class="m-0 text-sm text-gray-600">
|
|
23
|
+
Summary appears when MONITAI_LLM_API_KEY is set and sources have
|
|
24
|
+
updated. You can also refresh manually.
|
|
25
|
+
</p>
|
|
26
|
+
)}
|
|
27
|
+
{isLoading && <p class="m-0 text-sm text-gray-600">Generating…</p>}
|
|
28
|
+
{summary && (
|
|
29
|
+
<>
|
|
30
|
+
<p class="m-0 text-sm">{summary.text}</p>
|
|
31
|
+
<p class="m-0 mt-2 text-xs text-gray-500">
|
|
32
|
+
{new Date(summary.generatedAt).toLocaleString()} ·{' '}
|
|
33
|
+
{summary.severity}
|
|
34
|
+
</p>
|
|
35
|
+
</>
|
|
36
|
+
)}
|
|
37
|
+
</div>
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
class="shrink-0 px-3 py-1.5 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50"
|
|
41
|
+
disabled={isLoading}
|
|
42
|
+
onClick={() => {
|
|
43
|
+
void refresh()
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
Refresh
|
|
47
|
+
</button>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { defineSource } from 'monitai'
|
|
2
|
+
import type { WeatherData, WeatherParams } from './weather.types'
|
|
3
|
+
|
|
4
|
+
/** WMO Weather interpretation codes (WW) — Open-Meteo */
|
|
5
|
+
const WEATHER_CODES: Record<number, string> = {
|
|
6
|
+
0: 'Clear sky',
|
|
7
|
+
1: 'Mainly clear',
|
|
8
|
+
2: 'Partly cloudy',
|
|
9
|
+
3: 'Overcast',
|
|
10
|
+
45: 'Fog',
|
|
11
|
+
48: 'Depositing rime fog',
|
|
12
|
+
51: 'Light drizzle',
|
|
13
|
+
53: 'Moderate drizzle',
|
|
14
|
+
55: 'Dense drizzle',
|
|
15
|
+
56: 'Light freezing drizzle',
|
|
16
|
+
57: 'Dense freezing drizzle',
|
|
17
|
+
61: 'Slight rain',
|
|
18
|
+
63: 'Moderate rain',
|
|
19
|
+
65: 'Heavy rain',
|
|
20
|
+
66: 'Light freezing rain',
|
|
21
|
+
67: 'Heavy freezing rain',
|
|
22
|
+
71: 'Slight snowfall',
|
|
23
|
+
73: 'Moderate snowfall',
|
|
24
|
+
75: 'Heavy snowfall',
|
|
25
|
+
77: 'Snow grains',
|
|
26
|
+
80: 'Slight rain showers',
|
|
27
|
+
81: 'Moderate rain showers',
|
|
28
|
+
82: 'Violent rain showers',
|
|
29
|
+
85: 'Slight snow showers',
|
|
30
|
+
86: 'Heavy snow showers',
|
|
31
|
+
95: 'Thunderstorm',
|
|
32
|
+
96: 'Thunderstorm with slight hail',
|
|
33
|
+
97: 'Heavy thunderstorm',
|
|
34
|
+
99: 'Thunderstorm with heavy hail',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default defineSource({
|
|
38
|
+
id: (params: WeatherParams) => `weather:${params.city.toLowerCase()}`,
|
|
39
|
+
interval: '5m',
|
|
40
|
+
description: (params: WeatherParams) =>
|
|
41
|
+
`Current weather in ${params.city} (Open-Meteo)`,
|
|
42
|
+
publicProps: ['city'] as const,
|
|
43
|
+
fetcher: async (params: WeatherParams): Promise<WeatherData> => {
|
|
44
|
+
// apiKey is available only here (server). Open-Meteo needs no key;
|
|
45
|
+
// we still accept it to demonstrate the whitelist.
|
|
46
|
+
void params.apiKey
|
|
47
|
+
|
|
48
|
+
const url =
|
|
49
|
+
`https://api.open-meteo.com/v1/forecast` +
|
|
50
|
+
`?latitude=${params.lat}&longitude=${params.lon}` +
|
|
51
|
+
`¤t=temperature_2m,relative_humidity_2m,weather_code,wind_speed_10m` +
|
|
52
|
+
`&timezone=auto`
|
|
53
|
+
const res = await fetch(url)
|
|
54
|
+
if (!res.ok) throw new Error(`Open-Meteo HTTP ${res.status}`)
|
|
55
|
+
const data = await res.json()
|
|
56
|
+
const current = data.current
|
|
57
|
+
return {
|
|
58
|
+
temperature: current.temperature_2m as number,
|
|
59
|
+
humidity: current.relative_humidity_2m as number,
|
|
60
|
+
windSpeed: current.wind_speed_10m as number,
|
|
61
|
+
description:
|
|
62
|
+
WEATHER_CODES[current.weather_code as number] ??
|
|
63
|
+
`Weather code ${current.weather_code}`,
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface WeatherParams {
|
|
2
|
+
city: string
|
|
3
|
+
lat: number
|
|
4
|
+
lon: number
|
|
5
|
+
/** Demo secret — must never appear in HTML / client bundle */
|
|
6
|
+
apiKey?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface WeatherData {
|
|
10
|
+
temperature: number
|
|
11
|
+
humidity: number
|
|
12
|
+
windSpeed: number
|
|
13
|
+
description: string
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useSource, type WithSource } from 'monitai'
|
|
2
|
+
import type { WeatherData } from './weather.types'
|
|
3
|
+
|
|
4
|
+
export default function WeatherView({
|
|
5
|
+
source,
|
|
6
|
+
}: WithSource<WeatherData, { city: string }>) {
|
|
7
|
+
const { data, status, error } = useSource(source)
|
|
8
|
+
|
|
9
|
+
if (status === 'loading' && !data) {
|
|
10
|
+
return (
|
|
11
|
+
<div class="p-4 border border-gray-300 rounded-lg min-w-56">
|
|
12
|
+
Loading weather for {source.params.city}…
|
|
13
|
+
</div>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div class="p-4 border border-gray-300 rounded-lg min-w-56 shadow-sm">
|
|
19
|
+
<h3 class="m-0 mb-2 font-semibold">Weather: {source.params.city}</h3>
|
|
20
|
+
{status === 'error' && (
|
|
21
|
+
<p class="m-0 mb-2 text-red-600 text-sm">
|
|
22
|
+
Error: {error ?? 'unknown'}
|
|
23
|
+
</p>
|
|
24
|
+
)}
|
|
25
|
+
{data && (
|
|
26
|
+
<ul class="m-0 p-0 list-none text-sm space-y-1">
|
|
27
|
+
<li class="text-2xl font-bold">{Math.round(data.temperature)}°C</li>
|
|
28
|
+
<li>{data.description}</li>
|
|
29
|
+
<li class="text-gray-600">Humidity: {data.humidity}%</li>
|
|
30
|
+
<li class="text-gray-600">Wind: {data.windSpeed} km/h</li>
|
|
31
|
+
</ul>
|
|
32
|
+
)}
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createPage, island, refSource } from 'monitai'
|
|
2
|
+
import weatherView from './islands/weather/weather.view'
|
|
3
|
+
import weatherServer from './islands/weather/weather.server'
|
|
4
|
+
import serviceMonitorView from './islands/service-monitor/service-monitor.view'
|
|
5
|
+
import serviceMonitorServer from './islands/service-monitor/service-monitor.server'
|
|
6
|
+
import incidentSimulatorView from './islands/incident-simulator/incident-simulator.view'
|
|
7
|
+
import { simulateIncident } from './islands/incident-simulator/incident-simulator.actions'
|
|
8
|
+
import summaryBannerView from './islands/summary-banner/summary-banner.view'
|
|
9
|
+
import counterView from './islands/counter/counter.view'
|
|
10
|
+
|
|
11
|
+
const Weather = island('weather', weatherView)
|
|
12
|
+
const ServiceMonitor = island('service-monitor', serviceMonitorView)
|
|
13
|
+
const IncidentSimulator = island('incident-simulator', incidentSimulatorView)
|
|
14
|
+
const SummaryBanner = island('summary-banner', summaryBannerView)
|
|
15
|
+
const Counter = island('counter', counterView)
|
|
16
|
+
|
|
17
|
+
const moscowWeather = refSource(weatherServer, {
|
|
18
|
+
city: 'Moscow',
|
|
19
|
+
lat: 55.7558,
|
|
20
|
+
lon: 37.6173,
|
|
21
|
+
apiKey: process.env.WEATHER_API_KEY,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const paymentService = refSource(serviceMonitorServer, {
|
|
25
|
+
serviceName: 'Payment-Gateway',
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export default createPage(
|
|
29
|
+
() => (
|
|
30
|
+
<main class="p-6 max-w-4xl mx-auto space-y-6 font-sans">
|
|
31
|
+
<h1 class="text-2xl font-bold">Monitai Ops Dashboard</h1>
|
|
32
|
+
<SummaryBanner />
|
|
33
|
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
34
|
+
<ServiceMonitor source={paymentService} />
|
|
35
|
+
<IncidentSimulator source={paymentService} />
|
|
36
|
+
</div>
|
|
37
|
+
<Weather source={moscowWeather} />
|
|
38
|
+
<Counter initialCount={0} />
|
|
39
|
+
</main>
|
|
40
|
+
),
|
|
41
|
+
{
|
|
42
|
+
title: 'Monitai Dashboard',
|
|
43
|
+
actions: [simulateIncident],
|
|
44
|
+
},
|
|
45
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-monitai-app",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "monitai dev",
|
|
7
|
+
"build": "monitai build",
|
|
8
|
+
"start": "monitai start"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"preact": "^10.24.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/node": "^22.0.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"jsxImportSource": "preact",
|
|
10
|
+
"types": ["node"],
|
|
11
|
+
"paths": {
|
|
12
|
+
"monitai": ["../src/index.ts"],
|
|
13
|
+
"monitai/client": ["../src/client.ts"]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"include": ["./**/*.ts", "./**/*.tsx"]
|
|
17
|
+
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const version = '0.0.1';
|