@ractive-ch/tab-mcp 0.0.0-stage → 0.1.0-alpha.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/ip.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * IP address parsing and the public-address check used by the CIMD fetcher's
3
+ * SSRF guard (threat model A3) and by log truncation (A9).
4
+ */
5
+ /** Parse dotted-quad IPv4 into four octets, or undefined. */
6
+ export declare function parseIpv4(ip: string): number[] | undefined;
7
+ /** Parse IPv6 (with `::`, an optional zone, an embedded IPv4 tail) into 8 groups. */
8
+ export declare function parseIpv6(ip: string): number[] | undefined;
9
+ /**
10
+ * Whether an IP address (v4 or v6 text) is a globally reachable unicast
11
+ * address. Anything that does not parse counts as not public.
12
+ */
13
+ export declare function isPublicIp(ip: string): boolean;
14
+ /** Whether a URL hostname is a loopback name or address. */
15
+ export declare function isLoopbackHost(hostname: string): boolean;
16
+ /**
17
+ * The key per-IP limits count under (threat model A8, DEC-061): an IPv4
18
+ * address as is (/32, since many users share one behind NAT or CGNAT
19
+ * anyway), an IPv6 address by its /64, which one subscriber usually gets
20
+ * whole. IPv4-mapped IPv6 counts as IPv4. Anything else is used verbatim.
21
+ */
22
+ export declare function ipPrefixKey(ip: string): string;
package/log.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { LogLevel } from "./config.js";
2
+ /**
3
+ * Structured JSON-line logging (threat model A9). Callers pass only metadata:
4
+ * never request or response bodies, tool names, arguments, results, tokens,
5
+ * pairing codes or page secrets. There is deliberately no helper that accepts
6
+ * a body.
7
+ */
8
+ export type LogFields = Record<string, string | number | boolean | null>;
9
+ export interface Logger {
10
+ error(event: string, fields?: LogFields): void;
11
+ warn(event: string, fields?: LogFields): void;
12
+ info(event: string, fields?: LogFields): void;
13
+ debug(event: string, fields?: LogFields): void;
14
+ }
15
+ /** A logger that writes one JSON object per line to `sink` (stdout by default). */
16
+ export declare function createLogger(level: LogLevel, sink?: (line: string) => void): Logger;
17
+ /**
18
+ * Truncate an IP for logs: IPv4 to /24, IPv6 to /48. IPv4-mapped IPv6
19
+ * (`::ffff:a.b.c.d`) is treated as IPv4. `?` if it does not parse.
20
+ */
21
+ export declare function truncateIp(ip: string): string;
22
+ /**
23
+ * Defence in depth (DEC-047). The relay catches errors per message and per
24
+ * request; anything that still escapes is logged, never silently fatal:
25
+ * - an unhandled promise rejection is logged and the relay keeps running, so one
26
+ * bad request or tab cannot end every other session;
27
+ * - an uncaught exception is logged and the process exits with 1, because the
28
+ * relay's state may be inconsistent; the supervisor (Docker, systemd) restarts
29
+ * it and AI apps keep their tokens (they live in the store).
30
+ * Only the error's name is logged: messages can carry request data.
31
+ * Returns a function that removes the handlers.
32
+ */
33
+ export declare function installCrashLogging(logger: Logger, exit?: (code: number) => void): () => void;