tidewave 0.5.5 → 0.7.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/dist/core.d.ts CHANGED
@@ -19,7 +19,7 @@ export interface InternalResolvedModule {
19
19
  }
20
20
  export interface ExtractionRequest {
21
21
  readonly module: string;
22
- readonly symbol: string;
22
+ readonly symbol?: string;
23
23
  readonly member?: string;
24
24
  readonly isStatic?: boolean;
25
25
  }
@@ -32,6 +32,18 @@ export interface SymbolInfo {
32
32
  readonly location: string;
33
33
  readonly jsDoc?: string;
34
34
  }
35
+ export interface ExportSummary {
36
+ readonly name: string;
37
+ readonly kind: string;
38
+ readonly line: number;
39
+ readonly documentation?: string;
40
+ }
41
+ export interface FileInfo {
42
+ readonly path: string;
43
+ readonly overview?: string;
44
+ readonly exportCount: number;
45
+ readonly exports: ExportSummary[];
46
+ }
35
47
  export interface ExtractorOptions {
36
48
  readonly prefix?: string;
37
49
  }
@@ -62,19 +74,16 @@ export interface EvaluatedModuleResult {
62
74
  stderr: string;
63
75
  }
64
76
  export type ResolveResult = ResolvedModule | ResolveError;
65
- export type ExtractResult = SymbolInfo | ExtractError;
77
+ export type ExtractResult = SymbolInfo | FileInfo | ExtractError;
66
78
  export type InternalResolveResult = InternalResolvedModule | ResolveError;
67
- export declare function isError(result: ResolveResult | ExtractResult): boolean;
68
79
  export declare function isResolveError(result: ResolveResult | InternalResolveResult): result is ResolveError;
69
80
  export declare function isExtractError(result: ExtractResult): result is ExtractError;
81
+ export declare function isFileInfo(result: ExtractResult): result is FileInfo;
70
82
  export declare function resolveError(specifier: ModuleRequest['specifier'], source: ModuleRequest['source']): ResolveError;
71
83
  export declare function createExtractError(code: ExtractError['error']['code'], message: string, details?: unknown): ExtractError;
