@contentful/experience-design-system-cli 2.32.1-dev-build-10912f6.0 → 2.32.1-dev-build-1c6a348.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experience-design-system-cli",
3
- "version": "2.32.1-dev-build-10912f6.0",
3
+ "version": "2.32.1-dev-build-1c6a348.0",
4
4
  "description": "Contentful Experiences design system import CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,24 @@
1
+ export interface AbstractApiClientOptions {
2
+ host?: string;
3
+ cmaToken: string;
4
+ spaceId: string;
5
+ environmentId: string;
6
+ }
7
+ /**
8
+ * Shared base for CmaApiClient + EdsiApiClient. Owns the fields, URL
9
+ * helpers, and the /users/me validateToken flow that both clients need.
10
+ * Subclasses override validateToken() when they need to add
11
+ * service-specific follow-ups (e.g. EdsiApiClient calls checkPreflight()
12
+ * after the base check).
13
+ */
14
+ export declare abstract class AbstractApiClient {
15
+ protected readonly host: string;
16
+ protected readonly token: string;
17
+ protected readonly spaceId: string;
18
+ protected readonly environmentId: string;
19
+ constructor(opts: AbstractApiClientOptions);
20
+ protected base(): string;
21
+ protected buildHeaders(): Record<string, string>;
22
+ validateToken(): Promise<void>;
23
+ protected onValidateTokenResponse(_res: Response): void;
24
+ }
@@ -0,0 +1,8 @@
1
+ import { AbstractApiClient } from './abstract-api-client.js';
2
+ import type { CmaClientOptions } from '../../interfaces/clients/cma-client-options.js';
3
+ import type { ExistingEntitiesResponse } from '../../interfaces/responses/existing-entities-response.js';
4
+ export declare class CmaApiClient extends AbstractApiClient {
5
+ constructor(opts: CmaClientOptions);
6
+ listExistingEntities(): Promise<ExistingEntitiesResponse>;
7
+ private listAll;
8
+ }
@@ -0,0 +1,44 @@
1
+ import type { ManifestPayload, ServerPreviewResponse, ApplyOperationResponse, BreakingChange } from '@contentful/experience-design-system-types';
2
+ import { AbstractApiClient } from './abstract-api-client.js';
3
+ import type { EdsiClientOptions } from '../../interfaces/clients/edsi-client-options.js';
4
+ import type { PollOptions } from '../../interfaces/clients/poll-options.js';
5
+ export declare const DEFAULT_HOST = "https://api.contentful.com";
6
+ export declare const PREVIEW_ERROR_PREFIX = "preview failed:";
7
+ export declare const APPLY_ERROR_PREFIX = "apply failed:";
8
+ export declare const VALIDATION_FAILED_CODE = "\"ValidationFailed\"";
9
+ export interface PreviewValidationError {
10
+ componentName: string;
11
+ path: string;
12
+ message: string;
13
+ }
14
+ /**
15
+ * Parse the JSON body of a 422 from `previewImport()` into structured
16
+ * per-component validation errors. Returns [] for any malformed input
17
+ * so callers can fall back to the generic error path without try/catch.
18
+ *
19
+ * Path shape: `manifest:components/<Name>/$slots/<key>` or
20
+ * `manifest:components/<Name>/$properties/<key>`. Only the component
21
+ * name is extracted today; `path` and `message` are kept verbatim so
22
+ * future surfaces (debug logging, headless retry in SP-4) can render
23
+ * the field-level detail.
24
+ */
25
+ export declare function parsePreviewValidationErrors(body: string): PreviewValidationError[];
26
+ export declare function sanitizeBreakingChanges(raw: unknown): BreakingChange[];
27
+ export declare class EdsiApiClient extends AbstractApiClient {
28
+ private retry;
29
+ private lastRequestId?;
30
+ getLastRequestId(): string | undefined;
31
+ private noteRequestId;
32
+ protected onValidateTokenResponse(res: Response): void;
33
+ constructor(opts: EdsiClientOptions);
34
+ private headers;
35
+ private requestWithRetry;
36
+ validateToken(): Promise<void>;
37
+ checkPreflight(): Promise<void>;
38
+ previewImport(manifest: ManifestPayload, allowDeletions?: boolean): Promise<ServerPreviewResponse>;
39
+ applyImport(manifest: ManifestPayload, options: {
40
+ acknowledgeBreakingChanges: boolean;
41
+ allowDeletions?: boolean;
42
+ }): Promise<ApplyOperationResponse>;
43
+ pollOperation(operationId: string, opts?: PollOptions): Promise<ApplyOperationResponse>;
44
+ }
@@ -0,0 +1,10 @@
1
+ export { CmaApiClient } from './clients/cma-client.js';
2
+ export { EdsiApiClient, DEFAULT_HOST, PREVIEW_ERROR_PREFIX, APPLY_ERROR_PREFIX, VALIDATION_FAILED_CODE, parsePreviewValidationErrors, sanitizeBreakingChanges, } from './clients/edsi-client.js';
3
+ export type { PreviewValidationError } from './clients/edsi-client.js';
4
+ export { ApiError } from '../errors/api-error.js';
5
+ export type { CmaClientOptions } from '../interfaces/clients/cma-client-options.js';
6
+ export type { EdsiClientOptions } from '../interfaces/clients/edsi-client-options.js';
7
+ export type { PollOptions } from '../interfaces/clients/poll-options.js';
8
+ export type { ExistingComponentEntity } from '../interfaces/responses/existing-component-entity.js';
9
+ export type { ExistingTokenEntity } from '../interfaces/responses/existing-token-entity.js';
10
+ export type { ExistingEntitiesResponse } from '../interfaces/responses/existing-entities-response.js';
@@ -1,68 +1,4 @@
1
- import type { ManifestPayload, ServerPreviewResponse, ApplyOperationResponse, BreakingChange } from '@contentful/experience-design-system-types';
2
- export declare const DEFAULT_HOST = "https://api.contentful.com";
3
- export declare const PREVIEW_ERROR_PREFIX = "preview failed:";
4
- export declare const APPLY_ERROR_PREFIX = "apply failed:";
5
- export declare const VALIDATION_FAILED_CODE = "\"ValidationFailed\"";
6
- export interface ApiClientOptions {
7
- host?: string;
8
- cmaToken: string;
9
- spaceId: string;
10
- environmentId: string;
11
- retry?: {
12
- maxAttempts?: number;
13
- initialDelayMs?: number;
14
- maxDelayMs?: number;
15
- sleep?: (delayMs: number) => Promise<void>;
16
- };
17
- }
18
- export declare class ApiError extends Error {
19
- readonly status: number;
20
- readonly body: string;
21
- readonly guidance?: string | undefined;
22
- constructor(message: string, status: number, body: string, guidance?: string | undefined);
23
- }
24
- export interface PreviewValidationError {
25
- componentName: string;
26
- path: string;
27
- message: string;
28
- }
29
- /**
30
- * Parse the JSON body of a 422 from `previewImport()` into structured
31
- * per-component validation errors. Returns [] for any malformed input
32
- * so callers can fall back to the generic error path without try/catch.
33
- *
34
- * Path shape: `manifest:components/<Name>/$slots/<key>` or
35
- * `manifest:components/<Name>/$properties/<key>`. Only the component
36
- * name is extracted today; `path` and `message` are kept verbatim so
37
- * future surfaces (debug logging, headless retry in SP-4) can render
38
- * the field-level detail.
39
- */
40
- export declare function parsePreviewValidationErrors(body: string): PreviewValidationError[];
41
- export declare function sanitizeBreakingChanges(raw: unknown): BreakingChange[];
42
- export declare class ImportApiClient {
43
- private host;
44
- private token;
45
- private spaceId;
46
- private environmentId;
47
- private retry;
48
- private lastRequestId?;
49
- getLastRequestId(): string | undefined;
50
- private noteRequestId;
51
- constructor(opts: ApiClientOptions);
52
- private base;
53
- private headers;
54
- private requestWithRetry;
55
- validateToken(): Promise<void>;
56
- checkPreflight(): Promise<void>;
57
- previewImport(manifest: ManifestPayload, allowDeletions?: boolean): Promise<ServerPreviewResponse>;
58
- applyImport(manifest: ManifestPayload, options: {
59
- acknowledgeBreakingChanges: boolean;
60
- allowDeletions?: boolean;
61
- }): Promise<ApplyOperationResponse>;
62
- pollOperation(operationId: string, opts?: {
63
- intervalMs?: number;
64
- maxIntervalMs?: number;
65
- maxAttempts?: number;
66
- onProgress?: (op: ApplyOperationResponse) => void;
67
- }): Promise<ApplyOperationResponse>;
68
- }
1
+ export { EdsiApiClient, EdsiApiClient as ImportApiClient, DEFAULT_HOST, PREVIEW_ERROR_PREFIX, APPLY_ERROR_PREFIX, VALIDATION_FAILED_CODE, parsePreviewValidationErrors, sanitizeBreakingChanges, } from '../api/clients/edsi-client.js';
2
+ export type { PreviewValidationError } from '../api/clients/edsi-client.js';
3
+ export { ApiError } from '../errors/api-error.js';
4
+ export type { EdsiClientOptions as ApiClientOptions } from '../interfaces/clients/edsi-client-options.js';
@@ -0,0 +1,6 @@
1
+ export declare class ApiError extends Error {
2
+ readonly status: number;
3
+ readonly body: string;
4
+ readonly guidance?: string | undefined;
5
+ constructor(message: string, status: number, body: string, guidance?: string | undefined);
6
+ }
@@ -0,0 +1,4 @@
1
+ export declare function buildHeaders(token: string): Record<string, string>;
2
+ export declare function request(url: string, options: RequestInit & {
3
+ token: string;
4
+ }): Promise<Response>;
@@ -0,0 +1,4 @@
1
+ export declare const DEFAULT_API_HOST = "https://api.contentful.com";
2
+ export declare const DEFAULT_CONFIGURED_HOST = "api.contentful.com";
3
+ export declare function toConfiguredHost(host?: string): string | undefined;
4
+ export declare function toApiHost(host?: string): string;
@@ -1,4 +1 @@
1
- export declare const DEFAULT_API_HOST = "https://api.contentful.com";
2
- export declare const DEFAULT_CONFIGURED_HOST = "api.contentful.com";
3
- export declare function toConfiguredHost(host?: string): string | undefined;
4
- export declare function toApiHost(host?: string): string;
1
+ export { DEFAULT_API_HOST, DEFAULT_CONFIGURED_HOST, toConfiguredHost, toApiHost } from './helpers/url.js';
@@ -7,6 +7,7 @@ export interface PipelineOptions {
7
7
  cmaToken?: string;
8
8
  agent: string;
9
9
  model?: string;
10
+ bedrock?: boolean;
10
11
  skipAnalyze: boolean;
11
12
  skipGenerate: boolean;
12
13
  print: boolean;
@@ -27,6 +28,15 @@ export interface PipelineOptions {
27
28
  /** When true, auto-reject cycle participants and retry push instead of surfacing an error. */
28
29
  autoRejectCycles?: boolean;
29
30
  allowDeletions?: boolean;
31
+ /**
32
+ * Fetch existing Components + DesignTokens from the target space+env
33
+ * and persist them under outDir/.existing-entities.json so downstream
34
+ * agent steps can consume them as context. Requires spaceId +
35
+ * environmentId + cmaToken; skipped with a warning otherwise. No-op
36
+ * for the agent flow in this PR — the file is written but nothing
37
+ * reads it yet.
38
+ */
39
+ withSpaceContext?: boolean;
30
40
  compositionMode?: CompositionMode;
31
41
  compositionMap?: string;
32
42
  compositionAgent?: boolean;
@@ -7,6 +7,7 @@ export declare function buildSelectAgentArgs(opts: {
7
7
  sessionId: string;
8
8
  agent: string;
9
9
  model?: string;
10
+ bedrock?: boolean;
10
11
  selectPromptPath?: string;
11
12
  noCache?: boolean;
12
13
  }): string[];
@@ -23,6 +24,7 @@ export declare function buildGenerateComponentsArgs(opts: {
23
24
  tokensPath?: string;
24
25
  agent: string;
25
26
  model?: string;
27
+ bedrock?: boolean;
26
28
  noCache?: boolean;
27
29
  generatePromptPath?: string;
28
30
  }): string[];
@@ -49,6 +51,7 @@ export type WizardAppProps = {
49
51
  initialHost?: string;
50
52
  initialAgent?: string;
51
53
  initialModel?: string;
54
+ bedrock?: boolean;
52
55
  initialProjectPath?: string;
53
56
  host?: string;
54
57
  autoAcceptScope?: boolean;
@@ -80,4 +83,4 @@ export type WizardAppProps = {
80
83
  onRunPicked?: (selection: RunPickerSelection) => void;
81
84
  allowDeletions?: boolean;
82
85
  };
83
- export declare function WizardApp({ initialSpaceId, initialEnvironmentId, initialCmaToken, initialHost, initialAgent, initialModel, initialProjectPath, host, autoAcceptScope, autoRejectCycles, compositionMode, compositionMap, compositionAgent, compositionAgentMode, compositionRefresh, generateMap, promptOverrides, noCache, autoFilter, livePreview, noPush, noSave, outDirOverride, onConflictMode, selectPromptPath, generatePromptPath, skipMapTokens, seedExtractSessionId, seedGenerateSessionId, seedTokenSessionId, seedTokensPath, initialStep, initialRawTokensPath, initialRuns, onRunPicked, allowDeletions, }?: WizardAppProps): React.ReactElement;
86
+ export declare function WizardApp({ initialSpaceId, initialEnvironmentId, initialCmaToken, initialHost, initialAgent, initialModel, bedrock, initialProjectPath, host, autoAcceptScope, autoRejectCycles, compositionMode, compositionMap, compositionAgent, compositionAgentMode, compositionRefresh, generateMap, promptOverrides, noCache, autoFilter, livePreview, noPush, noSave, outDirOverride, onConflictMode, selectPromptPath, generatePromptPath, skipMapTokens, seedExtractSessionId, seedGenerateSessionId, seedTokenSessionId, seedTokensPath, initialStep, initialRawTokensPath, initialRuns, onRunPicked, allowDeletions, }?: WizardAppProps): React.ReactElement;
package/dist/src/index.js CHANGED
@@ -275,51 +275,70 @@ function resolveBinary(agent) {
275
275
  return override.trim();
276
276
  return AGENT_BINARIES[agent];
277
277
  }
278
- function resolveAgentModel(agent, explicit) {
278
+ function agentSupportsBedrock(agent) {
279
+ return BEDROCK_CAPABLE_AGENTS.has(agent);
280
+ }
281
+ function resolveAgentModel(agent, explicit, bedrock = false) {
279
282
  if (explicit && explicit.trim())
280
283
  return explicit.trim();
281
284
  const override = process.env[`EDS_AGENT_MODEL_${agent.toUpperCase()}`];
282
285
  if (override && override.trim())
283
286
  return override.trim();
287
+ if (bedrock && agent === "codex")
288
+ return DEFAULT_CODEX_BEDROCK_MODEL;
289
+ if (bedrock && agent === "opencode")
290
+ return withBedrockProviderPrefix(DEFAULT_MODELS.opencode);
284
291
  return DEFAULT_MODELS[agent];
285
292
  }
286
- function buildArgs(agent, prompt2, model, promptViaStdin = false) {
287
- const resolvedModel = resolveAgentModel(agent, model);
288
- const modelArg = resolvedModel ? ["--model", resolvedModel] : [];
293
+ function withBedrockProviderPrefix(model) {
294
+ return model.includes("/") ? model : `amazon-bedrock/${model}`;
295
+ }
296
+ function codexBedrockConfigArgs() {
297
+ const region = process.env.AWS_REGION?.trim() || process.env.AWS_DEFAULT_REGION?.trim() || DEFAULT_CODEX_BEDROCK_REGION;
298
+ return ["-c", "model_provider=amazon-bedrock", "-c", `model_providers.amazon-bedrock.region=${region}`];
299
+ }
300
+ function buildArgs(agent, prompt2, model, promptViaStdin = false, bedrock = false) {
301
+ const modelArg = ["--model", resolveAgentModel(agent, model, bedrock)];
289
302
  const promptArg = promptViaStdin ? [] : [prompt2];
290
303
  switch (agent) {
291
304
  case "claude":
292
305
  return ["--print", ...modelArg, ...promptArg];
293
- case "codex":
294
- return ["exec", ...modelArg, "--dangerously-bypass-approvals-and-sandbox", ...promptArg];
306
+ case "codex": {
307
+ const bedrockArgs = bedrock ? codexBedrockConfigArgs() : [];
308
+ return ["exec", ...bedrockArgs, ...modelArg, "--dangerously-bypass-approvals-and-sandbox", ...promptArg];
309
+ }
295
310
  case "opencode":
296
311
  return ["run", ...modelArg, ...promptArg];
297
312
  case "cursor":
298
313
  return ["--print", ...modelArg, ...promptArg];
299
314
  case "copilot": {
300
315
  const copilotModel = resolveAgentModel("copilot", model);
301
- const copilotModelArg = !copilotModel || copilotModel === "Auto" ? [] : ["--model", copilotModel];
316
+ const copilotModelArg = copilotModel === "Auto" ? [] : ["--model", copilotModel];
302
317
  return ["-p", ...promptArg, ...copilotModelArg, "--allow-all-tools"];
303
318
  }
304
319
  }
305
320
  }
306
321
  async function runAgent(options) {
307
322
  const { agent, prompt: prompt2, timeoutMs, model, onOutput, promptViaStdin, onDebugEvent } = options;
323
+ const bedrock = options.bedrock ?? process.env.EDS_BEDROCK === "1";
308
324
  const binary = resolveBinary(agent);
309
325
  const useStdin2 = !!promptViaStdin;
310
- const args = buildArgs(agent, prompt2, model, useStdin2);
326
+ const args = buildArgs(agent, prompt2, model, useStdin2, bedrock);
311
327
  const startedAt = Date.now();
312
328
  onDebugEvent?.("run.start", {
313
329
  agent,
314
330
  binary,
315
331
  model,
332
+ bedrock: !!bedrock,
316
333
  timeoutMs,
317
334
  promptLen: prompt2.length,
318
335
  promptHead: prompt2.slice(0, 500)
319
336
  });
320
337
  return new Promise((resolve27) => {
338
+ const bedrockEnv = bedrock ? BEDROCK_ENV_BY_AGENT[agent] : void 0;
321
339
  const child = spawn(binary, args, {
322
- stdio: ["pipe", "pipe", "pipe"]
340
+ stdio: ["pipe", "pipe", "pipe"],
341
+ ...bedrockEnv ? { env: { ...process.env, ...bedrockEnv } } : {}
323
342
  });
324
343
  if (useStdin2 && child.stdin) {
325
344
  child.stdin.on("error", () => {
@@ -437,7 +456,7 @@ function extractSentinelOutput(stdout) {
437
456
  return "multiple";
438
457
  return stdout.slice(startIdx + START.length, endIdx).trim();
439
458
  }
440
- var VALID_SELECT_TOOL_NAMES, VALID_TOOL_NAMES, VALID_TOKEN_TOOL_NAMES, VALID_CDF_TYPES, VALID_CATEGORIES, AGENT_BINARIES, DEFAULT_MODELS;
459
+ var VALID_SELECT_TOOL_NAMES, VALID_TOOL_NAMES, VALID_TOKEN_TOOL_NAMES, VALID_CDF_TYPES, VALID_CATEGORIES, AGENT_BINARIES, BEDROCK_ENV_BY_AGENT, BEDROCK_CAPABLE_AGENTS, DEFAULT_CODEX_BEDROCK_REGION, DEFAULT_MODELS, DEFAULT_CODEX_BEDROCK_MODEL;
441
460
  var init_agent_runner = __esm({
442
461
  "packages/experience-design-system-generation/dist/src/agent-runner.js"() {
443
462
  "use strict";
@@ -454,14 +473,22 @@ var init_agent_runner = __esm({
454
473
  cursor: "cursor-agent",
455
474
  copilot: "copilot"
456
475
  };
476
+ BEDROCK_ENV_BY_AGENT = {
477
+ claude: { CLAUDE_CODE_USE_BEDROCK: "1" }
478
+ };
479
+ BEDROCK_CAPABLE_AGENTS = /* @__PURE__ */ new Set(["claude", "codex", "opencode"]);
480
+ DEFAULT_CODEX_BEDROCK_REGION = "us-east-1";
457
481
  DEFAULT_MODELS = {
458
482
  claude: "haiku",
483
+ codex: "gpt-5.6-luna",
484
+ // requires OPENAI_API_KEY; ChatGPT account users must pass --model
459
485
  opencode: "claude-haiku-4-5",
460
486
  cursor: "gpt-mini",
461
487
  // cursor alias for gpt-5.4-mini-medium; haiku not in cursor's catalog
462
488
  copilot: "Auto"
463
489
  // the only model guaranteed on every Copilot plan (Free/Pro/Business/Enterprise); Pro+ users override via EDS_AGENT_MODEL_COPILOT
464
490
  };
491
+ DEFAULT_CODEX_BEDROCK_MODEL = "openai.gpt-5.6-luna";
465
492
  }
466
493
  });
467
494
 
@@ -851,6 +878,7 @@ var src_exports = {};
851
878
  __export(src_exports, {
852
879
  AGENT_NAMES: () => AGENT_NAMES,
853
880
  DEFAULT_AGENT_NAME: () => DEFAULT_AGENT_NAME,
881
+ agentSupportsBedrock: () => agentSupportsBedrock,
854
882
  buildArgs: () => buildArgs,
855
883
  buildPrompt: () => buildPrompt,
856
884
  checkAgentAuth: () => checkAgentAuth,
@@ -12575,7 +12603,7 @@ var init_src3 = __esm({
12575
12603
  }
12576
12604
  });
12577
12605
 
12578
- // packages/experience-design-system-cli/src/host-utils.ts
12606
+ // packages/experience-design-system-cli/src/helpers/url.ts
12579
12607
  function trimTrailingSlashes(value) {
12580
12608
  return value.replace(/\/+$/, "");
12581
12609
  }
@@ -12598,8 +12626,8 @@ function toApiHost(host) {
12598
12626
  return `https://${normalized}`;
12599
12627
  }
12600
12628
  var DEFAULT_API_HOST, DEFAULT_CONFIGURED_HOST;
12601
- var init_host_utils = __esm({
12602
- "packages/experience-design-system-cli/src/host-utils.ts"() {
12629
+ var init_url = __esm({
12630
+ "packages/experience-design-system-cli/src/helpers/url.ts"() {
12603
12631
  "use strict";
12604
12632
  DEFAULT_API_HOST = "https://api.contentful.com";
12605
12633
  DEFAULT_CONFIGURED_HOST = "api.contentful.com";
@@ -12806,7 +12834,99 @@ var init_user_agent = __esm({
12806
12834
  }
12807
12835
  });
12808
12836
 
12809
- // packages/experience-design-system-cli/src/apply/api-client.ts
12837
+ // packages/experience-design-system-cli/src/helpers/http.ts
12838
+ function buildHeaders(token) {
12839
+ return {
12840
+ Authorization: `Bearer ${token}`,
12841
+ "Content-Type": "application/json",
12842
+ "X-Contentful-User-Agent": buildUserAgent()
12843
+ };
12844
+ }
12845
+ async function request(url, options) {
12846
+ const init = {
12847
+ method: options.method ?? "GET",
12848
+ headers: buildHeaders(options.token)
12849
+ };
12850
+ if (options.body) init.body = options.body;
12851
+ return fetch(url, init);
12852
+ }
12853
+ var init_http = __esm({
12854
+ "packages/experience-design-system-cli/src/helpers/http.ts"() {
12855
+ "use strict";
12856
+ init_user_agent();
12857
+ }
12858
+ });
12859
+
12860
+ // packages/experience-design-system-cli/src/errors/api-error.ts
12861
+ var ERROR_BODY_LOG_CAP, ApiError;
12862
+ var init_api_error = __esm({
12863
+ "packages/experience-design-system-cli/src/errors/api-error.ts"() {
12864
+ "use strict";
12865
+ ERROR_BODY_LOG_CAP = 16384;
12866
+ ApiError = class extends Error {
12867
+ constructor(message, status, body, guidance) {
12868
+ super(message);
12869
+ this.status = status;
12870
+ this.body = body;
12871
+ this.guidance = guidance;
12872
+ if (body) {
12873
+ const trimmed = body.length > ERROR_BODY_LOG_CAP ? body.slice(0, ERROR_BODY_LOG_CAP) + "\u2026" : body;
12874
+ this.message = `${message}
12875
+ ${trimmed}`;
12876
+ }
12877
+ }
12878
+ status;
12879
+ body;
12880
+ guidance;
12881
+ };
12882
+ }
12883
+ });
12884
+
12885
+ // packages/experience-design-system-cli/src/api/clients/abstract-api-client.ts
12886
+ var AbstractApiClient;
12887
+ var init_abstract_api_client = __esm({
12888
+ "packages/experience-design-system-cli/src/api/clients/abstract-api-client.ts"() {
12889
+ "use strict";
12890
+ init_url();
12891
+ init_http();
12892
+ init_api_error();
12893
+ AbstractApiClient = class {
12894
+ host;
12895
+ token;
12896
+ spaceId;
12897
+ environmentId;
12898
+ constructor(opts) {
12899
+ this.host = toApiHost(opts.host);
12900
+ this.token = opts.cmaToken;
12901
+ this.spaceId = opts.spaceId;
12902
+ this.environmentId = opts.environmentId;
12903
+ }
12904
+ base() {
12905
+ return `${this.host}/spaces/${this.spaceId}/environments/${this.environmentId}`;
12906
+ }
12907
+ buildHeaders() {
12908
+ return buildHeaders(this.token);
12909
+ }
12910
+ async validateToken() {
12911
+ const url = `${this.host}/users/me`;
12912
+ const res = await request(url, { token: this.token });
12913
+ this.onValidateTokenResponse(res);
12914
+ if (res.status === 401) {
12915
+ throw new ApiError("CMA token is invalid or revoked", res.status, await res.text());
12916
+ }
12917
+ if (!res.ok) {
12918
+ throw new ApiError(`unexpected error validating token: ${res.status}`, res.status, await res.text());
12919
+ }
12920
+ }
12921
+ // Hook for subclasses to observe the raw /users/me response (e.g. capture
12922
+ // x-contentful-request-id). Default is a no-op.
12923
+ onValidateTokenResponse(_res) {
12924
+ }
12925
+ };
12926
+ }
12927
+ });
12928
+
12929
+ // packages/experience-design-system-cli/src/api/clients/edsi-client.ts
12810
12930
  function defaultSleep(delayMs) {
12811
12931
  return new Promise((resolve27) => setTimeout(resolve27, delayMs));
12812
12932
  }
@@ -12889,48 +13009,20 @@ function isApsDenialBody(body) {
12889
13009
  return false;
12890
13010
  }
12891
13011
  }
12892
- async function request(url, options) {
12893
- const headers = {
12894
- Authorization: `Bearer ${options.token}`,
12895
- "Content-Type": "application/json",
12896
- "X-Contentful-User-Agent": buildUserAgent()
12897
- };
12898
- const init = {
12899
- method: options.method ?? "GET",
12900
- headers
12901
- };
12902
- if (options.body) init.body = options.body;
12903
- return fetch(url, init);
12904
- }
12905
- var PREVIEW_ERROR_PREFIX, APPLY_ERROR_PREFIX, VALIDATION_FAILED_CODE, MAX_RETRY_AFTER_MS, ERROR_BODY_LOG_CAP, ApiError, COMPONENT_PATH_PREFIX, PROPERTY_BREAKING_REASONS, SLOT_BREAKING_REASONS, ImportApiClient;
12906
- var init_api_client = __esm({
12907
- "packages/experience-design-system-cli/src/apply/api-client.ts"() {
13012
+ var PREVIEW_ERROR_PREFIX, APPLY_ERROR_PREFIX, VALIDATION_FAILED_CODE, MAX_RETRY_AFTER_MS, COMPONENT_PATH_PREFIX, PROPERTY_BREAKING_REASONS, SLOT_BREAKING_REASONS, EdsiApiClient;
13013
+ var init_edsi_client = __esm({
13014
+ "packages/experience-design-system-cli/src/api/clients/edsi-client.ts"() {
12908
13015
  "use strict";
12909
13016
  init_src3();
12910
- init_host_utils();
13017
+ init_url();
12911
13018
  init_debug_logger();
12912
- init_user_agent();
13019
+ init_http();
13020
+ init_api_error();
13021
+ init_abstract_api_client();
12913
13022
  PREVIEW_ERROR_PREFIX = "preview failed:";
12914
13023
  APPLY_ERROR_PREFIX = "apply failed:";
12915
13024
  VALIDATION_FAILED_CODE = '"ValidationFailed"';
12916
13025
  MAX_RETRY_AFTER_MS = 6e4;
12917
- ERROR_BODY_LOG_CAP = 16384;
12918
- ApiError = class extends Error {
12919
- constructor(message, status, body, guidance) {
12920
- super(message);
12921
- this.status = status;
12922
- this.body = body;
12923
- this.guidance = guidance;
12924
- if (body) {
12925
- const trimmed = body.length > ERROR_BODY_LOG_CAP ? body.slice(0, ERROR_BODY_LOG_CAP) + "\u2026" : body;
12926
- this.message = `${message}
12927
- ${trimmed}`;
12928
- }
12929
- }
12930
- status;
12931
- body;
12932
- guidance;
12933
- };
12934
13026
  COMPONENT_PATH_PREFIX = "manifest:components/";
12935
13027
  PROPERTY_BREAKING_REASONS = /* @__PURE__ */ new Set([
12936
13028
  "removed",
@@ -12939,11 +13031,7 @@ ${trimmed}`;
12939
13031
  "validation_narrowed"
12940
13032
  ]);
12941
13033
  SLOT_BREAKING_REASONS = /* @__PURE__ */ new Set(["slot_removed", "slot_allowed_components_narrowed"]);
12942
- ImportApiClient = class {
12943
- host;
12944
- token;
12945
- spaceId;
12946
- environmentId;
13034
+ EdsiApiClient = class extends AbstractApiClient {
12947
13035
  retry;
12948
13036
  lastRequestId;
12949
13037
  getLastRequestId() {
@@ -12953,11 +13041,11 @@ ${trimmed}`;
12953
13041
  const requestId = response.headers.get("x-contentful-request-id");
12954
13042
  if (requestId) this.lastRequestId = requestId;
12955
13043
  }
13044
+ onValidateTokenResponse(res) {
13045
+ this.noteRequestId(res);
13046
+ }
12956
13047
  constructor(opts) {
12957
- this.host = toApiHost(opts.host);
12958
- this.token = opts.cmaToken;
12959
- this.spaceId = opts.spaceId;
12960
- this.environmentId = opts.environmentId;
13048
+ super(opts);
12961
13049
  const initialDelayMs = Math.max(0, opts.retry?.initialDelayMs ?? 250);
12962
13050
  this.retry = {
12963
13051
  maxAttempts: Math.max(1, Math.floor(opts.retry?.maxAttempts ?? 3)),
@@ -12966,15 +13054,8 @@ ${trimmed}`;
12966
13054
  sleep: opts.retry?.sleep ?? defaultSleep
12967
13055
  };
12968
13056
  }
12969
- base() {
12970
- return `${this.host}/spaces/${this.spaceId}/environments/${this.environmentId}`;
12971
- }
12972
13057
  headers() {
12973
- return {
12974
- Authorization: `Bearer ${this.token}`,
12975
- "Content-Type": "application/json",
12976
- "X-Contentful-User-Agent": buildUserAgent()
12977
- };
13058
+ return this.buildHeaders();
12978
13059
  }
12979
13060
  async requestWithRetry(phase, errorPrefix, makeCall, context = {}) {
12980
13061
  const debug = getDebugLogger();
@@ -13041,15 +13122,7 @@ ${trimmed}`;
13041
13122
  throw new Error("Retry attempts exhausted");
13042
13123
  }
13043
13124
  async validateToken() {
13044
- const url = `${this.host}/users/me`;
13045
- const res = await request(url, { token: this.token });
13046
- this.noteRequestId(res);
13047
- if (res.status === 401) {
13048
- throw new ApiError("CMA token is invalid or revoked", res.status, await res.text());
13049
- }
13050
- if (!res.ok) {
13051
- throw new ApiError(`unexpected error validating token: ${res.status}`, res.status, await res.text());
13052
- }
13125
+ await super.validateToken();
13053
13126
  await this.checkPreflight();
13054
13127
  }
13055
13128
  // Probe the sources-api preflight endpoint to catch APS-denied users up-front,
@@ -13205,6 +13278,15 @@ ${trimmed}`;
13205
13278
  }
13206
13279
  });
13207
13280
 
13281
+ // packages/experience-design-system-cli/src/apply/api-client.ts
13282
+ var init_api_client = __esm({
13283
+ "packages/experience-design-system-cli/src/apply/api-client.ts"() {
13284
+ "use strict";
13285
+ init_edsi_client();
13286
+ init_api_error();
13287
+ }
13288
+ });
13289
+
13208
13290
  // packages/experience-design-system-cli/src/lib/error-parser.ts
13209
13291
  function stripLambdaLogPrefix(body) {
13210
13292
  let out = body.replace(LAMBDA_LOG_PREFIX_RE, "");
@@ -14193,6 +14275,14 @@ var init_strip_allowed_components = __esm({
14193
14275
  }
14194
14276
  });
14195
14277
 
14278
+ // packages/experience-design-system-cli/src/host-utils.ts
14279
+ var init_host_utils = __esm({
14280
+ "packages/experience-design-system-cli/src/host-utils.ts"() {
14281
+ "use strict";
14282
+ init_url();
14283
+ }
14284
+ });
14285
+
14196
14286
  // packages/experience-design-system-cli/src/credentials-store.ts
14197
14287
  var credentials_store_exports = {};
14198
14288
  __export(credentials_store_exports, {
@@ -14808,7 +14898,7 @@ async function resolveSharedInputs(opts) {
14808
14898
  if (opts.tokens) {
14809
14899
  tokens = await readTokensFromPath("--tokens", opts.tokens);
14810
14900
  }
14811
- const client2 = new ImportApiClient({
14901
+ const client2 = new EdsiApiClient({
14812
14902
  host: opts.host,
14813
14903
  cmaToken,
14814
14904
  spaceId,
@@ -15548,7 +15638,7 @@ function App({ sessionId: sessionId2, artifactsRoot, reviewRoot }) {
15548
15638
  tokens
15549
15639
  );
15550
15640
  if (!manifest.componentsManifest) manifest.componentsManifest = {};
15551
- const client2 = new ImportApiClient({ cmaToken, spaceId, environmentId });
15641
+ const client2 = new EdsiApiClient({ cmaToken, spaceId, environmentId });
15552
15642
  const preview = await client2.previewImport(manifest, true);
15553
15643
  const annotations = {};
15554
15644
  for (const item of preview.components.new) {
@@ -16570,7 +16660,7 @@ var init_save_path_resolver = __esm({
16570
16660
  });
16571
16661
 
16572
16662
  // packages/experience-design-system-cli/src/runs/store.ts
16573
- import { readFile as readFile22, writeFile as writeFile5, mkdir as mkdir6, rename } from "node:fs/promises";
16663
+ import { readFile as readFile22, writeFile as writeFile6, mkdir as mkdir6, rename } from "node:fs/promises";
16574
16664
  import { join as join20 } from "node:path";
16575
16665
  import { homedir as homedir7 } from "node:os";
16576
16666
  import { randomBytes as randomBytes2 } from "node:crypto";
@@ -16633,7 +16723,7 @@ async function writeAtomic(file) {
16633
16723
  await mkdir6(RUNS_DIR, { recursive: true });
16634
16724
  const body = JSON.stringify(file, null, 2) + "\n";
16635
16725
  const tmp = `${RUNS_PATH}.${process.pid}.${Date.now()}.tmp`;
16636
- await writeFile5(tmp, body, { mode: 384 });
16726
+ await writeFile6(tmp, body, { mode: 384 });
16637
16727
  await rename(tmp, RUNS_PATH);
16638
16728
  }
16639
16729
  async function appendRun(input) {
@@ -24115,7 +24205,7 @@ async function runLivePreview(opts) {
24115
24205
  tokens = await readTokensFromPath("tokens", tokensPath);
24116
24206
  }
24117
24207
  const manifest = buildManifest3(components, tokens, { deleteAllComponents: opts.deleteAllComponents === true });
24118
- const client2 = new ImportApiClient({ host, cmaToken, spaceId, environmentId });
24208
+ const client2 = new EdsiApiClient({ host, cmaToken, spaceId, environmentId });
24119
24209
  const startedAt = Date.now();
24120
24210
  let timeoutHandle;
24121
24211
  const timeoutPromise = new Promise((_resolve, reject) => {
@@ -27590,6 +27680,7 @@ import { jsx as jsx52, jsxs as jsxs51 } from "react/jsx-runtime";
27590
27680
  function buildSelectAgentArgs(opts) {
27591
27681
  const args = ["analyze", "select-agent", "--agent", opts.agent, "--session", opts.sessionId, "--exclude-invalid"];
27592
27682
  if (opts.model) args.push("--model", opts.model);
27683
+ if (opts.bedrock) args.push("--bedrock");
27593
27684
  if (opts.selectPromptPath) args.push("--select-prompt-path", opts.selectPromptPath);
27594
27685
  if (opts.noCache) args.push("--no-cache");
27595
27686
  return args;
@@ -27625,6 +27716,7 @@ function buildGenerateComponentsArgs(opts) {
27625
27716
  const args = ["generate", "components", "--agent", opts.agent, "--session", opts.sessionId];
27626
27717
  if (opts.tokensPath) args.push("--tokens", opts.tokensPath);
27627
27718
  if (opts.model) args.push("--model", opts.model);
27719
+ if (opts.bedrock) args.push("--bedrock");
27628
27720
  if (opts.noCache) args.push("--no-cache");
27629
27721
  if (opts.generatePromptPath) args.push("--generate-prompt-path", opts.generatePromptPath);
27630
27722
  return args;
@@ -27667,6 +27759,7 @@ function WizardApp({
27667
27759
  initialHost,
27668
27760
  initialAgent,
27669
27761
  initialModel,
27762
+ bedrock = false,
27670
27763
  initialProjectPath,
27671
27764
  host,
27672
27765
  autoAcceptScope = false,
@@ -27728,6 +27821,7 @@ function WizardApp({
27728
27821
  step: modifyEntryReady || rawTokensEntryReady || pushFromPickerReady ? initialStepResolved : initialRuns && initialRuns.length > 0 ? "run-picker" : initialStepResolved,
27729
27822
  agent: initialAgent ?? "claude",
27730
27823
  ...initialModel ? { agentModel: initialModel } : {},
27824
+ ...bedrock ? { bedrock: true } : {},
27731
27825
  projectPath: initialProjectPath ?? "",
27732
27826
  outDir: initialOutDir,
27733
27827
  rawTokensPath: rawTokensEntryReady ? initialRawTokensPath : "",
@@ -27867,6 +27961,7 @@ If you are using AWS Bedrock, run:
27867
27961
  const result = await new Promise((res) => {
27868
27962
  const tokenArgs = [findCliPath(), "generate", "tokens", "--agent", state.agent, "--raw-tokens", rawTokensPath];
27869
27963
  if (state.agentModel) tokenArgs.push("--model", state.agentModel);
27964
+ if (state.bedrock) tokenArgs.push("--bedrock");
27870
27965
  const child = spawn4("node", tokenArgs);
27871
27966
  let stdout2 = "";
27872
27967
  let stderr = "";
@@ -27987,6 +28082,7 @@ If you are using AWS Bedrock, run:
27987
28082
  if (generateMap) extractArgs.push("--generate-map", generateMap);
27988
28083
  for (const p of promptOverrides ?? []) extractArgs.push("--prompt", p);
27989
28084
  if (state.agent) extractArgs.push("--agent", state.agent);
28085
+ if (state.bedrock) extractArgs.push("--bedrock");
27990
28086
  }
27991
28087
  const child = spawn4("node", extractArgs);
27992
28088
  let stdout2 = "";
@@ -28078,6 +28174,7 @@ Make sure this path contains TypeScript/React/Vue component files (.tsx, .ts, .v
28078
28174
  sessionId: sessionId2,
28079
28175
  agent: state.agent,
28080
28176
  ...state.agentModel ? { model: state.agentModel } : {},
28177
+ ...state.bedrock ? { bedrock: true } : {},
28081
28178
  selectPromptPath,
28082
28179
  noCache
28083
28180
  });
@@ -28176,6 +28273,7 @@ Make sure this path contains TypeScript/React/Vue component files (.tsx, .ts, .v
28176
28273
  tokensPath,
28177
28274
  agent: state.agent,
28178
28275
  ...state.agentModel ? { model: state.agentModel } : {},
28276
+ ...state.bedrock ? { bedrock: true } : {},
28179
28277
  noCache: effectiveNoCache
28180
28278
  })
28181
28279
  ];
@@ -28245,6 +28343,7 @@ Make sure this path contains TypeScript/React/Vue component files (.tsx, .ts, .v
28245
28343
  tokensPath,
28246
28344
  agent: state.agent,
28247
28345
  ...state.agentModel ? { model: state.agentModel } : {},
28346
+ ...state.bedrock ? { bedrock: true } : {},
28248
28347
  noCache: effectiveNoCache,
28249
28348
  generatePromptPath
28250
28349
  })
@@ -28326,7 +28425,7 @@ Make sure this path contains TypeScript/React/Vue component files (.tsx, .ts, .v
28326
28425
  update({ step: "credentials", credentialsValidating: true, credentialsError: "" });
28327
28426
  try {
28328
28427
  const resolvedHost = resolveWizardHost(host2);
28329
- const client2 = new ImportApiClient({
28428
+ const client2 = new EdsiApiClient({
28330
28429
  cmaToken,
28331
28430
  spaceId,
28332
28431
  environmentId,
@@ -28400,7 +28499,7 @@ Make sure this path contains TypeScript/React/Vue component files (.tsx, .ts, .v
28400
28499
  update({ step: "previewing" });
28401
28500
  const resolvedHost = resolveWizardHost(host2);
28402
28501
  try {
28403
- const client2 = new ImportApiClient({
28502
+ const client2 = new EdsiApiClient({
28404
28503
  cmaToken,
28405
28504
  spaceId,
28406
28505
  environmentId,
@@ -28562,7 +28661,7 @@ If using a custom --host, make sure the space exists on that host.`
28562
28661
  update({ step: "pushing", pushProgress: null });
28563
28662
  try {
28564
28663
  const resolvedHost = resolveWizardHost(host2);
28565
- const client2 = new ImportApiClient({
28664
+ const client2 = new EdsiApiClient({
28566
28665
  cmaToken,
28567
28666
  spaceId,
28568
28667
  environmentId,
@@ -29752,12 +29851,15 @@ import { isAbsolute as isAbsolute4, join as join15, relative as relative3, resol
29752
29851
  init_src();
29753
29852
  var AGENT_DESCRIPTION = `Agent to use: ${AGENT_NAMES.join(", ")} (defaults to value saved by experiences setup)`;
29754
29853
  var MODEL_DESCRIPTION = "Model to use (defaults to a lightweight per-agent model; override with EDS_AGENT_MODEL_<AGENT>)";
29854
+ var BEDROCK_AGENTS = AGENT_NAMES.filter((agent) => agentSupportsBedrock(agent)).join(", ");
29855
+ var BEDROCK_DESCRIPTION = `Route the selected agent through AWS Bedrock instead of its default model provider (requires AWS credentials in the environment: AWS_PROFILE, or AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN, plus AWS_REGION). Only supported by agents with a Bedrock routing mechanism (currently: ${BEDROCK_AGENTS}).`;
29755
29856
  function addAgentModelOptions(cmd, config = {}) {
29756
29857
  const { agentDescription = AGENT_DESCRIPTION, includeModel = true, modelDescription = MODEL_DESCRIPTION } = config;
29757
29858
  cmd.option("--agent <name>", agentDescription);
29758
29859
  if (includeModel) {
29759
29860
  cmd.option("--model <name>", modelDescription);
29760
29861
  }
29862
+ cmd.option("--bedrock", BEDROCK_DESCRIPTION);
29761
29863
  return cmd;
29762
29864
  }
29763
29865
 
@@ -30546,6 +30648,12 @@ function registerAnalyzeSelectAgentCommand(program) {
30546
30648
  return;
30547
30649
  }
30548
30650
  const agent = agentName;
30651
+ if (opts.bedrock && !agentSupportsBedrock(agent)) {
30652
+ process.stderr.write(`Error: --bedrock is not supported for --agent ${agent}
30653
+ `);
30654
+ await exitWithAnalytics(1);
30655
+ return;
30656
+ }
30549
30657
  const selectPromptPath = opts.selectPromptPath ?? savedCreds.selectPromptPath;
30550
30658
  if (selectPromptPath) {
30551
30659
  const resolvedPath = resolve12(selectPromptPath);
@@ -31789,6 +31897,14 @@ function registerAnalyzeCommand(program) {
31789
31897
  }
31790
31898
  return v;
31791
31899
  })();
31900
+ if (opts.bedrock) {
31901
+ const bedrockAgent = resolveCompositionAgentName(opts.agent);
31902
+ if (!agentSupportsBedrock(bedrockAgent)) {
31903
+ process.stderr.write(`Error: --bedrock is not supported for --agent ${bedrockAgent}
31904
+ `);
31905
+ process.exit(1);
31906
+ }
31907
+ }
31792
31908
  const projectRoot = resolve15(opts.project);
31793
31909
  const outDir = join15(projectRoot, ".contentful");
31794
31910
  let sourceDirectory;
@@ -32635,6 +32751,9 @@ async function runGenerateSkill(skill, opts, verbose = false) {
32635
32751
  );
32636
32752
  }
32637
32753
  const agent = agentName;
32754
+ if (opts.bedrock && !agentSupportsBedrock(agent)) {
32755
+ die2(`Error: --bedrock is not supported for --agent ${agent}`);
32756
+ }
32638
32757
  const generatePromptPath = skill === "components" ? opts.generatePromptPath ?? savedCreds.generatePromptPath : void 0;
32639
32758
  if (generatePromptPath) {
32640
32759
  if (!await pathExists3(resolve17(generatePromptPath))) {
@@ -34299,6 +34418,7 @@ function registerMapTokensCommand(program) {
34299
34418
  }
34300
34419
 
34301
34420
  // packages/experience-design-system-cli/src/import/command.ts
34421
+ init_src();
34302
34422
  init_path_utils();
34303
34423
  import { resolve as resolve25, join as join25 } from "node:path";
34304
34424
 
@@ -34307,14 +34427,52 @@ init_db();
34307
34427
  init_command();
34308
34428
  init_manifest();
34309
34429
  init_api_client();
34430
+ import { mkdir as mkdir5, writeFile as writeFile5 } from "node:fs/promises";
34431
+ import { join as join18, resolve as resolve21 } from "node:path";
34432
+ import { execFile as execFile2 } from "node:child_process";
34433
+
34434
+ // packages/experience-design-system-cli/src/api/clients/cma-client.ts
34435
+ init_http();
34436
+ init_api_error();
34437
+ init_abstract_api_client();
34438
+ var CMA_PAGE_LIMIT = 100;
34439
+ var CmaApiClient = class extends AbstractApiClient {
34440
+ constructor(opts) {
34441
+ super(opts);
34442
+ }
34443
+ async listExistingEntities() {
34444
+ const [components, tokens] = await Promise.all([
34445
+ this.listAll("component_types", "component_types"),
34446
+ this.listAll("design_tokens", "design_tokens")
34447
+ ]);
34448
+ return { components, tokens };
34449
+ }
34450
+ async listAll(resourcePath, opName) {
34451
+ const items = [];
34452
+ let skip = 0;
34453
+ while (true) {
34454
+ const url = `${this.base()}/${resourcePath}?limit=${CMA_PAGE_LIMIT}&skip=${skip}`;
34455
+ const res = await request(url, { token: this.token });
34456
+ if (!res.ok) {
34457
+ throw new ApiError(`${opName} list failed: ${res.status}`, res.status, await res.text());
34458
+ }
34459
+ const page = await res.json();
34460
+ items.push(...page.items);
34461
+ const returned = page.items.length;
34462
+ const total = page.total ?? items.length;
34463
+ if (returned === 0 || items.length >= total) break;
34464
+ skip += returned;
34465
+ }
34466
+ return items;
34467
+ }
34468
+ };
34469
+
34470
+ // packages/experience-design-system-cli/src/import/orchestrator.ts
34310
34471
  init_contentful_urls();
34311
34472
  init_debug_logger();
34312
34473
  init_analytics();
34313
34474
  init_env();
34314
34475
  init_cli_path();
34315
- import { mkdir as mkdir5 } from "node:fs/promises";
34316
- import { join as join18, resolve as resolve21 } from "node:path";
34317
- import { execFile as execFile2 } from "node:child_process";
34318
34476
  async function runStep(args, cliPath, analyticsSessionId, env = {}, streamStderr = false) {
34319
34477
  const debug = getDebugLogger();
34320
34478
  const startedAt = Date.now();
@@ -34422,11 +34580,66 @@ async function runPipeline(opts, progressWriter, cliPathOverride) {
34422
34580
  await mkdir5(outDir, { recursive: true });
34423
34581
  const steps = [];
34424
34582
  let stepNum = 0;
34425
- const totalSteps = 5 + (opts.print ? 1 : 0);
34583
+ const wantsSpaceContext = opts.withSpaceContext === true;
34584
+ const canFetchSpaceContext = wantsSpaceContext && !!opts.spaceId && !!opts.environmentId && !!opts.cmaToken;
34585
+ const totalSteps = 5 + (opts.print ? 1 : 0) + (canFetchSpaceContext ? 1 : 0);
34426
34586
  function stepLabel(name) {
34427
34587
  stepNum++;
34428
34588
  return ` Step ${stepNum}/${totalSteps} ${name} `;
34429
34589
  }
34590
+ if (wantsSpaceContext && !canFetchSpaceContext) {
34591
+ progressWriter(
34592
+ " Note: --with-space-context requires --space-id, --environment-id, and --cma-token; skipping context fetch."
34593
+ );
34594
+ }
34595
+ if (canFetchSpaceContext) {
34596
+ const fetchLabel = stepLabel("Fetching existing components + design tokens");
34597
+ const fetchStepId = createStep(db, sessionId2, "fetch existing entities", {
34598
+ spaceId: opts.spaceId,
34599
+ environmentId: opts.environmentId
34600
+ });
34601
+ const t0 = Date.now();
34602
+ try {
34603
+ const cma = new CmaApiClient({
34604
+ host: opts.host,
34605
+ cmaToken: opts.cmaToken,
34606
+ spaceId: opts.spaceId,
34607
+ environmentId: opts.environmentId
34608
+ });
34609
+ const result = await cma.listExistingEntities();
34610
+ const fetchDurationMs = Date.now() - t0;
34611
+ const existingEntitiesPath = join18(outDir, ".existing-entities.json");
34612
+ await writeFile5(existingEntitiesPath, JSON.stringify(result, null, 2), "utf8");
34613
+ updateStep(db, fetchStepId, "complete", {
34614
+ components: String(result.components.length),
34615
+ tokens: String(result.tokens.length),
34616
+ path: existingEntitiesPath
34617
+ });
34618
+ progressWriter(
34619
+ `${fetchLabel}\u2713 ${result.components.length} component${result.components.length === 1 ? "" : "s"}, ${result.tokens.length} token${result.tokens.length === 1 ? "" : "s"} (${(fetchDurationMs / 1e3).toFixed(1)}s)`
34620
+ );
34621
+ steps.push({
34622
+ step: "fetch existing entities",
34623
+ status: "complete",
34624
+ durationMs: fetchDurationMs,
34625
+ detail: { components: result.components.length, tokens: result.tokens.length }
34626
+ });
34627
+ } catch (error) {
34628
+ const fetchDurationMs = Date.now() - t0;
34629
+ const message = error instanceof Error ? error.message : String(error);
34630
+ updateStep(db, fetchStepId, "failed", {}, message);
34631
+ progressWriter(
34632
+ `${fetchLabel}\u26A0 fetch failed, continuing without space context (${(fetchDurationMs / 1e3).toFixed(1)}s)`
34633
+ );
34634
+ progressWriter(` ${message.split("\n")[0]}`);
34635
+ steps.push({
34636
+ step: "fetch existing entities",
34637
+ status: "failed",
34638
+ durationMs: fetchDurationMs,
34639
+ error: message
34640
+ });
34641
+ }
34642
+ }
34430
34643
  const analyzeLabel = stepLabel("Statically analyzing project");
34431
34644
  const analyzeSkipped = !opts.noCache && opts.skipAnalyze;
34432
34645
  let extractSessionId = null;
@@ -34454,6 +34667,7 @@ async function runPipeline(opts, progressWriter, cliPathOverride) {
34454
34667
  if (opts.generateMap) analyzeArgs.push("--generate-map", opts.generateMap);
34455
34668
  for (const p of opts.promptOverrides ?? []) analyzeArgs.push("--prompt", p);
34456
34669
  if (opts.agent) analyzeArgs.push("--agent", opts.agent);
34670
+ if (opts.bedrock) analyzeArgs.push("--bedrock");
34457
34671
  }
34458
34672
  const r = await runStep(analyzeArgs, cliPath, sessionId2);
34459
34673
  const durationMs = Date.now() - t0;
@@ -34504,6 +34718,7 @@ async function runPipeline(opts, progressWriter, cliPathOverride) {
34504
34718
  if (useAgentSelect) {
34505
34719
  editArgs = ["analyze", "select-agent", "--session", extractSessionId, "--agent", opts.agent];
34506
34720
  if (opts.model) editArgs.push("--model", opts.model);
34721
+ if (opts.bedrock) editArgs.push("--bedrock");
34507
34722
  if (opts.excludeInvalid) editArgs.push("--exclude-invalid");
34508
34723
  if (opts.noCache) editArgs.push("--no-cache");
34509
34724
  if (opts.selectPromptPath) editArgs.push("--select-prompt-path", opts.selectPromptPath);
@@ -34565,6 +34780,7 @@ async function runPipeline(opts, progressWriter, cliPathOverride) {
34565
34780
  const generateLabel = stepLabel("Categorizing component props");
34566
34781
  const generateArgs = ["generate", "components", "--agent", opts.agent];
34567
34782
  if (opts.model) generateArgs.push("--model", opts.model);
34783
+ if (opts.bedrock) generateArgs.push("--bedrock");
34568
34784
  if (extractSessionId) generateArgs.push("--session", extractSessionId);
34569
34785
  if (opts.dryRun) generateArgs.push("--dry-run");
34570
34786
  if (opts.verbose) generateArgs.push("--verbose");
@@ -35378,7 +35594,10 @@ function registerImportCommand(program) {
35378
35594
  "Override a stage prompt (repeatable). value is a file path or literal text, e.g. --prompt composition=./p.md",
35379
35595
  (v, acc) => [...acc, v],
35380
35596
  []
35381
- ).option("--auto-reject-cycles", "Automatically reject components involved in slot cycles and retry").option("--auto-filter", "Force the AI auto-filter ON (overrides the credentials.json autoFilter preference)").option(
35597
+ ).option("--auto-reject-cycles", "Automatically reject components involved in slot cycles and retry").option(
35598
+ "--with-space-context",
35599
+ "Fetch existing Components + DesignTokens from the target space+env and persist them under <out>/.existing-entities.json for future agent-context enrichment. Requires --space-id, --environment-id, and --cma-token."
35600
+ ).option("--auto-filter", "Force the AI auto-filter ON (overrides the credentials.json autoFilter preference)").option(
35382
35601
  "--no-auto-filter",
35383
35602
  "Skip the automatic AI pre-filter; jump straight to manual scope-gate (overrides the credentials.json autoFilter preference; no-op when paired with --auto-accept-scope)"
35384
35603
  ).option(
@@ -35595,6 +35814,11 @@ function registerImportCommand(program) {
35595
35814
  const resolvedAgent = resolveAgent(opts.agent, creds.agent);
35596
35815
  const resolvedModel = resolveModel(opts.model, creds.agentModel);
35597
35816
  const resolvedCompositionMode = resolveCompositionMode(opts, creds.compositionMode);
35817
+ if (opts.bedrock && !(isAgentName(resolvedAgent) && agentSupportsBedrock(resolvedAgent))) {
35818
+ process.stderr.write(`Error: --bedrock is not supported for --agent ${resolvedAgent}
35819
+ `);
35820
+ process.exit(1);
35821
+ }
35598
35822
  const pickerDecision = await shouldShowRunPicker({
35599
35823
  flags: {
35600
35824
  ...opts.pushFromRun !== void 0 ? { pushFromRun: opts.pushFromRun } : {},
@@ -35623,6 +35847,7 @@ function registerImportCommand(program) {
35623
35847
  initialHost: toConfiguredHost(opts.host ?? creds.host) ?? DEFAULT_CONFIGURED_HOST,
35624
35848
  initialAgent: resolvedAgent,
35625
35849
  ...resolvedModel ? { initialModel: resolvedModel } : {},
35850
+ ...opts.bedrock ? { bedrock: true } : {},
35626
35851
  initialProjectPath: opts.project !== "." ? normalizePath(opts.project) : void 0,
35627
35852
  host: opts.host,
35628
35853
  autoAcceptScope,
@@ -35686,6 +35911,11 @@ function registerImportCommand(program) {
35686
35911
  const headlessAgent = resolveAgent(opts.agent, headlessCreds.agent);
35687
35912
  const headlessModel = resolveModel(opts.model, headlessCreds.agentModel);
35688
35913
  const headlessCompositionMode = resolveCompositionMode(opts, headlessCreds.compositionMode);
35914
+ if (opts.bedrock && !(isAgentName(headlessAgent) && agentSupportsBedrock(headlessAgent))) {
35915
+ process.stderr.write(`Error: --bedrock is not supported for --agent ${headlessAgent}
35916
+ `);
35917
+ process.exit(1);
35918
+ }
35689
35919
  const result = await runPipeline(
35690
35920
  {
35691
35921
  project: projectRoot,
@@ -35695,6 +35925,7 @@ function registerImportCommand(program) {
35695
35925
  cmaToken,
35696
35926
  agent: headlessAgent,
35697
35927
  model: headlessModel,
35928
+ ...opts.bedrock ? { bedrock: true } : {},
35698
35929
  tokens: opts.tokens,
35699
35930
  selectAll: opts.selectAll,
35700
35931
  select: opts.select.length > 0 ? opts.select : void 0,
@@ -35713,6 +35944,7 @@ function registerImportCommand(program) {
35713
35944
  dryRun: dryRunForward,
35714
35945
  selectPromptPath: opts.selectPromptPath,
35715
35946
  autoRejectCycles: opts.autoRejectCycles ?? false,
35947
+ withSpaceContext: opts.withSpaceContext ?? false,
35716
35948
  allowDeletions: opts.allowDeletions ?? false,
35717
35949
  compositionMode: headlessCompositionMode,
35718
35950
  ...opts.compositionMap ? { compositionMap: opts.compositionMap } : {},
@@ -36096,15 +36328,26 @@ function pick(items, defaultIdx = 0) {
36096
36328
  process.stdout.write(` \x1B[2m[s] Skip\x1B[0m
36097
36329
  `);
36098
36330
  }
36099
- async function promptCodexModel(ask = prompt) {
36331
+ async function promptCodexModel() {
36100
36332
  if (process.env["OPENAI_API_KEY"]) return void 0;
36101
36333
  info("");
36102
36334
  process.stdout.write(` \x1B[33m\u26A0\x1B[0m No OPENAI_API_KEY \u2014 using ChatGPT account authentication.
36103
36335
  `);
36104
- info(" Tip: run \x1B[1mcodex\x1B[0m then type \x1B[1m/model\x1B[0m to browse the models available to your account.");
36105
- const model = await ask(" Model name (optional - press Enter for Codex default): ");
36106
- const trimmed = model.trim();
36107
- return trimmed || void 0;
36336
+ info(" Tip: run \x1B[1mcodex\x1B[0m then type \x1B[1m/model\x1B[0m to browse all available models.");
36337
+ info("");
36338
+ info(" Choose a model:");
36339
+ info("");
36340
+ pick([
36341
+ { label: "gpt-5.4-mini", description: "fast, lower cost" },
36342
+ { label: "gpt-5.5", description: "most capable" },
36343
+ { label: "gpt-5.4" }
36344
+ ]);
36345
+ info("");
36346
+ const choice = await prompt(" \x1B[2m\u203A\x1B[0m Your choice [1]: ");
36347
+ if (choice === "1" || choice === "") return "gpt-5.4-mini";
36348
+ if (choice === "2") return "gpt-5.5";
36349
+ if (choice === "3") return "gpt-5.4";
36350
+ return void 0;
36108
36351
  }
36109
36352
  async function setupAgent() {
36110
36353
  section("Step 4: Coding agent (claude, codex, opencode, or copilot)", "[required]");
@@ -36131,6 +36374,7 @@ async function setupAgent() {
36131
36374
  const parsed = choice2 === "" ? 1 : parseInt(choice2, 10);
36132
36375
  const idx = Number.isNaN(parsed) || parsed < 1 || parsed > found.length ? 0 : parsed - 1;
36133
36376
  const selected = found[idx];
36377
+ ok(`${selected.name} \x1B[2m(${selected.binary})\x1B[0m selected`);
36134
36378
  const agentModel = selected.binary === "codex" ? await promptCodexModel() : void 0;
36135
36379
  return { agent: selected.binary, agentModel };
36136
36380
  }
@@ -36820,6 +37064,13 @@ async function runBuild(opts) {
36820
37064
  child.on("exit", (code) => settle(code ?? 1));
36821
37065
  });
36822
37066
  }
37067
+ function resolveBedrockFromAncestors(actionCommand) {
37068
+ for (let c2 = actionCommand; c2; c2 = c2.parent) {
37069
+ const opts = c2.opts();
37070
+ if (opts.bedrock) return true;
37071
+ }
37072
+ return false;
37073
+ }
36823
37074
  function registerImportV2Command(program) {
36824
37075
  program.command("importv2").description("Launch the v2 import TUI (experience-design-system-cli-v2)").action(async () => {
36825
37076
  const { render: render7 } = await import("ink");
@@ -36867,6 +37118,9 @@ function createProgram() {
36867
37118
  break;
36868
37119
  }
36869
37120
  }
37121
+ if (resolveBedrockFromAncestors(actionCommand)) {
37122
+ process.env.EDS_BEDROCK = "1";
37123
+ }
36870
37124
  const chain = [];
36871
37125
  for (let c2 = actionCommand; c2 && c2.parent; c2 = c2.parent) chain.unshift(c2.name());
36872
37126
  const commandChain = chain.join(" ") || actionCommand.name();
@@ -0,0 +1,6 @@
1
+ export interface CmaClientOptions {
2
+ host?: string;
3
+ cmaToken: string;
4
+ spaceId: string;
5
+ environmentId: string;
6
+ }
@@ -0,0 +1,12 @@
1
+ export interface EdsiClientOptions {
2
+ host?: string;
3
+ cmaToken: string;
4
+ spaceId: string;
5
+ environmentId: string;
6
+ retry?: {
7
+ maxAttempts?: number;
8
+ initialDelayMs?: number;
9
+ maxDelayMs?: number;
10
+ sleep?: (delayMs: number) => Promise<void>;
11
+ };
12
+ }
@@ -0,0 +1,7 @@
1
+ import type { ApplyOperationResponse } from '@contentful/experience-design-system-types';
2
+ export interface PollOptions {
3
+ intervalMs?: number;
4
+ maxIntervalMs?: number;
5
+ maxAttempts?: number;
6
+ onProgress?: (op: ApplyOperationResponse) => void;
7
+ }
@@ -0,0 +1,8 @@
1
+ export interface ExistingComponentEntity {
2
+ id: string;
3
+ name: string;
4
+ description?: string;
5
+ contentProperties?: unknown[];
6
+ designProperties?: unknown[];
7
+ slots?: unknown[];
8
+ }
@@ -0,0 +1,6 @@
1
+ import type { ExistingComponentEntity } from './existing-component-entity.js';
2
+ import type { ExistingTokenEntity } from './existing-token-entity.js';
3
+ export interface ExistingEntitiesResponse {
4
+ components: ExistingComponentEntity[];
5
+ tokens: ExistingTokenEntity[];
6
+ }
@@ -0,0 +1,6 @@
1
+ export interface ExistingTokenEntity {
2
+ id: string;
3
+ name: string;
4
+ kind: string;
5
+ value?: unknown;
6
+ }
@@ -1,13 +1,16 @@
1
1
  import type { Command } from 'commander';
2
2
  export declare const AGENT_DESCRIPTION: string;
3
3
  export declare const MODEL_DESCRIPTION = "Model to use (defaults to a lightweight per-agent model; override with EDS_AGENT_MODEL_<AGENT>)";
4
+ export declare const BEDROCK_DESCRIPTION: string;
4
5
  export interface AgentModelOptionsConfig {
5
6
  agentDescription?: string;
6
7
  includeModel?: boolean;
7
8
  modelDescription?: string;
8
9
  }
9
10
  /**
10
- * Register --agent and optionally --model flags to a Commander command, with customizable descriptions.
11
- * Pass `includeModel: false` for commands where the model dimension is not applicable (e.g., mapping-resolution agents that select an agent for logic, not model choice).
11
+ * Register --agent, --bedrock, and optional --model flags with a Commander
12
+ * command. Pass includeModel: false to omit --model only — --bedrock is
13
+ * independent of model selection (it's a routing switch, not a model choice)
14
+ * and is always registered alongside --agent.
12
15
  */
13
16
  export declare function addAgentModelOptions(cmd: Command, config?: AgentModelOptionsConfig): Command;
@@ -15,5 +15,11 @@ export declare function runBuild(opts: {
15
15
  }): Promise<{
16
16
  exitCode: number;
17
17
  }>;
18
+ /**
19
+ * Walks `actionCommand` and its ancestors for a truthy `--bedrock`. --bedrock
20
+ * is registered per-subcommand (not at program scope, unlike --debug), so a
21
+ * root-level or subcommand-level setting can each carry it.
22
+ */
23
+ export declare function resolveBedrockFromAncestors(actionCommand: Command): boolean;
18
24
  export declare function createProgram(): Command;
19
25
  export {};
@@ -5,7 +5,7 @@ import type { ToolCall, TokenToolCall, ComponentSourceRef } from '@contentful/ex
5
5
  import type { ComponentTypeSummary } from '@contentful/experience-design-system-types';
6
6
  import type { SlotCycle, SlotEdge } from '../analyze/cycle-detection.js';
7
7
  export type StepStatus = 'pending' | 'complete' | 'failed' | 'interrupted';
8
- export type CommandName = 'analyze extract' | 'analyze select' | 'generate components' | 'generate tokens' | 'generate edit' | 'apply preview' | 'apply select' | 'apply push' | 'print components' | 'print tokens' | 'map tokens' | 'import';
8
+ export type CommandName = 'analyze extract' | 'analyze select' | 'generate components' | 'generate tokens' | 'generate edit' | 'apply preview' | 'apply select' | 'apply push' | 'print components' | 'print tokens' | 'map tokens' | 'fetch existing entities' | 'import';
9
9
  export interface SessionRow {
10
10
  id: string;
11
11
  name: string | null;
@@ -1,10 +1,4 @@
1
1
  import type { Command } from 'commander';
2
- import type { AgentName } from '@contentful/experience-design-system-generation';
3
- export declare function promptCodexModel(ask?: (q: string) => Promise<string>): Promise<string | undefined>;
4
- export declare function setupAgent(): Promise<{
5
- agent: AgentName | undefined;
6
- agentModel: string | undefined;
7
- }>;
8
2
  export type SkillPromptKind = 'select' | 'generate';
9
3
  /**
10
4
  * Prompt the operator for a custom skill prompt path. Returns the resolved
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experience-design-system-cli",
3
- "version": "2.32.1-dev-build-10912f6.0",
3
+ "version": "2.32.1-dev-build-1c6a348.0",
4
4
  "description": "Contentful Experiences design system import CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,8 +39,8 @@
39
39
  "svelte": "^5.56.4",
40
40
  "ts-morph": "^27.0.2",
41
41
  "typescript": "^5.9.3",
42
- "@contentful/experience-design-system-cli-v2": "2.32.1-dev-build-10912f6.0",
43
- "@contentful/experience-design-system-types": "2.32.1-dev-build-10912f6.0"
42
+ "@contentful/experience-design-system-cli-v2": "2.32.1-dev-build-1c6a348.0",
43
+ "@contentful/experience-design-system-types": "2.32.1-dev-build-1c6a348.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@tsconfig/node24": "^24.0.4",
@@ -52,9 +52,9 @@
52
52
  "ink-testing-library": "^4.0.0",
53
53
  "typescript-eslint": "^8.67.0",
54
54
  "vitest": "^4.0.16",
55
- "@contentful/experience-design-system-client": "2.32.1-dev-build-10912f6.0",
56
- "@contentful/experience-design-system-extraction": "2.32.1-dev-build-10912f6.0",
57
- "@contentful/experience-design-system-generation": "2.32.1-dev-build-10912f6.0"
55
+ "@contentful/experience-design-system-extraction": "2.32.1-dev-build-1c6a348.0",
56
+ "@contentful/experience-design-system-generation": "2.32.1-dev-build-1c6a348.0",
57
+ "@contentful/experience-design-system-client": "2.32.1-dev-build-1c6a348.0"
58
58
  },
59
59
  "repository": {
60
60
  "type": "git",