sonance-brand-mcp 1.3.110 → 1.3.111

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.
@@ -26,6 +26,11 @@ interface VariantStyles {
26
26
  boxShadow: string;
27
27
  }
28
28
 
29
+ interface ChatHistoryMessage {
30
+ role: string;
31
+ content: string;
32
+ }
33
+
29
34
  interface AIEditRequest {
30
35
  action: "edit" | "save";
31
36
  componentType: string;
@@ -37,6 +42,8 @@ interface AIEditRequest {
37
42
  editScope?: "component" | "variant";
38
43
  variantId?: string;
39
44
  variantStyles?: VariantStyles;
45
+ /** Conversation history for multi-turn context */
46
+ chatHistory?: ChatHistoryMessage[];
40
47
  }
41
48
 
42
49
  interface AIEditResponse {
@@ -240,7 +247,7 @@ export async function POST(request: Request) {
240
247
 
241
248
  try {
242
249
  const body: AIEditRequest = await request.json();
243
- const { action, componentType, filePath, currentCode, modifiedCode, userRequest, editScope, variantId, variantStyles } = body;
250
+ const { action, componentType, filePath, currentCode, modifiedCode, userRequest, editScope, variantId, variantStyles, chatHistory } = body;
244
251
 
245
252
  const projectRoot = process.cwd();
246
253
 
@@ -351,15 +358,31 @@ Return the complete modified file as JSON with these keys:
351
358
  - "explanation": Brief description of changes made
352
359
  - "previewCSS": CSS rules that will visually show the changes. Use selector [data-sonance-variant="${variantId || "selected"}"] to target the specific element(s). Example: "[data-sonance-variant='abc123'] { border-radius: 0.5rem; background-color: white; }"`;
353
360
 
361
+ // Build messages array with chat history for multi-turn context
362
+ const messages: Anthropic.MessageCreateParams["messages"] = [];
363
+
364
+ // Add conversation history if available (e.g., "make it darker", "undo that")
365
+ if (chatHistory && chatHistory.length > 0) {
366
+ for (const msg of chatHistory) {
367
+ if (msg.role === "user" || msg.role === "assistant") {
368
+ messages.push({
369
+ role: msg.role as "user" | "assistant",
370
+ content: msg.content,
371
+ });
372
+ }
373
+ }
374
+ }
375
+
376
+ // Add current user request
377
+ messages.push({
378
+ role: "user",
379
+ content: userMessage,
380
+ });
381
+
354
382
  const response = await anthropic.messages.create({
355
383
  model: "claude-sonnet-4-20250514",
356
384
  max_tokens: 8192,
357
- messages: [
358
- {
359
- role: "user",
360
- content: userMessage,
361
- },
362
- ],
385
+ messages,
363
386
  system: SYSTEM_PROMPT,
364
387
  });
365
388
 
@@ -64,6 +64,11 @@ interface VisionFileModification {
64
64
  explanation: string;
65
65
  }
66
66
 
67
+ interface ChatHistoryMessage {
68
+ role: string;
69
+ content: string;
70
+ }
71
+
67
72
  interface ApplyFirstRequest {
68
73
  action: "apply" | "accept" | "revert" | "preview";
69
74
  sessionId?: string;
@@ -73,6 +78,8 @@ interface ApplyFirstRequest {
73
78
  focusedElements?: VisionFocusedElement[];
74
79
  // For applying a previously previewed set of modifications
75
80
  previewedModifications?: VisionFileModification[];
81
+ /** Conversation history for multi-turn context */
82
+ chatHistory?: ChatHistoryMessage[];
76
83
  }
77
84
 
78
85
  interface BackupManifest {
@@ -1929,7 +1936,7 @@ export async function POST(request: Request) {
1929
1936
 
1930
1937
  try {
1931
1938
  const body: ApplyFirstRequest = await request.json();
1932
- const { action, sessionId, screenshot, pageRoute, userPrompt, focusedElements, previewedModifications } = body;
1939
+ const { action, sessionId, screenshot, pageRoute, userPrompt, focusedElements, previewedModifications, chatHistory } = body;
1933
1940
  const projectRoot = process.cwd();
1934
1941
 
1935
1942
  // ========== ACCEPT ACTION ==========
@@ -2840,13 +2847,31 @@ CRITICAL: Your "search" string MUST exist in the file. If you can't find the exa
2840
2847
  let finalExplanation: string | undefined;
2841
2848
 
2842
2849
  while (retryCount <= MAX_RETRIES) {
2843
- // Build messages for this attempt
2844
- const currentMessages: Anthropic.MessageCreateParams["messages"] = [
2845
- {
2846
- role: "user",
2847
- content: messageContent,
2848
- },
2849
- ];
2850
+ // Build messages for this attempt, starting with chat history if available
2851
+ const currentMessages: Anthropic.MessageCreateParams["messages"] = [];
2852
+
2853
+ // Add conversation history for multi-turn context (e.g., "make it darker", "undo that")
2854
+ if (chatHistory && chatHistory.length > 0) {
2855
+ for (const msg of chatHistory) {
2856
+ // Only include user and assistant messages, skip system messages
2857
+ if (msg.role === "user" || msg.role === "assistant") {
2858
+ currentMessages.push({
2859
+ role: msg.role as "user" | "assistant",
2860
+ content: msg.content,
2861
+ });
2862
+ }
2863
+ }
2864
+ debugLog("Added chat history to context", {
2865
+ messageCount: chatHistory.length,
2866
+ preview: chatHistory.slice(-2).map(m => ({ role: m.role, content: m.content.substring(0, 50) }))
2867
+ });
2868
+ }
2869
+
2870
+ // Add current user message with screenshot
2871
+ currentMessages.push({
2872
+ role: "user",
2873
+ content: messageContent,
2874
+ });
2850
2875
 
2851
2876
  // If this is a retry, add feedback about what went wrong
2852
2877
  if (retryCount > 0 && lastPatchErrors.length > 0) {
@@ -64,6 +64,11 @@ interface VisionFileModification {
64
64
  previewCSS?: string;
65
65
  }
66
66
 
67
+ interface ChatHistoryMessage {
68
+ role: string;
69
+ content: string;
70
+ }
71
+
67
72
  interface VisionEditRequest {
68
73
  action: "edit" | "save";
69
74
  screenshot?: string;
@@ -71,6 +76,8 @@ interface VisionEditRequest {
71
76
  userPrompt: string;
72
77
  focusedElements?: VisionFocusedElement[];
73
78
  modifications?: VisionFileModification[];
79
+ /** Conversation history for multi-turn context */
80
+ chatHistory?: ChatHistoryMessage[];
74
81
  }
75
82
 
76
83
  interface VisionEditResponse {
@@ -1925,7 +1932,7 @@ export async function POST(request: Request) {
1925
1932
 
1926
1933
  try {
1927
1934
  const body: VisionEditRequest = await request.json();
1928
- const { action, screenshot, pageRoute, userPrompt, focusedElements, modifications } = body;
1935
+ const { action, screenshot, pageRoute, userPrompt, focusedElements, modifications, chatHistory } = body;
1929
1936
 
1930
1937
  const projectRoot = process.cwd();
1931
1938
 
@@ -2800,13 +2807,31 @@ CRITICAL: Your "search" string MUST exist in the file. If you can't find the exa
2800
2807
  let finalExplanation: string | undefined;
2801
2808
 
2802
2809
  while (retryCount <= MAX_RETRIES) {
2803
- // Build messages for this attempt
2804
- const currentMessages: Anthropic.MessageCreateParams["messages"] = [
2805
- {
2806
- role: "user",
2807
- content: messageContent,
2808
- },
2809
- ];
2810
+ // Build messages for this attempt, starting with chat history if available
2811
+ const currentMessages: Anthropic.MessageCreateParams["messages"] = [];
2812
+
2813
+ // Add conversation history for multi-turn context (e.g., "make it darker", "undo that")
2814
+ if (chatHistory && chatHistory.length > 0) {
2815
+ for (const msg of chatHistory) {
2816
+ // Only include user and assistant messages, skip system messages
2817
+ if (msg.role === "user" || msg.role === "assistant") {
2818
+ currentMessages.push({
2819
+ role: msg.role as "user" | "assistant",
2820
+ content: msg.content,
2821
+ });
2822
+ }
2823
+ }
2824
+ debugLog("Added chat history to context", {
2825
+ messageCount: chatHistory.length,
2826
+ preview: chatHistory.slice(-2).map(m => ({ role: m.role, content: m.content.substring(0, 50) }))
2827
+ });
2828
+ }
2829
+
2830
+ // Add current user message with screenshot
2831
+ currentMessages.push({
2832
+ role: "user",
2833
+ content: messageContent,
2834
+ });
2810
2835
 
2811
2836
  // If this is a retry, add feedback about what went wrong
2812
2837
  if (retryCount > 0 && lastPatchErrors.length > 0) {