@data-club/ai-hub-server 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/argon2.d.ts +72 -0
- package/dist/auth/argon2.d.ts.map +1 -0
- package/dist/auth/argon2.js +145 -0
- package/dist/auth/argon2.js.map +1 -0
- package/dist/auth/encryption.d.ts +52 -0
- package/dist/auth/encryption.d.ts.map +1 -0
- package/dist/auth/encryption.js +98 -0
- package/dist/auth/encryption.js.map +1 -0
- package/dist/auth/jwt.d.ts +133 -0
- package/dist/auth/jwt.d.ts.map +1 -0
- package/dist/auth/jwt.js +147 -0
- package/dist/auth/jwt.js.map +1 -0
- package/dist/auth/middleware.d.ts +101 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +161 -0
- package/dist/auth/middleware.js.map +1 -0
- package/dist/auth/passwordPolicy.d.ts +72 -0
- package/dist/auth/passwordPolicy.d.ts.map +1 -0
- package/dist/auth/passwordPolicy.js +88 -0
- package/dist/auth/passwordPolicy.js.map +1 -0
- package/dist/auth/roleRules.d.ts +200 -0
- package/dist/auth/roleRules.d.ts.map +1 -0
- package/dist/auth/roleRules.js +365 -0
- package/dist/auth/roleRules.js.map +1 -0
- package/dist/auth/userView.d.ts +55 -0
- package/dist/auth/userView.d.ts.map +1 -0
- package/dist/auth/userView.js +77 -0
- package/dist/auth/userView.js.map +1 -0
- package/dist/bootstrap.d.ts +104 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +160 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/db/connection.d.ts +39 -0
- package/dist/db/connection.d.ts.map +1 -0
- package/dist/db/connection.js +62 -0
- package/dist/db/connection.js.map +1 -0
- package/dist/db/migrate.d.ts +31 -0
- package/dist/db/migrate.d.ts.map +1 -0
- package/dist/db/migrate.js +197 -0
- package/dist/db/migrate.js.map +1 -0
- package/dist/db/schema.d.ts +1902 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +662 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/seed.d.ts +92 -0
- package/dist/db/seed.d.ts.map +1 -0
- package/dist/db/seed.js +160 -0
- package/dist/db/seed.js.map +1 -0
- package/dist/handlers/fetch.d.ts +89 -0
- package/dist/handlers/fetch.d.ts.map +1 -0
- package/dist/handlers/fetch.js +173 -0
- package/dist/handlers/fetch.js.map +1 -0
- package/dist/handlers/nextjs.d.ts +40 -0
- package/dist/handlers/nextjs.d.ts.map +1 -0
- package/dist/handlers/nextjs.js +42 -0
- package/dist/handlers/nextjs.js.map +1 -0
- package/dist/handlers/responses.d.ts +46 -0
- package/dist/handlers/responses.d.ts.map +1 -0
- package/dist/handlers/responses.js +74 -0
- package/dist/handlers/responses.js.map +1 -0
- package/dist/handlers/routeTable.d.ts +21 -0
- package/dist/handlers/routeTable.d.ts.map +1 -0
- package/dist/handlers/routeTable.js +133 -0
- package/dist/handlers/routeTable.js.map +1 -0
- package/dist/handlers/router.d.ts +37 -0
- package/dist/handlers/router.d.ts.map +1 -0
- package/dist/handlers/router.js +82 -0
- package/dist/handlers/router.js.map +1 -0
- package/dist/handlers/sse.d.ts +38 -0
- package/dist/handlers/sse.d.ts.map +1 -0
- package/dist/handlers/sse.js +52 -0
- package/dist/handlers/sse.js.map +1 -0
- package/dist/handlers/types.d.ts +96 -0
- package/dist/handlers/types.d.ts.map +1 -0
- package/dist/handlers/types.js +14 -0
- package/dist/handlers/types.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/letta/client.d.ts +355 -0
- package/dist/letta/client.d.ts.map +1 -0
- package/dist/letta/client.js +529 -0
- package/dist/letta/client.js.map +1 -0
- package/dist/letta/eventTranslator.d.ts +166 -0
- package/dist/letta/eventTranslator.d.ts.map +1 -0
- package/dist/letta/eventTranslator.js +532 -0
- package/dist/letta/eventTranslator.js.map +1 -0
- package/dist/letta/index.d.ts +13 -0
- package/dist/letta/index.d.ts.map +1 -0
- package/dist/letta/index.js +12 -0
- package/dist/letta/index.js.map +1 -0
- package/dist/letta/modelSettings.d.ts +176 -0
- package/dist/letta/modelSettings.d.ts.map +1 -0
- package/dist/letta/modelSettings.js +314 -0
- package/dist/letta/modelSettings.js.map +1 -0
- package/dist/letta/promptWrapping.d.ts +141 -0
- package/dist/letta/promptWrapping.d.ts.map +1 -0
- package/dist/letta/promptWrapping.js +213 -0
- package/dist/letta/promptWrapping.js.map +1 -0
- package/dist/letta/sandbox.d.ts +100 -0
- package/dist/letta/sandbox.d.ts.map +1 -0
- package/dist/letta/sandbox.js +151 -0
- package/dist/letta/sandbox.js.map +1 -0
- package/dist/letta/settingsFileSeed.d.ts +146 -0
- package/dist/letta/settingsFileSeed.d.ts.map +1 -0
- package/dist/letta/settingsFileSeed.js +177 -0
- package/dist/letta/settingsFileSeed.js.map +1 -0
- package/dist/letta/subprocessThrottle.d.ts +151 -0
- package/dist/letta/subprocessThrottle.d.ts.map +1 -0
- package/dist/letta/subprocessThrottle.js +195 -0
- package/dist/letta/subprocessThrottle.js.map +1 -0
- package/dist/letta/tpmRecovery.d.ts +202 -0
- package/dist/letta/tpmRecovery.d.ts.map +1 -0
- package/dist/letta/tpmRecovery.js +314 -0
- package/dist/letta/tpmRecovery.js.map +1 -0
- package/dist/letta/types.d.ts +54 -0
- package/dist/letta/types.d.ts.map +1 -0
- package/dist/letta/types.js +16 -0
- package/dist/letta/types.js.map +1 -0
- package/dist/observability/logger.d.ts +48 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +81 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +53 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +92 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/routes/admin/agents.d.ts +63 -0
- package/dist/routes/admin/agents.d.ts.map +1 -0
- package/dist/routes/admin/agents.js +461 -0
- package/dist/routes/admin/agents.js.map +1 -0
- package/dist/routes/admin/rotatingMessages.d.ts +51 -0
- package/dist/routes/admin/rotatingMessages.d.ts.map +1 -0
- package/dist/routes/admin/rotatingMessages.js +292 -0
- package/dist/routes/admin/rotatingMessages.js.map +1 -0
- package/dist/routes/admin/sessions.d.ts +61 -0
- package/dist/routes/admin/sessions.d.ts.map +1 -0
- package/dist/routes/admin/sessions.js +232 -0
- package/dist/routes/admin/sessions.js.map +1 -0
- package/dist/routes/admin/settings.d.ts +110 -0
- package/dist/routes/admin/settings.d.ts.map +1 -0
- package/dist/routes/admin/settings.js +401 -0
- package/dist/routes/admin/settings.js.map +1 -0
- package/dist/routes/admin/users.d.ts +115 -0
- package/dist/routes/admin/users.d.ts.map +1 -0
- package/dist/routes/admin/users.js +374 -0
- package/dist/routes/admin/users.js.map +1 -0
- package/dist/routes/agents.d.ts +30 -0
- package/dist/routes/agents.d.ts.map +1 -0
- package/dist/routes/agents.js +55 -0
- package/dist/routes/agents.js.map +1 -0
- package/dist/routes/auth.d.ts +121 -0
- package/dist/routes/auth.d.ts.map +1 -0
- package/dist/routes/auth.js +422 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/chat.d.ts +97 -0
- package/dist/routes/chat.d.ts.map +1 -0
- package/dist/routes/chat.js +484 -0
- package/dist/routes/chat.js.map +1 -0
- package/dist/routes/featureToggles.d.ts +34 -0
- package/dist/routes/featureToggles.d.ts.map +1 -0
- package/dist/routes/featureToggles.js +47 -0
- package/dist/routes/featureToggles.js.map +1 -0
- package/dist/routes/health.d.ts +24 -0
- package/dist/routes/health.d.ts.map +1 -0
- package/dist/routes/health.js +37 -0
- package/dist/routes/health.js.map +1 -0
- package/dist/routes/metrics.d.ts +35 -0
- package/dist/routes/metrics.d.ts.map +1 -0
- package/dist/routes/metrics.js +106 -0
- package/dist/routes/metrics.js.map +1 -0
- package/dist/routes/sessions.d.ts +161 -0
- package/dist/routes/sessions.d.ts.map +1 -0
- package/dist/routes/sessions.js +1501 -0
- package/dist/routes/sessions.js.map +1 -0
- package/dist/routes/stubs.d.ts +25 -0
- package/dist/routes/stubs.d.ts.map +1 -0
- package/dist/routes/stubs.js +25 -0
- package/dist/routes/stubs.js.map +1 -0
- package/dist/state/cron.d.ts +58 -0
- package/dist/state/cron.d.ts.map +1 -0
- package/dist/state/cron.js +160 -0
- package/dist/state/cron.js.map +1 -0
- package/dist/state/rotationRunner.d.ts +96 -0
- package/dist/state/rotationRunner.d.ts.map +1 -0
- package/dist/state/rotationRunner.js +246 -0
- package/dist/state/rotationRunner.js.map +1 -0
- package/dist/state/rotationScheduler.d.ts +76 -0
- package/dist/state/rotationScheduler.d.ts.map +1 -0
- package/dist/state/rotationScheduler.js +124 -0
- package/dist/state/rotationScheduler.js.map +1 -0
- package/dist/state/turnRegistry.d.ts +95 -0
- package/dist/state/turnRegistry.d.ts.map +1 -0
- package/dist/state/turnRegistry.js +149 -0
- package/dist/state/turnRegistry.js.map +1 -0
- package/dist/state/turnRunner.d.ts +134 -0
- package/dist/state/turnRunner.d.ts.map +1 -0
- package/dist/state/turnRunner.js +476 -0
- package/dist/state/turnRunner.js.map +1 -0
- package/package.json +47 -0
- package/src/auth/argon2.ts +152 -0
- package/src/auth/encryption.ts +110 -0
- package/src/auth/jwt.ts +217 -0
- package/src/auth/middleware.ts +250 -0
- package/src/auth/passwordPolicy.ts +99 -0
- package/src/auth/roleRules.ts +497 -0
- package/src/auth/userView.ts +88 -0
- package/src/bootstrap.ts +254 -0
- package/src/db/connection.ts +75 -0
- package/src/db/migrate.ts +212 -0
- package/src/db/schema.ts +750 -0
- package/src/db/seed.ts +236 -0
- package/src/handlers/fetch.ts +251 -0
- package/src/handlers/nextjs.ts +49 -0
- package/src/handlers/responses.ts +95 -0
- package/src/handlers/routeTable.ts +188 -0
- package/src/handlers/router.ts +96 -0
- package/src/handlers/sse.ts +55 -0
- package/src/handlers/types.ts +104 -0
- package/src/index.ts +60 -0
- package/src/letta/client.ts +860 -0
- package/src/letta/eventTranslator.ts +667 -0
- package/src/letta/index.ts +46 -0
- package/src/letta/lettaCliShim.mjs +40 -0
- package/src/letta/sandbox.ts +167 -0
- package/src/letta/settingsFileSeed.ts +254 -0
- package/src/letta/subprocessThrottle.ts +251 -0
- package/src/letta/types.ts +65 -0
- package/src/observability/logger.ts +103 -0
- package/src/observability/metrics.ts +114 -0
- package/src/routes/admin/agents.ts +574 -0
- package/src/routes/admin/rotatingMessages.ts +351 -0
- package/src/routes/admin/sessions.ts +283 -0
- package/src/routes/admin/settings.ts +463 -0
- package/src/routes/admin/users.ts +455 -0
- package/src/routes/agents.ts +66 -0
- package/src/routes/auth.ts +513 -0
- package/src/routes/chat.ts +534 -0
- package/src/routes/featureToggles.ts +52 -0
- package/src/routes/health.ts +44 -0
- package/src/routes/metrics.ts +111 -0
- package/src/routes/sessions.ts +1878 -0
- package/src/state/cron.ts +179 -0
- package/src/state/rotationRunner.ts +326 -0
- package/src/state/rotationScheduler.ts +164 -0
- package/src/state/turnRegistry.ts +210 -0
- package/src/state/turnRunner.ts +588 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured logging via pino.
|
|
3
|
+
*
|
|
4
|
+
* Production: raw JSON to stdout, one line per record (§6.10 — twelve-factor
|
|
5
|
+
* pattern). Dev: piped through `pino-pretty` for human-readable output, gated
|
|
6
|
+
* on `NODE_ENV !== "production"` or `LOG_LEVEL=debug`.
|
|
7
|
+
*
|
|
8
|
+
* **Redaction is a load-bearing security control** (§13.3). pino's built-in
|
|
9
|
+
* `redact` option is the single point of truth — every log call goes through
|
|
10
|
+
* the configured logger, and a regression test asserts a known-secret value
|
|
11
|
+
* never appears in captured stdout.
|
|
12
|
+
*
|
|
13
|
+
* @see SPECIFICATIONS.md §6.10 — observability
|
|
14
|
+
* @see SPECIFICATIONS.md §13.3 — secrets
|
|
15
|
+
*/
|
|
16
|
+
import { pino } from "pino";
|
|
17
|
+
/**
|
|
18
|
+
* The redaction paths pino watches on every log record.
|
|
19
|
+
*
|
|
20
|
+
* The list explicitly covers the keys the spec calls out (`*_key`, `*_token`,
|
|
21
|
+
* `password`, `authorization`) plus their nested forms inside common places
|
|
22
|
+
* (`req.headers.authorization`, `body.password`, etc.). Adding a new
|
|
23
|
+
* sensitive field is a matter of appending a path here — there is no second
|
|
24
|
+
* redaction layer to keep in sync.
|
|
25
|
+
*/
|
|
26
|
+
const REDACT_PATHS = [
|
|
27
|
+
"password",
|
|
28
|
+
"current_password",
|
|
29
|
+
"new_password",
|
|
30
|
+
"passwordHash",
|
|
31
|
+
"password_hash",
|
|
32
|
+
"authorization",
|
|
33
|
+
"Authorization",
|
|
34
|
+
"headers.authorization",
|
|
35
|
+
"headers.Authorization",
|
|
36
|
+
"req.headers.authorization",
|
|
37
|
+
"req.headers.Authorization",
|
|
38
|
+
"request.headers.authorization",
|
|
39
|
+
"request.headers.Authorization",
|
|
40
|
+
"*.authorization",
|
|
41
|
+
"*.Authorization",
|
|
42
|
+
"service_token_signing_key",
|
|
43
|
+
"serviceTokenSigningKey",
|
|
44
|
+
"letta_api_key",
|
|
45
|
+
"lettaApiKey",
|
|
46
|
+
"metrics_scrape_token",
|
|
47
|
+
"metricsScrapeToken",
|
|
48
|
+
"encryption_key",
|
|
49
|
+
"encryptionKey",
|
|
50
|
+
"token",
|
|
51
|
+
"*.token",
|
|
52
|
+
"generated_password",
|
|
53
|
+
"*.generated_password",
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* Builds a pino logger with the project's redaction policy applied.
|
|
57
|
+
*
|
|
58
|
+
* @param opts - level + optional destination override.
|
|
59
|
+
* @returns the pino logger instance.
|
|
60
|
+
*/
|
|
61
|
+
export function createLogger(opts = {}) {
|
|
62
|
+
const config = {
|
|
63
|
+
level: opts.level ?? process.env.LOG_LEVEL ?? "info",
|
|
64
|
+
redact: {
|
|
65
|
+
paths: [...REDACT_PATHS],
|
|
66
|
+
censor: "[redacted]",
|
|
67
|
+
remove: false,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
return opts.destination ? pino(config, opts.destination) : pino(config);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The redaction-path list — exposed for tests so a new path added in
|
|
74
|
+
* `REDACT_PATHS` is automatically covered without test churn.
|
|
75
|
+
*
|
|
76
|
+
* @returns a fresh array of the redaction paths used by `createLogger`.
|
|
77
|
+
*/
|
|
78
|
+
export function getRedactPaths() {
|
|
79
|
+
return [...REDACT_PATHS];
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/observability/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAiD,MAAM,MAAM,CAAC;AAK3E;;;;;;;;GAQG;AACH,MAAM,YAAY,GAA0B;IAC1C,UAAU;IACV,kBAAkB;IAClB,cAAc;IACd,cAAc;IACd,eAAe;IACf,eAAe;IACf,eAAe;IACf,uBAAuB;IACvB,uBAAuB;IACvB,2BAA2B;IAC3B,2BAA2B;IAC3B,+BAA+B;IAC/B,+BAA+B;IAC/B,iBAAiB;IACjB,iBAAiB;IACjB,2BAA2B;IAC3B,wBAAwB;IACxB,eAAe;IACf,aAAa;IACb,sBAAsB;IACtB,oBAAoB;IACpB,gBAAgB;IAChB,eAAe;IACf,OAAO;IACP,SAAS;IACT,oBAAoB;IACpB,sBAAsB;CACvB,CAAC;AAkBF;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B,EAAE;IACzD,MAAM,MAAM,GAAkB;QAC5B,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM;QACpD,MAAM,EAAE;YACN,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC;YACxB,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE,KAAK;SACd;KACF,CAAC;IACF,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-local Prometheus-shaped metrics registry.
|
|
3
|
+
*
|
|
4
|
+
* v1 keeps this tiny — three counters + two gauges — to avoid pulling
|
|
5
|
+
* `prom-client` for what is a five-series surface. The names + types
|
|
6
|
+
* match §6.10's contract verbatim so an operator's existing dashboards
|
|
7
|
+
* keep working when a future version swaps in a heavier library.
|
|
8
|
+
*
|
|
9
|
+
* Counters monotonically increment (and persist across the process'
|
|
10
|
+
* lifetime); gauges hold a single most-recent value. Step 5 wires the
|
|
11
|
+
* chat-side series; Step 6 fills in the TPM-recovery counters.
|
|
12
|
+
*
|
|
13
|
+
* @see SPECIFICATIONS.md §6.10 — observability / metrics
|
|
14
|
+
*/
|
|
15
|
+
/** A monotonic counter. */
|
|
16
|
+
export interface Counter {
|
|
17
|
+
/** Adds `n` (default 1) to the counter. */
|
|
18
|
+
inc(n?: number): void;
|
|
19
|
+
/** Reads the current value. */
|
|
20
|
+
value(): number;
|
|
21
|
+
}
|
|
22
|
+
/** A single-value gauge. */
|
|
23
|
+
export interface Gauge {
|
|
24
|
+
/** Replaces the gauge's current value. */
|
|
25
|
+
set(value: number): void;
|
|
26
|
+
/** Reads the current value. */
|
|
27
|
+
value(): number;
|
|
28
|
+
}
|
|
29
|
+
/** Total `/chat` requests received. Bumped on every accepted POST. */
|
|
30
|
+
export declare const chatRequestsTotal: Counter;
|
|
31
|
+
/** TPM recovery attempts started — populated by Step 6. */
|
|
32
|
+
export declare const tpmRecoveryAttemptsTotal: Counter;
|
|
33
|
+
/** TPM recoveries that exhausted their budget — populated by Step 6. */
|
|
34
|
+
export declare const tpmExhaustedTotal: Counter;
|
|
35
|
+
/** Most-recent `/chat` turn duration in ms. */
|
|
36
|
+
export declare const chatDurationMs: Gauge;
|
|
37
|
+
/** Most-recent Letta SDK call duration in ms. */
|
|
38
|
+
export declare const lettaRequestDurationMs: Gauge;
|
|
39
|
+
/**
|
|
40
|
+
* Renders the registry as a Prometheus-text v0.0.4 exposition.
|
|
41
|
+
*
|
|
42
|
+
* The route handler in `routes/metrics.ts` calls this after the bearer
|
|
43
|
+
* token gate passes.
|
|
44
|
+
*
|
|
45
|
+
* @returns the full response body.
|
|
46
|
+
*/
|
|
47
|
+
export declare function renderMetrics(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Resets every series. **Test-only** — production never calls this.
|
|
50
|
+
* Without it, vitest's module-cache means counters carry across tests.
|
|
51
|
+
*/
|
|
52
|
+
export declare function _resetMetricsForTests(): void;
|
|
53
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/observability/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,2BAA2B;AAC3B,MAAM,WAAW,OAAO;IACtB,2CAA2C;IAC3C,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+BAA+B;IAC/B,KAAK,IAAI,MAAM,CAAC;CACjB;AAED,4BAA4B;AAC5B,MAAM,WAAW,KAAK;IACpB,0CAA0C;IAC1C,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,+BAA+B;IAC/B,KAAK,IAAI,MAAM,CAAC;CACjB;AA4BD,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,EAAE,OAAmB,CAAC;AACpD,2DAA2D;AAC3D,eAAO,MAAM,wBAAwB,EAAE,OAAmB,CAAC;AAC3D,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,EAAE,OAAmB,CAAC;AACpD,+CAA+C;AAC/C,eAAO,MAAM,cAAc,EAAE,KAAe,CAAC;AAC7C,iDAAiD;AACjD,eAAO,MAAM,sBAAsB,EAAE,KAAe,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAyBtC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAM5C"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-local Prometheus-shaped metrics registry.
|
|
3
|
+
*
|
|
4
|
+
* v1 keeps this tiny — three counters + two gauges — to avoid pulling
|
|
5
|
+
* `prom-client` for what is a five-series surface. The names + types
|
|
6
|
+
* match §6.10's contract verbatim so an operator's existing dashboards
|
|
7
|
+
* keep working when a future version swaps in a heavier library.
|
|
8
|
+
*
|
|
9
|
+
* Counters monotonically increment (and persist across the process'
|
|
10
|
+
* lifetime); gauges hold a single most-recent value. Step 5 wires the
|
|
11
|
+
* chat-side series; Step 6 fills in the TPM-recovery counters.
|
|
12
|
+
*
|
|
13
|
+
* @see SPECIFICATIONS.md §6.10 — observability / metrics
|
|
14
|
+
*/
|
|
15
|
+
/** Internal counter factory. */
|
|
16
|
+
function counter() {
|
|
17
|
+
let v = 0;
|
|
18
|
+
return {
|
|
19
|
+
inc(n = 1) {
|
|
20
|
+
v += n;
|
|
21
|
+
},
|
|
22
|
+
value() {
|
|
23
|
+
return v;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Internal gauge factory. */
|
|
28
|
+
function gauge() {
|
|
29
|
+
let v = 0;
|
|
30
|
+
return {
|
|
31
|
+
set(value) {
|
|
32
|
+
v = value;
|
|
33
|
+
},
|
|
34
|
+
value() {
|
|
35
|
+
return v;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Total `/chat` requests received. Bumped on every accepted POST. */
|
|
40
|
+
export const chatRequestsTotal = counter();
|
|
41
|
+
/** TPM recovery attempts started — populated by Step 6. */
|
|
42
|
+
export const tpmRecoveryAttemptsTotal = counter();
|
|
43
|
+
/** TPM recoveries that exhausted their budget — populated by Step 6. */
|
|
44
|
+
export const tpmExhaustedTotal = counter();
|
|
45
|
+
/** Most-recent `/chat` turn duration in ms. */
|
|
46
|
+
export const chatDurationMs = gauge();
|
|
47
|
+
/** Most-recent Letta SDK call duration in ms. */
|
|
48
|
+
export const lettaRequestDurationMs = gauge();
|
|
49
|
+
/**
|
|
50
|
+
* Renders the registry as a Prometheus-text v0.0.4 exposition.
|
|
51
|
+
*
|
|
52
|
+
* The route handler in `routes/metrics.ts` calls this after the bearer
|
|
53
|
+
* token gate passes.
|
|
54
|
+
*
|
|
55
|
+
* @returns the full response body.
|
|
56
|
+
*/
|
|
57
|
+
export function renderMetrics() {
|
|
58
|
+
return ([
|
|
59
|
+
"# HELP chat_requests_total Total /chat requests received.",
|
|
60
|
+
"# TYPE chat_requests_total counter",
|
|
61
|
+
`chat_requests_total ${chatRequestsTotal.value()}`,
|
|
62
|
+
"",
|
|
63
|
+
"# HELP tpm_recovery_attempts_total TPM recovery attempts started.",
|
|
64
|
+
"# TYPE tpm_recovery_attempts_total counter",
|
|
65
|
+
`tpm_recovery_attempts_total ${tpmRecoveryAttemptsTotal.value()}`,
|
|
66
|
+
"",
|
|
67
|
+
"# HELP tpm_exhausted_total TPM recoveries that exhausted their budget.",
|
|
68
|
+
"# TYPE tpm_exhausted_total counter",
|
|
69
|
+
`tpm_exhausted_total ${tpmExhaustedTotal.value()}`,
|
|
70
|
+
"",
|
|
71
|
+
"# HELP chat_duration_ms Most-recent /chat turn duration in ms.",
|
|
72
|
+
"# TYPE chat_duration_ms gauge",
|
|
73
|
+
`chat_duration_ms ${chatDurationMs.value()}`,
|
|
74
|
+
"",
|
|
75
|
+
"# HELP letta_request_duration_ms Most-recent Letta SDK call duration in ms.",
|
|
76
|
+
"# TYPE letta_request_duration_ms gauge",
|
|
77
|
+
`letta_request_duration_ms ${lettaRequestDurationMs.value()}`,
|
|
78
|
+
"",
|
|
79
|
+
].join("\n"));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Resets every series. **Test-only** — production never calls this.
|
|
83
|
+
* Without it, vitest's module-cache means counters carry across tests.
|
|
84
|
+
*/
|
|
85
|
+
export function _resetMetricsForTests() {
|
|
86
|
+
chatRequestsTotal.inc(-chatRequestsTotal.value());
|
|
87
|
+
tpmRecoveryAttemptsTotal.inc(-tpmRecoveryAttemptsTotal.value());
|
|
88
|
+
tpmExhaustedTotal.inc(-tpmExhaustedTotal.value());
|
|
89
|
+
chatDurationMs.set(0);
|
|
90
|
+
lettaRequestDurationMs.set(0);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/observability/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAkBH,gCAAgC;AAChC,SAAS,OAAO;IACd,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO;QACL,GAAG,CAAC,CAAC,GAAG,CAAC;YACP,CAAC,IAAI,CAAC,CAAC;QACT,CAAC;QACD,KAAK;YACH,OAAO,CAAC,CAAC;QACX,CAAC;KACF,CAAC;AACJ,CAAC;AAED,8BAA8B;AAC9B,SAAS,KAAK;IACZ,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO;QACL,GAAG,CAAC,KAAK;YACP,CAAC,GAAG,KAAK,CAAC;QACZ,CAAC;QACD,KAAK;YACH,OAAO,CAAC,CAAC;QACX,CAAC;KACF,CAAC;AACJ,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,MAAM,iBAAiB,GAAY,OAAO,EAAE,CAAC;AACpD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,wBAAwB,GAAY,OAAO,EAAE,CAAC;AAC3D,wEAAwE;AACxE,MAAM,CAAC,MAAM,iBAAiB,GAAY,OAAO,EAAE,CAAC;AACpD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAU,KAAK,EAAE,CAAC;AAC7C,iDAAiD;AACjD,MAAM,CAAC,MAAM,sBAAsB,GAAU,KAAK,EAAE,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CACL;QACE,2DAA2D;QAC3D,oCAAoC;QACpC,uBAAuB,iBAAiB,CAAC,KAAK,EAAE,EAAE;QAClD,EAAE;QACF,mEAAmE;QACnE,4CAA4C;QAC5C,+BAA+B,wBAAwB,CAAC,KAAK,EAAE,EAAE;QACjE,EAAE;QACF,wEAAwE;QACxE,oCAAoC;QACpC,uBAAuB,iBAAiB,CAAC,KAAK,EAAE,EAAE;QAClD,EAAE;QACF,gEAAgE;QAChE,+BAA+B;QAC/B,oBAAoB,cAAc,CAAC,KAAK,EAAE,EAAE;QAC5C,EAAE;QACF,6EAA6E;QAC7E,wCAAwC;QACxC,6BAA6B,sBAAsB,CAAC,KAAK,EAAE,EAAE;QAC7D,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACnC,iBAAiB,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC,CAAC;IAClD,wBAAwB,CAAC,GAAG,CAAC,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC,CAAC;IAChE,iBAAiB,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC,CAAC;IAClD,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACtB,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/admin/agents/*` — power_user + admin + super_admin catalog management.
|
|
3
|
+
*
|
|
4
|
+
* Three endpoints (no DELETE by design — agents are archive-only in v1):
|
|
5
|
+
*
|
|
6
|
+
* - `GET /admin/agents` — every agent in the deployment, including archived
|
|
7
|
+
* ones. Lets the admin UI render the catalog with the archived rows
|
|
8
|
+
* filtered in/out via the `[☐ Show archived]` toggle ([06-admin-agents.md]).
|
|
9
|
+
* - `POST /admin/agents` — body `{ display_name, letta_agent_id, tpm_recovery_enabled?, max_recovery_attempts?, default_retry_after_seconds? }`.
|
|
10
|
+
* Validates `letta_agent_id` against Letta (Step 5 wires the real check;
|
|
11
|
+
* Step 4 stubs it through with a `TODO`).
|
|
12
|
+
* - `PATCH /admin/agents/:id` — body `{ display_name?, letta_agent_id?, tpm_recovery_enabled?, max_recovery_attempts?, default_retry_after_seconds?, is_archived? }`.
|
|
13
|
+
* Archive / unarchive is just `{ is_archived: true | false }`. All fields
|
|
14
|
+
* optional; empty patch is a 200 no-op.
|
|
15
|
+
*
|
|
16
|
+
* **No DELETE.** Per §6.3.4 / §11, agents cannot be hard-deleted in v1 —
|
|
17
|
+
* archiving keeps existing sessions readable + writable while preventing new
|
|
18
|
+
* sessions from starting against the agent. Step 12's UI exposes only
|
|
19
|
+
* archive/unarchive; this server enforces the same.
|
|
20
|
+
*
|
|
21
|
+
* @see SPECIFICATIONS.md §6.3.4 — admin agents endpoints
|
|
22
|
+
* @see SPECIFICATIONS.md §6.5 — TPM recovery defaults
|
|
23
|
+
* @see ui-sketches/06-admin-agents.md
|
|
24
|
+
*/
|
|
25
|
+
import type { RouteHandler } from "../../handlers/types.js";
|
|
26
|
+
/**
|
|
27
|
+
* `GET /admin/agents` — every agent in the deployment, archived rows
|
|
28
|
+
* included. The admin UI filters them client-side via the
|
|
29
|
+
* `[☐ Show archived]` toggle ([06-admin-agents.md]).
|
|
30
|
+
*
|
|
31
|
+
* Sorted by `display_name` for stable rendering.
|
|
32
|
+
*
|
|
33
|
+
* Available to `power_user`+ per the §8.2 matrix.
|
|
34
|
+
*
|
|
35
|
+
* @see SPECIFICATIONS.md §6.3.4
|
|
36
|
+
*/
|
|
37
|
+
export declare const handleListAgents: RouteHandler;
|
|
38
|
+
/**
|
|
39
|
+
* `POST /admin/agents` — create a new ai-hub agent (catalog entry).
|
|
40
|
+
*
|
|
41
|
+
* Validates the Letta-side id via `validateLettaAgentId` (Step 4 stub —
|
|
42
|
+
* always passes; Step 5 wires the real check against the Letta SDK). On a
|
|
43
|
+
* Letta-id miss returns 400 `letta_agent_not_found` with the offending field
|
|
44
|
+
* named, so the React modal can surface the error inline on the field
|
|
45
|
+
* ([06-admin-agents.md]).
|
|
46
|
+
*
|
|
47
|
+
* @see SPECIFICATIONS.md §6.3.4
|
|
48
|
+
* @see ui-sketches/06-admin-agents.md
|
|
49
|
+
*/
|
|
50
|
+
export declare const handleCreateAgent: RouteHandler;
|
|
51
|
+
/**
|
|
52
|
+
* `PATCH /admin/agents/:id` — partial update.
|
|
53
|
+
*
|
|
54
|
+
* If `letta_agent_id` is in the patch, the same Letta-side validation runs
|
|
55
|
+
* as on create. `is_archived` is the archive / unarchive toggle (no separate
|
|
56
|
+
* endpoint). All fields optional; an empty patch (`{}`) is a 200 no-op that
|
|
57
|
+
* echoes the row unchanged.
|
|
58
|
+
*
|
|
59
|
+
* @see SPECIFICATIONS.md §6.3.4
|
|
60
|
+
* @see ui-sketches/06-admin-agents.md
|
|
61
|
+
*/
|
|
62
|
+
export declare const handlePatchAgent: RouteHandler;
|
|
63
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../src/routes/admin/agents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAgBH,OAAO,KAAK,EAAsB,YAAY,EAAE,MAAM,yBAAyB,CAAC;AA0PhF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,EAAE,YAM9B,CAAC;AA+BF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,EAAE,YAqF/B,CAAC;AAuBF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,EAAE,YAyG9B,CAAC"}
|