@senpi/runtime 1.0.95-dev.runtime-phase-2-api.20260505163136 → 1.0.95-dev.runtime-phase-2.20260506193916
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/README.md +0 -13
- package/dist/dsl/events/handlers.d.ts +2 -1
- package/dist/dsl/events/handlers.d.ts.map +1 -1
- package/dist/dsl/events/handlers.js +3 -0
- package/dist/dsl/events/handlers.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +1 -1
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -161
- package/dist/index.js.map +1 -1
- package/dist/runtime/auto-update/coordinator.d.ts +8 -12
- package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +17 -18
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/auto-update/gateway-restart.d.ts +2 -9
- package/dist/runtime/auto-update/gateway-restart.d.ts.map +1 -1
- package/dist/runtime/auto-update/gateway-restart.js +13 -23
- package/dist/runtime/auto-update/gateway-restart.js.map +1 -1
- package/dist/runtime/create-actions.d.ts.map +1 -1
- package/dist/runtime/create-actions.js +2 -13
- package/dist/runtime/create-actions.js.map +1 -1
- package/dist/runtime/run.d.ts +1 -47
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +0 -9
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime.d.ts +3 -58
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +7 -172
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/senpi/client.d.ts +2 -92
- package/dist/senpi/client.d.ts.map +1 -1
- package/dist/senpi/client.js +8 -181
- package/dist/senpi/client.js.map +1 -1
- package/dist/tracking/constants.d.ts.map +1 -1
- package/dist/tracking/constants.js +4 -0
- package/dist/tracking/constants.js.map +1 -1
- package/dist/tracking/index.d.ts +1 -0
- package/dist/tracking/index.d.ts.map +1 -1
- package/dist/tracking/index.js +1 -0
- package/dist/tracking/index.js.map +1 -1
- package/dist/tracking/plugin-event-tracker.d.ts +13 -0
- package/dist/tracking/plugin-event-tracker.d.ts.map +1 -0
- package/dist/tracking/plugin-event-tracker.js +27 -0
- package/dist/tracking/plugin-event-tracker.js.map +1 -0
- package/openclaw.plugin.json +0 -24
- package/package.json +2 -6
- package/dist/runtime/audit-query.types.d.ts +0 -113
- package/dist/runtime/audit-query.types.d.ts.map +0 -1
- package/dist/runtime/audit-query.types.js +0 -35
- package/dist/runtime/audit-query.types.js.map +0 -1
- package/dist/runtime-api/config.d.ts +0 -47
- package/dist/runtime-api/config.d.ts.map +0 -1
- package/dist/runtime-api/config.js +0 -74
- package/dist/runtime-api/config.js.map +0 -1
- package/dist/runtime-api/handlers/audit.d.ts +0 -76
- package/dist/runtime-api/handlers/audit.d.ts.map +0 -1
- package/dist/runtime-api/handlers/audit.js +0 -63
- package/dist/runtime-api/handlers/audit.js.map +0 -1
- package/dist/runtime-api/handlers/group-by-scanner.d.ts +0 -43
- package/dist/runtime-api/handlers/group-by-scanner.d.ts.map +0 -1
- package/dist/runtime-api/handlers/group-by-scanner.js +0 -43
- package/dist/runtime-api/handlers/group-by-scanner.js.map +0 -1
- package/dist/runtime-api/handlers/ingest-signals.d.ts +0 -54
- package/dist/runtime-api/handlers/ingest-signals.d.ts.map +0 -1
- package/dist/runtime-api/handlers/ingest-signals.js +0 -134
- package/dist/runtime-api/handlers/ingest-signals.js.map +0 -1
- package/dist/runtime-api/handlers/lookup.d.ts +0 -36
- package/dist/runtime-api/handlers/lookup.d.ts.map +0 -1
- package/dist/runtime-api/handlers/lookup.js +0 -31
- package/dist/runtime-api/handlers/lookup.js.map +0 -1
- package/dist/runtime-api/handlers/types.d.ts +0 -80
- package/dist/runtime-api/handlers/types.d.ts.map +0 -1
- package/dist/runtime-api/handlers/types.js +0 -8
- package/dist/runtime-api/handlers/types.js.map +0 -1
- package/dist/runtime-api/lifecycle.d.ts +0 -98
- package/dist/runtime-api/lifecycle.d.ts.map +0 -1
- package/dist/runtime-api/lifecycle.js +0 -137
- package/dist/runtime-api/lifecycle.js.map +0 -1
- package/dist/runtime-api/readiness.d.ts +0 -37
- package/dist/runtime-api/readiness.d.ts.map +0 -1
- package/dist/runtime-api/readiness.js +0 -35
- package/dist/runtime-api/readiness.js.map +0 -1
- package/dist/runtime-api/routes/audit.d.ts +0 -40
- package/dist/runtime-api/routes/audit.d.ts.map +0 -1
- package/dist/runtime-api/routes/audit.js +0 -82
- package/dist/runtime-api/routes/audit.js.map +0 -1
- package/dist/runtime-api/routes/audit.schema.d.ts +0 -75
- package/dist/runtime-api/routes/audit.schema.d.ts.map +0 -1
- package/dist/runtime-api/routes/audit.schema.js +0 -78
- package/dist/runtime-api/routes/audit.schema.js.map +0 -1
- package/dist/runtime-api/routes/health.d.ts +0 -53
- package/dist/runtime-api/routes/health.d.ts.map +0 -1
- package/dist/runtime-api/routes/health.js +0 -48
- package/dist/runtime-api/routes/health.js.map +0 -1
- package/dist/runtime-api/routes/signals.d.ts +0 -50
- package/dist/runtime-api/routes/signals.d.ts.map +0 -1
- package/dist/runtime-api/routes/signals.js +0 -65
- package/dist/runtime-api/routes/signals.js.map +0 -1
- package/dist/runtime-api/routes/signals.schema.d.ts +0 -94
- package/dist/runtime-api/routes/signals.schema.d.ts.map +0 -1
- package/dist/runtime-api/routes/signals.schema.js +0 -58
- package/dist/runtime-api/routes/signals.schema.js.map +0 -1
- package/dist/runtime-api/server.d.ts +0 -79
- package/dist/runtime-api/server.d.ts.map +0 -1
- package/dist/runtime-api/server.js +0 -105
- package/dist/runtime-api/server.js.map +0 -1
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeBox schema for the `POST /signals` request body.
|
|
3
|
-
*
|
|
4
|
-
* `SignalItemT` is derived from TypeBox `Static<>` and is structurally
|
|
5
|
-
* compatible with the hand-written {@link SignalItem} interface in
|
|
6
|
-
* `handlers/types.ts`. The interface in `handlers/types.ts` is kept as the
|
|
7
|
-
* canonical description (referenced by JSDoc across the codebase); this module
|
|
8
|
-
* derives the runtime-validatable form from TypeBox so both shapes stay in
|
|
9
|
-
* sync at compile-time.
|
|
10
|
-
*
|
|
11
|
-
* Note on `direction`: the TypeBox schema accepts any string so
|
|
12
|
-
* `SignalItemT["direction"]` is `string | undefined`, matching
|
|
13
|
-
* `Signal["direction"]` in `scanners/types.ts`. The tighter
|
|
14
|
-
* `"long" | "short" | null` constraint lives in the MCP layer; the runtime
|
|
15
|
-
* applies it implicitly during scanner-engine ingest.
|
|
16
|
-
*
|
|
17
|
-
* Note on `maxItems`: enforced at handler level using the configured
|
|
18
|
-
* `api.maxItemsPerSignalsRequest` value (default 10). Schema-level cap is
|
|
19
|
-
* kept open-ended so the shape works in tests without recompiling.
|
|
20
|
-
*/
|
|
21
|
-
import { Type } from "@sinclair/typebox";
|
|
22
|
-
/** TypeBox schema for one item in the `POST /signals` body. */
|
|
23
|
-
export const SignalItem = Type.Object({
|
|
24
|
-
/** Wallet address of the target runtime. Lowercased server-side. */
|
|
25
|
-
address: Type.String({ minLength: 1 }),
|
|
26
|
-
/** Configured scanner id. */
|
|
27
|
-
scanner: Type.String({ minLength: 1 }),
|
|
28
|
-
/** Asset for a single ingested signal. */
|
|
29
|
-
asset: Type.Optional(Type.String()),
|
|
30
|
-
/**
|
|
31
|
-
* Direction for a single ingested signal.
|
|
32
|
-
* Accepts any string — `"long"` / `"short"` are the conventional values.
|
|
33
|
-
*/
|
|
34
|
-
direction: Type.Optional(Type.String()),
|
|
35
|
-
/** Confidence score for a single ingested signal (0–1). */
|
|
36
|
-
score: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
37
|
-
/** Signal classification override for a single ingested signal. */
|
|
38
|
-
signal_type: Type.Optional(Type.String()),
|
|
39
|
-
/**
|
|
40
|
-
* Single ingest payload for signal-producing or context-producing scanners.
|
|
41
|
-
* Mutually exclusive with `signals[]`.
|
|
42
|
-
*/
|
|
43
|
-
data: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
|
|
44
|
-
/**
|
|
45
|
-
* Batch signal payloads for signal-producing external scanners.
|
|
46
|
-
* Mutually exclusive with `data`.
|
|
47
|
-
*/
|
|
48
|
-
signals: Type.Optional(Type.Array(Type.Object({
|
|
49
|
-
asset: Type.String(),
|
|
50
|
-
direction: Type.Optional(Type.String()),
|
|
51
|
-
score: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
52
|
-
signal_type: Type.Optional(Type.String()),
|
|
53
|
-
data: Type.Record(Type.String(), Type.Unknown()),
|
|
54
|
-
}))),
|
|
55
|
-
}, { additionalProperties: false });
|
|
56
|
-
/** TypeBox schema for the full `POST /signals` request body array. */
|
|
57
|
-
export const SignalsBody = Type.Array(SignalItem, { minItems: 1 });
|
|
58
|
-
//# sourceMappingURL=signals.schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signals.schema.js","sourceRoot":"","sources":["../../../src/runtime-api/routes/signals.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AAEtD,+DAA+D;AAC/D,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CACnC;IACE,oEAAoE;IACpE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACtC,6BAA6B;IAC7B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACtC,0CAA0C;IAC1C,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACnC;;;OAGG;IACH,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CA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4
|
-
* Wires the Fastify instance with:
|
|
5
|
-
* - `POST /signals` — ingest signals for one or more wallets.
|
|
6
|
-
* - `GET /audit` — MCP audit-query proxy scoped to one wallet.
|
|
7
|
-
* - `GET /health` — three-state readiness + per-runtime queue depth.
|
|
8
|
-
*
|
|
9
|
-
* Returns the Fastify instance, the mutable readiness flag, and the boot
|
|
10
|
-
* timestamp. The lifecycle layer (S5) calls `fastify.listen()` and flips
|
|
11
|
-
* `readiness.setOk()` / `readiness.setDraining()` around start/stop.
|
|
12
|
-
*
|
|
13
|
-
* This module owns only wiring — no business logic. All route logic
|
|
14
|
-
* delegates to the shared handlers in `handlers/`.
|
|
15
|
-
*/
|
|
16
|
-
import { type FastifyInstance } from "fastify";
|
|
17
|
-
import { createReadiness } from "./readiness.js";
|
|
18
|
-
import type { RuntimeHandle } from "../runtime/run.js";
|
|
19
|
-
import type { Logger } from "../utils/logger.js";
|
|
20
|
-
import type { ApiConfig } from "./config.js";
|
|
21
|
-
/**
|
|
22
|
-
* Dependencies passed to {@link createApi}.
|
|
23
|
-
*/
|
|
24
|
-
export interface CreateApiDeps {
|
|
25
|
-
/** Live runtime handles maintained by the plugin, keyed by lowercased address. */
|
|
26
|
-
runtimeHandles: Map<string, RuntimeHandle>;
|
|
27
|
-
/** Validated `api` config block (host, port, maxItemsPerSignalsRequest). */
|
|
28
|
-
apiConfig: ApiConfig;
|
|
29
|
-
/** Logger instance — forwarded to shared handlers for structured error logging. */
|
|
30
|
-
logger: Logger;
|
|
31
|
-
/**
|
|
32
|
-
* Plugin version string read from `openclaw.plugin.json` at boot.
|
|
33
|
-
* Exposed in `GET /health` so callers can correlate requests with deployments.
|
|
34
|
-
*/
|
|
35
|
-
version: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Artifacts returned by {@link createApi}.
|
|
39
|
-
*
|
|
40
|
-
* Ownership:
|
|
41
|
-
* - `fastify` — call `.listen()` and `.close()` in the lifecycle layer (S5).
|
|
42
|
-
* - `readiness` — call `setOk()` after `.listen()` resolves; `setDraining()`
|
|
43
|
-
* before `.close()` during graceful shutdown.
|
|
44
|
-
* - `bootedAt` — Unix epoch ms recorded when `createApi()` was called;
|
|
45
|
-
* used by `GET /health` to compute `uptime_ms`.
|
|
46
|
-
*/
|
|
47
|
-
export interface ApiArtifacts {
|
|
48
|
-
fastify: FastifyInstance;
|
|
49
|
-
readiness: ReturnType<typeof createReadiness>;
|
|
50
|
-
bootedAt: number;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Create and configure the Fastify HTTP server.
|
|
54
|
-
*
|
|
55
|
-
* Does NOT start listening. Call `artifacts.fastify.listen(...)` from the
|
|
56
|
-
* lifecycle layer (S5) after `createApi()` returns.
|
|
57
|
-
*
|
|
58
|
-
* Error handler behaviour:
|
|
59
|
-
* - `400` (schema validation), `413` (body too large), `415` (wrong
|
|
60
|
-
* content-type) are passed through as `INVALID_REQUEST` with the original
|
|
61
|
-
* Fastify message so callers can read the validation detail.
|
|
62
|
-
* - All other errors are logged and returned as `500 / UNAVAILABLE`.
|
|
63
|
-
*
|
|
64
|
-
* Request timeout strategy (resolved in S5):
|
|
65
|
-
* A single server-wide `requestTimeout: 30_000` covers all routes.
|
|
66
|
-
* The plan called for per-route values (10s for `/signals` + `/health`,
|
|
67
|
-
* 30s for `/audit`), but Fastify v5 does not expose a declarative per-route
|
|
68
|
-
* `requestTimeout` and wiring an `onRequest` hook with manual `setTimeout`
|
|
69
|
-
* calls adds meaningful complexity for a localhost-only server where requests
|
|
70
|
-
* that genuinely hang are almost always MCP-side. The 30s ceiling is driven
|
|
71
|
-
* entirely by `/audit` (MCP round-trip); `/signals` and `/health` both
|
|
72
|
-
* complete in well under 1s in practice. If per-route enforcement becomes
|
|
73
|
-
* necessary, add an `onRequest` hook in this file.
|
|
74
|
-
*
|
|
75
|
-
* @param deps Dependencies injected by the plugin entry point.
|
|
76
|
-
* @returns `{ fastify, readiness, bootedAt }`.
|
|
77
|
-
*/
|
|
78
|
-
export declare function createApi(deps: CreateApiDeps): ApiArtifacts;
|
|
79
|
-
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/runtime-api/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAIxD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kFAAkF;IAClF,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,4EAA4E;IAC5E,SAAS,EAAE,SAAS,CAAC;IACrB,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,eAAe,CAAC;IACzB,SAAS,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;IAC9C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,YAAY,CAiE3D"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `createApi()` — Fastify server factory for the runtime HTTP API.
|
|
3
|
-
*
|
|
4
|
-
* Wires the Fastify instance with:
|
|
5
|
-
* - `POST /signals` — ingest signals for one or more wallets.
|
|
6
|
-
* - `GET /audit` — MCP audit-query proxy scoped to one wallet.
|
|
7
|
-
* - `GET /health` — three-state readiness + per-runtime queue depth.
|
|
8
|
-
*
|
|
9
|
-
* Returns the Fastify instance, the mutable readiness flag, and the boot
|
|
10
|
-
* timestamp. The lifecycle layer (S5) calls `fastify.listen()` and flips
|
|
11
|
-
* `readiness.setOk()` / `readiness.setDraining()` around start/stop.
|
|
12
|
-
*
|
|
13
|
-
* This module owns only wiring — no business logic. All route logic
|
|
14
|
-
* delegates to the shared handlers in `handlers/`.
|
|
15
|
-
*/
|
|
16
|
-
import Fastify from "fastify";
|
|
17
|
-
import { registerSignalsRoute } from "./routes/signals.js";
|
|
18
|
-
import { registerAuditRoute } from "./routes/audit.js";
|
|
19
|
-
import { registerHealthRoute } from "./routes/health.js";
|
|
20
|
-
import { createReadiness } from "./readiness.js";
|
|
21
|
-
/**
|
|
22
|
-
* Create and configure the Fastify HTTP server.
|
|
23
|
-
*
|
|
24
|
-
* Does NOT start listening. Call `artifacts.fastify.listen(...)` from the
|
|
25
|
-
* lifecycle layer (S5) after `createApi()` returns.
|
|
26
|
-
*
|
|
27
|
-
* Error handler behaviour:
|
|
28
|
-
* - `400` (schema validation), `413` (body too large), `415` (wrong
|
|
29
|
-
* content-type) are passed through as `INVALID_REQUEST` with the original
|
|
30
|
-
* Fastify message so callers can read the validation detail.
|
|
31
|
-
* - All other errors are logged and returned as `500 / UNAVAILABLE`.
|
|
32
|
-
*
|
|
33
|
-
* Request timeout strategy (resolved in S5):
|
|
34
|
-
* A single server-wide `requestTimeout: 30_000` covers all routes.
|
|
35
|
-
* The plan called for per-route values (10s for `/signals` + `/health`,
|
|
36
|
-
* 30s for `/audit`), but Fastify v5 does not expose a declarative per-route
|
|
37
|
-
* `requestTimeout` and wiring an `onRequest` hook with manual `setTimeout`
|
|
38
|
-
* calls adds meaningful complexity for a localhost-only server where requests
|
|
39
|
-
* that genuinely hang are almost always MCP-side. The 30s ceiling is driven
|
|
40
|
-
* entirely by `/audit` (MCP round-trip); `/signals` and `/health` both
|
|
41
|
-
* complete in well under 1s in practice. If per-route enforcement becomes
|
|
42
|
-
* necessary, add an `onRequest` hook in this file.
|
|
43
|
-
*
|
|
44
|
-
* @param deps Dependencies injected by the plugin entry point.
|
|
45
|
-
* @returns `{ fastify, readiness, bootedAt }`.
|
|
46
|
-
*/
|
|
47
|
-
export function createApi(deps) {
|
|
48
|
-
const bootedAt = Date.now();
|
|
49
|
-
const readiness = createReadiness();
|
|
50
|
-
const fastify = Fastify({
|
|
51
|
-
logger: { level: "info" },
|
|
52
|
-
bodyLimit: 256 * 1024, // 256 KB — generous for signal batches, hard cap on abuse.
|
|
53
|
-
disableRequestLogging: false,
|
|
54
|
-
/**
|
|
55
|
-
* 30s request ceiling — driven by `/audit` (MCP round-trip).
|
|
56
|
-
* `/signals` and `/health` complete far faster; we accept the unified
|
|
57
|
-
* ceiling to avoid per-route hook complexity on a localhost-only server.
|
|
58
|
-
* Documented in docs/runtime-docs/runtime-api.md.
|
|
59
|
-
*/
|
|
60
|
-
requestTimeout: 30_000,
|
|
61
|
-
});
|
|
62
|
-
// Custom error handler — normalises Fastify validation / payload errors into
|
|
63
|
-
// the same `{ success, code, message }` envelope used by all three routes.
|
|
64
|
-
fastify.setErrorHandler((error, _req, reply) => {
|
|
65
|
-
// Fastify v5 types setErrorHandler with `unknown`; cast once for the handler.
|
|
66
|
-
const err = error;
|
|
67
|
-
const statusCode = err.statusCode;
|
|
68
|
-
if (statusCode === 400 ||
|
|
69
|
-
statusCode === 413 ||
|
|
70
|
-
statusCode === 415) {
|
|
71
|
-
return reply.status(statusCode).send({
|
|
72
|
-
success: false,
|
|
73
|
-
code: "INVALID_REQUEST",
|
|
74
|
-
message: err.message,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
deps.logger.error("[senpi-core][runtime-api] Unhandled error", {
|
|
78
|
-
err,
|
|
79
|
-
});
|
|
80
|
-
return reply.status(500).send({
|
|
81
|
-
success: false,
|
|
82
|
-
code: "UNAVAILABLE",
|
|
83
|
-
message: err.message,
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
registerSignalsRoute(fastify, {
|
|
87
|
-
runtimeHandles: deps.runtimeHandles,
|
|
88
|
-
logger: deps.logger,
|
|
89
|
-
maxItems: deps.apiConfig.maxItemsPerSignalsRequest,
|
|
90
|
-
transport: "http",
|
|
91
|
-
});
|
|
92
|
-
registerAuditRoute(fastify, {
|
|
93
|
-
runtimeHandles: deps.runtimeHandles,
|
|
94
|
-
logger: deps.logger,
|
|
95
|
-
});
|
|
96
|
-
registerHealthRoute(fastify, {
|
|
97
|
-
runtimeHandles: deps.runtimeHandles,
|
|
98
|
-
apiConfig: { host: deps.apiConfig.host, port: deps.apiConfig.port },
|
|
99
|
-
readiness,
|
|
100
|
-
version: deps.version,
|
|
101
|
-
bootedAt,
|
|
102
|
-
});
|
|
103
|
-
return { fastify, readiness, bootedAt };
|
|
104
|
-
}
|
|
105
|
-
//# sourceMappingURL=server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/runtime-api/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,OAAiC,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAsCjD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,SAAS,CAAC,IAAmB;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5B,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;IAEpC,MAAM,OAAO,GAAG,OAAO,CAAC;QACtB,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;QACzB,SAAS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