dynim-react 1.0.65 → 1.0.67
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/DynimProvider.d.ts +3 -3
- package/dist/DynimProvider.d.ts.map +1 -1
- package/dist/DynimProvider.js +46 -16
- package/package.json +2 -2
package/dist/DynimProvider.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Shared context for bundles to access React, packages, etc.
|
|
8
8
|
*/
|
|
9
9
|
import { type ReactNode } from 'react';
|
|
10
|
-
import type { CodeMessage, Checkpoint, RestoreResult
|
|
10
|
+
import type { CodeMessage, Checkpoint, RestoreResult } from 'dynim-core';
|
|
11
11
|
export interface DynimConfig {
|
|
12
12
|
/** Function to fetch a session token for authentication */
|
|
13
13
|
getSession?: () => Promise<{
|
|
@@ -30,8 +30,8 @@ export interface DynimContextValue {
|
|
|
30
30
|
exitBuilder: () => void;
|
|
31
31
|
/** Whether builder/edit mode is active */
|
|
32
32
|
isEditing: boolean;
|
|
33
|
-
/** Send a code edit request to AI
|
|
34
|
-
sendCode: (query: string
|
|
33
|
+
/** Send a code edit request to AI */
|
|
34
|
+
sendCode: (query: string) => Promise<void>;
|
|
35
35
|
/** Save current edits */
|
|
36
36
|
saveCode: () => Promise<void>;
|
|
37
37
|
/** Abandon/discard current edits */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynimProvider.d.ts","sourceRoot":"","sources":["../src/DynimProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAc,EAQZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAWf,OAAO,KAAK,EAKV,WAAW,EACX,UAAU,EACV,aAAa,
|
|
1
|
+
{"version":3,"file":"DynimProvider.d.ts","sourceRoot":"","sources":["../src/DynimProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAc,EAQZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;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,WAAW,EAAE,WAAW,CAAC;IACzB,2CAA2C;IAC3C,cAAc,EAAE,OAAO,CAAC;IACxB,gCAAgC;IAChC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAID,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,MAAW,GACZ,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CA+dlC;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
|
package/dist/DynimProvider.js
CHANGED
|
@@ -12,6 +12,19 @@ import ReactDOM from 'react-dom';
|
|
|
12
12
|
import { createBuilderClient, createBuilder, createCodeClient, createBundleLoader, createCSSLoader, BundleNotFoundError, BundleAuthError, } from 'dynim-core';
|
|
13
13
|
import { createSharedContext, updateSharedContext, isSharedContextReady } from './inference/sharedContext';
|
|
14
14
|
import { generateThemeCSS } from './theme';
|
|
15
|
+
/** Decode JWT payload to extract claims (no verification - just for reading IDs) */
|
|
16
|
+
function decodeJwtPayload(token) {
|
|
17
|
+
try {
|
|
18
|
+
const parts = token.split('.');
|
|
19
|
+
if (parts.length !== 3)
|
|
20
|
+
return null;
|
|
21
|
+
const payload = JSON.parse(atob(parts[1]));
|
|
22
|
+
return payload;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
15
28
|
const DynimContext = createContext(null);
|
|
16
29
|
/**
|
|
17
30
|
* DynimProvider - Wrap your app with this to enable Dynim functionality
|
|
@@ -199,6 +212,17 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
199
212
|
}
|
|
200
213
|
return cssLoaderRef.current;
|
|
201
214
|
}, []);
|
|
215
|
+
// Build CSS URL with project/customer IDs from cached token
|
|
216
|
+
const buildCSSUrl = useCallback((temp = false) => {
|
|
217
|
+
const token = cachedTokenRef.current;
|
|
218
|
+
if (!token)
|
|
219
|
+
return null;
|
|
220
|
+
const claims = decodeJwtPayload(token);
|
|
221
|
+
if (!claims?.sub || !claims?.project)
|
|
222
|
+
return null;
|
|
223
|
+
const params = `project_id=${claims.project}&customer_id=${claims.sub}`;
|
|
224
|
+
return temp ? `/api/code/css?${params}&temp=true` : `/api/code/css?${params}`;
|
|
225
|
+
}, []);
|
|
202
226
|
// Load bundle (JS + CSS)
|
|
203
227
|
const loadBundle = useCallback(async (bundleUrl, loadCSS = true) => {
|
|
204
228
|
const loader = getBundleLoader();
|
|
@@ -213,16 +237,18 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
213
237
|
cleanup();
|
|
214
238
|
// Load CSS alongside JS bundle
|
|
215
239
|
if (loadCSS) {
|
|
216
|
-
const cssLoader = getCSSLoader();
|
|
217
240
|
const isTemp = bundleUrl.includes('temp=true');
|
|
218
|
-
const cssUrl = isTemp
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
241
|
+
const cssUrl = buildCSSUrl(isTemp);
|
|
242
|
+
if (cssUrl) {
|
|
243
|
+
const cssLoader = getCSSLoader();
|
|
244
|
+
if (isTemp) {
|
|
245
|
+
// Temp/preview CSS - bust cache to get latest
|
|
246
|
+
cssLoader.loadWithCacheBust(cssUrl);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// Saved CSS - let browser cache
|
|
250
|
+
cssLoader.load(cssUrl);
|
|
251
|
+
}
|
|
226
252
|
}
|
|
227
253
|
}
|
|
228
254
|
}
|
|
@@ -240,7 +266,7 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
240
266
|
finally {
|
|
241
267
|
setIsBundleLoading(false);
|
|
242
268
|
}
|
|
243
|
-
}, [getBundleLoader, getCSSLoader]);
|
|
269
|
+
}, [getBundleLoader, getCSSLoader, buildCSSUrl]);
|
|
244
270
|
// Keep ref updated
|
|
245
271
|
useEffect(() => {
|
|
246
272
|
loadBundleRef.current = loadBundle;
|
|
@@ -345,21 +371,25 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
345
371
|
builderRef.current.exit();
|
|
346
372
|
}
|
|
347
373
|
}, []);
|
|
348
|
-
const sendCode = useCallback(async (query
|
|
349
|
-
await codeClientRef.current?.sendCode(query
|
|
374
|
+
const sendCode = useCallback(async (query) => {
|
|
375
|
+
await codeClientRef.current?.sendCode(query);
|
|
350
376
|
}, []);
|
|
351
377
|
const saveCode = useCallback(async () => {
|
|
352
378
|
await codeClientRef.current?.saveCode();
|
|
353
379
|
await loadSavedBundle();
|
|
354
380
|
// Force reload CSS with cache bust since saved CSS has changed
|
|
355
|
-
|
|
356
|
-
|
|
381
|
+
const cssUrl = buildCSSUrl(false);
|
|
382
|
+
if (cssUrl)
|
|
383
|
+
getCSSLoader().loadWithCacheBust(cssUrl);
|
|
384
|
+
}, [loadSavedBundle, getCSSLoader, buildCSSUrl]);
|
|
357
385
|
const abandonCode = useCallback(async () => {
|
|
358
386
|
await codeClientRef.current?.abandonCode();
|
|
359
387
|
await loadSavedBundle();
|
|
360
388
|
// Reload saved CSS (may have been showing temp CSS)
|
|
361
|
-
|
|
362
|
-
|
|
389
|
+
const cssUrl = buildCSSUrl(false);
|
|
390
|
+
if (cssUrl)
|
|
391
|
+
getCSSLoader().loadWithCacheBust(cssUrl);
|
|
392
|
+
}, [loadSavedBundle, getCSSLoader, buildCSSUrl]);
|
|
363
393
|
const getCheckpoints = useCallback(async () => {
|
|
364
394
|
return codeClientRef.current?.getCheckpoints() ?? [];
|
|
365
395
|
}, []);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dynim-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.67",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dev": "tsc --watch"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"dynim-core": "^1.0.
|
|
30
|
+
"dynim-core": "^1.0.41"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">=17.0.0",
|