@datalayer/agent-runtimes 1.5.128 → 1.6.5

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.
@@ -63,6 +63,7 @@ import { saidMessageId, useSaidSentence } from '../../voice/captions.js';
63
63
  import { isVoiceInterrupted, lineToSay, } from '../../voice/sayAloud.js';
64
64
  import { isFloatingChatViewMode } from '../viewModes.js';
65
65
  import { ToolApprovalBanner, ToolApprovalDialog, } from '../tools/index.js';
66
+ import { IDENTITY_AUTHORIZATION_REQUIRED, IdentityAuthorizationPanel, declineIdentityAuthorization, identityAuthorizationOf, } from '../tools/IdentityAuthorization.js';
66
67
  import { initialModelId, isOffered, offeredModels as offeredModelsFor, } from './modelChoice.js';
67
68
  // EphemeralDocument statically imports `@datalayer/jupyter-lexical` (which
68
69
  // initialises Lumino-backed nodes on load). Lazy-load it so notebook-only chats
@@ -1108,6 +1109,8 @@ showToolApprovalBanner = true, pendingApprovals: pendingApprovalsProp, onApprove
1108
1109
  */
1109
1110
  const [conversation, setConversation] = useState(() => emptyConversation(BROWSER_LIMITS));
1110
1111
  const conversationRef = useRef(conversation);
1112
+ // The grants the turn's tools wait for (ID-10), until it ends.
1113
+ const [identityAuthorizations, setIdentityAuthorizations] = useState([]);
1111
1114
  // Whether anything has changed it yet: a store is not written over by the
1112
1115
  // empty conversation a chat mounts with.
1113
1116
  const conversationTouchedRef = useRef(false);
@@ -2847,6 +2850,14 @@ showToolApprovalBanner = true, pendingApprovals: pendingApprovalsProp, onApprove
2847
2850
  if (event.activity) {
2848
2851
  voiceSayRef.current?.(event.activity);
2849
2852
  }
2853
+ if (event.activity?.type === IDENTITY_AUTHORIZATION_REQUIRED) {
2854
+ const authorization = identityAuthorizationOf(event.activity.data);
2855
+ if (authorization) {
2856
+ setIdentityAuthorizations(shown => shown.some(a => a.id === authorization.id)
2857
+ ? shown
2858
+ : [...shown, authorization]);
2859
+ }
2860
+ }
2850
2861
  read();
2851
2862
  // A running row said again with its display (VS-24): the host
2852
2863
  // drawing it elsewhere follows it as it streams.
@@ -2913,12 +2924,14 @@ showToolApprovalBanner = true, pendingApprovals: pendingApprovalsProp, onApprove
2913
2924
  }
2914
2925
  suppressAssistantTextForToolOnlyRef.current = false;
2915
2926
  pendingToolExecutionsRef.current = 0;
2927
+ setIdentityAuthorizations([]);
2916
2928
  setIsLoading(false);
2917
2929
  setIsStreaming(false);
2918
2930
  agentRuntimeStore.getState().requestRefresh(activeAgentId);
2919
2931
  break;
2920
2932
  case 'error':
2921
2933
  console.error('[ChatBase] Protocol error:', event.error);
2934
+ setIdentityAuthorizations([]);
2922
2935
  recorderRef.current?.recorder.turnEnded({
2923
2936
  error: event.error?.message ?? 'error',
2924
2937
  });
@@ -4046,7 +4059,10 @@ showToolApprovalBanner = true, pendingApprovals: pendingApprovalsProp, onApprove
4046
4059
  onBack: () => setShowDetails(false),
4047
4060
  } }) })), showToolApprovalBanner &&
4048
4061
  pendingApprovals &&
