@caplets/core 0.19.0 → 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.
Files changed (74) hide show
  1. package/dist/caplet-files-bundle.d.ts +24 -9
  2. package/dist/caplet-source.js +368 -4588
  3. package/dist/cli/auth.d.ts +40 -2
  4. package/dist/cli/cloud-add.d.ts +8 -0
  5. package/dist/cli/code-mode.d.ts +16 -0
  6. package/dist/cli/commands.d.ts +3 -1
  7. package/dist/cli/doctor.d.ts +3 -0
  8. package/dist/cli/setup.d.ts +7 -0
  9. package/dist/cli-tools.d.ts +1 -1
  10. package/dist/cli.d.ts +1 -0
  11. package/dist/cloud-auth/client.d.ts +15 -0
  12. package/dist/cloud-auth/types.d.ts +2 -1
  13. package/dist/code-mode/api.d.ts +32 -0
  14. package/dist/code-mode/declarations.d.ts +5 -0
  15. package/dist/code-mode/diagnostics.d.ts +8 -0
  16. package/dist/code-mode/index.d.ts +4 -0
  17. package/dist/code-mode/logs.d.ts +21 -0
  18. package/dist/code-mode/runner.d.ts +15 -0
  19. package/dist/code-mode/runtime-api.generated.d.ts +1 -0
  20. package/dist/code-mode/sandbox.d.ts +28 -0
  21. package/dist/code-mode/static-analysis.d.ts +2 -0
  22. package/dist/code-mode/tool.d.ts +11 -0
  23. package/dist/code-mode/types.d.ts +120 -0
  24. package/dist/code-mode.js +147855 -0
  25. package/dist/{completion-brgziz4L.js → completion-CbazRAiL.js} +5 -2
  26. package/dist/config/paths.d.ts +2 -0
  27. package/dist/config-runtime.d.ts +13 -4
  28. package/dist/config-runtime.js +31 -2
  29. package/dist/config.d.ts +34 -9
  30. package/dist/downstream.d.ts +20 -2
  31. package/dist/engine.d.ts +20 -0
  32. package/dist/exposure/direct-names.d.ts +9 -0
  33. package/dist/exposure/discovery.d.ts +75 -0
  34. package/dist/exposure/policy.d.ts +8 -0
  35. package/dist/generated-tool-input-schema.d.ts +89 -59
  36. package/dist/generated-tool-input-schema.js +38 -27
  37. package/dist/graphql.d.ts +1 -1
  38. package/dist/http-actions.d.ts +1 -1
  39. package/dist/index.d.ts +13 -0
  40. package/dist/index.js +1096 -154
  41. package/dist/native/service.d.ts +6 -0
  42. package/dist/native/tools.d.ts +2 -0
  43. package/dist/native.d.ts +1 -1
  44. package/dist/native.js +2 -2
  45. package/dist/observed-output-shapes/extract.d.ts +5 -0
  46. package/dist/observed-output-shapes/file-store.d.ts +17 -0
  47. package/dist/observed-output-shapes/index.d.ts +7 -0
  48. package/dist/observed-output-shapes/key.d.ts +14 -0
  49. package/dist/observed-output-shapes/merge.d.ts +2 -0
  50. package/dist/observed-output-shapes/pure.d.ts +5 -0
  51. package/dist/observed-output-shapes/pure.js +241 -0
  52. package/dist/observed-output-shapes/schema.d.ts +1 -0
  53. package/dist/observed-output-shapes/types.d.ts +84 -0
  54. package/dist/observed-output-shapes/typescript.d.ts +7 -0
  55. package/dist/observed-output-shapes-uzAMQPhg.js +485 -0
  56. package/dist/observed-output-shapes.js +2 -0
  57. package/dist/openapi.d.ts +1 -1
  58. package/dist/project-binding/index.d.ts +2 -0
  59. package/dist/project-binding.js +22 -0
  60. package/dist/redaction.d.ts +14 -0
  61. package/dist/redaction.js +30 -0
  62. package/dist/registry.d.ts +4 -0
  63. package/dist/remote/options.d.ts +2 -0
  64. package/dist/remote-control/types.d.ts +1 -1
  65. package/dist/runtime-plan/resources.d.ts +2 -0
  66. package/dist/runtime-plan.js +8 -2
  67. package/dist/schemas-1HZ0kFpx.js +4270 -0
  68. package/dist/serve/session.d.ts +15 -3
  69. package/dist/{service-BXcE4Rv8.js → service-D0MwLNyb.js} +29175 -26499
  70. package/dist/stable-json.d.ts +3 -0
  71. package/dist/stable-json.js +26 -0
  72. package/dist/tools.d.ts +22 -11
  73. package/dist/{validation-BBG4skZf.js → validation-CdqbI2zN.js} +25 -4
  74. package/package.json +29 -3
