@caplets/core 0.26.1 → 0.28.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 (43) hide show
  1. package/dist/attach/api.d.ts +10 -1
  2. package/dist/caplet-files-bundle.d.ts +1 -0
  3. package/dist/caplet-source.js +39 -3
  4. package/dist/cli/code-mode.d.ts +3 -2
  5. package/dist/cli/commands.d.ts +3 -1
  6. package/dist/cli/inspection.d.ts +2 -1
  7. package/dist/cli.d.ts +4 -0
  8. package/dist/code-mode/types.d.ts +2 -1
  9. package/dist/{completion-CFOJucl5.js → completion-CjE0EnbF.js} +16 -4
  10. package/dist/config/paths.d.ts +9 -0
  11. package/dist/config/validation.d.ts +2 -0
  12. package/dist/config-runtime.d.ts +6 -1
  13. package/dist/config-runtime.js +34 -3
  14. package/dist/config.d.ts +13 -2
  15. package/dist/engine.d.ts +18 -0
  16. package/dist/errors.d.ts +1 -1
  17. package/dist/esm-Db9dhnIG.js +7488 -0
  18. package/dist/exposure/namespace.d.ts +39 -0
  19. package/dist/index.js +840 -483
  20. package/dist/native/options.d.ts +1 -0
  21. package/dist/native/remote.d.ts +4 -2
  22. package/dist/native/service.d.ts +16 -2
  23. package/dist/native.js +1 -1
  24. package/dist/node-BgWIvSVP.js +17214 -0
  25. package/dist/rolldown-runtime-CE-6LUnI.js +44 -0
  26. package/dist/serve/http.d.ts +16 -1
  27. package/dist/serve/options.d.ts +2 -0
  28. package/dist/{service-aBIn4nrw.js → service-BfPCRxQ9.js} +2043 -154
  29. package/dist/src-Cd2QIUm1.js +813 -0
  30. package/dist/telemetry/context.d.ts +13 -0
  31. package/dist/telemetry/debug.d.ts +10 -0
  32. package/dist/telemetry/delivery.d.ts +1 -0
  33. package/dist/telemetry/events.d.ts +70 -0
  34. package/dist/telemetry/identity.d.ts +1 -0
  35. package/dist/telemetry/index.d.ts +8 -0
  36. package/dist/telemetry/intake.generated.d.ts +2 -0
  37. package/dist/telemetry/notice.d.ts +8 -0
  38. package/dist/telemetry/privacy.d.ts +3 -0
  39. package/dist/telemetry/providers.d.ts +21 -0
  40. package/dist/telemetry/runtime.d.ts +40 -0
  41. package/dist/telemetry/state.d.ts +53 -0
  42. package/dist/{validation-GD2x5HW1.js → validation-CWzd2gtn.js} +3 -1
  43. package/package.json +3 -1
@@ -1,4 +1,11 @@
1
1
  import type { CapletsEngine } from "../engine";
2
+ import type { CapletShadowingPolicy } from "../config";
3
+ import type { NativeCapletsService } from "../native/service";
4
+ export declare const CAPLETS_ATTACH_SESSION_HEADER = "caplets-attach-session-id";
5
+ export type AttachSessionMetadata = {
6
+ projectRoot?: string | undefined;
7
+ projectConfigPath?: string | undefined;
8
+ };
2
9
  export type AttachExportKind = "caplet" | "tool" | "resource" | "resourceTemplate" | "prompt" | "completion";
