capable-kit 0.0.1-alpha.1 → 0.0.1-alpha.3

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/README.md CHANGED
@@ -36,6 +36,38 @@ The package provides the `cap` CLI command. `capable` remains an alias:
36
36
  cap dev
37
37
  ```
38
38
 
39
+ ## Deploy
40
+
41
+ Capable detects supported build environments such as Vercel and emits their
42
+ native deployment output:
43
+
44
+ ```sh
45
+ vercel
46
+ ```
47
+
48
+ To create Vercel's Build Output API locally instead:
49
+
50
+ ```sh
51
+ cap build --preset vercel
52
+ vercel deploy --prebuilt
53
+ ```
54
+
55
+ For a deployment protected by Vercel Authentication, link the local project.
56
+ Capable reuses the Vercel CLI login to resolve that project's Protection Bypass
57
+ for Automation:
58
+
59
+ ```sh
60
+ vercel link
61
+ cap cli --app https://your-app.vercel.app hello
62
+ ```
63
+
64
+ An explicit environment variable remains available for CI or unlinked projects:
65
+
66
+ ```sh
67
+ export VERCEL_AUTOMATION_BYPASS_SECRET="..."
68
+ cap cli --app https://your-app.vercel.app hello
69
+ ```
70
+
39
71
  ## Package contents
40
72
 
41
73
  The published package includes compiled ESM in `dist/`, declaration files, and
package/dist/ai-sdk.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as CapabilityGroupDefinition, c as CapabilityInput, f as CapabilityOutput, i as CapabilityDefinition, j as CapabilityTree, t as AnyCapability } from "./index-BB5ogMv-.mjs";
2
- import { c as AppCapabilities, o as AnyApp } from "./index-BxJhwhKm.mjs";
2
+ import { c as AppCapabilities, o as AnyApp } from "./index-B_I9n6gN.mjs";
3
3
  import { Tool, ToolExecutionOptions } from "ai";
4
4
  //#region packages/ai-sdk/src/index.d.ts
5
5
  type AiSdkCapabilityMeta = false | {
package/dist/app.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as JsonSchema, D as ManifestNode, E as ManifestGroup, O as createAppManifest, S as ApplicationManifest, T as ManifestError, _ as createApp, a as APP_RUNTIME_SYMBOL, b as isApp, c as AppCapabilities, d as AppContextProvider, f as ApplicationTransport, g as TransportError, h as CapabilityResult, i as APP_CAPABILITIES_SYMBOL, l as AppCapabilityCall, m as CapabilityCall, n as mergeApps, o as AnyApp, p as CallableTree, r as selectApp, s as App, t as ApplicationSelection, u as AppCapabilityIsSubscribable, v as createRemoteApp, w as ManifestCapability, x as subscribe, y as getAppRuntime } from "./index-BxJhwhKm.mjs";
1
+ import { C as JsonSchema, D as ManifestNode, E as ManifestGroup, O as createAppManifest, S as ApplicationManifest, T as ManifestError, _ as createApp, a as APP_RUNTIME_SYMBOL, b as isApp, c as AppCapabilities, d as AppContextProvider, f as ApplicationTransport, g as TransportError, h as CapabilityResult, i as APP_CAPABILITIES_SYMBOL, l as AppCapabilityCall, m as CapabilityCall, n as mergeApps, o as AnyApp, p as CallableTree, r as selectApp, s as App, t as ApplicationSelection, u as AppCapabilityIsSubscribable, v as createRemoteApp, w as ManifestCapability, x as subscribe, y as getAppRuntime } from "./index-B_I9n6gN.mjs";
2
2
  export { APP_CAPABILITIES_SYMBOL, APP_RUNTIME_SYMBOL, type AnyApp, type App, type AppCapabilities, type AppCapabilityCall, type AppCapabilityIsSubscribable, type AppContextProvider, type ApplicationManifest, type ApplicationSelection, type ApplicationTransport, type CallableTree, type CapabilityCall, type CapabilityResult, type JsonSchema, type ManifestCapability, type ManifestError, type ManifestGroup, type ManifestNode, TransportError, createApp, createAppManifest, createRemoteApp, getAppRuntime, isApp, mergeApps, selectApp, subscribe };
package/dist/bin.mjs CHANGED
@@ -2,13 +2,14 @@
2
2
  import { t as APPLICATION_SYMBOL } from "./src-B53ZbNtC.mjs";
3
3
  import { l as isApp, o as createApp, s as createRemoteApp } from "./src-3UaBqI8H.mjs";
4
4
  import { a as createCliStyle, c as renderSection, l as supportsColor, n as runCli, o as descriptionColumn, s as renderRows } from "./src-BjBxOv7x.mjs";
5
- import { n as createHttpTransport } from "./src-XRJ9hgYX.mjs";
5
+ import { n as createHttpTransport } from "./src-DX2xrplP.mjs";
6
6
  import path from "node:path";
7
7
  import { spawn } from "node:child_process";
8
8
  import { fileURLToPath, pathToFileURL } from "node:url";
9
9
  import { existsSync } from "node:fs";
10
10
  import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
11
11
  import { build, createDevServer, createNitro, prepare } from "nitro/builder";
12
+ import { homedir } from "node:os";
12
13
  //#region packages/nitro-host/src/index.ts
13
14
  const virtualServerEntry = "#capable/entry";
14
15
  /**
@@ -106,7 +107,7 @@ function createCapableNitroConfig(project, options) {
106
107
  return {
107
108
  rootDir: project.rootDir,
108
109
  dev: options.dev,
109
- preset: options.dev ? "nitro-dev" : options.preset ?? "node-server",
110
+ ...options.dev ? { preset: "nitro-dev" } : options.preset ? { preset: options.preset } : { defaultPreset: "node-server" },
110
111
  compatibilityDate: "2026-07-15",
111
112
  alias: serverEntry ? {
112
113
  "#capable/server": serverEntry,
@@ -188,7 +189,7 @@ const TOPICS = {
188
189
  },
189
190
  {
190
191
  label: "--preset <preset>",
191
- description: "Nitro preset (default: node-server)"
192
+ description: "Nitro preset (auto-detected; fallback: node-server)"
192
193
  },
193
194
  APP_OPTION,
194
195
  HELP_OPTION
@@ -217,10 +218,17 @@ const TOPICS = {
217
218
  cli: {
218
219
  usage: "cap cli [options] <command...>",
219
220
  summary: "Call your App's Capabilities from the terminal.",
220
- options: [{
221
- label: "--app <path|url>",
222
- description: "Project, App entry, or a running Capable server URL"
223
- }, HELP_OPTION],
221
+ options: [
222
+ {
223
+ label: "--app <path|url>",
224
+ description: "Project, App entry, or a running Capable server URL"
225
+ },
226
+ {
227
+ label: "--protection-bypass <secret>",
228
+ description: "Vercel Deployment Protection bypass"
229
+ },
230
+ HELP_OPTION
231
+ ],
224
232
  footer: "Run `cap cli -- --help` to list the commands your App derives."
225
233
  }
226
234
  };
@@ -344,7 +352,7 @@ const SCRIPTS = {
344
352
  preview: "cap preview"
345
353
  };
346
354
  const DEPENDENCIES = {
347
- "capable-kit": "latest",
355
+ "capable-kit": "alpha",
348
356
  zod: "^4.0.0"
349
357
  };
350
358
  async function initializeCapableProject(options) {
@@ -376,7 +384,7 @@ async function readPackageJson(filename) {
376
384
  throw error;
377
385
  }
378
386
  const value = JSON.parse(source);
379
- if (!isRecord(value)) throw new Error(`${filename} must contain a JSON object`);
387
+ if (!isRecord$1(value)) throw new Error(`${filename} must contain a JSON object`);
380
388
  return value;
381
389
  }
382
390
  function preparePackageJson(directory, existing) {
@@ -415,7 +423,7 @@ function preparePackageJson(directory, existing) {
415
423
  function readObjectField(value, field) {
416
424
  const current = value[field];
417
425
  if (current === void 0) return {};
418
- if (!isRecord(current)) throw new Error(`package.json "${field}" must be an object`);
426
+ if (!isRecord$1(current)) throw new Error(`package.json "${field}" must be an object`);
419
427
  return { ...current };
420
428
  }
421
429
  function hasDeclaredDependency(packageJson, name) {
@@ -426,7 +434,7 @@ function hasDeclaredDependency(packageJson, name) {
426
434
  "optionalDependencies"
427
435
  ].some((field) => {
428
436
  const dependencies = packageJson[field];
429
- return isRecord(dependencies) && name in dependencies;
437
+ return isRecord$1(dependencies) && name in dependencies;
430
438
  });
431
439
  }
432
440
  function packageName(directory) {
@@ -435,6 +443,107 @@ function packageName(directory) {
435
443
  function applicationName(directory, packageJson) {
436
444
  return ((typeof packageJson.name === "string" ? packageJson.name.split("/").at(-1) : void 0) || path.basename(directory)).split(/[-_.\s]+/).filter(Boolean).map((part) => `${part[0].toUpperCase()}${part.slice(1)}`).join(" ") || "Capable App";
437
445
  }
446
+ function isRecord$1(value) {
447
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
448
+ }
449
+ //#endregion
450
+ //#region packages/toolchain/src/vercel-protection.ts
451
+ async function resolveVercelProtectionBypass(options) {
452
+ const explicit = trimmed(options.explicit);
453
+ if (explicit) return explicit;
454
+ const configured = trimmed(options.env.VERCEL_AUTOMATION_BYPASS_SECRET);
455
+ if (configured) return configured;
456
+ if (!isLikelyVercelDeployment(options.baseUrl)) return void 0;
457
+ const token = trimmed(options.env.VERCEL_TOKEN) ?? await readVercelCliToken(options.env);
458
+ if (!token) return void 0;
459
+ const project = await resolveLinkedProject(options.cwd, options.env);
460
+ if (!project) return void 0;
461
+ return await fetchAutomationBypass({
462
+ token,
463
+ project,
464
+ fetch: options.fetch ?? fetch
465
+ });
466
+ }
467
+ function isLikelyVercelDeployment(value) {
468
+ try {
469
+ const hostname = new URL(value).hostname.toLowerCase();
470
+ return hostname.endsWith(".vercel.app") || hostname.endsWith(".vercel.dev") || hostname.endsWith(".now.sh");
471
+ } catch {
472
+ return false;
473
+ }
474
+ }
475
+ async function readVercelCliToken(env) {
476
+ const home = homedir();
477
+ const paths = [
478
+ trimmed(env.VERCEL_AUTH_FILE),
479
+ path.join(home, "Library", "Application Support", "com.vercel.cli", "auth.json"),
480
+ trimmed(env.XDG_CONFIG_HOME) ? path.join(env.XDG_CONFIG_HOME, "com.vercel.cli", "auth.json") : void 0,
481
+ trimmed(env.XDG_DATA_HOME) ? path.join(env.XDG_DATA_HOME, "com.vercel.cli", "auth.json") : void 0,
482
+ path.join(home, ".config", "com.vercel.cli", "auth.json"),
483
+ path.join(home, ".local", "share", "com.vercel.cli", "auth.json"),
484
+ path.join(home, ".vercel", "auth.json"),
485
+ path.join(home, ".now", "auth.json")
486
+ ];
487
+ for (const filename of paths) {
488
+ if (!filename) continue;
489
+ const value = await readJson$1(filename);
490
+ const token = isRecord(value) ? trimmed(value.token) : void 0;
491
+ if (token) return token;
492
+ }
493
+ }
494
+ async function resolveLinkedProject(cwd, env) {
495
+ const projectId = trimmed(env.VERCEL_PROJECT_ID);
496
+ const orgId = trimmed(env.VERCEL_ORG_ID);
497
+ if (projectId && orgId) return {
498
+ projectId,
499
+ orgId
500
+ };
501
+ let directory = path.resolve(cwd);
502
+ while (true) {
503
+ const value = await readJson$1(path.join(directory, ".vercel/project.json"));
504
+ if (isRecord(value)) {
505
+ const linkedProjectId = trimmed(value.projectId);
506
+ const linkedOrgId = trimmed(value.orgId);
507
+ if (linkedProjectId && linkedOrgId) return {
508
+ projectId: linkedProjectId,
509
+ orgId: linkedOrgId
510
+ };
511
+ }
512
+ const parent = path.dirname(directory);
513
+ if (parent === directory) return void 0;
514
+ directory = parent;
515
+ }
516
+ }
517
+ async function fetchAutomationBypass(options) {
518
+ const url = new URL(`https://api.vercel.com/v9/projects/${encodeURIComponent(options.project.projectId)}`);
519
+ if (options.project.orgId.startsWith("team_")) url.searchParams.set("teamId", options.project.orgId);
520
+ let response;
521
+ try {
522
+ response = await options.fetch(url, { headers: { authorization: `Bearer ${options.token}` } });
523
+ } catch {
524
+ return;
525
+ }
526
+ if (!response.ok) return void 0;
527
+ let value;
528
+ try {
529
+ value = await response.json();
530
+ } catch {
531
+ return;
532
+ }
533
+ if (!isRecord(value) || !isRecord(value.protectionBypass)) return;
534
+ for (const [secret, metadata] of Object.entries(value.protectionBypass)) if (isRecord(metadata) && metadata.scope === "automation-bypass") return secret;
535
+ }
536
+ async function readJson$1(filename) {
537
+ try {
538
+ return JSON.parse(await readFile(filename, "utf8"));
539
+ } catch {
540
+ return;
541
+ }
542
+ }
543
+ function trimmed(value) {
544
+ if (typeof value !== "string") return void 0;
545
+ return value.trim() || void 0;
546
+ }
438
547
  function isRecord(value) {
439
548
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
440
549
  }
