@datalayer/agent-runtimes 1.6.36 → 1.6.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-embed/chunks/{CollapsiblePlugin-Df_cvRKL.js → CollapsiblePlugin-y8sx_FL8.js} +1 -1
- package/dist-embed/chunks/DatalayerAgentBridge-BuGt8vDu.js +1 -0
- package/dist-embed/chunks/{DeckComponent-sQU5JWCV.js → DeckComponent-BnyeYRQq.js} +1 -1
- package/dist-embed/chunks/{DocumentView-BGthuEds.js → DocumentView-DT4DcdJI.js} +1 -1
- package/dist-embed/chunks/{EphemeralDocument-CPSZcPKd.js → EphemeralDocument-CGISw1N3.js} +1 -1
- package/dist-embed/chunks/{ExcalidrawComponent-F2NybZbz.js → ExcalidrawComponent-Bl3R2Mic.js} +1 -1
- package/dist-embed/chunks/{ExcalidrawModal-CDiyt5M-.js → ExcalidrawModal-DSL5jBhG.js} +1 -1
- package/dist-embed/chunks/{JupyterLexicalExtension-CEBuhvME.js → JupyterLexicalExtension-C55KdpCk.js} +6 -6
- package/dist-embed/chunks/{NotebookToolSurfaces-BDYXmM7k.js → NotebookToolSurfaces-Bvj9nwA9.js} +1 -1
- package/dist-embed/chunks/{Output-C6ZHZSBH.js → Output-D-7eUege.js} +1 -1
- package/dist-embed/chunks/{YouTubePlugin-ChcBEMI-.js → YouTubePlugin-BPUrB3sh.js} +1 -1
- package/dist-embed/chunks/{ar-SA-G6X2FPQ2-CnEVkWCp.js → ar-SA-G6X2FPQ2-Dq_tRQtR.js} +1 -1
- package/dist-embed/chunks/{az-AZ-76LH7QW2-CSwFJ6du.js → az-AZ-76LH7QW2-DQAoJi9C.js} +1 -1
- package/dist-embed/chunks/{bg-BG-XCXSNQG7-JG4F_3L3.js → bg-BG-XCXSNQG7-CfZUFj2_.js} +1 -1
- package/dist-embed/chunks/{bn-BD-2XOGV67Q-__W94Bx-.js → bn-BD-2XOGV67Q-DiqZdhkT.js} +1 -1
- package/dist-embed/chunks/{ca-ES-6MX7JW3Y-CgTiQ3-C.js → ca-ES-6MX7JW3Y-B6c2PcO9.js} +1 -1
- package/dist-embed/chunks/{cs-CZ-2BRQDIVT-CuzIST9-.js → cs-CZ-2BRQDIVT-ha7l75va.js} +1 -1
- package/dist-embed/chunks/{da-DK-5WZEPLOC-D4Z2Xglb.js → da-DK-5WZEPLOC-C3b8_hbR.js} +1 -1
- package/dist-embed/chunks/{de-DE-XR44H4JA-E0rMdm2C.js → de-DE-XR44H4JA-CxWFSn3l.js} +1 -1
- package/dist-embed/chunks/{el-GR-BZB4AONW-DHhs1347.js → el-GR-BZB4AONW-iSsL6em8.js} +1 -1
- package/dist-embed/chunks/{es-ES-U4NZUMDT-DI3jTuDV.js → es-ES-U4NZUMDT-BEbh9GGw.js} +1 -1
- package/dist-embed/chunks/{esm-DqlTXy-D.js → esm-RWOqF6ly.js} +1 -1
- package/dist-embed/chunks/{eu-ES-A7QVB2H4-ChXyoAj9.js → eu-ES-A7QVB2H4-C7o7R9hc.js} +1 -1
- package/dist-embed/chunks/{fa-IR-HGAKTJCU-D1qRoSi6.js → fa-IR-HGAKTJCU-DQNpeHKi.js} +1 -1
- package/dist-embed/chunks/{fi-FI-Z5N7JZ37-Cxzt5XFf.js → fi-FI-Z5N7JZ37-D083iC1R.js} +1 -1
- package/dist-embed/chunks/{fr-FR-RHASNOE6-DxKK7jD9.js → fr-FR-RHASNOE6-CUvaq7hG.js} +1 -1
- package/dist-embed/chunks/{gl-ES-HMX3MZ6V-CFdnAa4-.js → gl-ES-HMX3MZ6V-DU31KRvC.js} +1 -1
- package/dist-embed/chunks/{he-IL-6SHJWFNN-lBjIyRxj.js → he-IL-6SHJWFNN-bMtU7JNY.js} +1 -1
- package/dist-embed/chunks/{hi-IN-IWLTKZ5I-CtdCPck4.js → hi-IN-IWLTKZ5I-Pma0rKxO.js} +1 -1
- package/dist-embed/chunks/{hu-HU-A5ZG7DT2-D_CFF32t.js → hu-HU-A5ZG7DT2-Dof3afSc.js} +1 -1
- package/dist-embed/chunks/{id-ID-SAP4L64H-CwTXhwLK.js → id-ID-SAP4L64H-ZwqZHBDj.js} +1 -1
- package/dist-embed/chunks/{index-DCpvl_OP.js → index-9EhrHHj7.js} +2 -2
- package/dist-embed/chunks/{it-IT-JPQ66NNP-BUEFwYid.js → it-IT-JPQ66NNP-C-uM6NhO.js} +1 -1
- package/dist-embed/chunks/{ja-JP-DBVTYXUO-BAK_QQr1.js → ja-JP-DBVTYXUO-qzihtLnX.js} +1 -1
- package/dist-embed/chunks/{kaa-6HZHGXH3-C2yLyxLW.js → kaa-6HZHGXH3-Amx_Jfx0.js} +1 -1
- package/dist-embed/chunks/{kab-KAB-ZGHBKWFO-CW0xgQ8n.js → kab-KAB-ZGHBKWFO-BPZfDYRT.js} +1 -1
- package/dist-embed/chunks/{kk-KZ-P5N5QNE5-iG2uKF6i.js → kk-KZ-P5N5QNE5-B83bJ3Yw.js} +1 -1
- package/dist-embed/chunks/{km-KH-HSX4SM5Z-Bm_m99ak.js → km-KH-HSX4SM5Z-BvPDwBVw.js} +1 -1
- package/dist-embed/chunks/{ko-KR-MTYHY66A-Clgfny6b.js → ko-KR-MTYHY66A-jpQ_OpzG.js} +1 -1
- package/dist-embed/chunks/{ku-TR-6OUDTVRD-Y8Y_vzzq.js → ku-TR-6OUDTVRD-RsfwTm7i.js} +1 -1
- package/dist-embed/chunks/{lib-COZbOw0Z.js → lib-BBnVlTAj.js} +1 -1
- package/dist-embed/chunks/{lib-B9ahcmxX.js → lib-Bi95m_cb.js} +1 -1
- package/dist-embed/chunks/{lib-CbUWOQj9.js → lib-C7Y61LM1.js} +1 -1
- package/dist-embed/chunks/{lib-CpkMRAJY.js → lib-CFx15o08.js} +1 -1
- package/dist-embed/chunks/{lib-DBCP5fWa.js → lib-CdtiDxdA.js} +1 -1
- package/dist-embed/chunks/{lib-8ZUSfvoH.js → lib-CoK70EWs.js} +1 -1
- package/dist-embed/chunks/{lib-BepajD8I.js → lib-CsiCQ8oM.js} +1 -1
- package/dist-embed/chunks/{lib-B5Wbadbg.js → lib-D0Q8IWel.js} +1 -1
- package/dist-embed/chunks/{lib-j6VKUVII.js → lib-D6X8UF4a.js} +1 -1
- package/dist-embed/chunks/{lib-BP80BmI2.js → lib-DGhrI5Uw.js} +1 -1
- package/dist-embed/chunks/{lib-DmPUUoao.js → lib-DMy40SOL.js} +1 -1
- package/dist-embed/chunks/{lib-obIZUupc.js → lib-DTyx2eLX.js} +1 -1
- package/dist-embed/chunks/{lib-BFuQ3UQC.js → lib-DdeRC7g0.js} +1 -1
- package/dist-embed/chunks/{lib-NBgDVJov.js → lib-Dj12Ge-1.js} +1 -1
- package/dist-embed/chunks/{lib-DHHIihJW.js → lib-Pqxz_81N.js} +1 -1
- package/dist-embed/chunks/{lib-DggdYYmh.js → lib-UYAFV0Oh.js} +1 -1
- package/dist-embed/chunks/{lib-D25l5ZAy.js → lib-XSPvEMl2.js} +1 -1
- package/dist-embed/chunks/{lib-DwylwlRk.js → lib-p7v7zGkv.js} +1 -1
- package/dist-embed/chunks/{lt-LT-XHIRWOB4-D7Por38P.js → lt-LT-XHIRWOB4-qZ_KjUTQ.js} +1 -1
- package/dist-embed/chunks/{lv-LV-5QDEKY6T-Bz5t6-LB.js → lv-LV-5QDEKY6T-BOKJbljG.js} +1 -1
- package/dist-embed/chunks/{mr-IN-CRQNXWMA-B1NTMzvS.js → mr-IN-CRQNXWMA-xba6p6AI.js} +1 -1
- package/dist-embed/chunks/{my-MM-5M5IBNSE-C1gGuOaf.js → my-MM-5M5IBNSE-B_H0GaRX.js} +1 -1
- package/dist-embed/chunks/{nb-NO-T6EIAALU-o2E12ucR.js → nb-NO-T6EIAALU-Ddg4NpHf.js} +1 -1
- package/dist-embed/chunks/{nl-NL-IS3SIHDZ-Bqxu5mbZ.js → nl-NL-IS3SIHDZ-DS_Sofox.js} +1 -1
- package/dist-embed/chunks/{nn-NO-6E72VCQL-DxUXxDPK.js → nn-NO-6E72VCQL-CYSB6TTi.js} +1 -1
- package/dist-embed/chunks/{oc-FR-POXYY2M6-CDttJVdz.js → oc-FR-POXYY2M6-QrIn4XvF.js} +1 -1
- package/dist-embed/chunks/{pa-IN-N4M65BXN-Dp8ANANJ.js → pa-IN-N4M65BXN-BbacRfk_.js} +1 -1
- package/dist-embed/chunks/{percentages-BXMCSKIN-B5xVDaSp.js → percentages-BXMCSKIN-TyKhSuec.js} +3 -3
- package/dist-embed/chunks/{pl-PL-T2D74RX3-N3d_R6le.js → pl-PL-T2D74RX3-Cn2ehrU4.js} +1 -1
- package/dist-embed/chunks/{pt-BR-5N22H2LF-CpPiMZ-u.js → pt-BR-5N22H2LF-CpNtiBPh.js} +1 -1
- package/dist-embed/chunks/{pt-PT-UZXXM6DQ-EGdAVYif.js → pt-PT-UZXXM6DQ-CcDR3Igq.js} +1 -1
- package/dist-embed/chunks/{ro-RO-JPDTUUEW-Bkty7yik.js → ro-RO-JPDTUUEW-CANXxss1.js} +1 -1
- package/dist-embed/chunks/{ru-RU-B4JR7IUQ-BRHTHx-M.js → ru-RU-B4JR7IUQ-B_NkKbWo.js} +1 -1
- package/dist-embed/chunks/{si-LK-N5RQ5JYF-BnP3_yrO.js → si-LK-N5RQ5JYF-Da_Bg8Mv.js} +1 -1
- package/dist-embed/chunks/{sk-SK-C5VTKIMK-CcOBsX7R.js → sk-SK-C5VTKIMK-BKs6l_DT.js} +1 -1
- package/dist-embed/chunks/{sl-SI-NN7IZMDC-DjcpDjk-.js → sl-SI-NN7IZMDC-C4TvSXZU.js} +1 -1
- package/dist-embed/chunks/{subset-shared.chunk-DuIbGrTT.js → subset-shared.chunk-BZGTZU2h.js} +1 -1
- package/dist-embed/chunks/{subset-worker.chunk-CNz8UZDr.js → subset-worker.chunk-CNJFtQV7.js} +1 -1
- package/dist-embed/chunks/{sv-SE-XGPEYMSR-DbihwJ2w.js → sv-SE-XGPEYMSR-DdKzikID.js} +1 -1
- package/dist-embed/chunks/{ta-IN-2NMHFXQM--fKIkmrb.js → ta-IN-2NMHFXQM-CDzGLNXS.js} +1 -1
- package/dist-embed/chunks/{th-TH-HPSO5L25-CkS_jtXJ.js → th-TH-HPSO5L25-X4BJ7awj.js} +1 -1
- package/dist-embed/chunks/{tr-TR-DEFEU3FU-B7b1yuT5.js → tr-TR-DEFEU3FU-CN69_6_H.js} +1 -1
- package/dist-embed/chunks/{uk-UA-QMV73CPH-DMXQPyW5.js → uk-UA-QMV73CPH-KjB2cySI.js} +1 -1
- package/dist-embed/chunks/{vi-VN-M7AON7JQ-DQGL1ixT.js → vi-VN-M7AON7JQ-BqVSbGWG.js} +1 -1
- package/dist-embed/chunks/{zh-CN-LNUGB5OW-BzDVFX-Z.js → zh-CN-LNUGB5OW-oRPI4tbl.js} +1 -1
- package/dist-embed/chunks/{zh-HK-E62DVLB3-DwTp6Tkq.js → zh-HK-E62DVLB3-BUlz3y0i.js} +1 -1
- package/dist-embed/chunks/{zh-TW-RAJ6MFWO-VbTpKAX1.js → zh-TW-RAJ6MFWO-NxjUwhr3.js} +1 -1
- package/dist-embed/datalayer-app-main.js +90 -88
- package/dist-embed/datalayer-app.css +1 -1
- package/lib/AgentDocument.js +2 -2
- package/lib/AgentNotebook.js +2 -2
- package/lib/apps/plugins/agents/DatalayerAgentBridge.js +10 -3
- package/lib/apps/plugins/agents/SandboxSelector.js +1 -1
- package/lib/apps/plugins/agents/handoffRuntime.d.ts +36 -0
- package/lib/apps/plugins/agents/handoffRuntime.js +50 -0
- package/lib/apps/plugins/agents/plugin.d.ts +20 -6
- package/lib/apps/plugins/agents/plugin.js +1 -0
- package/lib/apps/plugins/agents/switchable.d.ts +14 -2
- package/lib/apps/plugins/agents/switchable.js +13 -3
- package/lib/examples/main.js +2 -2
- package/lib/loop-main.js +27 -25
- package/lib/portable/hosts/agentClient.d.ts +9 -9
- package/lib/portable/hosts/agentClient.js +34 -8
- package/lib/portable/hosts/contracts.json +3 -28
- package/lib/portable/hosts/index.d.ts +0 -1
- package/lib/portable/hosts/index.js +0 -1
- package/lib/specs/agents/agents.d.ts +1 -0
- package/lib/specs/agents/agents.js +246 -0
- package/lib/specs/apps.js +5 -9
- package/lib/specs/cogs.js +3 -0
- package/lib/types/agentspecs.d.ts +19 -0
- package/lib/types/agentspecs.js +7 -0
- package/package.json +1 -1
- package/scripts/codegen/generate_agents.py +28 -0
- package/scripts/codegen/generate_sandbox_agents.py +1 -0
- package/dist-embed/chunks/DatalayerAgentBridge-BmoysA2b.js +0 -1
- package/lib/portable/hosts/sessionUid.d.ts +0 -9
- package/lib/portable/hosts/sessionUid.js +0 -29
package/lib/AgentDocument.js
CHANGED
|
@@ -27,7 +27,7 @@ import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
|
27
27
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
28
28
|
import { Text, Spinner } from '@primer/react';
|
|
29
29
|
import { AlertIcon } from '@primer/octicons-react';
|
|
30
|
-
import {
|
|
30
|
+
import { AppearanceControls, Box, createThemeStore, DatalayerThemeProvider, setupPrimerPortals, themeConfigs, useSystemColorMode, } from '@datalayer/primer-addons';
|
|
31
31
|
import { JupyterReactTheme, disposeServiceManager, loadJupyterConfig, getJupyterServerUrl, getJupyterServerToken, setJupyterServerUrl, setJupyterServerToken, useJupyter, } from '@datalayer/jupyter-react';
|
|
32
32
|
import { ComponentPickerMenuPlugin, JupyterInputOutputPlugin, DraggableBlockPlugin, LexicalConfigProvider, LexicalStatePlugin, FloatingTextFormatToolbarPlugin, CodeActionMenuPlugin, TableCellResizerPlugin, } from '@datalayer/jupyter-lexical';
|
|
33
33
|
import { ServiceManager, ServerConnection } from '@jupyterlab/services';
|
|
@@ -341,6 +341,6 @@ export const AgentDocument = () => {
|
|
|
341
341
|
return (_jsx(DatalayerThemeProvider, { colorMode: colorMode, theme: themeConfig.primerTheme, themeStyles: themeConfig.themeStyles, children: _jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", height: "100vh", gap: 3, bg: "canvas.default", children: [_jsx(AlertIcon, { size: 48 }), _jsx(Text, { sx: { color: 'danger.fg', fontSize: 2 }, children: "Failed to connect" }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: error })] }) }));
|
|
342
342
|
}
|
|
343
343
|
// Ready — lexical editor + chat side-by-side
|
|
344
|
-
return (_jsx(DatalayerThemeProvider, { colorMode: colorMode, theme: themeConfig.primerTheme, themeStyles: themeConfig.themeStyles, children: _jsxs(Box, { display: "flex", flexDirection: "column", height: "100vh", width: "100vw", overflow: "hidden", bg: "canvas.default", children: [_jsx(Box, { display: "flex", justifyContent: "flex-end", alignItems: "center", px: 3, py: 2, borderBottom: "1px solid", borderColor: "border.default", flexShrink: 0, children: _jsx(
|
|
344
|
+
return (_jsx(DatalayerThemeProvider, { colorMode: colorMode, theme: themeConfig.primerTheme, themeStyles: themeConfig.themeStyles, children: _jsxs(Box, { display: "flex", flexDirection: "column", height: "100vh", width: "100vw", overflow: "hidden", bg: "canvas.default", children: [_jsx(Box, { display: "flex", justifyContent: "flex-end", alignItems: "center", px: 3, py: 2, borderBottom: "1px solid", borderColor: "border.default", flexShrink: 0, children: _jsx(AppearanceControls, { layout: "inline", useStore: useAgentDocumentThemeStore }) }), _jsxs(Box, { display: "flex", flex: 1, minHeight: 0, overflow: "hidden", children: [serviceManager && kernelResolved && (_jsx(LexicalPanel, { serviceManager: serviceManager, kernelId: kernelId, colormode: resolvedMode, backgroundColor: themeBackground, onToolsReady: handleToolsReady, onKernelReady: handleKernelReady })), _jsx(ChatPanel, { agentId: agentId, tools: tools, kernel: documentKernel })] })] }) }));
|
|
345
345
|
};
|
|
346
346
|
export default AgentDocument;
|
package/lib/AgentNotebook.js
CHANGED
|
@@ -21,7 +21,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
21
21
|
import { useEffect, useState } from 'react';
|
|
22
22
|
import { Text, Spinner } from '@primer/react';
|
|
23
23
|
import { AlertIcon } from '@primer/octicons-react';
|
|
24
|
-
import {
|
|
24
|
+
import { AppearanceControls, Box, createThemeStore, DatalayerThemeProvider, setupPrimerPortals, themeConfigs, useSystemColorMode, } from '@datalayer/primer-addons';
|
|
25
25
|
import { Notebook, JupyterReactTheme, notebookStore, disposeServiceManager, loadJupyterConfig, getJupyterServerUrl, getJupyterServerToken, setJupyterServerUrl, setJupyterServerToken, } from '@datalayer/jupyter-react';
|
|
26
26
|
import { ServiceManager, ServerConnection } from '@jupyterlab/services';
|
|
27
27
|
import { Chat } from './chat/index.js';
|
|
@@ -287,6 +287,6 @@ export const AgentNotebook = () => {
|
|
|
287
287
|
return (_jsx(DatalayerThemeProvider, { colorMode: colorMode, theme: themeConfig.primerTheme, themeStyles: themeConfig.themeStyles, children: _jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", height: "100vh", gap: 3, bg: "canvas.default", children: [_jsx(AlertIcon, { size: 48 }), _jsx(Text, { sx: { color: 'danger.fg', fontSize: 2 }, children: "Failed to connect" }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: error })] }) }));
|
|
288
288
|
}
|
|
289
289
|
// Ready — notebook + chat side-by-side
|
|
290
|
-
return (_jsx(DatalayerThemeProvider, { colorMode: colorMode, theme: themeConfig.primerTheme, themeStyles: themeConfig.themeStyles, children: _jsxs(Box, { display: "flex", flexDirection: "column", height: "100vh", width: "100vw", overflow: "hidden", bg: "canvas.default", children: [_jsx(Box, { display: "flex", justifyContent: "flex-end", alignItems: "center", px: 3, height: `${TOP_BAR_HEIGHT}px`, boxSizing: "border-box", borderBottom: "1px solid", borderColor: "border.default", flexShrink: 0, children: _jsx(
|
|
290
|
+
return (_jsx(DatalayerThemeProvider, { colorMode: colorMode, theme: themeConfig.primerTheme, themeStyles: themeConfig.themeStyles, children: _jsxs(Box, { display: "flex", flexDirection: "column", height: "100vh", width: "100vw", overflow: "hidden", bg: "canvas.default", children: [_jsx(Box, { display: "flex", justifyContent: "flex-end", alignItems: "center", px: 3, height: `${TOP_BAR_HEIGHT}px`, boxSizing: "border-box", borderBottom: "1px solid", borderColor: "border.default", flexShrink: 0, children: _jsx(AppearanceControls, { layout: "inline", useStore: useAgentNotebookThemeStore }) }), _jsxs(Box, { display: "flex", flex: 1, minHeight: 0, overflow: "hidden", children: [serviceManager && (_jsx(NotebookPanel, { serviceManager: serviceManager, kernelId: kernelId, colormode: resolvedMode, backgroundColor: themeBackground })), _jsx(ChatPanel, { agentId: agentId, kernel: notebookKernel })] })] }) }));
|
|
291
291
|
};
|
|
292
292
|
export default AgentNotebook;
|
|
@@ -147,11 +147,17 @@ export function DatalayerAgentBridge() {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
if (already) {
|
|
150
|
+
// The runtime's Jupyter, when the host gave it — a terminal session
|
|
151
|
+
// handed over by `/browser` does: the notebook opens on it, as the
|
|
152
|
+
// terminal's `/notebook` does. Without it the agent is already on its
|
|
153
|
+
// runtime and the chat is all the page talks to.
|
|
154
|
+
const jupyter = visitors ? undefined : kept?.jupyter;
|
|
150
155
|
service.report({
|
|
151
156
|
variant: 'datalayer',
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
157
|
+
sandbox_running: Boolean(jupyter),
|
|
158
|
+
...(jupyter
|
|
159
|
+
? { jupyter_url: jupyter.url, jupyter_token: jupyter.token }
|
|
160
|
+
: {}),
|
|
155
161
|
agent_base_url: already,
|
|
156
162
|
});
|
|
157
163
|
return;
|
|
@@ -197,6 +203,7 @@ export function DatalayerAgentBridge() {
|
|
|
197
203
|
status,
|
|
198
204
|
error,
|
|
199
205
|
already,
|
|
206
|
+
kept,
|
|
200
207
|
visitors,
|
|
201
208
|
visitorAgent,
|
|
202
209
|
]);
|
|
@@ -62,7 +62,7 @@ export function SandboxSelector(_props) {
|
|
|
62
62
|
// Held here: drawn, said why on hover, not taken. `aria-disabled`
|
|
63
63
|
// rather than `disabled`: a disabled button takes no pointer, and
|
|
64
64
|
// its reason would never be read.
|
|
65
|
-
const held = heldTargetReason(entry, service?.serverUrl ?? '');
|
|
65
|
+
const held = heldTargetReason(entry, service?.serverUrl ?? '', service?.fixedTarget);
|
|
66
66
|
return (_jsx(SegmentedControl.Button, { selected: position === index, "aria-disabled": held ? true : undefined, "data-sandbox-target": entry, "data-sandbox-target-held": held ? '' : undefined, sx: {
|
|
67
67
|
listStyle: 'none',
|
|
68
68
|
...(held
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a session handed over from the terminal runs, and the Agents
|
|
3
|
+
* plugin's configuration that keeps it there.
|
|
4
|
+
*
|
|
5
|
+
* `/browser` mints a handoff carrying `runtime` (`routes/loop.py`); the LOOP
|
|
6
|
+
* page redeems it and configures this plugin from it, so the switch shows the
|
|
7
|
+
* session's place selected and every other place held.
|
|
8
|
+
*
|
|
9
|
+
* @module apps/plugins/agents/handoffRuntime
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentsConfig } from './plugin';
|
|
12
|
+
/**
|
|
13
|
+
* Where the handed-over session's agent runs, as the terminal said.
|
|
14
|
+
*
|
|
15
|
+
* The page cannot tell for itself: on Datalayer it is served through the
|
|
16
|
+
* terminal's relay at `http://127.0.0.1:<port>`, which looks exactly like a
|
|
17
|
+
* local server. The Jupyter token arrives here, in the exchange's answer, and
|
|
18
|
+
* never in the page's address.
|
|
19
|
+
*/
|
|
20
|
+
export type SessionRuntime = {
|
|
21
|
+
where: 'local';
|
|
22
|
+
} | {
|
|
23
|
+
where: 'datalayer';
|
|
24
|
+
name: string;
|
|
25
|
+
jupyterUrl: string;
|
|
26
|
+
jupyterToken: string;
|
|
27
|
+
};
|
|
28
|
+
/** The exchange's `runtime`, or an error saying what is missing. */
|
|
29
|
+
export declare function sessionRuntimeOf(runtime: unknown): SessionRuntime;
|
|
30
|
+
/**
|
|
31
|
+
* The Agents plugin's configuration for a session: where it runs, and only
|
|
32
|
+
* there. A handed-over session is fixed to its place — Datalayer with the
|
|
33
|
+
* runtime's Jupyter for the notebook, or Local — and the switch holds the
|
|
34
|
+
* others; a page opened without a handoff starts on Local, movable.
|
|
35
|
+
*/
|
|
36
|
+
export declare function agentsConfigOf(serverUrl: string, runtime: SessionRuntime | undefined): AgentsConfig;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/** The exchange's `runtime`, or an error saying what is missing. */
|
|
6
|
+
export function sessionRuntimeOf(runtime) {
|
|
7
|
+
const value = (runtime ?? {});
|
|
8
|
+
if (value.where === 'local') {
|
|
9
|
+
return { where: 'local' };
|
|
10
|
+
}
|
|
11
|
+
if (value.where === 'datalayer' &&
|
|
12
|
+
typeof value.name === 'string' &&
|
|
13
|
+
typeof value.jupyter_url === 'string' &&
|
|
14
|
+
typeof value.jupyter_token === 'string') {
|
|
15
|
+
return {
|
|
16
|
+
where: 'datalayer',
|
|
17
|
+
name: value.name,
|
|
18
|
+
jupyterUrl: value.jupyter_url,
|
|
19
|
+
jupyterToken: value.jupyter_token,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
throw new Error('The handed-over session does not say where its agent runs: update agent-runtimes on the server that minted the handoff.');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The Agents plugin's configuration for a session: where it runs, and only
|
|
26
|
+
* there. A handed-over session is fixed to its place — Datalayer with the
|
|
27
|
+
* runtime's Jupyter for the notebook, or Local — and the switch holds the
|
|
28
|
+
* others; a page opened without a handoff starts on Local, movable.
|
|
29
|
+
*/
|
|
30
|
+
export function agentsConfigOf(serverUrl, runtime) {
|
|
31
|
+
if (runtime?.where === 'datalayer') {
|
|
32
|
+
return {
|
|
33
|
+
serverUrl,
|
|
34
|
+
target: 'datalayer',
|
|
35
|
+
targetFixed: true,
|
|
36
|
+
// The agent is already on the runtime, reached through the relay —
|
|
37
|
+
// this page's origin — which adds the person's token.
|
|
38
|
+
datalayerKept: {
|
|
39
|
+
url: serverUrl,
|
|
40
|
+
name: runtime.name,
|
|
41
|
+
jupyter: { url: runtime.jupyterUrl, token: runtime.jupyterToken },
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
serverUrl,
|
|
47
|
+
target: 'local',
|
|
48
|
+
targetFixed: runtime !== undefined,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -114,13 +114,25 @@ export type AgentsConfig = {
|
|
|
114
114
|
*/
|
|
115
115
|
datalayerVisitors?: DatalayerVisitors;
|
|
116
116
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* person's own token
|
|
117
|
+
* An agent already on a runtime of its own, so nothing is allocated or
|
|
118
|
+
* created: a deployment kept there (R-33), its agent made from the
|
|
119
|
+
* deployment record when the runtime started, which the chat speaks to
|
|
120
|
+
* with the person's own token; or the runtime a terminal session runs on,
|
|
121
|
+
* handed over by `/browser`, reached through the terminal's relay, which
|
|
122
|
+
* adds the token itself. `url` is the runtime's agent-runtimes address.
|
|
123
|
+
*
|
|
124
|
+
* `jupyter` is the runtime's Jupyter server, when the page opens notebooks
|
|
125
|
+
* on it: its base URL (the ingress) and its own token. Given, the sandbox
|
|
126
|
+
* is reported running there; absent, the chat is all the page talks to.
|
|
127
|
+
* `name` is the runtime's.
|
|
121
128
|
*/
|
|
122
129
|
datalayerKept?: {
|
|
123
130
|
url: string;
|
|
131
|
+
name?: string;
|
|
132
|
+
jupyter?: {
|
|
133
|
+
url: string;
|
|
134
|
+
token: string;
|
|
135
|
+
};
|
|
124
136
|
};
|
|
125
137
|
/**
|
|
126
138
|
* An embed token for the application (R-20): what an embedded
|
|
@@ -131,8 +143,10 @@ export type AgentsConfig = {
|
|
|
131
143
|
embedToken?: string;
|
|
132
144
|
/**
|
|
133
145
|
* The target is the host's decision, not the reader's: started there even
|
|
134
|
-
* with the control hidden
|
|
135
|
-
*
|
|
146
|
+
* with the control hidden, and, with the control shown, every other target
|
|
147
|
+
* held in it with the reason (`heldTargetReason`). For an application that
|
|
148
|
+
* runs where it is deployed, and for a session handed over from the
|
|
149
|
+
* terminal, which runs where it was started; a workspace leaves it unset.
|
|
136
150
|
*/
|
|
137
151
|
targetFixed?: boolean;
|
|
138
152
|
};
|
|
@@ -62,6 +62,7 @@ export const AgentsPlugin = definePlugin({
|
|
|
62
62
|
// read here, so that it is held on the web like any other.
|
|
63
63
|
initialTarget: offeredTarget((showVariants || config.targetFixed ? config.target : 'browser') ??
|
|
64
64
|
'local', config.serverUrl),
|
|
65
|
+
targetFixed: config.targetFixed,
|
|
65
66
|
kernelSource: config.kernelSource,
|
|
66
67
|
localAgent: config.localAgent,
|
|
67
68
|
// The capacity plugins' say, read at switch time — lazily, because a
|
|
@@ -59,6 +59,11 @@ export declare const SANDBOX_TARGETS: readonly SandboxTarget[];
|
|
|
59
59
|
* Why a target is shown but not offered here — said on it — or nothing when
|
|
60
60
|
* it is offered.
|
|
61
61
|
*
|
|
62
|
+
* A host that fixed the target (`fixed`) offers that one and no other: a
|
|
63
|
+
* session the terminal handed over runs where it was started — on a Datalayer
|
|
64
|
+
* runtime, or on this machine — and the page cannot move it. The others stay
|
|
65
|
+
* in the switch, held, saying so.
|
|
66
|
+
*
|
|
62
67
|
* *Local* is a local agent with the Jupyter server it starts beside itself,
|
|
63
68
|
* and a web page has no machine of the reader's to start them on. Decided
|
|
64
69
|
* 2026-10-10 (Eric): not offered on the web for now, and left in the switch,
|
|
@@ -66,7 +71,7 @@ export declare const SANDBOX_TARGETS: readonly SandboxTarget[];
|
|
|
66
71
|
* JupyterLab it is offered as before — the same line the code-sandbox picker
|
|
67
72
|
* draws for a Jupyter Server's kernels (`codeSandboxProviders`).
|
|
68
73
|
*/
|
|
69
|
-
export declare function heldTargetReason(target: SandboxTarget, serverUrl: string): string | undefined;
|
|
74
|
+
export declare function heldTargetReason(target: SandboxTarget, serverUrl: string, fixed?: SandboxTarget): string | undefined;
|
|
70
75
|
export declare const TARGET_SPECS: Record<SandboxTarget, SandboxTargetSpec>;
|
|
71
76
|
/** Whether an agent runs on this target — the question the chat asks. */
|
|
72
77
|
export declare function targetHasAgent(target: SandboxTarget): boolean;
|
|
@@ -81,6 +86,8 @@ export declare function targetRunsAgentInPage(target: SandboxTarget): boolean;
|
|
|
81
86
|
export type SwitchableSandboxService = SandboxService & {
|
|
82
87
|
/** Where the sandbox currently runs. */
|
|
83
88
|
readonly target: ReadonlySignal<SandboxTarget>;
|
|
89
|
+
/** The one target offered, when the host fixed it; every other is held. */
|
|
90
|
+
readonly fixedTarget?: SandboxTarget;
|
|
84
91
|
/** Move it. Disconnects the old backing before starting the new one. */
|
|
85
92
|
setTarget: (target: SandboxTarget) => Promise<void>;
|
|
86
93
|
/** The in-browser services, when the browser is the active target. */
|
|
@@ -91,6 +98,11 @@ export type SwitchableSandboxService = SandboxService & {
|
|
|
91
98
|
export type SwitchableConfig = {
|
|
92
99
|
serverUrl: string;
|
|
93
100
|
initialTarget?: SandboxTarget;
|
|
101
|
+
/**
|
|
102
|
+
* Whether the initial target is the only one: the host decided where the
|
|
103
|
+
* agent runs, and the reader cannot move it (`heldTargetReason`).
|
|
104
|
+
*/
|
|
105
|
+
targetFixed?: boolean;
|
|
94
106
|
/**
|
|
95
107
|
* Agent to create when Local is selected.
|
|
96
108
|
*
|
|
@@ -119,7 +131,7 @@ export type SwitchableConfig = {
|
|
|
119
131
|
*/
|
|
120
132
|
kernelSource?: ServiceManagerSource;
|
|
121
133
|
};
|
|
122
|
-
export declare function createSwitchableSandboxService({ serverUrl, initialTarget, kernelSource, localAgent, blueprint, }: SwitchableConfig): SwitchableSandboxService;
|
|
134
|
+
export declare function createSwitchableSandboxService({ serverUrl, initialTarget, targetFixed, kernelSource, localAgent, blueprint, }: SwitchableConfig): SwitchableSandboxService;
|
|
123
135
|
/**
|
|
124
136
|
* Create the agent whose per-agent Jupyter sandbox backs Local, on the
|
|
125
137
|
* agent-runtimes server at `serverUrl`, unless it is there already — then
|
|
@@ -45,6 +45,11 @@ export const SANDBOX_TARGETS = [
|
|
|
45
45
|
* Why a target is shown but not offered here — said on it — or nothing when
|
|
46
46
|
* it is offered.
|
|
47
47
|
*
|
|
48
|
+
* A host that fixed the target (`fixed`) offers that one and no other: a
|
|
49
|
+
* session the terminal handed over runs where it was started — on a Datalayer
|
|
50
|
+
* runtime, or on this machine — and the page cannot move it. The others stay
|
|
51
|
+
* in the switch, held, saying so.
|
|
52
|
+
*
|
|
48
53
|
* *Local* is a local agent with the Jupyter server it starts beside itself,
|
|
49
54
|
* and a web page has no machine of the reader's to start them on. Decided
|
|
50
55
|
* 2026-10-10 (Eric): not offered on the web for now, and left in the switch,
|
|
@@ -52,7 +57,10 @@ export const SANDBOX_TARGETS = [
|
|
|
52
57
|
* JupyterLab it is offered as before — the same line the code-sandbox picker
|
|
53
58
|
* draws for a Jupyter Server's kernels (`codeSandboxProviders`).
|
|
54
59
|
*/
|
|
55
|
-
export function heldTargetReason(target, serverUrl) {
|
|
60
|
+
export function heldTargetReason(target, serverUrl, fixed) {
|
|
61
|
+
if (fixed && target !== fixed) {
|
|
62
|
+
return `This session runs on ${TARGET_SPECS[fixed].label}: it cannot be moved from here.`;
|
|
63
|
+
}
|
|
56
64
|
// A host that names its own agent-runtimes server — `app.mount`, `loop apps
|
|
57
65
|
// run --web` (P-08, P-25) — is not asking for the reader's machine:
|
|
58
66
|
// Local is that server, and it is offered. Held, every message of a page
|
|
@@ -139,8 +147,9 @@ export function targetHasAgent(target) {
|
|
|
139
147
|
export function targetRunsAgentInPage(target) {
|
|
140
148
|
return target === 'browser';
|
|
141
149
|
}
|
|
142
|
-
export function createSwitchableSandboxService({ serverUrl, initialTarget = 'local', kernelSource, localAgent, blueprint, }) {
|
|
150
|
+
export function createSwitchableSandboxService({ serverUrl, initialTarget = 'local', targetFixed = false, kernelSource, localAgent, blueprint, }) {
|
|
143
151
|
const target = signal(initialTarget);
|
|
152
|
+
const fixedTarget = targetFixed ? initialTarget : undefined;
|
|
144
153
|
// Both implementations exist from the start, but neither connects until it is
|
|
145
154
|
// the active one — a Pyodide kernel that nobody asked for is megabytes of
|
|
146
155
|
// download, and a WebSocket to a server nobody chose is noise in the logs.
|
|
@@ -256,6 +265,7 @@ export function createSwitchableSandboxService({ serverUrl, initialTarget = 'loc
|
|
|
256
265
|
: 'server';
|
|
257
266
|
},
|
|
258
267
|
target,
|
|
268
|
+
fixedTarget,
|
|
259
269
|
snapshot,
|
|
260
270
|
status,
|
|
261
271
|
ready,
|
|
@@ -323,7 +333,7 @@ export function createSwitchableSandboxService({ serverUrl, initialTarget = 'loc
|
|
|
323
333
|
return;
|
|
324
334
|
}
|
|
325
335
|
// Held here: refused whoever asks, not only by the switch's button.
|
|
326
|
-
const held = heldTargetReason(next, serverUrl);
|
|
336
|
+
const held = heldTargetReason(next, serverUrl, fixedTarget);
|
|
327
337
|
if (held) {
|
|
328
338
|
throw new Error(held);
|
|
329
339
|
}
|
package/lib/examples/main.js
CHANGED
|
@@ -18,7 +18,7 @@ import { DatalayerThemeProvider, DatalayerLogoText, getLogoColors, themeConfigs,
|
|
|
18
18
|
import { AgentSummary } from '../components/agents/AgentSummary.js';
|
|
19
19
|
import { HomeIcon, SignInIcon, SignOutIcon } from '@primer/octicons-react';
|
|
20
20
|
import { ActionList, ActionMenu, Button, SegmentedControl, Spinner, Text, TextInput, } from '@primer/react';
|
|
21
|
-
import {
|
|
21
|
+
import { AppearanceControls } from '@datalayer/primer-addons/lib/components/appearance/index.js';
|
|
22
22
|
import { coreStore, iamStore } from '@datalayer/core';
|
|
23
23
|
import { DATALAYER_IAM_TOKEN_KEY, DATALAYER_IAM_USER_KEY, } from '../state/substates/index.js';
|
|
24
24
|
import { SignInSimple } from '@datalayer/core/lib/views/iam/index.js';
|
|
@@ -1181,7 +1181,7 @@ const ExampleAppThemed = ({ selectedExample, isChangingExample, error, ExampleCo
|
|
|
1181
1181
|
void onRuntimeTargetChange(target);
|
|
1182
1182
|
}
|
|
1183
1183
|
}, children: capabilities.label }, target));
|
|
1184
|
-
}) }) })), !isHome && !shouldShowAuthScreen && !isLoopWorkspace && (_jsx(AgentSummary, { summary: agentSummary })), isChangingExample && (_jsx(Box, { as: "span", color: "fg.muted", fontSize: 0, children: "Loading\u2026" }))] }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 3, children: [_jsx(
|
|
1184
|
+
}) }) })), !isHome && !shouldShowAuthScreen && !isLoopWorkspace && (_jsx(AgentSummary, { summary: agentSummary })), isChangingExample && (_jsx(Box, { as: "span", color: "fg.muted", fontSize: 0, children: "Loading\u2026" }))] }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 3, children: [_jsx(AppearanceControls, { layout: "inline", useStore: useExampleThemeStore }), _jsx(Box, { display: "flex", alignItems: "center", gap: 2, children: token ? (_jsxs(_Fragment, { children: [_jsx(UserBadge, { token: token, variant: "small", onTokenExpired: () => {
|
|
1185
1185
|
handleHeaderLogout();
|
|
1186
1186
|
setShowSignIn(true);
|
|
1187
1187
|
} }), _jsx(Button, { size: "small", variant: "invisible", onClick: handleHeaderLogout, leadingVisual: SignOutIcon, sx: { color: 'fg.muted' }, children: "Sign out" })] })) : (_jsx(Button, { size: "small", variant: "invisible", onClick: () => setShowSignIn(true), leadingVisual: SignInIcon, sx: { color: 'fg.muted' }, children: "Sign in" })) }), _jsx(Box, { as: "a", href: "https://datalayer.ai", target: "_blank", rel: "noopener noreferrer", "aria-label": "Open Datalayer website", display: "inline-flex", alignItems: "center", children: _jsx(DatalayerLogoText, { size: 24, variant: themeVariant, colorMode: colorMode, primaryColor: logoColors.primary, secondaryColor: logoColors.secondary, textColor: logoColors.textColor, primaryGradient: logoColors.primaryGradient, secondaryGradient: logoColors.secondaryGradient, gradient: true }) })] })] }), _jsx(Box, { marginTop: "60px", height: "calc(100vh - 60px)", overflow: "hidden", children: shouldShowAuthScreen ? (
|
package/lib/loop-main.js
CHANGED
|
@@ -38,6 +38,7 @@ import { ChatPlugin } from './apps/plugins/chat/index.js';
|
|
|
38
38
|
import { A2uiPlugin } from './apps/plugins/a2ui/index.js';
|
|
39
39
|
import { AgentspecsPlugin } from './apps/plugins/agentspecs/index.js';
|
|
40
40
|
import { AgentsPlugin } from './apps/plugins/agents/index.js';
|
|
41
|
+
import { agentsConfigOf, sessionRuntimeOf, } from './apps/plugins/agents/handoffRuntime.js';
|
|
41
42
|
import { ModelsPlugin } from './apps/plugins/models/index.js';
|
|
42
43
|
import { DocumentPlugin } from './apps/plugins/document/index.js';
|
|
43
44
|
import { NotebookPlugin } from './apps/plugins/notebook/index.js';
|
|
@@ -67,37 +68,42 @@ async function resolveSession(serverUrl) {
|
|
|
67
68
|
if (!handoff) {
|
|
68
69
|
return fallback;
|
|
69
70
|
}
|
|
71
|
+
let session;
|
|
70
72
|
try {
|
|
71
73
|
const response = await fetch(`${serverUrl}/api/v1/loop/handoff/exchange?code=${encodeURIComponent(handoff)}`, { method: 'POST' });
|
|
72
74
|
if (!response.ok) {
|
|
73
75
|
return fallback;
|
|
74
76
|
}
|
|
75
|
-
|
|
76
|
-
params.delete('handoff');
|
|
77
|
-
const query = params.toString();
|
|
78
|
-
window.history.replaceState({}, '', `${window.location.pathname}${query ? `?${query}` : ''}`);
|
|
79
|
-
return {
|
|
80
|
-
serverUrl,
|
|
81
|
-
agentId: session.agent_id ?? fallback.agentId,
|
|
82
|
-
conversationId: session.conversation_id ?? undefined,
|
|
83
|
-
model: session.model ?? undefined,
|
|
84
|
-
view: session.view ?? view,
|
|
85
|
-
sandbox: {
|
|
86
|
-
state: session.sandbox?.sandbox_running ? 'running' : 'idle',
|
|
87
|
-
variant: session.sandbox?.variant,
|
|
88
|
-
kernelId: session.sandbox?.kernel_id,
|
|
89
|
-
jupyterUrl: session.sandbox?.jupyter_url,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
77
|
+
session = await response.json();
|
|
92
78
|
}
|
|
93
79
|
catch {
|
|
94
80
|
// A handoff that cannot be redeemed is not a reason to show nothing: the
|
|
95
81
|
// page still opens, just without the terminal's conversation.
|
|
96
82
|
return fallback;
|
|
97
83
|
}
|
|
84
|
+
params.delete('handoff');
|
|
85
|
+
const query = params.toString();
|
|
86
|
+
window.history.replaceState({}, '', `${window.location.pathname}${query ? `?${query}` : ''}`);
|
|
87
|
+
return {
|
|
88
|
+
serverUrl,
|
|
89
|
+
agentId: session.agent_id ?? fallback.agentId,
|
|
90
|
+
conversationId: session.conversation_id ?? undefined,
|
|
91
|
+
model: session.model ?? undefined,
|
|
92
|
+
view: session.view ?? view,
|
|
93
|
+
sandbox: {
|
|
94
|
+
state: session.sandbox?.sandbox_running ? 'running' : 'idle',
|
|
95
|
+
variant: session.sandbox?.variant,
|
|
96
|
+
kernelId: session.sandbox?.kernel_id,
|
|
97
|
+
jupyterUrl: session.sandbox?.jupyter_url,
|
|
98
|
+
},
|
|
99
|
+
// Redeemed but not saying where it runs is a server out of step with
|
|
100
|
+
// this page: said on the page, rather than guessed at (`sessionRuntimeOf`).
|
|
101
|
+
runtime: sessionRuntimeOf(session.runtime),
|
|
102
|
+
};
|
|
98
103
|
}
|
|
99
104
|
function LoopPage() {
|
|
100
105
|
const [session, setSession] = useState(null);
|
|
106
|
+
const [failure, setFailure] = useState(null);
|
|
101
107
|
const { colorMode, theme } = useThemeStore();
|
|
102
108
|
const systemColorMode = useSystemColorMode();
|
|
103
109
|
const resolvedMode = colorMode === 'auto' ? systemColorMode : colorMode;
|
|
@@ -110,7 +116,7 @@ function LoopPage() {
|
|
|
110
116
|
}, []);
|
|
111
117
|
useEffect(() => {
|
|
112
118
|
const serverUrl = window.location.origin;
|
|
113
|
-
|
|
119
|
+
resolveSession(serverUrl).then(setSession, (error) => setFailure(error instanceof Error ? error.message : String(error)));
|
|
114
120
|
}, []);
|
|
115
121
|
return (_jsx(DatalayerThemeProvider, { colorMode: resolvedMode, theme: themeConfig.primerTheme, themeStyles: themeConfig.themeStyles, children: _jsx(QueryClientProvider, { client: internalQueryClient, children: _jsx(Box, { height: "100vh", overflow: "hidden", children: session ? (_jsx(LoopWorkspace, { serverUrl: session.serverUrl, agentId: session.agentId, conversationId: session.conversationId, model: session.model, sandbox: session.sandbox, initialViewType: session.view,
|
|
116
122
|
// The notebook and document plugins depend on the sandbox, so
|
|
@@ -118,18 +124,14 @@ function LoopPage() {
|
|
|
118
124
|
// server it talks to.
|
|
119
125
|
extensions: [
|
|
120
126
|
ChatPlugin,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// A session handed over from the terminal is server-backed;
|
|
124
|
-
// the header control can move it from there.
|
|
125
|
-
target: 'local',
|
|
126
|
-
}),
|
|
127
|
+
// Where the terminal's session runs, and only there.
|
|
128
|
+
configurePlugin(AgentsPlugin, agentsConfigOf(session.serverUrl, session.runtime)),
|
|
127
129
|
NotebookPlugin,
|
|
128
130
|
DocumentPlugin,
|
|
129
131
|
A2uiPlugin,
|
|
130
132
|
AgentspecsPlugin,
|
|
131
133
|
ModelsPlugin,
|
|
132
|
-
] })) : null }) }) }));
|
|
134
|
+
] })) : failure ? (_jsx(Box, { p: 4, color: "danger.fg", children: failure })) : null }) }) }));
|
|
133
135
|
}
|
|
134
136
|
const container = document.getElementById('root');
|
|
135
137
|
if (container) {
|
|
@@ -14,12 +14,13 @@ export type HostTurnRequest<P> = Readonly<{
|
|
|
14
14
|
principalId: string;
|
|
15
15
|
prompt: string;
|
|
16
16
|
provenance: P;
|
|
17
|
-
sessionId?: string;
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* The session the thread runs, as the host keeps it: a message to it.
|
|
19
|
+
* Without one, the turn opens a new session, whose uid the runtime mints
|
|
20
|
+
* (a ULID) and names back in the turn's `loop.turn` event; the host keeps
|
|
21
|
+
* it against its thread from `TurnStream.sessionId`.
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
sessionId?: string;
|
|
23
24
|
/**
|
|
24
25
|
* The host user never linked: exchanged as a visitor, which ai-agents
|
|
25
26
|
* answers only when the installation's owner opened it to visitors and the
|
|
@@ -67,13 +68,12 @@ export type TurnProvenance = Readonly<{
|
|
|
67
68
|
message_id: string;
|
|
68
69
|
}>;
|
|
69
70
|
/**
|
|
70
|
-
* What is the host's own in a turn: the
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* What is the host's own in a turn: the place Datalayer checks the channel
|
|
72
|
+
* policy against, the delivery target handed back with every delivery, the
|
|
73
|
+
* provenance sent with the turn, and what is said when its installation
|
|
74
|
+
* holds no host key.
|
|
74
75
|
*/
|
|
75
76
|
export type HostShape<P> = Readonly<{
|
|
76
|
-
sessionUidOf(request: HostTurnRequest<P>): string;
|
|
77
77
|
placeOf(request: HostTurnRequest<P>): Place;
|
|
78
78
|
targetOf(request: HostTurnRequest<P>): Record<string, unknown>;
|
|
79
79
|
/** The turn's provenance; a host that sends none leaves it out. */
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* started or sent on the deployment's session API (idempotent by the host's
|
|
8
8
|
* event id), its AG-UI stream reduced to semantic events, and its session
|
|
9
9
|
* mapped to the host's thread so approvals and completions are delivered.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* A new session's uid is the runtime's (a ULID), named back in the stream;
|
|
11
|
+
* the host keeps it against its thread. What is the host's own (its thread
|
|
12
|
+
* key, the place, the delivery target, its words) is injected as a
|
|
12
13
|
* `HostShape`. Moved from the Slack service (DC-004).
|
|
13
14
|
*
|
|
14
15
|
* @module portable/hosts/agentClient
|
|
@@ -238,7 +239,6 @@ export class HttpAgentClient {
|
|
|
238
239
|
async startTurn(request) {
|
|
239
240
|
const host = await this.credentials.forTurn(request);
|
|
240
241
|
assertTrustedStreamUrl(this.apiUrl, host.sessionApiUrl);
|
|
241
|
-
const sessionId = request.sessionId ?? this.shape.sessionUidOf(request);
|
|
242
242
|
const provenance = this.shape.provenanceOf?.(request);
|
|
243
243
|
const headers = {
|
|
244
244
|
accept: 'text/event-stream',
|
|
@@ -247,7 +247,7 @@ export class HttpAgentClient {
|
|
|
247
247
|
[IDEMPOTENCY_HEADER]: request.externalEventId,
|
|
248
248
|
};
|
|
249
249
|
const response = request.sessionId
|
|
250
|
-
? await this.fetchImplementation(`${host.sessionApiUrl}/${encodeURIComponent(sessionId)}/messages`, {
|
|
250
|
+
? await this.fetchImplementation(`${host.sessionApiUrl}/${encodeURIComponent(request.sessionId)}/messages`, {
|
|
251
251
|
body: JSON.stringify({
|
|
252
252
|
external_event_id: request.externalEventId,
|
|
253
253
|
text: request.prompt,
|
|
@@ -262,7 +262,6 @@ export class HttpAgentClient {
|
|
|
262
262
|
deployment_uid: host.deploymentUid,
|
|
263
263
|
external_event_id: request.externalEventId,
|
|
264
264
|
opener: request.prompt,
|
|
265
|
-
session: sessionId,
|
|
266
265
|
...(host.userToken ? { user_token: host.userToken } : {}),
|
|
267
266
|
...(provenance ? { provenance } : {}),
|
|
268
267
|
}),
|
|
@@ -275,6 +274,20 @@ export class HttpAgentClient {
|
|
|
275
274
|
// limit, a session of someone else.
|
|
276
275
|
throw new HostRefusedError(response.status, await refusalDetailOf(response), 'The turn');
|
|
277
276
|
}
|
|
277
|
+
const events = agUiEventsOf(response.body)[Symbol.asyncIterator]();
|
|
278
|
+
// A new session is named by the runtime: its `loop.turn` event, the
|
|
279
|
+
// first or second of the stream (after `loop.session`), on a first run
|
|
280
|
+
// and on a retry's replay alike.
|
|
281
|
+
const head = [];
|
|
282
|
+
let sessionId = request.sessionId;
|
|
283
|
+
while (!sessionId) {
|
|
284
|
+
const next = await events.next();
|
|
285
|
+
if (next.done) {
|
|
286
|
+
throw new Error('Datalayer named no session for the turn.');
|
|
287
|
+
}
|
|
288
|
+
head.push(next.value);
|
|
289
|
+
sessionId = turnOf(next.value)?.session || undefined;
|
|
290
|
+
}
|
|
278
291
|
const hostKey = host.bindable && this.hostKeyFor
|
|
279
292
|
? await this.hostKeyFor(request)
|
|
280
293
|
: undefined;
|
|
@@ -285,7 +298,20 @@ export class HttpAgentClient {
|
|
|
285
298
|
return {
|
|
286
299
|
run,
|
|
287
300
|
sessionId,
|
|
288
|
-
updates: this.#updates(
|
|
301
|
+
updates: this.#updates((async function* () {
|
|
302
|
+
try {
|
|
303
|
+
yield* head;
|
|
304
|
+
for (;;) {
|
|
305
|
+
const next = await events.next();
|
|
306
|
+
if (next.done)
|
|
307
|
+
return;
|
|
308
|
+
yield next.value;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
finally {
|
|
312
|
+
await events.return?.();
|
|
313
|
+
}
|
|
314
|
+
})(), host, sessionId, run),
|
|
289
315
|
};
|
|
290
316
|
}
|
|
291
317
|
/**
|
|
@@ -329,9 +355,9 @@ export class HttpAgentClient {
|
|
|
329
355
|
throw new Error(`Datalayer did not map the thread to its session (${response.status}).`);
|
|
330
356
|
}
|
|
331
357
|
}
|
|
332
|
-
async *#updates(
|
|
358
|
+
async *#updates(events, host, sessionId, run) {
|
|
333
359
|
const tools = new Map();
|
|
334
|
-
for await (const event of
|
|
360
|
+
for await (const event of events) {
|
|
335
361
|
const turn = turnOf(event);
|
|
336
362
|
if (turn?.turn) {
|
|
337
363
|
run.id = turn.turn;
|