3
10
  export type AttachInvokeRequest = {
4
11
  revision: string;
@@ -26,7 +33,7 @@ export type AttachManifestExport = {
26
33
  annotations?: unknown;
27
34
  schemaHash: string | null;
28
35
  capletId: string;
29
- shadowing: "forbid" | "allow";
36
+ shadowing: CapletShadowingPolicy;
30
37
  };
31
38
  export type AttachProgressiveCapletExport = AttachManifestExport & {
32
39
  kind: "caplet";
@@ -104,6 +111,8 @@ export type AttachProjection = {
104
111
  routes: Map<string, AttachRoute>;
105
112
  };
106
113
  export declare function buildAttachProjection(engine: CapletsEngine): Promise<AttachProjection>;
114
+ export declare function buildNativeAttachProjection(service: NativeCapletsService): Promise<AttachProjection>;
115
+ export declare function invokeNativeAttachExport(service: NativeCapletsService, projection: AttachProjection, request: AttachInvokeRequest): Promise<unknown>;
107
116
  export declare function invokeAttachExport(engine: CapletsEngine, projection: AttachProjection, request: AttachInvokeRequest): Promise<unknown>;
108
117
  export declare function attachErrorResponse(error: unknown): {
109
118
  status: 400 | 404 | 409 | 500;
@@ -454,6 +454,7 @@ export declare const capletFileSchema: z.ZodObject<{
454
454
  shadowing: z.ZodOptional<z.ZodEnum<{
455
455
  forbid: "forbid";
456
456
  allow: "allow";
457
+ namespace: "namespace";
457
458
  }>>;
458
459
  }, z.core.$strict>;
459
460
  export declare function capletJsonSchema(): unknown;
@@ -10031,6 +10031,7 @@ function superRefine(fn, params) {
10031
10031
  //#endregion
10032
10032
  //#region src/config/validation.ts
10033
10033
  const SERVER_ID_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
10034
+ const NAMESPACE_ALIAS_LABEL_PATTERN = /^[a-z](?:[a-z0-9-]{0,30}[a-z0-9])?$/;
10034
10035
  const HEADER_NAME_PATTERN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
10035
10036
  const HTTP_BASE_URL_PATTERN = /^(?![a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/?#]*@)[^?#]*$/;
10036
10037
  const FORBIDDEN_HEADERS = /* @__PURE__ */ new Set([
@@ -10169,7 +10170,11 @@ const capletExposureSchema = _enum([
10169
10170
  "direct_and_code_mode",
10170
10171
  "progressive_and_code_mode"
10171
10172
  ]).describe("How this Caplet is exposed to agents.");
10172
- const capletShadowingSchema = _enum(["forbid", "allow"]).describe("Whether attached local Caplets may shadow this remote Caplet ID.");
10173
+ const capletShadowingSchema = _enum([
10174
+ "forbid",
10175
+ "allow",
10176
+ "namespace"
10177
+ ]).describe("Whether attached local Caplets may shadow this remote Caplet ID.");
10173
10178
  const capletEndpointAuthSchema = discriminatedUnion("type", [
10174
10179
  object({ type: literal("none") }).strict(),
10175
10180
  object({
@@ -10849,7 +10854,11 @@ const exposureSchema = _enum([
10849
10854
  "direct_and_code_mode",
10850
10855
  "progressive_and_code_mode"
10851
10856
  ]);
10852
- const shadowingSchema = _enum(["forbid", "allow"]).default("forbid");
10857
+ const shadowingSchema = _enum([
10858
+ "forbid",
10859
+ "allow",
10860
+ "namespace"
10861
+ ]).default("forbid");
10853
10862
  const commonSchema = {
10854
10863
  name: string().trim().min(1).max(80),
10855
10864
  description: string().refine((value) => value.trim().length >= 10, "description must contain at least 10 non-whitespace characters").refine((value) => value.length <= 1500, "description must be at most 1500 characters"),
@@ -10988,6 +10997,28 @@ const capletSetSchema = object({
10988
10997
  maxSearchLimit: number().int().positive().max(50).default(50),
10989
10998
  toolCacheTtlMs: number().int().nonnegative().default(3e4)
10990
10999
  }).strict();
11000
+ const namespaceAliasLabelSchema = string().regex(NAMESPACE_ALIAS_LABEL_PATTERN, "namespace alias labels must be lowercase DNS-style labels using letters, numbers, or hyphens");
11001
+ const namespaceAliasesSchema = object({
11002
+ local: namespaceAliasLabelSchema.optional(),
11003
+ upstreams: record(string().trim().min(1), namespaceAliasLabelSchema).default({})
11004
+ }).strict().default({ upstreams: {} }).superRefine((aliases, ctx) => {
11005
+ const seen = /* @__PURE__ */ new Map();
11006
+ const addAlias = (value, path) => {
11007
+ if (!value) return;
11008
+ const existing = seen.get(value);
11009
+ if (existing) {
11010
+ ctx.addIssue({
11011
+ code: "custom",
11012
+ path,
11013
+ message: `namespace alias '${value}' is already used at ${existing.join(".")}`
11014
+ });
11015
+ return;
11016
+ }
11017
+ seen.set(value, path);
11018
+ };
11019
+ addAlias(aliases.local, ["local"]);
11020
+ for (const [selector, alias] of Object.entries(aliases.upstreams)) addAlias(alias, ["upstreams", selector]);
11021
+ });
10991
11022
  const configSchema = object({
10992
11023
  version: literal(1).default(1),
10993
11024
  defaultSearchLimit: number().int().positive().default(20),
@@ -11018,7 +11049,8 @@ const configSchema = object({
11018
11049
  graphqlEndpoints: record(string().regex(SERVER_ID_PATTERN), graphQlEndpointSchema).default({}),
11019
11050
  httpApis: record(string().regex(SERVER_ID_PATTERN), httpApiSchema).default({}),
11020
11051
  cliTools: record(string().regex(SERVER_ID_PATTERN), cliToolsSchema).default({}),
11021
- capletSets: record(string().regex(SERVER_ID_PATTERN), capletSetSchema).default({})
11052
+ capletSets: record(string().regex(SERVER_ID_PATTERN), capletSetSchema).default({}),
11053
+ namespaceAliases: namespaceAliasesSchema
11022
11054
  }).strict().superRefine((config, ctx) => {
11023
11055
  if (config.defaultSearchLimit > config.maxSearchLimit) ctx.addIssue({
11024
11056
  code: "custom",
@@ -11041,6 +11073,10 @@ function parseConfig(input) {
11041
11073
  exposureDiscoveryConcurrency: config.options.exposureDiscoveryConcurrency,
11042
11074
  completion: config.completion
11043
11075
  },
11076
+ namespaceAliases: stripUndefined({
11077
+ local: config.namespaceAliases.local,
11078
+ upstreams: config.namespaceAliases.upstreams
11079
+ }),
11044
11080
  mcpServers: mapBackend(config.mcpServers, "mcp", (id, raw) => {
11045
11081
  const server = raw;
11046
11082
  return {
@@ -3,6 +3,7 @@ export type CodeModeCliOptions = {
3
3
  configPath?: string | undefined;
4
4
  projectConfigPath?: string | undefined;
5
5
  authDir?: string | undefined;
6
+ telemetryStateDir?: string | undefined;
6
7
  inlineCode?: string | undefined;
7
8
  file?: string | undefined;
8
9
  timeoutMs?: number | undefined;
@@ -14,6 +15,6 @@ export type CodeModeCliOptions = {
14
15
  setExitCode: (code: number) => void;
15
16
  };
16
17
  export declare function runCodeModeCli(options: CodeModeCliOptions): Promise<void>;
17
- export declare function runCodeModeReplCli(options: Pick<CodeModeCliOptions, "env" | "configPath" | "projectConfigPath" | "authDir" | "sessionId" | "recoveryRef" | "json" | "writeOut" | "setExitCode">): Promise<void>;
18
- export declare function codeModeTypesCli(options: Pick<CodeModeCliOptions, "env" | "configPath" | "projectConfigPath" | "authDir" | "json" | "writeOut">): Promise<void>;
18
+ export declare function runCodeModeReplCli(options: Pick<CodeModeCliOptions, "env" | "configPath" | "projectConfigPath" | "authDir" | "telemetryStateDir" | "sessionId" | "recoveryRef" | "json" | "writeOut" | "setExitCode">): Promise<void>;
19
+ export declare function codeModeTypesCli(options: Pick<CodeModeCliOptions, "env" | "configPath" | "projectConfigPath" | "authDir" | "telemetryStateDir" | "json" | "writeOut">): Promise<void>;
19
20
  export declare function readCodeModeCliCode(options: Pick<CodeModeCliOptions, "inlineCode" | "file" | "readStdin">): Promise<string>;
@@ -32,8 +32,9 @@ export declare const cliCommands: {
32
32
  readonly config: "config";
33
33
  readonly auth: "auth";
34
34
  readonly vault: "vault";
35
+ readonly telemetry: "telemetry";
35
36
  };
36
- export declare const topLevelCommandNames: readonly ["serve", "daemon", "code-mode", "attach", "remote", "cloud", "init", "setup", "doctor", "list", "install", "add", "inspect", "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", "config", "auth", "vault", "completion"];
37
+ export declare const topLevelCommandNames: readonly ["serve", "daemon", "code-mode", "attach", "remote", "cloud", "init", "setup", "doctor", "list", "install", "add", "inspect", "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", "config", "auth", "vault", "telemetry", "completion"];
37
38
  export declare const cliSubcommands: {
38
39
  readonly add: readonly ["cli", "mcp", "openapi", "google-discovery", "graphql", "http"];
39
40
  readonly auth: readonly ["login", "logout", "list", "refresh"];
@@ -44,6 +45,7 @@ export declare const cliSubcommands: {
44
45
  readonly config: readonly ["path", "paths"];
45
46
  readonly daemon: readonly ["install", "uninstall", "start", "restart", "stop", "status", "logs"];
46
47
  readonly setup: readonly ["codex", "claude-code", "opencode", "pi", "mcp-client"];
48
+ readonly telemetry: readonly ["status", "enable", "disable", "delete-id", "rotate-id", "debug"];
47
49
  readonly vault: readonly ["set", "get", "list", "delete", "access"];
48
50
  };
49
51
  export declare const cliNestedSubcommands: {
@@ -1,4 +1,4 @@
1
- import { type CapletConfig, type ConfigSource, type ConfigWithSources } from "../config";
1
+ import { type CapletConfig, type CapletShadowingPolicy, type ConfigSource, type ConfigWithSources } from "../config";
2
2
  import type { ServerStatus } from "../registry";
3
3
  type CapletListRow = {
4
4
  server: string;
@@ -10,6 +10,7 @@ type CapletListRow = {
10
10
  source: ConfigSource["kind"] | "remote" | "unknown";
11
11
  path: string | null;
12
12
  shadows: ConfigSource[];
13
+ shadowing?: CapletShadowingPolicy | undefined;
13
14
  };
14
15
  type ConfigPaths = {
15
16
  userConfig: string;
package/dist/cli.d.ts CHANGED
@@ -4,6 +4,7 @@ import { type AttachServeOptions } from "./attach/options";
4
4
  import type { ProjectBindingWebSocketFactory } from "./project-binding/transport";
5
5
  import { type DaemonOperationOptions } from "./daemon";
6
6
  import { type ServeOptions } from "./serve";
7
+ import { TelemetryDebugSink } from "./telemetry";
7
8
  export { initConfig, starterConfig } from "./cli/init";
8
9
  export { installCaplets, normalizeGitRepo } from "./cli/install";
9
10
  export { addCliCaplet, addGoogleDiscoveryCaplet, addGraphqlCaplet, addHttpCaplet, addMcpCaplet, addOpenApiCaplet, } from "./cli/add";
@@ -15,6 +16,9 @@ type CliIO = {
15
16
  signal?: AbortSignal;
16
17
  projectBindingWebSocketFactory?: ProjectBindingWebSocketFactory;
17
18
  authDir?: string;
19
+ telemetryStateDir?: string;
20
+ stderrIsTTY?: boolean;
21
+ telemetryDebugSink?: TelemetryDebugSink;
18
22
  version?: string;
19
23
  setExitCode?: (code: number) => void;
20
24
  serve?: (options: ServeOptions) => Promise<void>;
@@ -6,7 +6,7 @@ export type CodeModeCallableCaplet = {
6
6
  id: string;
7
7
  name: string;
8
8
  description: string;
9
- shadowing?: "forbid" | "allow";
9
+ shadowing?: "forbid" | "allow" | "namespace";
10
10
  useWhen?: string;
11
11
  avoidWhen?: string;
12
12
  };
@@ -35,6 +35,7 @@ export type CodeModeRunMeta = {
35
35
  durationMs: number;
36
36
  timeoutMs: number;
37
37
  maxTimeoutMs: number;
38
+ anyCapletInvoked: boolean;
38
39
  sessionId?: string | null;
39
40
  sessionStatus?: CodeModeSessionStatus | null;
40
41
  recoveryRef?: string | null;
@@ -1,5 +1,6 @@
1
- import { Hn as __exportAll, It as DEFAULT_AUTH_DIR, Kt as resolveProjectConfigPath, Lt as DEFAULT_COMPLETION_CACHE_DIR, Ut as resolveCapletsRoot, Wt as resolveConfigPath, lt as loadConfigWithSources } from "./service-aBIn4nrw.js";
2
- import { u as CapletsError } from "./validation-GD2x5HW1.js";
1
+ import { r as __exportAll } from "./rolldown-runtime-CE-6LUnI.js";
2
+ import { Dt as loadConfigWithSources, cn as resolveCapletsRoot, dn as resolveProjectConfigPath, en as DEFAULT_AUTH_DIR, ln as resolveConfigPath, tn as DEFAULT_COMPLETION_CACHE_DIR } from "./service-BfPCRxQ9.js";
3
+ import { d as CapletsError } from "./validation-CWzd2gtn.js";
3
4
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
4
5
  import { dirname, join } from "node:path";
5
6
  import { createHash } from "node:crypto";
@@ -42,7 +43,8 @@ const cliCommands = {
42
43
  complete: "complete",
43
44
  config: "config",
44
45
  auth: "auth",
45
- vault: "vault"
46
+ vault: "vault",
47
+ telemetry: "telemetry"
46
48
  };
47
49
  const topLevelCommandNames = [
48
50
  cliCommands.serve,
@@ -74,6 +76,7 @@ const topLevelCommandNames = [
74
76
  cliCommands.config,
75
77
  cliCommands.auth,
76
78
  cliCommands.vault,
79
+ cliCommands.telemetry,
77
80
  cliCommands.completion
78
81
  ];
79
82
  const cliSubcommands = {
@@ -117,6 +120,14 @@ const cliSubcommands = {
117
120
  "pi",
118
121
  "mcp-client"
119
122
  ],
123
+ [cliCommands.telemetry]: [
124
+ "status",
125
+ "enable",
126
+ "disable",
127
+ "delete-id",
128
+ "rotate-id",
129
+ "debug"
130
+ ],
120
131
  [cliCommands.vault]: [
121
132
  "set",
122
133
  "get",
@@ -165,7 +176,8 @@ function listCaplets(configWithSources, options) {
165
176
  status: initialServerStatus(server),
166
177
  source: sources[server.server]?.kind ?? "unknown",
167
178
  path: sources[server.server]?.path ?? null,
168
- shadows: shadows[server.server] ?? []
179
+ shadows: shadows[server.server] ?? [],
180
+ shadowing: server.shadowing
169
181
  })).sort((left, right) => left.server.localeCompare(right.server));
170
182
  }
171
183
  function initialServerStatus(server) {
@@ -5,17 +5,26 @@ export declare function defaultStateBaseDir(env?: PathEnv, home?: string, platfo
5
5
  export declare function defaultCacheBaseDir(env?: PathEnv, home?: string, platform?: Platform): string;
6
6
  export declare function defaultConfigPath(env?: PathEnv, home?: string, platform?: Platform): string;
7
7
  export declare function defaultAuthDir(env?: PathEnv, home?: string, platform?: Platform): string;
8
+ export declare function defaultTelemetryStateDir(env?: PathEnv, home?: string, platform?: Platform): string;
9
+ export declare function defaultTelemetryIdentityPath(env?: PathEnv, home?: string, platform?: Platform): string;
10
+ export declare function defaultTelemetryNoticePath(env?: PathEnv, home?: string, platform?: Platform): string;
11
+ export declare function defaultTelemetryDeliveryHealthPath(env?: PathEnv, home?: string, platform?: Platform): string;
8
12
  export declare function defaultArtifactDir(env?: PathEnv, home?: string, platform?: Platform): string;
9
13
  export declare function defaultCompletionCacheDir(env?: PathEnv, home?: string, platform?: Platform): string;
10
14
  export declare function defaultObservedOutputShapeCacheDir(env?: PathEnv, home?: string, platform?: Platform): string;
11
15
  export declare const DEFAULT_CONFIG_PATH: string;
12
16
  export declare const DEFAULT_AUTH_DIR: string;
13
17
  export declare const DEFAULT_ARTIFACT_DIR: string;
18
+ export declare const DEFAULT_TELEMETRY_STATE_DIR: string;
19
+ export declare const DEFAULT_TELEMETRY_IDENTITY_PATH: string;
20
+ export declare const DEFAULT_TELEMETRY_NOTICE_PATH: string;
21
+ export declare const DEFAULT_TELEMETRY_DELIVERY_HEALTH_PATH: string;
14
22
  export declare const DEFAULT_COMPLETION_CACHE_DIR: string;
15
23
  export declare const DEFAULT_OBSERVED_OUTPUT_SHAPE_CACHE_DIR: string;
16
24
  export declare const PROJECT_CONFIG_FILE: string;
17
25
  export declare function resolveConfigPath(path?: string): string;
18
26
  export declare function resolveProjectConfigPath(cwd?: string): string;
19
27
  export declare function resolveCapletsRoot(configPath?: string): string;
28
+ export declare function resolveTelemetryStateDir(path?: string): string;
20
29
  export declare function resolveProjectCapletsRoot(cwd?: string): string;
21
30
  export {};
@@ -1,4 +1,5 @@
1
1
  export declare const SERVER_ID_PATTERN: RegExp;
2
+ export declare const NAMESPACE_ALIAS_LABEL_PATTERN: RegExp;
2
3
  export declare const HEADER_NAME_PATTERN: RegExp;
3
4
  export declare const HTTP_BASE_URL_PATTERN: RegExp;
4
5
  export declare const FORBIDDEN_HEADERS: Set<string>;
@@ -10,6 +11,7 @@ type ValidationIssueSink = {
10
11
  }): void;
11
12
  };
12
13
  export declare function validateHttpActionHeaders(headers: Record<string, unknown>, ctx: ValidationIssueSink, path: Array<string>): void;
14
+ export declare function isValidNamespaceAliasLabel(value: string): boolean;
13
15
  export declare function isAllowedRemoteUrl(value: string): boolean;
14
16
  export declare function isAllowedHttpBaseUrl(value: string): boolean;
15
17
  export declare function isUrl(value: string): boolean;
@@ -49,7 +49,7 @@ export type AgentSelectionHintsConfig = {
49
49
  avoidWhen?: string | undefined;
50
50
  };
51
51
  export type CapletExposure = "direct" | "progressive" | "code_mode" | "direct_and_code_mode" | "progressive_and_code_mode";
52
- export type CapletShadowingPolicy = "forbid" | "allow";
52
+ export type CapletShadowingPolicy = "forbid" | "allow" | "namespace";
53
53
  export type CapletServerConfig = CommonCapletConfig & {
54
54
  backend: "mcp";
55
55
  transport: "stdio" | "http" | "sse";
@@ -157,6 +157,10 @@ export type CapletSetConfig = CommonCapletConfig & {
157
157
  toolCacheTtlMs: number;
158
158
  };
159
159
  export type CapletConfig = CapletServerConfig | OpenApiEndpointConfig | GoogleDiscoveryApiConfig | GraphQlEndpointConfig | HttpApiConfig | CliToolsConfig | CapletSetConfig;
160
+ export type NamespaceAliasesConfig = {
161
+ local?: string | undefined;
162
+ upstreams: Record<string, string>;
163
+ };
160
164
  export type CapletsConfig = {
161
165
  version: 1;
162
166
  options: {
@@ -172,6 +176,7 @@ export type CapletsConfig = {
172
176
  negativeCacheTtlMs: number;
173
177
  };
174
178
  };
179
+ namespaceAliases: NamespaceAliasesConfig;
175
180
  mcpServers: Record<string, CapletServerConfig>;
176
181
  openapiEndpoints: Record<string, OpenApiEndpointConfig>;
177
182
  googleDiscoveryApis: Record<string, GoogleDiscoveryApiConfig>;
@@ -1,5 +1,5 @@
1
1
  import { _ as record, b as unknown, d as literal, l as discriminatedUnion, m as object, o as array, p as number, r as _enum, s as boolean, v as string, y as union } from "./schemas-BoqMu4MG.js";
2
- import { a as isAllowedHttpBaseUrl, c as validateHttpActionHeaders, i as SERVER_ID_PATTERN, n as HEADER_NAME_PATTERN, o as isAllowedRemoteUrl, r as HTTP_BASE_URL_PATTERN, s as isUrl, t as FORBIDDEN_HEADERS, u as CapletsError } from "./validation-GD2x5HW1.js";
2
+ import { a as SERVER_ID_PATTERN, c as isUrl, d as CapletsError, i as NAMESPACE_ALIAS_LABEL_PATTERN, l as validateHttpActionHeaders, n as HEADER_NAME_PATTERN, o as isAllowedHttpBaseUrl, r as HTTP_BASE_URL_PATTERN, s as isAllowedRemoteUrl, t as FORBIDDEN_HEADERS } from "./validation-CWzd2gtn.js";
3
3
  //#region src/config-runtime.ts
4
4
  const stringMapSchema = record(string(), string());
5
5
  const authSchema = discriminatedUnion("type", [
@@ -49,7 +49,11 @@ const exposureSchema = _enum([
49
49
  "direct_and_code_mode",
50
50
  "progressive_and_code_mode"
51
51
  ]);
52
- const shadowingSchema = _enum(["forbid", "allow"]).default("forbid");
52
+ const shadowingSchema = _enum([
53
+ "forbid",
54
+ "allow",
55
+ "namespace"
56
+ ]).default("forbid");
53
57
  const commonSchema = {
54
58
  name: string().trim().min(1).max(80),
55
59
  description: string().refine((value) => value.trim().length >= 10, "description must contain at least 10 non-whitespace characters").refine((value) => value.length <= 1500, "description must be at most 1500 characters"),
@@ -188,6 +192,28 @@ const capletSetSchema = object({
188
192
  maxSearchLimit: number().int().positive().max(50).default(50),
189
193
  toolCacheTtlMs: number().int().nonnegative().default(3e4)
190
194
  }).strict();
195
+ const namespaceAliasLabelSchema = string().regex(NAMESPACE_ALIAS_LABEL_PATTERN, "namespace alias labels must be lowercase DNS-style labels using letters, numbers, or hyphens");
196
+ const namespaceAliasesSchema = object({
197
+ local: namespaceAliasLabelSchema.optional(),
198
+ upstreams: record(string().trim().min(1), namespaceAliasLabelSchema).default({})
199
+ }).strict().default({ upstreams: {} }).superRefine((aliases, ctx) => {
200
+ const seen = /* @__PURE__ */ new Map();
201
+ const addAlias = (value, path) => {
202
+ if (!value) return;
203
+ const existing = seen.get(value);
204
+ if (existing) {
205
+ ctx.addIssue({
206
+ code: "custom",
207
+ path,
208
+ message: `namespace alias '${value}' is already used at ${existing.join(".")}`
209
+ });
210
+ return;
211
+ }
212
+ seen.set(value, path);
213
+ };
214
+ addAlias(aliases.local, ["local"]);
215
+ for (const [selector, alias] of Object.entries(aliases.upstreams)) addAlias(alias, ["upstreams", selector]);
216
+ });
191
217
  const configSchema = object({
192
218
  version: literal(1).default(1),
193
219
  defaultSearchLimit: number().int().positive().default(20),
@@ -218,7 +244,8 @@ const configSchema = object({
218
244
  graphqlEndpoints: record(string().regex(SERVER_ID_PATTERN), graphQlEndpointSchema).default({}),
219
245
  httpApis: record(string().regex(SERVER_ID_PATTERN), httpApiSchema).default({}),
220
246
  cliTools: record(string().regex(SERVER_ID_PATTERN), cliToolsSchema).default({}),
221
- capletSets: record(string().regex(SERVER_ID_PATTERN), capletSetSchema).default({})
247
+ capletSets: record(string().regex(SERVER_ID_PATTERN), capletSetSchema).default({}),
248
+ namespaceAliases: namespaceAliasesSchema
222
249
  }).strict().superRefine((config, ctx) => {
223
250
  if (config.defaultSearchLimit > config.maxSearchLimit) ctx.addIssue({
224
251
  code: "custom",
@@ -241,6 +268,10 @@ function parseConfig(input) {
241
268
  exposureDiscoveryConcurrency: config.options.exposureDiscoveryConcurrency,
242
269
  completion: config.completion
243
270
  },
271
+ namespaceAliases: stripUndefined({
272
+ local: config.namespaceAliases.local,
273
+ upstreams: config.namespaceAliases.upstreams
274
+ }),
244
275
  mcpServers: mapBackend(config.mcpServers, "mcp", (id, raw) => {
245
276
  const server = raw;
246
277
  return {
package/dist/config.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { FileVaultStore, type VaultConfigOrigin } from "./vault";
3
- export { DEFAULT_AUTH_DIR, DEFAULT_COMPLETION_CACHE_DIR, DEFAULT_CONFIG_PATH, PROJECT_CONFIG_FILE, defaultCacheBaseDir, defaultCompletionCacheDir, resolveCapletsRoot, resolveConfigPath, resolveProjectCapletsRoot, resolveProjectConfigPath, } from "./config/paths";
3
+ export { DEFAULT_AUTH_DIR, DEFAULT_COMPLETION_CACHE_DIR, DEFAULT_CONFIG_PATH, DEFAULT_TELEMETRY_STATE_DIR, PROJECT_CONFIG_FILE, defaultCacheBaseDir, defaultCompletionCacheDir, defaultTelemetryStateDir, resolveCapletsRoot, resolveConfigPath, resolveProjectCapletsRoot, resolveProjectConfigPath, resolveTelemetryStateDir, } from "./config/paths";
4
4
  export type RemoteAuthConfig = {
5
5
  type: "none";
6
6
  } | {
@@ -64,7 +64,7 @@ export type AgentSelectionHintsConfig = {
64
64
  useWhen?: string | undefined;
65
65
  avoidWhen?: string | undefined;
66
66
  };
67
- export type CapletShadowingPolicy = "forbid" | "allow";
67
+ export type CapletShadowingPolicy = "forbid" | "allow" | "namespace";
68
68
  export type CapletExposure = "direct" | "progressive" | "code_mode" | "direct_and_code_mode" | "progressive_and_code_mode";
69
69
  export type CapletServerConfig = AgentSelectionHintsConfig & {
70
70
  server: string;
@@ -261,6 +261,10 @@ export type CapletSetConfig = AgentSelectionHintsConfig & {
261
261
  runtime?: RuntimeRequirementsConfig | undefined;
262
262
  };
263
263
  export type CapletConfig = CapletServerConfig | OpenApiEndpointConfig | GoogleDiscoveryApiConfig | GraphQlEndpointConfig | HttpApiConfig | CliToolsConfig | CapletSetConfig;
264
+ export type NamespaceAliasesConfig = {
265
+ local?: string | undefined;
266
+ upstreams: Record<string, string>;
267
+ };
264
268
  export type CapletsOptions = {
265
269
  defaultSearchLimit: number;
266
270
  maxSearchLimit: number;
@@ -277,7 +281,9 @@ export type CompletionConfig = {
277
281
  };
278
282
  export type CapletsConfig = {
279
283
  version: 1;
284
+ telemetry?: boolean | undefined;
280
285
  options: CapletsOptions;
286
+ namespaceAliases: NamespaceAliasesConfig;
281
287
  mcpServers: Record<string, CapletServerConfig>;
282
288
  openapiEndpoints: Record<string, OpenApiEndpointConfig>;
283
289
  googleDiscoveryApis: Record<string, GoogleDiscoveryApiConfig>;
@@ -333,6 +339,7 @@ export declare const configFileSchema: z.ZodObject<{
333
339
  version: z.ZodDefault<z.ZodLiteral<1>>;
334
340
  defaultSearchLimit: z.ZodDefault<z.ZodNumber>;
335
341
  maxSearchLimit: z.ZodDefault<z.ZodNumber>;
342
+ telemetry: z.ZodOptional<z.ZodBoolean>;
336
343
  completion: z.ZodDefault<z.ZodObject<{
337
344
  discoveryTimeoutMs: z.ZodDefault<z.ZodNumber>;
338
345
  overallTimeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -350,6 +357,10 @@ export declare const configFileSchema: z.ZodObject<{
350
357
  exposureDiscoveryTimeoutMs: z.ZodDefault<z.ZodNumber>;
351
358
  exposureDiscoveryConcurrency: z.ZodDefault<z.ZodNumber>;
352
359
  }, z.core.$strict>>;
360
+ namespaceAliases: z.ZodDefault<z.ZodObject<{
361
+ local: z.ZodOptional<z.ZodString>;
362
+ upstreams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
363
+ }, z.core.$strict>>;
353
364
  mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
354
365
  openapiEndpoints: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
355
366
  googleDiscoveryApis: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
package/dist/engine.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { type CapletConfig, type CapletsConfig, type LocalOverlayConfigWarning } from "./config";
2
2
  import { type ObservedOutputShapeKey, type ObservedOutputShapeStore } from "./observed-output-shapes";
3
3
  import { type ExposureSnapshot } from "./exposure/discovery";
4
+ import { type RuntimeMode } from "./telemetry";
5
+ import type { TelemetryDebugSink, TelemetryDispatcher, TelemetrySurface, TelemetryVisibility } from "./telemetry";
4
6
  export type CapletsEngineOptions = {
5
7
  configPath?: string;
6
8
  projectConfigPath?: string;
@@ -18,6 +20,14 @@ export type CapletsEngineOptions = {
18
20
  observedOutputShapeCacheDir?: string | undefined;
19
21
  projectFingerprint?: string | undefined;
20
22
  vaultRecoveryTarget?: "global" | "remote" | undefined;
23
+ telemetryStateDir?: string | undefined;
24
+ telemetryEnv?: NodeJS.ProcessEnv | undefined;
25
+ telemetrySurface?: TelemetrySurface | undefined;
26
+ telemetryVisibility?: TelemetryVisibility | undefined;
27
+ telemetryRuntimeMode?: RuntimeMode | undefined;
28
+ telemetryIntegration?: "opencode" | "pi" | "native" | "unknown" | undefined;
29
+ telemetryDebugSink?: TelemetryDebugSink | undefined;
30
+ telemetryDispatcher?: TelemetryDispatcher | undefined;
21
31
  };
22
32
  export type CapletsEngineReloadEvent = {
23
33
  previous: CapletsConfig;
@@ -41,6 +51,8 @@ export declare class CapletsEngine {
41
51
  private readonly observedOutputShapeStore;
42
52
  private readonly observedOutputShapeScope;
43
53
  private readonly projectFingerprint;
54
+ private readonly telemetry;
55
+ private readonly telemetryExecuteExposureMode;
44
56
  private readonly reloadListeners;
45
57
  private lastExposureSnapshot;
46
58
  private watchers;
@@ -65,6 +77,10 @@ export declare class CapletsEngine {
65
77
  readDirectResource(serverId: string, downstreamUri: string): Promise<unknown>;
66
78
  getDirectPrompt(serverId: string, promptName: string, args: Record<string, unknown>): Promise<unknown>;
67
79
  completeCliWords(words: string[]): Promise<string[]>;
80
+ captureCodeModeOutcome(envelope: unknown, options: {
81
+ started: number;
82
+ timeoutMs?: number | undefined;
83
+ }): Promise<void>;
68
84
  close(): Promise<void>;
69
85
  private listCompletionTools;
70
86
  private listTools;
@@ -80,4 +96,6 @@ export declare class CapletsEngine {
80
96
  private watchEntry;
81
97
  private watchDirectoryTree;
82
98
  private scheduleWatcherRefresh;
99
+ private captureReliabilityError;
100
+ private captureToolActivation;
83
101
  }
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const CAPLETS_ERROR_CODES: readonly ["CONFIG_NOT_FOUND", "CONFIG_EXISTS", "CONFIG_INVALID", "REQUEST_INVALID", "SERVER_NOT_FOUND", "SERVER_UNAVAILABLE", "SERVER_START_TIMEOUT", "UNKNOWN_OPERATION", "TOOL_NOT_FOUND", "TOOL_CALL_TIMEOUT", "AUTH_REQUIRED", "AUTH_FAILED", "REMOTE_CREDENTIALS_REVOKED", "AUTH_REFRESH_FAILED", "DOWNSTREAM_PROTOCOL_ERROR", "DOWNSTREAM_TOOL_ERROR", "UNSUPPORTED_OPERATION", "UNSUPPORTED_CAPABILITY", "PROMPT_NOT_FOUND", "DOWNSTREAM_RESOURCE_ERROR", "DOWNSTREAM_PROMPT_ERROR", "DOWNSTREAM_COMPLETION_ERROR", "ATTACH_MANIFEST_STALE", "ATTACH_EXPORT_NOT_FOUND", "UNSUPPORTED_TRANSPORT", "INTERNAL_ERROR"];
1
+ export declare const CAPLETS_ERROR_CODES: readonly ["CONFIG_NOT_FOUND", "CONFIG_EXISTS", "CONFIG_INVALID", "REQUEST_INVALID", "SERVER_NOT_FOUND", "SERVER_UNAVAILABLE", "SERVER_START_TIMEOUT", "UNKNOWN_OPERATION", "CAPLET_NAMESPACE_COLLISION", "TOOL_NOT_FOUND", "TOOL_CALL_TIMEOUT", "AUTH_REQUIRED", "AUTH_FAILED", "REMOTE_CREDENTIALS_REVOKED", "AUTH_REFRESH_FAILED", "DOWNSTREAM_PROTOCOL_ERROR", "DOWNSTREAM_TOOL_ERROR", "UNSUPPORTED_OPERATION", "UNSUPPORTED_CAPABILITY", "PROMPT_NOT_FOUND", "DOWNSTREAM_RESOURCE_ERROR", "DOWNSTREAM_PROMPT_ERROR", "DOWNSTREAM_COMPLETION_ERROR", "ATTACH_MANIFEST_STALE", "ATTACH_EXPORT_NOT_FOUND", "UNSUPPORTED_TRANSPORT", "INTERNAL_ERROR"];
2
2
  export type CapletsErrorCode = (typeof CAPLETS_ERROR_CODES)[number];
3
3
  export type SafeErrorSummary = {
4
4
  code: CapletsErrorCode;