@datalayer/core 1.0.20 → 1.0.22

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.
Files changed (138) hide show
  1. package/README.md +27 -0
  2. package/lib/api/DatalayerApi.d.ts +5 -1
  3. package/lib/api/DatalayerApi.js +55 -8
  4. package/lib/api/iam/oauth2.d.ts +3 -3
  5. package/lib/api/iam/oauth2.js +2 -2
  6. package/lib/api/iam/profile.d.ts +9 -1
  7. package/lib/api/iam/profile.js +15 -0
  8. package/lib/api/runtimes/checkpoints.js +1 -1
  9. package/lib/api/runtimes/snapshots.d.ts +7 -7
  10. package/lib/api/runtimes/snapshots.js +9 -9
  11. package/lib/client/auth/storage.js +103 -12
  12. package/lib/client/index.d.ts +7 -7
  13. package/lib/client/index.js +1 -1
  14. package/lib/client/mixins/RuntimesMixin.d.ts +6 -6
  15. package/lib/client/mixins/RuntimesMixin.js +5 -5
  16. package/lib/client/mixins/SpacerMixin.js +22 -1
  17. package/lib/collaboration/DatalayerCollaborationProvider.d.ts +4 -3
  18. package/lib/components/avatars/DLAvatar.d.ts +24 -0
  19. package/lib/components/avatars/DLAvatar.js +26 -0
  20. package/lib/components/avatars/UserProfileAvatar.js +4 -4
  21. package/lib/components/avatars/index.d.ts +1 -0
  22. package/lib/components/avatars/index.js +1 -0
  23. package/lib/components/billing/BillableAccountSelect.d.ts +35 -0
  24. package/lib/components/billing/BillableAccountSelect.js +340 -0
  25. package/lib/components/billing/index.d.ts +1 -0
  26. package/lib/components/billing/index.js +5 -0
  27. package/lib/components/checkout/StripeCheckout.d.ts +24 -3
  28. package/lib/components/checkout/StripeCheckout.js +1116 -55
  29. package/lib/components/display/DatalayerBox.js +6 -1
  30. package/lib/components/index.d.ts +2 -0
  31. package/lib/components/index.js +2 -0
  32. package/lib/components/principal/Principal.d.ts +37 -0
  33. package/lib/components/principal/Principal.js +54 -0
  34. package/lib/components/principal/PrincipalAvatar.d.ts +10 -0
  35. package/lib/components/principal/PrincipalAvatar.js +55 -0
  36. package/lib/components/principal/PrincipalBadge.d.ts +20 -0
  37. package/lib/components/principal/PrincipalBadge.js +208 -0
  38. package/lib/components/principal/PrincipalBanner.d.ts +7 -0
  39. package/lib/components/principal/PrincipalBanner.js +84 -0
  40. package/lib/components/principal/PrincipalDetailsOverlay.d.ts +23 -0
  41. package/lib/components/principal/PrincipalDetailsOverlay.js +86 -0
  42. package/lib/components/principal/PrincipalSwitcherMenu.d.ts +14 -0
  43. package/lib/components/principal/PrincipalSwitcherMenu.js +287 -0
  44. package/lib/components/principal/index.d.ts +7 -0
  45. package/lib/components/principal/index.js +10 -0
  46. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +2 -2
  47. package/lib/components/sharing/ShareAccessComponent.d.ts +18 -0
  48. package/lib/components/sharing/ShareAccessComponent.js +1368 -0
  49. package/lib/components/sharing/SharingEditor.d.ts +20 -0
  50. package/lib/components/sharing/SharingEditor.js +65 -0
  51. package/lib/components/sharing/index.d.ts +9 -0
  52. package/lib/components/sharing/index.js +12 -0
  53. package/lib/components/snapshots/{RuntimeSnapshotMenu.d.ts → SandboxSnapshotMenu.d.ts} +4 -4
  54. package/lib/components/snapshots/{RuntimeSnapshotMenu.js → SandboxSnapshotMenu.js} +33 -33
  55. package/lib/components/snapshots/index.d.ts +1 -1
  56. package/lib/components/snapshots/index.js +1 -1
  57. package/lib/components/storage/ContentsBrowser.js +2 -2
  58. package/lib/components/tokens/SpaceVariantToken.d.ts +1 -1
  59. package/lib/components/tokens/SpaceVariantToken.js +7 -4
  60. package/lib/components/users/PeerIndicator.js +5 -4
  61. package/lib/hooks/index.d.ts +5 -0
  62. package/lib/hooks/index.js +5 -0
  63. package/lib/hooks/useBillableAccountStore.d.ts +31 -0
  64. package/lib/hooks/useBillableAccountStore.js +53 -0
  65. package/lib/hooks/useCache.d.ts +125 -18
  66. package/lib/hooks/useCache.js +893 -120
  67. package/lib/hooks/useDatalayer.js +31 -3
  68. package/lib/hooks/useIAM.js +1 -8
  69. package/lib/hooks/usePrincipalStore.d.ts +41 -0
  70. package/lib/hooks/usePrincipalStore.js +101 -0
  71. package/lib/hooks/useProjects.d.ts +44 -0
  72. package/lib/hooks/useProjects.js +26 -2
  73. package/lib/hooks/useSelectedBillableAccount.d.ts +14 -0
  74. package/lib/hooks/useSelectedBillableAccount.js +36 -0
  75. package/lib/hooks/useSelectedPrincipal.d.ts +17 -0
  76. package/lib/hooks/useSelectedPrincipal.js +29 -0
  77. package/lib/hooks/useUsageRefreshStore.d.ts +8 -0
  78. package/lib/hooks/useUsageRefreshStore.js +16 -0
  79. package/lib/index.d.ts +2 -2
  80. package/lib/index.js +1 -1
  81. package/lib/mocks/components/FlashMock.js +8 -2
  82. package/lib/models/{RuntimeSnapshot.d.ts → CodeSandboxSnapshot.d.ts} +5 -5
  83. package/lib/models/{RuntimeSnapshot.js → CodeSandboxSnapshot.js} +1 -1
  84. package/lib/models/{RuntimeSnapshotDTO.d.ts → CodeSandboxSnapshotDTO.d.ts} +30 -30
  85. package/lib/models/{RuntimeSnapshotDTO.js → CodeSandboxSnapshotDTO.js} +6 -6
  86. package/lib/models/Environment.d.ts +4 -0
  87. package/lib/models/IAM.d.ts +66 -0
  88. package/lib/models/Organization.d.ts +1 -0
  89. package/lib/models/Organization.js +1 -0
  90. package/lib/models/Page.d.ts +2 -2
  91. package/lib/models/Page.js +2 -2
  92. package/lib/models/Profile.d.ts +1 -1
  93. package/lib/models/RuntimeDTO.d.ts +2 -2
  94. package/lib/models/Space.d.ts +1 -0
  95. package/lib/models/Space.js +29 -5
  96. package/lib/models/SpaceDTO.d.ts +4 -0
  97. package/lib/models/SpaceDTO.js +5 -0
  98. package/lib/models/Usage.d.ts +15 -0
  99. package/lib/models/Usage.js +9 -0
  100. package/lib/models/User.d.ts +21 -0
  101. package/lib/models/User.js +6 -2
  102. package/lib/models/index.d.ts +2 -2
  103. package/lib/models/index.js +2 -2
  104. package/lib/otel/auth.js +0 -4
  105. package/lib/services/index.d.ts +1 -1
  106. package/lib/services/index.js +1 -1
  107. package/lib/state/substates/IAMState.js +0 -7
  108. package/lib/state/substates/RuntimesState.d.ts +9 -9
  109. package/lib/state/substates/RuntimesState.js +3 -3
  110. package/lib/stateful/runtimes/actions.d.ts +17 -17
  111. package/lib/stateful/runtimes/actions.js +35 -55
  112. package/lib/stateful/runtimes/apis.d.ts +3 -3
  113. package/lib/stateful/runtimes/snapshots.d.ts +2 -2
  114. package/lib/stateful/runtimes/snapshots.js +7 -7
  115. package/lib/utils/Format.d.ts +6 -0
  116. package/lib/utils/Format.js +17 -0
  117. package/lib/utils/Handles.d.ts +3 -0
  118. package/lib/utils/Handles.js +53 -0
  119. package/lib/utils/Snapshot.d.ts +1 -1
  120. package/lib/utils/Snapshot.js +1 -1
  121. package/lib/utils/index.d.ts +1 -0
  122. package/lib/utils/index.js +1 -0
  123. package/lib/views/datasources/DatasourceDetail.d.ts +7 -1
  124. package/lib/views/datasources/DatasourceDetail.js +61 -23
  125. package/lib/views/datasources/DatasourceNew.d.ts +8 -1
  126. package/lib/views/datasources/DatasourceNew.js +23 -10
  127. package/lib/views/datasources/Datasources.d.ts +5 -1
  128. package/lib/views/datasources/Datasources.js +38 -30
  129. package/lib/views/iam-tokens/IAMTokenNew.d.ts +3 -1
  130. package/lib/views/iam-tokens/IAMTokenNew.js +2 -2
  131. package/lib/views/iam-tokens/IAMTokens.d.ts +3 -1
  132. package/lib/views/iam-tokens/IAMTokens.js +2 -2
  133. package/lib/views/otel/OtelHeader.d.ts +5 -0
  134. package/lib/views/otel/OtelHeader.js +3 -3
  135. package/lib/views/profile/UserBadge.d.ts +7 -2
  136. package/lib/views/profile/UserBadge.js +11 -2
  137. package/lib/views/secrets/Secrets.js +21 -21
  138. package/package.json +7 -8
