@brickkit/cli 0.13.3 → 0.15.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/dashboard-dist/{api-reference-mT9VNcPb.js → api-reference-BP4ULs5J.js} +4 -4
- package/dashboard-dist/app.js +10 -10
- package/dashboard-dist/{client-CwATkLJa.js → client-CID_ep-s.js} +1 -1
- package/dashboard-dist/{core-BEUWp6B5.js → core-B123mLVe.js} +1 -1
- package/dashboard-dist/{docs-BRrtyxDB.js → docs-B5JrvjJm.js} +2 -2
- package/dashboard-dist/kit.js +1 -1
- package/dashboard-dist/{popover-Bj9x-88h.js → popover-B4rnc_po.js} +1 -1
- package/dist/bin.js +44 -1
- package/dist/bin.js.map +1 -1
- package/dist/build.js +13 -6
- package/dist/build.js.map +1 -1
- package/dist/client-contract-file.js +1 -1
- package/dist/client-contract-file.js.map +1 -1
- package/dist/dashboard-host.js +35 -14
- package/dist/dashboard-host.js.map +1 -1
- package/dist/dashboard-protocol.js +21 -1
- package/dist/dashboard-protocol.js.map +1 -1
- package/dist/dashboard.d.ts +1 -1
- package/dist/definitions.js +1 -0
- package/dist/definitions.js.map +1 -1
- package/dist/dev-protocol.js.map +1 -1
- package/dist/dev-worker.js +51 -12
- package/dist/dev-worker.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/project.js +4 -2
- package/dist/project.js.map +1 -1
- package/dist/vite.js +2 -1
- package/dist/vite.js.map +1 -1
- package/package.json +2 -2
|
@@ -73,6 +73,14 @@ const ROUTES = {
|
|
|
73
73
|
production: false,
|
|
74
74
|
view: "workflows"
|
|
75
75
|
},
|
|
76
|
+
/** The app's schedules, served beside the workflow inspector: list them, run one now. */
|
|
77
|
+
schedules: {
|
|
78
|
+
path: "/api/schedules",
|
|
79
|
+
prefix: true,
|
|
80
|
+
methods: ["GET", "POST"],
|
|
81
|
+
production: false,
|
|
82
|
+
view: "schedules"
|
|
83
|
+
},
|
|
76
84
|
ingest: {
|
|
77
85
|
path: "/api/ingest",
|
|
78
86
|
methods: ["POST"],
|
|
@@ -184,6 +192,18 @@ const LIVE_LIMITS = {
|
|
|
184
192
|
failures: 200,
|
|
185
193
|
reloads: 100
|
|
186
194
|
};
|
|
187
|
-
|
|
195
|
+
/** How a schedule fires: its cron expression and time zone, or its interval (`every 6h`). */
|
|
196
|
+
function describeSchedule(schedule) {
|
|
197
|
+
if (schedule.cron) return schedule.timeZone && schedule.timeZone !== "UTC" ? `${schedule.cron} (${schedule.timeZone})` : schedule.cron;
|
|
198
|
+
const ms = schedule.every ?? 0;
|
|
199
|
+
for (const [unit, size] of [
|
|
200
|
+
["d", 864e5],
|
|
201
|
+
["h", 36e5],
|
|
202
|
+
["m", 6e4],
|
|
203
|
+
["s", 1e3]
|
|
204
|
+
]) if (ms % size === 0) return `every ${ms / size}${unit}`;
|
|
205
|
+
return `every ${ms}ms`;
|
|
206
|
+
}
|
|
207
|
+
export { matchRoute as _, INSPECTOR_TOKEN_HEADER as a, SHARED_MODULES as c, assetUrl as d, decode as f, isExternalHref as g, docsHref as h, DOCS_PATHS as i, SPAN as l, docsFileUrl as m, ATTR as n, LIVE_LIMITS as o, describeSchedule as p, CSRF_HEADER as r, ROUTES as s, ASSETS as t, THEME_STORAGE_KEY as u };
|
|
188
208
|
|
|
189
209
|
//# sourceMappingURL=dashboard-protocol.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard-protocol.js","names":[],"sources":["../src/dashboard-protocol.ts"],"sourcesContent":["import type { Attributes } from \"@opentelemetry/api\";\nimport type { ArchitectureSchema } from \"@brickkit/core\";\n\n/*\n * What the dashboard server and its page agree on: the routes, headers, event\n * names and the data they carry. Types and constants only, so the page can\n * import it without the server's code.\n */\n\n// ---------------------------------------------------------------------------\n// Span records: what the app's tracer reports, over IPC or `/api/ingest`\n\nexport interface SpanEventRecord {\n name: string;\n timeMs: number;\n attributes: Attributes;\n}\n\nexport interface SpanStartRecord {\n phase: \"start\";\n traceId: string;\n spanId: string;\n parentSpanId?: string;\n name: string;\n startMs: number;\n attributes: Attributes;\n}\n\nexport interface SpanEndRecord {\n phase: \"end\";\n traceId: string;\n spanId: string;\n name: string;\n endMs: number;\n status: \"unset\" | \"ok\" | \"error\";\n statusMessage?: string;\n attributes: Attributes;\n events: SpanEventRecord[];\n}\n\nexport type TelemetryRecord = SpanStartRecord | SpanEndRecord;\n\nexport type WorkerErrorPhase = \"startup\" | \"uncaught\" | \"unhandled-rejection\";\n\nexport interface SerializedError {\n name: string;\n message: string;\n stack?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Routes\n\n/** The dashboard's built-in views; `#/<view>/…` opens one. */\nexport const VIEW_NAMES = [\n \"requests\",\n \"logs\",\n \"overview\",\n \"apis\",\n \"docs\",\n \"workflows\",\n \"errors\",\n \"reloads\",\n] as const;\nexport type ViewName = (typeof VIEW_NAMES)[number];\n\ninterface RouteSpec {\n path: string;\n /** Also answers every path below `path`. */\n prefix?: boolean;\n /** The methods it answers; any when absent. */\n methods?: readonly string[];\n /** Served by the production dashboard; `\"extension\"`: only when it has one. */\n production: boolean | \"extension\";\n /** The page's view that needs it; a view whose routes production lacks is hidden there. */\n view?: ViewName;\n /** It changes something, so the request must carry `CSRF_HEADER`. */\n csrf?: true;\n}\n\nconst GET = [\"GET\"] as const;\n\n/**\n * Every route the dashboard serves. The server dispatches from this table and\n * the page builds its URLs from it. Production serves only what is marked\n * `production`: the shell, live state and stored history. Nothing that\n * changes the app or reaches into it, and nothing from the project's source.\n */\nexport const ROUTES = {\n /** Open to everyone: uptime monitors cannot sign in. */\n health: { path: \"/_health\", methods: [\"GET\", \"HEAD\"], production: true },\n shell: { path: \"/\", methods: GET, production: true },\n assets: { path: \"/assets\", prefix: true, methods: GET, production: true },\n /** The app itself, for an extension's `appFetch`. */\n app: { path: \"/app\", prefix: true, production: \"extension\" },\n state: { path: \"/api/state\", methods: GET, production: true },\n events: { path: \"/api/events\", methods: GET, production: true },\n history: {\n path: \"/api/history\",\n prefix: true,\n methods: GET,\n production: true,\n },\n docs: {\n path: \"/api/docs\",\n prefix: true,\n methods: GET,\n production: false,\n view: \"docs\",\n },\n openapi: {\n path: \"/api/openapi\",\n methods: GET,\n production: false,\n view: \"apis\",\n },\n /** Try it in the APIs view; the app is another origin. */\n proxy: { path: \"/api/proxy\", production: false, view: \"apis\" },\n /** The workflow inspector the app serves on a port of its own. */\n workflows: {\n path: \"/workflows\",\n prefix: true,\n production: false,\n view: \"workflows\",\n },\n ingest: {\n path: \"/api/ingest\",\n methods: [\"POST\"],\n production: false,\n csrf: true,\n },\n restart: {\n path: \"/api/restart\",\n methods: [\"POST\"],\n production: false,\n csrf: true,\n },\n} as const satisfies Record<string, RouteSpec>;\n\nexport type RouteName = keyof typeof ROUTES;\n\n/** The route a request is for, or undefined when none answers it. */\nexport function matchRoute(\n method: string | undefined,\n pathname: string,\n): RouteName | undefined {\n for (const [name, route] of Object.entries(ROUTES) as [\n RouteName,\n RouteSpec,\n ][]) {\n const at =\n pathname === route.path ||\n (route.prefix === true && pathname.startsWith(`${route.path}/`));\n if (at && (!route.methods || route.methods.includes(method ?? \"\")))\n return name;\n }\n return undefined;\n}\n\n/** Views the production dashboard hides: they need a route it does not serve. */\nexport const PRODUCTION_HIDDEN_VIEWS: ReadonlySet<string> = new Set<ViewName>(\n Object.values(ROUTES as Record<RouteName, RouteSpec>).flatMap((route) =>\n route.view && route.production === false ? [route.view] : [],\n ),\n);\n\n/** What each history query endpoint answers, as JSON. */\nexport interface HistoryResponses {\n summary: HistorySummary;\n traces: { total: number; traces: HistoryTrace[] };\n facets: HistoryFacets;\n volume: VolumeBucket[];\n}\n\n/** The history endpoints: the JSON queries, and `export` (CSV). */\nexport type HistoryEndpoint = keyof HistoryResponses | \"export\";\n\n/** A history query's address; with no endpoint, what the history holds. */\nexport const historyUrl = (\n endpoint?: HistoryEndpoint,\n params?: URLSearchParams,\n): string =>\n `${ROUTES.history.path}${endpoint ? `/${endpoint}` : \"\"}${params ? `?${params}` : \"\"}`;\n\nexport const historyTraceUrl = (traceId: string): string =>\n `${historyUrl(\"traces\")}/${encodeURIComponent(traceId)}`;\n\n/** The Docs tab's data: tree, search, compiled pages, files, components. */\nexport const DOCS_PATHS = {\n info: ROUTES.docs.path,\n search: `${ROUTES.docs.path}/search`,\n components: `${ROUTES.docs.path}/components.js`,\n page: `${ROUTES.docs.path}/page`,\n files: `${ROUTES.docs.path}/files`,\n} as const;\n\n/** A path segment as written, when it is not valid percent-encoding. */\nexport function decode(value: string): string {\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\n\n/**\n * A page address, `#/<segments>#<anchor>`, each part encoded. Every view's\n * links are built with it, and the page's `parseRoute` reads them back.\n */\nexport const hashHref = (segments: string[], anchor?: string): string =>\n `#/${encodePath(segments)}${anchor ? `#${encodeURIComponent(anchor)}` : \"\"}`;\n\n/** The page's address of a docs page, optionally at one of its headings. */\nexport const docsHref = (path: string[], anchor?: string): string =>\n hashHref([\"docs\", ...path], anchor);\n\nconst encodePath = (path: string[]): string =>\n path.map(encodeURIComponent).join(\"/\");\n\n/** Where a file in the docs folder is served, by its path inside it. */\nexport const docsFileUrl = (path: string): string =>\n `${DOCS_PATHS.files}/${encodePath(path.split(\"/\"))}`;\n\n/** Where a compiled docs page is served, by its slugs. */\nexport const docsPageUrl = (path: string[]): string =>\n `${DOCS_PATHS.page}/${encodePath(path)}`;\n\n/** Where the docs search answers `query`. */\nexport const docsSearchUrl = (query: string): string =>\n `${DOCS_PATHS.search}?q=${encodeURIComponent(query)}`;\n\n/** Whether a link names a scheme (`https:`, `mailto:`) and so leaves the dashboard. */\nexport const isExternalHref = (href: string): boolean =>\n /^[a-z][a-z\\d+.-]*:/i.test(href);\n\n/**\n * Sent with every request that changes something (restart, ingest). A page on\n * another site cannot send it without a preflight, which the server never\n * answers.\n */\nexport const CSRF_HEADER = \"x-brick-dashboard\";\nexport const CSRF_VALUE = \"1\";\n\n/** The header that proves a request to the workflow inspector comes from the dashboard. */\nexport const INSPECTOR_TOKEN_HEADER = \"x-brick-inspector\";\n\n/** What a process that cannot share memory with the dashboard posts to `/api/ingest`. */\nexport interface IngestPayload {\n /** Span records, of the newest generation. */\n records?: TelemetryRecord[];\n /** A notice that the app loaded: a new generation begins. */\n worker?: string;\n}\n\n// ---------------------------------------------------------------------------\n// The shell and its assets\n\n/** The files the shell loads from `ROUTES.assets.path`. `app.*` come from the dashboard's build. */\nexport const ASSETS = {\n app: \"app.js\",\n appCss: \"app.css\",\n /** The project's extension, or the list of parts when plugins have one too. */\n extension: \"extension.js\",\n extensionCss: \"extension.css\",\n /** The project's theme tokens; see `themeCss`. */\n theme: \"brick-theme.css\",\n} as const;\n\n/** Where an asset is served. */\nexport const assetUrl = (file: string): string =>\n `${ROUTES.assets.path}/${file}`;\n\n/**\n * What the shell tells the page in its markup: a `<meta name=\"brick-extension\"\n * data-revision data-src>` for the extension, and the theme's `<link>`.\n */\nexport const SHELL = {\n extensionMeta: 'meta[name=\"brick-extension\"]',\n themeLink: \"link[data-brick-theme]\",\n} as const;\n\n// ---------------------------------------------------------------------------\n// Modules the page shares with the project's own\n\n/**\n * What the dashboard supplies to the project's docs components and dashboard\n * extension, so there is one copy of React and of the UI kit on the page: the\n * bundler leaves `specifier` external, the shell's import map points it at\n * `/assets/<file>`, and `file` hands over the page's `globalThis.__brickDashboard[global]`.\n */\nexport const SHARED_MODULES = [\n { specifier: \"react\", file: \"react.js\", global: \"React\" },\n {\n specifier: \"react/jsx-runtime\",\n file: \"react-jsx-runtime.js\",\n global: \"jsxRuntime\",\n },\n {\n specifier: \"react/jsx-dev-runtime\",\n file: \"react-jsx-runtime.js\",\n global: \"jsxRuntime\",\n },\n { specifier: \"react-dom\", file: \"react-dom.js\", global: \"ReactDOM\" },\n {\n specifier: \"react-dom/client\",\n file: \"react-dom-client.js\",\n global: \"ReactDOMClient\",\n },\n // The UI kit is a module of the dashboard's own build.\n { specifier: \"@brickkit/cli/dashboard\", file: \"kit.js\" },\n] as const;\n\nexport type SharedGlobal = Extract<\n (typeof SHARED_MODULES)[number],\n { global: string }\n>[\"global\"];\n\n/**\n * One of several dashboard extensions (the app's and its plugins'), as\n * `/assets/extension.js` lists them in `export const parts`.\n */\nexport interface ExtensionPart {\n name: string;\n /** Relative to `extension.js`. */\n src: string;\n /** A plugin's: its pages without a place go under a section named after it. */\n plugin: boolean;\n}\n\n/** Where the page keeps the chosen theme; the shell applies it before first paint. */\nexport const THEME_STORAGE_KEY = \"brick-dashboard-theme\";\n\n// ---------------------------------------------------------------------------\n// Span names and attribute keys core sets, read here and on the page\n\nexport { SPAN, ATTR } from \"@brickkit/core/client\";\n\n// ---------------------------------------------------------------------------\n// Live data\n\n/** How many of each the live state keeps, on the server and on the page. */\nexport const LIVE_LIMITS = { traces: 200, failures: 200, reloads: 100 };\n\nexport type SpanOutcome = \"running\" | \"ok\" | \"error\" | \"interrupted\";\n\nexport interface TraceSpan {\n spanId: string;\n parentSpanId?: string;\n name: string;\n startMs: number;\n endMs?: number;\n status: SpanOutcome;\n statusMessage?: string;\n attributes: Attributes;\n events: SpanEventRecord[];\n}\n\nexport interface TraceSummary {\n traceId: string;\n name: string;\n method?: string;\n route?: string;\n /** The request's actual path, which differs from a wildcard route template. */\n path?: string;\n httpStatus?: number;\n generation: number;\n startMs: number;\n endMs?: number;\n durationMs?: number;\n status: SpanOutcome;\n truncated: boolean;\n /** The service and action that handled the request, when it ran one. */\n service?: string;\n action?: string;\n /** Why it failed, when it did. */\n message?: string;\n spans: TraceSpan[];\n}\n\nexport interface FailureSummary {\n id: number;\n at: number;\n phase: \"request\" | WorkerErrorPhase;\n code: string;\n message: string;\n status?: number;\n stack?: string;\n traceId?: string;\n route?: string;\n service?: string;\n action?: string;\n generation: number;\n}\n\nexport type ReloadKind = \"started\" | \"restarting\" | \"exited\" | \"contract-ready\";\n\nexport interface ReloadSummary {\n id: number;\n at: number;\n kind: ReloadKind;\n generation: number;\n detail?: string;\n}\n\n/** Services, actions, and routes of the application as last started. */\nexport interface ArchitectureSnapshot {\n generation: number;\n schema: ArchitectureSchema;\n}\n\n/** The OpenAPI documents the app offers, for the dashboard's APIs view. */\nexport interface ApiSnapshot {\n /** Changes each time the documents are replaced, so views know to reload. */\n revision: number;\n /** Where the app listens; Try it in the APIs view sends requests here. */\n appUrl?: string;\n /** Names of the documents, in order. */\n titles: string[];\n}\n\n/** What the dashboard knows about the app's developer documentation. */\nexport type DocsSnapshot =\n | {\n status: \"ready\";\n /** Changes whenever the pages change, so the Docs tab reloads. */\n revision: number;\n title: string;\n /** Whether the project supplied components of its own. */\n components: boolean;\n }\n /** The packages the docs need are not installed. */\n | { status: \"missing\"; packages: string[]; message: string }\n /** Why the docs cannot be shown. */\n | { status: \"error\"; message: string };\n\n/** The project's dashboard extension as last built. */\nexport interface ExtensionBuild {\n revision: number;\n /** Why the last build failed. */\n error?: string;\n}\n\nexport type DevTelemetryEvent =\n | { type: \"trace\"; trace: TraceSummary }\n | { type: \"failure\"; failure: FailureSummary }\n | { type: \"reload\"; reload: ReloadSummary }\n | { type: \"architecture\"; architecture: ArchitectureSnapshot }\n | { type: \"api\"; api: ApiSnapshot }\n | { type: \"docs\"; docs: DocsSnapshot | null }\n | { type: \"inspector\"; inspector: boolean };\n\nexport interface DevTelemetrySnapshot {\n traces: TraceSummary[];\n failures: FailureSummary[];\n reloads: ReloadSummary[];\n architecture: ArchitectureSnapshot | null;\n api: ApiSnapshot | null;\n /** Null when the app has no `documentation`. */\n docs: DocsSnapshot | null;\n /** Whether the app serves the workflow inspector the dashboard can show. */\n inspector: boolean;\n}\n\n/** `/api/state`, and the first event of `/api/events`: the store's snapshot and the server's own fields. */\nexport interface DashboardSnapshot extends DevTelemetrySnapshot {\n /** Whether the host can restart the app; the page shows the button. */\n canRestart: boolean;\n /** Days of requests kept on disk; zero when history is off. */\n historyDays: number;\n /** `production` is the read-only monitoring dashboard of `brick start`. */\n mode: \"dev\" | \"production\";\n /** The project's extension; null when it has none. */\n extension: ExtensionBuild | null;\n}\n\n/** The server-sent events of `/api/events`, by name, with the data each carries. */\nexport type DashboardEvents = {\n snapshot: DashboardSnapshot;\n /** A rebuilt extension: the page reloads to run it. */\n extension: ExtensionBuild | null;\n} & { [E in DevTelemetryEvent as E[\"type\"]]: E };\n\n/** The store's event names; each event is sent under its `type`. */\nexport const TELEMETRY_EVENTS = Object.keys({\n trace: true,\n failure: true,\n reload: true,\n architecture: true,\n api: true,\n docs: true,\n inspector: true,\n} satisfies Record<\n DevTelemetryEvent[\"type\"],\n true\n>) as DevTelemetryEvent[\"type\"][];\n\n// ---------------------------------------------------------------------------\n// Stored history\n\n/** A finished request without its spans; fetch the full trace by id. */\nexport type HistoryTrace = Omit<TraceSummary, \"spans\"> & {\n /** \"GET /api/page/:id\" when the method and route are known, else the span name. */\n endpoint: string;\n};\n\n/** How a request ended: a 5xx or crash, a 4xx, or neither. */\nexport type Outcome = \"ok\" | \"client\" | \"server\";\n\n/** Rows in one page of `/api/history/traces`, unless the query asks for another number. */\nexport const HISTORY_PAGE_SIZE = 100;\n\nexport interface VolumeBucket {\n start: number;\n ok: number;\n client: number;\n server: number;\n}\n\n/** The numbers behind the cards at the top of the log, for what matches. */\nexport interface HistorySummary {\n total: number;\n clientErrors: number;\n serverErrors: number;\n medianMs: number;\n p95Ms: number;\n}\n\nexport interface FacetValue {\n value: string;\n count: number;\n}\n\n/** What is in the range, counted for each filter as if it were not applied. */\nexport interface HistoryFacets {\n outcome: FacetValue[];\n method: FacetValue[];\n service: FacetValue[];\n endpoint: FacetValue[];\n}\n\nexport interface HistoryInfo {\n days: number;\n count: number;\n oldestMs?: number;\n}\n\n// ---------------------------------------------------------------------------\n// Docs\n\n/** One entry of the docs sidebar. */\nexport type DocsNode =\n | { type: \"page\"; name: string; url: string; description?: string }\n | {\n type: \"folder\";\n name: string;\n index?: { name: string; url: string };\n children: DocsNode[];\n defaultOpen?: boolean;\n }\n | { type: \"separator\"; name?: string };\n\nexport interface DocsTree {\n name: string;\n children: DocsNode[];\n}\n\nexport interface DocsHeading {\n title: string;\n url: string;\n depth: number;\n}\n\n/** A page ready to run in the browser. */\nexport interface DocsPage {\n title: string;\n description?: string;\n /** The file, relative to the docs folder. */\n path: string;\n slugs: string[];\n toc: DocsHeading[];\n /** MDX compiled to a function body; see `runMdx` in the dashboard. */\n code: string;\n /** Set instead of `code` when the page does not compile. */\n error?: string;\n}\n\nexport interface DocsSearchHit {\n id: string;\n type: \"page\" | \"heading\" | \"text\";\n content: string;\n /** Route within the docs, with a `#heading` when the hit is inside a page. */\n url: string;\n}\n\nexport interface DocsInfo {\n tree: DocsTree;\n /** Whether the project supplied components of its own. */\n components: boolean;\n revision: number;\n}\n"],"mappings":";;AAgFA,MAAM,MAAM,CAAC,KAAK;;;;;;;AAQlB,MAAa,SAAS;;CAEpB,QAAQ;EAAE,MAAM;EAAY,SAAS,CAAC,OAAO,MAAM;EAAG,YAAY;CAAK;CACvE,OAAO;EAAE,MAAM;EAAK,SAAS;EAAK,YAAY;CAAK;CACnD,QAAQ;EAAE,MAAM;EAAW,QAAQ;EAAM,SAAS;EAAK,YAAY;CAAK;;CAExE,KAAK;EAAE,MAAM;EAAQ,QAAQ;EAAM,YAAY;CAAY;CAC3D,OAAO;EAAE,MAAM;EAAc,SAAS;EAAK,YAAY;CAAK;CAC5D,QAAQ;EAAE,MAAM;EAAe,SAAS;EAAK,YAAY;CAAK;CAC9D,SAAS;EACP,MAAM;EACN,QAAQ;EACR,SAAS;EACT,YAAY;CACd;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,SAAS;EACT,YAAY;EACZ,MAAM;CACR;CACA,SAAS;EACP,MAAM;EACN,SAAS;EACT,YAAY;EACZ,MAAM;CACR;;CAEA,OAAO;EAAE,MAAM;EAAc,YAAY;EAAO,MAAM;CAAO;;CAE7D,WAAW;EACT,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,MAAM;CACR;CACA,QAAQ;EACN,MAAM;EACN,SAAS,CAAC,MAAM;EAChB,YAA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AK;CACL,QAAQ;;CAER,WAAW;CACX,cAAc;;CAEd,OAAO;AACT;;AAGA,MAAa,YAAY,SACvB,GAAG,OAAO,OAAO,KAAK,GAAG;;;;;;;AAoB3B,MAAa,iBAAiB;CAC5B;EAAE,WAAW;EAAS,MAAM;EAAY,QAAQ;CAAQ;CACxD;EACE,WAAW;EACX,MAAM;EACN,QAAQ;CACV;CACA;EACE,WAAW;EACX,MAAM;EACN,QAAQ;CACV;CACA;EAAE,WAAW;EAAa,MAAM;EAAgB,QAAQ;CAAW;CACnE;EACE,WAAW;EACX,MAAM;EACN,QAAQ;CACV;CAEA;EAAE,WAAW;EAA2B,MAAM;CAAS;AACzD;;AAoBA,MAAa,oBAAoB;;AAWjC,MAAa,cAAc;CAAE,QAAQ;CAAK,UAAU;CAAK,SAAS;AAAI"}
|
|
1
|
+
{"version":3,"file":"dashboard-protocol.js","names":[],"sources":["../src/dashboard-protocol.ts"],"sourcesContent":["import type { Attributes } from \"@opentelemetry/api\";\nimport type { ArchitectureSchema } from \"@brickkit/core\";\n\n/*\n * What the dashboard server and its page agree on: the routes, headers, event\n * names and the data they carry. Types and constants only, so the page can\n * import it without the server's code.\n */\n\n// ---------------------------------------------------------------------------\n// Span records: what the app's tracer reports, over IPC or `/api/ingest`\n\nexport interface SpanEventRecord {\n name: string;\n timeMs: number;\n attributes: Attributes;\n}\n\nexport interface SpanStartRecord {\n phase: \"start\";\n traceId: string;\n spanId: string;\n parentSpanId?: string;\n name: string;\n startMs: number;\n attributes: Attributes;\n}\n\nexport interface SpanEndRecord {\n phase: \"end\";\n traceId: string;\n spanId: string;\n name: string;\n endMs: number;\n status: \"unset\" | \"ok\" | \"error\";\n statusMessage?: string;\n attributes: Attributes;\n events: SpanEventRecord[];\n}\n\nexport type TelemetryRecord = SpanStartRecord | SpanEndRecord;\n\nexport type WorkerErrorPhase = \"startup\" | \"uncaught\" | \"unhandled-rejection\";\n\nexport interface SerializedError {\n name: string;\n message: string;\n stack?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Routes\n\n/** The dashboard's built-in views; `#/<view>/…` opens one. */\nexport const VIEW_NAMES = [\n \"requests\",\n \"logs\",\n \"overview\",\n \"apis\",\n \"docs\",\n \"workflows\",\n \"schedules\",\n \"errors\",\n \"reloads\",\n] as const;\nexport type ViewName = (typeof VIEW_NAMES)[number];\n\ninterface RouteSpec {\n path: string;\n /** Also answers every path below `path`. */\n prefix?: boolean;\n /** The methods it answers; any when absent. */\n methods?: readonly string[];\n /** Served by the production dashboard; `\"extension\"`: only when it has one. */\n production: boolean | \"extension\";\n /** The page's view that needs it; a view whose routes production lacks is hidden there. */\n view?: ViewName;\n /** It changes something, so the request must carry `CSRF_HEADER`. */\n csrf?: true;\n}\n\nconst GET = [\"GET\"] as const;\n\n/**\n * Every route the dashboard serves. The server dispatches from this table and\n * the page builds its URLs from it. Production serves only what is marked\n * `production`: the shell, live state and stored history. Nothing that\n * changes the app or reaches into it, and nothing from the project's source.\n */\nexport const ROUTES = {\n /** Open to everyone: uptime monitors cannot sign in. */\n health: { path: \"/_health\", methods: [\"GET\", \"HEAD\"], production: true },\n shell: { path: \"/\", methods: GET, production: true },\n assets: { path: \"/assets\", prefix: true, methods: GET, production: true },\n /** The app itself, for an extension's `appFetch`. */\n app: { path: \"/app\", prefix: true, production: \"extension\" },\n state: { path: \"/api/state\", methods: GET, production: true },\n events: { path: \"/api/events\", methods: GET, production: true },\n history: {\n path: \"/api/history\",\n prefix: true,\n methods: GET,\n production: true,\n },\n docs: {\n path: \"/api/docs\",\n prefix: true,\n methods: GET,\n production: false,\n view: \"docs\",\n },\n openapi: {\n path: \"/api/openapi\",\n methods: GET,\n production: false,\n view: \"apis\",\n },\n /** Try it in the APIs view; the app is another origin. */\n proxy: { path: \"/api/proxy\", production: false, view: \"apis\" },\n /** The workflow inspector the app serves on a port of its own. */\n workflows: {\n path: \"/workflows\",\n prefix: true,\n production: false,\n view: \"workflows\",\n },\n /** The app's schedules, served beside the workflow inspector: list them, run one now. */\n schedules: {\n path: \"/api/schedules\",\n prefix: true,\n methods: [\"GET\", \"POST\"],\n production: false,\n view: \"schedules\",\n },\n ingest: {\n path: \"/api/ingest\",\n methods: [\"POST\"],\n production: false,\n csrf: true,\n },\n restart: {\n path: \"/api/restart\",\n methods: [\"POST\"],\n production: false,\n csrf: true,\n },\n} as const satisfies Record<string, RouteSpec>;\n\nexport type RouteName = keyof typeof ROUTES;\n\n/** The route a request is for, or undefined when none answers it. */\nexport function matchRoute(\n method: string | undefined,\n pathname: string,\n): RouteName | undefined {\n for (const [name, route] of Object.entries(ROUTES) as [\n RouteName,\n RouteSpec,\n ][]) {\n const at =\n pathname === route.path ||\n (route.prefix === true && pathname.startsWith(`${route.path}/`));\n if (at && (!route.methods || route.methods.includes(method ?? \"\")))\n return name;\n }\n return undefined;\n}\n\n/** Views the production dashboard hides: they need a route it does not serve. */\nexport const PRODUCTION_HIDDEN_VIEWS: ReadonlySet<string> = new Set<ViewName>(\n Object.values(ROUTES as Record<RouteName, RouteSpec>).flatMap((route) =>\n route.view && route.production === false ? [route.view] : [],\n ),\n);\n\n/** What each history query endpoint answers, as JSON. */\nexport interface HistoryResponses {\n summary: HistorySummary;\n traces: { total: number; traces: HistoryTrace[] };\n facets: HistoryFacets;\n volume: VolumeBucket[];\n}\n\n/** The history endpoints: the JSON queries, and `export` (CSV). */\nexport type HistoryEndpoint = keyof HistoryResponses | \"export\";\n\n/** A history query's address; with no endpoint, what the history holds. */\nexport const historyUrl = (\n endpoint?: HistoryEndpoint,\n params?: URLSearchParams,\n): string =>\n `${ROUTES.history.path}${endpoint ? `/${endpoint}` : \"\"}${params ? `?${params}` : \"\"}`;\n\nexport const historyTraceUrl = (traceId: string): string =>\n `${historyUrl(\"traces\")}/${encodeURIComponent(traceId)}`;\n\n/** The Docs tab's data: tree, search, compiled pages, files, components. */\nexport const DOCS_PATHS = {\n info: ROUTES.docs.path,\n search: `${ROUTES.docs.path}/search`,\n components: `${ROUTES.docs.path}/components.js`,\n page: `${ROUTES.docs.path}/page`,\n files: `${ROUTES.docs.path}/files`,\n} as const;\n\n/** A path segment as written, when it is not valid percent-encoding. */\nexport function decode(value: string): string {\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\n\n/**\n * A page address, `#/<segments>#<anchor>`, each part encoded. Every view's\n * links are built with it, and the page's `parseRoute` reads them back.\n */\nexport const hashHref = (segments: string[], anchor?: string): string =>\n `#/${encodePath(segments)}${anchor ? `#${encodeURIComponent(anchor)}` : \"\"}`;\n\n/** The page's address of a docs page, optionally at one of its headings. */\nexport const docsHref = (path: string[], anchor?: string): string =>\n hashHref([\"docs\", ...path], anchor);\n\nconst encodePath = (path: string[]): string =>\n path.map(encodeURIComponent).join(\"/\");\n\n/** Where a file in the docs folder is served, by its path inside it. */\nexport const docsFileUrl = (path: string): string =>\n `${DOCS_PATHS.files}/${encodePath(path.split(\"/\"))}`;\n\n/** Where a compiled docs page is served, by its slugs. */\nexport const docsPageUrl = (path: string[]): string =>\n `${DOCS_PATHS.page}/${encodePath(path)}`;\n\n/** Where the docs search answers `query`. */\nexport const docsSearchUrl = (query: string): string =>\n `${DOCS_PATHS.search}?q=${encodeURIComponent(query)}`;\n\n/** Whether a link names a scheme (`https:`, `mailto:`) and so leaves the dashboard. */\nexport const isExternalHref = (href: string): boolean =>\n /^[a-z][a-z\\d+.-]*:/i.test(href);\n\n/**\n * Sent with every request that changes something (restart, ingest). A page on\n * another site cannot send it without a preflight, which the server never\n * answers.\n */\nexport const CSRF_HEADER = \"x-brick-dashboard\";\nexport const CSRF_VALUE = \"1\";\n\n/** The header that proves a request to the workflow inspector comes from the dashboard. */\nexport const INSPECTOR_TOKEN_HEADER = \"x-brick-inspector\";\n\n/** What a process that cannot share memory with the dashboard posts to `/api/ingest`. */\nexport interface IngestPayload {\n /** Span records, of the newest generation. */\n records?: TelemetryRecord[];\n /** A notice that the app loaded: a new generation begins. */\n worker?: string;\n}\n\n// ---------------------------------------------------------------------------\n// The shell and its assets\n\n/** The files the shell loads from `ROUTES.assets.path`. `app.*` come from the dashboard's build. */\nexport const ASSETS = {\n app: \"app.js\",\n appCss: \"app.css\",\n /** The project's extension, or the list of parts when plugins have one too. */\n extension: \"extension.js\",\n extensionCss: \"extension.css\",\n /** The project's theme tokens; see `themeCss`. */\n theme: \"brick-theme.css\",\n} as const;\n\n/** Where an asset is served. */\nexport const assetUrl = (file: string): string =>\n `${ROUTES.assets.path}/${file}`;\n\n/**\n * What the shell tells the page in its markup: a `<meta name=\"brick-extension\"\n * data-revision data-src>` for the extension, and the theme's `<link>`.\n */\nexport const SHELL = {\n extensionMeta: 'meta[name=\"brick-extension\"]',\n themeLink: \"link[data-brick-theme]\",\n} as const;\n\n// ---------------------------------------------------------------------------\n// Modules the page shares with the project's own\n\n/**\n * What the dashboard supplies to the project's docs components and dashboard\n * extension, so there is one copy of React and of the UI kit on the page: the\n * bundler leaves `specifier` external, the shell's import map points it at\n * `/assets/<file>`, and `file` hands over the page's `globalThis.__brickDashboard[global]`.\n */\nexport const SHARED_MODULES = [\n { specifier: \"react\", file: \"react.js\", global: \"React\" },\n {\n specifier: \"react/jsx-runtime\",\n file: \"react-jsx-runtime.js\",\n global: \"jsxRuntime\",\n },\n {\n specifier: \"react/jsx-dev-runtime\",\n file: \"react-jsx-runtime.js\",\n global: \"jsxRuntime\",\n },\n { specifier: \"react-dom\", file: \"react-dom.js\", global: \"ReactDOM\" },\n {\n specifier: \"react-dom/client\",\n file: \"react-dom-client.js\",\n global: \"ReactDOMClient\",\n },\n // The UI kit is a module of the dashboard's own build.\n { specifier: \"@brickkit/cli/dashboard\", file: \"kit.js\" },\n] as const;\n\nexport type SharedGlobal = Extract<\n (typeof SHARED_MODULES)[number],\n { global: string }\n>[\"global\"];\n\n/**\n * One of several dashboard extensions (the app's and its plugins'), as\n * `/assets/extension.js` lists them in `export const parts`.\n */\nexport interface ExtensionPart {\n name: string;\n /** Relative to `extension.js`. */\n src: string;\n /** A plugin's: its pages without a place go under a section named after it. */\n plugin: boolean;\n}\n\n/** Where the page keeps the chosen theme; the shell applies it before first paint. */\nexport const THEME_STORAGE_KEY = \"brick-dashboard-theme\";\n\n// ---------------------------------------------------------------------------\n// Span names and attribute keys core sets, read here and on the page\n\nexport { SPAN, ATTR } from \"@brickkit/core/client\";\n\n// ---------------------------------------------------------------------------\n// Live data\n\n/** How many of each the live state keeps, on the server and on the page. */\nexport const LIVE_LIMITS = { traces: 200, failures: 200, reloads: 100 };\n\nexport type SpanOutcome = \"running\" | \"ok\" | \"error\" | \"interrupted\";\n\nexport interface TraceSpan {\n spanId: string;\n parentSpanId?: string;\n name: string;\n startMs: number;\n endMs?: number;\n status: SpanOutcome;\n statusMessage?: string;\n attributes: Attributes;\n events: SpanEventRecord[];\n}\n\nexport interface TraceSummary {\n traceId: string;\n name: string;\n method?: string;\n route?: string;\n /** The request's actual path, which differs from a wildcard route template. */\n path?: string;\n httpStatus?: number;\n generation: number;\n startMs: number;\n endMs?: number;\n durationMs?: number;\n status: SpanOutcome;\n truncated: boolean;\n /** The service and action that handled the request, when it ran one. */\n service?: string;\n action?: string;\n /** Why it failed, when it did. */\n message?: string;\n spans: TraceSpan[];\n}\n\nexport interface FailureSummary {\n id: number;\n at: number;\n phase: \"request\" | WorkerErrorPhase;\n code: string;\n message: string;\n status?: number;\n stack?: string;\n traceId?: string;\n route?: string;\n service?: string;\n action?: string;\n generation: number;\n}\n\nexport type ReloadKind = \"started\" | \"restarting\" | \"exited\" | \"contract-ready\";\n\nexport interface ReloadSummary {\n id: number;\n at: number;\n kind: ReloadKind;\n generation: number;\n detail?: string;\n}\n\n/** Services, actions, and routes of the application as last started. */\nexport interface ArchitectureSnapshot {\n generation: number;\n schema: ArchitectureSchema;\n}\n\n/** The OpenAPI documents the app offers, for the dashboard's APIs view. */\nexport interface ApiSnapshot {\n /** Changes each time the documents are replaced, so views know to reload. */\n revision: number;\n /** Where the app listens; Try it in the APIs view sends requests here. */\n appUrl?: string;\n /** Names of the documents, in order. */\n titles: string[];\n}\n\n/** What the dashboard knows about the app's developer documentation. */\nexport type DocsSnapshot =\n | {\n status: \"ready\";\n /** Changes whenever the pages change, so the Docs tab reloads. */\n revision: number;\n title: string;\n /** Whether the project supplied components of its own. */\n components: boolean;\n }\n /** The packages the docs need are not installed. */\n | { status: \"missing\"; packages: string[]; message: string }\n /** Why the docs cannot be shown. */\n | { status: \"error\"; message: string };\n\n/** The project's dashboard extension as last built. */\nexport interface ExtensionBuild {\n revision: number;\n /** Why the last build failed. */\n error?: string;\n}\n\nexport type DevTelemetryEvent =\n | { type: \"trace\"; trace: TraceSummary }\n | { type: \"failure\"; failure: FailureSummary }\n | { type: \"reload\"; reload: ReloadSummary }\n | { type: \"architecture\"; architecture: ArchitectureSnapshot }\n | { type: \"api\"; api: ApiSnapshot }\n | { type: \"docs\"; docs: DocsSnapshot | null }\n | { type: \"inspector\"; inspector: boolean };\n\nexport interface DevTelemetrySnapshot {\n traces: TraceSummary[];\n failures: FailureSummary[];\n reloads: ReloadSummary[];\n architecture: ArchitectureSnapshot | null;\n api: ApiSnapshot | null;\n /** Null when the app has no `documentation`. */\n docs: DocsSnapshot | null;\n /** Whether the app serves the workflow inspector the dashboard can show. */\n inspector: boolean;\n}\n\n/** `/api/state`, and the first event of `/api/events`: the store's snapshot and the server's own fields. */\nexport interface DashboardSnapshot extends DevTelemetrySnapshot {\n /** Whether the host can restart the app; the page shows the button. */\n canRestart: boolean;\n /** Days of requests kept on disk; zero when history is off. */\n historyDays: number;\n /** `production` is the read-only monitoring dashboard of `brick start`. */\n mode: \"dev\" | \"production\";\n /** The project's extension; null when it has none. */\n extension: ExtensionBuild | null;\n}\n\n/** The server-sent events of `/api/events`, by name, with the data each carries. */\nexport type DashboardEvents = {\n snapshot: DashboardSnapshot;\n /** A rebuilt extension: the page reloads to run it. */\n extension: ExtensionBuild | null;\n} & { [E in DevTelemetryEvent as E[\"type\"]]: E };\n\n/** The store's event names; each event is sent under its `type`. */\nexport const TELEMETRY_EVENTS = Object.keys({\n trace: true,\n failure: true,\n reload: true,\n architecture: true,\n api: true,\n docs: true,\n inspector: true,\n} satisfies Record<\n DevTelemetryEvent[\"type\"],\n true\n>) as DevTelemetryEvent[\"type\"][];\n\n// ---------------------------------------------------------------------------\n// Stored history\n\n/** A finished request without its spans; fetch the full trace by id. */\nexport type HistoryTrace = Omit<TraceSummary, \"spans\"> & {\n /** \"GET /api/page/:id\" when the method and route are known, else the span name. */\n endpoint: string;\n};\n\n/** How a request ended: a 5xx or crash, a 4xx, or neither. */\nexport type Outcome = \"ok\" | \"client\" | \"server\";\n\n/** Rows in one page of `/api/history/traces`, unless the query asks for another number. */\nexport const HISTORY_PAGE_SIZE = 100;\n\nexport interface VolumeBucket {\n start: number;\n ok: number;\n client: number;\n server: number;\n}\n\n/** The numbers behind the cards at the top of the log, for what matches. */\nexport interface HistorySummary {\n total: number;\n clientErrors: number;\n serverErrors: number;\n medianMs: number;\n p95Ms: number;\n}\n\nexport interface FacetValue {\n value: string;\n count: number;\n}\n\n/** What is in the range, counted for each filter as if it were not applied. */\nexport interface HistoryFacets {\n outcome: FacetValue[];\n method: FacetValue[];\n service: FacetValue[];\n endpoint: FacetValue[];\n}\n\nexport interface HistoryInfo {\n days: number;\n count: number;\n oldestMs?: number;\n}\n\n// ---------------------------------------------------------------------------\n// Docs\n\n/** One entry of the docs sidebar. */\nexport type DocsNode =\n | { type: \"page\"; name: string; url: string; description?: string }\n | {\n type: \"folder\";\n name: string;\n index?: { name: string; url: string };\n children: DocsNode[];\n defaultOpen?: boolean;\n }\n | { type: \"separator\"; name?: string };\n\nexport interface DocsTree {\n name: string;\n children: DocsNode[];\n}\n\nexport interface DocsHeading {\n title: string;\n url: string;\n depth: number;\n}\n\n/** A page ready to run in the browser. */\nexport interface DocsPage {\n title: string;\n description?: string;\n /** The file, relative to the docs folder. */\n path: string;\n slugs: string[];\n toc: DocsHeading[];\n /** MDX compiled to a function body; see `runMdx` in the dashboard. */\n code: string;\n /** Set instead of `code` when the page does not compile. */\n error?: string;\n}\n\nexport interface DocsSearchHit {\n id: string;\n type: \"page\" | \"heading\" | \"text\";\n content: string;\n /** Route within the docs, with a `#heading` when the hit is inside a page. */\n url: string;\n}\n\nexport interface DocsInfo {\n tree: DocsTree;\n /** Whether the project supplied components of its own. */\n components: boolean;\n revision: number;\n}\n\n/** How a schedule fires: its cron expression and time zone, or its interval (`every 6h`). */\nexport function describeSchedule(schedule: {\n cron?: string;\n timeZone?: string;\n every?: number;\n}): string {\n if (schedule.cron)\n return schedule.timeZone && schedule.timeZone !== \"UTC\"\n ? `${schedule.cron} (${schedule.timeZone})`\n : schedule.cron;\n const ms = schedule.every ?? 0;\n for (const [unit, size] of [\n [\"d\", 86_400_000],\n [\"h\", 3_600_000],\n [\"m\", 60_000],\n [\"s\", 1000],\n ] as const)\n if (ms % size === 0) return `every ${ms / size}${unit}`;\n return `every ${ms}ms`;\n}\n"],"mappings":";;AAiFA,MAAM,MAAM,CAAC,KAAK;;;;;;;AAQlB,MAAa,SAAS;;CAEpB,QAAQ;EAAE,MAAM;EAAY,SAAS,CAAC,OAAO,MAAM;EAAG,YAAY;CAAK;CACvE,OAAO;EAAE,MAAM;EAAK,SAAS;EAAK,YAAY;CAAK;CACnD,QAAQ;EAAE,MAAM;EAAW,QAAQ;EAAM,SAAS;EAAK,YAAY;CAAK;;CAExE,KAAK;EAAE,MAAM;EAAQ,QAAQ;EAAM,YAAY;CAAY;CAC3D,OAAO;EAAE,MAAM;EAAc,SAAS;EAAK,YAAY;CAAK;CAC5D,QAAQ;EAAE,MAAM;EAAe,SAAS;EAAK,YAAY;CAAK;CAC9D,SAAS;EACP,MAAM;EACN,QAAQ;EACR,SAAS;EACT,YAAY;CACd;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,SAAS;EACT,YAAY;EACZ,MAAM;CACR;CACA,SAAS;EACP,MAAM;EACN,SAAS;EACT,YAAY;EACZ,MAAM;CACR;;CAEA,OAAO;EAAE,MAAM;EAAc,YAAY;EAAO,MAA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
|
/** The dashboard's built-in views; `#/<view>/…` opens one. */
|
|
13
|
-
declare const VIEW_NAMES: readonly ["requests", "logs", "overview", "apis", "docs", "workflows", "errors", "reloads"];
|
|
13
|
+
declare const VIEW_NAMES: readonly ["requests", "logs", "overview", "apis", "docs", "workflows", "schedules", "errors", "reloads"];
|
|
14
14
|
type ViewName = (typeof VIEW_NAMES)[number];
|
|
15
15
|
type SpanOutcome = "running" | "ok" | "error" | "interrupted";
|
|
16
16
|
interface TraceSpan {
|
package/dist/definitions.js
CHANGED
package/dist/definitions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","names":[],"sources":["../src/definitions.ts"],"sourcesContent":["// The project structure's file names, shared by the manifest and the lint.\n// A leaf: the lint plugin bundles it to run under Node.\n\n/** Definition file kinds: `<name>.<kind>.ts`. */\nexport const DEFINITION_KINDS = [\n \"service\",\n \"events\",\n \"resource\",\n \"table\",\n \"action\",\n \"command\",\n \"tool\",\n \"socket\",\n \"listener\",\n \"workflow\",\n \"step\",\n] as const;\nexport type DefinitionKind = (typeof DEFINITION_KINDS)[number];\n\n/** The extensions a definition file may have. */\nexport const DEFINITION_EXTENSIONS = [\"ts\", \"tsx\", \"mts\", \"js\", \"jsx\", \"mjs\"];\n\n/** A definition file name: the name, then the kind, then the extension. */\nexport const DEFINITION_FILE = new RegExp(\n `^(.*)\\\\.(${DEFINITION_KINDS.join(\"|\")})\\\\.(${DEFINITION_EXTENSIONS.join(\"|\")})$`,\n);\n\n/** A test file name: `*.test.ts`, `*.spec.mjs` and the like. */\nexport const TEST_FILE = /\\.(test|spec)\\.[cm]?[jt]sx?$/;\n\n/** The generated file that imports every definition file. */\nexport const MANIFEST_FILE = \"services.gen.ts\";\n"],"mappings":";;AAIA,MAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAIA,MAAa,wBAAwB;CAAC;CAAM;CAAO;CAAO;CAAM;CAAO;AAAK;;AAG5E,MAAa,kBAAkB,IAAI,OACjC,YAAY,iBAAiB,KAAK,GAAG,EAAE,OAAO,sBAAsB,KAAK,GAAG,EAAE,GAChF;;AAGA,MAAa,YAAY;;AAGzB,MAAa,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"definitions.js","names":[],"sources":["../src/definitions.ts"],"sourcesContent":["// The project structure's file names, shared by the manifest and the lint.\n// A leaf: the lint plugin bundles it to run under Node.\n\n/** Definition file kinds: `<name>.<kind>.ts`. */\nexport const DEFINITION_KINDS = [\n \"service\",\n \"events\",\n \"resource\",\n \"table\",\n \"action\",\n \"command\",\n \"tool\",\n \"socket\",\n \"listener\",\n \"schedule\",\n \"workflow\",\n \"step\",\n] as const;\nexport type DefinitionKind = (typeof DEFINITION_KINDS)[number];\n\n/** The extensions a definition file may have. */\nexport const DEFINITION_EXTENSIONS = [\"ts\", \"tsx\", \"mts\", \"js\", \"jsx\", \"mjs\"];\n\n/** A definition file name: the name, then the kind, then the extension. */\nexport const DEFINITION_FILE = new RegExp(\n `^(.*)\\\\.(${DEFINITION_KINDS.join(\"|\")})\\\\.(${DEFINITION_EXTENSIONS.join(\"|\")})$`,\n);\n\n/** A test file name: `*.test.ts`, `*.spec.mjs` and the like. */\nexport const TEST_FILE = /\\.(test|spec)\\.[cm]?[jt]sx?$/;\n\n/** The generated file that imports every definition file. */\nexport const MANIFEST_FILE = \"services.gen.ts\";\n"],"mappings":";;AAIA,MAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAIA,MAAa,wBAAwB;CAAC;CAAM;CAAO;CAAO;CAAM;CAAO;AAAK;;AAG5E,MAAa,kBAAkB,IAAI,OACjC,YAAY,iBAAiB,KAAK,GAAG,EAAE,OAAO,sBAAsB,KAAK,GAAG,EAAE,GAChF;;AAGA,MAAa,YAAY;;AAGzB,MAAa,gBAAgB"}
|
package/dist/dev-protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-protocol.js","names":[],"sources":["../src/dev-protocol.ts"],"sourcesContent":["import type {\n ApiDocument,\n ArchitectureSchema,\n DocumentationOptions,\n} from \"@brickkit/core\";\nimport type {\n SerializedError,\n TelemetryRecord,\n WorkerErrorPhase,\n} from \"./dashboard-protocol\";\n\nconst SEND_TIMEOUT_MS = 1000;\n\n/*\n * What `brick dev`'s supervisor and its worker process agree on: the options\n * the worker starts with, and the messages it sends back over IPC.\n */\n\n/** The worker's one argument, as JSON. */\nexport interface WorkerOptions {\n /** Absolute path of the app entry. */\n entry: string;\n port: number;\n prefix?: string;\n /** Absolute path of the browser contract to write before serving. */\n clientOutput?: string;\n /** The supervisor serves the dashboard, so the worker reports its spans. */\n telemetry: boolean;\n}\n\n/** Messages the dev worker sends to the supervisor over the IPC channel. */\nexport type WorkerMessage =\n | { type: \"brick:telemetry\"; records: TelemetryRecord[] }\n | { type: \"brick:error\"; phase: WorkerErrorPhase; error: SerializedError }\n | { type: \"brick:architecture\"; architecture: ArchitectureSchema }\n | { type: \"brick:api-documents\"; documents: ApiDocument[] }\n | {\n type: \"brick:inspector\";\n /** The loopback port the workflow inspector
|
|
1
|
+
{"version":3,"file":"dev-protocol.js","names":[],"sources":["../src/dev-protocol.ts"],"sourcesContent":["import type {\n ApiDocument,\n ArchitectureSchema,\n DocumentationOptions,\n} from \"@brickkit/core\";\nimport type {\n SerializedError,\n TelemetryRecord,\n WorkerErrorPhase,\n} from \"./dashboard-protocol\";\n\nconst SEND_TIMEOUT_MS = 1000;\n\n/*\n * What `brick dev`'s supervisor and its worker process agree on: the options\n * the worker starts with, and the messages it sends back over IPC.\n */\n\n/** The worker's one argument, as JSON. */\nexport interface WorkerOptions {\n /** Absolute path of the app entry. */\n entry: string;\n port: number;\n prefix?: string;\n /** Absolute path of the browser contract to write before serving. */\n clientOutput?: string;\n /** The supervisor serves the dashboard, so the worker reports its spans. */\n telemetry: boolean;\n}\n\n/** Messages the dev worker sends to the supervisor over the IPC channel. */\nexport type WorkerMessage =\n | { type: \"brick:telemetry\"; records: TelemetryRecord[] }\n | { type: \"brick:error\"; phase: WorkerErrorPhase; error: SerializedError }\n | { type: \"brick:architecture\"; architecture: ArchitectureSchema }\n | { type: \"brick:api-documents\"; documents: ApiDocument[] }\n | {\n type: \"brick:inspector\";\n /** The loopback port the workflow inspector and the schedules listen on. */\n port: number;\n /** Whether it serves the workflow inspector, not only the schedules. */\n workflows: boolean;\n /** What the dashboard sends with each request to prove who it is. */\n token: string;\n }\n | {\n type: \"brick:documentation\";\n /** The app's `documentation` option; absent when it has none. */\n documentation?: DocumentationOptions;\n }\n /** The local files the entry imports, for the supervisor to watch. */\n | { type: \"brick:dependencies\"; files: string[] }\n /** The browser contract is written; the frontend may start. */\n | { type: \"brick:contract-ready\" };\n\n/** Resolves once the message is written, or after a short timeout if the channel is gone. */\nexport function sendToSupervisor(message: WorkerMessage): Promise<void> {\n if (!process.send) return Promise.resolve();\n return new Promise((resolve) => {\n const timer = setTimeout(resolve, SEND_TIMEOUT_MS);\n try {\n process.send!(message, () => {\n clearTimeout(timer);\n resolve();\n });\n } catch {\n clearTimeout(timer);\n resolve();\n }\n });\n}\n"],"mappings":";AAWA,MAAM,kBAAkB;;AA6CxB,SAAgB,iBAAiB,SAAuC;CACtE,IAAI,CAAC,QAAQ,MAAM,OAAO,QAAQ,QAAQ;CAC1C,OAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,QAAQ,WAAW,SAAS,eAAe;EACjD,IAAI;GACF,QAAQ,KAAM,eAAe;IAC3B,aAAa,KAAK;IAClB,QAAQ;GACV,CAAC;EACH,QAAQ;GACN,aAAa,KAAK;GAClB,QAAQ;EACV;CACF,CAAC;AACH"}
|
package/dist/dev-worker.js
CHANGED
|
@@ -34,38 +34,76 @@ function browserAsset(request, client) {
|
|
|
34
34
|
return new Response(Bun.file(file), { headers: { "cache-control": "public, max-age=31536000, immutable" } });
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
+
* The app's schedules, for the dashboard's Schedules view: `GET` lists them,
|
|
38
|
+
* `POST <path>/<name>` runs one now.
|
|
39
|
+
*/
|
|
40
|
+
async function schedulesRoute(schedules, names, request, pathname) {
|
|
41
|
+
let name;
|
|
42
|
+
try {
|
|
43
|
+
name = decodeURIComponent(pathname.slice(ROUTES.schedules.path.length + 1));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return new Response(error.message, { status: 400 });
|
|
46
|
+
}
|
|
47
|
+
if (request.method === "GET" && !name) return Response.json(await schedules.list());
|
|
48
|
+
if (request.method !== "POST" || !name) return new Response("Not found", { status: 404 });
|
|
49
|
+
if (!names.has(name)) return new Response(`No schedule named '${name}'`, { status: 404 });
|
|
50
|
+
try {
|
|
51
|
+
return Response.json({ started: await schedules.trigger(name) });
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return new Response(error.message, { status: 500 });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
37
57
|
* Serve the Workflow inspector (the Workflow SDK's observability UI, built into
|
|
38
|
-
* this package) for the app's world,
|
|
39
|
-
* dashboard proxies
|
|
40
|
-
*
|
|
41
|
-
* and
|
|
58
|
+
* this package) for the app's world, and the app's schedules, on a loopback
|
|
59
|
+
* port of its own. The dashboard proxies them at `/workflows` and
|
|
60
|
+
* `/api/schedules`; it is the only caller that knows the token. The UI can
|
|
61
|
+
* cancel runs and resume hooks, and a schedule can be run from it, so nothing
|
|
62
|
+
* else may reach it, and it exists only under `brick dev`.
|
|
42
63
|
*
|
|
43
64
|
* @param app - The loaded app, running in this process.
|
|
44
65
|
* @param directory - The inspector's build; this package's own by default.
|
|
45
|
-
* @returns The inspector, or `undefined` when the app runs no workflows.
|
|
66
|
+
* @returns The inspector, or `undefined` when the app runs no workflows and has no schedules.
|
|
46
67
|
* @throws When the inspector's build is missing.
|
|
47
68
|
*/
|
|
48
69
|
async function startInspector(app, directory = INSPECTOR_DIRECTORY) {
|
|
49
70
|
const target = app.events?.workflows;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
const schedules = app.events?.schedules;
|
|
72
|
+
if (!target && !schedules) return void 0;
|
|
73
|
+
const workflows = target && await workflowsPage(target, directory).catch((error) => {
|
|
74
|
+
if (!schedules) throw error;
|
|
75
|
+
console.warn(`[Brick-TS] ${error.message}`);
|
|
76
|
+
});
|
|
77
|
+
const names = new Set(schedules ? app.events.describe().schedules?.map((schedule) => schedule.name) : []);
|
|
56
78
|
const token = randomBytes(16).toString("hex");
|
|
57
79
|
const server = Bun.serve({
|
|
58
80
|
hostname: "127.0.0.1",
|
|
59
81
|
port: 0,
|
|
60
82
|
idleTimeout: 0,
|
|
61
|
-
fetch: (request) =>
|
|
83
|
+
fetch: (request) => {
|
|
84
|
+
if (request.headers.get("x-brick-inspector") !== token) return new Response("Forbidden", { status: 403 });
|
|
85
|
+
const { pathname } = new URL(request.url);
|
|
86
|
+
if (schedules && pathname.startsWith(ROUTES.schedules.path)) return schedulesRoute(schedules, names, request, pathname);
|
|
87
|
+
if (!workflows) return new Response("Not found", { status: 404 });
|
|
88
|
+
return browserAsset(request, workflows.client) ?? workflows.page(request);
|
|
89
|
+
}
|
|
62
90
|
});
|
|
63
91
|
return {
|
|
64
92
|
port: server.port,
|
|
93
|
+
workflows: Boolean(workflows),
|
|
65
94
|
token,
|
|
66
95
|
stop: () => void server.stop(true)
|
|
67
96
|
};
|
|
68
97
|
}
|
|
98
|
+
async function workflowsPage(target, directory) {
|
|
99
|
+
const entry = join(directory, "server", "index.js");
|
|
100
|
+
if (!existsSync(entry)) throw new Error("The workflow inspector is not built. Build it with: bun run --filter @brickkit/cli build");
|
|
101
|
+
const { createFetchHandler } = await import(pathToFileURL(entry).href);
|
|
102
|
+
return {
|
|
103
|
+
page: createFetchHandler(INSPECTOR_PATH, { world: target.world }),
|
|
104
|
+
client: join(directory, "client")
|
|
105
|
+
};
|
|
106
|
+
}
|
|
69
107
|
// src/dev-worker.ts
|
|
70
108
|
let stopping = false;
|
|
71
109
|
const stop = () => {
|
|
@@ -144,6 +182,7 @@ try {
|
|
|
144
182
|
startInspector(app).then((inspector) => inspector && sendToSupervisor({
|
|
145
183
|
type: "brick:inspector",
|
|
146
184
|
port: inspector.port,
|
|
185
|
+
workflows: inspector.workflows,
|
|
147
186
|
token: inspector.token
|
|
148
187
|
}), (error) => console.warn(`[Brick-TS] Could not start the workflow inspector: ${error instanceof Error ? error.message : String(error)}`));
|
|
149
188
|
if (!app.definition.telemetry) console.warn("[Brick-TS] The dashboard shows no requests: pass { telemetry: true } to brick() in your app entry.");
|
package/dist/dev-worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-worker.js","names":[],"sources":["../src/dev-inspector.ts","../src/dev-worker.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { existsSync, statSync } from \"node:fs\";\nimport { join, resolve, sep } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { BrickApp } from \"@brickkit/core\";\nimport type { CreateFetchHandler } from \"../../workflow-inspector/server/handler\";\nimport { INSPECTOR_TOKEN_HEADER, ROUTES } from \"./dashboard-protocol\";\n\nconst INSPECTOR_PATH = ROUTES.workflows.path;\n\nexport interface Inspector {\n readonly port: number;\n /** Every request must carry it in `INSPECTOR_TOKEN_HEADER`. */\n readonly token: string;\n stop(): void;\n}\n\n/** The built inspector, next to `src/` in the repo and next to `dist/` when published. */\nconst INSPECTOR_DIRECTORY = fileURLToPath(\n new URL(\"../inspector-dist/\", import.meta.url),\n);\n\n/** Whether a path is a regular file; any failure to find out (not a directory, name too long) says no. */\nfunction isFile(path: string): boolean {\n try {\n return statSync(path).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * A file of the inspector's browser build. Its names carry a hash of their\n * content, so a browser may keep them for good. Anything else under `assets/`\n * is a plain 404: the page would answer with HTML. `undefined` for requests\n * outside `assets/`, which are the page's to answer.\n */\nfunction browserAsset(request: Request, client: string): Response | undefined {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") return undefined;\n const { pathname } = new URL(request.url);\n if (!pathname.startsWith(`${INSPECTOR_PATH}/assets/`)) return undefined;\n const file = resolve(client, pathname.slice(INSPECTOR_PATH.length + 1));\n if (!file.startsWith(client + sep) || !isFile(file))\n return new Response(\"Not found\", { status: 404 });\n return new Response(Bun.file(file), {\n headers: { \"cache-control\": \"public, max-age=31536000, immutable\" },\n });\n}\n\n/**\n * Serve the Workflow inspector (the Workflow SDK's observability UI, built into\n * this package) for the app's world, on a loopback port of its own. The\n * dashboard proxies it at `/workflows`; it is the only caller that knows the\n * token. The UI can cancel runs and resume hooks, so nothing else may reach it,\n * and it exists only under `brick dev`.\n *\n * @param app - The loaded app, running in this process.\n * @param directory - The inspector's build; this package's own by default.\n * @returns The inspector, or `undefined` when the app runs no workflows.\n * @throws When the inspector's build is missing.\n */\nexport async function startInspector(\n app: BrickApp,\n directory = INSPECTOR_DIRECTORY,\n): Promise<Inspector | undefined> {\n const target = app.events?.workflows;\n if (!target) return undefined;\n const entry = join(directory, \"server\", \"index.js\");\n if (!existsSync(entry))\n throw new Error(\n \"The workflow inspector is not built. Build it with: bun run --filter @brickkit/cli build\",\n );\n const { createFetchHandler } = (await import(pathToFileURL(entry).href)) as {\n createFetchHandler: CreateFetchHandler;\n };\n const page = createFetchHandler(INSPECTOR_PATH, {\n // Core types only the parts of the world it calls; the world is a whole Workflow SDK World.\n world: target.world as Parameters<CreateFetchHandler>[1][\"world\"],\n });\n const client = join(directory, \"client\");\n const token = randomBytes(16).toString(\"hex\");\n const server = Bun.serve({\n hostname: \"127.0.0.1\",\n port: 0,\n // The UI streams a run's output and holds the connection open.\n idleTimeout: 0,\n fetch: (request) =>\n request.headers.get(INSPECTOR_TOKEN_HEADER) === token\n ? (browserAsset(request, client) ?? page(request))\n : new Response(\"Forbidden\", { status: 403 }),\n });\n return { port: server.port!, token, stop: () => void server.stop(true) };\n}\n","import { getGlobalRegistry, stopAllEvents } from \"@brickkit/core\";\nimport { startInspector } from \"./dev-inspector\";\nimport { startDevApplication } from \"./dev-application\";\nimport type { WorkerErrorPhase } from \"./dashboard-protocol\";\nimport { sendToSupervisor, type WorkerOptions } from \"./dev-protocol\";\nimport { installWorkerTelemetry, reportWorkerError } from \"./dev-telemetry\";\n\nlet stopping = false;\n// A reload stops this process. Deliveries cut off would stay claimed, and wait\n// a minute (claimTimeoutMs) before the next process takes them. Stop every\n// started hub: an event emitted while the entry still loads starts one.\nconst stop = () => {\n if (stopping) return;\n stopping = true;\n void Promise.race([stopAllEvents(), Bun.sleep(3000)])\n .catch((error: unknown) =>\n console.error(\n `[Brick-TS] Could not stop the events: ${error instanceof Error ? error.message : String(error)}`,\n ),\n )\n .finally(() => process.exit(0));\n};\nprocess.on(\"SIGTERM\", stop);\nif (process.connected && typeof process.send === \"function\") {\n // The terminal also signals the supervisor, which sends SIGTERM and waits for us.\n process.on(\"SIGINT\", () => {});\n process.on(\"disconnect\", stop);\n} else {\n process.on(\"SIGINT\", stop);\n}\n\nconst options: WorkerOptions = JSON.parse(process.argv[2]!);\nconst { telemetry } = options;\nlet startupComplete = false;\nlet reported = false;\n\nasync function reportOnce(phase: WorkerErrorPhase, error: unknown) {\n if (!telemetry || reported) return;\n reported = true;\n await reportWorkerError(phase, error);\n}\n\nasync function exitAfterFailure(phase: WorkerErrorPhase, error: unknown) {\n await reportOnce(phase, error);\n console.error(error);\n process.exit(1);\n}\n\nif (telemetry) {\n installWorkerTelemetry();\n // Failures before the app is listening are startup failures, not crashes.\n const phaseOf = (): WorkerErrorPhase =>\n startupComplete ? \"uncaught\" : \"startup\";\n process.on(\"uncaughtException\", (error) => {\n void exitAfterFailure(phaseOf(), error);\n });\n process.on(\"unhandledRejection\", (reason) => {\n void exitAfterFailure(\n startupComplete ? \"unhandled-rejection\" : \"startup\",\n reason,\n );\n });\n}\n\n// Scan local imports so dependencies outside the app directory are watched too.\n{\n const files = new Set<string>();\n try {\n await Bun.build({\n entrypoints: [options.entry],\n target: \"bun\",\n packages: \"external\",\n plugins: [\n {\n name: \"brick:dependencies\",\n setup(build) {\n build.onLoad({ filter: /./ }, (args) => {\n files.add(args.path);\n return undefined;\n });\n },\n },\n ],\n });\n } finally {\n // Awaited: a build error ends this process, and the list must arrive first.\n await sendToSupervisor({ type: \"brick:dependencies\", files: [...files] });\n }\n}\n\ntry {\n const app = await startDevApplication(options);\n startupComplete = true;\n if (telemetry) {\n void sendToSupervisor({\n type: \"brick:architecture\",\n architecture: getGlobalRegistry().exportArchitecture(app.definition),\n });\n void sendToSupervisor({\n type: \"brick:documentation\",\n documentation: app.definition.documentation,\n });\n void app.referenceDocuments().then(\n (documents) =>\n sendToSupervisor({ type: \"brick:api-documents\", documents }),\n (error: unknown) =>\n console.warn(\n `[Brick-TS] Could not load the API documents: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n void startInspector(app).then(\n (inspector) =>\n inspector &&\n sendToSupervisor({\n type: \"brick:inspector\",\n port: inspector.port,\n token: inspector.token,\n }),\n (error: unknown) =>\n console.warn(\n `[Brick-TS] Could not start the workflow inspector: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n if (!app.definition.telemetry)\n console.warn(\n \"[Brick-TS] The dashboard shows no requests: pass { telemetry: true } to brick() in your app entry.\",\n );\n }\n} catch (error) {\n await reportOnce(\"startup\", error);\n throw error;\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAM,iBAAiB,OAAO,UAAU;;AAUxC,MAAM,sBAAsB,cAC1B,IAAI,IAAI,sBAAsB,YAAY,GAAG,CAC/C;;AAGA,SAAS,OAAO,MAAuB;CACrC,IAAI;EACF,OAAO,SAAS,IAAI,CAAC,CAAC,OAAO;CAC/B,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;AAQA,SAAS,aAAa,SAAkB,QAAsC;CAC5E,IAAI,QAAQ,WAAW,SAAS,QAAQ,WAAW,QAAQ,OAAO,KAAA;CAClE,MAAM,E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;GACF,CACF;EACF,CAAC;CACH,UAAU;EAER,MAAM,iBAAiB;GAAE,MAAM;GAAsB,OAAO,CAAC,GAAG,KAAK;EAAE,CAAC;CAC1E;AACF;AAEA,IAAI;CACF,MAAM,MAAM,MAAM,oBAAoB,OAAO;CAC7C,kBAAkB;CAClB,IAAI,WAAW;EACb,iBAAsB;GACpB,MAAM;GACN,cAAc,kBAAkB,CAAC,CAAC,mBAAmB,IAAI,UAAU;EACrE,CAAC;EACD,iBAAsB;GACpB,MAAM;GACN,eAAe,IAAI,WAAW;EAChC,CAAC;EACD,IAAS,mBAAmB,CAAC,CAAC,MAC3B,cACC,iBAAiB;GAAE,MAAM;GAAuB;EAAU,CAAC,IAC5D,UACC,QAAQ,KACN,gDAAgD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GACvG,CACJ;EACA,eAAoB,GAAG,CAAC,CAAC,MACtB,cACC,aACA,iBAAiB;GACf,MAAM;GACN,MAAM,UAAU;GAChB,OAAO,UAAU;EACnB,CAAC,IACF,UACC,QAAQ,KACN,sDAAsD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAC7G,CACJ;EACA,IAAI,CAAC,IAAI,WAAW,WAClB,QAAQ,KACN,oGACF;CACJ;AACF,SAAS,OAAO;CACd,MAAM,WAAW,WAAW,KAAK;CACjC,MAAM;AACR"}
|
|
1
|
+
{"version":3,"file":"dev-worker.js","names":[],"sources":["../src/dev-inspector.ts","../src/dev-worker.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { existsSync, statSync } from \"node:fs\";\nimport { join, resolve, sep } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { BrickApp, ScheduleControl } from \"@brickkit/core\";\nimport type { CreateFetchHandler } from \"../../workflow-inspector/server/handler\";\nimport { INSPECTOR_TOKEN_HEADER, ROUTES } from \"./dashboard-protocol\";\n\nconst INSPECTOR_PATH = ROUTES.workflows.path;\n\nexport interface Inspector {\n readonly port: number;\n /** Whether it serves the workflow inspector; it may serve only the schedules. */\n readonly workflows: boolean;\n /** Every request must carry it in `INSPECTOR_TOKEN_HEADER`. */\n readonly token: string;\n stop(): void;\n}\n\n/** The built inspector, next to `src/` in the repo and next to `dist/` when published. */\nconst INSPECTOR_DIRECTORY = fileURLToPath(\n new URL(\"../inspector-dist/\", import.meta.url),\n);\n\n/** Whether a path is a regular file; any failure to find out (not a directory, name too long) says no. */\nfunction isFile(path: string): boolean {\n try {\n return statSync(path).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * A file of the inspector's browser build. Its names carry a hash of their\n * content, so a browser may keep them for good. Anything else under `assets/`\n * is a plain 404: the page would answer with HTML. `undefined` for requests\n * outside `assets/`, which are the page's to answer.\n */\nfunction browserAsset(request: Request, client: string): Response | undefined {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") return undefined;\n const { pathname } = new URL(request.url);\n if (!pathname.startsWith(`${INSPECTOR_PATH}/assets/`)) return undefined;\n const file = resolve(client, pathname.slice(INSPECTOR_PATH.length + 1));\n if (!file.startsWith(client + sep) || !isFile(file))\n return new Response(\"Not found\", { status: 404 });\n return new Response(Bun.file(file), {\n headers: { \"cache-control\": \"public, max-age=31536000, immutable\" },\n });\n}\n\n/**\n * The app's schedules, for the dashboard's Schedules view: `GET` lists them,\n * `POST <path>/<name>` runs one now.\n */\nasync function schedulesRoute(\n schedules: ScheduleControl,\n names: ReadonlySet<string>,\n request: Request,\n pathname: string,\n): Promise<Response> {\n let name: string;\n try {\n name = decodeURIComponent(pathname.slice(ROUTES.schedules.path.length + 1));\n } catch (error) {\n return new Response((error as Error).message, { status: 400 });\n }\n if (request.method === \"GET\" && !name)\n return Response.json(await schedules.list());\n if (request.method !== \"POST\" || !name)\n return new Response(\"Not found\", { status: 404 });\n if (!names.has(name))\n return new Response(`No schedule named '${name}'`, { status: 404 });\n try {\n return Response.json({ started: await schedules.trigger(name) });\n } catch (error) {\n return new Response((error as Error).message, { status: 500 });\n }\n}\n\n/**\n * Serve the Workflow inspector (the Workflow SDK's observability UI, built into\n * this package) for the app's world, and the app's schedules, on a loopback\n * port of its own. The dashboard proxies them at `/workflows` and\n * `/api/schedules`; it is the only caller that knows the token. The UI can\n * cancel runs and resume hooks, and a schedule can be run from it, so nothing\n * else may reach it, and it exists only under `brick dev`.\n *\n * @param app - The loaded app, running in this process.\n * @param directory - The inspector's build; this package's own by default.\n * @returns The inspector, or `undefined` when the app runs no workflows and has no schedules.\n * @throws When the inspector's build is missing.\n */\nexport async function startInspector(\n app: BrickApp,\n directory = INSPECTOR_DIRECTORY,\n): Promise<Inspector | undefined> {\n const target = app.events?.workflows;\n const schedules = app.events?.schedules;\n if (!target && !schedules) return undefined;\n // An unbuilt inspector costs the Workflows view, not the schedules.\n const workflows =\n target &&\n (await workflowsPage(target, directory).catch((error: unknown) => {\n if (!schedules) throw error;\n console.warn(`[Brick-TS] ${(error as Error).message}`);\n return undefined;\n }));\n const names = new Set(\n schedules\n ? app.events!.describe().schedules?.map((schedule) => schedule.name)\n : [],\n );\n const token = randomBytes(16).toString(\"hex\");\n const server = Bun.serve({\n hostname: \"127.0.0.1\",\n port: 0,\n // The UI streams a run's output and holds the connection open.\n idleTimeout: 0,\n fetch: (request) => {\n if (request.headers.get(INSPECTOR_TOKEN_HEADER) !== token)\n return new Response(\"Forbidden\", { status: 403 });\n const { pathname } = new URL(request.url);\n if (schedules && pathname.startsWith(ROUTES.schedules.path))\n return schedulesRoute(schedules, names, request, pathname);\n if (!workflows) return new Response(\"Not found\", { status: 404 });\n return browserAsset(request, workflows.client) ?? workflows.page(request);\n },\n });\n return {\n port: server.port!,\n workflows: Boolean(workflows),\n token,\n stop: () => void server.stop(true),\n };\n}\n\nasync function workflowsPage(\n target: NonNullable<NonNullable<BrickApp[\"events\"]>[\"workflows\"]>,\n directory: string,\n) {\n const entry = join(directory, \"server\", \"index.js\");\n if (!existsSync(entry))\n throw new Error(\n \"The workflow inspector is not built. Build it with: bun run --filter @brickkit/cli build\",\n );\n const { createFetchHandler } = (await import(pathToFileURL(entry).href)) as {\n createFetchHandler: CreateFetchHandler;\n };\n const page = createFetchHandler(INSPECTOR_PATH, {\n // Core types only the parts of the world it calls; the world is a whole Workflow SDK World.\n world: target.world as Parameters<CreateFetchHandler>[1][\"world\"],\n });\n return { page, client: join(directory, \"client\") };\n}\n","import { getGlobalRegistry, stopAllEvents } from \"@brickkit/core\";\nimport { startInspector } from \"./dev-inspector\";\nimport { startDevApplication } from \"./dev-application\";\nimport type { WorkerErrorPhase } from \"./dashboard-protocol\";\nimport { sendToSupervisor, type WorkerOptions } from \"./dev-protocol\";\nimport { installWorkerTelemetry, reportWorkerError } from \"./dev-telemetry\";\n\nlet stopping = false;\n// A reload stops this process. Deliveries cut off would stay claimed, and wait\n// a minute (claimTimeoutMs) before the next process takes them. Stop every\n// started hub: an event emitted while the entry still loads starts one.\nconst stop = () => {\n if (stopping) return;\n stopping = true;\n void Promise.race([stopAllEvents(), Bun.sleep(3000)])\n .catch((error: unknown) =>\n console.error(\n `[Brick-TS] Could not stop the events: ${error instanceof Error ? error.message : String(error)}`,\n ),\n )\n .finally(() => process.exit(0));\n};\nprocess.on(\"SIGTERM\", stop);\nif (process.connected && typeof process.send === \"function\") {\n // The terminal also signals the supervisor, which sends SIGTERM and waits for us.\n process.on(\"SIGINT\", () => {});\n process.on(\"disconnect\", stop);\n} else {\n process.on(\"SIGINT\", stop);\n}\n\nconst options: WorkerOptions = JSON.parse(process.argv[2]!);\nconst { telemetry } = options;\nlet startupComplete = false;\nlet reported = false;\n\nasync function reportOnce(phase: WorkerErrorPhase, error: unknown) {\n if (!telemetry || reported) return;\n reported = true;\n await reportWorkerError(phase, error);\n}\n\nasync function exitAfterFailure(phase: WorkerErrorPhase, error: unknown) {\n await reportOnce(phase, error);\n console.error(error);\n process.exit(1);\n}\n\nif (telemetry) {\n installWorkerTelemetry();\n // Failures before the app is listening are startup failures, not crashes.\n const phaseOf = (): WorkerErrorPhase =>\n startupComplete ? \"uncaught\" : \"startup\";\n process.on(\"uncaughtException\", (error) => {\n void exitAfterFailure(phaseOf(), error);\n });\n process.on(\"unhandledRejection\", (reason) => {\n void exitAfterFailure(\n startupComplete ? \"unhandled-rejection\" : \"startup\",\n reason,\n );\n });\n}\n\n// Scan local imports so dependencies outside the app directory are watched too.\n{\n const files = new Set<string>();\n try {\n await Bun.build({\n entrypoints: [options.entry],\n target: \"bun\",\n packages: \"external\",\n plugins: [\n {\n name: \"brick:dependencies\",\n setup(build) {\n build.onLoad({ filter: /./ }, (args) => {\n files.add(args.path);\n return undefined;\n });\n },\n },\n ],\n });\n } finally {\n // Awaited: a build error ends this process, and the list must arrive first.\n await sendToSupervisor({ type: \"brick:dependencies\", files: [...files] });\n }\n}\n\ntry {\n const app = await startDevApplication(options);\n startupComplete = true;\n if (telemetry) {\n void sendToSupervisor({\n type: \"brick:architecture\",\n architecture: getGlobalRegistry().exportArchitecture(app.definition),\n });\n void sendToSupervisor({\n type: \"brick:documentation\",\n documentation: app.definition.documentation,\n });\n void app.referenceDocuments().then(\n (documents) =>\n sendToSupervisor({ type: \"brick:api-documents\", documents }),\n (error: unknown) =>\n console.warn(\n `[Brick-TS] Could not load the API documents: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n void startInspector(app).then(\n (inspector) =>\n inspector &&\n sendToSupervisor({\n type: \"brick:inspector\",\n port: inspector.port,\n workflows: inspector.workflows,\n token: inspector.token,\n }),\n (error: unknown) =>\n console.warn(\n `[Brick-TS] Could not start the workflow inspector: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n if (!app.definition.telemetry)\n console.warn(\n \"[Brick-TS] The dashboard shows no requests: pass { telemetry: true } to brick() in your app entry.\",\n );\n }\n} catch (error) {\n await reportOnce(\"startup\", error);\n throw error;\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAM,iBAAiB,OAAO,UAAU;;AAYxC,MAAM,sBAAsB,cAC1B,IAAI,IAAI,sBAAsB,YAAY,GAAG,CAC/C;;AAGA,SAAS,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
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* What `brick worker` runs: load the app
|
|
37
|
-
* process, without serving HTTP. Run it beside API processes that only record
|
|
36
|
+
* What `brick worker` runs: load the app, deliver its events and run its
|
|
37
|
+
* schedules from this process, without serving HTTP. Run it beside API processes that only record
|
|
38
38
|
* events (`events: { dispatch: false }`), or alone for an app with no routes.
|
|
39
39
|
* Workflow listeners run here too: the world starts and the steps of every run
|
|
40
40
|
* in it execute in this process.
|
package/dist/project.js
CHANGED
|
@@ -87,6 +87,7 @@ const DEFINE_FUNCTIONS = {
|
|
|
87
87
|
defineAction: "action",
|
|
88
88
|
defineTool: "tool",
|
|
89
89
|
defineListener: "listener",
|
|
90
|
+
defineSchedule: "schedule",
|
|
90
91
|
definePlugin: "plugin",
|
|
91
92
|
defineResource: "resource",
|
|
92
93
|
crud: "crud",
|
|
@@ -212,7 +213,7 @@ function memberCall(node) {
|
|
|
212
213
|
};
|
|
213
214
|
}
|
|
214
215
|
// package.json
|
|
215
|
-
var version = "0.
|
|
216
|
+
var version = "0.15.0";
|
|
216
217
|
// src/lint/rules/checks.ts
|
|
217
218
|
const MANIFEST_STEM = MANIFEST_FILE.replace(/\.ts$/, "");
|
|
218
219
|
/** This release's range, for the `brick` field example: `^0.12.0`. */
|
|
@@ -765,6 +766,7 @@ const SERVICE_FOLDERS = {
|
|
|
765
766
|
tool: "tools",
|
|
766
767
|
socket: "sockets",
|
|
767
768
|
listener: "listeners",
|
|
769
|
+
schedule: "schedules",
|
|
768
770
|
workflow: "workflows",
|
|
769
771
|
step: "workflows",
|
|
770
772
|
table: "tables"
|
|
@@ -794,7 +796,7 @@ const rules = {
|
|
|
794
796
|
});
|
|
795
797
|
});
|
|
796
798
|
}),
|
|
797
|
-
"file-suffixes": rule("Each kind of definition goes in a file with its suffix: .service, .action, .command, .tool, .socket, .listener, .workflow, .step, .resource, .table, .events.", (context) => {
|
|
799
|
+
"file-suffixes": rule("Each kind of definition goes in a file with its suffix: .service, .action, .command, .tool, .socket, .listener, .schedule, .workflow, .step, .resource, .table, .events.", (context) => {
|
|
798
800
|
const info = fileInfo(context);
|
|
799
801
|
if (info.exempt) return {};
|
|
800
802
|
return onDefinitions((definitions) => {
|