@caplets/core 0.18.9 → 0.20.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/attach/options.d.ts +10 -0
- package/dist/attach/server.d.ts +5 -0
- package/dist/caplet-files-bundle.d.ts +430 -0
- package/dist/caplet-files.d.ts +3 -266
- package/dist/caplet-source/bundle.d.ts +7 -0
- package/dist/caplet-source/filesystem.d.ts +7 -0
- package/dist/caplet-source/filesystem.js +2 -0
- package/dist/caplet-source/index.d.ts +4 -0
- package/dist/caplet-source/parse.d.ts +35 -0
- package/dist/caplet-source/types.d.ts +9 -0
- package/dist/caplet-source.js +7011 -0
- package/dist/cli/auth.d.ts +40 -2
- package/dist/cli/cloud-add.d.ts +8 -0
- package/dist/cli/code-mode.d.ts +16 -0
- package/dist/cli/commands.d.ts +8 -1
- package/dist/cli/doctor.d.ts +21 -0
- package/dist/cli/setup-caplet.d.ts +12 -0
- package/dist/cli/setup.d.ts +11 -0
- package/dist/cli-tools.d.ts +1 -1
- package/dist/cli.d.ts +8 -1
- package/dist/cloud/apply.d.ts +36 -0
- package/dist/cloud/client.d.ts +30 -0
- package/dist/cloud/presence.d.ts +29 -0
- package/dist/cloud/project-root.d.ts +2 -0
- package/dist/cloud/runtime-adapter.d.ts +23 -0
- package/dist/cloud/runtime-http.d.ts +6 -0
- package/dist/cloud/sync.d.ts +10 -0
- package/dist/cloud-auth/client.d.ts +57 -0
- package/dist/cloud-auth/errors.d.ts +11 -0
- package/dist/cloud-auth/open-url.d.ts +7 -0
- package/dist/cloud-auth/store.d.ts +35 -0
- package/dist/cloud-auth/types.d.ts +67 -0
- package/dist/code-mode/api.d.ts +32 -0
- package/dist/code-mode/declarations.d.ts +5 -0
- package/dist/code-mode/diagnostics.d.ts +8 -0
- package/dist/code-mode/index.d.ts +4 -0
- package/dist/code-mode/logs.d.ts +21 -0
- package/dist/code-mode/runner.d.ts +15 -0
- package/dist/code-mode/runtime-api.generated.d.ts +1 -0
- package/dist/code-mode/sandbox.d.ts +28 -0
- package/dist/code-mode/static-analysis.d.ts +2 -0
- package/dist/code-mode/tool.d.ts +11 -0
- package/dist/code-mode/types.d.ts +120 -0
- package/dist/code-mode.js +147855 -0
- package/dist/{completion-RqzHpHRY.js → completion-CbazRAiL.js} +20 -1
- package/dist/config/paths.d.ts +2 -0
- package/dist/config-runtime.d.ts +183 -0
- package/dist/config-runtime.js +421 -0
- package/dist/config.d.ts +76 -9
- package/dist/downstream.d.ts +20 -2
- package/dist/engine.d.ts +20 -0
- package/dist/exposure/direct-names.d.ts +9 -0
- package/dist/exposure/discovery.d.ts +75 -0
- package/dist/exposure/policy.d.ts +8 -0
- package/dist/filesystem-Kkg32TOJ.js +66 -0
- package/dist/generated-tool-input-schema.d.ts +89 -59
- package/dist/generated-tool-input-schema.js +172 -1
- package/dist/graphql.d.ts +1 -1
- package/dist/http-actions.d.ts +1 -1
- package/dist/index.d.ts +48 -0
- package/dist/index.js +4176 -501
- package/dist/native/options.d.ts +22 -3
- package/dist/native/remote.d.ts +2 -1
- package/dist/native/service.d.ts +13 -3
- package/dist/native/tools.d.ts +2 -0
- package/dist/native.d.ts +1 -1
- package/dist/native.js +3 -431
- package/dist/observed-output-shapes/extract.d.ts +5 -0
- package/dist/observed-output-shapes/file-store.d.ts +17 -0
- package/dist/observed-output-shapes/index.d.ts +7 -0
- package/dist/observed-output-shapes/key.d.ts +14 -0
- package/dist/observed-output-shapes/merge.d.ts +2 -0
- package/dist/observed-output-shapes/pure.d.ts +5 -0
- package/dist/observed-output-shapes/pure.js +241 -0
- package/dist/observed-output-shapes/schema.d.ts +1 -0
- package/dist/observed-output-shapes/types.d.ts +84 -0
- package/dist/observed-output-shapes/typescript.d.ts +7 -0
- package/dist/observed-output-shapes-uzAMQPhg.js +485 -0
- package/dist/observed-output-shapes.js +2 -0
- package/dist/openapi.d.ts +1 -1
- package/dist/project-binding/attach.d.ts +46 -0
- package/dist/project-binding/errors.d.ts +17 -0
- package/dist/project-binding/gitignore.d.ts +5 -0
- package/dist/project-binding/index.d.ts +2 -0
- package/dist/project-binding/mutagen.d.ts +65 -0
- package/dist/project-binding/routes.d.ts +9 -0
- package/dist/project-binding/session.d.ts +82 -0
- package/dist/project-binding/sync-filter.d.ts +19 -0
- package/dist/project-binding/sync-size.d.ts +27 -0
- package/dist/project-binding/transport.d.ts +21 -0
- package/dist/project-binding/types.d.ts +31 -0
- package/dist/project-binding/workspaces.d.ts +60 -0
- package/dist/project-binding.js +22 -0
- package/dist/redaction.d.ts +14 -0
- package/dist/redaction.js +30 -0
- package/dist/registry.d.ts +4 -0
- package/dist/remote/options.d.ts +44 -0
- package/dist/remote/selection.d.ts +26 -0
- package/dist/remote-control/types.d.ts +1 -1
- package/dist/runtime-plan/features.d.ts +7 -0
- package/dist/runtime-plan/index.d.ts +4 -0
- package/dist/runtime-plan/planner.d.ts +5 -0
- package/dist/runtime-plan/resources.d.ts +13 -0
- package/dist/runtime-plan/types.d.ts +82 -0
- package/dist/runtime-plan.js +281 -0
- package/dist/schemas-1HZ0kFpx.js +4270 -0
- package/dist/{generated-tool-input-schema--kVuUNc5.js → schemas-BZ6BBrh7.js} +1 -161
- package/dist/serve/daemon/config.d.ts +8 -0
- package/dist/serve/daemon/index.d.ts +16 -0
- package/dist/serve/daemon/paths.d.ts +3 -0
- package/dist/serve/daemon/platform-darwin.d.ts +2 -0
- package/dist/serve/daemon/platform-linux.d.ts +2 -0
- package/dist/serve/daemon/platform-windows.d.ts +2 -0
- package/dist/serve/daemon/platform.d.ts +9 -0
- package/dist/serve/daemon/process.d.ts +5 -0
- package/dist/serve/daemon/types.d.ts +86 -0
- package/dist/serve/http.d.ts +8 -0
- package/dist/serve/index.d.ts +5 -1
- package/dist/serve/native-session.d.ts +19 -0
- package/dist/serve/options.d.ts +1 -0
- package/dist/serve/session.d.ts +15 -3
- package/dist/server/options.d.ts +1 -1
- package/dist/{options-DnOUjft1.js → service-D0MwLNyb.js} +38003 -27618
- package/dist/setup/hash.d.ts +3 -0
- package/dist/setup/local-store.d.ts +34 -0
- package/dist/setup/runner.d.ts +40 -0
- package/dist/setup/types.d.ts +52 -0
- package/dist/stable-json.d.ts +3 -0
- package/dist/stable-json.js +26 -0
- package/dist/tools.d.ts +38 -12
- package/dist/validation-CdqbI2zN.js +174 -0
- package/package.json +48 -6
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type SetupApproval, type SetupAttempt, type SetupTargetKind } from "./types";
|
|
2
|
+
type SetupApprovalInput = Omit<SetupApproval, "projectFingerprint"> & {
|
|
3
|
+
projectFingerprint?: string | undefined;
|
|
4
|
+
};
|
|
5
|
+
export type LocalSetupStoreOptions = {
|
|
6
|
+
baseDir?: string;
|
|
7
|
+
now?: () => Date;
|
|
8
|
+
maxAttempts?: number;
|
|
9
|
+
retentionDays?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare class LocalSetupStore {
|
|
12
|
+
private readonly root;
|
|
13
|
+
private readonly now;
|
|
14
|
+
private readonly maxAttempts;
|
|
15
|
+
private readonly retentionDays;
|
|
16
|
+
constructor(options?: LocalSetupStoreOptions);
|
|
17
|
+
getApproval(capletId: string, contentHash: string, targetKind: SetupTargetKind): Promise<SetupApproval | undefined>;
|
|
18
|
+
getApproval(projectFingerprint: string, capletId: string, contentHash: string, targetKind: SetupTargetKind): Promise<SetupApproval | undefined>;
|
|
19
|
+
approve(input: SetupApprovalInput): Promise<SetupApproval>;
|
|
20
|
+
recordAttempt(attempt: SetupAttempt): Promise<void>;
|
|
21
|
+
listAttempts(capletId: string): Promise<SetupAttempt[]>;
|
|
22
|
+
listAttempts(projectFingerprint: string, capletId: string): Promise<SetupAttempt[]>;
|
|
23
|
+
retention(): {
|
|
24
|
+
maxAttempts: number;
|
|
25
|
+
days: number;
|
|
26
|
+
};
|
|
27
|
+
private approvals;
|
|
28
|
+
private prunedAttempts;
|
|
29
|
+
private approvalsPath;
|
|
30
|
+
private attempts;
|
|
31
|
+
private attemptsDir;
|
|
32
|
+
private attemptsPath;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CapletSetupConfig } from "../config";
|
|
2
|
+
import type { RuntimeFeature } from "../config-runtime";
|
|
3
|
+
import type { LocalSetupStore } from "./local-store";
|
|
4
|
+
import { type SetupActor, type SetupAttempt, type SetupTargetKind } from "./types";
|
|
5
|
+
export type SpawnResult = {
|
|
6
|
+
exitCode?: number | undefined;
|
|
7
|
+
signal?: string | undefined;
|
|
8
|
+
stdout: string;
|
|
9
|
+
stderr: string;
|
|
10
|
+
durationMs: number;
|
|
11
|
+
};
|
|
12
|
+
export type SetupSpawn = (command: string, args: string[], options: {
|
|
13
|
+
cwd?: string | undefined;
|
|
14
|
+
env: NodeJS.ProcessEnv;
|
|
15
|
+
timeoutMs: number;
|
|
16
|
+
maxOutputBytes: number;
|
|
17
|
+
}) => Promise<SpawnResult>;
|
|
18
|
+
export type RunCapletSetupOptions = {
|
|
19
|
+
projectFingerprint?: string;
|
|
20
|
+
capletId: string;
|
|
21
|
+
contentHash: string;
|
|
22
|
+
setupHash?: string | undefined;
|
|
23
|
+
targetKind: SetupTargetKind;
|
|
24
|
+
runtimeFeatures?: RuntimeFeature[] | undefined;
|
|
25
|
+
projectBindingRequired?: boolean | undefined;
|
|
26
|
+
projectWorkspacePath?: string | undefined;
|
|
27
|
+
setup: CapletSetupConfig;
|
|
28
|
+
actor: SetupActor;
|
|
29
|
+
approved: boolean;
|
|
30
|
+
store: Pick<LocalSetupStore, "recordAttempt" | "retention">;
|
|
31
|
+
spawn?: SetupSpawn;
|
|
32
|
+
now?: () => Date;
|
|
33
|
+
};
|
|
34
|
+
export declare function runCapletSetup(options: RunCapletSetupOptions): Promise<SetupAttempt[]>;
|
|
35
|
+
export declare function spawnCommand(command: string, args: string[], options: {
|
|
36
|
+
cwd?: string | undefined;
|
|
37
|
+
env: NodeJS.ProcessEnv;
|
|
38
|
+
timeoutMs: number;
|
|
39
|
+
maxOutputBytes: number;
|
|
40
|
+
}): Promise<SpawnResult>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CapletSetupCommandConfig, CapletSetupConfig } from "../config";
|
|
2
|
+
import type { RuntimeFeature } from "../config-runtime";
|
|
3
|
+
export declare const setupTargetKinds: readonly ["local_host", "remote_host", "hosted_sandbox"];
|
|
4
|
+
export type SetupTargetKind = (typeof setupTargetKinds)[number];
|
|
5
|
+
export type SetupActor = "cli-interactive" | "cli-yes" | "ui" | "automation";
|
|
6
|
+
export type SetupAttemptStatus = "running" | "succeeded" | "failed";
|
|
7
|
+
export type SetupApproval = {
|
|
8
|
+
projectFingerprint: string;
|
|
9
|
+
capletId: string;
|
|
10
|
+
contentHash: string;
|
|
11
|
+
targetKind: SetupTargetKind;
|
|
12
|
+
approvedAt: string;
|
|
13
|
+
actor: SetupActor;
|
|
14
|
+
};
|
|
15
|
+
export type SetupAttempt = {
|
|
16
|
+
attemptId: string;
|
|
17
|
+
projectFingerprint: string;
|
|
18
|
+
capletId: string;
|
|
19
|
+
contentHash: string;
|
|
20
|
+
setupHash?: string | undefined;
|
|
21
|
+
targetKind: SetupTargetKind;
|
|
22
|
+
runtimeFeatures?: RuntimeFeature[] | undefined;
|
|
23
|
+
actor: SetupActor;
|
|
24
|
+
status: SetupAttemptStatus;
|
|
25
|
+
phase: "commands" | "verify";
|
|
26
|
+
commandLabel: string;
|
|
27
|
+
argv: string[];
|
|
28
|
+
exitCode?: number | undefined;
|
|
29
|
+
signal?: string | undefined;
|
|
30
|
+
durationMs: number;
|
|
31
|
+
startedAt: string;
|
|
32
|
+
finishedAt: string;
|
|
33
|
+
stdout: string;
|
|
34
|
+
stderr: string;
|
|
35
|
+
redacted: boolean;
|
|
36
|
+
retention: {
|
|
37
|
+
maxAttempts: number;
|
|
38
|
+
days: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type SetupPlan = {
|
|
42
|
+
projectFingerprint: string;
|
|
43
|
+
capletId: string;
|
|
44
|
+
name: string;
|
|
45
|
+
contentHash: string;
|
|
46
|
+
targetKind: SetupTargetKind;
|
|
47
|
+
setup: CapletSetupConfig;
|
|
48
|
+
approved: boolean;
|
|
49
|
+
commands: CapletSetupCommandConfig[];
|
|
50
|
+
verify: CapletSetupCommandConfig[];
|
|
51
|
+
};
|
|
52
|
+
export declare function isSetupTargetKind(value: string): value is SetupTargetKind;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/stable-json.ts
|
|
2
|
+
function stableJsonValue(value) {
|
|
3
|
+
if (Array.isArray(value)) return value.map((item) => stableJsonValue(item));
|
|
4
|
+
if (isPlainObject(value)) {
|
|
5
|
+
const sorted = {};
|
|
6
|
+
for (const key of Object.keys(value).sort()) {
|
|
7
|
+
const item = value[key];
|
|
8
|
+
if (item !== void 0) sorted[key] = stableJsonValue(item);
|
|
9
|
+
}
|
|
10
|
+
return sorted;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function stableJsonStringify(value) {
|
|
15
|
+
return JSON.stringify(stableJsonValue(value));
|
|
16
|
+
}
|
|
17
|
+
async function stableJsonSha256Hex(value) {
|
|
18
|
+
const bytes = new TextEncoder().encode(stableJsonStringify(value));
|
|
19
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
20
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
21
|
+
}
|
|
22
|
+
function isPlainObject(value) {
|
|
23
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { stableJsonSha256Hex, stableJsonStringify, stableJsonValue };
|
package/dist/tools.d.ts
CHANGED
|
@@ -6,43 +6,54 @@ import type { DownstreamManager } from "./downstream";
|
|
|
6
6
|
import type { GraphQLManager } from "./graphql";
|
|
7
7
|
import type { HttpActionManager } from "./http-actions";
|
|
8
8
|
import type { OpenApiManager } from "./openapi";
|
|
9
|
+
import { type ObservedOutputShapeStore } from "./observed-output-shapes";
|
|
9
10
|
import type { ServerRegistry } from "./registry";
|
|
10
11
|
import { type ResultMarkdownContext } from "./result-content";
|
|
11
12
|
export { generatedToolInputSchema } from "./generated-tool-input-schema";
|
|
12
13
|
export type GeneratedServerToolRequest = RequiredOperationRequest;
|
|
13
|
-
export
|
|
14
|
-
|
|
14
|
+
export type HandleServerToolOptions = {
|
|
15
|
+
observedOutputShapeStore?: ObservedOutputShapeStore | undefined;
|
|
16
|
+
observedOutputShapeScope?: "local" | "self_hosted" | "cloud" | undefined;
|
|
17
|
+
workspaceId?: string | undefined;
|
|
18
|
+
projectFingerprint?: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
export declare function handleServerTool(server: CapletConfig, request: unknown, registry: ServerRegistry, downstream: DownstreamManager, openapi?: OpenApiManager, graphql?: GraphQLManager, http?: HttpActionManager, cli?: CliToolsManager, caplets?: CapletSetManager, options?: HandleServerToolOptions): Promise<any>;
|
|
21
|
+
export declare function validateOperationRequest(request: unknown, _maxSearchLimit: number, backend?: string): RequiredOperationRequest;
|
|
15
22
|
type RequiredOperationRequest = {
|
|
16
|
-
operation: "inspect" | "
|
|
23
|
+
operation: "inspect" | "check";
|
|
17
24
|
} | {
|
|
18
|
-
operation: "
|
|
25
|
+
operation: "tools";
|
|
19
26
|
limit?: number;
|
|
27
|
+
cursor?: string;
|
|
20
28
|
} | {
|
|
21
29
|
operation: "search_tools";
|
|
22
30
|
query: string;
|
|
23
31
|
limit?: number;
|
|
32
|
+
cursor?: string;
|
|
24
33
|
} | {
|
|
25
|
-
operation: "
|
|
26
|
-
|
|
34
|
+
operation: "describe_tool";
|
|
35
|
+
name: string;
|
|
27
36
|
} | {
|
|
28
37
|
operation: "call_tool";
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
name: string;
|
|
39
|
+
args: Record<string, unknown>;
|
|
31
40
|
fields?: string[];
|
|
32
41
|
} | {
|
|
33
|
-
operation: "
|
|
42
|
+
operation: "resources" | "resource_templates" | "prompts";
|
|
34
43
|
limit?: number;
|
|
44
|
+
cursor?: string;
|
|
35
45
|
} | {
|
|
36
46
|
operation: "search_resources" | "search_prompts";
|
|
37
47
|
query: string;
|
|
38
48
|
limit?: number;
|
|
49
|
+
cursor?: string;
|
|
39
50
|
} | {
|
|
40
51
|
operation: "read_resource";
|
|
41
52
|
uri: string;
|
|
42
53
|
} | {
|
|
43
54
|
operation: "get_prompt";
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
name: string;
|
|
56
|
+
args: Record<string, unknown>;
|
|
46
57
|
} | {
|
|
47
58
|
operation: "complete";
|
|
48
59
|
ref: {
|
|
@@ -62,6 +73,20 @@ export type CapletArtifact = {
|
|
|
62
73
|
displayPath: string;
|
|
63
74
|
pathResolution: "absolute" | "relative-to-mcp-server";
|
|
64
75
|
};
|
|
76
|
+
export type CapletExecutionMetadata = {
|
|
77
|
+
kind: "local" | "remote" | "cloud" | "local-fallback";
|
|
78
|
+
runtimeId?: string | undefined;
|
|
79
|
+
sandboxId?: string | undefined;
|
|
80
|
+
presenceId?: string | undefined;
|
|
81
|
+
fallback?: boolean | undefined;
|
|
82
|
+
fallbackReason?: "hosted_runtime_limit_reached" | "hosted_runtime_degraded" | undefined;
|
|
83
|
+
project?: {
|
|
84
|
+
bound: boolean;
|
|
85
|
+
fingerprint?: string | undefined;
|
|
86
|
+
syncReceiptId?: string | undefined;
|
|
87
|
+
applyReceiptId?: string | undefined;
|
|
88
|
+
} | undefined;
|
|
89
|
+
};
|
|
65
90
|
export type CapletResultMetadata = {
|
|
66
91
|
id: string;
|
|
67
92
|
name: string;
|
|
@@ -73,12 +98,13 @@ export type CapletResultMetadata = {
|
|
|
73
98
|
status: "ok" | "error";
|
|
74
99
|
elapsedMs?: number;
|
|
75
100
|
artifacts?: CapletArtifact[];
|
|
101
|
+
execution?: CapletExecutionMetadata | undefined;
|
|
76
102
|
};
|
|
77
103
|
export declare function metadataFor(server: CapletConfig, operation: RequiredOperationRequest["operation"], target?: string | {
|
|
78
104
|
tool?: string;
|
|
79
105
|
uri?: string;
|
|
80
106
|
prompt?: string;
|
|
81
|
-
}, startedAt?: number): CapletResultMetadata;
|
|
107
|
+
}, startedAt?: number, execution?: CapletExecutionMetadata): CapletResultMetadata;
|
|
82
108
|
export declare function annotateMcpResult<T extends object>(result: T, metadata: CapletResultMetadata): T;
|
|
83
109
|
export declare function jsonResult(value: unknown, metadata?: CapletResultMetadata): CallToolResult;
|
|
84
110
|
export declare function annotateCallToolResult<T extends object>(result: T, metadata: CapletResultMetadata): T & CallToolResult;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
//#region src/redaction.ts
|
|
2
|
+
const SECRET_KEY_PATTERN = /(token|secret|authorization|auth|api[-_]?key|password|credential|clientsecret|client_secret|code|refresh)/iu;
|
|
3
|
+
const SECRET_TEXT_PATTERNS = [
|
|
4
|
+
/(Authorization:\s*Bearer\s+)[0-9A-Za-z._~+/=-]+/giu,
|
|
5
|
+
/(bearer\s+)[a-z0-9._~+/=-]+/giu,
|
|
6
|
+
/([?&](?:access_token|refresh_token|token|code)=)[^&\s]+/giu
|
|
7
|
+
];
|
|
8
|
+
function isSecretKey(key) {
|
|
9
|
+
return SECRET_KEY_PATTERN.test(key);
|
|
10
|
+
}
|
|
11
|
+
function redactSecretText(value, options = {}) {
|
|
12
|
+
const replacement = options.replacement ?? "[REDACTED]";
|
|
13
|
+
let text = value;
|
|
14
|
+
for (const pattern of [...options.patterns ?? [], ...SECRET_TEXT_PATTERNS]) text = text.replace(pattern, (...args) => {
|
|
15
|
+
return `${typeof args[1] === "string" ? args[1] : ""}${replacement}`;
|
|
16
|
+
});
|
|
17
|
+
for (const secret of options.additionalSecrets?.filter(Boolean) ?? []) text = text.split(secret).join(replacement);
|
|
18
|
+
return {
|
|
19
|
+
text,
|
|
20
|
+
redacted: text !== value
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/errors.ts
|
|
25
|
+
const CAPLETS_ERROR_CODES = [
|
|
26
|
+
"CONFIG_NOT_FOUND",
|
|
27
|
+
"CONFIG_EXISTS",
|
|
28
|
+
"CONFIG_INVALID",
|
|
29
|
+
"REQUEST_INVALID",
|
|
30
|
+
"SERVER_NOT_FOUND",
|
|
31
|
+
"SERVER_UNAVAILABLE",
|
|
32
|
+
"SERVER_START_TIMEOUT",
|
|
33
|
+
"UNKNOWN_OPERATION",
|
|
34
|
+
"TOOL_NOT_FOUND",
|
|
35
|
+
"TOOL_CALL_TIMEOUT",
|
|
36
|
+
"AUTH_REQUIRED",
|
|
37
|
+
"AUTH_FAILED",
|
|
38
|
+
"AUTH_REFRESH_FAILED",
|
|
39
|
+
"DOWNSTREAM_PROTOCOL_ERROR",
|
|
40
|
+
"DOWNSTREAM_TOOL_ERROR",
|
|
41
|
+
"UNSUPPORTED_OPERATION",
|
|
42
|
+
"UNSUPPORTED_CAPABILITY",
|
|
43
|
+
"PROMPT_NOT_FOUND",
|
|
44
|
+
"DOWNSTREAM_RESOURCE_ERROR",
|
|
45
|
+
"DOWNSTREAM_PROMPT_ERROR",
|
|
46
|
+
"DOWNSTREAM_COMPLETION_ERROR",
|
|
47
|
+
"UNSUPPORTED_TRANSPORT",
|
|
48
|
+
"INTERNAL_ERROR"
|
|
49
|
+
];
|
|
50
|
+
var CapletsError = class extends Error {
|
|
51
|
+
code;
|
|
52
|
+
details;
|
|
53
|
+
constructor(code, message, details) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = "CapletsError";
|
|
56
|
+
this.code = code;
|
|
57
|
+
this.details = details;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
function redactSecrets(value) {
|
|
61
|
+
if (typeof value === "string") return redactSecretText(value).text;
|
|
62
|
+
if (Array.isArray(value)) return value.map((item) => redactSecrets(item));
|
|
63
|
+
if (value && typeof value === "object") {
|
|
64
|
+
const redacted = {};
|
|
65
|
+
for (const [key, nested] of Object.entries(value)) redacted[key] = isSecretKey(key) ? "[REDACTED]" : redactSecrets(nested);
|
|
66
|
+
return redacted;
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
function toSafeError(error, fallback = "INTERNAL_ERROR") {
|
|
71
|
+
if (error instanceof CapletsError) return {
|
|
72
|
+
code: error.code,
|
|
73
|
+
message: String(redactSecrets(error.message)),
|
|
74
|
+
...error.details === void 0 ? {} : { details: redactSecrets(error.details) }
|
|
75
|
+
};
|
|
76
|
+
if (error instanceof Error) return {
|
|
77
|
+
code: fallback,
|
|
78
|
+
message: String(redactSecrets(error.message))
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
code: fallback,
|
|
82
|
+
message: String(redactSecrets(error))
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function errorResult(error, fallback) {
|
|
86
|
+
const safe = toSafeError(error, fallback);
|
|
87
|
+
const structuredContent = { error: safe };
|
|
88
|
+
return {
|
|
89
|
+
isError: true,
|
|
90
|
+
content: [{
|
|
91
|
+
type: "text",
|
|
92
|
+
text: [
|
|
93
|
+
"# Error",
|
|
94
|
+
"",
|
|
95
|
+
`## ${safe.code}`,
|
|
96
|
+
"",
|
|
97
|
+
safe.message,
|
|
98
|
+
"",
|
|
99
|
+
"## Details",
|
|
100
|
+
"",
|
|
101
|
+
"```json",
|
|
102
|
+
JSON.stringify(safe, null, 2),
|
|
103
|
+
"```"
|
|
104
|
+
].join("\n")
|
|
105
|
+
}],
|
|
106
|
+
structuredContent
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/config/validation.ts
|
|
111
|
+
const SERVER_ID_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
112
|
+
const HEADER_NAME_PATTERN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
113
|
+
const HTTP_BASE_URL_PATTERN = /^(?![a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/?#]*@)[^?#]*$/;
|
|
114
|
+
const FORBIDDEN_HEADERS = new Set([
|
|
115
|
+
"accept",
|
|
116
|
+
"authorization",
|
|
117
|
+
"connection",
|
|
118
|
+
"content-length",
|
|
119
|
+
"content-type",
|
|
120
|
+
"host",
|
|
121
|
+
"keep-alive",
|
|
122
|
+
"mcp-protocol-version",
|
|
123
|
+
"mcp-session-id",
|
|
124
|
+
"proxy-authenticate",
|
|
125
|
+
"proxy-authorization",
|
|
126
|
+
"te",
|
|
127
|
+
"trailer",
|
|
128
|
+
"transfer-encoding",
|
|
129
|
+
"upgrade"
|
|
130
|
+
]);
|
|
131
|
+
function validateHttpActionHeaders(headers, ctx, path) {
|
|
132
|
+
for (const headerName of Object.keys(headers)) {
|
|
133
|
+
const normalized = headerName.toLowerCase();
|
|
134
|
+
if (!HEADER_NAME_PATTERN.test(headerName) || FORBIDDEN_HEADERS.has(normalized)) ctx.addIssue({
|
|
135
|
+
code: "custom",
|
|
136
|
+
path: [...path, headerName],
|
|
137
|
+
message: `header ${headerName} is not allowed`
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function isAllowedRemoteUrl(value) {
|
|
142
|
+
let url;
|
|
143
|
+
try {
|
|
144
|
+
url = new URL(value);
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (url.protocol === "https:") return true;
|
|
149
|
+
return url.protocol === "http:" && [
|
|
150
|
+
"localhost",
|
|
151
|
+
"127.0.0.1",
|
|
152
|
+
"[::1]",
|
|
153
|
+
"::1"
|
|
154
|
+
].includes(url.hostname);
|
|
155
|
+
}
|
|
156
|
+
function isAllowedHttpBaseUrl(value) {
|
|
157
|
+
let url;
|
|
158
|
+
try {
|
|
159
|
+
url = new URL(value);
|
|
160
|
+
} catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return isAllowedRemoteUrl(value) && !url.username && !url.password && !url.search && !url.hash;
|
|
164
|
+
}
|
|
165
|
+
function isUrl(value) {
|
|
166
|
+
try {
|
|
167
|
+
new URL(value);
|
|
168
|
+
return true;
|
|
169
|
+
} catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { isAllowedHttpBaseUrl as a, validateHttpActionHeaders as c, errorResult as d, redactSecrets as f, SERVER_ID_PATTERN as i, CAPLETS_ERROR_CODES as l, HEADER_NAME_PATTERN as n, isAllowedRemoteUrl as o, toSafeError as p, HTTP_BASE_URL_PATTERN as r, isUrl as s, FORBIDDEN_HEADERS as t, CapletsError as u };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caplets/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Core runtime library for Caplets progressive disclosure gateways.",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Core runtime library for Caplets Code Mode and progressive disclosure gateways.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"caplets",
|
|
7
7
|
"gateway",
|
|
@@ -38,6 +38,46 @@
|
|
|
38
38
|
"./native": {
|
|
39
39
|
"types": "./dist/native.d.ts",
|
|
40
40
|
"default": "./dist/native.js"
|
|
41
|
+
},
|
|
42
|
+
"./caplet-source": {
|
|
43
|
+
"types": "./dist/caplet-source/index.d.ts",
|
|
44
|
+
"default": "./dist/caplet-source.js"
|
|
45
|
+
},
|
|
46
|
+
"./caplet-source/filesystem": {
|
|
47
|
+
"types": "./dist/caplet-source/filesystem.d.ts",
|
|
48
|
+
"default": "./dist/caplet-source/filesystem.js"
|
|
49
|
+
},
|
|
50
|
+
"./code-mode": {
|
|
51
|
+
"types": "./dist/code-mode/index.d.ts",
|
|
52
|
+
"default": "./dist/code-mode.js"
|
|
53
|
+
},
|
|
54
|
+
"./observed-output-shapes": {
|
|
55
|
+
"types": "./dist/observed-output-shapes/index.d.ts",
|
|
56
|
+
"default": "./dist/observed-output-shapes.js"
|
|
57
|
+
},
|
|
58
|
+
"./observed-output-shapes/pure": {
|
|
59
|
+
"types": "./dist/observed-output-shapes/pure.d.ts",
|
|
60
|
+
"default": "./dist/observed-output-shapes/pure.js"
|
|
61
|
+
},
|
|
62
|
+
"./project-binding": {
|
|
63
|
+
"types": "./dist/project-binding/index.d.ts",
|
|
64
|
+
"default": "./dist/project-binding.js"
|
|
65
|
+
},
|
|
66
|
+
"./redaction": {
|
|
67
|
+
"types": "./dist/redaction.d.ts",
|
|
68
|
+
"default": "./dist/redaction.js"
|
|
69
|
+
},
|
|
70
|
+
"./runtime-plan": {
|
|
71
|
+
"types": "./dist/runtime-plan/index.d.ts",
|
|
72
|
+
"default": "./dist/runtime-plan.js"
|
|
73
|
+
},
|
|
74
|
+
"./stable-json": {
|
|
75
|
+
"types": "./dist/stable-json.d.ts",
|
|
76
|
+
"default": "./dist/stable-json.js"
|
|
77
|
+
},
|
|
78
|
+
"./config-runtime": {
|
|
79
|
+
"types": "./dist/config-runtime.d.ts",
|
|
80
|
+
"default": "./dist/config-runtime.js"
|
|
41
81
|
}
|
|
42
82
|
},
|
|
43
83
|
"publishConfig": {
|
|
@@ -48,9 +88,12 @@
|
|
|
48
88
|
"@hono/mcp": "^0.3.0",
|
|
49
89
|
"@hono/node-server": "^2.0.4",
|
|
50
90
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
91
|
+
"ajv": "^8.20.0",
|
|
51
92
|
"commander": "^15.0.0",
|
|
52
|
-
"graphql": "^16.14.
|
|
93
|
+
"graphql": "^16.14.1",
|
|
53
94
|
"hono": "^4.12.23",
|
|
95
|
+
"quickjs-emscripten": "^0.32.0",
|
|
96
|
+
"typescript": "^6.0.3",
|
|
54
97
|
"vfile": "^6.0.3",
|
|
55
98
|
"vfile-matter": "^5.0.1",
|
|
56
99
|
"yaml": "^2.9.0",
|
|
@@ -58,10 +101,9 @@
|
|
|
58
101
|
},
|
|
59
102
|
"devDependencies": {
|
|
60
103
|
"@types/node": "^25.9.1",
|
|
61
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
104
|
+
"@typescript/native-preview": "7.0.0-dev.20260603.1",
|
|
62
105
|
"rolldown": "^1.0.3",
|
|
63
|
-
"
|
|
64
|
-
"vitest": "^4.1.7"
|
|
106
|
+
"vitest": "^4.1.8"
|
|
65
107
|
},
|
|
66
108
|
"engines": {
|
|
67
109
|
"node": ">=22"
|