@caplets/core 0.24.0 → 0.24.1

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.
@@ -1,4 +1,4 @@
1
- import { Dt as resolveConfigPath, Et as resolveCapletsRoot, Tn as __exportAll, bt as DEFAULT_AUTH_DIR, kt as resolveProjectConfigPath, tt as loadConfigWithSources, xt as DEFAULT_COMPLETION_CACHE_DIR } from "./service-BCT_Ls_3.js";
1
+ import { Dt as resolveConfigPath, Et as resolveCapletsRoot, Tn as __exportAll, bt as DEFAULT_AUTH_DIR, kt as resolveProjectConfigPath, tt as loadConfigWithSources, xt as DEFAULT_COMPLETION_CACHE_DIR } from "./service-Cvnuu9wr.js";
2
2
  import { u as CapletsError } from "./validation-DgxCzt-A.js";
3
3
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
4
4
  import { dirname, join } from "node:path";
package/dist/config.d.ts CHANGED
@@ -299,6 +299,7 @@ export type LocalOverlayConfigWarning = {
299
299
  kind: ConfigSourceKind;
300
300
  path: string;
301
301
  message: string;
302
+ recoverable?: boolean | undefined;
302
303
  };
303
304
  export type LocalOverlayConfigWithSources = ConfigWithSources & {
304
305
  warnings: LocalOverlayConfigWarning[];
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { $ as GoogleDiscoveryManager, $t as ListPromptsRequestSchema, A as emptyCodeModeRunMeta, At as ReadBuffer, B as codeModeDeclarationHash, Bt as CompleteRequestSchema, C as nativeCapletToolDescription, Cn as safeParse, Ct as defaultCacheBaseDir, Dt as resolveConfigPath, Et as resolveCapletsRoot, F as createCodeModeCapletsApi, Ft as Protocol, G as resolveExposure, Gt as ElicitResultSchema, H as generateCodeModeRunToolDescription, Ht as CreateMessageResultWithToolsSchema, I as listCodeModeCallableCaplets, It as mergeCapabilities, J as findProjectRoot, Jt as GetPromptRequestSchema, K as decodeDirectResourceUri, Kt as EmptyResultSchema, L as CodeModeJournalStore, Lt as toJsonSchemaCompat, M as CodeModeSessionManager, Mt as assertClientRequestTaskCapability, N as QuickJsCodeModeSandbox, Nt as assertToolsCallTaskCapability, O as codeModeRunInputSchema, Ot as resolveProjectCapletsRoot, P as diagnoseCodeModeTypeScript, Pt as AjvJsonSchemaValidator, Q as capabilityDescription, Qt as LATEST_PROTOCOL_VERSION, R as CodeModeLogStore, Rt as CallToolRequestSchema, S as nativeCapletPromptGuidance, Sn as objectFromShape, St as DEFAULT_OBSERVED_OUTPUT_SHAPE_CACHE_DIR, Tt as defaultStateBaseDir, U as minifyCodeModeDeclarationText, Ut as CreateTaskResultSchema, V as generateCodeModeDeclarations, Vt as CreateMessageResultSchema, W as CapletsEngine, X as handleServerTool, Xt as InitializedNotificationSchema, Y as fingerprintProjectRoot, Yt as InitializeRequestSchema, Z as ServerRegistry, Zt as JSONRPCMessageSchema, _ as resolveHostedCloudRemote, _n as getParseErrorMessage, _t as deleteTokenBundle, a as projectBindingError, an as McpError, at as parseConfig, b as parseServerBaseUrl, bn as isZ4Schema, c as cloudAuthPath, cn as SetLevelRequestSchema, ct as loadCapletFilesFromMap, d as CloudAuthClient, dn as isInitializeRequest, dt as markdownStructuredContent, en as ListResourceTemplatesRequestSchema, et as loadConfig, fn as isJSONRPCErrorResponse, ft as refreshOAuthTokenBundle, g as resolveCapletsRemote, gn as getObjectShape, gt as startOAuthFlow, hn as getLiteralValue, ht as startGenericOAuthFlow, i as ProjectBindingError, in as LoggingLevelSchema, it as loadProjectConfig, j as runCodeMode, jt as serializeMessage, k as codeModeRunParamsSchema, kt as resolveProjectConfigPath, l as migrateCredentials, ln as assertCompleteRequestPrompt, lt as hasRenderableStructuredContent, m as buildProjectSyncManifest, mn as isJSONRPCResultResponse, mt as runOAuthFlow, n as resolveRemoteSelection, nn as ListRootsResultSchema, nt as loadGlobalConfig, o as projectBindingRecovery, on as ReadResourceRequestSchema, ot as discoverCapletFiles, p as createSdkRemoteCapletsClient, pn as isJSONRPCRequest, pt as runGenericOAuthFlow, q as directResourceUriMatchesTemplate, qt as ErrorCode, r as PROJECT_BINDING_ERROR_CODES, rn as ListToolsRequestSchema, rt as loadLocalOverlayConfigWithSources, s as CloudAuthStore, sn as SUPPORTED_PROTOCOL_VERSIONS, st as validateCapletFile, t as createNativeCapletsService, tn as ListResourcesRequestSchema, tt as loadConfigWithSources, u as redactedCloudAuthStatus, un as assertCompleteRequestResourceTemplate, ut as markdownCallToolResultContent, v as resolveRemoteMode, vn as getSchemaDescription, vt as isTokenBundleExpired, w as nativeCapletToolName, wn as safeParseAsync, wt as defaultConfigBaseDir, x as resolveCapletsServer, xn as normalizeObjectSchema, y as controlUrlForBase, yn as isSchemaOptional, yt as readTokenBundle, z as redactCodeModeLogText, zt as CallToolResultSchema } from "./service-BCT_Ls_3.js";
1
+ import { $ as GoogleDiscoveryManager, $t as ListPromptsRequestSchema, A as emptyCodeModeRunMeta, At as ReadBuffer, B as codeModeDeclarationHash, Bt as CompleteRequestSchema, C as nativeCapletToolDescription, Cn as safeParse, Ct as defaultCacheBaseDir, Dt as resolveConfigPath, Et as resolveCapletsRoot, F as createCodeModeCapletsApi, Ft as Protocol, G as resolveExposure, Gt as ElicitResultSchema, H as generateCodeModeRunToolDescription, Ht as CreateMessageResultWithToolsSchema, I as listCodeModeCallableCaplets, It as mergeCapabilities, J as findProjectRoot, Jt as GetPromptRequestSchema, K as decodeDirectResourceUri, Kt as EmptyResultSchema, L as CodeModeJournalStore, Lt as toJsonSchemaCompat, M as CodeModeSessionManager, Mt as assertClientRequestTaskCapability, N as QuickJsCodeModeSandbox, Nt as assertToolsCallTaskCapability, O as codeModeRunInputSchema, Ot as resolveProjectCapletsRoot, P as diagnoseCodeModeTypeScript, Pt as AjvJsonSchemaValidator, Q as capabilityDescription, Qt as LATEST_PROTOCOL_VERSION, R as CodeModeLogStore, Rt as CallToolRequestSchema, S as nativeCapletPromptGuidance, Sn as objectFromShape, St as DEFAULT_OBSERVED_OUTPUT_SHAPE_CACHE_DIR, Tt as defaultStateBaseDir, U as minifyCodeModeDeclarationText, Ut as CreateTaskResultSchema, V as generateCodeModeDeclarations, Vt as CreateMessageResultSchema, W as CapletsEngine, X as handleServerTool, Xt as InitializedNotificationSchema, Y as fingerprintProjectRoot, Yt as InitializeRequestSchema, Z as ServerRegistry, Zt as JSONRPCMessageSchema, _ as resolveHostedCloudRemote, _n as getParseErrorMessage, _t as deleteTokenBundle, a as projectBindingError, an as McpError, at as parseConfig, b as parseServerBaseUrl, bn as isZ4Schema, c as cloudAuthPath, cn as SetLevelRequestSchema, ct as loadCapletFilesFromMap, d as CloudAuthClient, dn as isInitializeRequest, dt as markdownStructuredContent, en as ListResourceTemplatesRequestSchema, et as loadConfig, fn as isJSONRPCErrorResponse, ft as refreshOAuthTokenBundle, g as resolveCapletsRemote, gn as getObjectShape, gt as startOAuthFlow, hn as getLiteralValue, ht as startGenericOAuthFlow, i as ProjectBindingError, in as LoggingLevelSchema, it as loadProjectConfig, j as runCodeMode, jt as serializeMessage, k as codeModeRunParamsSchema, kt as resolveProjectConfigPath, l as migrateCredentials, ln as assertCompleteRequestPrompt, lt as hasRenderableStructuredContent, m as buildProjectSyncManifest, mn as isJSONRPCResultResponse, mt as runOAuthFlow, n as resolveRemoteSelection, nn as ListRootsResultSchema, nt as loadGlobalConfig, o as projectBindingRecovery, on as ReadResourceRequestSchema, ot as discoverCapletFiles, p as createSdkRemoteCapletsClient, pn as isJSONRPCRequest, pt as runGenericOAuthFlow, q as directResourceUriMatchesTemplate, qt as ErrorCode, r as PROJECT_BINDING_ERROR_CODES, rn as ListToolsRequestSchema, rt as loadLocalOverlayConfigWithSources, s as CloudAuthStore, sn as SUPPORTED_PROTOCOL_VERSIONS, st as validateCapletFile, t as createNativeCapletsService, tn as ListResourcesRequestSchema, tt as loadConfigWithSources, u as redactedCloudAuthStatus, un as assertCompleteRequestResourceTemplate, ut as markdownCallToolResultContent, v as resolveRemoteMode, vn as getSchemaDescription, vt as isTokenBundleExpired, w as nativeCapletToolName, wn as safeParseAsync, wt as defaultConfigBaseDir, x as resolveCapletsServer, xn as normalizeObjectSchema, y as controlUrlForBase, yn as isSchemaOptional, yt as readTokenBundle, z as redactCodeModeLogText, zt as CallToolResultSchema } from "./service-Cvnuu9wr.js";
2
2
  import { _ as record, b as unknown, d as literal, m as object, n as ZodOptional, o as array, p as number, r as _enum, s as boolean, v as string, x as url } from "./schemas-C0PNPwjS.js";
3
3
  import { f as redactSecrets, i as SERVER_ID_PATTERN, l as CAPLETS_ERROR_CODES, p as toSafeError, u as CapletsError } from "./validation-DgxCzt-A.js";
4
4
  import { generatedToolInputJsonSchemaForCaplet, generatedToolInputSchema, generatedToolInputSchemaForCaplet } from "./generated-tool-input-schema.js";
5
5
  import { f as observedOutputShapeKey, g as stableJsonStringify, h as schemaHash, i as observeOutputShape, u as FileObservedOutputShapeStore } from "./observed-output-shapes-D2k2-q8K.js";
6
- import { a as formatCapletList, c as resolveCliConfigPaths, l as cliCommands$1, n as completionScript, o as formatConfigPaths, s as listCaplets, t as completeCliWords, u as completionShells } from "./completion-CzHdM9B_.js";
6
+ import { a as formatCapletList, c as resolveCliConfigPaths, l as cliCommands$1, n as completionScript, o as formatConfigPaths, s as listCaplets, t as completeCliWords, u as completionShells } from "./completion-BeVXdm9q.js";
7
7
  import { n as normalizeCapletSourcePath, t as FilesystemCapletSource } from "./filesystem-Kkg32TOJ.js";
8
8
  import { parseConfig as parseConfig$1 } from "./config-runtime.js";
9
9
  import fs, { accessSync, chmodSync, closeSync, constants, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
@@ -1553,7 +1553,7 @@ const EMPTY_COMPLETION_RESULT = { completion: {
1553
1553
  } };
1554
1554
  //#endregion
1555
1555
  //#region package.json
1556
- var version = "0.24.0";
1556
+ var version = "0.24.1";
1557
1557
  //#endregion
1558
1558
  //#region src/serve/session.ts
1559
1559
  var CapletsMcpSession = class {
package/dist/native.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as nativeCapletToolDescription, D as nativeCodeModeToolName, E as nativeCodeModeToolId, S as nativeCapletPromptGuidance, T as nativeCapletsSystemGuidance, f as RemoteNativeCapletsService, h as resolveNativeCapletsServiceOptions, p as createSdkRemoteCapletsClient, t as createNativeCapletsService, w as nativeCapletToolName } from "./service-BCT_Ls_3.js";
1
+ import { C as nativeCapletToolDescription, D as nativeCodeModeToolName, E as nativeCodeModeToolId, S as nativeCapletPromptGuidance, T as nativeCapletsSystemGuidance, f as RemoteNativeCapletsService, h as resolveNativeCapletsServiceOptions, p as createSdkRemoteCapletsClient, t as createNativeCapletsService, w as nativeCapletToolName } from "./service-Cvnuu9wr.js";
2
2
  import { generatedToolInputJsonSchema, generatedToolInputSchema } from "./generated-tool-input-schema.js";
3
3
  //#region src/native/process-cleanup.ts
4
4
  function registerNativeCapletsProcessCleanup(service, options = {}) {
@@ -27102,6 +27102,16 @@ const publicCapletSetSchema = object$1({
27102
27102
  });
27103
27103
  });
27104
27104
  const normalizedCapletSetSchema = publicCapletSetSchema.extend({ body: string().optional() });
27105
+ const CAPLET_BACKEND_KEYS = [
27106
+ "mcpServers",
27107
+ "openapiEndpoints",
27108
+ "googleDiscoveryApis",
27109
+ "graphqlEndpoints",
27110
+ "httpApis",
27111
+ "cliTools",
27112
+ "capletSets"
27113
+ ];
27114
+ const CAPLET_BACKEND_KEY_SET = new Set(CAPLET_BACKEND_KEYS);
27105
27115
  function configSchemaFor(serverValueSchema, openApiEndpointValueSchema, googleDiscoveryApiValueSchema, graphQlEndpointValueSchema, httpApiValueSchema, cliToolsValueSchema, capletSetValueSchema) {
27106
27116
  return object$1({
27107
27117
  $schema: string().optional().describe("Optional JSON Schema for editor validation."),
@@ -27555,8 +27565,11 @@ function loadLocalOverlayConfigWithSources(path = resolveConfigPath(), projectPa
27555
27565
  }
27556
27566
  function readBestEffortConfigInput(path, kind, warnings, transform) {
27557
27567
  try {
27558
- const input = readPublicConfigInput(path);
27559
- return transform ? transform(input) : input;
27568
+ const normalized = normalizeLocalPaths(readBestEffortJsonConfigInput(path), dirname(path));
27569
+ const filtered = quarantineMissingEnvCaplets(transform ? transform(normalized) : normalized, kind, path, warnings);
27570
+ const parsed = configFileSchema.safeParse(interpolateConfig(filtered));
27571
+ if (!parsed.success) throw new CapletsError("CONFIG_INVALID", `Caplets config at ${path} is invalid`, parsed.error.issues);
27572
+ return filtered;
27560
27573
  } catch (error) {
27561
27574
  warnings.push({
27562
27575
  kind,
@@ -27566,6 +27579,55 @@ function readBestEffortConfigInput(path, kind, warnings, transform) {
27566
27579
  return;
27567
27580
  }
27568
27581
  }
27582
+ function readBestEffortJsonConfigInput(path) {
27583
+ try {
27584
+ return JSON.parse(readFileSync(path, "utf8"));
27585
+ } catch (error) {
27586
+ throw new CapletsError("CONFIG_INVALID", `Caplets config at ${path} is not valid JSON`, redactSecrets(error));
27587
+ }
27588
+ }
27589
+ function quarantineMissingEnvCaplets(input, kind, sourcePath, warnings) {
27590
+ let filtered = input;
27591
+ for (const backend of CAPLET_BACKEND_KEYS) {
27592
+ const caplets = filtered[backend];
27593
+ if (!isPlainObject$5(caplets)) continue;
27594
+ for (const [id, caplet] of Object.entries(caplets)) {
27595
+ const missing = missingEnvReferences(caplet, [backend, id]);
27596
+ if (missing.length === 0) continue;
27597
+ filtered = removeCapletBackendId(filtered, backend, id);
27598
+ warnings.push({
27599
+ kind,
27600
+ path: typeof sourcePath === "function" ? sourcePath(id) : sourcePath,
27601
+ message: formatMissingEnvWarning(id, missing),
27602
+ recoverable: true
27603
+ });
27604
+ }
27605
+ }
27606
+ return filtered;
27607
+ }
27608
+ function missingEnvReferences(value, path) {
27609
+ if (isPublicMetadataPath(path)) return [];
27610
+ if (typeof value === "string") return missingEnvReferencesInString(value, path.join("."));
27611
+ if (Array.isArray(value)) return value.flatMap((item, index) => missingEnvReferences(item, [...path, String(index)]));
27612
+ if (isPlainObject$5(value)) return Object.entries(value).flatMap(([key, nested]) => missingEnvReferences(nested, [...path, key]));
27613
+ return [];
27614
+ }
27615
+ function missingEnvReferencesInString(value, path) {
27616
+ const missing = [];
27617
+ for (const match of value.matchAll(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$env:([A-Za-z_][A-Za-z0-9_]*)/g)) {
27618
+ const name = match[1] ?? match[2];
27619
+ if (name && process.env[name] === void 0) missing.push({
27620
+ name,
27621
+ path
27622
+ });
27623
+ }
27624
+ return missing;
27625
+ }
27626
+ function formatMissingEnvWarning(id, missing) {
27627
+ const names = [...new Set(missing.map((reference) => reference.name))];
27628
+ const paths = [...new Set(missing.map((reference) => reference.path))];
27629
+ return `Caplet ${id} references missing ${names.length === 1 ? "environment variable" : "environment variables"} ${names.join(", ")} at ${paths.join(", ")}; skipping Caplet ${id}.`;
27630
+ }
27569
27631
  function loadBestEffortCapletFiles(root, kind, warnings) {
27570
27632
  const result = loadCapletFilesWithPathsBestEffort(root);
27571
27633
  if (!result) return;
@@ -27574,9 +27636,11 @@ function loadBestEffortCapletFiles(root, kind, warnings) {
27574
27636
  path: warning.path ?? root,
27575
27637
  message: warning.message
27576
27638
  });
27639
+ const config = quarantineMissingEnvCaplets(result.config, kind, (id) => result.paths[id] ?? root, warnings);
27640
+ const retainedIds = new Set(capletIds(config));
27577
27641
  return {
27578
- config: result.config,
27579
- paths: result.paths
27642
+ config,
27643
+ paths: Object.fromEntries(Object.entries(result.paths).filter(([id]) => retainedIds.has(id)))
27580
27644
  };
27581
27645
  }
27582
27646
  function errorMessage$3(error) {
@@ -27737,6 +27801,15 @@ function mergeConfigInputsWithSources(...inputs) {
27737
27801
  shadows
27738
27802
  };
27739
27803
  }
27804
+ function removeCapletBackendId(input, backend, id) {
27805
+ const caplets = input[backend];
27806
+ if (!isPlainObject$5(caplets)) return input;
27807
+ const { [id]: _removed, ...remaining } = caplets;
27808
+ return {
27809
+ ...input,
27810
+ [backend]: remaining
27811
+ };
27812
+ }
27740
27813
  function removeCapletId(input, id) {
27741
27814
  const { [id]: _mcpServer, ...mcpServers } = input.mcpServers ?? {};
27742
27815
  const { [id]: _openapiEndpoint, ...openapiEndpoints } = input.openapiEndpoints ?? {};
@@ -27867,7 +27940,7 @@ function interpolateConfig(value, path = []) {
27867
27940
  return value;
27868
27941
  }
27869
27942
  function isPublicMetadataPath(path) {
27870
- if (path.length < 3 || path[0] !== "mcpServers" && path[0] !== "openapiEndpoints" && path[0] !== "googleDiscoveryApis" && path[0] !== "graphqlEndpoints" && path[0] !== "httpApis" && path[0] !== "cliTools" && path[0] !== "capletSets") return false;
27943
+ if (path.length < 3 || !CAPLET_BACKEND_KEY_SET.has(path[0] ?? "")) return false;
27871
27944
  return NON_INTERPOLATED_SERVER_FIELDS.has(path[2] ?? "");
27872
27945
  }
27873
27946
  function isPlainObject$5(value) {
@@ -63362,7 +63435,7 @@ var CapletsEngine = class {
63362
63435
  }
63363
63436
  }
63364
63437
  async completeCliWords(words) {
63365
- const { completeCliWords } = await import("./completion-CzHdM9B_.js").then((n) => n.r);
63438
+ const { completeCliWords } = await import("./completion-BeVXdm9q.js").then((n) => n.r);
63366
63439
  return await completeCliWords(words, {
63367
63440
  config: this.registry.config,
63368
63441
  managers: {
@@ -81942,9 +82015,9 @@ function createLocalOverlayConfigLoader(options) {
81942
82015
  return parseConfig({});
81943
82016
  }
81944
82017
  for (const warning of result.warnings) writeErr(options, `Caplets local overlay warning${typeof warning.path === "string" ? ` at ${warning.path}` : ""}: ${warning.message}\n`);
81945
- const warnings = new Set(result.warnings.map(warningKey));
81946
- if (hasLoaded && [...warnings].some((warning) => !previousWarnings.has(warning))) throw new CapletsError("CONFIG_INVALID", "Caplets local overlay reload produced new warnings; keeping last known-good config.");
81947
- previousWarnings = warnings;
82018
+ const fatalWarnings = new Set(result.warnings.filter((warning) => !warning.recoverable).map(warningKey));
82019
+ if (hasLoaded && [...fatalWarnings].some((warning) => !previousWarnings.has(warning))) throw new CapletsError("CONFIG_INVALID", "Caplets local overlay reload produced new warnings; keeping last known-good config.");
82020
+ previousWarnings = fatalWarnings;
81948
82021
  hasLoaded = true;
81949
82022
  return result.config;
81950
82023
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caplets/core",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
4
4
  "description": "Core runtime library for Caplets Code Mode and progressive disclosure gateways.",
5
5
  "keywords": [
6
6
  "caplets",