72
84
  export interface TidewaveConfig {
73
- port?: number;
74
- host?: string;
75
85
  clientUrl?: string;
76
86
  allowRemoteAccess?: boolean;
77
- allowedOrigins?: string[];
78
87
  projectName?: string;
79
88
  framework?: string;
80
89
  team?: {
@@ -1,3 +1,4 @@
1
- import type { Handler } from '../index';
1
+ import { type Request, type Handler } from '../index';
2
2
  import type { TidewaveConfig } from '../../core';
3
- export declare function createHandleConfig(config: TidewaveConfig): Handler;
3
+ export type LocalPortGetter = (req: Request) => number | undefined;
4
+ export declare function createHandleConfig(config: TidewaveConfig, getLocalPort?: LocalPortGetter): Handler;
@@ -1,5 +1,6 @@
1
1
  import type { ServerResponse } from 'http';
2
2
  import type { IncomingMessage, NextFunction, Server } from 'connect';
3
+ import { type LocalPortGetter } from './handlers/config';
3
4
  import type { TidewaveConfig } from '../core';
4
5
  export interface Request extends IncomingMessage {
5
6
  body?: Record<string, unknown>;
@@ -8,9 +9,12 @@ export type Response = ServerResponse<IncomingMessage>;
8
9
  export type NextFn = NextFunction;
9
10
  export declare const ENDPOINT: "/tidewave";
10
11
  export type Handler = (req: Request, res: Response, next: NextFn) => Promise<void>;
11
- declare function getHandlers(config: TidewaveConfig): Record<string, Handler>;
12
- export declare function configureServer(server?: Server, config?: TidewaveConfig): Server;
13
- export declare function serve(server: Server, config?: TidewaveConfig): void;
12
+ export interface HandlerOptions {
13
+ getLocalPort?: LocalPortGetter;
14
+ }
15
+ declare function getHandlers(config: TidewaveConfig, options?: HandlerOptions): Record<string, Handler>;
16
+ export declare function configureServer(server?: Server, config?: TidewaveConfig, options?: HandlerOptions): Server;
14
17
  export declare function checkSecurity(config: TidewaveConfig): (req: Request, res: Response, next: NextFn) => void;
15
18
  export declare function methodNotAllowed(res: Response): void;
19
+ export declare function originNotAllowed(res: Response): void;
16
20
  export { getHandlers };
@@ -2,11 +2,3 @@ import type { TidewaveConfig } from '../core';
2
2
  import type { Request, Response } from './index';
3
3
  export declare function checkRemoteIp(req: Request, res: Response, config: TidewaveConfig): boolean;
4
4
  export declare function isLocalIp(ip?: string): boolean;
5
- export declare function checkOrigin(req: Request, res: Response, config: TidewaveConfig): boolean;
6
- export declare function getDefaultAllowedOrigins(config: TidewaveConfig): string[];
7
- export declare function parseUrl(url: string): {
8
- scheme?: string;
9
- host: string;
10
- port?: number;
11
- } | null;
12
- export declare function isOriginAllowed(origin: ReturnType<typeof parseUrl>, allowed: ReturnType<typeof parseUrl>): boolean;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Patch console methods to write directly to the tidewave logger.
3
+ * This is called automatically when this module is imported.
4
+ */
5
+ export declare function patchConsole(): void;
@@ -2,7 +2,7 @@ import type { LogRecordProcessor, SdkLogRecord } from '@opentelemetry/sdk-logs';
2
2
  import type { Context } from '@opentelemetry/api';
3
3
  /**
4
4
  * Custom LogRecordProcessor that captures OpenTelemetry logger logs
5
- * and writes them directly to the circular buffer.
5
+ * and writes them directly to the tidewave logger.
6
6
  *
7
7
  * This is opt-in for users who want to capture actual logger logs
8
8
  * (not console.log, which is handled separately by console patching).
@@ -0,0 +1,37 @@
1
+ export interface StoredLogRecord {
2
+ timestamp: string;
3
+ severityText: string;
4
+ body: string;
5
+ attributes?: Record<string, unknown>;
6
+ }
7
+ export interface LogFilterOptions {
8
+ tail?: number;
9
+ grep?: string;
10
+ level?: string;
11
+ since?: string;
12
+ }
13
+ /**
14
+ * Tidewave log store.
15
+ *
16
+ * Storing logs in memory can be problematic, because some frameworks
17
+ * can use multiple execution contexts with isolated module loading
18
+ * and globals. In such circumstances, if we import the logger and
19
+ * write to it within the app, it may be a different logger instance
20
+ * from the one that the MCP server uses the get the logs. To avoid
21
+ * issues we persist logs in a NDJSON file, so it works across
22
+ * execution contexts.
23
+ */
24
+ export declare class TidewaveLogger {
25
+ private logFilePath;
26
+ constructor();
27
+ /**
28
+ * Store a log entry.
29
+ */
30
+ addLog(log: StoredLogRecord): Promise<void>;
31
+ /**
32
+ * Get stored logs.
33
+ */
34
+ getLogs(options?: LogFilterOptions): Promise<StoredLogRecord[]>;
35
+ private getAllLogs;
36
+ }
37
+ export declare const tidewaveLogger: TidewaveLogger;
@@ -3,7 +3,7 @@ import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
3
3
  import type { Span, Context } from '@opentelemetry/api';
4
4
  /**
5
5
  * Custom SpanProcessor that converts OpenTelemetry spans to logs and writes them
6
- * directly to the circular buffer.
6
+ * directly to the tidewave logger.
7
7
  * This is used to capture Next.js HTTP request/response spans and
8
8
  * make them available via the get_logs tool.
9
9
  */
@@ -14,7 +14,7 @@ export declare class TidewaveSpanProcessor implements SpanProcessor {
14
14
  onStart(_span: Span, _parentContext: Context): void;
15
15
  /**
16
16
  * Called when a span ends. This is where we convert the span to a log entry
17
- * and write it directly to the circular buffer.
17
+ * and write it directly to the tidewave logger.
18
18
  */
19
19
  onEnd(span: ReadableSpan): void;
20
20
  /**
@@ -7,5 +7,6 @@ export type FunctionLike = (...args: any[]) => unknown;
7
7
  export type Nextable<H extends FunctionLike> = (...args: [...Parameters<H>, NextHandler]) => ValueOrPromise<any>;
8
8
  export type ValueOrPromise<T> = T | Promise<T>;
9
9
  export type RequestHandler<Req extends Request, Res extends Response> = (req: Req, res: Res) => ValueOrPromise<void>;
10
+ export declare function getRequestLocalPort(request: Request): number | undefined;
10
11
  export declare function tidewaveHandler(config?: TidewaveConfig): Promise<NextJsHandler>;
11
12
  export {};