stitchkit 0.0.1 → 0.2.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/LICENSE +21 -0
- package/README.md +376 -4
- package/dist/browser/client.d.ts +30 -0
- package/dist/browser/client.d.ts.map +1 -0
- package/dist/browser/http.d.ts +77 -0
- package/dist/browser/http.d.ts.map +1 -0
- package/dist/browser/socket-io.d.ts +69 -0
- package/dist/browser/socket-io.d.ts.map +1 -0
- package/dist/browser/stream.d.ts +2 -0
- package/dist/browser/stream.d.ts.map +1 -0
- package/dist/contract/define.d.ts +94 -0
- package/dist/contract/define.d.ts.map +1 -0
- package/dist/contract/errors.d.ts +47 -0
- package/dist/contract/errors.d.ts.map +1 -0
- package/dist/contract/index.d.ts +4 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +26 -0
- package/dist/contract/pagination.d.ts +19 -0
- package/dist/contract/pagination.d.ts.map +1 -0
- package/dist/index-5sxnvwb1.js +368 -0
- package/dist/index-809wc1tt.js +18 -0
- package/dist/index-a35v22fh.js +29 -0
- package/dist/index-kckky6zw.js +96 -0
- package/dist/index-ke4mx4ea.js +38 -0
- package/dist/index-n7bmdwmz.js +68 -0
- package/dist/index-v2z2v3mq.js +587 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +111 -0
- package/dist/internal/errors.d.ts +5 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/typed.d.ts +9 -0
- package/dist/internal/typed.d.ts.map +1 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +26 -0
- package/dist/observability/audit.d.ts +32 -0
- package/dist/observability/audit.d.ts.map +1 -0
- package/dist/observability/context.d.ts +60 -0
- package/dist/observability/context.d.ts.map +1 -0
- package/dist/observability/event.d.ts +49 -0
- package/dist/observability/event.d.ts.map +1 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +266 -0
- package/dist/observability/sanitize.d.ts +42 -0
- package/dist/observability/sanitize.d.ts.map +1 -0
- package/dist/observability/trace.d.ts +42 -0
- package/dist/observability/trace.d.ts.map +1 -0
- package/dist/react/cache-bridge.d.ts +53 -0
- package/dist/react/cache-bridge.d.ts.map +1 -0
- package/dist/react/cursor-query.d.ts +37 -0
- package/dist/react/cursor-query.d.ts.map +1 -0
- package/dist/react.d.ts +3 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +52 -0
- package/dist/server/cache.d.ts +15 -0
- package/dist/server/cache.d.ts.map +1 -0
- package/dist/server/context.d.ts +9 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/create.d.ts +4 -0
- package/dist/server/create.d.ts.map +1 -0
- package/dist/server/event-bus.d.ts +24 -0
- package/dist/server/event-bus.d.ts.map +1 -0
- package/dist/server/implement.d.ts +16 -0
- package/dist/server/implement.d.ts.map +1 -0
- package/dist/server/index.d.ts +17 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +399 -0
- package/dist/server/logger.d.ts +21 -0
- package/dist/server/logger.d.ts.map +1 -0
- package/dist/server/middleware/auth.d.ts +50 -0
- package/dist/server/middleware/auth.d.ts.map +1 -0
- package/dist/server/middleware/cookies.d.ts +34 -0
- package/dist/server/middleware/cookies.d.ts.map +1 -0
- package/dist/server/middleware/cors.d.ts +9 -0
- package/dist/server/middleware/cors.d.ts.map +1 -0
- package/dist/server/multipart.d.ts +14 -0
- package/dist/server/multipart.d.ts.map +1 -0
- package/dist/server/node.d.ts +12 -0
- package/dist/server/node.d.ts.map +1 -0
- package/dist/server/rate-limit.d.ts +17 -0
- package/dist/server/rate-limit.d.ts.map +1 -0
- package/dist/server/request.d.ts +22 -0
- package/dist/server/request.d.ts.map +1 -0
- package/dist/server/router.d.ts +42 -0
- package/dist/server/router.d.ts.map +1 -0
- package/dist/server/socket-io.d.ts +42 -0
- package/dist/server/socket-io.d.ts.map +1 -0
- package/dist/server/stream.d.ts +18 -0
- package/dist/server/stream.d.ts.map +1 -0
- package/dist/server/swept-map.d.ts +22 -0
- package/dist/server/swept-map.d.ts.map +1 -0
- package/dist/server/types.d.ts +127 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/tools/agent.d.ts +27 -0
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/coerce.d.ts +8 -0
- package/dist/tools/coerce.d.ts.map +1 -0
- package/dist/tools/execute.d.ts +45 -0
- package/dist/tools/execute.d.ts.map +1 -0
- package/dist/tools/flatten.d.ts +15 -0
- package/dist/tools/flatten.d.ts.map +1 -0
- package/dist/tools/json-schema.d.ts +18 -0
- package/dist/tools/json-schema.d.ts.map +1 -0
- package/dist/tools/manifest.d.ts +13 -0
- package/dist/tools/manifest.d.ts.map +1 -0
- package/dist/tools/mcp-handler.d.ts +21 -0
- package/dist/tools/mcp-handler.d.ts.map +1 -0
- package/dist/tools/mcp-stdio.d.ts +25 -0
- package/dist/tools/mcp-stdio.d.ts.map +1 -0
- package/dist/tools/mcp.d.ts +92 -0
- package/dist/tools/mcp.d.ts.map +1 -0
- package/dist/tools/mount.d.ts +73 -0
- package/dist/tools/mount.d.ts.map +1 -0
- package/dist/tools/names.d.ts +2 -0
- package/dist/tools/names.d.ts.map +1 -0
- package/dist/tools/remote.d.ts +22 -0
- package/dist/tools/remote.d.ts.map +1 -0
- package/dist/tools/schema.d.ts +21 -0
- package/dist/tools/schema.d.ts.map +1 -0
- package/dist/tools/view-file.d.ts +57 -0
- package/dist/tools/view-file.d.ts.map +1 -0
- package/dist/tools.d.ts +12 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +837 -0
- package/package.json +147 -4
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { RuntimeContext } from '../../contract';
|
|
2
|
+
import type { MethodDef } from '../types';
|
|
3
|
+
export interface JwtPayload {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare function verifyJwt(token: string, secret: string): Promise<JwtPayload>;
|
|
7
|
+
export declare function extractToken(req: Request, cookieName?: string): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Per-scope access predicate. `endpoint.scope` selects which rule applies:
|
|
10
|
+
* - `'public'` — always pass (identity attached if present).
|
|
11
|
+
* - `'authenticated'` — any resolved identity passes.
|
|
12
|
+
* - function — custom check; gets the identity and the full context
|
|
13
|
+
* (so it can read `ctx.pathParams` for resource-scoped access). May be
|
|
14
|
+
* async — resource-scoped checks usually need a DB lookup.
|
|
15
|
+
*/
|
|
16
|
+
export type AuthRule<TIdentity> = 'public' | 'authenticated' | ((identity: Awaited<TIdentity>, ctx: RuntimeContext) => boolean | Promise<boolean>);
|
|
17
|
+
export interface AuthHookConfig<TIdentity> {
|
|
18
|
+
/** Resolve the request identity — cookie / bearer + DB lookup. */
|
|
19
|
+
resolve: (ctx: RuntimeContext) => Promise<TIdentity | null>;
|
|
20
|
+
/** Access rule per scope; `endpoint.scope` is the key. */
|
|
21
|
+
rules: Record<string, AuthRule<TIdentity>>;
|
|
22
|
+
/** Scope applied when an endpoint declares none. */
|
|
23
|
+
defaultScope?: string;
|
|
24
|
+
/** Write the resolved identity onto the context for handlers. */
|
|
25
|
+
inject?: (ctx: RuntimeContext, identity: Awaited<TIdentity> | null) => void;
|
|
26
|
+
/** Thrown when the scope needs an identity and there is none. */
|
|
27
|
+
onAnonymous?: () => never;
|
|
28
|
+
/** Thrown when an identity is present but the rule rejects it. */
|
|
29
|
+
onForbidden?: () => never;
|
|
30
|
+
}
|
|
31
|
+
export type AuthHook = (ctx: RuntimeContext, endpoint: MethodDef) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Build a `beforeHandle` hook that enforces `endpoint.scope`.
|
|
34
|
+
*
|
|
35
|
+
* Identity resolution and the scope vocabulary stay in the project; the
|
|
36
|
+
* project annotates its `rules` object with `satisfies Record<MyScope, …>` to
|
|
37
|
+
* keep scope coverage exhaustive.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createAuthHook<TIdentity>(config: AuthHookConfig<TIdentity>): AuthHook;
|
|
40
|
+
/**
|
|
41
|
+
* Bearer-token identity resolver — the MCP / API-key counterpart of the
|
|
42
|
+
* cookie session hook. Strips `Authorization: Bearer <token>` and hands the
|
|
43
|
+
* raw token (plus the request, for IP / user-agent) to the project lookup.
|
|
44
|
+
*/
|
|
45
|
+
export interface BearerResolverConfig<TIdentity> {
|
|
46
|
+
/** Resolve a raw token to identity. Return `null` for unknown / revoked. */
|
|
47
|
+
lookup: (token: string, req: Request) => Promise<TIdentity | null>;
|
|
48
|
+
}
|
|
49
|
+
export declare function createBearerResolver<TIdentity>(config: BearerResolverConfig<TIdentity>): (req: Request) => Promise<TIdentity | null>;
|
|
50
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/server/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG1C,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AASD,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CA4ClF;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU7E;AAUD;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,CAAC,SAAS,IAC1B,QAAQ,GACR,eAAe,GACf,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,cAAc,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AAEx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Age?: number;
|
|
4
|
+
path?: string;
|
|
5
|
+
domain?: string;
|
|
6
|
+
secure?: boolean;
|
|
7
|
+
httpOnly?: boolean;
|
|
8
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
9
|
+
}
|
|
10
|
+
export declare function serializeCookie(name: string, value: string, opts?: CookieOptions): string;
|
|
11
|
+
/** A cookie's name + options bundled into a typed read/set/clear handle. */
|
|
12
|
+
export interface CookieDef {
|
|
13
|
+
/** Read this cookie's value from a request (`undefined` if absent). */
|
|
14
|
+
get(req: Request): string | undefined;
|
|
15
|
+
/** Build a `Set-Cookie` header value for `value` with the baked-in options. */
|
|
16
|
+
set(value: string): string;
|
|
17
|
+
/** Build a `Set-Cookie` header value that clears the cookie. */
|
|
18
|
+
clear(): string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Bundle a cookie's name + options into a typed handle — define it once,
|
|
22
|
+
* then `get` / `set` / `clear` without repeating the config at every call site.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* const session = defineCookie({ name: 'sid', httpOnly: true, path: '/' });
|
|
26
|
+
* session.get(req); // string | undefined
|
|
27
|
+
* session.set('abc123'); // → Set-Cookie value
|
|
28
|
+
* session.clear(); // → Set-Cookie value (Max-Age=0)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function defineCookie(config: CookieOptions & {
|
|
32
|
+
name: string;
|
|
33
|
+
}): CookieDef;
|
|
34
|
+
//# sourceMappingURL=cookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../../src/server/middleware/cookies.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1E;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACtC;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,aAAkB,GACvB,MAAM,CASR;AAED,4EAA4E;AAC5E,MAAM,WAAW,SAAS;IACxB,uEAAuE;IACvE,GAAG,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC,+EAA+E;IAC/E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,gEAAgE;IAChE,KAAK,IAAI,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAahF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CorsConfig {
|
|
2
|
+
origin?: string | string[];
|
|
3
|
+
credentials?: boolean;
|
|
4
|
+
methods?: string;
|
|
5
|
+
headers?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function corsHeaders(config: CorsConfig, requestOrigin?: string | null): Record<string, string>;
|
|
8
|
+
export declare function corsPreflightResponse(config: CorsConfig, req: Request): Response;
|
|
9
|
+
//# sourceMappingURL=cors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../../src/server/middleware/cors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,UAAU,EAClB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmCxB;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,GAAG,QAAQ,CAKhF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
/** A parsed multipart request — the uploaded `file` and the validated `fields`. */
|
|
3
|
+
export interface MultipartResult {
|
|
4
|
+
file: File;
|
|
5
|
+
fields: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Parse a `multipart/form-data` request — extract the file at `fileField` and
|
|
9
|
+
* the remaining fields (each JSON-decoded, then validated by `fieldsSchema`
|
|
10
|
+
* when given). Rejects with a 400 if the file is missing or the upload exceeds
|
|
11
|
+
* `maxBytes` (default 25 MB).
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseMultipart(req: Request, fileField: string, fieldsSchema?: ZodType<unknown>, maxBytes?: number): Promise<MultipartResult>;
|
|
14
|
+
//# sourceMappingURL=multipart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/server/multipart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAGnC,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAKD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAC/B,QAAQ,SAA2B,GAClC,OAAO,CAAC,eAAe,CAAC,CAkC1B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HandlerConfig } from './types';
|
|
2
|
+
export interface NodeServerConfig extends HandlerConfig {
|
|
3
|
+
port?: number;
|
|
4
|
+
hostname?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface NodeServerHandle {
|
|
7
|
+
url: string;
|
|
8
|
+
port: number;
|
|
9
|
+
close(closeActive?: boolean): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function serveNode(config: NodeServerConfig): Promise<NodeServerHandle>;
|
|
12
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/server/node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgBnF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Token-bucket limit — at most `max` requests per `window` seconds. */
|
|
2
|
+
export interface RateLimitConfig {
|
|
3
|
+
window: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* In-memory token-bucket rate limiter. `check(key, config)` consumes a token
|
|
8
|
+
* and returns whether the request is allowed; `remaining(key, config)` reports
|
|
9
|
+
* the count without consuming. Idle keys are swept on a 60-second timer;
|
|
10
|
+
* `destroy()` stops it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createRateLimiter(): {
|
|
13
|
+
destroy: () => void;
|
|
14
|
+
check(key: string, config: RateLimitConfig): boolean;
|
|
15
|
+
remaining(key: string, config: RateLimitConfig): number;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=rate-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/server/rate-limit.ts"],"names":[],"mappings":"AAOA,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AASD;;;;;GAKG;AACH,wBAAgB,iBAAiB;;eAQlB,MAAM,UAAU,eAAe,GAAG,OAAO;mBAiBrC,MAAM,UAAU,eAAe,GAAG,MAAM;EAO1D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP request helpers — header parsing, client identification, trace ids.
|
|
3
|
+
* Pure `Request → value` functions; no framework state.
|
|
4
|
+
*/
|
|
5
|
+
/** Compact, time-sortable id — base36 timestamp + base36 random, ~14 chars. */
|
|
6
|
+
export declare function generateTraceId(): string;
|
|
7
|
+
/**
|
|
8
|
+
* Trace id for a request: a trusted inbound `x-request-id` / `x-trace-id`
|
|
9
|
+
* header (set by the edge proxy) when present and sane, else a fresh one.
|
|
10
|
+
* Shared by the router, the logger and any consumer that wants the same id.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveTraceId(req: Request): string;
|
|
13
|
+
/** Client IP from `x-forwarded-for` / `x-real-ip` (IPv4-mapped prefix stripped). */
|
|
14
|
+
export declare function extractIp(req: Request): string;
|
|
15
|
+
/** Client identity — IP + user-agent. The one place projects derive both. */
|
|
16
|
+
export declare function getClientInfo(req: Request): {
|
|
17
|
+
ipAddress?: string;
|
|
18
|
+
userAgent?: string;
|
|
19
|
+
};
|
|
20
|
+
/** Flatten a URL query string — repeated keys collapse to arrays. */
|
|
21
|
+
export declare function parseQueryParams(url: URL): Record<string, string | string[]>;
|
|
22
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/server/request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+EAA+E;AAC/E,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CASnD;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAM9C;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAKA;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAQ5E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { LifecycleHooks, MethodDef, RawRoute, ServiceDef } from './types';
|
|
2
|
+
/** A service mounted under a path prefix, carrying optional group hooks. */
|
|
3
|
+
export interface NormalizedGroup {
|
|
4
|
+
prefix: string;
|
|
5
|
+
service: ServiceDef;
|
|
6
|
+
hooks?: LifecycleHooks;
|
|
7
|
+
}
|
|
8
|
+
interface RouteEntry {
|
|
9
|
+
method: MethodDef;
|
|
10
|
+
service: ServiceDef;
|
|
11
|
+
pattern: string;
|
|
12
|
+
segments: string[];
|
|
13
|
+
groupHooks?: LifecycleHooks;
|
|
14
|
+
}
|
|
15
|
+
/** Compiled route table — HTTP method → entries (param routes sorted last). */
|
|
16
|
+
export type RouteMap = Map<string, RouteEntry[]>;
|
|
17
|
+
export interface RouteMatch {
|
|
18
|
+
method: MethodDef;
|
|
19
|
+
service: ServiceDef;
|
|
20
|
+
pathParams: Record<string, string>;
|
|
21
|
+
groupHooks?: LifecycleHooks;
|
|
22
|
+
}
|
|
23
|
+
export declare function buildRouteMap(groups: NormalizedGroup[]): RouteMap;
|
|
24
|
+
export declare function matchRoute(routeMap: RouteMap, httpMethod: string, pathname: string): RouteMatch | null;
|
|
25
|
+
/**
|
|
26
|
+
* HTTP methods that have a route matching `pathname` — for a `405` `Allow`
|
|
27
|
+
* header when the path exists but not under the requested method.
|
|
28
|
+
*/
|
|
29
|
+
export declare function allowedMethods(routeMap: RouteMap, pathname: string): string[];
|
|
30
|
+
/** Startup guard — throws when two routes collapse to the same shape. */
|
|
31
|
+
export declare function validateRoutes(routeMap: RouteMap): void;
|
|
32
|
+
export declare function matchRawRoute(rawRoutes: RawRoute[], httpMethod: string, pathname: string): {
|
|
33
|
+
route: RawRoute;
|
|
34
|
+
params: Record<string, string>;
|
|
35
|
+
} | null;
|
|
36
|
+
/**
|
|
37
|
+
* Build a `RawRoute` that serves files from `dir` under `prefix`.
|
|
38
|
+
* Rejects path traversal (`..`); 404 for a missing file.
|
|
39
|
+
*/
|
|
40
|
+
export declare function staticRoute(prefix: string, dir: string): RawRoute;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/server/router.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE/E,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB;AAED,UAAU,UAAU;IAClB,MAAM,EAAE,SAAS,CA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
|
3
|
+
*
|
|
4
|
+
* Every project repeats the same wiring: `new SocketIOServer(...)`, a
|
|
5
|
+
* `@socket.io/bun-engine` instance, `io.bind(engine)`, `engine.handler()` for
|
|
6
|
+
* the `Bun.serve` `websocket` field, and an `/socket.io/*` route delegating to
|
|
7
|
+
* `engine.handleRequest`. `createSocketIOServer` is exactly that wiring.
|
|
8
|
+
*
|
|
9
|
+
* Connection handlers, rooms and handshake auth stay in the project — they are
|
|
10
|
+
* domain logic. This helper owns only the transport plumbing: it returns the
|
|
11
|
+
* typed `io` to attach handlers to, the `websocket` handler for `Bun.serve`,
|
|
12
|
+
* and a ready-made `route` to drop into `createServer({ rawRoutes })`.
|
|
13
|
+
*/
|
|
14
|
+
import { Server as BunEngine } from '@socket.io/bun-engine';
|
|
15
|
+
import { Server as SocketIOServer } from 'socket.io';
|
|
16
|
+
import type { SocketEventMap } from '../browser/socket-io';
|
|
17
|
+
import type { RawRoute } from './types';
|
|
18
|
+
export interface SocketIOServerConfig {
|
|
19
|
+
/** CORS — the browser origin(s) allowed to open a socket. */
|
|
20
|
+
cors: {
|
|
21
|
+
origin: string | string[];
|
|
22
|
+
credentials?: boolean;
|
|
23
|
+
};
|
|
24
|
+
/** Socket.IO endpoint path. Default `/socket.io/`. */
|
|
25
|
+
path?: string;
|
|
26
|
+
/** Transports offered to clients. Default `['websocket', 'polling']`. */
|
|
27
|
+
transports?: Array<'websocket' | 'polling'>;
|
|
28
|
+
/** Heartbeat: ms without a pong before the connection is dropped. Default `20000`. */
|
|
29
|
+
pingTimeout?: number;
|
|
30
|
+
/** Heartbeat: ms between pings. Default `10000`. */
|
|
31
|
+
pingInterval?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface SocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap> {
|
|
34
|
+
/** The typed Socket.IO server — attach `io.on('connection', ...)` handlers. */
|
|
35
|
+
io: SocketIOServer<TClientEvents, TServerEvents>;
|
|
36
|
+
/** WebSocket handler for `Bun.serve({ websocket })`. */
|
|
37
|
+
websocket: ReturnType<BunEngine['handler']>['websocket'];
|
|
38
|
+
/** Ready `/socket.io/*` route — drop into `createServer({ rawRoutes })`. */
|
|
39
|
+
route: RawRoute;
|
|
40
|
+
}
|
|
41
|
+
export declare function createSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOServerConfig): SocketIOServerHandle<TServerEvents, TClientEvents>;
|
|
42
|
+
//# sourceMappingURL=socket-io.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-io.d.ts","sourceRoot":"","sources":["../../src/server/socket-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW,oBAAoB;IACnC,6DAA6D;IAC7D,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC3D,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,UAAU,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAC5C,sFAAsF;IACtF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB,CACnC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc;IAEpC,+EAA+E;IAC/E,EAAE,EAAE,cAAc,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACjD,wDAAwD;IACxD,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACzD,4EAA4E;IAC5E,KAAK,EAAE,QAAQ,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EACpC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CAAC,aAAa,EAAE,aAAa,CAAC,CAqClF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn an async generator into a Server-Sent Events `Response` — each yielded
|
|
3
|
+
* value is one JSON `data:` event, the stream ends with a `[DONE]` sentinel,
|
|
4
|
+
* and a thrown error is emitted as a final `{ error }` event.
|
|
5
|
+
*/
|
|
6
|
+
export declare function streamSSE(generator: AsyncGenerator<unknown>): Response;
|
|
7
|
+
/** Options for `parseSSE`. */
|
|
8
|
+
export interface ParseSSEOptions {
|
|
9
|
+
/** Called for a `data:` line that is not valid JSON — the alternative to throwing. */
|
|
10
|
+
onParseError?: (raw: string, error: Error) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse a Server-Sent Events `Response` body into an async generator of JSON
|
|
14
|
+
* values — the client counterpart of `streamSSE`. Stops at the `[DONE]`
|
|
15
|
+
* sentinel; the stream lock is released on every exit path.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseSSE<T>(response: Response, options?: ParseSSEOptions): AsyncGenerator<T>;
|
|
18
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/server/stream.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,QAAQ,CA2BtE;AAED,8BAA8B;AAC9B,MAAM,WAAW,eAAe;IAC9B,sFAAsF;IACtF,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACpD;AAED;;;;GAIG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAC/B,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,eAAe,GACxB,cAAc,CAAC,CAAC,CAAC,CAkCnB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A string-keyed `Map` with a background sweep that evicts expired entries.
|
|
3
|
+
* The shared scaffold behind `createCache` and `createRateLimiter` — they
|
|
4
|
+
* differ only in the expiry predicate and the sweep interval.
|
|
5
|
+
*/
|
|
6
|
+
/** Config for `createSweptMap`. */
|
|
7
|
+
export interface SweptMapOptions<V> {
|
|
8
|
+
/** Sweep interval, in milliseconds. */
|
|
9
|
+
intervalMs: number;
|
|
10
|
+
/** `true` for an entry that should be evicted — `now` is `Date.now()`. */
|
|
11
|
+
isExpired: (value: V, now: number) => boolean;
|
|
12
|
+
}
|
|
13
|
+
/** A swept map — its backing store plus a teardown. */
|
|
14
|
+
export interface SweptMap<V> {
|
|
15
|
+
/** The backing map — read and written directly by the owner. */
|
|
16
|
+
store: Map<string, V>;
|
|
17
|
+
/** Stop the sweep timer and clear the map. */
|
|
18
|
+
destroy: () => void;
|
|
19
|
+
}
|
|
20
|
+
/** Build a `Map` that evicts expired entries on a background timer. */
|
|
21
|
+
export declare function createSweptMap<V>(options: SweptMapOptions<V>): SweptMap<V>;
|
|
22
|
+
//# sourceMappingURL=swept-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swept-map.d.ts","sourceRoot":"","sources":["../../src/server/swept-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mCAAmC;AACnC,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CAC/C;AAED,uDAAuD;AACvD,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,gEAAgE;IAChE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACtB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAmB1E"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
import type { EndpointDef, HandlerContext, HttpMethod, RuntimeContext, Transport } from '../contract';
|
|
3
|
+
import type { CorsConfig } from './middleware/cors';
|
|
4
|
+
type Prop<T, K extends string> = K extends keyof T ? T[K] : undefined;
|
|
5
|
+
type InferParams<E> = Prop<E, 'params'> extends ZodType<infer P> ? P : undefined;
|
|
6
|
+
type InferInput<E> = Prop<E, 'input'> extends ZodType<infer I> ? I : undefined;
|
|
7
|
+
type InferOutput<E> = Prop<E, 'output'> extends ZodType<infer O> ? O : never;
|
|
8
|
+
export type Handlers<C extends Record<string, EndpointDef>, TCtx extends RuntimeContext = HandlerContext> = {
|
|
9
|
+
[K in keyof C]: (ctx: TCtx & {
|
|
10
|
+
params: InferParams<C[K]>;
|
|
11
|
+
input: InferInput<C[K]>;
|
|
12
|
+
}) => Prop<C[K], 'output'> extends ZodType ? Promise<InferOutput<C[K]>> | InferOutput<C[K]> : void | Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
export interface MethodDef<TParams = unknown, TInput = unknown, TOutput = unknown> {
|
|
15
|
+
method: HttpMethod;
|
|
16
|
+
path: string;
|
|
17
|
+
desc: string;
|
|
18
|
+
toolName?: string;
|
|
19
|
+
expose?: readonly Transport[];
|
|
20
|
+
scope?: string;
|
|
21
|
+
paramsSchema?: ZodType<TParams>;
|
|
22
|
+
inputSchema?: ZodType<TInput>;
|
|
23
|
+
outputSchema?: ZodType<TOutput>;
|
|
24
|
+
multipart?: string;
|
|
25
|
+
handler: (ctx: RuntimeContext) => Promise<TOutput> | TOutput;
|
|
26
|
+
}
|
|
27
|
+
export interface ServiceDef {
|
|
28
|
+
name: string;
|
|
29
|
+
prefix: string;
|
|
30
|
+
scope: string;
|
|
31
|
+
methods: Record<string, MethodDef<unknown, unknown, unknown>>;
|
|
32
|
+
}
|
|
33
|
+
export interface LifecycleHooks {
|
|
34
|
+
onRequest?: (req: Request) => undefined | Response | Promise<undefined | Response>;
|
|
35
|
+
beforeHandle?: (ctx: RuntimeContext, endpoint: MethodDef) => void | Promise<void>;
|
|
36
|
+
afterHandle?: (ctx: RuntimeContext, result: unknown, endpoint: MethodDef) => unknown | Promise<unknown>;
|
|
37
|
+
onError?: (ctx: RuntimeContext, error: unknown, endpoint?: MethodDef) => Response | Promise<Response> | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface RouteGroup {
|
|
40
|
+
pathPrefix?: string;
|
|
41
|
+
services: ServiceDef[];
|
|
42
|
+
hooks?: LifecycleHooks;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A non-contract HTTP route — for things that cannot be a clean JSON
|
|
46
|
+
* request/response contract: auth bootstrap (cookies, OAuth redirects),
|
|
47
|
+
* external webhooks (signature/IP verification), static files, socket.io.
|
|
48
|
+
*
|
|
49
|
+
* Matched in the same router as contract routes (shared CORS / `onRequest`),
|
|
50
|
+
* but the handler is raw `Request → Response` — no schema parsing and no
|
|
51
|
+
* `beforeHandle` auth gate; the route authorizes itself.
|
|
52
|
+
*/
|
|
53
|
+
/** The concrete `Bun.serve` server instance, passed through to raw handlers. */
|
|
54
|
+
export type BunServer = ReturnType<typeof Bun.serve>;
|
|
55
|
+
/** Context passed to a `RawRoute` handler alongside the raw `Request`. */
|
|
56
|
+
export interface RawRouteContext {
|
|
57
|
+
/** Matched `:param` path segments — empty object for exact / wildcard paths. */
|
|
58
|
+
params: Record<string, string>;
|
|
59
|
+
/**
|
|
60
|
+
* The `Bun.serve` instance — needed for connection upgrades (e.g. WebSocket).
|
|
61
|
+
* Absent when the handler runs via the bare `createHandler` fetch.
|
|
62
|
+
*/
|
|
63
|
+
server?: BunServer;
|
|
64
|
+
}
|
|
65
|
+
export interface RawRoute {
|
|
66
|
+
method: HttpMethod | 'ALL';
|
|
67
|
+
/** Exact path, `:param` segments, or a trailing `/*` prefix wildcard. */
|
|
68
|
+
path: string;
|
|
69
|
+
/**
|
|
70
|
+
* Raw handler — a standard `Request → Response` fetch handler plus a routing
|
|
71
|
+
* `ctx` (matched path params, the server). Errors thrown here are caught by
|
|
72
|
+
* the router and run through `hooks.onError` — same shape as contract errors.
|
|
73
|
+
*/
|
|
74
|
+
handler: (req: Request, ctx: RawRouteContext) => Response | Promise<Response>;
|
|
75
|
+
}
|
|
76
|
+
export interface StitchLogger {
|
|
77
|
+
info(msg: string, data?: Record<string, unknown>): void;
|
|
78
|
+
warn(msg: string, data?: Record<string, unknown>): void;
|
|
79
|
+
error(msg: string, data?: Record<string, unknown>): void;
|
|
80
|
+
debug(msg: string, data?: Record<string, unknown>): void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Runtime-neutral handler config — everything `createHandler` needs.
|
|
84
|
+
* No Bun globals, no Bun types. This is the portability seam.
|
|
85
|
+
*/
|
|
86
|
+
export interface HandlerConfig {
|
|
87
|
+
services?: ServiceDef[];
|
|
88
|
+
groups?: RouteGroup[];
|
|
89
|
+
rawRoutes?: RawRoute[];
|
|
90
|
+
cors?: CorsConfig;
|
|
91
|
+
hooks?: LifecycleHooks;
|
|
92
|
+
logging?: boolean | StitchLogger;
|
|
93
|
+
traceId?: (req: Request) => string;
|
|
94
|
+
}
|
|
95
|
+
type BunServeOptions = Parameters<typeof Bun.serve>[0];
|
|
96
|
+
type BunWebSocketHandlers = BunServeOptions extends {
|
|
97
|
+
websocket?: infer T;
|
|
98
|
+
} ? T : never;
|
|
99
|
+
type BunRoutes = BunServeOptions extends {
|
|
100
|
+
routes?: infer T;
|
|
101
|
+
} ? T : never;
|
|
102
|
+
type BunDevelopmentOptions = BunServeOptions extends {
|
|
103
|
+
development?: infer T;
|
|
104
|
+
} ? T : never;
|
|
105
|
+
export type ServerPassthrough = Omit<BunServeOptions, 'fetch' | 'port' | 'hostname' | 'unix' | 'routes' | 'websocket' | 'development'>;
|
|
106
|
+
/**
|
|
107
|
+
* Full config for `createServer` — extends `HandlerConfig` with Bun-specific
|
|
108
|
+
* options (`Bun.serve` routes, websocket, development, passthrough).
|
|
109
|
+
*/
|
|
110
|
+
export interface BunServerConfig extends HandlerConfig {
|
|
111
|
+
port?: number;
|
|
112
|
+
hostname?: string;
|
|
113
|
+
routes?: BunRoutes;
|
|
114
|
+
websocket?: BunWebSocketHandlers;
|
|
115
|
+
development?: BunDevelopmentOptions;
|
|
116
|
+
bun?: ServerPassthrough;
|
|
117
|
+
}
|
|
118
|
+
export type StitchServeOptions = ServerPassthrough & {
|
|
119
|
+
port: number;
|
|
120
|
+
hostname?: string;
|
|
121
|
+
routes?: BunRoutes;
|
|
122
|
+
websocket?: BunWebSocketHandlers;
|
|
123
|
+
development?: BunDevelopmentOptions;
|
|
124
|
+
fetch(req: Request): Promise<Response>;
|
|
125
|
+
};
|
|
126
|
+
export {};
|
|
127
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,cAAc,EACd,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,KAAK,IAAI,CAAC,CAAC,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IACnD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ToolSet } from 'ai';
|
|
2
|
+
import type { ServiceDef } from '../server/types';
|
|
3
|
+
import { type ToolCallHooks, type ToolLifecycle } from './execute';
|
|
4
|
+
import { type ToolExtend } from './mount';
|
|
5
|
+
export interface AgentContext {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface AgentMountConfig {
|
|
9
|
+
context?: AgentContext;
|
|
10
|
+
/** Tool-call observability hooks. */
|
|
11
|
+
hooks?: ToolCallHooks;
|
|
12
|
+
/**
|
|
13
|
+
* Auth / scope gate and result transform for every tool call — the tool-side
|
|
14
|
+
* twin of `createServer`'s `beforeHandle` / `afterHandle`. Without it an
|
|
15
|
+
* agent tool call bypasses the auth a `createServer` `beforeHandle` enforces.
|
|
16
|
+
*/
|
|
17
|
+
lifecycle?: ToolLifecycle;
|
|
18
|
+
extend?: ToolExtend;
|
|
19
|
+
/** Coerce JSON-stringified arrays/objects in tool arguments. Default: true. */
|
|
20
|
+
coerceJsonArgs?: boolean;
|
|
21
|
+
/** Flatten discriminated union inputs into a single object. Default: false. */
|
|
22
|
+
flattenUnionInput?: boolean;
|
|
23
|
+
/** Global error hint injected into every failed tool result. */
|
|
24
|
+
errorHint?: (toolName: string, errorCode: string) => string | null;
|
|
25
|
+
}
|
|
26
|
+
export declare function mountAgent(services: ServiceDef | ServiceDef[], config?: AgentMountConfig): ToolSet;
|
|
27
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/tools/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAuB,MAAM,WAAW,CAAC;AACxF,OAAO,EAAmD,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3F,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,qCAAqC;IACrC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACpE;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,UAAU,GAAG,UAAU,EAAE,EACnC,MAAM,GAAE,gBAAqB,GAC5B,OAAO,CAyCT"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Wrap array/object fields with `z.preprocess(jsonCoerce)` — tolerant of
|
|
4
|
+
* LLM double-serialization (sending `"[1,2]"` instead of `[1,2]`).
|
|
5
|
+
* Preserves optional/nullable wrappers so the emitted JSON Schema is identical.
|
|
6
|
+
*/
|
|
7
|
+
export declare function withJsonCoercion(schema: z.ZodObject<z.ZodRawShape>): z.ZodObject<z.ZodRawShape>;
|
|
8
|
+
//# sourceMappingURL=coerce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../../src/tools/coerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GACjC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAyB5B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { RuntimeContext, TransportSource } from '../contract';
|
|
2
|
+
import type { MethodDef } from '../server/types';
|
|
3
|
+
export type ToolResult = {
|
|
4
|
+
ok: true;
|
|
5
|
+
data: unknown;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
code: string;
|
|
9
|
+
details?: unknown;
|
|
10
|
+
hint?: string;
|
|
11
|
+
};
|
|
12
|
+
export interface ToolCallContext {
|
|
13
|
+
source: TransportSource;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface ToolCallHooks {
|
|
17
|
+
beforeToolCall?: (toolName: string, args: Record<string, unknown>, context: ToolCallContext) => void | Promise<void>;
|
|
18
|
+
afterToolCall?: (toolName: string, args: Record<string, unknown>, result: ToolResult, durationMs: number, context: ToolCallContext) => void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The tool-side twin of the HTTP server's `beforeHandle` / `afterHandle`. A
|
|
22
|
+
* tool call runs the same handler an HTTP request would — `ToolLifecycle` makes
|
|
23
|
+
* it run the same gate. Pass a `createAuthHook` result as `beforeHandle` here
|
|
24
|
+
* and tools are scope-guarded exactly as HTTP routes are; without it a tool
|
|
25
|
+
* call bypasses the auth a `createServer` `beforeHandle` enforces.
|
|
26
|
+
*
|
|
27
|
+
* Structurally a subset of `LifecycleHooks` — the same hook object used for
|
|
28
|
+
* `createServer({ hooks })` is assignable here.
|
|
29
|
+
*/
|
|
30
|
+
export interface ToolLifecycle {
|
|
31
|
+
/** Auth / scope gate — throw to reject the call. */
|
|
32
|
+
beforeHandle?: (ctx: RuntimeContext, endpoint: MethodDef) => void | Promise<void>;
|
|
33
|
+
/** Transform the handler result before it is returned. */
|
|
34
|
+
afterHandle?: (ctx: RuntimeContext, result: unknown, endpoint: MethodDef) => unknown | Promise<unknown>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalise any thrown value into a failed `ToolResult` — the one place an
|
|
38
|
+
* `AppError` becomes a tool error. Shared by `executeToolMethod` and both
|
|
39
|
+
* transport mounts so every tool error has one shape.
|
|
40
|
+
*/
|
|
41
|
+
export declare function toolResultFromError(err: unknown): Extract<ToolResult, {
|
|
42
|
+
ok: false;
|
|
43
|
+
}>;
|
|
44
|
+
export declare function executeToolMethod(method: MethodDef<unknown, unknown, unknown>, toolName: string, rawArgs: Record<string, unknown>, context: ToolCallContext, hooks?: ToolCallHooks, lifecycle?: ToolLifecycle): Promise<ToolResult>;
|
|
45
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,MAAM,UAAU,GAClB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC3B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CA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K,CAAC,EAAE,aAAa,EACrB,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,UAAU,CAAC,CA8FrB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Flatten a `ZodDiscriminatedUnion` into a single `ZodObject` for LLM
|
|
4
|
+
* transports that cannot represent `oneOf` (MCP).
|
|
5
|
+
*
|
|
6
|
+
* The discriminator becomes a `z.enum(...)` of all variant values; fields
|
|
7
|
+
* from each variant become optional with a `.describe()` hint indicating
|
|
8
|
+
* which variant requires them.
|
|
9
|
+
*
|
|
10
|
+
* **Lossy:** per-variant field requiredness is replaced with optional +
|
|
11
|
+
* description hint. The original union remains the validation schema in
|
|
12
|
+
* `executeToolMethod` — this is the advertised schema only.
|
|
13
|
+
*/
|
|
14
|
+
export declare function flattenDiscriminatedUnion(union: z.ZodDiscriminatedUnion): z.ZodObject<z.ZodRawShape>;
|
|
15
|
+
//# sourceMappingURL=flatten.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/tools/flatten.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,CAAC,CAAC,qBAAqB,GAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAkD5B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single Zod → JSON Schema conversion point for the tools layer.
|
|
3
|
+
*
|
|
4
|
+
* MCP and agent both ultimately turn a contract schema into JSON Schema. This
|
|
5
|
+
* is the one place stitchkit converts — with the options that match what the
|
|
6
|
+
* transport SDKs emit, so a build-time validity probe tests the same thing the
|
|
7
|
+
* SDK will later emit, not a divergent code path.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
/** Conversion direction — `input` for tool arguments, `output` for results. */
|
|
11
|
+
export type JsonSchemaIo = 'input' | 'output';
|
|
12
|
+
/**
|
|
13
|
+
* Convert a Zod schema to JSON Schema. Throws on a construct JSON Schema cannot
|
|
14
|
+
* represent (`z.date()`, `z.bigint()`, `z.map()`, …). The caller decides what
|
|
15
|
+
* to do with that failure — see `onIncompatibleSchema`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo): Record<string, unknown>;
|
|
18
|
+
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/tools/json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzF"}
|