4049
- pendingApprovals.length > 0 && (_jsx(ToolApprovalBannerSection, { pendingApprovals: pendingApprovals, onApprove: handleBannerApprove, onReject: handleBannerReject })), showErrors && error && (_jsxs(Box, { display: "flex", alignItems: "center", gap: 2, p: padding, bg: "danger.subtle", borderBottom: "1px solid", borderColor: "danger.muted", children: [_jsx(AlertIcon, { size: 16 }), _jsx(Text, { sx: { color: 'danger.fg', fontSize: 1 }, children: error.message })] })), surfaceVisible ? (_jsxs(Box, { flex: 1, minHeight: 0, display: "flex", overflow: "hidden", position: "relative", children: [_jsx(Box, { flex: 1, minWidth: 0, minHeight: 0, display: "flex", flexDirection: "column", overflow: "hidden", sx: surfaceChatFloating
4062
+ pendingApprovals.length > 0 && (_jsx(ToolApprovalBannerSection, { pendingApprovals: pendingApprovals, onApprove: handleBannerApprove, onReject: handleBannerReject })), _jsx(IdentityAuthorizationPanel, { authorizations: identityAuthorizations, agentName: title || activeAgentId, onDecline: authorization => {
4063
+ setIdentityAuthorizations(shown => shown.filter(a => a.id !== authorization.id));
4064
+ declineIdentityAuthorization(wsBaseUrl, authorization.id, protocol?.authToken).catch(refused => console.warn('[ChatBase]', refused));
4065
+ } }), showErrors && error && (_jsxs(Box, { display: "flex", alignItems: "center", gap: 2, p: padding, bg: "danger.subtle", borderBottom: "1px solid", borderColor: "danger.muted", children: [_jsx(AlertIcon, { size: 16 }), _jsx(Text, { sx: { color: 'danger.fg', fontSize: 1 }, children: error.message })] })), surfaceVisible ? (_jsxs(Box, { flex: 1, minHeight: 0, display: "flex", overflow: "hidden", position: "relative", children: [_jsx(Box, { flex: 1, minWidth: 0, minHeight: 0, display: "flex", flexDirection: "column", overflow: "hidden", sx: surfaceChatFloating
4050
4066
  ? null
4051
4067
  : surfaceCollapsed
4052
4068
  ? null
@@ -65,6 +65,7 @@ export { ToolCallDisplay, type ToolCallDisplayProps } from './tools';
65
65
  export { ICON_PACKAGES, SpecMark, hasMark, marksOfFrontendTool, marksOfMcpServer, marksOfRuntimeTool, marksOfSkill, marksOfToolCall, parseIconRef, useMarkIcon, type IconPackage, type IconRef, type MarkIcon, type MarkedMcpServer, type Marks, type SpecMarkProps, type ToolKind, type ToolMarks, } from './marks';
66
66
  export { ToolApprovalDialog, useToolApprovalDialog, type ToolApprovalDialogProps, } from './tools/ToolApprovalDialog';
67
67
  export { ToolApprovalBanner, type ToolApprovalBannerProps, type PendingApproval, } from './tools/ToolApprovalBanner';
68
+ export { IDENTITY_AUTHORIZATION_REQUIRED, IdentityAuthorizationPanel, declineIdentityAuthorization, identityAuthorizationOf, type IdentityAuthorization, type IdentityAuthorizationPanelProps, } from './tools/IdentityAuthorization';
68
69
  export { Chat, type ChatProps, type ChatSessionActions } from './Chat';
69
70
  export { ChatFloating, type ChatFloatingProps } from './ChatFloating';
70
71
  export { ChatInline, type ChatInlineProps, type ChatInlineProtocolConfig, } from './ChatInline';
package/lib/chat/index.js CHANGED
@@ -78,6 +78,7 @@ export { ToolCallDisplay } from './tools/index.js';
78
78
  export { ICON_PACKAGES, SpecMark, hasMark, marksOfFrontendTool, marksOfMcpServer, marksOfRuntimeTool, marksOfSkill, marksOfToolCall, parseIconRef, useMarkIcon, } from './marks/index.js';
79
79
  export { ToolApprovalDialog, useToolApprovalDialog, } from './tools/ToolApprovalDialog.js';
80
80
  export { ToolApprovalBanner, } from './tools/ToolApprovalBanner.js';
81
+ export { IDENTITY_AUTHORIZATION_REQUIRED, IdentityAuthorizationPanel, declineIdentityAuthorization, identityAuthorizationOf, } from './tools/IdentityAuthorization.js';
81
82
  // Components - Transport-agnostic chat
82
83
  export { Chat } from './Chat.js';
83
84
  export { ChatFloating } from './ChatFloating.js';
@@ -0,0 +1,41 @@
1
+ /** The custom event's name the runtime emits. */
2
+ export declare const IDENTITY_AUTHORIZATION_REQUIRED = "identity.authorization_required";
3
+ /** A grant a tool waits for. */
4
+ export interface IdentityAuthorization {
5
+ /** The id the decline is sent with. */
6
+ id: string;
7
+ /** The agent that asks. */
8
+ agent: string;
9
+ /** The provider to connect (`github`, `google`). */
10
+ provider: string;
11
+ /** The scopes asked for. */
12
+ scopes: string[];
13
+ /** Where the person grants it. */
14
+ url: string;
15
+ }
16
+ /**
17
+ * The authorization a custom event's value carries, or `null` when it is not
18
+ * one (a URL that is not http(s) is never opened).
19
+ */
20
+ export declare function identityAuthorizationOf(value: unknown): IdentityAuthorization | null;
21
+ /** Props of {@link IdentityAuthorizationPanel}. */
22
+ export interface IdentityAuthorizationPanelProps {
23
+ /** The grants the turn waits for. */
24
+ authorizations: IdentityAuthorization[];
25
+ /** The agent's name when the event does not carry one. */
26
+ agentName?: string;
27
+ /** Called with an authorization the person declines. */
28
+ onDecline: (authorization: IdentityAuthorization) => void;
29
+ /** Opens a URL in a new window (`window.open` by default). */
30
+ openWindow?: (url: string) => void;
31
+ }
32
+ /**
33
+ * The grants a turn waits for, each with *Connect* and *Decline*.
34
+ */
35
+ export declare function IdentityAuthorizationPanel({ authorizations, agentName, onDecline, openWindow, }: IdentityAuthorizationPanelProps): import("react").JSX.Element | null;
36
+ /**
37
+ * Tell the runtime the person declined: the tool call ends with a sentence.
38
+ *
39
+ * `baseUrl` is the runtime's (no `/api/v1`).
40
+ */
41
+ export declare function declineIdentityAuthorization(baseUrl: string, id: string, authToken?: string, fetcher?: typeof fetch): Promise<void>;
@@ -0,0 +1,76 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2025-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ /**
7
+ * A third party's grant a tool waits for, drawn as an approval (ID-10).
8
+ *
9
+ * The runtime emits `identity.authorization_required` (an AG-UI custom event)
10
+ * while a tool waits for the person to grant a provider (GitHub, Google…):
11
+ * the agent, the provider, the scopes and the authorization URL. *Connect*
12
+ * opens the URL in a new window, where the person grants it, and the tool
13
+ * carries on once they have; *Decline* ends the tool call with a sentence.
14
+ *
15
+ * @module chat/tools/IdentityAuthorization
16
+ */
17
+ import { Box } from '@datalayer/primer-addons';
18
+ import { Button, Text } from '@primer/react';
19
+ import { KeyIcon, LinkExternalIcon, XIcon } from '@primer/octicons-react';
20
+ import { useChatWords } from '../ChatLanguage.js';
21
+ /** The custom event's name the runtime emits. */
22
+ export const IDENTITY_AUTHORIZATION_REQUIRED = 'identity.authorization_required';
23
+ /**
24
+ * The authorization a custom event's value carries, or `null` when it is not
25
+ * one (a URL that is not http(s) is never opened).
26
+ */
27
+ export function identityAuthorizationOf(value) {
28
+ if (!value || typeof value !== 'object') {
29
+ return null;
30
+ }
31
+ const v = value;
32
+ const url = typeof v.url === 'string' ? v.url : '';
33
+ if (typeof v.id !== 'string' ||
34
+ !v.id ||
35
+ typeof v.provider !== 'string' ||
36
+ !v.provider ||
37
+ !/^https?:\/\//.test(url)) {
38
+ return null;
39
+ }
40
+ return {
41
+ id: v.id,
42
+ agent: typeof v.agent === 'string' ? v.agent : '',
43
+ provider: v.provider,
44
+ scopes: Array.isArray(v.scopes)
45
+ ? v.scopes.filter((s) => typeof s === 'string')
46
+ : [],
47
+ url,
48
+ };
49
+ }
50
+ function openInNewWindow(url) {
51
+ window.open(url, '_blank', 'noopener,noreferrer');
52
+ }
53
+ /**
54
+ * The grants a turn waits for, each with *Connect* and *Decline*.
55
+ */
56
+ export function IdentityAuthorizationPanel({ authorizations, agentName, onDecline, openWindow = openInNewWindow, }) {
57
+ const words = useChatWords();
58
+ if (authorizations.length === 0) {
59
+ return null;
60
+ }
61
+ return (_jsx(Box, { borderBottom: "1px solid", borderColor: "attention.muted", bg: "attention.subtle", px: 3, py: 2, children: authorizations.map(authorization => (_jsxs(Box, { role: "alertdialog", "aria-label": words.connectToContinue(authorization.provider), display: "flex", alignItems: "center", justifyContent: "space-between", gap: 2, py: 1, children: [_jsxs(Box, { display: "flex", alignItems: "flex-start", gap: 2, children: [_jsx(KeyIcon, { size: 16 }), _jsxs(Box, { children: [_jsx(Text, { as: "p", sx: { fontWeight: 'semibold', fontSize: 1, m: 0 }, children: words.connectToContinue(authorization.provider) }), _jsx(Text, { as: "p", sx: { color: 'fg.muted', fontSize: 0, m: 0 }, children: words.connectAsks(authorization.agent || agentName || 'The agent', authorization.scopes.join(', ') || authorization.provider) })] })] }), _jsxs(Box, { display: "flex", gap: 1, children: [_jsx(Button, { size: "small", variant: "primary", leadingVisual: LinkExternalIcon, onClick: () => openWindow(authorization.url), children: words.connect }), _jsx(Button, { size: "small", variant: "default", leadingVisual: XIcon, onClick: () => onDecline(authorization), children: words.decline })] })] }, authorization.id))) }));
62
+ }
63
+ /**
64
+ * Tell the runtime the person declined: the tool call ends with a sentence.
65
+ *
66
+ * `baseUrl` is the runtime's (no `/api/v1`).
67
+ */
68
+ export async function declineIdentityAuthorization(baseUrl, id, authToken, fetcher = fetch) {
69
+ const response = await fetcher(`${baseUrl}/api/v1/configure/identity/authorizations/${encodeURIComponent(id)}/decline`, {
70
+ method: 'POST',
71
+ headers: authToken ? { Authorization: `Bearer ${authToken}` } : {},
72
+ });
73
+ if (!response.ok) {
74
+ throw new Error(`The decline of ${id} was refused (${response.status}): the tool may already have its answer.`);
75
+ }
76
+ }
@@ -8,3 +8,4 @@ export { SubagentActivity, type SubagentActivityProps, } from './SubagentActivit
8
8
  export { A2AAgentDialog, a2aAgentDetails, agentCardUrl, useAgentCard, type A2AAgentDetails, type A2AAgentDialogProps, type AgentCardFetch, } from './A2AAgentDialog';
9
9
  export { ToolApprovalBanner, type ToolApprovalBannerProps, type PendingApproval, } from './ToolApprovalBanner';
10
10
  export { ToolApprovalDialog, useToolApprovalDialog, type ToolApprovalDialogProps, } from './ToolApprovalDialog';
11
+ export { IDENTITY_AUTHORIZATION_REQUIRED, IdentityAuthorizationPanel, declineIdentityAuthorization, identityAuthorizationOf, type IdentityAuthorization, type IdentityAuthorizationPanelProps, } from './IdentityAuthorization';
@@ -12,3 +12,4 @@ export { SubagentActivity, } from './SubagentActivity.js';
12
12
  export { A2AAgentDialog, a2aAgentDetails, agentCardUrl, useAgentCard, } from './A2AAgentDialog.js';
13
13
  export { ToolApprovalBanner, } from './ToolApprovalBanner.js';
14
14
  export { ToolApprovalDialog, useToolApprovalDialog, } from './ToolApprovalDialog.js';
15
+ export { IDENTITY_AUTHORIZATION_REQUIRED, IdentityAuthorizationPanel, declineIdentityAuthorization, identityAuthorizationOf, } from './IdentityAuthorization.js';
@@ -78,6 +78,10 @@ export type ChatWords = {
78
78
  arguments: string;
79
79
  approvalWarning: string;
80
80
  rememberChoice: string;
81
+ connectToContinue: (provider: string) => string;
82
+ connectAsks: (agent: string, scopes: string) => string;
83
+ connect: string;
84
+ decline: string;
81
85
  /** An approval waits and cannot be answered in the balloon itself. */
82
86
  waitingOpen: string;
83
87
  /** It waits on the person's yes. */
package/lib/chat/words.js CHANGED
@@ -77,6 +77,10 @@ export const CHAT_WORDS = {
77
77
  arguments: 'Arguments:',
78
78
  approvalWarning: 'This tool will perform an action on your behalf. Please review the arguments before approving.',
79
79
  rememberChoice: 'Remember my choice for this tool',
80
+ connectToContinue: provider => `Connect ${provider} to continue`,
81
+ connectAsks: (agent, scopes) => `${agent} asks for access to ${scopes}.`,
82
+ connect: 'Connect',
83
+ decline: 'Decline',
80
84
  waitingOpen: 'Waiting for you — open the conversation to answer.',
81
85
  waitingForYou: 'Waiting for you',
82
86
  paused: 'Paused — it answers again once it is resumed.',
@@ -151,6 +155,10 @@ export const CHAT_WORDS = {
151
155
  arguments: 'Arguments :',
152
156
  approvalWarning: 'Cet outil va agir en votre nom. Vérifiez ses arguments avant de l’approuver.',
153
157
  rememberChoice: 'Mémoriser mon choix pour cet outil',
158
+ connectToContinue: provider => `Connectez ${provider} pour continuer`,
159
+ connectAsks: (agent, scopes) => `${agent} demande l’accès à ${scopes}.`,
160
+ connect: 'Connecter',
161
+ decline: 'Refuser',
154
162
  waitingOpen: 'Il vous attend — ouvrez la conversation pour répondre.',
155
163
  waitingForYou: 'Il vous attend',
156
164
  paused: 'En pause — il répondra de nouveau une fois relancé.',
@@ -225,6 +233,10 @@ export const CHAT_WORDS = {
225
233
  arguments: 'Argumentos:',
226
234
  approvalWarning: 'Esta herramienta actuará en tu nombre. Revisa sus argumentos antes de aprobarla.',
227
235
  rememberChoice: 'Recordar mi elección para esta herramienta',
236
+ connectToContinue: provider => `Conecta ${provider} para continuar`,
237
+ connectAsks: (agent, scopes) => `${agent} pide acceso a ${scopes}.`,
238
+ connect: 'Conectar',
239
+ decline: 'Rechazar',
228
240
  waitingOpen: 'Te está esperando: abre la conversación para responder.',
229
241
  waitingForYou: 'Te está esperando',
230
242
  paused: 'En pausa: responderá de nuevo cuando se reanude.',
@@ -299,6 +311,10 @@ export const CHAT_WORDS = {
299
311
  arguments: 'Argumente:',
300
312
  approvalWarning: 'Dieses Werkzeug handelt in deinem Namen. Prüfe seine Argumente, bevor du es freigibst.',
301
313
  rememberChoice: 'Meine Wahl für dieses Werkzeug merken',
314
+ connectToContinue: provider => `${provider} verbinden, um fortzufahren`,
315
+ connectAsks: (agent, scopes) => `${agent} bittet um Zugriff auf ${scopes}.`,
316
+ connect: 'Verbinden',
317
+ decline: 'Ablehnen',
302
318
  waitingOpen: 'Wartet auf dich – öffne das Gespräch, um zu antworten.',
303
319
  waitingForYou: 'Wartet auf dich',
304
320
  paused: 'Pausiert – antwortet wieder, sobald es fortgesetzt wird.',
@@ -373,6 +389,10 @@ export const CHAT_WORDS = {
373
389
  arguments: 'Argomenti:',
374
390
  approvalWarning: 'Questo strumento agirà per tuo conto. Controlla i suoi argomenti prima di approvarlo.',
375
391
  rememberChoice: 'Ricorda la mia scelta per questo strumento',
392
+ connectToContinue: provider => `Collega ${provider} per continuare`,
393
+ connectAsks: (agent, scopes) => `${agent} chiede l’accesso a ${scopes}.`,
394
+ connect: 'Collega',
395
+ decline: 'Rifiuta',
376
396
  waitingOpen: 'Ti sta aspettando: apri la conversazione per rispondere.',
377
397
  waitingForYou: 'Ti sta aspettando',
378
398
  paused: 'In pausa: risponderà di nuovo quando verrà ripreso.',
@@ -447,6 +467,10 @@ export const CHAT_WORDS = {
447
467
  arguments: 'Argumentos:',
448
468
  approvalWarning: 'Esta ferramenta vai agir em seu nome. Revise os argumentos antes de aprovar.',
449
469
  rememberChoice: 'Lembrar minha escolha para esta ferramenta',
470
+ connectToContinue: provider => `Conecte ${provider} para continuar`,
471
+ connectAsks: (agent, scopes) => `${agent} pede acesso a ${scopes}.`,
472
+ connect: 'Conectar',
473
+ decline: 'Recusar',
450
474
  waitingOpen: 'Esperando por você — abra a conversa para responder.',
451
475
  waitingForYou: 'Esperando por você',
452
476
  paused: 'Em pausa — volta a responder quando for retomado.',