@datalayer/core 0.0.19 → 0.0.21
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/App.js +0 -5
- package/lib/api/iam/datasources.d.ts +86 -0
- package/lib/api/iam/datasources.js +185 -0
- package/lib/api/iam/index.d.ts +2 -0
- package/lib/api/iam/index.js +2 -0
- package/lib/api/iam/secrets.d.ts +85 -0
- package/lib/api/iam/secrets.js +196 -0
- package/lib/client/auth/storage.js +17 -62
- package/lib/client/base.d.ts +3 -0
- package/lib/client/base.js +2 -2
- package/lib/client/index.d.ts +82 -3
- package/lib/client/index.js +5 -1
- package/lib/client/mixins/IAMMixin.d.ts +62 -0
- package/lib/client/mixins/IAMMixin.js +116 -0
- package/lib/collaboration/DatalayerCollaboration.d.ts +1 -2
- package/lib/collaboration/DatalayerCollaborationProvider.d.ts +1 -1
- package/lib/collaboration/DatalayerCollaborationProvider.js +1 -1
- package/lib/components/auth/Login.js +0 -5
- package/lib/components/auth/index.js +1 -6
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -1
- package/lib/components/toolbars/AssignmentEditorToolbar.js +9 -7
- package/lib/examples/CellExample.js +4 -3
- package/lib/examples/NotebookExample.js +2 -7
- package/lib/hooks/index.d.ts +0 -2
- package/lib/hooks/index.js +0 -2
- package/lib/hooks/useBackdrop.d.ts +2 -3
- package/lib/hooks/useBackdropJupyterLab.d.ts +2 -2
- package/lib/hooks/useCache.d.ts +18 -4
- package/lib/hooks/useCache.js +87 -69
- package/lib/hooks/useScreenshot.d.ts +2 -3
- package/lib/hooks/useWindowSize.d.ts +1 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -2
- package/lib/main.js +4 -1
- package/lib/models/Datasource.d.ts +170 -0
- package/lib/models/Datasource.js +140 -0
- package/lib/models/Runtime.d.ts +1 -1
- package/lib/models/RuntimeSnapshotDTO.d.ts +1 -1
- package/lib/models/RuntimeSnapshotDTO.js +1 -1
- package/lib/models/Secret.d.ts +159 -0
- package/lib/models/Secret.js +135 -0
- package/lib/models/SpaceDTO.d.ts +0 -11
- package/lib/models/index.d.ts +0 -1
- package/lib/models/index.js +0 -1
- package/lib/state/substates/IAMState.d.ts +1 -1
- package/lib/state/substates/LayoutState.d.ts +2 -2
- package/lib/state/substates/NbformatState.d.ts +1 -1
- package/lib/state/substates/index.d.ts +0 -1
- package/lib/state/substates/index.js +0 -1
- package/lib/utils/File.d.ts +1 -1
- package/lib/utils/File.js +1 -1
- package/lib/utils/Notebook.d.ts +5 -3
- package/lib/utils/Notebook.js +5 -3
- package/lib/utils/cli/index.js +0 -5
- package/lib/utils/cli/query.js +0 -5
- package/lib/views/datasources/DatasourceDetail.d.ts +2 -0
- package/lib/views/datasources/DatasourceDetail.js +91 -0
- package/lib/views/datasources/DatasourceNew.d.ts +2 -0
- package/lib/views/datasources/DatasourceNew.js +118 -0
- package/lib/views/datasources/Datasources.d.ts +2 -0
- package/lib/views/datasources/Datasources.js +49 -0
- package/lib/views/datasources/index.d.ts +3 -0
- package/lib/views/datasources/index.js +7 -0
- package/lib/views/iam-tokens/IAMTokenEdit.d.ts +2 -0
- package/lib/views/iam-tokens/IAMTokenEdit.js +86 -0
- package/lib/views/iam-tokens/IAMTokenNew.d.ts +2 -0
- package/lib/views/iam-tokens/IAMTokenNew.js +118 -0
- package/lib/views/iam-tokens/IAMTokens.d.ts +2 -0
- package/lib/views/iam-tokens/IAMTokens.js +53 -0
- package/lib/views/iam-tokens/Tokens.d.ts +2 -0
- package/lib/views/iam-tokens/Tokens.js +53 -0
- package/lib/views/iam-tokens/index.d.ts +3 -0
- package/lib/views/iam-tokens/index.js +7 -0
- package/lib/views/index.d.ts +1 -0
- package/lib/views/secrets/SecretEdit.d.ts +2 -0
- package/lib/views/secrets/SecretEdit.js +149 -0
- package/lib/views/secrets/SecretNew.d.ts +2 -0
- package/lib/views/secrets/SecretNew.js +99 -0
- package/lib/views/secrets/Secrets.d.ts +2 -0
- package/lib/views/secrets/Secrets.js +48 -0
- package/lib/views/secrets/index.d.ts +3 -0
- package/lib/views/secrets/index.js +7 -0
- package/package.json +15 -16
- package/patches/.gitkeep +1 -0
- package/patches/@datalayer+jupyter-lexical+1.0.7.patch +5491 -0
- package/patches/@datalayer+jupyter-react+2.0.1.patch +2674 -0
- package/scripts/apply-patches.sh +44 -0
- package/scripts/create-patches.sh +40 -0
- package/scripts/fix-esm-imports.cjs +124 -0
- package/scripts/sync-jupyter.sh +121 -0
- package/lib/components/chat/ChatComponent.d.ts +0 -4
- package/lib/components/chat/ChatComponent.js +0 -143
- package/lib/components/chat/MessagePart.d.ts +0 -11
- package/lib/components/chat/MessagePart.js +0 -23
- package/lib/components/chat/display/DynamicToolPart.d.ts +0 -6
- package/lib/components/chat/display/DynamicToolPart.js +0 -5
- package/lib/components/chat/display/ReasoningPart.d.ts +0 -6
- package/lib/components/chat/display/ReasoningPart.js +0 -58
- package/lib/components/chat/display/TextPart.d.ts +0 -9
- package/lib/components/chat/display/TextPart.js +0 -93
- package/lib/components/chat/display/ToolPart.d.ts +0 -6
- package/lib/components/chat/display/ToolPart.js +0 -148
- package/lib/components/chat/display/index.d.ts +0 -4
- package/lib/components/chat/display/index.js +0 -13
- package/lib/components/chat/handler.d.ts +0 -8
- package/lib/components/chat/handler.js +0 -43
- package/lib/components/chat/index.d.ts +0 -4
- package/lib/components/chat/index.js +0 -13
- package/lib/hooks/useAIAgents.d.ts +0 -13
- package/lib/hooks/useAIAgents.js +0 -72
- package/lib/hooks/useAIJupyterChat.d.ts +0 -36
- package/lib/hooks/useAIJupyterChat.js +0 -53
- package/lib/hooks/useNotebookAIAgent.d.ts +0 -8
- package/lib/hooks/useNotebookAIAgent.js +0 -56
- package/lib/models/AIAgent.d.ts +0 -17
- package/lib/state/substates/AIAgentState.d.ts +0 -11
- package/lib/state/substates/AIAgentState.js +0 -42
- package/lib/tools/adapters/agui/AgUIToolAdapter.d.ts +0 -75
- package/lib/tools/adapters/agui/AgUIToolAdapter.js +0 -244
- package/lib/tools/adapters/agui/index.d.ts +0 -10
- package/lib/tools/adapters/agui/index.js +0 -19
- package/lib/tools/adapters/agui/lexicalHooks.d.ts +0 -27
- package/lib/tools/adapters/agui/lexicalHooks.js +0 -64
- package/lib/tools/adapters/agui/notebookHooks.d.ts +0 -27
- package/lib/tools/adapters/agui/notebookHooks.js +0 -61
- package/lib/tools/index.d.ts +0 -6
- package/lib/tools/index.js +0 -18
- package/lib/{models/AIAgent.js → views/index.js} +1 -1
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Text, IconButton } from '@primer/react';
|
|
3
|
-
import { Box } from '@datalayer/primer-addons';
|
|
4
|
-
import { CopyIcon, SyncIcon } from '@primer/octicons-react';
|
|
5
|
-
import { Streamdown } from 'streamdown';
|
|
6
|
-
export function TextPart({ text, message, isLastPart, onRegenerate, }) {
|
|
7
|
-
const copy = (text) => {
|
|
8
|
-
navigator.clipboard.writeText(text).catch((error) => {
|
|
9
|
-
console.error('Error copying text:', error);
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
return (_jsxs(Box, { sx: {
|
|
13
|
-
padding: 3,
|
|
14
|
-
borderRadius: 2,
|
|
15
|
-
backgroundColor: message.role === 'user' ? 'accent.subtle' : 'canvas.subtle',
|
|
16
|
-
marginBottom: 2,
|
|
17
|
-
}, children: [_jsxs(Box, { sx: {
|
|
18
|
-
display: 'flex',
|
|
19
|
-
justifyContent: 'space-between',
|
|
20
|
-
alignItems: 'flex-start',
|
|
21
|
-
marginBottom: 2,
|
|
22
|
-
}, children: [_jsx(Text, { sx: {
|
|
23
|
-
fontWeight: 'bold',
|
|
24
|
-
fontSize: 1,
|
|
25
|
-
color: 'fg.muted',
|
|
26
|
-
textTransform: 'uppercase',
|
|
27
|
-
}, children: message.role === 'user' ? 'You' : 'Assistant' }), message.role === 'assistant' && isLastPart && (_jsxs(Box, { sx: { display: 'flex', gap: 1 }, children: [_jsx(IconButton, { icon: SyncIcon, "aria-label": "Regenerate", size: "small", variant: "invisible", onClick: () => onRegenerate(message.id) }), _jsx(IconButton, { icon: CopyIcon, "aria-label": "Copy", size: "small", variant: "invisible", onClick: () => copy(text) })] }))] }), _jsx(Box, { sx: {
|
|
28
|
-
fontSize: 1,
|
|
29
|
-
lineHeight: 1.6,
|
|
30
|
-
'& > *:first-child': { marginTop: 0 },
|
|
31
|
-
'& > *:last-child': { marginBottom: 0 },
|
|
32
|
-
'& p': { marginTop: 0, marginBottom: '1em' },
|
|
33
|
-
'& h1, & h2, & h3, & h4, & h5, & h6': {
|
|
34
|
-
marginTop: '1em',
|
|
35
|
-
marginBottom: '0.5em',
|
|
36
|
-
fontWeight: 'bold',
|
|
37
|
-
},
|
|
38
|
-
'& ul, & ol': {
|
|
39
|
-
marginTop: '0.5em',
|
|
40
|
-
marginBottom: '0.5em',
|
|
41
|
-
paddingLeft: '1.5em',
|
|
42
|
-
},
|
|
43
|
-
'& code': {
|
|
44
|
-
backgroundColor: 'neutral.muted',
|
|
45
|
-
padding: '2px 4px',
|
|
46
|
-
borderRadius: 1,
|
|
47
|
-
fontSize: '0.9em',
|
|
48
|
-
fontFamily: 'mono',
|
|
49
|
-
},
|
|
50
|
-
'& pre': {
|
|
51
|
-
backgroundColor: 'canvas.inset',
|
|
52
|
-
padding: 3,
|
|
53
|
-
borderRadius: 2,
|
|
54
|
-
overflow: 'auto',
|
|
55
|
-
marginTop: '1em',
|
|
56
|
-
marginBottom: '1em',
|
|
57
|
-
border: '1px solid',
|
|
58
|
-
borderColor: 'border.default',
|
|
59
|
-
},
|
|
60
|
-
'& pre code': {
|
|
61
|
-
backgroundColor: 'transparent',
|
|
62
|
-
padding: 0,
|
|
63
|
-
fontSize: '0.875em',
|
|
64
|
-
},
|
|
65
|
-
'& blockquote': {
|
|
66
|
-
borderLeft: '3px solid',
|
|
67
|
-
borderColor: 'border.default',
|
|
68
|
-
paddingLeft: 3,
|
|
69
|
-
marginLeft: 0,
|
|
70
|
-
color: 'fg.muted',
|
|
71
|
-
},
|
|
72
|
-
'& a': {
|
|
73
|
-
color: 'accent.fg',
|
|
74
|
-
textDecoration: 'underline',
|
|
75
|
-
},
|
|
76
|
-
'& table': {
|
|
77
|
-
width: '100%',
|
|
78
|
-
borderCollapse: 'collapse',
|
|
79
|
-
marginTop: '1em',
|
|
80
|
-
marginBottom: '1em',
|
|
81
|
-
},
|
|
82
|
-
'& th, & td': {
|
|
83
|
-
border: '1px solid',
|
|
84
|
-
borderColor: 'border.default',
|
|
85
|
-
padding: 2,
|
|
86
|
-
textAlign: 'left',
|
|
87
|
-
},
|
|
88
|
-
'& th': {
|
|
89
|
-
backgroundColor: 'canvas.subtle',
|
|
90
|
-
fontWeight: 'bold',
|
|
91
|
-
},
|
|
92
|
-
}, children: _jsx(Streamdown, { children: text }) })] }));
|
|
93
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
|
-
* Distributed under the terms of the Modified BSD License.
|
|
5
|
-
*/
|
|
6
|
-
/*
|
|
7
|
-
* Copyright (c) 2024-2025 Datalayer, Inc.
|
|
8
|
-
*
|
|
9
|
-
* BSD 3-Clause License
|
|
10
|
-
*/
|
|
11
|
-
import React from 'react';
|
|
12
|
-
import { Text, Button } from '@primer/react';
|
|
13
|
-
import { Box } from '@datalayer/primer-addons';
|
|
14
|
-
import { ChevronDownIcon } from '@primer/octicons-react';
|
|
15
|
-
export function ToolPart({ part }) {
|
|
16
|
-
const [isExpanded, setIsExpanded] = React.useState(true);
|
|
17
|
-
const getStatusInfo = (state) => {
|
|
18
|
-
const statusMap = {
|
|
19
|
-
call: { label: 'Pending', color: 'accent.fg', icon: '○' },
|
|
20
|
-
'input-streaming': { label: 'Pending', color: 'accent.fg', icon: '○' },
|
|
21
|
-
'input-available': {
|
|
22
|
-
label: 'Running',
|
|
23
|
-
color: 'attention.fg',
|
|
24
|
-
icon: '⏱',
|
|
25
|
-
},
|
|
26
|
-
executing: { label: 'Running', color: 'attention.fg', icon: '⏱' },
|
|
27
|
-
'output-available': {
|
|
28
|
-
label: 'Completed',
|
|
29
|
-
color: 'success.fg',
|
|
30
|
-
icon: '✓',
|
|
31
|
-
},
|
|
32
|
-
'output-error': { label: 'Error', color: 'danger.fg', icon: '✕' },
|
|
33
|
-
error: { label: 'Error', color: 'danger.fg', icon: '✕' },
|
|
34
|
-
};
|
|
35
|
-
return (statusMap[state] || {
|
|
36
|
-
label: state,
|
|
37
|
-
color: 'fg.muted',
|
|
38
|
-
icon: '•',
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
const statusInfo = getStatusInfo(part.state);
|
|
42
|
-
const toolName = part.type.split('-').slice(1).join('-') || part.type;
|
|
43
|
-
return (_jsxs(Box, { sx: {
|
|
44
|
-
marginBottom: 2,
|
|
45
|
-
border: '1px solid',
|
|
46
|
-
borderColor: 'border.default',
|
|
47
|
-
borderRadius: 2,
|
|
48
|
-
overflow: 'hidden',
|
|
49
|
-
}, children: [_jsxs(Button, { variant: "invisible", onClick: () => setIsExpanded(!isExpanded), sx: {
|
|
50
|
-
width: '100%',
|
|
51
|
-
display: 'flex',
|
|
52
|
-
justifyContent: 'space-between',
|
|
53
|
-
alignItems: 'center',
|
|
54
|
-
padding: 3,
|
|
55
|
-
backgroundColor: 'canvas.subtle',
|
|
56
|
-
border: 'none',
|
|
57
|
-
borderBottom: isExpanded ? '1px solid' : 'none',
|
|
58
|
-
borderColor: 'border.default',
|
|
59
|
-
textAlign: 'left',
|
|
60
|
-
cursor: 'pointer',
|
|
61
|
-
'&:hover': {
|
|
62
|
-
backgroundColor: 'neutral.muted',
|
|
63
|
-
},
|
|
64
|
-
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2 }, children: [_jsx(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: "\uD83D\uDD27" }), _jsx(Text, { sx: { fontSize: 1, fontWeight: 'semibold' }, children: toolName }), _jsxs(Box, { sx: {
|
|
65
|
-
display: 'inline-flex',
|
|
66
|
-
alignItems: 'center',
|
|
67
|
-
gap: 1,
|
|
68
|
-
paddingX: 2,
|
|
69
|
-
paddingY: 1,
|
|
70
|
-
borderRadius: 2,
|
|
71
|
-
backgroundColor: 'neutral.subtle',
|
|
72
|
-
fontSize: 0,
|
|
73
|
-
}, children: [_jsx(Text, { sx: { color: statusInfo.color }, children: statusInfo.icon }), _jsx(Text, { sx: { color: statusInfo.color, fontWeight: 'semibold' }, children: statusInfo.label })] })] }), _jsx(Box, { as: "span", sx: {
|
|
74
|
-
display: 'inline-flex',
|
|
75
|
-
transform: isExpanded ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
76
|
-
transition: 'transform 0.2s',
|
|
77
|
-
}, children: _jsx(ChevronDownIcon, {}) })] }), isExpanded && (_jsxs(Box, { children: [_jsxs(Box, { sx: {
|
|
78
|
-
padding: 3,
|
|
79
|
-
borderBottom: part.state === 'output-available' ||
|
|
80
|
-
part.state === 'output-error'
|
|
81
|
-
? '1px solid'
|
|
82
|
-
: 'none',
|
|
83
|
-
borderColor: 'border.default',
|
|
84
|
-
}, children: [_jsx(Text, { sx: {
|
|
85
|
-
display: 'block',
|
|
86
|
-
fontSize: 0,
|
|
87
|
-
fontWeight: 'semibold',
|
|
88
|
-
color: 'fg.muted',
|
|
89
|
-
textTransform: 'uppercase',
|
|
90
|
-
letterSpacing: '0.05em',
|
|
91
|
-
marginBottom: 2,
|
|
92
|
-
}, children: "Parameters" }), _jsx(Box, { sx: {
|
|
93
|
-
backgroundColor: 'canvas.inset',
|
|
94
|
-
borderRadius: 2,
|
|
95
|
-
overflow: 'auto',
|
|
96
|
-
border: '1px solid',
|
|
97
|
-
borderColor: 'border.default',
|
|
98
|
-
}, children: _jsx("pre", { style: {
|
|
99
|
-
margin: 0,
|
|
100
|
-
padding: '12px',
|
|
101
|
-
fontSize: '12px',
|
|
102
|
-
fontFamily: 'monospace',
|
|
103
|
-
lineHeight: 1.5,
|
|
104
|
-
overflow: 'auto',
|
|
105
|
-
}, children: JSON.stringify(part.input, null, 2) }) })] }), part.state === 'output-available' && (_jsxs(Box, { sx: { padding: 3 }, children: [_jsx(Text, { sx: {
|
|
106
|
-
display: 'block',
|
|
107
|
-
fontSize: 0,
|
|
108
|
-
fontWeight: 'semibold',
|
|
109
|
-
color: 'fg.muted',
|
|
110
|
-
textTransform: 'uppercase',
|
|
111
|
-
letterSpacing: '0.05em',
|
|
112
|
-
marginBottom: 2,
|
|
113
|
-
}, children: "Result" }), _jsx(Box, { sx: {
|
|
114
|
-
backgroundColor: 'canvas.default',
|
|
115
|
-
borderRadius: 2,
|
|
116
|
-
overflow: 'auto',
|
|
117
|
-
border: '1px solid',
|
|
118
|
-
borderColor: 'border.default',
|
|
119
|
-
}, children: _jsx("pre", { style: {
|
|
120
|
-
margin: 0,
|
|
121
|
-
padding: '12px',
|
|
122
|
-
fontSize: '12px',
|
|
123
|
-
fontFamily: 'monospace',
|
|
124
|
-
lineHeight: 1.5,
|
|
125
|
-
overflow: 'auto',
|
|
126
|
-
}, children: part.output
|
|
127
|
-
? typeof part.output === 'string'
|
|
128
|
-
? part.output
|
|
129
|
-
: JSON.stringify(part.output, null, 2)
|
|
130
|
-
: 'No output' }) })] })), part.state === 'output-error' &&
|
|
131
|
-
'errorText' in part &&
|
|
132
|
-
part.errorText && (_jsxs(Box, { sx: { padding: 3 }, children: [_jsx(Text, { sx: {
|
|
133
|
-
display: 'block',
|
|
134
|
-
fontSize: 0,
|
|
135
|
-
fontWeight: 'semibold',
|
|
136
|
-
color: 'danger.fg',
|
|
137
|
-
textTransform: 'uppercase',
|
|
138
|
-
letterSpacing: '0.05em',
|
|
139
|
-
marginBottom: 2,
|
|
140
|
-
}, children: "Error" }), _jsx(Box, { sx: {
|
|
141
|
-
backgroundColor: 'danger.subtle',
|
|
142
|
-
borderRadius: 2,
|
|
143
|
-
overflow: 'auto',
|
|
144
|
-
border: '1px solid',
|
|
145
|
-
borderColor: 'danger.muted',
|
|
146
|
-
padding: 2,
|
|
147
|
-
}, children: _jsx(Text, { sx: { fontSize: 0, color: 'danger.fg' }, children: part.errorText }) })] }))] }))] }));
|
|
148
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
/*
|
|
6
|
-
* Copyright (c) 2024-2025 Datalayer, Inc.
|
|
7
|
-
*
|
|
8
|
-
* BSD 3-Clause License
|
|
9
|
-
*/
|
|
10
|
-
export { TextPart } from './TextPart';
|
|
11
|
-
export { ReasoningPart } from './ReasoningPart';
|
|
12
|
-
export { ToolPart } from './ToolPart';
|
|
13
|
-
export { DynamicToolPart } from './DynamicToolPart';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Call the API extension
|
|
3
|
-
*
|
|
4
|
-
* @param endPoint API REST end point for the extension
|
|
5
|
-
* @param init Initial values for the request
|
|
6
|
-
* @returns The response body interpreted as JSON
|
|
7
|
-
*/
|
|
8
|
-
export declare function requestAPI<T>(endPoint?: string, init?: RequestInit): Promise<T>;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
/*
|
|
6
|
-
* Copyright (c) 2024-2025 Datalayer, Inc.
|
|
7
|
-
*
|
|
8
|
-
* BSD 3-Clause License
|
|
9
|
-
*/
|
|
10
|
-
import { URLExt } from '@jupyterlab/coreutils';
|
|
11
|
-
import { ServerConnection } from '@jupyterlab/services';
|
|
12
|
-
/**
|
|
13
|
-
* Call the API extension
|
|
14
|
-
*
|
|
15
|
-
* @param endPoint API REST end point for the extension
|
|
16
|
-
* @param init Initial values for the request
|
|
17
|
-
* @returns The response body interpreted as JSON
|
|
18
|
-
*/
|
|
19
|
-
export async function requestAPI(endPoint = '', init = {}) {
|
|
20
|
-
// Make request to Jupyter API
|
|
21
|
-
const settings = ServerConnection.makeSettings();
|
|
22
|
-
const requestUrl = URLExt.join(settings.baseUrl, 'datalayer', endPoint);
|
|
23
|
-
let response;
|
|
24
|
-
try {
|
|
25
|
-
response = await ServerConnection.makeRequest(requestUrl, init, settings);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
throw new ServerConnection.NetworkError(error);
|
|
29
|
-
}
|
|
30
|
-
let data = await response.text();
|
|
31
|
-
if (data.length > 0) {
|
|
32
|
-
try {
|
|
33
|
-
data = JSON.parse(data);
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
// Not a JSON response body
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (!response.ok) {
|
|
40
|
-
throw new ServerConnection.ResponseError(response, data.message || data);
|
|
41
|
-
}
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
/*
|
|
6
|
-
* Copyright (c) 2024-2025 Datalayer, Inc.
|
|
7
|
-
*
|
|
8
|
-
* BSD 3-Clause License
|
|
9
|
-
*/
|
|
10
|
-
export * from './ChatComponent';
|
|
11
|
-
export * from './MessagePart';
|
|
12
|
-
export * from './handler';
|
|
13
|
-
export * from './display';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type RequestOptions = {
|
|
2
|
-
signal?: AbortSignal;
|
|
3
|
-
baseUrl?: string;
|
|
4
|
-
};
|
|
5
|
-
export type RoomType = 'notebook_persist' | 'notebook_memory' | 'doc_memory';
|
|
6
|
-
export declare const useAIAgents: (baseUrlOverride?: string) => {
|
|
7
|
-
createAIAgent: (documentId: string, documentType: RoomType, ingress?: string, token?: string, kernelId?: string, { signal, baseUrl }?: RequestOptions) => Promise<any>;
|
|
8
|
-
getAIAgents: ({ signal, baseUrl, }?: RequestOptions) => Promise<any>;
|
|
9
|
-
deleteAIAgent: (documentId: string, { signal, baseUrl }?: RequestOptions) => Promise<any>;
|
|
10
|
-
getAIAgent: (documentId: string, { signal, baseUrl }?: RequestOptions) => Promise<any>;
|
|
11
|
-
patchAIAgent: (documentId: string, ingress?: string, token?: string, kernelId?: string, { signal, baseUrl }?: RequestOptions) => Promise<any>;
|
|
12
|
-
};
|
|
13
|
-
export default useAIAgents;
|
package/lib/hooks/useAIAgents.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
import { URLExt } from '@jupyterlab/coreutils';
|
|
6
|
-
import { useCoreStore } from '../state';
|
|
7
|
-
import { useDatalayer } from './useDatalayer';
|
|
8
|
-
export const useAIAgents = (baseUrlOverride = 'api/ai-agents/v1') => {
|
|
9
|
-
const { configuration } = useCoreStore();
|
|
10
|
-
const { requestDatalayer } = useDatalayer({ notifyOnError: false });
|
|
11
|
-
const createAIAgent = (documentId, documentType, ingress, token, kernelId, { signal, baseUrl = baseUrlOverride } = {}) => {
|
|
12
|
-
return requestDatalayer({
|
|
13
|
-
url: URLExt.join(configuration.aiagentsRunUrl, baseUrl, 'agents'),
|
|
14
|
-
method: 'POST',
|
|
15
|
-
body: {
|
|
16
|
-
document_id: documentId,
|
|
17
|
-
document_type: documentType,
|
|
18
|
-
runtime: {
|
|
19
|
-
ingress,
|
|
20
|
-
token,
|
|
21
|
-
kernel_id: kernelId,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
signal,
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
const getAIAgents = ({ signal, baseUrl = baseUrlOverride, } = {}) => {
|
|
28
|
-
return requestDatalayer({
|
|
29
|
-
url: URLExt.join(configuration.aiagentsRunUrl, baseUrl, 'agents'),
|
|
30
|
-
method: 'GET',
|
|
31
|
-
signal,
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const deleteAIAgent = (documentId, { signal, baseUrl = baseUrlOverride } = {}) => {
|
|
35
|
-
return requestDatalayer({
|
|
36
|
-
url: URLExt.join(configuration.aiagentsRunUrl, baseUrl, 'agents', documentId),
|
|
37
|
-
method: 'DELETE',
|
|
38
|
-
signal,
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
const getAIAgent = (documentId, { signal, baseUrl = baseUrlOverride } = {}) => {
|
|
42
|
-
return requestDatalayer({
|
|
43
|
-
url: URLExt.join(configuration.aiagentsRunUrl, baseUrl, 'agents', documentId),
|
|
44
|
-
method: 'GET',
|
|
45
|
-
signal,
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
const patchAIAgent = (documentId, ingress, token, kernelId, { signal, baseUrl = baseUrlOverride } = {}) => {
|
|
49
|
-
return requestDatalayer({
|
|
50
|
-
url: URLExt.join(configuration.aiagentsRunUrl, baseUrl, 'agents', documentId),
|
|
51
|
-
method: 'PATCH',
|
|
52
|
-
body: {
|
|
53
|
-
runtime: ingress && token && kernelId
|
|
54
|
-
? {
|
|
55
|
-
ingress,
|
|
56
|
-
token,
|
|
57
|
-
kernel_id: kernelId,
|
|
58
|
-
}
|
|
59
|
-
: null,
|
|
60
|
-
},
|
|
61
|
-
signal,
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
return {
|
|
65
|
-
createAIAgent,
|
|
66
|
-
getAIAgents,
|
|
67
|
-
deleteAIAgent,
|
|
68
|
-
getAIAgent,
|
|
69
|
-
patchAIAgent,
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
export default useAIAgents;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export interface IUseAIJupyterChatOptions {
|
|
2
|
-
apiUrl?: string;
|
|
3
|
-
initialMessages?: unknown[];
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Hook to manage chat state with JupyterLab backend.
|
|
7
|
-
* Adapts Vercel AI SDK's useChat for Datalayer AI context.
|
|
8
|
-
*/
|
|
9
|
-
export declare function useAIJupyterChat(_options?: IUseAIJupyterChatOptions): {
|
|
10
|
-
messages: import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[];
|
|
11
|
-
sendMessage: (message?: (Omit<import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>, "id" | "role"> & {
|
|
12
|
-
id?: string | undefined;
|
|
13
|
-
role?: "user" | "system" | "assistant" | undefined;
|
|
14
|
-
} & {
|
|
15
|
-
text?: never;
|
|
16
|
-
files?: never;
|
|
17
|
-
messageId?: string;
|
|
18
|
-
}) | {
|
|
19
|
-
text: string;
|
|
20
|
-
files?: FileList | import("ai").FileUIPart[];
|
|
21
|
-
metadata?: unknown;
|
|
22
|
-
parts?: never;
|
|
23
|
-
messageId?: string;
|
|
24
|
-
} | {
|
|
25
|
-
files: FileList | import("ai").FileUIPart[];
|
|
26
|
-
metadata?: unknown;
|
|
27
|
-
parts?: never;
|
|
28
|
-
messageId?: string;
|
|
29
|
-
} | undefined, options?: import("ai").ChatRequestOptions) => Promise<void>;
|
|
30
|
-
status: import("ai").ChatStatus;
|
|
31
|
-
setMessages: (messages: import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[] | ((messages: import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[]) => import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[])) => void;
|
|
32
|
-
regenerate: ({ messageId, ...options }?: {
|
|
33
|
-
messageId?: string;
|
|
34
|
-
} & import("ai").ChatRequestOptions) => Promise<void>;
|
|
35
|
-
clearChat: () => void;
|
|
36
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
/*
|
|
6
|
-
* Copyright (c) 2024-2025 Datalayer, Inc.
|
|
7
|
-
*
|
|
8
|
-
* BSD 3-Clause License
|
|
9
|
-
*/
|
|
10
|
-
import { useCallback, useMemo } from 'react';
|
|
11
|
-
import { useChat } from '@ai-sdk/react';
|
|
12
|
-
import { DefaultChatTransport } from 'ai';
|
|
13
|
-
import { ServerConnection } from '@jupyterlab/services';
|
|
14
|
-
import { URLExt } from '@jupyterlab/coreutils';
|
|
15
|
-
/**
|
|
16
|
-
* Hook to manage chat state with JupyterLab backend.
|
|
17
|
-
* Adapts Vercel AI SDK's useChat for Datalayer AI context.
|
|
18
|
-
*/
|
|
19
|
-
export function useAIJupyterChat(_options = {}) {
|
|
20
|
-
// Build the full API URL for the chat endpoint
|
|
21
|
-
const settings = ServerConnection.makeSettings();
|
|
22
|
-
const chatEndpoint = URLExt.join(settings.baseUrl, 'datalayer', 'chat');
|
|
23
|
-
const { messages, sendMessage, status, setMessages, regenerate } = useChat({
|
|
24
|
-
id: 'ai-jupyter-chat',
|
|
25
|
-
transport: new DefaultChatTransport({
|
|
26
|
-
api: chatEndpoint,
|
|
27
|
-
credentials: settings.token ? 'include' : 'omit',
|
|
28
|
-
headers: {
|
|
29
|
-
Authorization: `token ${settings.token || ''}`,
|
|
30
|
-
'X-XSRFToken': settings.token || '',
|
|
31
|
-
},
|
|
32
|
-
fetch: async (input, init) => {
|
|
33
|
-
return fetch(input, {
|
|
34
|
-
...init,
|
|
35
|
-
mode: 'cors',
|
|
36
|
-
credentials: settings.token ? 'include' : 'omit',
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
40
|
-
});
|
|
41
|
-
// Clear chat history
|
|
42
|
-
const clearChat = useCallback(() => {
|
|
43
|
-
setMessages([]);
|
|
44
|
-
}, [setMessages]);
|
|
45
|
-
return useMemo(() => ({
|
|
46
|
-
messages,
|
|
47
|
-
sendMessage,
|
|
48
|
-
status,
|
|
49
|
-
setMessages,
|
|
50
|
-
regenerate,
|
|
51
|
-
clearChat,
|
|
52
|
-
}), [messages, sendMessage, status, setMessages, regenerate, clearChat]);
|
|
53
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { IAIAgent } from '../models';
|
|
2
|
-
/**
|
|
3
|
-
* Get the document AI Agent if any.
|
|
4
|
-
*
|
|
5
|
-
* It handles checking the AI Agent is alive so it should only be use once per document.
|
|
6
|
-
*/
|
|
7
|
-
export declare function useNotebookAIAgent(notebookId: string): IAIAgent | undefined;
|
|
8
|
-
export default useNotebookAIAgent;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
import { useEffect } from 'react';
|
|
6
|
-
import { useAIAgentStore } from '../state';
|
|
7
|
-
import { useAIAgents } from './useAIAgents';
|
|
8
|
-
/**
|
|
9
|
-
* Get the document AI Agent if any.
|
|
10
|
-
*
|
|
11
|
-
* It handles checking the AI Agent is alive so it should only be use once per document.
|
|
12
|
-
*/
|
|
13
|
-
export function useNotebookAIAgent(notebookId) {
|
|
14
|
-
const { getAIAgent } = useAIAgents();
|
|
15
|
-
const { aiAgents, addAIAgent, deleteAIAgent, updateAIAgent } = useAIAgentStore();
|
|
16
|
-
// Check AI Agent is alive.
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
let abortController;
|
|
19
|
-
const refreshAIAgent = async () => {
|
|
20
|
-
abortController = new AbortController();
|
|
21
|
-
try {
|
|
22
|
-
const response = await getAIAgent(notebookId, {
|
|
23
|
-
signal: abortController.signal,
|
|
24
|
-
});
|
|
25
|
-
if (!response.success) {
|
|
26
|
-
deleteAIAgent(notebookId);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const currentAgent = aiAgents.find(agent => agent.documentId === notebookId);
|
|
30
|
-
const runtimeId = response.agent.runtime?.id;
|
|
31
|
-
if (currentAgent) {
|
|
32
|
-
if (currentAgent.runtimeId !== runtimeId) {
|
|
33
|
-
updateAIAgent(notebookId, runtimeId);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
addAIAgent({
|
|
38
|
-
documentId: notebookId,
|
|
39
|
-
runtimeId,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch (r) {
|
|
44
|
-
deleteAIAgent(notebookId);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const refreshInterval = setInterval(refreshAIAgent, 60_000);
|
|
48
|
-
return () => {
|
|
49
|
-
abortController?.abort('Component unmounted');
|
|
50
|
-
clearInterval(refreshInterval);
|
|
51
|
-
};
|
|
52
|
-
}, [aiAgents, notebookId]);
|
|
53
|
-
const aiAgent = aiAgents.find(aiAgent => aiAgent.documentId === notebookId);
|
|
54
|
-
return aiAgent;
|
|
55
|
-
}
|
|
56
|
-
export default useNotebookAIAgent;
|
package/lib/models/AIAgent.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI Agent model
|
|
3
|
-
*/
|
|
4
|
-
export type IAIAgent = {
|
|
5
|
-
/**
|
|
6
|
-
* ID of the document monitored by the agent.
|
|
7
|
-
*/
|
|
8
|
-
documentId: string;
|
|
9
|
-
/**
|
|
10
|
-
* ID of the runtime connected to the agent.
|
|
11
|
-
*
|
|
12
|
-
* This is not the name of the remote pod but
|
|
13
|
-
* the Jupyter Kernel ID of the process within it.
|
|
14
|
-
*/
|
|
15
|
-
runtimeId?: string;
|
|
16
|
-
};
|
|
17
|
-
export default IAIAgent;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { IAIAgent } from '../../models';
|
|
2
|
-
export type AIAgentState = {
|
|
3
|
-
aiAgents: readonly IAIAgent[];
|
|
4
|
-
addAIAgent: (aiAgent: IAIAgent) => void;
|
|
5
|
-
deleteAIAgent: (documentId: string) => void;
|
|
6
|
-
updateAIAgent: (documentId: string, runtimeId?: string) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare const aiAgentStore: import("zustand").StoreApi<AIAgentState>;
|
|
9
|
-
export declare function useAIAgentStore(): AIAgentState;
|
|
10
|
-
export declare function useAIAgentStore<T>(selector: (state: AIAgentState) => T): T;
|
|
11
|
-
export default useAIAgentStore;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
import { createStore } from 'zustand/vanilla';
|
|
6
|
-
import { useStore } from 'zustand';
|
|
7
|
-
export const aiAgentStore = createStore(set => ({
|
|
8
|
-
aiAgents: [],
|
|
9
|
-
addAIAgent: (aiAgent) => {
|
|
10
|
-
set((state) => {
|
|
11
|
-
if (!state.aiAgents.includes(aiAgent)) {
|
|
12
|
-
return { aiAgents: state.aiAgents.concat([aiAgent]) };
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
deleteAIAgent: (documentId) => {
|
|
20
|
-
set((state) => {
|
|
21
|
-
return {
|
|
22
|
-
aiAgents: state.aiAgents.filter(a => a.documentId === documentId),
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
},
|
|
26
|
-
updateAIAgent: (documentId, runtimeId) => {
|
|
27
|
-
set((state) => {
|
|
28
|
-
const index = state.aiAgents.findIndex(aiAgent => aiAgent.documentId === documentId);
|
|
29
|
-
if (index >= 0) {
|
|
30
|
-
state.aiAgents[index].runtimeId = runtimeId;
|
|
31
|
-
return { aiAgents: [...state.aiAgents] };
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
}));
|
|
39
|
-
export function useAIAgentStore(selector) {
|
|
40
|
-
return useStore(aiAgentStore, selector);
|
|
41
|
-
}
|
|
42
|
-
export default useAIAgentStore;
|