@astrale-os/adapter-cloudflare 0.3.1 → 0.4.0
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 +202 -0
- package/package.json +4 -4
- package/template/.agents/skills/astrale-cli/SKILL.md +633 -0
- package/template/.domain-studio/comments.json +4 -0
- package/template/.env.example +3 -6
- package/template/CLAUDE.md +8 -6
- package/template/README.md +28 -20
- package/template/client/__tests__/app.test.tsx +39 -248
- package/template/client/__tests__/harness.ts +0 -47
- package/template/client/__tests__/shell.test.ts +46 -0
- package/template/client/package.json +1 -1
- package/template/client/src/app.tsx +6 -8
- package/template/client/src/shell/index.ts +1 -0
- package/template/client/src/shell/transformers.ts +36 -33
- package/template/client/src/shell/use-node.ts +21 -13
- package/template/client/src/ui/index.ts +4 -7
- package/template/core/README.md +23 -0
- package/template/deps.ts +10 -9
- package/template/domain.ts +11 -9
- package/template/env.ts +3 -5
- package/template/functions/index.ts +14 -37
- package/template/icons.ts +25 -0
- package/template/integrations/README.md +22 -0
- package/template/package.json +3 -3
- package/template/runtime/index.ts +25 -72
- package/template/schema/index.ts +10 -10
- package/template/tsconfig.json +1 -0
- package/template/views/index.ts +15 -12
- package/template/client/__tests__/kernel.test.ts +0 -77
- package/template/client/__tests__/seam.test.tsx +0 -115
- package/template/client/src/status/components/StatusCard.tsx +0 -160
- package/template/client/src/status/components/index.ts +0 -1
- package/template/client/src/status/hooks/index.ts +0 -3
- package/template/client/src/status/hooks/useCheck.mutation.ts +0 -16
- package/template/client/src/status/hooks/useCheckable.query.ts +0 -72
- package/template/client/src/status/index.ts +0 -7
- package/template/client/src/status/status.api.ts +0 -29
- package/template/client/src/status/status.mappers.ts +0 -102
- package/template/client/src/status/status.types.ts +0 -26
- package/template/client/src/ui/StatusBadge.tsx +0 -31
- package/template/client/src/views/status.tsx +0 -28
- package/template/core/monitor/health.ts +0 -34
- package/template/core/monitor/index.ts +0 -9
- package/template/core/monitor/keys.ts +0 -41
- package/template/core/monitor/node.ts +0 -63
- package/template/integrations/prober/http.ts +0 -32
- package/template/integrations/prober/mock.ts +0 -18
- package/template/integrations/prober/port.ts +0 -26
- package/template/integrations/prober/registry.ts +0 -65
- package/template/pnpm-lock.yaml +0 -2780
- package/template/runtime/monitoring/index.ts +0 -8
- package/template/runtime/monitoring/monitor/check.ts +0 -29
- package/template/runtime/monitoring/monitor/index.ts +0 -10
- package/template/runtime/monitoring/monitor/seed.ts +0 -104
- package/template/runtime/monitoring/monitor/watch.ts +0 -31
- package/template/runtime/monitoring/page/add.ts +0 -21
- package/template/runtime/monitoring/page/check.ts +0 -50
- package/template/runtime/monitoring/page/create.ts +0 -24
- package/template/runtime/monitoring/page/index.ts +0 -9
- package/template/runtime/shared.ts +0 -21
- package/template/schema/monitor.ts +0 -92
- package/template/views/status-page.ts +0 -16
- package/template/views/welcome.ts +0 -35
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compiled-schema accessors for the monitor context — the ONE place class paths,
|
|
3
|
-
* method paths, and qualified prop keys come from. Pure (schema-derived); never
|
|
4
|
-
* hand-write key strings. `D` (the compiled domain) comes from `schema/index`,
|
|
5
|
-
* re-exported here so the rest of the context reads it from one place.
|
|
6
|
-
*/
|
|
7
|
-
import { K } from '@astrale-os/kernel-core'
|
|
8
|
-
|
|
9
|
-
import { D } from '../../schema'
|
|
10
|
-
|
|
11
|
-
export { D, K }
|
|
12
|
-
|
|
13
|
-
/** Kernel ops/classes the logic addresses. */
|
|
14
|
-
export const NODE_CREATE = K.Node.createNode.path.method.raw
|
|
15
|
-
export const FOLDER_CLASS = K.Folder.path.class.raw
|
|
16
|
-
export const NAME_KEY = K.Named.name.key
|
|
17
|
-
|
|
18
|
-
/** Domain class/edge paths. */
|
|
19
|
-
export const MONITOR_CLASS = D.Monitor.path.class.raw
|
|
20
|
-
export const STATUS_PAGE_CLASS = D.StatusPage.path.class.raw
|
|
21
|
-
export const WATCHES_EDGE = D.watches.path.class.raw
|
|
22
|
-
|
|
23
|
-
/** Qualified storage keys for Monitor node props. */
|
|
24
|
-
export const MONITOR_KEYS = {
|
|
25
|
-
url: D.Monitor.url.key,
|
|
26
|
-
status: D.Monitor.status.key,
|
|
27
|
-
statusCode: D.Monitor.statusCode.key,
|
|
28
|
-
latencyMs: D.Monitor.latencyMs.key,
|
|
29
|
-
lastCheckedAt: D.Monitor.lastCheckedAt.key,
|
|
30
|
-
} as const
|
|
31
|
-
|
|
32
|
-
/** Qualified storage key for the StatusPage's rolled-up status. */
|
|
33
|
-
export const PAGE_KEYS = {
|
|
34
|
-
status: D.StatusPage.status.key,
|
|
35
|
-
} as const
|
|
36
|
-
|
|
37
|
-
/** Qualified key for the `watches` edge's `critical` prop. Edge-prop accessors
|
|
38
|
-
* aren't typed yet (an SDK gap), so this casts to read the key. */
|
|
39
|
-
export const WATCHES_KEYS = {
|
|
40
|
-
critical: (D.watches as unknown as { critical: { key: string } }).critical.key,
|
|
41
|
-
} as const
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node identity — PURE domain constants + slug logic (no I/O): where monitors and
|
|
3
|
-
* status pages live in the graph, how a new node's slug is formed, and the seed
|
|
4
|
-
* set. `runtime/` consumes these; the IMPURE bits (the slug's entropy suffix, the
|
|
5
|
-
* node writes) stay in `runtime/`, so this file is deterministic and testable.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/** Where monitoring nodes live in the graph (domain layout; `seed` creates the folders). */
|
|
9
|
-
export const MONITORING_PARENT = '/monitoring'
|
|
10
|
-
export const MONITORS_PARENT = `${MONITORING_PARENT}/monitors`
|
|
11
|
-
export const STATUS_PAGES_PARENT = `${MONITORING_PARENT}/pages`
|
|
12
|
-
|
|
13
|
-
/** Deterministic URL-/name-safe stem (lowercased, non-alnum → `-`, clamped). Pure. */
|
|
14
|
-
export function slugify(text: string): string {
|
|
15
|
-
return (
|
|
16
|
-
text
|
|
17
|
-
.replace(/^https?:\/\//i, '')
|
|
18
|
-
.toLowerCase()
|
|
19
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
20
|
-
.replace(/^-|-$/g, '')
|
|
21
|
-
.slice(0, 40) || 'node'
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Slug for a NEW node: the stem + a caller-supplied `suffix`. Pure — `runtime/`
|
|
27
|
-
* injects the `suffix` (clock/RNG entropy for collision safety) so core stays
|
|
28
|
-
* deterministic. `seed` uses fixed slugs (not this) for idempotency.
|
|
29
|
-
*/
|
|
30
|
-
export function uniqueSlug(text: string, suffix: string): string {
|
|
31
|
-
return `${slugify(text)}-${suffix}`
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface StarterMonitor {
|
|
35
|
-
slug: string
|
|
36
|
-
name: string
|
|
37
|
-
url: string
|
|
38
|
-
/** Whether the seeded status page treats this monitor as critical. */
|
|
39
|
-
critical: boolean
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Monitors laid down by `seed` (postInstall). httpbin returns a deterministic
|
|
44
|
-
* status code, so the second starter is a stable demo target; the first points at
|
|
45
|
-
* a real site. Fixed slugs keep `seed` idempotent across reinstalls.
|
|
46
|
-
*/
|
|
47
|
-
export const STARTERS: readonly StarterMonitor[] = [
|
|
48
|
-
{
|
|
49
|
-
slug: 'astrale',
|
|
50
|
-
name: 'Astrale homepage',
|
|
51
|
-
url: 'https://astrale.ai',
|
|
52
|
-
critical: true,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
slug: 'httpbin-200',
|
|
56
|
-
name: 'HTTP 200 smoke check',
|
|
57
|
-
url: 'https://httpbin.org/status/200',
|
|
58
|
-
critical: false,
|
|
59
|
-
},
|
|
60
|
-
]
|
|
61
|
-
|
|
62
|
-
/** The status page `seed` creates, watching every starter monitor. */
|
|
63
|
-
export const STARTER_PAGE = { slug: 'status', name: 'Public status' } as const
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP prober — the REAL external adapter: a single keyless `fetch` to the
|
|
3
|
-
* target, timing the round-trip. This is the shape your domain's external calls
|
|
4
|
-
* take — a timeout via `AbortSignal`, failures mapped to a domain result rather
|
|
5
|
-
* than thrown. NO API key: a fresh scaffold makes a true external call out of
|
|
6
|
-
* the box (it's the registry default).
|
|
7
|
-
*/
|
|
8
|
-
import type { Prober, ProbeResult } from './port'
|
|
9
|
-
|
|
10
|
-
export interface HttpProberConfig {
|
|
11
|
-
/** Per-probe timeout in ms (default 10000). */
|
|
12
|
-
timeoutMs?: number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const DEFAULT_TIMEOUT_MS = 10_000
|
|
16
|
-
|
|
17
|
-
/** Build the keyless HTTP prober (a `GET` with a timeout). */
|
|
18
|
-
export function createHttpProber(config: HttpProberConfig = {}): Prober {
|
|
19
|
-
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
20
|
-
return {
|
|
21
|
-
async probe(url): Promise<ProbeResult> {
|
|
22
|
-
const start = Date.now()
|
|
23
|
-
try {
|
|
24
|
-
const res = await fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(timeoutMs) })
|
|
25
|
-
return { statusCode: res.status, latencyMs: Date.now() - start }
|
|
26
|
-
} catch {
|
|
27
|
-
// Unreachable / timeout / DNS failure — a `down` result, not an error.
|
|
28
|
-
return { statusCode: 0, latencyMs: Date.now() - start }
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mock prober — offline + deterministic, no network. Used by tests (construct it
|
|
3
|
-
* directly with the status you want) and by `PROBER=mock` for an offline dev
|
|
4
|
-
* loop. Returns a fixed result regardless of URL.
|
|
5
|
-
*/
|
|
6
|
-
import type { Prober, ProbeResult } from './port'
|
|
7
|
-
|
|
8
|
-
/** Build an offline prober that always returns `opts` (default: a healthy 200). */
|
|
9
|
-
export function createMockProber(opts: { statusCode?: number; latencyMs?: number } = {}): Prober {
|
|
10
|
-
const statusCode = opts.statusCode ?? 200
|
|
11
|
-
const latencyMs = opts.latencyMs ?? 1
|
|
12
|
-
const result: ProbeResult = { statusCode, latencyMs }
|
|
13
|
-
return {
|
|
14
|
-
probe() {
|
|
15
|
-
return Promise.resolve(result)
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prober — the PORT between the domain's logic and whatever performs the actual
|
|
3
|
-
* uptime probe. This is the external-API seam every real domain has, reduced to
|
|
4
|
-
* the narrowest interface the logic needs.
|
|
5
|
-
*
|
|
6
|
-
* `runtime/` logic depends on THIS interface only — never on `fetch`, an SDK, or
|
|
7
|
-
* `env`. Adapters in this folder implement it: `http.ts` (a real, keyless HTTP
|
|
8
|
-
* request) and `mock.ts` (offline + deterministic, for tests). The registry
|
|
9
|
-
* picks one from `env`; the handler logic only ever sees the resolved port. Swap
|
|
10
|
-
* or add a backend = one adapter + one arm in `registry.ts`.
|
|
11
|
-
*/
|
|
12
|
-
export interface ProbeResult {
|
|
13
|
-
/** Observed HTTP status code, or `0` if the host was unreachable. */
|
|
14
|
-
statusCode: number
|
|
15
|
-
/** Round-trip time in ms. */
|
|
16
|
-
latencyMs: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface Prober {
|
|
20
|
-
/**
|
|
21
|
-
* Probe a URL once. MUST resolve, never reject: an unreachable host or a
|
|
22
|
-
* timeout is a `down` RESULT (`statusCode: 0`), not an error — a probe failing
|
|
23
|
-
* is the normal case a monitor exists to observe.
|
|
24
|
-
*/
|
|
25
|
-
probe(url: string): Promise<ProbeResult>
|
|
26
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prober registry — the ONE place the worker env (and the probed node) become the
|
|
3
|
-
* live `Prober` port. Adding a backend = one more arm in `selectProber`; handler
|
|
4
|
-
* logic only ever sees the resolved port.
|
|
5
|
-
*
|
|
6
|
-
* Resolution is PER-REQUEST and PER-NODE: each `prober(target)` call selects +
|
|
7
|
-
* builds the port from env AND the monitor being probed — nothing is built at
|
|
8
|
-
* `deps()` / isolate setup. A per-node choice can't be memoized at the isolate
|
|
9
|
-
* level, which is exactly why `deps` exposes `prober()` as a FUNCTION, not a
|
|
10
|
-
* value. The default is the keyless `http` prober (so the scaffold makes a real
|
|
11
|
-
* probe out of the box); `PROBER=mock` forces the offline prober.
|
|
12
|
-
*/
|
|
13
|
-
import type { Env } from '../../env'
|
|
14
|
-
import type { Prober } from './port'
|
|
15
|
-
|
|
16
|
-
import { createHttpProber } from './http'
|
|
17
|
-
import { createMockProber } from './mock'
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The node a probe is for — what the registry may branch on. Mirrors how the
|
|
21
|
-
* `services` domain picks a provider from a node's class; here we also look at
|
|
22
|
-
* the target url. The handler passes this from `self.node()`; omit it for
|
|
23
|
-
* node-less callers (e.g. `seed`, which just wants the env default).
|
|
24
|
-
*/
|
|
25
|
-
export interface ProbeTarget {
|
|
26
|
-
/** The monitor node's class path (`node.class.raw`). */
|
|
27
|
-
class: string
|
|
28
|
-
/** The url this monitor probes (`node.props[MONITOR_KEYS.url]`). */
|
|
29
|
-
url: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface ProberRegistry {
|
|
33
|
-
/** Resolve the prober for a probe — built per call from env + the target node. */
|
|
34
|
-
prober(target?: ProbeTarget): Prober
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Build the registry from the worker env. The port is resolved per request. */
|
|
38
|
-
export function buildProberRegistry(env: Env): ProberRegistry {
|
|
39
|
-
return {
|
|
40
|
-
prober(target) {
|
|
41
|
-
return selectProber(env, target)
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Bind the abstract prober port to the concrete adapter for this env + target. */
|
|
47
|
-
function selectProber(env: Env, target?: ProbeTarget): Prober {
|
|
48
|
-
if (target && isLocalTarget(target.url)) {
|
|
49
|
-
return createMockProber()
|
|
50
|
-
}
|
|
51
|
-
// Default: the real, keyless HTTP prober. Pass the env override (if any); the
|
|
52
|
-
// adapter owns the default timeout, so there's no second copy of it here.
|
|
53
|
-
return createHttpProber({ timeoutMs: parsePositiveInt(env.PROBE_TIMEOUT_MS) })
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** A loopback / unspecified host the public edge can't reach. */
|
|
57
|
-
function isLocalTarget(url: string): boolean {
|
|
58
|
-
return /^https?:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:|\/|$)/i.test(url)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function parsePositiveInt(value: string | undefined): number | undefined {
|
|
62
|
-
if (!value) return undefined
|
|
63
|
-
const n = Number.parseInt(value, 10)
|
|
64
|
-
return Number.isFinite(n) && n > 0 ? n : undefined
|
|
65
|
-
}
|