dynim-core 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type WidgetConfig } from './widget';
|
|
6
6
|
import { type DiffEntry } from './diff-state';
|
|
7
|
+
import { type CodeClient } from './code-client';
|
|
7
8
|
export interface BuilderConfig {
|
|
8
9
|
logo?: string;
|
|
9
10
|
onSave?: (diffs: DiffEntry[]) => void;
|
|
@@ -22,6 +23,8 @@ export interface BuilderConfig {
|
|
|
22
23
|
token: string;
|
|
23
24
|
refreshToken?: string;
|
|
24
25
|
}>;
|
|
26
|
+
/** External CodeClient to use (shares state with parent) - if not provided, creates its own */
|
|
27
|
+
codeClient?: CodeClient;
|
|
25
28
|
}
|
|
26
29
|
export interface Builder {
|
|
27
30
|
enter: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/builder/builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA6B,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxE,OAAO,EAAmC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/builder/builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA6B,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxE,OAAO,EAAmC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAO/E,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAIlE,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,+FAA+F;IAC/F,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,UAAU,EAAE,MAAM,SAAS,EAAE,CAAC;IAC9B,cAAc,EAAE,MAAM,OAAO,CAAC;IAC9B,YAAY,EAAE,MAAM,OAAO,CAAC;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wBAAgB,aAAa,CAAC,MAAM,GAAE,aAAkB,GAAG,OAAO,CAwlBjE;;;;AAMD,wBAAyC"}
|
package/dist/builder/builder.js
CHANGED
|
@@ -17,7 +17,7 @@ import { createCodeClient } from './code-client';
|
|
|
17
17
|
import { createBuilderClient } from './builder-client';
|
|
18
18
|
import { buildElementIdentifier, getRelevantStyles } from './element-utils';
|
|
19
19
|
export function createBuilder(config = {}) {
|
|
20
|
-
const { logo = 'Builder', onSave, onExit, onEnter, chatConfig = {}, contentRoot = document.body, pageId = window.location.pathname, apiBase = 'http://localhost:8080', sessionToken, refreshToken, getSession } = config;
|
|
20
|
+
const { logo = 'Builder', onSave, onExit, onEnter, chatConfig = {}, contentRoot = document.body, pageId = window.location.pathname, apiBase = 'http://localhost:8080', sessionToken, refreshToken, getSession, codeClient: externalCodeClient } = config;
|
|
21
21
|
let isActive = false;
|
|
22
22
|
let chatWidget = null;
|
|
23
23
|
let state = null;
|
|
@@ -85,54 +85,68 @@ export function createBuilder(config = {}) {
|
|
|
85
85
|
const undoBtn = root.querySelector('.builder-bar__btn--undo');
|
|
86
86
|
const modal = root.querySelector('.builder-modal');
|
|
87
87
|
let builderClient = null;
|
|
88
|
+
// Track unsubscribe function for external client
|
|
89
|
+
let unsubscribeFromClient = null;
|
|
88
90
|
function initCodeClient(stateRef) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
// Handler for message updates (used by both internal and external client)
|
|
92
|
+
const handleMessageUpdate = (message) => {
|
|
93
|
+
console.log('[Builder] Message update:', message.status);
|
|
94
|
+
// Update the chat UI with the latest text
|
|
95
|
+
const messages = stateRef.getState().messages;
|
|
96
|
+
const lastMessage = messages[messages.length - 1];
|
|
97
|
+
if (lastMessage?.role === 'assistant') {
|
|
98
|
+
stateRef.updateMessage(lastMessage.id, {
|
|
99
|
+
text: message.text || ''
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (message.status === 'done') {
|
|
103
|
+
console.log('[Builder] Chat complete');
|
|
104
|
+
}
|
|
105
|
+
else if (message.status === 'error') {
|
|
106
|
+
console.log('[Builder] Chat error:', message.error);
|
|
99
107
|
if (lastMessage?.role === 'assistant') {
|
|
100
108
|
stateRef.updateMessage(lastMessage.id, {
|
|
101
|
-
text: message.
|
|
109
|
+
text: message.error || 'Something went wrong. Please try again.'
|
|
102
110
|
});
|
|
103
111
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
// Use external client if provided, otherwise create our own
|
|
115
|
+
if (externalCodeClient) {
|
|
116
|
+
console.log('[Builder] Using external CodeClient');
|
|
117
|
+
client = externalCodeClient;
|
|
118
|
+
// Subscribe to message updates
|
|
119
|
+
unsubscribeFromClient = client.onMessage(handleMessageUpdate);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
console.log('[Builder] Creating internal CodeClient');
|
|
123
|
+
client = createCodeClient({
|
|
124
|
+
apiBase,
|
|
125
|
+
sessionToken,
|
|
126
|
+
refreshToken,
|
|
127
|
+
getSession,
|
|
128
|
+
onMessageUpdate: handleMessageUpdate,
|
|
129
|
+
onStreamStart: () => {
|
|
130
|
+
console.log('[Builder] Stream started');
|
|
131
|
+
},
|
|
132
|
+
onStreamEnd: () => {
|
|
133
|
+
console.log('[Builder] Stream ended');
|
|
134
|
+
},
|
|
135
|
+
onError: (error) => {
|
|
136
|
+
console.error('[Builder] Backend error:', error);
|
|
137
|
+
const messages = stateRef.getState().messages;
|
|
138
|
+
const lastMessage = messages[messages.length - 1];
|
|
109
139
|
if (lastMessage?.role === 'assistant') {
|
|
110
140
|
stateRef.updateMessage(lastMessage.id, {
|
|
111
|
-
text: message
|
|
141
|
+
text: error.message || 'Sorry, something went wrong. Please try again.'
|
|
112
142
|
});
|
|
113
143
|
}
|
|
144
|
+
},
|
|
145
|
+
onAuthError: (error) => {
|
|
146
|
+
console.error('[Builder] Auth error:', error);
|
|
114
147
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
console.log('[Builder] Stream started');
|
|
118
|
-
},
|
|
119
|
-
onStreamEnd: () => {
|
|
120
|
-
console.log('[Builder] Stream ended');
|
|
121
|
-
},
|
|
122
|
-
onError: (error) => {
|
|
123
|
-
console.error('[Builder] Backend error:', error);
|
|
124
|
-
const messages = stateRef.getState().messages;
|
|
125
|
-
const lastMessage = messages[messages.length - 1];
|
|
126
|
-
if (lastMessage?.role === 'assistant') {
|
|
127
|
-
stateRef.updateMessage(lastMessage.id, {
|
|
128
|
-
text: error.message || 'Sorry, something went wrong. Please try again.'
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
onAuthError: (error) => {
|
|
133
|
-
console.error('[Builder] Auth error:', error);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
136
150
|
}
|
|
137
151
|
function initBuilderClient() {
|
|
138
152
|
builderClient = createBuilderClient({
|
|
@@ -528,6 +542,9 @@ export function createBuilder(config = {}) {
|
|
|
528
542
|
exit();
|
|
529
543
|
chatWidget?.destroy();
|
|
530
544
|
root.remove();
|
|
545
|
+
// Cleanup external client subscription
|
|
546
|
+
unsubscribeFromClient?.();
|
|
547
|
+
unsubscribeFromClient = null;
|
|
531
548
|
}
|
|
532
549
|
};
|
|
533
550
|
}
|
|
@@ -96,6 +96,8 @@ export interface CodeClient {
|
|
|
96
96
|
getMessage: () => CodeMessage;
|
|
97
97
|
/** Reset message state */
|
|
98
98
|
resetMessage: () => void;
|
|
99
|
+
/** Subscribe to message updates (returns unsubscribe function) */
|
|
100
|
+
onMessage: (callback: (message: CodeMessage) => void) => () => void;
|
|
99
101
|
}
|
|
100
102
|
export declare function createCodeClient(config?: CodeClientConfig): CodeClient;
|
|
101
103
|
//# sourceMappingURL=code-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-client.d.ts","sourceRoot":"","sources":["../../src/builder/code-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC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AAO,CAAC,IAAI,CAAC,CAAC;IAC9B,8EAA8E;IAC9E,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACpC,kFAAkF;IAClF,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,mCAAmC;IACnC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChE,6BAA6B;IAC7B,eAAe,EAAE,MAAM,OAAO,CAAC;IAC/B,gCAAgC;IAChC,UAAU,EAAE,MAAM,WAAW,CAAC;IAC9B,0BAA0B;IAC1B,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,kEAAkE;IAClE,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;CACrE;AAcD,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,gBAAqB,GAAG,UAAU,CA+d1E"}
|
|
@@ -34,10 +34,17 @@ export function createCodeClient(config = {}) {
|
|
|
34
34
|
let currentMessage = createEmptyMessage();
|
|
35
35
|
// Track if we need to add a line break before next text (after tool use)
|
|
36
36
|
let needsTextBreak = false;
|
|
37
|
+
// Additional message listeners (for sharing client between components)
|
|
38
|
+
const messageListeners = new Set();
|
|
39
|
+
/** Notify all listeners of message update */
|
|
40
|
+
function notifyListeners() {
|
|
41
|
+
notifyListeners();
|
|
42
|
+
messageListeners.forEach(listener => listener(currentMessage));
|
|
43
|
+
}
|
|
37
44
|
/** Update message state and notify listeners */
|
|
38
45
|
function updateMessage(updates) {
|
|
39
46
|
currentMessage = { ...currentMessage, ...updates };
|
|
40
|
-
|
|
47
|
+
notifyListeners();
|
|
41
48
|
}
|
|
42
49
|
/** Append to thinking content */
|
|
43
50
|
function appendThinking(content) {
|
|
@@ -50,7 +57,7 @@ export function createCodeClient(config = {}) {
|
|
|
50
57
|
...currentMessage,
|
|
51
58
|
thinking: currentMessage.thinking + content
|
|
52
59
|
};
|
|
53
|
-
|
|
60
|
+
notifyListeners();
|
|
54
61
|
}
|
|
55
62
|
/** Append to text content */
|
|
56
63
|
function appendText(content) {
|
|
@@ -64,7 +71,7 @@ export function createCodeClient(config = {}) {
|
|
|
64
71
|
...currentMessage,
|
|
65
72
|
text: currentMessage.text + prefix + content
|
|
66
73
|
};
|
|
67
|
-
|
|
74
|
+
notifyListeners();
|
|
68
75
|
}
|
|
69
76
|
/** Mark that next text should have a line break (called after tool use) */
|
|
70
77
|
function markTextBreak() {
|
|
@@ -76,7 +83,7 @@ export function createCodeClient(config = {}) {
|
|
|
76
83
|
...currentMessage,
|
|
77
84
|
edits: [...currentMessage.edits, edit]
|
|
78
85
|
};
|
|
79
|
-
|
|
86
|
+
notifyListeners();
|
|
80
87
|
}
|
|
81
88
|
/**
|
|
82
89
|
* Get a valid session token, refreshing if necessary
|
|
@@ -303,7 +310,7 @@ export function createCodeClient(config = {}) {
|
|
|
303
310
|
}
|
|
304
311
|
// Reset message state after save
|
|
305
312
|
currentMessage = createEmptyMessage();
|
|
306
|
-
|
|
313
|
+
notifyListeners();
|
|
307
314
|
console.log('[CodeClient] Code saved successfully');
|
|
308
315
|
}
|
|
309
316
|
catch (error) {
|
|
@@ -332,7 +339,7 @@ export function createCodeClient(config = {}) {
|
|
|
332
339
|
}
|
|
333
340
|
// Reset message state after abandon
|
|
334
341
|
currentMessage = createEmptyMessage();
|
|
335
|
-
|
|
342
|
+
notifyListeners();
|
|
336
343
|
console.log('[CodeClient] Code abandoned successfully');
|
|
337
344
|
}
|
|
338
345
|
catch (error) {
|
|
@@ -412,7 +419,14 @@ export function createCodeClient(config = {}) {
|
|
|
412
419
|
resetMessage: () => {
|
|
413
420
|
currentMessage = createEmptyMessage();
|
|
414
421
|
needsTextBreak = false;
|
|
415
|
-
|
|
422
|
+
notifyListeners();
|
|
423
|
+
},
|
|
424
|
+
onMessage: (callback) => {
|
|
425
|
+
messageListeners.add(callback);
|
|
426
|
+
// Return unsubscribe function
|
|
427
|
+
return () => {
|
|
428
|
+
messageListeners.delete(callback);
|
|
429
|
+
};
|
|
416
430
|
}
|
|
417
431
|
};
|
|
418
432
|
}
|