@cat-factory/integrations 0.32.0 → 0.33.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/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/modules/documents/ConfluenceProvider.d.ts +1 -2
- package/dist/modules/documents/ConfluenceProvider.d.ts.map +1 -1
- package/dist/modules/documents/DocumentConnectionService.d.ts +11 -28
- package/dist/modules/documents/DocumentConnectionService.d.ts.map +1 -1
- package/dist/modules/documents/DocumentConnectionService.js +12 -71
- package/dist/modules/documents/DocumentConnectionService.js.map +1 -1
- package/dist/modules/documents/DocumentImportService.d.ts +4 -7
- package/dist/modules/documents/DocumentImportService.d.ts.map +1 -1
- package/dist/modules/documents/DocumentImportService.js +6 -9
- package/dist/modules/documents/DocumentImportService.js.map +1 -1
- package/dist/modules/documents/FigmaProvider.d.ts +4 -5
- package/dist/modules/documents/FigmaProvider.d.ts.map +1 -1
- package/dist/modules/documents/FigmaProvider.js +22 -21
- package/dist/modules/documents/FigmaProvider.js.map +1 -1
- package/dist/modules/documents/GitHubDocsProvider.d.ts +1 -2
- package/dist/modules/documents/GitHubDocsProvider.d.ts.map +1 -1
- package/dist/modules/documents/LinearDocumentProvider.d.ts +1 -2
- package/dist/modules/documents/LinearDocumentProvider.d.ts.map +1 -1
- package/dist/modules/documents/NotionProvider.d.ts +1 -2
- package/dist/modules/documents/NotionProvider.d.ts.map +1 -1
- package/dist/modules/documents/{ClaudeDesignProvider.d.ts → ZeplinProvider.d.ts} +12 -11
- package/dist/modules/documents/ZeplinProvider.d.ts.map +1 -0
- package/dist/modules/documents/ZeplinProvider.js +126 -0
- package/dist/modules/documents/ZeplinProvider.js.map +1 -0
- package/dist/modules/documents/design.logic.d.ts +60 -0
- package/dist/modules/documents/design.logic.d.ts.map +1 -0
- package/dist/modules/documents/design.logic.js +0 -0
- package/dist/modules/documents/design.logic.js.map +1 -0
- package/dist/modules/documents/figma.logic.d.ts +30 -9
- package/dist/modules/documents/figma.logic.d.ts.map +1 -1
- package/dist/modules/documents/figma.logic.js +51 -36
- package/dist/modules/documents/figma.logic.js.map +1 -1
- package/dist/modules/documents/zeplin.logic.d.ts +102 -0
- package/dist/modules/documents/zeplin.logic.d.ts.map +1 -0
- package/dist/modules/documents/zeplin.logic.js +193 -0
- package/dist/modules/documents/zeplin.logic.js.map +1 -0
- package/package.json +3 -3
- package/dist/modules/documents/ClaudeDesignProvider.d.ts.map +0 -1
- package/dist/modules/documents/ClaudeDesignProvider.js +0 -163
- package/dist/modules/documents/ClaudeDesignProvider.js.map +0 -1
- package/dist/modules/documents/claudeDesign.logic.d.ts +0 -88
- package/dist/modules/documents/claudeDesign.logic.d.ts.map +0 -1
- package/dist/modules/documents/claudeDesign.logic.js +0 -317
- package/dist/modules/documents/claudeDesign.logic.js.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { DocumentSourceDescriptor } from '@cat-factory/kernel';
|
|
2
|
+
import { type DesignBlock, type DesignComponent, type DesignContext, type DesignToken } from './design.logic.js';
|
|
3
|
+
/** Zeplin's REST API host. The PAT is sent to this host only — see {@link assertSafeZeplinUrl}. */
|
|
4
|
+
export declare const ZEPLIN_API_HOST = "api.zeplin.dev";
|
|
5
|
+
/** What the connect UI renders, and which credentials the provider needs. */
|
|
6
|
+
export declare const ZEPLIN_DESCRIPTOR: DocumentSourceDescriptor;
|
|
7
|
+
/**
|
|
8
|
+
* The Zeplin REST host is fixed, so any request/redirect must stay on `api.zeplin.dev`
|
|
9
|
+
* over https; a redirect off-host is treated as an SSRF attempt and rejected. Mirrors the
|
|
10
|
+
* per-hop guard the other host-pinned providers run. Kept pure so it is unit-testable
|
|
11
|
+
* without a network.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertSafeZeplinUrl(url: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve a Zeplin reference from raw user input into the stable composite external id
|
|
16
|
+
* this provider stores: `"<projectId>"` for a whole-project link, or
|
|
17
|
+
* `"<projectId>:<screenId>"` for a specific screen. Accepts an `app.zeplin.io`
|
|
18
|
+
* project/screen URL, a bare project id, or a `projectId:screenId` string. Returns null
|
|
19
|
+
* when no project id is found.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseZeplinRef(input: string): string | null;
|
|
22
|
+
/** Split a composite external id back into its project id and optional screen id. */
|
|
23
|
+
export declare function splitZeplinExternalId(externalId: string): {
|
|
24
|
+
projectId: string;
|
|
25
|
+
screenId?: string;
|
|
26
|
+
};
|
|
27
|
+
/** Build the canonical web URL stored on the imported document. */
|
|
28
|
+
export declare function zeplinUrlFor(externalId: string): string;
|
|
29
|
+
/** Accept either a bare array or a `{ <key>: [...] }` envelope, else an empty array. */
|
|
30
|
+
export declare function unwrapArray<T>(value: unknown, key: string): T[];
|
|
31
|
+
/** Accept either a bare object or a `{ <key>: {...} }` envelope, else null. */
|
|
32
|
+
export declare function unwrapObject<T>(value: unknown, key: string): T | null;
|
|
33
|
+
export interface ZeplinScreen {
|
|
34
|
+
id?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
image?: {
|
|
38
|
+
width?: number;
|
|
39
|
+
height?: number;
|
|
40
|
+
} | null;
|
|
41
|
+
}
|
|
42
|
+
export interface ZeplinComponent {
|
|
43
|
+
id?: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
section?: {
|
|
47
|
+
name?: string;
|
|
48
|
+
} | null;
|
|
49
|
+
}
|
|
50
|
+
/** A Zeplin colour token: 0–255 channels + 0–1 alpha (Zeplin's representation). */
|
|
51
|
+
interface ZeplinColor {
|
|
52
|
+
name?: string;
|
|
53
|
+
r?: number;
|
|
54
|
+
g?: number;
|
|
55
|
+
b?: number;
|
|
56
|
+
a?: number;
|
|
57
|
+
}
|
|
58
|
+
interface ZeplinTextStyle {
|
|
59
|
+
name?: string;
|
|
60
|
+
font_family?: string;
|
|
61
|
+
font_size?: number;
|
|
62
|
+
}
|
|
63
|
+
interface ZeplinSpacing {
|
|
64
|
+
name?: string;
|
|
65
|
+
value?: number;
|
|
66
|
+
}
|
|
67
|
+
/** The `/projects/:id/design_tokens` payload we read (lenient — verify-at-build). */
|
|
68
|
+
export interface ZeplinDesignTokens {
|
|
69
|
+
colors?: ZeplinColor[];
|
|
70
|
+
text_styles?: ZeplinTextStyle[];
|
|
71
|
+
spacing?: ZeplinSpacing[];
|
|
72
|
+
measurements?: ZeplinSpacing[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The single source of truth for how many screens a whole-project import pulls and
|
|
76
|
+
* renders: {@link ZeplinProvider} builds its `?limit=` query from this, and
|
|
77
|
+
* {@link zeplinScreensToBlocks} bounds the rendered blocks by it, so the fetch and the
|
|
78
|
+
* render can't drift.
|
|
79
|
+
*/
|
|
80
|
+
export declare const MAX_SCREENS = 40;
|
|
81
|
+
/** Map Zeplin screens into source-neutral blocks (name + an optional description line). */
|
|
82
|
+
export declare function zeplinScreensToBlocks(screens: ZeplinScreen[]): DesignBlock[];
|
|
83
|
+
/** Map Zeplin components into source-neutral components (grouped by their section). */
|
|
84
|
+
export declare function zeplinComponentsToDesign(components: ZeplinComponent[]): DesignComponent[];
|
|
85
|
+
/** Map Zeplin design tokens (colours / typography / spacing) into source-neutral tokens. */
|
|
86
|
+
export declare function zeplinTokens(tokens: ZeplinDesignTokens | undefined | null): DesignToken[];
|
|
87
|
+
export interface ZeplinContextInput {
|
|
88
|
+
/** The composite external id (`<projectId>` or `<projectId>:<screenId>`). */
|
|
89
|
+
externalId: string;
|
|
90
|
+
/** The Zeplin project's name (from the API), used for the document title. */
|
|
91
|
+
projectName: string;
|
|
92
|
+
/** The fetched screens (the whole project, or just the one referenced). */
|
|
93
|
+
screens: ZeplinScreen[];
|
|
94
|
+
/** The project's design-system components. */
|
|
95
|
+
components: ZeplinComponent[];
|
|
96
|
+
/** The project's design tokens, or null when unavailable. */
|
|
97
|
+
designTokens?: ZeplinDesignTokens | null;
|
|
98
|
+
}
|
|
99
|
+
/** Assemble the fetched Zeplin pieces into the shared {@link DesignContext}. */
|
|
100
|
+
export declare function buildZeplinDesignContext(input: ZeplinContextInput): DesignContext;
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=zeplin.logic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zeplin.logic.d.ts","sourceRoot":"","sources":["../../../src/modules/documents/zeplin.logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAA;AAa1B,mGAAmG;AACnG,eAAO,MAAM,eAAe,mBAAmB,CAAA;AAE/C,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,EAAE,wBAiB/B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAErD;AAMD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuB3D;AAED,qFAAqF;AACrF,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG;IACzD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAIA;AAED,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIvD;AASD,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,CAO/D;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,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A2F;AAC3F,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,WAAW,EAAE,CAQ5E;AAED,uFAAuF;AACvF,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAQzF;AAWD,4FAA4F;AAC5F,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,GAAG,WAAW,EAAE,CAmBzF;AAED,MAAM,WAAW,kBAAkB;IACjC,6EAA6E;IAC7E,UAAU,EAAE,MAAM,CAAA;IAClB,6EAA6E;IAC7E,WAAW,EAAE,MAAM,CAAA;IACnB,2EAA2E;IAC3E,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB,8CAA8C;IAC9C,UAAU,EAAE,eAAe,EAAE,CAAA;IAC7B,6DAA6D;IAC7D,YAAY,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAA;CACzC;AAED,gFAAgF;AAChF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAcjF"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { dimensionMeta, } from './design.logic.js';
|
|
2
|
+
import { assertHostPinned } from './http.js';
|
|
3
|
+
// Zeplin-specific pure logic, kept out of the provider shell so it is unit-testable
|
|
4
|
+
// without a live workspace: parsing/canonicalising a project+screen ref out of user input,
|
|
5
|
+
// the fixed-host SSRF guard, and mapping Zeplin's screens / components / design-tokens JSON
|
|
6
|
+
// into the source-neutral `DesignContext` the shared `renderDesignContext` emits. The
|
|
7
|
+
// `fetch` itself (the `Authorization: Bearer` REST client) lives in `ZeplinProvider`.
|
|
8
|
+
//
|
|
9
|
+
// Zeplin is the design→dev *handoff* tool, so its content model is screens + a
|
|
10
|
+
// design-system (components + tokens), NOT Figma's node tree — which is exactly why it
|
|
11
|
+
// rides the shared `DesignContext` rather than a Figma-shaped renderer.
|
|
12
|
+
/** Zeplin's REST API host. The PAT is sent to this host only — see {@link assertSafeZeplinUrl}. */
|
|
13
|
+
export const ZEPLIN_API_HOST = 'api.zeplin.dev';
|
|
14
|
+
/** What the connect UI renders, and which credentials the provider needs. */
|
|
15
|
+
export const ZEPLIN_DESCRIPTOR = {
|
|
16
|
+
source: 'zeplin',
|
|
17
|
+
label: 'Zeplin',
|
|
18
|
+
icon: 'i-lucide-layout-template',
|
|
19
|
+
credentialFields: [
|
|
20
|
+
{
|
|
21
|
+
key: 'apiToken',
|
|
22
|
+
label: 'Personal access token',
|
|
23
|
+
secret: true,
|
|
24
|
+
placeholder: 'zeplin PAT',
|
|
25
|
+
help: 'Create a personal access token in Zeplin → Profile → Developer → Personal access tokens. It is stored sealed and shared by the workspace.',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
refLabel: 'Zeplin project or screen URL',
|
|
29
|
+
refPlaceholder: 'https://app.zeplin.io/project/<projectId>/screen/<screenId>',
|
|
30
|
+
// No catalogue search exposed here — import a specific project/screen by URL.
|
|
31
|
+
searchable: false,
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The Zeplin REST host is fixed, so any request/redirect must stay on `api.zeplin.dev`
|
|
35
|
+
* over https; a redirect off-host is treated as an SSRF attempt and rejected. Mirrors the
|
|
36
|
+
* per-hop guard the other host-pinned providers run. Kept pure so it is unit-testable
|
|
37
|
+
* without a network.
|
|
38
|
+
*/
|
|
39
|
+
export function assertSafeZeplinUrl(url) {
|
|
40
|
+
assertHostPinned(url, ZEPLIN_API_HOST, 'Zeplin');
|
|
41
|
+
}
|
|
42
|
+
// ---- Ref parsing + canonical URL ------------------------------------------
|
|
43
|
+
const ID = /^[A-Za-z0-9]+$/;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a Zeplin reference from raw user input into the stable composite external id
|
|
46
|
+
* this provider stores: `"<projectId>"` for a whole-project link, or
|
|
47
|
+
* `"<projectId>:<screenId>"` for a specific screen. Accepts an `app.zeplin.io`
|
|
48
|
+
* project/screen URL, a bare project id, or a `projectId:screenId` string. Returns null
|
|
49
|
+
* when no project id is found.
|
|
50
|
+
*/
|
|
51
|
+
export function parseZeplinRef(input) {
|
|
52
|
+
const trimmed = input.trim();
|
|
53
|
+
if (!trimmed)
|
|
54
|
+
return null;
|
|
55
|
+
// Bare ref: a project id, optionally `:`-suffixed with a screen id.
|
|
56
|
+
if (!trimmed.includes('/') && !/zeplin\.io/i.test(trimmed)) {
|
|
57
|
+
const [project, screen, ...rest] = trimmed.split(':');
|
|
58
|
+
if (!project || !ID.test(project) || rest.length)
|
|
59
|
+
return null;
|
|
60
|
+
if (!screen)
|
|
61
|
+
return project;
|
|
62
|
+
return ID.test(screen) ? `${project}:${screen}` : project;
|
|
63
|
+
}
|
|
64
|
+
let url;
|
|
65
|
+
try {
|
|
66
|
+
url = new URL(trimmed);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
if (!/(^|\.)zeplin\.io$/i.test(url.hostname))
|
|
72
|
+
return null;
|
|
73
|
+
const project = url.pathname.match(/\/project\/([A-Za-z0-9]+)/)?.[1];
|
|
74
|
+
if (!project)
|
|
75
|
+
return null;
|
|
76
|
+
const screen = url.pathname.match(/\/screen\/([A-Za-z0-9]+)/)?.[1];
|
|
77
|
+
return screen ? `${project}:${screen}` : project;
|
|
78
|
+
}
|
|
79
|
+
/** Split a composite external id back into its project id and optional screen id. */
|
|
80
|
+
export function splitZeplinExternalId(externalId) {
|
|
81
|
+
const idx = externalId.indexOf(':');
|
|
82
|
+
if (idx === -1)
|
|
83
|
+
return { projectId: externalId };
|
|
84
|
+
return { projectId: externalId.slice(0, idx), screenId: externalId.slice(idx + 1) };
|
|
85
|
+
}
|
|
86
|
+
/** Build the canonical web URL stored on the imported document. */
|
|
87
|
+
export function zeplinUrlFor(externalId) {
|
|
88
|
+
const { projectId, screenId } = splitZeplinExternalId(externalId);
|
|
89
|
+
const base = `https://app.zeplin.io/project/${projectId}`;
|
|
90
|
+
return screenId ? `${base}/screen/${screenId}` : base;
|
|
91
|
+
}
|
|
92
|
+
// ---- Response envelope unwrapping -----------------------------------------
|
|
93
|
+
// Zeplin's REST responses are inconsistent about wrapping collections/objects in a named
|
|
94
|
+
// envelope (`{ screens: [...] }` / `{ screen: {...} }`) vs returning them bare, so every
|
|
95
|
+
// read normalises through these. Pure + exported so the provider shell stays a thin fetch
|
|
96
|
+
// layer and the unwrap is unit-testable without a network.
|
|
97
|
+
/** Accept either a bare array or a `{ <key>: [...] }` envelope, else an empty array. */
|
|
98
|
+
export function unwrapArray(value, key) {
|
|
99
|
+
if (Array.isArray(value))
|
|
100
|
+
return value;
|
|
101
|
+
if (value && typeof value === 'object') {
|
|
102
|
+
const inner = value[key];
|
|
103
|
+
if (Array.isArray(inner))
|
|
104
|
+
return inner;
|
|
105
|
+
}
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
/** Accept either a bare object or a `{ <key>: {...} }` envelope, else null. */
|
|
109
|
+
export function unwrapObject(value, key) {
|
|
110
|
+
if (!value || typeof value !== 'object')
|
|
111
|
+
return null;
|
|
112
|
+
const inner = value[key];
|
|
113
|
+
if (inner && typeof inner === 'object')
|
|
114
|
+
return inner;
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The single source of truth for how many screens a whole-project import pulls and
|
|
119
|
+
* renders: {@link ZeplinProvider} builds its `?limit=` query from this, and
|
|
120
|
+
* {@link zeplinScreensToBlocks} bounds the rendered blocks by it, so the fetch and the
|
|
121
|
+
* render can't drift.
|
|
122
|
+
*/
|
|
123
|
+
export const MAX_SCREENS = 40;
|
|
124
|
+
function screenMeta(screen) {
|
|
125
|
+
return dimensionMeta(screen.image?.width, screen.image?.height);
|
|
126
|
+
}
|
|
127
|
+
/** Map Zeplin screens into source-neutral blocks (name + an optional description line). */
|
|
128
|
+
export function zeplinScreensToBlocks(screens) {
|
|
129
|
+
return screens.slice(0, MAX_SCREENS).map((screen) => ({
|
|
130
|
+
title: screen.name?.trim() || '(unnamed screen)',
|
|
131
|
+
meta: screenMeta(screen),
|
|
132
|
+
sections: screen.description?.trim()
|
|
133
|
+
? [{ heading: 'Description', lines: [screen.description.trim()] }]
|
|
134
|
+
: [],
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
/** Map Zeplin components into source-neutral components (grouped by their section). */
|
|
138
|
+
export function zeplinComponentsToDesign(components) {
|
|
139
|
+
return components
|
|
140
|
+
.filter((c) => c.name?.trim())
|
|
141
|
+
.map((c) => ({
|
|
142
|
+
name: c.name.trim(),
|
|
143
|
+
group: c.section?.name?.trim() || undefined,
|
|
144
|
+
note: c.description?.trim() || undefined,
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
function colorHex(c) {
|
|
148
|
+
const to2 = (n) => Math.max(0, Math.min(255, Math.round(n ?? 0)))
|
|
149
|
+
.toString(16)
|
|
150
|
+
.padStart(2, '0');
|
|
151
|
+
const hex = `#${to2(c.r)}${to2(c.g)}${to2(c.b)}`;
|
|
152
|
+
return c.a != null && c.a < 1 ? `${hex} (a=${c.a.toFixed(2)})` : hex;
|
|
153
|
+
}
|
|
154
|
+
/** Map Zeplin design tokens (colours / typography / spacing) into source-neutral tokens. */
|
|
155
|
+
export function zeplinTokens(tokens) {
|
|
156
|
+
if (!tokens)
|
|
157
|
+
return [];
|
|
158
|
+
const out = [];
|
|
159
|
+
for (const c of tokens.colors ?? []) {
|
|
160
|
+
if (c.name?.trim())
|
|
161
|
+
out.push({ collection: 'Colors', name: c.name.trim(), value: colorHex(c) });
|
|
162
|
+
}
|
|
163
|
+
for (const t of tokens.text_styles ?? []) {
|
|
164
|
+
if (!t.name?.trim())
|
|
165
|
+
continue;
|
|
166
|
+
const value = [t.font_family, t.font_size != null ? `${t.font_size}px` : null]
|
|
167
|
+
.filter(Boolean)
|
|
168
|
+
.join(' ');
|
|
169
|
+
out.push({ collection: 'Typography', name: t.name.trim(), value: value || '—' });
|
|
170
|
+
}
|
|
171
|
+
for (const s of [...(tokens.spacing ?? []), ...(tokens.measurements ?? [])]) {
|
|
172
|
+
if (s.name?.trim()) {
|
|
173
|
+
out.push({ collection: 'Spacing', name: s.name.trim(), value: String(s.value ?? '') });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/** Assemble the fetched Zeplin pieces into the shared {@link DesignContext}. */
|
|
179
|
+
export function buildZeplinDesignContext(input) {
|
|
180
|
+
const { projectId, screenId } = splitZeplinExternalId(input.externalId);
|
|
181
|
+
const title = screenId && input.screens[0]?.name?.trim()
|
|
182
|
+
? `${input.projectName || projectId} — ${input.screens[0].name.trim()}`
|
|
183
|
+
: input.projectName || projectId;
|
|
184
|
+
return {
|
|
185
|
+
title,
|
|
186
|
+
url: zeplinUrlFor(input.externalId),
|
|
187
|
+
blocks: zeplinScreensToBlocks(input.screens),
|
|
188
|
+
components: zeplinComponentsToDesign(input.components),
|
|
189
|
+
tokens: zeplinTokens(input.designTokens),
|
|
190
|
+
references: [],
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=zeplin.logic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zeplin.logic.js","sourceRoot":"","sources":["../../../src/modules/documents/zeplin.logic.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,GAKd,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAE5C,oFAAoF;AACpF,2FAA2F;AAC3F,4FAA4F;AAC5F,sFAAsF;AACtF,sFAAsF;AACtF,EAAE;AACF,+EAA+E;AAC/E,uFAAuF;AACvF,wEAAwE;AAExE,mGAAmG;AACnG,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAgB,CAAA;AAE/C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAA6B;IACzD,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,QAAQ;IAC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
|
4
4
|
"description": "External-system integration domain logic for the Agent Architecture Board (GitHub, documents, tasks, environments, runners).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"ai": "^6.0.209",
|
|
28
|
-
"@cat-factory/contracts": "0.
|
|
29
|
-
"@cat-factory/kernel": "0.
|
|
28
|
+
"@cat-factory/contracts": "0.49.0",
|
|
29
|
+
"@cat-factory/kernel": "0.50.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"typescript": "7.0.1-rc",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClaudeDesignProvider.d.ts","sourceRoot":"","sources":["../../../src/modules/documents/ClaudeDesignProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAA;AA8C5B,qBAAa,oBAAqB,YAAW,sBAAsB;IACjE,QAAQ,CAAC,IAAI,EAAG,eAAe,CAAS;IACxC,QAAQ,CAAC,UAAU;;;;;;;;;;;;;;;MAA2B;IAE9C,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB,CAMpE;IAED,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAErC;IAEK,aAAa,CACjB,WAAW,EAAE,mBAAmB,EAChC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,CAAC,CAmB1B;IAED,0FAA0F;YAC5E,iBAAiB;IAoC/B,2FAA2F;YAC7E,SAAS;IA+BvB,yFAAyF;IACzF,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,OAAO;YAQD,GAAG;CAiBlB"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { ValidationError, } from '@cat-factory/kernel';
|
|
2
|
-
import { CLAUDE_DESIGN_API_HOST, CLAUDE_DESIGN_DESCRIPTOR, DS_MANIFEST_PATH, claudeDesignUrlFor, parseClaudeDesignRef, renderClaudeDesignProject, splitClaudeDesignExternalId, } from './claudeDesign.logic.js';
|
|
3
|
-
import { DocumentHttpError, createHostPinnedFetch, readCappedText } from './http.js';
|
|
4
|
-
// ClaudeDesignProvider: the document-source provider for Anthropic's Claude Design. It
|
|
5
|
-
// authenticates with a **per-user** personal access token (the credential is stored
|
|
6
|
-
// keyed by user id, not shared across the workspace — see the descriptor's
|
|
7
|
-
// `credentialScope: 'user'`), reads a design-system project's files over the REST API,
|
|
8
|
-
// and renders the component inventory + design tokens to the Markdown the planner +
|
|
9
|
-
// `.cat-context/` materialisation consume. All Claude-Design-specific *pure* logic (ref
|
|
10
|
-
// parsing, the host-pin guard, the HTML/manifest → Markdown normalizer) lives in
|
|
11
|
-
// `claudeDesign.logic.ts`; this class is the thin `fetch` shell.
|
|
12
|
-
//
|
|
13
|
-
// PROVISIONAL API SHAPE: the endpoint paths/headers below target the per-user-PAT read
|
|
14
|
-
// the product is moving toward (today the design-system read is claude.ai-login-bound).
|
|
15
|
-
// The host is pinned; re-verify the exact endpoints against the current API when the
|
|
16
|
-
// credentialed read ships — they are the intended shape, not a frozen contract. The
|
|
17
|
-
// normalizer they feed is solid and fully unit-tested regardless.
|
|
18
|
-
const API_BASE = `https://${CLAUDE_DESIGN_API_HOST}/v1`;
|
|
19
|
-
const USER_AGENT = 'cat-factory';
|
|
20
|
-
/** Hard cap on the bytes read off any response body, to protect the isolate. */
|
|
21
|
-
const MAX_RESPONSE_BYTES = 5_000_000;
|
|
22
|
-
/** Bound how many project files we pull for a whole-project import. */
|
|
23
|
-
const MAX_PROJECT_FILES = 12;
|
|
24
|
-
/**
|
|
25
|
-
* `fetch` pinned to the Claude Design host, following redirects by hand so the SSRF host
|
|
26
|
-
* guard runs against every hop (a 302 can't chase the PAT off-host). Shared transport.
|
|
27
|
-
*/
|
|
28
|
-
const safeFetch = createHostPinnedFetch({ host: CLAUDE_DESIGN_API_HOST, label: 'Claude Design' });
|
|
29
|
-
export class ClaudeDesignProvider {
|
|
30
|
-
kind = 'claude-design';
|
|
31
|
-
descriptor = CLAUDE_DESIGN_DESCRIPTOR;
|
|
32
|
-
normalizeConnection(input) {
|
|
33
|
-
const apiToken = input.apiToken?.trim();
|
|
34
|
-
if (!apiToken) {
|
|
35
|
-
throw new ValidationError('Claude Design requires a personal access token');
|
|
36
|
-
}
|
|
37
|
-
return { credentials: { apiToken }, label: 'Claude Design' };
|
|
38
|
-
}
|
|
39
|
-
parseRef(input) {
|
|
40
|
-
return parseClaudeDesignRef(input);
|
|
41
|
-
}
|
|
42
|
-
async fetchDocument(credentials, externalId) {
|
|
43
|
-
const { projectId, filePath } = splitClaudeDesignExternalId(externalId);
|
|
44
|
-
if (!projectId) {
|
|
45
|
-
throw new DocumentHttpError(400, `Claude Design ref is missing a project id: ${externalId}`);
|
|
46
|
-
}
|
|
47
|
-
const files = filePath
|
|
48
|
-
? [{ path: filePath, content: await this.fetchFile(credentials, projectId, filePath) }]
|
|
49
|
-
: await this.fetchProjectFiles(credentials, projectId);
|
|
50
|
-
const projectName = this.deriveName(projectId, filePath, files);
|
|
51
|
-
const body = renderClaudeDesignProject(projectName, files);
|
|
52
|
-
return {
|
|
53
|
-
externalId,
|
|
54
|
-
title: projectName,
|
|
55
|
-
url: claudeDesignUrlFor(externalId),
|
|
56
|
-
body,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/** List a project's files, then fetch the manifest + a bounded slice of HTML previews. */
|
|
60
|
-
async fetchProjectFiles(credentials, projectId) {
|
|
61
|
-
const listed = await this.get(credentials, `/design/projects/${encodeURIComponent(projectId)}/files`);
|
|
62
|
-
const paths = normalizePaths(listed);
|
|
63
|
-
if (paths.length === 0) {
|
|
64
|
-
throw new DocumentHttpError(404, `Claude Design project ${projectId} has no readable files`);
|
|
65
|
-
}
|
|
66
|
-
// The manifest is the authoritative index; then prefer component-preview HTML and any
|
|
67
|
-
// stylesheet (for tokens), bounded so a huge project can't stall the import.
|
|
68
|
-
const manifest = paths.filter((p) => p.endsWith(DS_MANIFEST_PATH));
|
|
69
|
-
const styles = paths.filter((p) => /\.css$/i.test(p));
|
|
70
|
-
const html = paths.filter((p) => /\.html?$/i.test(p));
|
|
71
|
-
const chosen = [...manifest, ...styles, ...html].slice(0, MAX_PROJECT_FILES);
|
|
72
|
-
const out = [];
|
|
73
|
-
for (const path of chosen) {
|
|
74
|
-
try {
|
|
75
|
-
out.push({ path, content: await this.fetchFile(credentials, projectId, path) });
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
// A single unreadable file shouldn't fail the whole import — skip it.
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (out.length === 0) {
|
|
82
|
-
throw new DocumentHttpError(502, `Claude Design project ${projectId} returned no file content`);
|
|
83
|
-
}
|
|
84
|
-
return out;
|
|
85
|
-
}
|
|
86
|
-
/** Fetch one file's textual content (raw, or unwrapped from a `{ content }` JSON body). */
|
|
87
|
-
async fetchFile(credentials, projectId, path) {
|
|
88
|
-
const url = `${API_BASE}/design/projects/${encodeURIComponent(projectId)}/files/${path
|
|
89
|
-
.split('/')
|
|
90
|
-
.map(encodeURIComponent)
|
|
91
|
-
.join('/')}`;
|
|
92
|
-
const res = await safeFetch(url, { method: 'GET', headers: this.headers(credentials) });
|
|
93
|
-
if (!res.ok) {
|
|
94
|
-
const text = await readCappedText(res, MAX_RESPONSE_BYTES, 'Claude Design').catch(() => '');
|
|
95
|
-
throw new DocumentHttpError(res.status, `Claude Design GET ${url} → ${res.status}: ${text.slice(0, 300)}`);
|
|
96
|
-
}
|
|
97
|
-
const text = await readCappedText(res, MAX_RESPONSE_BYTES, 'Claude Design');
|
|
98
|
-
// The files endpoint may return raw file bytes or a `{ content }` JSON envelope.
|
|
99
|
-
const contentType = res.headers.get('content-type') ?? '';
|
|
100
|
-
if (contentType.includes('application/json')) {
|
|
101
|
-
try {
|
|
102
|
-
const json = JSON.parse(text);
|
|
103
|
-
if (typeof json.content === 'string')
|
|
104
|
-
return json.content;
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
// Not a JSON envelope after all — fall through and use the raw text.
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return text;
|
|
111
|
-
}
|
|
112
|
-
/** Name the document: the manifest's `name`, else the file path, else the project id. */
|
|
113
|
-
deriveName(projectId, filePath, files) {
|
|
114
|
-
const manifest = files.find((f) => f.path.endsWith(DS_MANIFEST_PATH));
|
|
115
|
-
if (manifest) {
|
|
116
|
-
try {
|
|
117
|
-
const json = JSON.parse(manifest.content);
|
|
118
|
-
if (typeof json.name === 'string' && json.name.trim())
|
|
119
|
-
return json.name.trim();
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
// ignore — fall through
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (filePath)
|
|
126
|
-
return `${projectId} — ${filePath}`;
|
|
127
|
-
return projectId;
|
|
128
|
-
}
|
|
129
|
-
headers(credentials) {
|
|
130
|
-
return {
|
|
131
|
-
authorization: `Bearer ${credentials.apiToken ?? ''}`,
|
|
132
|
-
accept: 'application/json',
|
|
133
|
-
'user-agent': USER_AGENT,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
async get(credentials, path) {
|
|
137
|
-
const url = `${API_BASE}${path}`;
|
|
138
|
-
const res = await safeFetch(url, { method: 'GET', headers: this.headers(credentials) });
|
|
139
|
-
if (!res.ok) {
|
|
140
|
-
const text = await readCappedText(res, MAX_RESPONSE_BYTES, 'Claude Design').catch(() => '');
|
|
141
|
-
throw new DocumentHttpError(res.status, `Claude Design GET ${url} → ${res.status}: ${text.slice(0, 300)}`);
|
|
142
|
-
}
|
|
143
|
-
const text = await readCappedText(res, MAX_RESPONSE_BYTES, 'Claude Design');
|
|
144
|
-
try {
|
|
145
|
-
return JSON.parse(text);
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
throw new DocumentHttpError(502, `Claude Design returned an unparseable body for ${path}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/** Flatten the file-list response into a clean string[] of paths. */
|
|
153
|
-
function normalizePaths(listed) {
|
|
154
|
-
const raw = listed.files ?? listed.paths ?? [];
|
|
155
|
-
const out = [];
|
|
156
|
-
for (const entry of raw) {
|
|
157
|
-
const path = typeof entry === 'string' ? entry : entry?.path;
|
|
158
|
-
if (typeof path === 'string' && path.trim())
|
|
159
|
-
out.push(path.trim());
|
|
160
|
-
}
|
|
161
|
-
return out;
|
|
162
|
-
}
|
|
163
|
-
//# sourceMappingURL=ClaudeDesignProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClaudeDesignProvider.js","sourceRoot":"","sources":["../../../src/modules/documents/ClaudeDesignProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAKhB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,2BAA2B,GAE5B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAEpF,uFAAuF;AACvF,oFAAoF;AACpF,2EAA2E;AAC3E,uFAAuF;AACvF,oFAAoF;AACpF,wFAAwF;AACxF,iFAAiF;AACjF,iEAAiE;AACjE,EAAE;AACF,uFAAuF;AACvF,wFAAwF;AACxF,qFAAqF;AACrF,oFAAoF;AACpF,kEAAkE;AAElE,MAAM,QAAQ,GAAG,WAAW,sBAAsB,KAAK,CAAA;AACvD,MAAM,UAAU,GAAG,aAAa,CAAA;AAChC,gFAAgF;AAChF,MAAM,kBAAkB,GAAG,SAAS,CAAA;AACpC,uEAAuE;AACvE,MAAM,iBAAiB,GAAG,EA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,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAA;QAC5D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE;YAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACpE,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { DocumentSourceDescriptor } from '@cat-factory/kernel';
|
|
2
|
-
/**
|
|
3
|
-
* Claude Design's programmatic-read host. PROVISIONAL: today the design-system read is
|
|
4
|
-
* bound to a claude.ai login; this provider targets the per-user-PAT API shape the
|
|
5
|
-
* product is moving toward. The host is pinned (see {@link assertSafeClaudeDesignUrl})
|
|
6
|
-
* and the exact endpoints in `ClaudeDesignProvider` should be re-verified against the
|
|
7
|
-
* current API when the credentialed read ships — treat them as the intended shape, not a
|
|
8
|
-
* frozen contract.
|
|
9
|
-
*/
|
|
10
|
-
export declare const CLAUDE_DESIGN_API_HOST = "api.claude.com";
|
|
11
|
-
/** Where a human opens the project (the canonical URL stored on imported documents). */
|
|
12
|
-
export declare const CLAUDE_DESIGN_APP_HOST = "claude.ai";
|
|
13
|
-
/** What the connect UI renders, and which credentials the provider needs. */
|
|
14
|
-
export declare const CLAUDE_DESIGN_DESCRIPTOR: DocumentSourceDescriptor;
|
|
15
|
-
/**
|
|
16
|
-
* The Claude Design read host is fixed, so any request/redirect must stay on it over
|
|
17
|
-
* https. A redirect off-host (e.g. to a link-local metadata address) is rejected as an
|
|
18
|
-
* SSRF attempt. Delegates to the shared host-pin guard; throws a plain `Error` the
|
|
19
|
-
* provider maps to a `DocumentHttpError`. Kept pure so it is unit-testable without a
|
|
20
|
-
* network.
|
|
21
|
-
*/
|
|
22
|
-
export declare function assertSafeClaudeDesignUrl(url: string): void;
|
|
23
|
-
/**
|
|
24
|
-
* Resolve a Claude Design reference from raw user input into the stable composite
|
|
25
|
-
* external id this provider stores: `"<projectId>"` for a whole project, or
|
|
26
|
-
* `"<projectId>::<filePath>"` for a single component/file. Accepts a
|
|
27
|
-
* `claude.ai/design/<projectId>` URL (optionally `…/files/<path>` or `?file=<path>`), a
|
|
28
|
-
* bare project id, or the composite form. Returns null when no project id is found.
|
|
29
|
-
*
|
|
30
|
-
* Deterministic (same input → same external id), which the
|
|
31
|
-
* `(workspace, source, externalId)` document key relies on for de-duplication.
|
|
32
|
-
*/
|
|
33
|
-
export declare function parseClaudeDesignRef(input: string): string | null;
|
|
34
|
-
/** Split a composite external id back into its project id and optional file path. */
|
|
35
|
-
export declare function splitClaudeDesignExternalId(externalId: string): {
|
|
36
|
-
projectId: string;
|
|
37
|
-
filePath?: string;
|
|
38
|
-
};
|
|
39
|
-
/** Build the canonical web URL stored on the imported document (matched by `getByUrl`). */
|
|
40
|
-
export declare function claudeDesignUrlFor(externalId: string): string;
|
|
41
|
-
/** A single component card, as recorded by Claude Design's `@dsCard` markers/manifest. */
|
|
42
|
-
export interface DsCard {
|
|
43
|
-
name?: string;
|
|
44
|
-
group?: string;
|
|
45
|
-
subtitle?: string;
|
|
46
|
-
path?: string;
|
|
47
|
-
}
|
|
48
|
-
/** One fetched project file (path + raw textual content). */
|
|
49
|
-
export interface ClaudeDesignFile {
|
|
50
|
-
path: string;
|
|
51
|
-
content: string;
|
|
52
|
-
}
|
|
53
|
-
/** The manifest file name Claude Design compiles its card index into. */
|
|
54
|
-
export declare const DS_MANIFEST_PATH = "_ds_manifest.json";
|
|
55
|
-
/**
|
|
56
|
-
* Parse a `_ds_manifest.json` payload (a bare array of cards, or `{ cards: [...] }`)
|
|
57
|
-
* into a lenient {@link DsCard} list. Unknown shapes yield `[]` so the caller falls
|
|
58
|
-
* back to per-file HTML extraction.
|
|
59
|
-
*/
|
|
60
|
-
export declare function parseDsManifest(json: unknown): DsCard[];
|
|
61
|
-
/**
|
|
62
|
-
* Read the first-line `<!-- @dsCard group="…" name="…" subtitle="…" -->` marker Claude
|
|
63
|
-
* Design writes at the top of each component-preview HTML. Returns null when absent.
|
|
64
|
-
*/
|
|
65
|
-
export declare function parseDsCardComment(html: string): DsCard | null;
|
|
66
|
-
/**
|
|
67
|
-
* Extract CSS custom properties (`--token: value`) from a stylesheet/HTML blob as design
|
|
68
|
-
* tokens, deduped (last value wins) and sorted. These are Claude Design's design tokens —
|
|
69
|
-
* the analogue of Figma variables.
|
|
70
|
-
*/
|
|
71
|
-
export declare function extractCssTokens(content: string): string[];
|
|
72
|
-
/** Strip `<script>`/`<style>` blocks and all tags, returning collapsed visible text. */
|
|
73
|
-
export declare function htmlToText(html: string): string;
|
|
74
|
-
/** Render a grouped component inventory from a card list (`### <group>` → `- <name>`). */
|
|
75
|
-
export declare function dsCardsToMarkdown(cards: DsCard[]): string;
|
|
76
|
-
/**
|
|
77
|
-
* Normalize a whole Claude Design project's fetched files into the lightweight Markdown a
|
|
78
|
-
* frontend agent consumes. Strategy:
|
|
79
|
-
* 1. If a `_ds_manifest.json` is present, it is the authoritative component index →
|
|
80
|
-
* `### Components` grouped inventory.
|
|
81
|
-
* 2. Otherwise, recover the inventory from each preview HTML's `@dsCard` marker.
|
|
82
|
-
* 3. Design tokens are unioned from the CSS custom properties across all files.
|
|
83
|
-
* 4. A bounded slice of visible text gives the agent a sense of the content.
|
|
84
|
-
*
|
|
85
|
-
* `projectName` titles the document. Pure: no network, fully unit-testable.
|
|
86
|
-
*/
|
|
87
|
-
export declare function renderClaudeDesignProject(projectName: string, files: ClaudeDesignFile[]): string;
|
|
88
|
-
//# sourceMappingURL=claudeDesign.logic.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claudeDesign.logic.d.ts","sourceRoot":"","sources":["../../../src/modules/documents/claudeDesign.logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAmBnE;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,mBAAmB,C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