@@ -0,0 +1,3 @@
1
+ export declare function stableJsonValue(value: unknown): unknown;
2
+ export declare function stableJsonStringify(value: unknown): string;
3
+ export declare function stableJsonSha256Hex(value: unknown): Promise<string>;
@@ -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 declare function handleServerTool(server: CapletConfig, request: unknown, registry: ServerRegistry, downstream: DownstreamManager, openapi?: OpenApiManager, graphql?: GraphQLManager, http?: HttpActionManager, cli?: CliToolsManager, caplets?: CapletSetManager): Promise<any>;
14
- export declare function validateOperationRequest(request: unknown, maxSearchLimit: number, backend?: string): RequiredOperationRequest;
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" | "check_backend";
23
+ operation: "inspect" | "check";
17
24
  } | {
18
- operation: "list_tools";
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: "get_tool";
26
- tool: string;
34
+ operation: "describe_tool";
35
+ name: string;
27
36
  } | {
28
37
  operation: "call_tool";
29
- tool: string;
30
- arguments: Record<string, unknown>;
38
+ name: string;
39
+ args: Record<string, unknown>;
31
40
  fields?: string[];
32
41
  } | {
33
- operation: "list_resources" | "list_resource_templates" | "list_prompts";
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
- prompt: string;
45
- arguments: Record<string, unknown>;
55
+ name: string;
56
+ args: Record<string, unknown>;
46
57
  } | {
47
58
  operation: "complete";
48
59
  ref: {
@@ -1,3 +1,26 @@
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
1
24
  //#region src/errors.ts
2
25
  const CAPLETS_ERROR_CODES = [
3
26
  "CONFIG_NOT_FOUND",
@@ -34,14 +57,12 @@ var CapletsError = class extends Error {
34
57
  this.details = details;
35
58
  }
36
59
  };
37
- const SECRET_KEY_PATTERN = /(token|secret|authorization|auth|api[-_]?key|password|credential|clientsecret|client_secret|code|refresh)/i;
38
- const SECRET_VALUE_PATTERN = /(bearer\s+)[a-z0-9._~+/=-]+|([?&](?:access_token|refresh_token|token|code)=)[^&\s]+/gi;
39
60
  function redactSecrets(value) {
40
- if (typeof value === "string") return value.replace(SECRET_VALUE_PATTERN, "$1$2[REDACTED]");
61
+ if (typeof value === "string") return redactSecretText(value).text;
41
62
  if (Array.isArray(value)) return value.map((item) => redactSecrets(item));
42
63
  if (value && typeof value === "object") {
43
64
  const redacted = {};
44
- for (const [key, nested] of Object.entries(value)) redacted[key] = SECRET_KEY_PATTERN.test(key) ? "[REDACTED]" : redactSecrets(nested);
65
+ for (const [key, nested] of Object.entries(value)) redacted[key] = isSecretKey(key) ? "[REDACTED]" : redactSecrets(nested);
45
66
  return redacted;
46
67
  }
47
68
  return value;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@caplets/core",
3
- "version": "0.19.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",
@@ -47,10 +47,34 @@
47
47
  "types": "./dist/caplet-source/filesystem.d.ts",
48
48
  "default": "./dist/caplet-source/filesystem.js"
49
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
+ },
50
70
  "./runtime-plan": {
51
71
  "types": "./dist/runtime-plan/index.d.ts",
52
72
  "default": "./dist/runtime-plan.js"
53
73
  },
74
+ "./stable-json": {
75
+ "types": "./dist/stable-json.d.ts",
76
+ "default": "./dist/stable-json.js"
77
+ },
54
78
  "./config-runtime": {
55
79
  "types": "./dist/config-runtime.d.ts",
56
80
  "default": "./dist/config-runtime.js"
@@ -64,9 +88,12 @@
64
88
  "@hono/mcp": "^0.3.0",
65
89
  "@hono/node-server": "^2.0.4",
66
90
  "@modelcontextprotocol/sdk": "^1.29.0",
91
+ "ajv": "^8.20.0",
67
92
  "commander": "^15.0.0",
68
93
  "graphql": "^16.14.1",
69
94
  "hono": "^4.12.23",
95
+ "quickjs-emscripten": "^0.32.0",
96
+ "typescript": "^6.0.3",
70
97
  "vfile": "^6.0.3",
71
98
  "vfile-matter": "^5.0.1",
72
99
  "yaml": "^2.9.0",
@@ -76,7 +103,6 @@
76
103
  "@types/node": "^25.9.1",
77
104
  "@typescript/native-preview": "7.0.0-dev.20260603.1",
78
105
  "rolldown": "^1.0.3",
79
- "typescript": "^6.0.3",
80
106
  "vitest": "^4.1.8"
81
107
  },
82
108
  "engines": {