@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.
Files changed (123) hide show
  1. package/dist/assets-pack.d.ts +1 -1
  2. package/dist/assets-pack.js +1 -1
  3. package/dist/build.d.ts +15 -0
  4. package/dist/build.d.ts.map +1 -0
  5. package/dist/build.js +15 -0
  6. package/dist/build.js.map +1 -0
  7. package/dist/client.d.ts +9 -0
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +10 -1
  10. package/dist/client.js.map +1 -1
  11. package/dist/cloudflare.d.ts +15 -3
  12. package/dist/cloudflare.d.ts.map +1 -1
  13. package/dist/cloudflare.js +52 -18
  14. package/dist/cloudflare.js.map +1 -1
  15. package/dist/codegen/worker.d.ts +26 -6
  16. package/dist/codegen/worker.d.ts.map +1 -1
  17. package/dist/codegen/worker.js +67 -54
  18. package/dist/codegen/worker.js.map +1 -1
  19. package/dist/codegen/wrangler.d.ts +11 -2
  20. package/dist/codegen/wrangler.d.ts.map +1 -1
  21. package/dist/codegen/wrangler.js +11 -5
  22. package/dist/codegen/wrangler.js.map +1 -1
  23. package/dist/index.d.ts +6 -3
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +5 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/params.d.ts +30 -30
  28. package/dist/params.d.ts.map +1 -1
  29. package/dist/parse-output.d.ts +1 -1
  30. package/dist/parse-output.js +1 -1
  31. package/package.json +6 -2
  32. package/src/assets-pack.ts +1 -1
  33. package/src/build.ts +15 -0
  34. package/src/client.ts +11 -1
  35. package/src/cloudflare.ts +53 -18
  36. package/src/codegen/worker.ts +76 -59
  37. package/src/codegen/wrangler.ts +15 -5
  38. package/src/index.ts +6 -3
  39. package/src/params.ts +32 -31
  40. package/src/parse-output.ts +1 -1
  41. package/template/.agents/skills/astrale-cli/SKILL.md +26 -12
  42. package/template/.agents/skills/astrale-domain/SKILL.md +46 -29
  43. package/template/.env.example +6 -0
  44. package/template/README.md +25 -10
  45. package/template/astrale.config.ts +27 -33
  46. package/template/client/README.md +80 -63
  47. package/template/client/__tests__/app.test.tsx +188 -99
  48. package/template/client/__tests__/harness.ts +67 -12
  49. package/template/client/__tests__/kernel.test.ts +65 -50
  50. package/template/client/__tests__/seam.test.tsx +111 -0
  51. package/template/client/index.html +1 -1
  52. package/template/client/package.json +1 -0
  53. package/template/client/src/app.tsx +40 -83
  54. package/template/client/src/main.tsx +2 -2
  55. package/template/client/src/monitor/components/MonitorCard.tsx +50 -0
  56. package/template/client/src/monitor/components/index.ts +1 -0
  57. package/template/client/src/monitor/hooks/index.ts +3 -0
  58. package/template/client/src/monitor/hooks/useCheck.mutation.ts +16 -0
  59. package/template/client/src/monitor/hooks/useMonitor.query.ts +64 -0
  60. package/template/client/src/monitor/index.ts +6 -0
  61. package/template/client/src/monitor/monitor.api.ts +11 -0
  62. package/template/client/src/monitor/monitor.mappers.ts +38 -0
  63. package/template/client/src/monitor/monitor.types.ts +23 -0
  64. package/template/client/src/monitor/ui/MonitorDetails.UI.tsx +38 -0
  65. package/template/client/src/monitor/ui/StatusBadge.UI.tsx +14 -0
  66. package/template/client/src/monitor/ui/index.ts +8 -0
  67. package/template/client/src/shell/client.ts +67 -0
  68. package/template/client/src/shell/index.ts +20 -0
  69. package/template/client/src/shell/invoke.ts +35 -0
  70. package/template/client/src/shell/transformers.ts +72 -0
  71. package/template/client/src/shell/use-async.ts +56 -0
  72. package/template/client/src/shell/use-capability.ts +61 -0
  73. package/template/client/src/shell/use-node.ts +61 -0
  74. package/template/client/src/shell/use-shell.ts +91 -0
  75. package/template/client/src/shell/view-router.tsx +98 -0
  76. package/template/client/src/styles.css +177 -4
  77. package/template/client/src/ui/format.ts +24 -0
  78. package/template/client/src/ui/index.ts +9 -0
  79. package/template/client/src/ui/surface.tsx +56 -0
  80. package/template/client/src/ui/value.tsx +32 -0
  81. package/template/client/src/views/monitor.tsx +30 -0
  82. package/template/client/tsconfig.json +3 -2
  83. package/template/client/vite.config.ts +14 -15
  84. package/template/client/vitest.config.ts +12 -5
  85. package/template/core/monitor/health.ts +19 -0
  86. package/template/core/monitor/index.ts +9 -0
  87. package/template/core/monitor/keys.ts +29 -0
  88. package/template/core/monitor/node.ts +51 -0
  89. package/template/deps.ts +25 -0
  90. package/template/domain.ts +33 -0
  91. package/template/env.ts +4 -0
  92. package/template/integrations/prober/http.ts +43 -0
  93. package/template/integrations/prober/mock.ts +22 -0
  94. package/template/integrations/prober/port.ts +28 -0
  95. package/template/integrations/prober/registry.ts +66 -0
  96. package/template/package.json +2 -3
  97. package/template/pnpm-lock.yaml +2766 -0
  98. package/template/runtime/index.ts +79 -0
  99. package/template/runtime/monitor/check.ts +29 -0
  100. package/template/runtime/monitor/dependsOn.ts +16 -0
  101. package/template/runtime/monitor/index.ts +12 -0
  102. package/template/runtime/monitor/seed.ts +74 -0
  103. package/template/runtime/monitor/shared.ts +17 -0
  104. package/template/runtime/monitor/watch.ts +37 -0
  105. package/template/schema/index.ts +13 -4
  106. package/template/schema/monitor.ts +80 -0
  107. package/template/tsconfig.json +13 -2
  108. package/template/views/index.ts +9 -2
  109. package/template/views/monitor.ts +22 -0
  110. package/dist/astrale.d.ts +0 -27
  111. package/dist/astrale.d.ts.map +0 -1
  112. package/dist/astrale.js +0 -222
  113. package/dist/astrale.js.map +0 -1
  114. package/src/astrale.ts +0 -259
  115. package/template/client/src/lib/kernel.ts +0 -135
  116. package/template/client/src/lib/shell.ts +0 -197
  117. package/template/client/src/lib/use-node.ts +0 -66
  118. package/template/client/src/lib/use-shell.ts +0 -85
  119. package/template/methods/index.ts +0 -66
  120. package/template/methods/note.ts +0 -131
  121. package/template/schema/compiled.ts +0 -14
  122. package/template/schema/note.ts +0 -64
  123. 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
+ }
@@ -14,11 +14,10 @@
14
14
  "typecheck": "tsgo --noEmit"
15
15
  },
16
16
  "dependencies": {
17
- "@astrale-os/adapter-cloudflare": ">=0.1.7 <1.0.0",
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.5 <1.0.0",
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
  },