@caplets/core 0.16.0 → 0.18.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.
@@ -0,0 +1,22 @@
1
+ export type RemoteAuthFlow = {
2
+ id: string;
3
+ server: string;
4
+ authorizationUrl: string;
5
+ createdAt: number;
6
+ complete(callbackUrl: string): Promise<void>;
7
+ };
8
+ export type RemoteAuthFlowStoreOptions = {
9
+ ttlMs?: number;
10
+ now?: () => number;
11
+ };
12
+ export declare class RemoteAuthFlowStore {
13
+ private readonly options;
14
+ private readonly flows;
15
+ constructor(options?: RemoteAuthFlowStoreOptions);
16
+ create(flow: Omit<RemoteAuthFlow, "id" | "createdAt">, id?: string): RemoteAuthFlow;
17
+ get(id: string): RemoteAuthFlow | undefined;
18
+ delete(id: string): void;
19
+ private pruneExpired;
20
+ private isExpired;
21
+ private now;
22
+ }
@@ -0,0 +1,11 @@
1
+ import type { RemoteCliCommand, RemoteCliRequest } from "./types";
2
+ export type RemoteControlClientOptions = {
3
+ baseUrl: URL;
4
+ requestInit: RequestInit;
5
+ fetch?: typeof fetch;
6
+ };
7
+ export declare class RemoteControlClient {
8
+ #private;
9
+ constructor(options: RemoteControlClientOptions);
10
+ request(command: RemoteCliCommand, args: RemoteCliRequest["arguments"]): Promise<unknown>;
11
+ }
@@ -0,0 +1,9 @@
1
+ import { type CapletsEngineOptions } from "../engine";
2
+ import type { RemoteAuthFlowStore } from "./auth-flow";
3
+ import type { RemoteCliRequest, RemoteCliResponse } from "./types";
4
+ export type RemoteControlDispatchContext = CapletsEngineOptions & {
5
+ projectCapletsRoot: string;
6
+ authFlowStore?: RemoteAuthFlowStore;
7
+ controlCallbackBaseUrl?: string;
8
+ };
9
+ export declare function dispatchRemoteCliRequest(request: RemoteCliRequest, context: RemoteControlDispatchContext): Promise<RemoteCliResponse>;
@@ -0,0 +1,17 @@
1
+ import type { CapletsErrorCode } from "../errors";
2
+ export type RemoteCliCommand = "list" | "get_caplet" | "check_backend" | "list_tools" | "search_tools" | "get_tool" | "call_tool" | "list_resources" | "search_resources" | "list_resource_templates" | "read_resource" | "list_prompts" | "search_prompts" | "get_prompt" | "complete" | "init" | "add" | "install" | "complete_cli" | "auth_login_start" | "auth_login_complete" | "auth_logout" | "auth_list";
3
+ export type RemoteCliRequest = {
4
+ command: RemoteCliCommand;
5
+ arguments: Record<string, unknown>;
6
+ };
7
+ export type RemoteCliResponse = {
8
+ ok: true;
9
+ result: unknown;
10
+ } | {
11
+ ok: false;
12
+ error: {
13
+ code: CapletsErrorCode;
14
+ message: string;
15
+ nextAction?: string;
16
+ };
17
+ };
@@ -1,12 +1,23 @@
1
1
  import { Hono } from "hono";
2
2
  import { CapletsEngine, type CapletsEngineOptions } from "../engine";
3
+ import { type RemoteControlDispatchContext } from "../remote-control/dispatch";
4
+ import { RemoteAuthFlowStore } from "../remote-control/auth-flow";
3
5
  import type { HttpServeOptions } from "./options";
4
6
  type HttpServeIo = {
5
7
  writeErr?: (value: string) => void;
8
+ control?: Omit<RemoteControlDispatchContext, "writeErr">;
9
+ authFlowStore?: RemoteAuthFlowStore;
6
10
  };
7
11
  export type CapletsHttpApp = Hono & {
8
12
  closeCapletsSessions: () => Promise<void>;
9
13
  };
10
14
  export declare function createHttpServeApp(options: HttpServeOptions, engine: CapletsEngine, io?: HttpServeIo): CapletsHttpApp;
