@datalayer/agent-runtimes 1.0.25 → 1.0.26
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/lib/components/agents/index.d.ts +6 -0
- package/lib/components/{students → agents}/index.js +6 -1
- package/lib/components/{NotificationEventCard.js → cards/NotificationEventCard.js} +1 -1
- package/lib/components/{OutputCard.js → cards/OutputCard.js} +1 -1
- package/lib/components/cards/index.d.ts +9 -0
- package/lib/components/cards/index.js +13 -0
- package/lib/components/{runtimes/RuntimeCellVariables.d.ts → code-sandboxes/CodeSandboxCellVariables.d.ts} +3 -3
- package/lib/components/{runtimes/RuntimeCellVariables.js → code-sandboxes/CodeSandboxCellVariables.js} +2 -2
- package/lib/components/{runtimes/RuntimeCellVariablesDialog.d.ts → code-sandboxes/CodeSandboxCellVariablesDialog.d.ts} +4 -4
- package/lib/components/{runtimes/RuntimeCellVariablesDialog.js → code-sandboxes/CodeSandboxCellVariablesDialog.js} +4 -4
- package/lib/components/code-sandboxes/CodeSandboxLauncher.d.ts +0 -2
- package/lib/components/code-sandboxes/CodeSandboxLauncher.js +0 -2
- package/lib/components/code-sandboxes/CodeSandboxPicker.d.ts +30 -5
- package/lib/components/code-sandboxes/CodeSandboxPicker.js +188 -55
- package/lib/components/{runtimes/RuntimePickerCell.d.ts → code-sandboxes/CodeSandboxPickerCell.d.ts} +5 -5
- package/lib/components/{runtimes/RuntimePickerCell.js → code-sandboxes/CodeSandboxPickerCell.js} +6 -6
- package/lib/components/{runtimes/RuntimeReservationControl.d.ts → code-sandboxes/CodeSandboxReservationControl.d.ts} +3 -3
- package/lib/components/{runtimes/RuntimeReservationControl.js → code-sandboxes/CodeSandboxReservationControl.js} +5 -5
- package/lib/components/{runtimes/RuntimeTransfer.d.ts → code-sandboxes/CodeSandboxTransfer.d.ts} +1 -1
- package/lib/components/{runtimes/RuntimeUtils.d.ts → code-sandboxes/CodeSandboxUtils.d.ts} +3 -3
- package/lib/components/{runtimes/RuntimeUtils.js → code-sandboxes/CodeSandboxUtils.js} +1 -1
- package/lib/components/code-sandboxes/CodeSandboxVariables.d.ts +71 -0
- package/lib/components/{runtimes/RuntimeVariables.js → code-sandboxes/CodeSandboxVariables.js} +77 -2
- package/lib/components/code-sandboxes/NewCodeSandboxControls.js +3 -3
- package/lib/components/code-sandboxes/index.d.ts +19 -1
- package/lib/components/code-sandboxes/index.js +19 -1
- package/lib/components/index.d.ts +4 -6
- package/lib/components/index.js +4 -6
- package/lib/components/progress/CreditsIndicator.js +1 -1
- package/package.json +2 -2
- package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +0 -7
- package/lib/components/runtimes/RuntimeLauncherDialog.js +0 -11
- package/lib/components/runtimes/RuntimePickerBase.d.ts +0 -8
- package/lib/components/runtimes/RuntimePickerBase.js +0 -12
- package/lib/components/runtimes/RuntimePickerNotebook.d.ts +0 -42
- package/lib/components/runtimes/RuntimePickerNotebook.js +0 -197
- package/lib/components/runtimes/RuntimeSimplePicker.d.ts +0 -38
- package/lib/components/runtimes/RuntimeSimplePicker.js +0 -156
- package/lib/components/runtimes/RuntimeVariables.d.ts +0 -38
- package/lib/components/runtimes/index.d.ts +0 -12
- package/lib/components/runtimes/index.js +0 -17
- package/lib/components/students/StudentItemStatus.d.ts +0 -7
- package/lib/components/students/StudentItemStatus.js +0 -68
- package/lib/components/students/index.d.ts +0 -1
- package/scripts/codegen/__pycache__/versioning.cpython-313.pyc +0 -0
- /package/lib/components/{AgentSummary.d.ts → agents/AgentSummary.d.ts} +0 -0
- /package/lib/components/{AgentSummary.js → agents/AgentSummary.js} +0 -0
- /package/lib/components/{NotificationEventCard.d.ts → cards/NotificationEventCard.d.ts} +0 -0
- /package/lib/components/{OutputCard.d.ts → cards/OutputCard.d.ts} +0 -0
- /package/lib/components/{ToolApprovalCard.d.ts → cards/ToolApprovalCard.d.ts} +0 -0
- /package/lib/components/{ToolApprovalCard.js → cards/ToolApprovalCard.js} +0 -0
- /package/lib/components/{runtimes/RuntimeTransfer.js → code-sandboxes/CodeSandboxTransfer.js} +0 -0
|
@@ -9,7 +9,7 @@ import { Box } from '@datalayer/primer-addons';
|
|
|
9
9
|
import { ChevronDownIcon, DownloadIcon, EyeClosedIcon, EyeIcon, TrashIcon, } from '@primer/octicons-react';
|
|
10
10
|
import { createMarkdownDownloadPayload, downloadTextPayload, formatDurationMs, formatRelativeTime, } from '@datalayer/core/lib/utils';
|
|
11
11
|
import { Streamdown } from 'streamdown';
|
|
12
|
-
import { streamdownMarkdownStyles } from '
|
|
12
|
+
import { streamdownMarkdownStyles } from '../../chat/styles/streamdownStyles';
|
|
13
13
|
const EVENT_KIND_VARIANT = {
|
|
14
14
|
'agent-start-requested': 'attention',
|
|
15
15
|
'agent-assigned': 'accent',
|
|
@@ -9,7 +9,7 @@ import { Box } from '@datalayer/primer-addons';
|
|
|
9
9
|
import { ChevronDownIcon, DownloadIcon, EyeClosedIcon, EyeIcon, TrashIcon, } from '@primer/octicons-react';
|
|
10
10
|
import { createMarkdownDownloadPayload, downloadTextPayload, formatDurationMs, formatRelativeTime, } from '@datalayer/core/lib/utils';
|
|
11
11
|
import { Streamdown } from 'streamdown';
|
|
12
|
-
import { streamdownMarkdownStyles } from '
|
|
12
|
+
import { streamdownMarkdownStyles } from '../../chat/styles/streamdownStyles';
|
|
13
13
|
export function OutputCard({ event, onToggleRead, onDelete, onOpenAgent, }) {
|
|
14
14
|
const [isOutputExpanded, setIsOutputExpanded] = useState(false);
|
|
15
15
|
const outputText = event.kind === 'agent-output' && event.payload?.outputs
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cards an agent run is read through: the notifications it emitted, the
|
|
3
|
+
* outputs it produced, and the tool calls waiting for an approval.
|
|
4
|
+
*
|
|
5
|
+
* @module components/cards
|
|
6
|
+
*/
|
|
7
|
+
export * from './NotificationEventCard';
|
|
8
|
+
export * from './OutputCard';
|
|
9
|
+
export * from './ToolApprovalCard';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The cards an agent run is read through: the notifications it emitted, the
|
|
7
|
+
* outputs it produced, and the tool calls waiting for an approval.
|
|
8
|
+
*
|
|
9
|
+
* @module components/cards
|
|
10
|
+
*/
|
|
11
|
+
export * from './NotificationEventCard';
|
|
12
|
+
export * from './OutputCard';
|
|
13
|
+
export * from './ToolApprovalCard';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ITranslator } from '@jupyterlab/translation';
|
|
2
2
|
/**
|
|
3
|
-
* {@link
|
|
3
|
+
* {@link CodeSandboxCellVariables} properties
|
|
4
4
|
*/
|
|
5
5
|
interface IRuntimeCellVariablesProps {
|
|
6
6
|
/**
|
|
@@ -35,5 +35,5 @@ interface IRuntimeCellVariablesProps {
|
|
|
35
35
|
/**
|
|
36
36
|
* Runtime Cell Variables Picker.
|
|
37
37
|
*/
|
|
38
|
-
export declare function
|
|
39
|
-
export default
|
|
38
|
+
export declare function CodeSandboxCellVariables(props: IRuntimeCellVariablesProps): JSX.Element;
|
|
39
|
+
export default CodeSandboxCellVariables;
|
|
@@ -11,7 +11,7 @@ import { Box } from '@datalayer/primer-addons';
|
|
|
11
11
|
/**
|
|
12
12
|
* Runtime Cell Variables Picker.
|
|
13
13
|
*/
|
|
14
|
-
export function
|
|
14
|
+
export function CodeSandboxCellVariables(props) {
|
|
15
15
|
const { getInputOptions, getOutputOptions, inputs, output, setInputs, setOutput, translator, } = props;
|
|
16
16
|
const trans = useMemo(() => (translator ?? nullTranslator).load('jupyterlab'), [translator]);
|
|
17
17
|
const inputForOutputRef = useRef(null);
|
|
@@ -169,4 +169,4 @@ export function RuntimeCellVariables(props) {
|
|
|
169
169
|
.filter(item => item.selected)
|
|
170
170
|
.map(item => item.id), onSelectedChange: onSelectedInputsChange, "aria-labelledby": "cell-input-variables", selectionVariant: "multiple", emptyStateText: trans.__('No available variables.'), loading: inputLoading }) })] })] }), _jsxs(FormControl, { children: [_jsx(FormControl.Label, { id: "cell-output-variables", children: trans.__('Output') }), _jsxs(Autocomplete, { children: [_jsx(Autocomplete.Input, { ref: inputForOutputRef, value: output, onChange: onOutputChange }), _jsx(Autocomplete.Overlay, { children: _jsx(Autocomplete.Menu, { items: outputsState ?? [], selectedItemIds: output ? [output] : [], "aria-labelledby": "cell-output-variables", loading: getOutputOptions && !outputsState, emptyStateText: trans.__('Not among the available variables.'), onOpenChange: handleOutputMenuOpenChange }) })] })] })] }));
|
|
171
171
|
}
|
|
172
|
-
export default
|
|
172
|
+
export default CodeSandboxCellVariables;
|
|
@@ -2,9 +2,9 @@ import { ISessionContext } from '@jupyterlab/apputils';
|
|
|
2
2
|
import { CodeCellModel } from '@jupyterlab/cells';
|
|
3
3
|
import { ITranslator } from '@jupyterlab/translation';
|
|
4
4
|
/**
|
|
5
|
-
* {@link
|
|
5
|
+
* {@link CodeSandboxCellVariablesDialog} properties
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface ICodeSandboxCellVariablesDialogProps {
|
|
8
8
|
/**
|
|
9
9
|
* Code cell model
|
|
10
10
|
*/
|
|
@@ -33,5 +33,5 @@ export interface IRuntimeCellVariablesDialogProps {
|
|
|
33
33
|
/**
|
|
34
34
|
* Dialog to define the runtime cell variables to transfer
|
|
35
35
|
*/
|
|
36
|
-
export declare function
|
|
37
|
-
export default
|
|
36
|
+
export declare function CodeSandboxCellVariablesDialog(props: ICodeSandboxCellVariablesDialogProps): JSX.Element;
|
|
37
|
+
export default CodeSandboxCellVariablesDialog;
|
|
@@ -9,11 +9,11 @@ import { nullTranslator } from '@jupyterlab/translation';
|
|
|
9
9
|
import { JSONExt } from '@lumino/coreutils';
|
|
10
10
|
import { KernelExecutor } from '@datalayer/jupyter-react';
|
|
11
11
|
import { RuntimeSnippetsFacade } from '../../jupyter';
|
|
12
|
-
import {
|
|
12
|
+
import { CodeSandboxCellVariables } from './CodeSandboxCellVariables';
|
|
13
13
|
/**
|
|
14
14
|
* Dialog to define the runtime cell variables to transfer
|
|
15
15
|
*/
|
|
16
|
-
export function
|
|
16
|
+
export function CodeSandboxCellVariablesDialog(props) {
|
|
17
17
|
const { onClose, model, preference, sessionContext, translator } = props;
|
|
18
18
|
const [inputs, setInputs] = useState([]);
|
|
19
19
|
const [output, setOutput] = useState();
|
|
@@ -96,6 +96,6 @@ export function RuntimeCellVariablesDialog(props) {
|
|
|
96
96
|
onClick: setVariables,
|
|
97
97
|
autoFocus: true,
|
|
98
98
|
},
|
|
99
|
-
], children: _jsx(
|
|
99
|
+
], children: _jsx(CodeSandboxCellVariables, { inputs: inputs, getInputOptions: sessionContext ? getInputCandidates : undefined, setInputs: setInputs, output: output ?? undefined, getOutputOptions: getOutputCandidates, setOutput: setOutput, translator: translator }) }));
|
|
100
100
|
}
|
|
101
|
-
export default
|
|
101
|
+
export default CodeSandboxCellVariablesDialog;
|
|
@@ -55,5 +55,3 @@ export interface ICodeSandboxLauncherProps {
|
|
|
55
55
|
* The launcher of a new code sandbox.
|
|
56
56
|
*/
|
|
57
57
|
export declare function CodeSandboxLauncher(props: ICodeSandboxLauncherProps): JSX.Element;
|
|
58
|
-
export declare const RuntimeLauncherDialog: typeof CodeSandboxLauncher;
|
|
59
|
-
export type IRuntimeLauncherDialogProps = ICodeSandboxLauncherProps;
|
|
@@ -268,5 +268,3 @@ export function CodeSandboxLauncher(props) {
|
|
|
268
268
|
jupyterLabAdapter?.jupyterLab &&
|
|
269
269
|
!configuration.whiteLabel && (_jsxs(FormControl, { sx: { paddingTop: '10px' }, children: [_jsx(FormControl.Label, { id: "open-example-label", children: "Open example notebook" }), _jsx(ToggleSwitch, { disabled: !environments.find(spec => spec.name === selection)?.example, checked: openExample, size: "small", onClick: handleSwitchClick, "aria-labelledby": "open-example-label" })] })), error && (_jsx(FlashClosable, { variant: flashLevel, actions: navigate && upgradeSubscription && flashLevel === 'warning' ? (_jsx(Button, { onClick: handleUpgrade, title: 'Upgrade your subscription.', children: "Upgrade" })) : undefined, children: error }))] }) }));
|
|
270
270
|
}
|
|
271
|
-
// Backward-compatible aliases (deprecated: use CodeSandboxLauncher).
|
|
272
|
-
export const RuntimeLauncherDialog = CodeSandboxLauncher;
|
|
@@ -2,7 +2,8 @@ import { ReactElement, ReactNode } from 'react';
|
|
|
2
2
|
import { ISessionContext } from '@jupyterlab/apputils';
|
|
3
3
|
import { ITranslator } from '@jupyterlab/translation';
|
|
4
4
|
import { IRuntimeDesc } from '../../models';
|
|
5
|
-
import { IMultiServiceManager } from '../../runtimes';
|
|
5
|
+
import { type IMultiServiceManager } from '../../runtimes';
|
|
6
|
+
import type { CodeSandboxTransfer } from './CodeSandboxTransfer';
|
|
6
7
|
type IDisplayMode = 'menu' | 'radio';
|
|
7
8
|
/**
|
|
8
9
|
* {@link CodeSandboxPicker} properties
|
|
@@ -38,13 +39,18 @@ export interface ICodeSandboxPickerProps {
|
|
|
38
39
|
location?: string;
|
|
39
40
|
};
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
+
* The sandbox shown as chosen.
|
|
43
|
+
*
|
|
44
|
+
* Given with {@link setRuntimeDesc}, the choice belongs to the host — a
|
|
45
|
+
* cell keeps it in its metadata. Omitted, the picker holds it itself and
|
|
46
|
+
* reports it through {@link onTransferChange}, which is what a dialog with
|
|
47
|
+
* no state of its own needs.
|
|
42
48
|
*/
|
|
43
49
|
runtimeDesc?: IRuntimeDesc;
|
|
44
50
|
/**
|
|
45
51
|
* Set runtime description.
|
|
46
52
|
*/
|
|
47
|
-
setRuntimeDesc
|
|
53
|
+
setRuntimeDesc?: (desc?: IRuntimeDesc) => void;
|
|
48
54
|
/**
|
|
49
55
|
* Document session context.
|
|
50
56
|
*/
|
|
@@ -61,11 +67,30 @@ export interface ICodeSandboxPickerProps {
|
|
|
61
67
|
* Change the look depending on the menu integration.
|
|
62
68
|
*/
|
|
63
69
|
variant?: 'document' | 'cell';
|
|
70
|
+
/**
|
|
71
|
+
* Whether the questions of a NEW sandbox are asked below the list.
|
|
72
|
+
*
|
|
73
|
+
* They are the launcher's own — see `NewCodeSandboxControls` — and only
|
|
74
|
+
* concern a sandbox that does not run yet.
|
|
75
|
+
*/
|
|
76
|
+
withNewSandboxControls?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Whether the variables of the current sandbox may be carried to the
|
|
79
|
+
* chosen one, when both speak a language the snippets can serialize.
|
|
80
|
+
*/
|
|
81
|
+
withVariablesTransfer?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Called with the answer a dialog would return: the sandbox to assign and
|
|
84
|
+
* the variables to carry over.
|
|
85
|
+
*
|
|
86
|
+
* The sandbox is named the way the callers start it: `remote-` and
|
|
87
|
+
* `browser-` prefix an environment to start one in, a local environment is
|
|
88
|
+
* named by its specification alone, and `id` names one that already runs.
|
|
89
|
+
*/
|
|
90
|
+
onTransferChange?: (transfer: CodeSandboxTransfer) => void;
|
|
64
91
|
}
|
|
65
92
|
/**
|
|
66
93
|
* The picker of a code sandbox: what runs already, and what could run.
|
|
67
94
|
*/
|
|
68
95
|
export declare function CodeSandboxPicker(props: ICodeSandboxPickerProps): ReactElement;
|
|
69
|
-
export declare const RuntimePickerBase: typeof CodeSandboxPicker;
|
|
70
|
-
export type IRuntimePickerBaseProps = ICodeSandboxPickerProps;
|
|
71
96
|
export default CodeSandboxPicker;
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
6
|
+
import { useCallback, useEffect, useMemo, useState, } from 'react';
|
|
7
7
|
import { nullTranslator } from '@jupyterlab/translation';
|
|
8
8
|
//import { kernelIcon } from '@jupyterlab/ui-components';
|
|
9
9
|
import { ActionList, ActionMenu, IconButton, Text, RadioGroup, Radio, FormControl, LabelGroup, Label, } from '@primer/react';
|
|
@@ -12,8 +12,11 @@ import { Box } from '@datalayer/primer-addons';
|
|
|
12
12
|
import { CpuIcon } from '@primer/octicons-react';
|
|
13
13
|
import { BrowserIcon, LaptopSimpleIcon } from '@datalayer/icons-react';
|
|
14
14
|
import { CreditsIndicator } from '../progress';
|
|
15
|
-
import { isRuntimeRemote } from '../../runtimes';
|
|
16
|
-
import {
|
|
15
|
+
import { isRuntimeRemote, } from '../../runtimes';
|
|
16
|
+
import { useIAMStore } from '../../state/substates';
|
|
17
|
+
import { getGroupedCodeSandboxDescs, } from './CodeSandboxUtils';
|
|
18
|
+
import { creditsLimitFor, NewCodeSandboxControls, useNewCodeSandboxAllowance, } from './NewCodeSandboxControls';
|
|
19
|
+
import { CodeSandboxVariables, useCodeSandboxVariablesTransfer, } from './CodeSandboxVariables';
|
|
17
20
|
/**
|
|
18
21
|
* Maximal runtime display name length after which it is trimmed.
|
|
19
22
|
*/
|
|
@@ -22,8 +25,23 @@ const RUNTIME_DISPLAY_NAME_MAX_LENGTH = 25;
|
|
|
22
25
|
* The picker of a code sandbox: what runs already, and what could run.
|
|
23
26
|
*/
|
|
24
27
|
export function CodeSandboxPicker(props) {
|
|
25
|
-
const { disabled, display, filterRuntime, multiServiceManager, postActions, preActions, preference,
|
|
26
|
-
|
|
28
|
+
const { disabled, display, filterRuntime, multiServiceManager, onTransferChange, postActions, preActions, preference, sessionContext, translator, variant, withNewSandboxControls, withVariablesTransfer, } = props;
|
|
29
|
+
/*
|
|
30
|
+
* The choice, held here when the host does not hold it.
|
|
31
|
+
*
|
|
32
|
+
* A cell keeps its sandbox in its metadata and passes both the value and
|
|
33
|
+
* the setter; a dialog has nowhere to keep it, so the picker does.
|
|
34
|
+
*/
|
|
35
|
+
const isControlled = props.setRuntimeDesc !== undefined;
|
|
36
|
+
const [ownRuntimeDesc, setOwnRuntimeDesc] = useState();
|
|
37
|
+
const runtimeDesc = isControlled ? props.runtimeDesc : ownRuntimeDesc;
|
|
38
|
+
const setRuntimeDesc = useCallback((desc) => {
|
|
39
|
+
if (!isControlled) {
|
|
40
|
+
setOwnRuntimeDesc(desc ? { ...desc } : undefined);
|
|
41
|
+
}
|
|
42
|
+
props.setRuntimeDesc?.(desc);
|
|
43
|
+
}, [isControlled, props.setRuntimeDesc]);
|
|
44
|
+
const [groupedRuntimeDescs, setGroupedRuntimeDescs] = useState(getGroupedCodeSandboxDescs(multiServiceManager, preference?.id, translator, filterRuntime, variant));
|
|
27
45
|
const trans = useMemo(() => (translator ?? nullTranslator).load('jupyterlab'), [translator]);
|
|
28
46
|
const [defaultSet, setDefaultSet] = useState(false);
|
|
29
47
|
const [remoteModelsReady, setRemoteModelsReady] = useState(!multiServiceManager.remote);
|
|
@@ -38,7 +56,7 @@ export function CodeSandboxPicker(props) {
|
|
|
38
56
|
if (disposed) {
|
|
39
57
|
return;
|
|
40
58
|
}
|
|
41
|
-
setGroupedRuntimeDescs(
|
|
59
|
+
setGroupedRuntimeDescs(getGroupedCodeSandboxDescs(multiServiceManager, preference?.id, translator, filterRuntime, variant));
|
|
42
60
|
};
|
|
43
61
|
const refreshRuntimeModels = multiServiceManager.remote?.runtimesManager.refreshRuntimeModels?.();
|
|
44
62
|
if (refreshRuntimeModels) {
|
|
@@ -80,6 +98,15 @@ export function CodeSandboxPicker(props) {
|
|
|
80
98
|
multiServiceManager.remote?.environments.changed.disconnect(updateGroupedRuntimeDescs);
|
|
81
99
|
};
|
|
82
100
|
}, [multiServiceManager, preference?.id, translator, filterRuntime, variant]);
|
|
101
|
+
/*
|
|
102
|
+
* The sandbox the session already runs on, shown as chosen.
|
|
103
|
+
*
|
|
104
|
+
* Preferably the very row of the list, so the choice is visibly one of
|
|
105
|
+
* them. A session whose sandbox is not listed — the list may leave the
|
|
106
|
+
* current one out, and the remote ones land late — is named from the
|
|
107
|
+
* specifications instead, so the picker still opens on what is running
|
|
108
|
+
* rather than on nothing.
|
|
109
|
+
*/
|
|
83
110
|
useEffect(() => {
|
|
84
111
|
if (defaultSet) {
|
|
85
112
|
return;
|
|
@@ -96,8 +123,24 @@ export function CodeSandboxPicker(props) {
|
|
|
96
123
|
}
|
|
97
124
|
});
|
|
98
125
|
});
|
|
99
|
-
if (!matched
|
|
100
|
-
|
|
126
|
+
if (!matched) {
|
|
127
|
+
if (!remoteModelsReady) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const kernelName = sessionContext.session?.kernel?.name;
|
|
131
|
+
const spec = kernelName
|
|
132
|
+
? sessionContext.specsManager.specs?.kernelspecs[kernelName]
|
|
133
|
+
: undefined;
|
|
134
|
+
if (spec) {
|
|
135
|
+
setRuntimeDesc({
|
|
136
|
+
name: spec.name,
|
|
137
|
+
kernelId,
|
|
138
|
+
language: spec.language,
|
|
139
|
+
displayName: sessionContext.kernelDisplayName,
|
|
140
|
+
location: sessionContext.location ??
|
|
141
|
+
'local',
|
|
142
|
+
});
|
|
143
|
+
}
|
|
101
144
|
}
|
|
102
145
|
}
|
|
103
146
|
}
|
|
@@ -109,55 +152,145 @@ export function CodeSandboxPicker(props) {
|
|
|
109
152
|
sessionContext,
|
|
110
153
|
setRuntimeDesc,
|
|
111
154
|
]);
|
|
155
|
+
/*
|
|
156
|
+
* What a NEW sandbox costs, and the answer the host is given.
|
|
157
|
+
*
|
|
158
|
+
* Only asked when the host wants them: a cell picking among the sandboxes
|
|
159
|
+
* that already run has neither a reservation to make nor an answer to
|
|
160
|
+
* shape. The arithmetic is the launcher's, from its own module.
|
|
161
|
+
*/
|
|
162
|
+
const { refreshCredits } = useIAMStore();
|
|
163
|
+
const [timeLimit, setTimeLimit] = useState(10);
|
|
164
|
+
const [userStorage, setUserStorage] = useState(false);
|
|
165
|
+
const asksForNewSandbox = withNewSandboxControls || !!onTransferChange;
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (asksForNewSandbox) {
|
|
168
|
+
refreshCredits();
|
|
169
|
+
}
|
|
170
|
+
}, [asksForNewSandbox]);
|
|
171
|
+
const resolvedBurningRate = runtimeDesc?.burningRate ??
|
|
172
|
+
multiServiceManager.remote?.environments
|
|
173
|
+
.get()
|
|
174
|
+
.find(env => env.name === runtimeDesc?.name)?.burning_rate;
|
|
175
|
+
const allowance = useNewCodeSandboxAllowance(resolvedBurningRate);
|
|
176
|
+
const isNewSandbox = !!runtimeDesc && !runtimeDesc.kernelId;
|
|
177
|
+
const effectiveMaxMinutes = runtimeDesc?.location === 'remote'
|
|
178
|
+
? allowance.effectiveMaxMinutes
|
|
179
|
+
: Math.max(1, allowance.maxFromCredits ?? -1);
|
|
180
|
+
const outOfCredits = allowance.hasKnownCredits &&
|
|
181
|
+
allowance.hasKnownRunAllowance &&
|
|
182
|
+
!allowance.hasRemainingRuns &&
|
|
183
|
+
(allowance.maxFromCredits ?? -1) < Number.EPSILON;
|
|
184
|
+
const variables = useCodeSandboxVariablesTransfer(sessionContext, runtimeDesc, withVariablesTransfer);
|
|
185
|
+
const selectedVariables = variables.selected;
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
if (!onTransferChange) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const maxMinutes = runtimeDesc?.location === 'remote' ? allowance.maxFromCredits : undefined;
|
|
191
|
+
const effectiveTimeLimit = runtimeDesc?.location === 'remote'
|
|
192
|
+
? Math.max(1, Math.min(timeLimit, maxMinutes && maxMinutes > 0 ? maxMinutes : 10))
|
|
193
|
+
: timeLimit;
|
|
194
|
+
const creditsLimit = runtimeDesc?.location === 'remote' && resolvedBurningRate
|
|
195
|
+
? creditsLimitFor(effectiveTimeLimit, resolvedBurningRate)
|
|
196
|
+
: undefined;
|
|
197
|
+
// A new remote sandbox that the account cannot pay for is no answer at
|
|
198
|
+
// all: the dialog is left with nothing to assign rather than with a
|
|
199
|
+
// start that would be refused.
|
|
200
|
+
if (isNewSandbox && runtimeDesc?.location === 'remote') {
|
|
201
|
+
if (!resolvedBurningRate || !Number.isFinite(resolvedBurningRate)) {
|
|
202
|
+
onTransferChange({ runtime: null, selectedVariables });
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (allowance.hasKnownCredits &&
|
|
206
|
+
allowance.hasKnownRunAllowance &&
|
|
207
|
+
!allowance.hasRemainingRuns &&
|
|
208
|
+
(!creditsLimit || creditsLimit <= 0)) {
|
|
209
|
+
onTransferChange({ runtime: null, selectedVariables });
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
onTransferChange({
|
|
214
|
+
runtime: runtimeDesc
|
|
215
|
+
? {
|
|
216
|
+
environmentName: ['browser', 'remote'].includes(runtimeDesc.location)
|
|
217
|
+
? `${runtimeDesc.location}-${runtimeDesc.name}`
|
|
218
|
+
: runtimeDesc.name,
|
|
219
|
+
id: runtimeDesc.kernelId,
|
|
220
|
+
creditsLimit,
|
|
221
|
+
capabilities: userStorage ? ['user_storage'] : undefined,
|
|
222
|
+
}
|
|
223
|
+
: null,
|
|
224
|
+
selectedVariables,
|
|
225
|
+
});
|
|
226
|
+
}, [
|
|
227
|
+
allowance,
|
|
228
|
+
isNewSandbox,
|
|
229
|
+
onTransferChange,
|
|
230
|
+
resolvedBurningRate,
|
|
231
|
+
runtimeDesc,
|
|
232
|
+
selectedVariables,
|
|
233
|
+
timeLimit,
|
|
234
|
+
userStorage,
|
|
235
|
+
]);
|
|
112
236
|
// For cell using submenu instead of group would be nice unfortunately the feature
|
|
113
237
|
// is not yet implemented in the component there has been a not-great demo story.
|
|
114
238
|
// https://github.com/primer/react/pull/3585
|
|
115
|
-
return (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
239
|
+
return (_jsxs(_Fragment, { children: [display === 'menu' ? (
|
|
240
|
+
/*
|
|
241
|
+
* Section for Menu display.
|
|
242
|
+
*/
|
|
243
|
+
_jsxs(ActionMenu, { children: [variant === 'cell' ? (_jsx(ActionMenu.Anchor, { children: _jsx(IconButton, { disabled: disabled || groupedRuntimeDescs === null,
|
|
244
|
+
// icon={() => <kernelIcon.react className="dla-Cell-runtime-icon" tag={'span'} />}
|
|
245
|
+
icon: () => (_jsx("span", { className: "dla-Cell-runtime-icon", children: _jsx(CpuIcon, {}) })), "aria-label": trans.__('Assign a Runtime to the Cell.'), title: trans.__('Assign a Runtime to the Cell.'), size: "small", variant: "invisible" }) })) : (_jsxs(ActionMenu.Button, { variant: "default", disabled: disabled || groupedRuntimeDescs === null, children: [_jsx(Text, { fontWeight: 'bold', children: trans.__('Runtime:') }), ' ' + (runtimeDesc?.displayName ?? trans.__('No Runtime'))] })), _jsx(ActionMenu.Overlay, { ...overlayProps, width: "medium", sx: { overflowY: 'auto' }, side: variant === 'cell' ? 'outside-left' : 'outside-right', children: _jsxs(ActionList, { selectionVariant: "single", children: [variant === 'cell' && (_jsxs(ActionList.Item, { selected: runtimeDesc === undefined, onSelect: () => {
|
|
246
|
+
setRuntimeDesc(undefined);
|
|
247
|
+
}, children: [preference?.location && (_jsx(ActionList.LeadingVisual, { children: preference.location === 'local' ? (_jsx(LaptopSimpleIcon, {})) : preference.location === 'browser' ? (_jsx(BrowserIcon, {})) : (_jsx(CloudUploadIcon, {})) })), trans.__('Assign the Notebook Runtime')] }, 'null')), !!preActions && preActions, Object.entries(groupedRuntimeDescs ?? {}).map(([group, runtimeDescs]) => (_jsxs(ActionList.Group, { children: [_jsx(ActionList.GroupHeading, { children: group }), runtimeDescs.map(candidateRuntimeDesc => {
|
|
248
|
+
const annotation = candidateRuntimeDesc.podName
|
|
249
|
+
? ` - ${candidateRuntimeDesc.podName.split('-', 2).reverse()[0]}`
|
|
250
|
+
: candidateRuntimeDesc.kernelId
|
|
251
|
+
? ` - ${candidateRuntimeDesc.kernelId}`
|
|
252
|
+
: '';
|
|
253
|
+
const fullDisplayName = (candidateRuntimeDesc.displayName ?? '') + annotation;
|
|
254
|
+
const displayName = (candidateRuntimeDesc.displayName?.length ?? 0) >
|
|
255
|
+
RUNTIME_DISPLAY_NAME_MAX_LENGTH
|
|
256
|
+
? candidateRuntimeDesc.displayName.slice(0, RUNTIME_DISPLAY_NAME_MAX_LENGTH) + '…'
|
|
257
|
+
: (candidateRuntimeDesc.displayName ?? '');
|
|
258
|
+
return (_jsxs(ActionList.Item, { title: fullDisplayName, selected: (candidateRuntimeDesc.location ===
|
|
259
|
+
runtimeDesc?.location ||
|
|
260
|
+
(isRuntimeRemote(candidateRuntimeDesc.location) &&
|
|
261
|
+
isRuntimeRemote(runtimeDesc?.location ?? 'local'))) &&
|
|
262
|
+
(candidateRuntimeDesc.kernelId ??
|
|
263
|
+
candidateRuntimeDesc.name) ===
|
|
264
|
+
(runtimeDesc?.kernelId ?? runtimeDesc?.name), onSelect: () => {
|
|
265
|
+
setRuntimeDesc(candidateRuntimeDesc);
|
|
266
|
+
}, children: [_jsx(ActionList.LeadingVisual, { children: candidateRuntimeDesc.location === 'local' ? (_jsx(LaptopSimpleIcon, {})) : candidateRuntimeDesc.location === 'browser' ? (_jsx(BrowserIcon, {})) : (_jsx(CloudUploadIcon, {})) }), displayName + annotation.slice(0, 10)] }, candidateRuntimeDesc.name));
|
|
267
|
+
})] }, group))), !!postActions && (_jsxs(_Fragment, { children: [_jsx(ActionList.Divider, {}), postActions] }))] }) })] })) : (
|
|
268
|
+
/*
|
|
269
|
+
* Section for Radio display.
|
|
270
|
+
*/
|
|
271
|
+
_jsxs(_Fragment, { children: [defaultSet && (_jsx(RadioGroup, { name: "kernel-options", "aria-labelledby": "kernel-options", children: Object.entries(groupedRuntimeDescs ?? {}).map(([group, runtimeDescs]) => (_jsxs(Box, { children: [_jsx(Box, { as: "h4", style: { marginTop: 0 }, children: group }), runtimeDescs.map(k => {
|
|
272
|
+
return (
|
|
273
|
+
// A kernel identifies a runtime that already runs; an
|
|
274
|
+
// environment to start one in has none, and is named
|
|
275
|
+
// by where it runs and what it runs.
|
|
276
|
+
_jsxs(Box, { title: k.name, children: [_jsxs(FormControl, { children: [_jsx(Radio, { value: k.kernelId, onChange: () => {
|
|
277
|
+
setRuntimeDesc(k);
|
|
278
|
+
}, checked: (k.location === runtimeDesc?.location ||
|
|
279
|
+
(isRuntimeRemote(k.location) &&
|
|
280
|
+
isRuntimeRemote(runtimeDesc?.location ?? 'local'))) &&
|
|
281
|
+
(k.kernelId ?? k.name) ===
|
|
282
|
+
(runtimeDesc?.kernelId ?? runtimeDesc?.name) }), _jsx(FormControl.Label, { children: _jsxs(Box, { display: "flex", children: [_jsx(Box, { children: k.displayName }), k.kernelId && k.location === 'remote' && (_jsx(Box, { ml: 3, mt: 1, children: _jsx(CreditsIndicator, { kernelId: k.kernelId, serviceManager: multiServiceManager.remote }, "credits-indicator") }))] }) }), _jsx(FormControl.Caption, { children: _jsxs(LabelGroup, { sx: { marginTop: 1 }, children: [_jsx(Label, { variant: "secondary", children: k.name }), _jsx(Label, { variant: "secondary", sx: { marginLeft: 1 }, children: k.location }), k.burningRate && (_jsxs(Label, { variant: "sponsors", sx: { marginLeft: 1 }, children: [k.burningRate, " credits/second"] })), k.gpu && (_jsx(Label, { variant: "success", sx: { marginLeft: 1 }, children: "GPU" }))] }) })] }), _jsx(ActionList.Divider, {})] }, `${k.location}:${k.kernelId ?? k.name}`));
|
|
283
|
+
})] }, group))) })), !!postActions && _jsx(_Fragment, { children: postActions })] })), withNewSandboxControls && isNewSandbox && (
|
|
284
|
+
// The user asked for a NEW sandbox: the questions are the launcher's,
|
|
285
|
+
// asked through the launcher's own controls. A sandbox of this page
|
|
286
|
+
// or of this server reserves nothing, so only the time of a remote
|
|
287
|
+
// one is asked for.
|
|
288
|
+
_jsx(NewCodeSandboxControls, { withReservation: runtimeDesc?.location === 'remote', burningRate: resolvedBurningRate, timeLimit: timeLimit, onTimeChange: setTimeLimit, max: effectiveMaxMinutes, disabled: outOfCredits, error: runtimeDesc?.location !== 'remote'
|
|
289
|
+
? undefined
|
|
290
|
+
: outOfCredits && (allowance.maxFromCredits ?? -1) >= 0
|
|
291
|
+
? 'You must add credits to your account.'
|
|
292
|
+
: timeLimit === 0
|
|
293
|
+
? 'You must set a time limit.'
|
|
294
|
+
: undefined, userStorage: userStorage, onUserStorageToggle: () => setUserStorage(current => !current) })), variables.available && (_jsx(CodeSandboxVariables, { selectedVariables: variables.selected, setSelectVariable: variables.setSelected, transferVariables: variables.transfer, setTransferVariable: variables.setTransfer, kernelVariables: variables.variables, translator: translator }))] }));
|
|
160
295
|
}
|
|
161
|
-
// Backward-compatible aliases (deprecated: use CodeSandboxPicker).
|
|
162
|
-
export const RuntimePickerBase = CodeSandboxPicker;
|
|
163
296
|
export default CodeSandboxPicker;
|
package/lib/components/{runtimes/RuntimePickerCell.d.ts → code-sandboxes/CodeSandboxPickerCell.d.ts}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ISessionContext } from '@jupyterlab/apputils';
|
|
2
2
|
import { CodeCellModel } from '@jupyterlab/cells';
|
|
3
3
|
import type { IMarkdownParser, IRenderMime } from '@jupyterlab/rendermime';
|
|
4
|
-
import { type ICodeSandboxPickerProps } from '
|
|
4
|
+
import { type ICodeSandboxPickerProps } from './CodeSandboxPicker';
|
|
5
5
|
/**
|
|
6
|
-
* {@link
|
|
6
|
+
* {@link CodeSandboxPickerCell} properties
|
|
7
7
|
*/
|
|
8
|
-
export type
|
|
8
|
+
export type ICodeSandboxPickerCellProps = Pick<ICodeSandboxPickerProps, 'multiServiceManager' | 'preference' | 'translator'> & {
|
|
9
9
|
/**
|
|
10
10
|
* Callback to allow the user to login
|
|
11
11
|
*/
|
|
@@ -30,5 +30,5 @@ export type IRuntimePickerCellProps = Pick<ICodeSandboxPickerProps, 'multiServic
|
|
|
30
30
|
/**
|
|
31
31
|
* Runtime picker component for a cell.
|
|
32
32
|
*/
|
|
33
|
-
export declare function
|
|
34
|
-
export default
|
|
33
|
+
export declare function CodeSandboxPickerCell(props: ICodeSandboxPickerCellProps): JSX.Element;
|
|
34
|
+
export default CodeSandboxPickerCell;
|
package/lib/components/{runtimes/RuntimePickerCell.js → code-sandboxes/CodeSandboxPickerCell.js}
RENAMED
|
@@ -12,13 +12,13 @@ import { isRuntimeRemote } from '../../runtimes';
|
|
|
12
12
|
import { RuntimeSnippetsFacade } from '../../jupyter';
|
|
13
13
|
import { ExternalTokenSilentLogin } from '@datalayer/core/lib/components/iam';
|
|
14
14
|
import { SnippetDialog } from '../../components/snippets/SnippetDialog';
|
|
15
|
-
import { CodeSandboxPicker, } from '
|
|
16
|
-
import { CodeSandboxLauncher } from '
|
|
17
|
-
import {
|
|
15
|
+
import { CodeSandboxPicker, } from './CodeSandboxPicker';
|
|
16
|
+
import { CodeSandboxLauncher } from './CodeSandboxLauncher';
|
|
17
|
+
import { CodeSandboxCellVariablesDialog } from './CodeSandboxCellVariablesDialog';
|
|
18
18
|
/**
|
|
19
19
|
* Runtime picker component for a cell.
|
|
20
20
|
*/
|
|
21
|
-
export function
|
|
21
|
+
export function CodeSandboxPickerCell(props) {
|
|
22
22
|
const { logIn, markdownParser, model, preference, sanitizer, multiServiceManager, sessionContext, translator, } = props;
|
|
23
23
|
const { token } = useIAMStore();
|
|
24
24
|
const { configuration } = useCoreStore();
|
|
@@ -99,6 +99,6 @@ export function RuntimePickerCell(props) {
|
|
|
99
99
|
const datalayerMeta = model.getMetadata('datalayer') ?? {};
|
|
100
100
|
return (_jsxs(_Fragment, { children: [_jsx(CodeSandboxPicker, { display: "menu", filterRuntime: filterKernel, preference: preference, multiServiceManager: multiServiceManager, runtimeDesc: datalayerMeta.kernel ? datalayerMeta.kernel : undefined, setRuntimeDesc: setSelectedRuntimeDesc, variant: 'cell', preActions: _jsxs(ActionList.Item, { disabled: !multiServiceManager.remote, onSelect: setCell, selected: hasCellRuntime, title: !multiServiceManager.remote
|
|
101
101
|
? 'You are not connected with Datalayer.'
|
|
102
|
-
: 'Assign a new temporary Runtime on each Cell execution.', children: [_jsx(ActionList.LeadingVisual, { children: _jsx(CloudUploadIcon, {}) }), trans.__('Assign a Cell Runtime')] }), postActions: token || !logIn ? (_jsxs(_Fragment, { children: [RuntimeSnippetsFacade.supports(preference?.language ?? '') && (_jsx(ActionList.Item, { onSelect: openVariableDialog, disabled: !isForeign, title: trans.__('Define variables to transfer between the document kernel and the cell kernel.'), children: trans.__('Define Cell Variables Transfer') })), !configuration.whiteLabel && (_jsx(ActionList.Item, { onSelect: openSnippetDialog, disabled: snippets.length === 0, title: trans.__('Inject a code snippet at the end of the cell.'), children: trans.__('Inject Code Snippet') }))] })) : (_jsx(ActionList.Item, { onSelect: props.logIn, title: 'Runtime Provider.', children: _jsx(ExternalTokenSilentLogin, { message: "Click to sign in" }) })), translator: translator }), isVariableDialogOpen && (_jsx(
|
|
102
|
+
: 'Assign a new temporary Runtime on each Cell execution.', children: [_jsx(ActionList.LeadingVisual, { children: _jsx(CloudUploadIcon, {}) }), trans.__('Assign a Cell Runtime')] }), postActions: token || !logIn ? (_jsxs(_Fragment, { children: [RuntimeSnippetsFacade.supports(preference?.language ?? '') && (_jsx(ActionList.Item, { onSelect: openVariableDialog, disabled: !isForeign, title: trans.__('Define variables to transfer between the document kernel and the cell kernel.'), children: trans.__('Define Cell Variables Transfer') })), !configuration.whiteLabel && (_jsx(ActionList.Item, { onSelect: openSnippetDialog, disabled: snippets.length === 0, title: trans.__('Inject a code snippet at the end of the cell.'), children: trans.__('Inject Code Snippet') }))] })) : (_jsx(ActionList.Item, { onSelect: props.logIn, title: 'Runtime Provider.', children: _jsx(ExternalTokenSilentLogin, { message: "Click to sign in" }) })), translator: translator }), isVariableDialogOpen && (_jsx(CodeSandboxCellVariablesDialog, { model: model, onClose: closeVariableDialog, preference: preference, sessionContext: sessionContext, translator: translator })), isSnippetDialogOpen && (_jsx(SnippetDialog, { language: language, model: model, snippets: snippets, onClose: closeSnippetDialog, markdownParser: markdownParser, sanitizer: sanitizer })), isKernelDialogOpen && (_jsx(CodeSandboxLauncher, { manager: multiServiceManager.remote, onSubmit: onStartRemote, startRuntime: 'defer', submitLabel: "Assign", markdownParser: markdownParser, sanitizer: sanitizer }))] }));
|
|
103
103
|
}
|
|
104
|
-
export default
|
|
104
|
+
export default CodeSandboxPickerCell;
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* TODO this should be configurable
|
|
5
5
|
*/
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const MAXIMAL_CODE_SANDBOX_TIME_RESERVATION_MINUTES: number;
|
|
7
7
|
/**
|
|
8
8
|
* Time control properties
|
|
9
9
|
*/
|
|
10
|
-
export interface
|
|
10
|
+
export interface ICodeSandboxReservationControlProps {
|
|
11
11
|
/**
|
|
12
12
|
* Callback on add credits button
|
|
13
13
|
*/
|
|
@@ -44,4 +44,4 @@ export interface IKernelReservationControlProps {
|
|
|
44
44
|
/**
|
|
45
45
|
* Runtime reservation control
|
|
46
46
|
*/
|
|
47
|
-
export declare function
|
|
47
|
+
export declare function CodeSandboxReservationControl(props: ICodeSandboxReservationControlProps): JSX.Element;
|