@@ -179,13 +179,6 @@ export const iamStore = createStore((set, get) => {
179
179
  storeUser(user);
180
180
  storeToken(token);
181
181
  set(() => ({ user, token }));
182
- // TODO Centralize User Setting Management.
183
- const aiagentsRunUrl = user.settings?.aiAgentsUrl;
184
- if (aiagentsRunUrl) {
185
- coreStore.getState().setConfiguration({
186
- aiagentsRunUrl,
187
- });
188
- }
189
182
  }
190
183
  catch (error) {
191
184
  if (error.name === 'RunResponseError' &&
@@ -1,6 +1,6 @@
1
1
  import type { IMultiServiceManager } from '../../stateful/runtimes';
2
2
  import type { IRuntimesConfiguration } from '../../config';
3
- import type { IRuntimePod, IRuntimeSnapshot, IRuntimeModel } from '../../models';
3
+ import type { IRuntimePod, ICodeSandboxSnapshot, IRuntimeModel } from '../../models';
4
4
  /**
5
5
  * Datalayer Runtimes state.
6
6
  */
@@ -49,21 +49,21 @@ export type RuntimesState = {
49
49
  showDisclaimer: boolean;
50
50
  setShowDisclaimer: (showDisclaimer: boolean) => void;
51
51
  /**
52
- * Runtime snapshots.
52
+ * Code Sandbox snapshots.
53
53
  */
54
- runtimeSnapshots: readonly IRuntimeSnapshot[];
54
+ runtimeSnapshots: readonly ICodeSandboxSnapshot[];
55
55
  /**
56
- * Add a runtime snapshot.
56
+ * Add a code sandbox snapshot.
57
57
  */
58
- addRuntimeSnapshot: (snapshot: IRuntimeSnapshot) => void;
58
+ addSandboxSnapshot: (snapshot: ICodeSandboxSnapshot) => void;
59
59
  /**
60
- * Remove a Runtime Snapshot.
60
+ * Remove a Code Sandbox Snapshot.
61
61
  */
62
- removeRuntimeSnapshot: (id: string) => void;
62
+ removeSandboxSnapshot: (id: string) => void;
63
63
  /**
64
- * Set Runtime Snapshots.
64
+ * Set Code Sandbox Snapshots.
65
65
  */
66
- setRuntimeSnapshots: (snapshots: IRuntimeSnapshot[]) => void;
66
+ setSandboxSnapshots: (snapshots: ICodeSandboxSnapshot[]) => void;
67
67
  /**
68
68
  * Package version.
69
69
  */
@@ -90,7 +90,7 @@ export const runtimesStore = createStore((set, get) => {
90
90
  /**
91
91
  * Add a Kernel Snapshot
92
92
  */
93
- addRuntimeSnapshot: (snapshot) => {
93
+ addSandboxSnapshot: (snapshot) => {
94
94
  const snapshots = get().runtimeSnapshots;
95
95
  const index = snapshots.findIndex(s => s.id === snapshot.id);
96
96
  if (index < 0) {
@@ -106,7 +106,7 @@ export const runtimesStore = createStore((set, get) => {
106
106
  /**
107
107
  * Remove a Kernel Snapshot.
108
108
  */
109
- removeRuntimeSnapshot: (id) => {
109
+ removeSandboxSnapshot: (id) => {
110
110
  const snapshots = get().runtimeSnapshots;
111
111
  const index = snapshots.findIndex(s => s.id === id);
112
112
  if (index >= 0) {
@@ -118,7 +118,7 @@ export const runtimesStore = createStore((set, get) => {
118
118
  /**
119
119
  * Set Kernel Snapshots.
120
120
  */
121
- setRuntimeSnapshots: (snapshots) => {
121
+ setSandboxSnapshots: (snapshots) => {
122
122
  if (!JSONExt.deepEqual(get().runtimeSnapshots, snapshots)) {
123
123
  set({ runtimeSnapshots: [...snapshots] });
124
124
  }
@@ -1,5 +1,5 @@
1
1
  import { IRuntimeOptions } from '../../api';
2
- import type { IRuntimeSnapshot, IDatalayerEnvironment, IRuntimePod } from '../../models';
2
+ import type { ICodeSandboxSnapshot, IDatalayerEnvironment, IRuntimePod } from '../../models';
3
3
  /**
4
4
  * Get available Environments.
5
5
  */
@@ -45,15 +45,15 @@ export declare function snapshotRuntime(options: {
45
45
  * Whether to stop the runtime after the snapshot completion or not.
46
46
  */
47
47
  stop?: boolean;
48
- }): Promise<IRuntimeSnapshot>;
48
+ }): Promise<ICodeSandboxSnapshot | undefined>;
49
49
  /**
50
- * Get Runtime Snapshots.
50
+ * Get Code Sandbox Snapshots.
51
51
  */
52
- export declare function getRuntimeSnapshots(): Promise<IRuntimeSnapshot[]>;
52
+ export declare function getSandboxSnapshots(): Promise<ICodeSandboxSnapshot[]>;
53
53
  /**
54
- * Load a Runtime Snapshot within a Runtime.
54
+ * Load a Code Sandbox Snapshot within a Runtime.
55
55
  */
56
- export declare function loadRuntimeSnapshot(options: {
56
+ export declare function loadSandboxSnapshot(options: {
57
57
  /**
58
58
  * Runtime ID
59
59
  */
@@ -64,35 +64,35 @@ export declare function loadRuntimeSnapshot(options: {
64
64
  from: string;
65
65
  }): Promise<void>;
66
66
  /**
67
- * Returns the Runtime Snapshot download URL.
67
+ * Returns the Code Sandbox Snapshot download URL.
68
68
  *
69
69
  * @param id Snapshot UID to download
70
70
  * @returns The download URL
71
71
  */
72
- export declare function createRuntimeSnapshotDownloadURL(id: string): string;
72
+ export declare function createSandboxSnapshotDownloadURL(id: string): string;
73
73
  /**
74
- * Export a Runtime Snapshot.
74
+ * Export a Code Sandbox Snapshot.
75
75
  *
76
- * @param id Runtime snapshot UID to download
76
+ * @param id Code Sandbox snapshot UID to download
77
77
  */
78
- export declare function exportRuntimeSnapshot(id: string): void;
78
+ export declare function exportCodeSandboxSnapshot(id: string): void;
79
79
  /**
80
- * Delete a Runtime Snapshot.
80
+ * Delete a Code Sandbox Snapshot.
81
81
  */
82
- export declare function deleteRuntimeSnapshot(id: string): Promise<void>;
82
+ export declare function deleteCodeSandboxSnapshot(id: string): Promise<void>;
83
83
  /**
84
- * Update Runtime Snapshot metadata.
84
+ * Update Code Sandbox Snapshot metadata.
85
85
  */
86
- export declare function updateRuntimeSnapshot(id: string, metadata: {
86
+ export declare function updateCodeSandboxSnapshot(id: string, metadata: {
87
87
  name?: string;
88
88
  description?: string;
89
89
  }): Promise<void>;
90
90
  /**
91
- * Upload a Runtime Snapshot.
91
+ * Upload a Code Sandbox Snapshot.
92
92
  *
93
93
  * Note: The promise will be rejected if the runtime state is empty.
94
94
  */
95
- export declare function uploadRuntimeSnapshot(options: {
95
+ export declare function uploadCodeSandboxSnapshot(options: {
96
96
  file: File | Blob;
97
97
  metadata: {
98
98
  filename: string;
@@ -9,9 +9,8 @@ import { URLExt } from '@jupyterlab/coreutils';
9
9
  import { PromiseDelegate } from '@lumino/coreutils';
10
10
  import { Upload } from 'tus-js-client';
11
11
  import { requestDatalayerAPI, } from '../../api/index.js';
12
- import { asRuntimeSnapshot } from '../../models/index.js';
12
+ import { asCodeSandboxSnapshot } from '../../models/index.js';
13
13
  import { iamStore, runtimesStore } from '../../state/index.js';
14
- import { sleep } from '../../utils/index.js';
15
14
  /**
16
15
  * Get available Environments.
17
16
  */
@@ -100,7 +99,7 @@ export async function deleteRuntime(options) {
100
99
  */
101
100
  export async function snapshotRuntime(options) {
102
101
  const data = await requestDatalayerAPI({
103
- url: URLExt.join(runtimesStore.getState().runtimesRunUrl, 'api/runtimes/v1/runtime-snapshots'),
102
+ url: URLExt.join(runtimesStore.getState().runtimesRunUrl, 'api/runtimes/v1/sandbox-snapshots'),
104
103
  method: 'POST',
105
104
  body: {
106
105
  pod_name: options.id,
@@ -110,29 +109,34 @@ export async function snapshotRuntime(options) {
110
109
  },
111
110
  token: iamStore.getState().token,
112
111
  });
113
- if (!data.success || !data.snapshot) {
114
- throw new Error(`Failed to take the runtime snapshot ${options.id} - ${data}`);
112
+ if (!data.success) {
113
+ throw new Error(`Failed to take the code sandbox snapshot ${options.id} - ${data}`);
114
+ }
115
+ // Runtimes service can return 202 Accepted without inline snapshot payload
116
+ // while the snapshot lifecycle completes asynchronously via pub-sub events.
117
+ if (!data.snapshot) {
118
+ return undefined;
115
119
  }
116
- return asRuntimeSnapshot(data.snapshot);
120
+ return asCodeSandboxSnapshot(data.snapshot);
117
121
  }
118
122
  /**
119
- * Get Runtime Snapshots.
123
+ * Get Code Sandbox Snapshots.
120
124
  */
121
- export async function getRuntimeSnapshots() {
125
+ export async function getSandboxSnapshots() {
122
126
  const data = await requestDatalayerAPI({
123
- url: URLExt.join(runtimesStore.getState().runtimesRunUrl, 'api/runtimes/v1/runtime-snapshots'),
127
+ url: URLExt.join(runtimesStore.getState().runtimesRunUrl, 'api/runtimes/v1/sandbox-snapshots'),
124
128
  token: iamStore.getState().token,
125
129
  });
126
130
  if (!data.success) {
127
- console.error('Failed to fetch runtime snapshots.', data);
131
+ console.error('Failed to fetch code sandbox snapshots.', data);
128
132
  return [];
129
133
  }
130
- return (data.snapshots ?? []).map(asRuntimeSnapshot);
134
+ return (data.snapshots ?? []).map(asCodeSandboxSnapshot);
131
135
  }
132
136
  /**
133
- * Load a Runtime Snapshot within a Runtime.
137
+ * Load a Code Sandbox Snapshot within a Runtime.
134
138
  */
135
- export async function loadRuntimeSnapshot(options) {
139
+ export async function loadSandboxSnapshot(options) {
136
140
  const data = await requestDatalayerAPI({
137
141
  url: URLExt.join(runtimesStore.getState().runtimesRunUrl, 'api/runtimes/v1/runtimes', options.id),
138
142
  method: 'PUT',
@@ -142,29 +146,29 @@ export async function loadRuntimeSnapshot(options) {
142
146
  token: iamStore.getState().token,
143
147
  });
144
148
  if (!data.success) {
145
- throw new Error(`Failed to load the runtime snapshot; ${data.message}`);
149
+ throw new Error(`Failed to load the code sandbox snapshot; ${data.message}`);
146
150
  }
147
151
  }
148
152
  /**
149
- * Returns the Runtime Snapshot download URL.
153
+ * Returns the Code Sandbox Snapshot download URL.
150
154
  *
151
155
  * @param id Snapshot UID to download
152
156
  * @returns The download URL
153
157
  */
154
- export function createRuntimeSnapshotDownloadURL(id) {
155
- return (URLExt.join(runtimesStore.getState().runtimesRunUrl, `api/runtimes/v1/runtime-snapshots/${id}`) +
158
+ export function createSandboxSnapshotDownloadURL(id) {
159
+ return (URLExt.join(runtimesStore.getState().runtimesRunUrl, `api/runtimes/v1/sandbox-snapshots/${id}`) +
156
160
  URLExt.objectToQueryString({
157
161
  download: '1',
158
162
  token: iamStore.getState().token ?? '',
159
163
  }));
160
164
  }
161
165
  /**
162
- * Export a Runtime Snapshot.
166
+ * Export a Code Sandbox Snapshot.
163
167
  *
164
- * @param id Runtime snapshot UID to download
168
+ * @param id Code Sandbox snapshot UID to download
165
169
  */
166
- export function exportRuntimeSnapshot(id) {
167
- const url = createRuntimeSnapshotDownloadURL(id);
170
+ export function exportCodeSandboxSnapshot(id) {
171
+ const url = createSandboxSnapshotDownloadURL(id);
168
172
  const element = document.createElement('a');
169
173
  element.href = url;
170
174
  element.download = '';
@@ -173,46 +177,22 @@ export function exportRuntimeSnapshot(id) {
173
177
  document.body.removeChild(element);
174
178
  }
175
179
  /**
176
- * Delete a Runtime Snapshot.
180
+ * Delete a Code Sandbox Snapshot.
177
181
  */
178
- export async function deleteRuntimeSnapshot(id) {
182
+ export async function deleteCodeSandboxSnapshot(id) {
179
183
  await requestDatalayerAPI({
180
- url: URLExt.join(runtimesStore.getState().runtimesRunUrl, `api/runtimes/v1/runtime-snapshots/${id}`),
184
+ url: URLExt.join(runtimesStore.getState().runtimesRunUrl, `api/runtimes/v1/sandbox-snapshots/${id}`),
181
185
  method: 'DELETE',
182
186
  token: iamStore.getState().token,
183
187
  });
184
- // Poll Runtime Snapshot state up-to its deletion.
185
- try {
186
- let sleepTimeout = 1000;
187
- while (true) {
188
- await sleep(sleepTimeout);
189
- sleepTimeout *= 2;
190
- const response = await requestDatalayerAPI({
191
- url: URLExt.join(runtimesStore.getState().runtimesRunUrl, `api/runtimes/v1/runtime-snapshots/${id}`),
192
- token: iamStore.getState().token,
193
- });
194
- if (response.success === false) {
195
- throw new Error(response.message);
196
- }
197
- }
198
- }
199
- catch (error) {
200
- if (error.name === 'RunResponseError' &&
201
- error.response.status === 404) {
202
- // Expected not found
203
- }
204
- else {
205
- throw error;
206
- }
207
- }
208
188
  }
209
189
  /**
210
- * Update Runtime Snapshot metadata.
190
+ * Update Code Sandbox Snapshot metadata.
211
191
  */
212
- export async function updateRuntimeSnapshot(id, metadata) {
192
+ export async function updateCodeSandboxSnapshot(id, metadata) {
213
193
  if (metadata.name || metadata.description) {
214
194
  await requestDatalayerAPI({
215
- url: URLExt.join(runtimesStore.getState().runtimesRunUrl, `api/runtimes/v1/runtime-snapshots/${id}`),
195
+ url: URLExt.join(runtimesStore.getState().runtimesRunUrl, `api/runtimes/v1/sandbox-snapshots/${id}`),
216
196
  method: 'PATCH',
217
197
  body: { ...metadata },
218
198
  token: iamStore.getState().token,
@@ -220,19 +200,19 @@ export async function updateRuntimeSnapshot(id, metadata) {
220
200
  }
221
201
  }
222
202
  /**
223
- * Upload a Runtime Snapshot.
203
+ * Upload a Code Sandbox Snapshot.
224
204
  *
225
205
  * Note: The promise will be rejected if the runtime state is empty.
226
206
  */
227
- export async function uploadRuntimeSnapshot(options) {
207
+ export async function uploadCodeSandboxSnapshot(options) {
228
208
  if (options.file.size === 0) {
229
- return Promise.reject('Empty Runtime Snapshot.');
209
+ return Promise.reject('Empty Code Sandbox Snapshot.');
230
210
  }
231
211
  const tracker = new PromiseDelegate();
232
212
  // Create a new tus upload.
233
213
  const upload = new Upload(options.file, {
234
214
  // Endpoint is the upload creation URL from your tus server.
235
- endpoint: `${runtimesStore.getState().runtimesRunUrl}/api/runtimes/v1/runtime-snapshots/upload`,
215
+ endpoint: `${runtimesStore.getState().runtimesRunUrl}/api/runtimes/v1/sandbox-snapshots/upload`,
236
216
  headers: { Authorization: `Bearer ${iamStore.getState().token}` },
237
217
  // Retry delays will enable tus-js-client to automatically retry on errors.
238
218
  // retryDelays: [0, 3000, 5000, 10000, 20000],
@@ -5,7 +5,7 @@ import { ISessionContext } from '@jupyterlab/apputils';
5
5
  import { ServiceManager, Kernel, ServerConnection } from '@jupyterlab/services';
6
6
  import { IDisposable } from '@lumino/disposable';
7
7
  import { ISignal } from '@lumino/signaling';
8
- import type { IRuntimeSnapshot, IRuntimeCapabilities, IRuntimeModel, IDatalayerEnvironment, IRuntimeType, IRuntimeLocation } from '../../models';
8
+ import type { ICodeSandboxSnapshot, IRuntimeCapabilities, IRuntimeModel, IDatalayerEnvironment, IRuntimeType, IRuntimeLocation } from '../../models';
9
9
  /**
10
10
  * Abstract interface for the Datalayer session context.
11
11
  * It extends the JupyterLab session context
@@ -188,13 +188,13 @@ export interface IRemoteRuntimesManager extends IDisposable {
188
188
  * Whether to stop the kernel after the snapshot completion or not.
189
189
  */
190
190
  stop?: boolean;
191
- }): Promise<IRuntimeSnapshot | undefined>;
191
+ }): Promise<ICodeSandboxSnapshot | undefined>;
192
192
  /**
193
193
  * Load a snapshot within a runtim
194
194
  *
195
195
  * The runtime may be given by its `id` or `podName`.
196
196
  */
197
- loadRuntimeSnapshot(options: {
197
+ loadSandboxSnapshot(options: {
198
198
  /**
199
199
  * The kernel id
200
200
  */
@@ -12,13 +12,13 @@ type Props = {
12
12
  *
13
13
  * Note: You should use this only for browser runtimes.
14
14
  */
15
- export declare function createRuntimeSnapshot(props: Props): Promise<void>;
15
+ export declare function createSandboxSnapshot(props: Props): Promise<void>;
16
16
  /**
17
17
  * Load a snapshot within a browser kernel.
18
18
  *
19
19
  * Note: You should use this only for browser kernels.
20
20
  */
21
- export declare function loadBrowserRuntimeSnapshot({ connection, id, }: {
21
+ export declare function loadBrowserSandboxSnapshot({ connection, id, }: {
22
22
  connection: Kernel.IKernelConnection;
23
23
  id: string;
24
24
  }): Promise<void>;
@@ -3,13 +3,13 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  import { KernelExecutor } from '@datalayer/jupyter-react';
6
- import { createRuntimeSnapshotDownloadURL, uploadRuntimeSnapshot } from './index.js';
6
+ import { createSandboxSnapshotDownloadURL, uploadCodeSandboxSnapshot } from './index.js';
7
7
  /**
8
8
  * Snapshot a runtime through the frontend and upload it to the cloud.
9
9
  *
10
10
  * Note: You should use this only for browser runtimes.
11
11
  */
12
- export async function createRuntimeSnapshot(props) {
12
+ export async function createSandboxSnapshot(props) {
13
13
  const { connection, metadata, onUploadProgress } = props;
14
14
  const dump = await new KernelExecutor({ connection }).execute(GET_RUNTIME_SNAPSHOT_SNIPPET, {
15
15
  storeHistory: false,
@@ -19,7 +19,7 @@ export async function createRuntimeSnapshot(props) {
19
19
  // Convert the data to blob.
20
20
  const bytes = base64ToBytes(serializedData);
21
21
  const file = new Blob([bytes.buffer]);
22
- return uploadRuntimeSnapshot({
22
+ return uploadCodeSandboxSnapshot({
23
23
  file,
24
24
  metadata,
25
25
  onProgress: onUploadProgress,
@@ -36,14 +36,14 @@ function base64ToBytes(base64) {
36
36
  *
37
37
  * Note: You should use this only for browser kernels.
38
38
  */
39
- export async function loadBrowserRuntimeSnapshot({ connection, id, }) {
40
- const downloadURL = createRuntimeSnapshotDownloadURL(id);
39
+ export async function loadBrowserSandboxSnapshot({ connection, id, }) {
40
+ const downloadURL = createSandboxSnapshotDownloadURL(id);
41
41
  const response = await fetch(downloadURL);
42
42
  const buffer = await response.arrayBuffer();
43
43
  const base64 = bytesToBase64(new Uint8Array(buffer));
44
44
  await new KernelExecutor({
45
45
  connection,
46
- }).execute(getLoadRuntimeSnapshotSnippet(base64), {
46
+ }).execute(getLoadSandboxSnapshotSnippet(base64), {
47
47
  storeHistory: false,
48
48
  silent: true,
49
49
  });
@@ -104,7 +104,7 @@ const GET_RUNTIME_SNAPSHOT_SNIPPET = `def _create_snapshot():
104
104
  _create_snapshot()
105
105
  del _create_snapshot
106
106
  `;
107
- function getLoadRuntimeSnapshotSnippet(content) {
107
+ function getLoadSandboxSnapshotSnippet(content) {
108
108
  return `async def _load_snapshot():
109
109
  import os
110
110
  import logging
@@ -9,6 +9,12 @@ export declare const MEMORY_UNIT_LIMITS: {
9
9
  readonly [U in MemoryUnit]: number;
10
10
  };
11
11
  export declare function formatForDisplay(numBytes: number | undefined, units?: MemoryUnit | undefined): string;
12
+ /**
13
+ * Format a byte size value using a human-friendly unit.
14
+ *
15
+ * Examples: 0 B, 532 B, 1.2 KB, 24 MB, 1.45 GB
16
+ */
17
+ export declare function formatByteSize(numBytes: number | string | null | undefined): string;
12
18
  /**
13
19
  * Given a number of bytes, convert to the most human-readable
14
20
  * format, (GB, TB, etc).
@@ -17,6 +17,23 @@ export function formatForDisplay(numBytes, units) {
17
17
  const lu = convertToLargestUnit(numBytes, units);
18
18
  return lu[0].toFixed(2) + ' ' + lu[1];
19
19
  }
20
+ /**
21
+ * Format a byte size value using a human-friendly unit.
22
+ *
23
+ * Examples: 0 B, 532 B, 1.2 KB, 24 MB, 1.45 GB
24
+ */
25
+ export function formatByteSize(numBytes) {
26
+ const normalizedNumBytes = typeof numBytes === 'string' ? Number(numBytes) : numBytes;
27
+ if (!Number.isFinite(normalizedNumBytes) || !normalizedNumBytes || normalizedNumBytes < 0) {
28
+ return '0 B';
29
+ }
30
+ const [value, unit] = convertToLargestUnit(normalizedNumBytes);
31
+ const decimals = value >= 100 ? 0 : value >= 10 ? 1 : 2;
32
+ const formattedValue = value
33
+ .toFixed(decimals)
34
+ .replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1');
35
+ return `${formattedValue} ${unit}`;
36
+ }
20
37
  /**
21
38
  * Given a number of bytes, convert to the most human-readable
22
39
  * format, (GB, TB, etc).
@@ -0,0 +1,3 @@
1
+ export declare function isExternalUrnHandle(handle?: string): boolean;
2
+ export declare function formatFriendlyHandle(handle?: string): string;
3
+ export declare function normalizeHandleFromName(value?: string): string;
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ const EXT_URN_PREFIX = 'urn:dla:iam:ext::';
6
+ export function isExternalUrnHandle(handle) {
7
+ const normalized = (handle || '').trim().toLowerCase();
8
+ return normalized.startsWith(EXT_URN_PREFIX);
9
+ }
10
+ export function formatFriendlyHandle(handle) {
11
+ const normalizedHandle = (handle || '').trim();
12
+ if (!normalizedHandle) {
13
+ return 'unknown';
14
+ }
15
+ if (!isExternalUrnHandle(normalizedHandle)) {
16
+ return normalizedHandle;
17
+ }
18
+ const externalId = normalizedHandle.slice(EXT_URN_PREFIX.length);
19
+ const [providerRaw, ...restParts] = externalId.split(':');
20
+ const provider = (providerRaw || '').toLowerCase();
21
+ const providerLabel = provider === 'github'
22
+ ? 'GitHub'
23
+ : provider === 'google'
24
+ ? 'Google'
25
+ : providerRaw || 'External';
26
+ const identifier = restParts.join(':').trim();
27
+ if (!identifier) {
28
+ return providerLabel;
29
+ }
30
+ const shortIdentifier = identifier.length > 18 ? `${identifier.slice(0, 15)}...` : identifier;
31
+ return `${providerLabel} ${shortIdentifier}`;
32
+ }
33
+ export function normalizeHandleFromName(value) {
34
+ const source = String(value || '').trim();
35
+ if (!source) {
36
+ return '';
37
+ }
38
+ const transliterated = source
39
+ .replace(/ß/g, 'ss')
40
+ .replace(/æ/gi, 'ae')
41
+ .replace(/œ/gi, 'oe')
42
+ .replace(/ø/gi, 'o')
43
+ .replace(/đ/gi, 'd')
44
+ .replace(/þ/gi, 'th')
45
+ .replace(/ł/gi, 'l')
46
+ .normalize('NFKD')
47
+ .replace(/[\u0300-\u036f]/g, '');
48
+ return transliterated
49
+ .toLowerCase()
50
+ .replace(/[^a-z0-9]+/g, '-')
51
+ .replace(/^-+|-+$/g, '')
52
+ .replace(/-{2,}/g, '-');
53
+ }
@@ -4,4 +4,4 @@
4
4
  * @param suffix Name prefix
5
5
  * @returns The kernel snapshot name
6
6
  */
7
- export declare function createRuntimeSnapshotName(suffix: string): string;
7
+ export declare function createSandboxSnapshotName(suffix: string): string;
@@ -16,6 +16,6 @@ const KERNEL_SNAPSHOT_DESCRIPTION_CONFIGURATION = {
16
16
  * @param suffix Name prefix
17
17
  * @returns The kernel snapshot name
18
18
  */
19
- export function createRuntimeSnapshotName(suffix) {
19
+ export function createSandboxSnapshotName(suffix) {
20
20
  return `${uniqueNamesGenerator(KERNEL_SNAPSHOT_DESCRIPTION_CONFIGURATION)}-${suffix}`;
21
21
  }
@@ -10,6 +10,7 @@ export * from './DownloadFile';
10
10
  export * from './Env';
11
11
  export * from './File';
12
12
  export * from './Format';
13
+ export * from './Handles';
13
14
  export * from './Ids';
14
15
  export * from './Jwt';
15
16
  export * from './Jupyter';
@@ -14,6 +14,7 @@ export * from './DownloadFile.js';
14
14
  export * from './Env.js';
15
15
  export * from './File.js';
16
16
  export * from './Format.js';
17
+ export * from './Handles.js';
17
18
  export * from './Ids.js';
18
19
  export * from './Jwt.js';
19
20
  export * from './Jupyter.js';
@@ -1,2 +1,8 @@
1
- export declare const DatasourceDetail: () => import("react/jsx-runtime").JSX.Element;
1
+ export type DatasourceDetailProps = {
2
+ /** Optional principal uid used to scope datasource reads/updates. */
3
+ principalUid?: string;
4
+ /** Optional principal kind used to scope datasource reads/updates. */
5
+ principalKind?: 'user' | 'organization' | 'team';
6
+ };
7
+ export declare const DatasourceDetail: ({ principalUid, principalKind, }?: DatasourceDetailProps) => import("react/jsx-runtime").JSX.Element;
2
8
  export default DatasourceDetail;