11
15
  export declare function serveHttp(options: HttpServeOptions, engineOptions?: CapletsEngineOptions, writeErr?: (value: string) => void): Promise<void>;
16
+ export declare function routePath(base: string, path: string): string;
17
+ export declare function servicePaths(base: string): {
18
+ base: string;
19
+ mcp: string;
20
+ control: string;
21
+ health: string;
22
+ };
12
23
  export {};
@@ -7,6 +7,7 @@ export type RawServeOptions = {
7
7
  user?: string;
8
8
  password?: string;
9
9
  allowUnauthenticatedHttp?: boolean;
10
+ trustProxy?: boolean;
10
11
  };
11
12
  export type StdioServeOptions = {
12
13
  transport: "stdio";
@@ -19,6 +20,7 @@ export type HttpServeOptions = {
19
20
  auth: HttpBasicAuthOptions;
20
21
  warnUnauthenticatedNetwork: boolean;
21
22
  loopback: boolean;
23
+ trustProxy: boolean;
22
24
  };
23
25
  export type HttpBasicAuthOptions = {
24
26
  enabled: false;
@@ -29,6 +31,6 @@ export type HttpBasicAuthOptions = {
29
31
  password: string;
30
32
  };
31
33
  export type ServeOptions = StdioServeOptions | HttpServeOptions;
32
- export type ServeEnv = Partial<Record<"CAPLETS_SERVER_USER" | "CAPLETS_SERVER_PASSWORD", string>>;
34
+ export type ServeEnv = Partial<Record<"CAPLETS_SERVER_URL" | "CAPLETS_SERVER_USER" | "CAPLETS_SERVER_PASSWORD", string>>;
33
35
  export declare function resolveServeOptions(raw: RawServeOptions, env?: ServeEnv): ServeOptions;
34
36
  export declare function isLoopbackHost(host: string): boolean;
@@ -0,0 +1,41 @@
1
+ export type CapletsMode = "auto" | "local" | "remote";
2
+ export type CapletsServerEnv = Partial<Record<"CAPLETS_MODE" | "CAPLETS_SERVER_URL" | "CAPLETS_SERVER_USER" | "CAPLETS_SERVER_PASSWORD", string>>;
3
+ export type CapletsModeInput = {
4
+ mode?: string;
5
+ serverUrl?: string;
6
+ };
7
+ export type CapletsServerInput = {
8
+ url?: string;
9
+ user?: string;
10
+ password?: string;
11
+ fetch?: typeof fetch;
12
+ };
13
+ export type CapletsServerAuth = {
14
+ enabled: false;
15
+ user: string;
16
+ } | {
17
+ enabled: true;
18
+ user: string;
19
+ password: string;
20
+ };
21
+ export type ResolvedCapletsServer = {
22
+ baseUrl: URL;
23
+ mcpUrl: URL;
24
+ controlUrl: URL;
25
+ healthUrl: URL;
26
+ auth: CapletsServerAuth;
27
+ requestInit: RequestInit;
28
+ fetch?: typeof fetch;
29
+ };
30
+ export declare function resolveCapletsMode(input?: CapletsModeInput, env?: CapletsServerEnv): {
31
+ mode: "local";
32
+ } | {
33
+ mode: "remote";
34
+ };
35
+ export declare function resolveCapletsServer(input?: CapletsServerInput, env?: CapletsServerEnv): ResolvedCapletsServer;
36
+ export declare function mcpUrlForBase(baseUrl: URL): URL;
37
+ export declare function controlUrlForBase(baseUrl: URL): URL;
38
+ export declare function healthUrlForBase(baseUrl: URL): URL;
39
+ export declare function appendBasePath(baseUrl: URL, path: string): URL;
40
+ export declare function parseServerBaseUrl(value: string): URL;
41
+ export declare function isLoopbackHost(host: string): boolean;
package/dist/tools.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { z } from "zod";
2
1
  import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
2
  import type { CapletSetManager } from "./caplet-sets";
4
3
  import type { CapletConfig } from "./config";
@@ -8,24 +7,10 @@ import type { GraphQLManager } from "./graphql";
8
7
  import type { HttpActionManager } from "./http-actions";
9
8
  import type { OpenApiManager } from "./openapi";
10
9
  import type { ServerRegistry } from "./registry";
11
- export declare const generatedToolInputSchema: z.ZodObject<{
12
- operation: z.ZodEnum<{
13
- get_caplet: "get_caplet";
14
- check_backend: "check_backend";
15
- list_tools: "list_tools";
16
- search_tools: "search_tools";
17
- get_tool: "get_tool";
18
- call_tool: "call_tool";
19
- }>;
20
- query: z.ZodOptional<z.ZodString>;
21
- limit: z.ZodOptional<z.ZodNumber>;
22
- tool: z.ZodOptional<z.ZodString>;
23
- arguments: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
24
- fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
25
- }, z.core.$strict>;
26
- export type GeneratedServerToolRequest = z.infer<typeof generatedToolInputSchema>;
10
+ export { generatedToolInputSchema } from "./generated-tool-input-schema";
11
+ export type GeneratedServerToolRequest = RequiredOperationRequest;
27
12
  export declare function handleServerTool(server: CapletConfig, request: unknown, registry: ServerRegistry, downstream: DownstreamManager, openapi?: OpenApiManager, graphql?: GraphQLManager, http?: HttpActionManager, cli?: CliToolsManager, caplets?: CapletSetManager): Promise<any>;
28
- export declare function validateOperationRequest(request: unknown, maxSearchLimit: number): RequiredOperationRequest;
13
+ export declare function validateOperationRequest(request: unknown, maxSearchLimit: number, backend?: string): RequiredOperationRequest;
29
14
  type RequiredOperationRequest = {
30
15
  operation: "get_caplet" | "check_backend";
31
16
  } | {
@@ -43,6 +28,33 @@ type RequiredOperationRequest = {
43
28
  tool: string;
44
29
  arguments: Record<string, unknown>;
45
30
  fields?: string[];
31
+ } | {
32
+ operation: "list_resources" | "list_resource_templates" | "list_prompts";
33
+ limit?: number;
34
+ } | {
35
+ operation: "search_resources" | "search_prompts";
36
+ query: string;
37
+ limit?: number;
38
+ } | {
39
+ operation: "read_resource";
40
+ uri: string;
41
+ } | {
42
+ operation: "get_prompt";
43
+ prompt: string;
44
+ arguments: Record<string, unknown>;
45
+ } | {
46
+ operation: "complete";
47
+ ref: {
48
+ type: "prompt";
49
+ name: string;
50
+ } | {
51
+ type: "resourceTemplate";
52
+ uri: string;
53
+ };
54
+ argument: {
55
+ name: string;
56
+ value: string;
57
+ };
46
58
  };
47
59
  export type CapletArtifact = {
48
60
  kind: "screenshot" | "snapshot" | "console-log" | "network-log" | "file";
@@ -55,13 +67,19 @@ export type CapletResultMetadata = {
55
67
  backend: string;
56
68
  operation: RequiredOperationRequest["operation"];
57
69
  tool?: string;
70
+ uri?: string;
71
+ prompt?: string;
58
72
  status: "ok" | "error";
59
73
  elapsedMs?: number;
60
74
  artifacts?: CapletArtifact[];
61
75
  };
62
- export declare function metadataFor(server: CapletConfig, operation: RequiredOperationRequest["operation"], tool?: string, startedAt?: number): CapletResultMetadata;
76
+ export declare function metadataFor(server: CapletConfig, operation: RequiredOperationRequest["operation"], target?: string | {
77
+ tool?: string;
78
+ uri?: string;
79
+ prompt?: string;
80
+ }, startedAt?: number): CapletResultMetadata;
81
+ export declare function annotateMcpResult<T extends object>(result: T, metadata: CapletResultMetadata): T;
63
82
  export declare function jsonResult(value: unknown, metadata?: CapletResultMetadata): CallToolResult;
64
83
  export declare function annotateCallToolResult<T extends object>(result: T, metadata: CapletResultMetadata): T & CallToolResult;
65
84
  export declare function projectCallToolResult<T extends object>(result: T, outputSchema: unknown, fields: string[]): T & CallToolResult;
66
85
  export declare function extractArtifacts(result: unknown): CapletArtifact[];
67
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caplets/core",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Core runtime library for Caplets progressive disclosure gateways.",
5
5
  "keywords": [
6
6
  "caplets",