@astrale-os/adapter-cloudflare 0.1.8 → 0.1.10
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/dist/assets-pack.d.ts +1 -1
- package/dist/assets-pack.js +1 -1
- package/dist/build.d.ts +15 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +15 -0
- package/dist/build.js.map +1 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -1
- package/dist/client.js.map +1 -1
- package/dist/cloudflare.d.ts +15 -3
- package/dist/cloudflare.d.ts.map +1 -1
- package/dist/cloudflare.js +52 -18
- package/dist/cloudflare.js.map +1 -1
- package/dist/codegen/worker.d.ts +26 -6
- package/dist/codegen/worker.d.ts.map +1 -1
- package/dist/codegen/worker.js +67 -54
- package/dist/codegen/worker.js.map +1 -1
- package/dist/codegen/wrangler.d.ts +11 -2
- package/dist/codegen/wrangler.d.ts.map +1 -1
- package/dist/codegen/wrangler.js +11 -5
- package/dist/codegen/wrangler.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/params.d.ts +30 -30
- package/dist/params.d.ts.map +1 -1
- package/dist/parse-output.d.ts +1 -1
- package/dist/parse-output.js +1 -1
- package/package.json +6 -2
- package/src/assets-pack.ts +1 -1
- package/src/build.ts +15 -0
- package/src/client.ts +11 -1
- package/src/cloudflare.ts +53 -18
- package/src/codegen/worker.ts +76 -59
- package/src/codegen/wrangler.ts +15 -5
- package/src/index.ts +6 -3
- package/src/params.ts +32 -31
- package/src/parse-output.ts +1 -1
- package/template/.agents/skills/astrale-cli/SKILL.md +26 -12
- package/template/.agents/skills/astrale-domain/SKILL.md +46 -29
- package/template/.env.example +6 -0
- package/template/README.md +25 -10
- package/template/astrale.config.ts +27 -33
- package/template/client/README.md +80 -63
- package/template/client/__tests__/app.test.tsx +188 -99
- package/template/client/__tests__/harness.ts +67 -12
- package/template/client/__tests__/kernel.test.ts +65 -50
- package/template/client/__tests__/seam.test.tsx +111 -0
- package/template/client/index.html +1 -1
- package/template/client/package.json +1 -0
- package/template/client/src/app.tsx +40 -83
- package/template/client/src/main.tsx +2 -2
- package/template/client/src/monitor/components/MonitorCard.tsx +50 -0
- package/template/client/src/monitor/components/index.ts +1 -0
- package/template/client/src/monitor/hooks/index.ts +3 -0
- package/template/client/src/monitor/hooks/useCheck.mutation.ts +16 -0
- package/template/client/src/monitor/hooks/useMonitor.query.ts +64 -0
- package/template/client/src/monitor/index.ts +6 -0
- package/template/client/src/monitor/monitor.api.ts +11 -0
- package/template/client/src/monitor/monitor.mappers.ts +38 -0
- package/template/client/src/monitor/monitor.types.ts +23 -0
- package/template/client/src/monitor/ui/MonitorDetails.UI.tsx +38 -0
- package/template/client/src/monitor/ui/StatusBadge.UI.tsx +14 -0
- package/template/client/src/monitor/ui/index.ts +8 -0
- package/template/client/src/shell/client.ts +67 -0
- package/template/client/src/shell/index.ts +20 -0
- package/template/client/src/shell/invoke.ts +35 -0
- package/template/client/src/shell/transformers.ts +72 -0
- package/template/client/src/shell/use-async.ts +56 -0
- package/template/client/src/shell/use-capability.ts +61 -0
- package/template/client/src/shell/use-node.ts +61 -0
- package/template/client/src/shell/use-shell.ts +91 -0
- package/template/client/src/shell/view-router.tsx +98 -0
- package/template/client/src/styles.css +177 -4
- package/template/client/src/ui/format.ts +24 -0
- package/template/client/src/ui/index.ts +9 -0
- package/template/client/src/ui/surface.tsx +56 -0
- package/template/client/src/ui/value.tsx +32 -0
- package/template/client/src/views/monitor.tsx +30 -0
- package/template/client/tsconfig.json +3 -2
- package/template/client/vite.config.ts +14 -15
- package/template/client/vitest.config.ts +12 -5
- package/template/core/monitor/health.ts +19 -0
- package/template/core/monitor/index.ts +9 -0
- package/template/core/monitor/keys.ts +29 -0
- package/template/core/monitor/node.ts +51 -0
- package/template/deps.ts +25 -0
- package/template/domain.ts +33 -0
- package/template/env.ts +4 -0
- package/template/integrations/prober/http.ts +43 -0
- package/template/integrations/prober/mock.ts +22 -0
- package/template/integrations/prober/port.ts +28 -0
- package/template/integrations/prober/registry.ts +66 -0
- package/template/package.json +2 -3
- package/template/pnpm-lock.yaml +2766 -0
- package/template/runtime/index.ts +79 -0
- package/template/runtime/monitor/check.ts +29 -0
- package/template/runtime/monitor/dependsOn.ts +16 -0
- package/template/runtime/monitor/index.ts +12 -0
- package/template/runtime/monitor/seed.ts +74 -0
- package/template/runtime/monitor/shared.ts +17 -0
- package/template/runtime/monitor/watch.ts +37 -0
- package/template/schema/index.ts +13 -4
- package/template/schema/monitor.ts +80 -0
- package/template/tsconfig.json +13 -2
- package/template/views/index.ts +9 -2
- package/template/views/monitor.ts +22 -0
- package/dist/astrale.d.ts +0 -27
- package/dist/astrale.d.ts.map +0 -1
- package/dist/astrale.js +0 -222
- package/dist/astrale.js.map +0 -1
- package/src/astrale.ts +0 -259
- package/template/client/src/lib/kernel.ts +0 -135
- package/template/client/src/lib/shell.ts +0 -197
- package/template/client/src/lib/use-node.ts +0 -66
- package/template/client/src/lib/use-shell.ts +0 -85
- package/template/methods/index.ts +0 -66
- package/template/methods/note.ts +0 -131
- package/template/schema/compiled.ts +0 -14
- package/template/schema/note.ts +0 -64
- package/template/views/note.ts +0 -21
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
/** Probe verb — `GET` (default) or the lighter `HEAD`. */
|
|
12
|
+
method?: 'GET' | 'HEAD'
|
|
13
|
+
/** Per-probe timeout in ms (default 10000). */
|
|
14
|
+
timeoutMs?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const DEFAULT_TIMEOUT_MS = 10_000
|
|
18
|
+
|
|
19
|
+
/** Build the keyless HTTP prober. */
|
|
20
|
+
export function createHttpProber(config: HttpProberConfig = {}): Prober {
|
|
21
|
+
const method = config.method ?? 'GET'
|
|
22
|
+
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
23
|
+
return {
|
|
24
|
+
async probe(url): Promise<ProbeResult> {
|
|
25
|
+
const start = Date.now()
|
|
26
|
+
try {
|
|
27
|
+
const res = await fetch(url, {
|
|
28
|
+
method,
|
|
29
|
+
redirect: 'follow',
|
|
30
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
31
|
+
})
|
|
32
|
+
return {
|
|
33
|
+
statusCode: res.status,
|
|
34
|
+
latencyMs: Date.now() - start,
|
|
35
|
+
ok: res.status >= 200 && res.status < 400,
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// Unreachable / timeout / DNS failure — a `down` result, not an error.
|
|
39
|
+
return { statusCode: 0, latencyMs: Date.now() - start, ok: false }
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 = {
|
|
13
|
+
statusCode,
|
|
14
|
+
latencyMs,
|
|
15
|
+
ok: statusCode >= 200 && statusCode < 400,
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
probe() {
|
|
19
|
+
return Promise.resolve(result)
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
/** Convenience flag — `statusCode` in `[200, 400)`. */
|
|
18
|
+
ok: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Prober {
|
|
22
|
+
/**
|
|
23
|
+
* Probe a URL once. MUST resolve, never reject: an unreachable host or a
|
|
24
|
+
* timeout is a `down` RESULT (`statusCode: 0`), not an error — a probe failing
|
|
25
|
+
* is the normal case a monitor exists to observe.
|
|
26
|
+
*/
|
|
27
|
+
probe(url: string): Promise<ProbeResult>
|
|
28
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
const DEFAULT_TIMEOUT_MS = 10_000
|
|
47
|
+
|
|
48
|
+
/** Bind the abstract prober port to the concrete adapter for this env + target. */
|
|
49
|
+
function selectProber(env: Env, target?: ProbeTarget): Prober {
|
|
50
|
+
if (target && isLocalTarget(target.url)) {
|
|
51
|
+
return createMockProber()
|
|
52
|
+
}
|
|
53
|
+
// Default: the real, keyless HTTP prober.
|
|
54
|
+
return createHttpProber({ timeoutMs: parseIntOr(env.PROBE_TIMEOUT_MS, DEFAULT_TIMEOUT_MS) })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A loopback / unspecified host the public edge can't reach. */
|
|
58
|
+
function isLocalTarget(url: string): boolean {
|
|
59
|
+
return /^https?:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:|\/|$)/i.test(url)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function parseIntOr(value: string | undefined, fallback: number): number {
|
|
63
|
+
if (!value) return fallback
|
|
64
|
+
const n = Number.parseInt(value, 10)
|
|
65
|
+
return Number.isFinite(n) && n > 0 ? n : fallback
|
|
66
|
+
}
|
package/template/package.json
CHANGED
|
@@ -14,11 +14,10 @@
|
|
|
14
14
|
"typecheck": "tsgo --noEmit"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@astrale-os/adapter-cloudflare": ">=0.1.
|
|
18
|
-
"@astrale-os/devkit": ">=0.1.6 <1.0.0",
|
|
17
|
+
"@astrale-os/adapter-cloudflare": ">=0.1.10 <1.0.0",
|
|
19
18
|
"@astrale-os/kernel-core": ">=0.4.3 <1.0.0",
|
|
20
19
|
"@astrale-os/kernel-dsl": ">=0.1.2 <1.0.0",
|
|
21
|
-
"@astrale-os/sdk": ">=0.1.
|
|
20
|
+
"@astrale-os/sdk": ">=0.1.7 <1.0.0",
|
|
22
21
|
"@hono/node-server": "^1.19.0",
|
|
23
22
|
"zod": "^4.3.6"
|
|
24
23
|
},
|