@@ -451,7 +560,7 @@ async function runCapableCommand(argv, options = {}) {
451
560
  return 0;
452
561
  }
453
562
  if (command.command === "cli") return runCli({
454
- app: await resolveCliApp(command.app, options),
563
+ app: await resolveCliApp(command.app, command.protectionBypass, options),
455
564
  argv: command.argv,
456
565
  ...!options.stdout && process.stdout.isTTY ? { isTTY: true } : {},
457
566
  ...!options.stdout && process.stdout.columns ? { columns: process.stdout.columns } : {},
@@ -607,6 +716,7 @@ function parseInit(argv) {
607
716
  function parseCli(argv) {
608
717
  const values = [...argv];
609
718
  let app;
719
+ let protectionBypass;
610
720
  while (values.length) {
611
721
  const token = values[0];
612
722
  if (token === "--help" || token === "-h") return {
@@ -617,14 +727,24 @@ function parseCli(argv) {
617
727
  values.shift();
618
728
  break;
619
729
  }
620
- if (token !== "--app") break;
621
- values.shift();
622
- if (app) throw new UsageError("Specify a CLI App once.");
623
- app = takeValue(values, token);
730
+ if (token === "--app") {
731
+ values.shift();
732
+ if (app) throw new UsageError("Specify a CLI App once.");
733
+ app = takeValue(values, token);
734
+ continue;
735
+ }
736
+ if (token === "--protection-bypass") {
737
+ values.shift();
738
+ if (protectionBypass) throw new UsageError("Specify a protection bypass once.");
739
+ protectionBypass = takeValue(values, token);
740
+ continue;
741
+ }
742
+ break;
624
743
  }
625
744
  return {
626
745
  command: "cli",
627
746
  ...app ? { app } : {},
747
+ ...protectionBypass ? { protectionBypass } : {},
628
748
  argv: values
629
749
  };
630
750
  }
@@ -647,8 +767,20 @@ function capitalize(value) {
647
767
  function shellArgument(value) {
648
768
  return /^[a-zA-Z0-9_./-]+$/.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
649
769
  }
650
- async function resolveCliApp(configured, options) {
651
- if (configured && isHttpUrl(configured)) return createRemoteApp(createHttpTransport({ url: new URL("/_capable/", configured) }));
770
+ async function resolveCliApp(configured, explicitProtectionBypass, options) {
771
+ if (configured && isHttpUrl(configured)) {
772
+ const env = options.env ?? process.env;
773
+ const protectionBypass = await resolveVercelProtectionBypass({
774
+ baseUrl: configured,
775
+ cwd: path.resolve(options.cwd ?? process.cwd()),
776
+ env,
777
+ ...explicitProtectionBypass ? { explicit: explicitProtectionBypass } : {}
778
+ });
779
+ return createRemoteApp(createHttpTransport({
780
+ url: new URL("/_capable/", configured),
781
+ fetch: createRemoteAppFetch(protectionBypass)
782
+ }));
783
+ }
652
784
  const project = await resolveCapableProject({
653
785
  ...configured ? { project: configured } : {},
654
786
  ...options.cwd ? { cwd: options.cwd } : {},
@@ -675,6 +807,35 @@ function isHttpUrl(value) {
675
807
  return false;
676
808
  }
677
809
  }
810
+ function createRemoteAppFetch(protectionBypass) {
811
+ let bypassRequired = false;
812
+ return async (request) => {
813
+ if (bypassRequired && protectionBypass) {
814
+ const response = await fetch(withVercelProtectionBypass(request, protectionBypass));
815
+ if (isVercelProtectionResponse(response)) throw vercelProtectionError();
816
+ return response;
817
+ }
818
+ const retry = protectionBypass ? withVercelProtectionBypass(request.clone(), protectionBypass) : void 0;
819
+ const response = await fetch(request);
820
+ if (!isVercelProtectionResponse(response)) return response;
821
+ if (!retry) throw vercelProtectionError();
822
+ bypassRequired = true;
823
+ const retried = await fetch(retry);
824
+ if (isVercelProtectionResponse(retried)) throw vercelProtectionError();
825
+ return retried;
826
+ };
827
+ }
828
+ function withVercelProtectionBypass(request, protectionBypass) {
829
+ const headers = new Headers(request.headers);
830
+ headers.set("x-vercel-protection-bypass", protectionBypass);
831
+ return new Request(request, { headers });
832
+ }
833
+ function isVercelProtectionResponse(response) {
834
+ return response.url.startsWith("https://vercel.com/sso-api") || response.url.startsWith("https://vercel.com/login");
835
+ }
836
+ function vercelProtectionError() {
837
+ return /* @__PURE__ */ new Error("Vercel Deployment Protection blocked the remote App. Run `vercel link` while logged in, set VERCEL_AUTOMATION_BYPASS_SECRET to a valid Protection Bypass for Automation secret, or use a public production domain.");
838
+ }
678
839
  function isFetchServer(value) {
679
840
  return Boolean(value && typeof value === "object" && typeof value.fetch === "function");
680
841
  }