@biela.dev/ai-bridge 0.1.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.cjs +470 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +193 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +458 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { DeviceLayoutContract } from '@biela.dev/devices';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Serialize a Device Layout Contract into a complete AI instruction prompt.
|
|
5
|
+
*
|
|
6
|
+
* This is the core of the AI Bridge — it converts structured device data
|
|
7
|
+
* into precise natural language instructions that Claude can follow to
|
|
8
|
+
* generate pixel-perfect mobile UI components.
|
|
9
|
+
*/
|
|
10
|
+
declare function serializeDLCForAI(dlc: DeviceLayoutContract, appDescription: string): string;
|
|
11
|
+
|
|
12
|
+
/** Result of UI generation */
|
|
13
|
+
interface GenerationResult {
|
|
14
|
+
code: string;
|
|
15
|
+
contract: DeviceLayoutContract;
|
|
16
|
+
metadata: {
|
|
17
|
+
device: string;
|
|
18
|
+
generatedAt: string;
|
|
19
|
+
promptUsed: string;
|
|
20
|
+
enrichedDescription: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Parameters for generateMobileUI */
|
|
24
|
+
interface GenerateMobileUIParams {
|
|
25
|
+
deviceId: string;
|
|
26
|
+
appDescription: string;
|
|
27
|
+
orientation?: "portrait";
|
|
28
|
+
style?: "ios-native" | "android-native" | "custom";
|
|
29
|
+
darkMode?: boolean;
|
|
30
|
+
/** Claude API key — falls back to CLAUDE_API_KEY env var */
|
|
31
|
+
claudeApiKey?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Parameters for refineUI */
|
|
34
|
+
interface RefineUIParams {
|
|
35
|
+
previousCode: string;
|
|
36
|
+
contract: DeviceLayoutContract;
|
|
37
|
+
refinementInstruction: string;
|
|
38
|
+
claudeApiKey?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Result of UI refinement */
|
|
41
|
+
interface RefinementResult {
|
|
42
|
+
code: string;
|
|
43
|
+
changesSummary: string;
|
|
44
|
+
}
|
|
45
|
+
/** Validation result from validateGeneratedUI */
|
|
46
|
+
interface ValidationResult {
|
|
47
|
+
valid: boolean;
|
|
48
|
+
warnings: string[];
|
|
49
|
+
errors: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Compact DLC summary for refinement prompts (prompt #2+).
|
|
54
|
+
*
|
|
55
|
+
* Instead of re-sending the full ~2000-token DLC prompt on every turn,
|
|
56
|
+
* this produces a short reminder (~200 tokens) with just the device ID,
|
|
57
|
+
* dimensions, and any validation errors/warnings from the previous render.
|
|
58
|
+
*/
|
|
59
|
+
declare function serializeCompactDLC(dlc: DeviceLayoutContract, validation?: ValidationResult): string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Validate generated UI code against a Device Layout Contract.
|
|
63
|
+
*
|
|
64
|
+
* Performs static analysis on the code string to catch common constraint
|
|
65
|
+
* violations before rendering. This is a best-effort check — it catches
|
|
66
|
+
* obvious issues but can't guarantee pixel-perfect compliance.
|
|
67
|
+
*/
|
|
68
|
+
declare function validateGeneratedUI(code: string, dlc: DeviceLayoutContract): ValidationResult;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Enrich a short app description into a detailed feature specification.
|
|
72
|
+
*
|
|
73
|
+
* Takes a brief prompt like "a banking app" and returns a 150-200 word
|
|
74
|
+
* structured specification including screens, navigation patterns,
|
|
75
|
+
* data types, and interactions appropriate for the target platform.
|
|
76
|
+
*/
|
|
77
|
+
declare function enrichAppDescription(rawPrompt: string, dlc: DeviceLayoutContract, apiKey?: string): Promise<string>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generate a mobile UI component for a specific device.
|
|
81
|
+
*
|
|
82
|
+
* Full pipeline: device lookup → DLC retrieval → description enrichment →
|
|
83
|
+
* prompt serialization → Claude API call → code extraction → validation.
|
|
84
|
+
*/
|
|
85
|
+
declare function generateMobileUI(params: GenerateMobileUIParams): Promise<GenerationResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Refine a previously generated UI component.
|
|
88
|
+
*
|
|
89
|
+
* Enables iterative improvements without re-running the full generation
|
|
90
|
+
* pipeline. Sends the previous code + refinement instruction to Claude.
|
|
91
|
+
*/
|
|
92
|
+
declare function refineUI(params: RefineUIParams): Promise<RefinementResult>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Tracks prompt session state to determine whether to send the full DLC
|
|
96
|
+
* injection (first prompt) or a compact summary (subsequent prompts).
|
|
97
|
+
*
|
|
98
|
+
* Usage:
|
|
99
|
+
* const session = createPromptSession(dlc, "a banking app");
|
|
100
|
+
* session.getInjection(); // → full DLC prompt (first time)
|
|
101
|
+
* session.getInjection(); // → compact summary (second time onward)
|
|
102
|
+
* session.getInjection({ validation }); // → compact + validation feedback
|
|
103
|
+
* session.switchDevice(newDlc); // → resets to full prompt for new device
|
|
104
|
+
*/
|
|
105
|
+
interface PromptSession {
|
|
106
|
+
/** Get the appropriate injection for the current turn. */
|
|
107
|
+
getInjection(opts?: {
|
|
108
|
+
validation?: ValidationResult;
|
|
109
|
+
}): string;
|
|
110
|
+
/** How many prompts have been sent in this session. */
|
|
111
|
+
getTurnCount(): number;
|
|
112
|
+
/** Whether this is the first prompt (full DLC will be sent). */
|
|
113
|
+
isFirstTurn(): boolean;
|
|
114
|
+
/** Switch to a different device — resets the session so the next injection is full. */
|
|
115
|
+
switchDevice(dlc: DeviceLayoutContract): void;
|
|
116
|
+
/** Get the current device contract. */
|
|
117
|
+
getContract(): DeviceLayoutContract;
|
|
118
|
+
/** Force the next injection to be a full DLC prompt (useful after settings changes). */
|
|
119
|
+
resetToFull(): void;
|
|
120
|
+
/** Get history of all injections sent. */
|
|
121
|
+
getHistory(): PromptHistoryEntry[];
|
|
122
|
+
}
|
|
123
|
+
interface PromptHistoryEntry {
|
|
124
|
+
turn: number;
|
|
125
|
+
type: "full" | "compact";
|
|
126
|
+
deviceId: string;
|
|
127
|
+
injection: string;
|
|
128
|
+
timestamp: number;
|
|
129
|
+
}
|
|
130
|
+
declare function createPromptSession(initialDlc: DeviceLayoutContract, appDescription: string): PromptSession;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Injection settings — configurable overrides for the DLC prompt injection.
|
|
134
|
+
*
|
|
135
|
+
* Lets users customize what gets injected, toggle integration modes,
|
|
136
|
+
* and add custom constraints or remove default ones.
|
|
137
|
+
*/
|
|
138
|
+
interface InjectionSettings {
|
|
139
|
+
/** Integration modes — toggle on/off */
|
|
140
|
+
modes: {
|
|
141
|
+
/** NPM SDK mode: serializeDLCForAI() + validateGeneratedUI() used as imports */
|
|
142
|
+
sdk: boolean;
|
|
143
|
+
/** API mode: Studio exposes DLC over local HTTP/WebSocket */
|
|
144
|
+
api: boolean;
|
|
145
|
+
/** Built-in generation: generateMobileUI() calls Claude directly */
|
|
146
|
+
builtinGeneration: boolean;
|
|
147
|
+
};
|
|
148
|
+
/** Prompt customization */
|
|
149
|
+
prompt: {
|
|
150
|
+
/** Additional constraints to append to the DLC prompt */
|
|
151
|
+
extraConstraints: string[];
|
|
152
|
+
/** Constraints to suppress from the default DLC prompt (matched by substring) */
|
|
153
|
+
suppressedConstraints: string[];
|
|
154
|
+
/** Custom app description prefix (prepended to user's description) */
|
|
155
|
+
descriptionPrefix: string;
|
|
156
|
+
/** Custom app description suffix (appended to user's description) */
|
|
157
|
+
descriptionSuffix: string;
|
|
158
|
+
/** Override the design language instruction */
|
|
159
|
+
designLanguageOverride: string | null;
|
|
160
|
+
/** Override the output requirements section entirely */
|
|
161
|
+
outputRequirementsOverride: string[] | null;
|
|
162
|
+
};
|
|
163
|
+
/** Validation settings */
|
|
164
|
+
validation: {
|
|
165
|
+
/** Treat warnings as errors */
|
|
166
|
+
strictMode: boolean;
|
|
167
|
+
/** Disable specific warning checks by ID */
|
|
168
|
+
suppressedWarnings: string[];
|
|
169
|
+
/** Auto-inject validation feedback into refinement prompts */
|
|
170
|
+
autoFeedback: boolean;
|
|
171
|
+
};
|
|
172
|
+
/** API server settings (when api mode is enabled) */
|
|
173
|
+
apiServer: {
|
|
174
|
+
port: number;
|
|
175
|
+
host: string;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
declare function createDefaultSettings(): InjectionSettings;
|
|
179
|
+
/**
|
|
180
|
+
* Apply injection settings to modify a generated prompt.
|
|
181
|
+
* Processes suppressions and additions.
|
|
182
|
+
*/
|
|
183
|
+
declare function applySettingsToPrompt(prompt: string, settings: InjectionSettings): string;
|
|
184
|
+
/**
|
|
185
|
+
* Serialize settings to JSON for persistence (localStorage, file, etc.)
|
|
186
|
+
*/
|
|
187
|
+
declare function serializeSettings(settings: InjectionSettings): string;
|
|
188
|
+
/**
|
|
189
|
+
* Deserialize settings from JSON, merging with defaults for missing fields.
|
|
190
|
+
*/
|
|
191
|
+
declare function deserializeSettings(json: string): InjectionSettings;
|
|
192
|
+
|
|
193
|
+
export { type GenerateMobileUIParams, type GenerationResult, type InjectionSettings, type PromptHistoryEntry, type PromptSession, type RefineUIParams, type RefinementResult, type ValidationResult, applySettingsToPrompt, createDefaultSettings, createPromptSession, deserializeSettings, enrichAppDescription, generateMobileUI, refineUI, serializeCompactDLC, serializeDLCForAI, serializeSettings, validateGeneratedUI };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { DeviceLayoutContract } from '@biela.dev/devices';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Serialize a Device Layout Contract into a complete AI instruction prompt.
|
|
5
|
+
*
|
|
6
|
+
* This is the core of the AI Bridge — it converts structured device data
|
|
7
|
+
* into precise natural language instructions that Claude can follow to
|
|
8
|
+
* generate pixel-perfect mobile UI components.
|
|
9
|
+
*/
|
|
10
|
+
declare function serializeDLCForAI(dlc: DeviceLayoutContract, appDescription: string): string;
|
|
11
|
+
|
|
12
|
+
/** Result of UI generation */
|
|
13
|
+
interface GenerationResult {
|
|
14
|
+
code: string;
|
|
15
|
+
contract: DeviceLayoutContract;
|
|
16
|
+
metadata: {
|
|
17
|
+
device: string;
|
|
18
|
+
generatedAt: string;
|
|
19
|
+
promptUsed: string;
|
|
20
|
+
enrichedDescription: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Parameters for generateMobileUI */
|
|
24
|
+
interface GenerateMobileUIParams {
|
|
25
|
+
deviceId: string;
|
|
26
|
+
appDescription: string;
|
|
27
|
+
orientation?: "portrait";
|
|
28
|
+
style?: "ios-native" | "android-native" | "custom";
|
|
29
|
+
darkMode?: boolean;
|
|
30
|
+
/** Claude API key — falls back to CLAUDE_API_KEY env var */
|
|
31
|
+
claudeApiKey?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Parameters for refineUI */
|
|
34
|
+
interface RefineUIParams {
|
|
35
|
+
previousCode: string;
|
|
36
|
+
contract: DeviceLayoutContract;
|
|
37
|
+
refinementInstruction: string;
|
|
38
|
+
claudeApiKey?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Result of UI refinement */
|
|
41
|
+
interface RefinementResult {
|
|
42
|
+
code: string;
|
|
43
|
+
changesSummary: string;
|
|
44
|
+
}
|
|
45
|
+
/** Validation result from validateGeneratedUI */
|
|
46
|
+
interface ValidationResult {
|
|
47
|
+
valid: boolean;
|
|
48
|
+
warnings: string[];
|
|
49
|
+
errors: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Compact DLC summary for refinement prompts (prompt #2+).
|
|
54
|
+
*
|
|
55
|
+
* Instead of re-sending the full ~2000-token DLC prompt on every turn,
|
|
56
|
+
* this produces a short reminder (~200 tokens) with just the device ID,
|
|
57
|
+
* dimensions, and any validation errors/warnings from the previous render.
|
|
58
|
+
*/
|
|
59
|
+
declare function serializeCompactDLC(dlc: DeviceLayoutContract, validation?: ValidationResult): string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Validate generated UI code against a Device Layout Contract.
|
|
63
|
+
*
|
|
64
|
+
* Performs static analysis on the code string to catch common constraint
|
|
65
|
+
* violations before rendering. This is a best-effort check — it catches
|
|
66
|
+
* obvious issues but can't guarantee pixel-perfect compliance.
|
|
67
|
+
*/
|
|
68
|
+
declare function validateGeneratedUI(code: string, dlc: DeviceLayoutContract): ValidationResult;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Enrich a short app description into a detailed feature specification.
|
|
72
|
+
*
|
|
73
|
+
* Takes a brief prompt like "a banking app" and returns a 150-200 word
|
|
74
|
+
* structured specification including screens, navigation patterns,
|
|
75
|
+
* data types, and interactions appropriate for the target platform.
|
|
76
|
+
*/
|
|
77
|
+
declare function enrichAppDescription(rawPrompt: string, dlc: DeviceLayoutContract, apiKey?: string): Promise<string>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generate a mobile UI component for a specific device.
|
|
81
|
+
*
|
|
82
|
+
* Full pipeline: device lookup → DLC retrieval → description enrichment →
|
|
83
|
+
* prompt serialization → Claude API call → code extraction → validation.
|
|
84
|
+
*/
|
|
85
|
+
declare function generateMobileUI(params: GenerateMobileUIParams): Promise<GenerationResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Refine a previously generated UI component.
|
|
88
|
+
*
|
|
89
|
+
* Enables iterative improvements without re-running the full generation
|
|
90
|
+
* pipeline. Sends the previous code + refinement instruction to Claude.
|
|
91
|
+
*/
|
|
92
|
+
declare function refineUI(params: RefineUIParams): Promise<RefinementResult>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Tracks prompt session state to determine whether to send the full DLC
|
|
96
|
+
* injection (first prompt) or a compact summary (subsequent prompts).
|
|
97
|
+
*
|
|
98
|
+
* Usage:
|
|
99
|
+
* const session = createPromptSession(dlc, "a banking app");
|
|
100
|
+
* session.getInjection(); // → full DLC prompt (first time)
|
|
101
|
+
* session.getInjection(); // → compact summary (second time onward)
|
|
102
|
+
* session.getInjection({ validation }); // → compact + validation feedback
|
|
103
|
+
* session.switchDevice(newDlc); // → resets to full prompt for new device
|
|
104
|
+
*/
|
|
105
|
+
interface PromptSession {
|
|
106
|
+
/** Get the appropriate injection for the current turn. */
|
|
107
|
+
getInjection(opts?: {
|
|
108
|
+
validation?: ValidationResult;
|
|
109
|
+
}): string;
|
|
110
|
+
/** How many prompts have been sent in this session. */
|
|
111
|
+
getTurnCount(): number;
|
|
112
|
+
/** Whether this is the first prompt (full DLC will be sent). */
|
|
113
|
+
isFirstTurn(): boolean;
|
|
114
|
+
/** Switch to a different device — resets the session so the next injection is full. */
|
|
115
|
+
switchDevice(dlc: DeviceLayoutContract): void;
|
|
116
|
+
/** Get the current device contract. */
|
|
117
|
+
getContract(): DeviceLayoutContract;
|
|
118
|
+
/** Force the next injection to be a full DLC prompt (useful after settings changes). */
|
|
119
|
+
resetToFull(): void;
|
|
120
|
+
/** Get history of all injections sent. */
|
|
121
|
+
getHistory(): PromptHistoryEntry[];
|
|
122
|
+
}
|
|
123
|
+
interface PromptHistoryEntry {
|
|
124
|
+
turn: number;
|
|
125
|
+
type: "full" | "compact";
|
|
126
|
+
deviceId: string;
|
|
127
|
+
injection: string;
|
|
128
|
+
timestamp: number;
|
|
129
|
+
}
|
|
130
|
+
declare function createPromptSession(initialDlc: DeviceLayoutContract, appDescription: string): PromptSession;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Injection settings — configurable overrides for the DLC prompt injection.
|
|
134
|
+
*
|
|
135
|
+
* Lets users customize what gets injected, toggle integration modes,
|
|
136
|
+
* and add custom constraints or remove default ones.
|
|
137
|
+
*/
|
|
138
|
+
interface InjectionSettings {
|
|
139
|
+
/** Integration modes — toggle on/off */
|
|
140
|
+
modes: {
|
|
141
|
+
/** NPM SDK mode: serializeDLCForAI() + validateGeneratedUI() used as imports */
|
|
142
|
+
sdk: boolean;
|
|
143
|
+
/** API mode: Studio exposes DLC over local HTTP/WebSocket */
|
|
144
|
+
api: boolean;
|
|
145
|
+
/** Built-in generation: generateMobileUI() calls Claude directly */
|
|
146
|
+
builtinGeneration: boolean;
|
|
147
|
+
};
|
|
148
|
+
/** Prompt customization */
|
|
149
|
+
prompt: {
|
|
150
|
+
/** Additional constraints to append to the DLC prompt */
|
|
151
|
+
extraConstraints: string[];
|
|
152
|
+
/** Constraints to suppress from the default DLC prompt (matched by substring) */
|
|
153
|
+
suppressedConstraints: string[];
|
|
154
|
+
/** Custom app description prefix (prepended to user's description) */
|
|
155
|
+
descriptionPrefix: string;
|
|
156
|
+
/** Custom app description suffix (appended to user's description) */
|
|
157
|
+
descriptionSuffix: string;
|
|
158
|
+
/** Override the design language instruction */
|
|
159
|
+
designLanguageOverride: string | null;
|
|
160
|
+
/** Override the output requirements section entirely */
|
|
161
|
+
outputRequirementsOverride: string[] | null;
|
|
162
|
+
};
|
|
163
|
+
/** Validation settings */
|
|
164
|
+
validation: {
|
|
165
|
+
/** Treat warnings as errors */
|
|
166
|
+
strictMode: boolean;
|
|
167
|
+
/** Disable specific warning checks by ID */
|
|
168
|
+
suppressedWarnings: string[];
|
|
169
|
+
/** Auto-inject validation feedback into refinement prompts */
|
|
170
|
+
autoFeedback: boolean;
|
|
171
|
+
};
|
|
172
|
+
/** API server settings (when api mode is enabled) */
|
|
173
|
+
apiServer: {
|
|
174
|
+
port: number;
|
|
175
|
+
host: string;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
declare function createDefaultSettings(): InjectionSettings;
|
|
179
|
+
/**
|
|
180
|
+
* Apply injection settings to modify a generated prompt.
|
|
181
|
+
* Processes suppressions and additions.
|
|
182
|
+
*/
|
|
183
|
+
declare function applySettingsToPrompt(prompt: string, settings: InjectionSettings): string;
|
|
184
|
+
/**
|
|
185
|
+
* Serialize settings to JSON for persistence (localStorage, file, etc.)
|
|
186
|
+
*/
|
|
187
|
+
declare function serializeSettings(settings: InjectionSettings): string;
|
|
188
|
+
/**
|
|
189
|
+
* Deserialize settings from JSON, merging with defaults for missing fields.
|
|
190
|
+
*/
|
|
191
|
+
declare function deserializeSettings(json: string): InjectionSettings;
|
|
192
|
+
|
|
193
|
+
export { type GenerateMobileUIParams, type GenerationResult, type InjectionSettings, type PromptHistoryEntry, type PromptSession, type RefineUIParams, type RefinementResult, type ValidationResult, applySettingsToPrompt, createDefaultSettings, createPromptSession, deserializeSettings, enrichAppDescription, generateMobileUI, refineUI, serializeCompactDLC, serializeDLCForAI, serializeSettings, validateGeneratedUI };
|