@datalayer/agent-runtimes 1.6.40 → 1.6.42

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.
@@ -80,6 +80,34 @@ export declare function assistantStateOfTurn(turn: ChatTurnSnapshot, presence: P
80
80
  arriving?: boolean;
81
81
  leaving?: boolean;
82
82
  }): AssistantState;
83
+ /** What a click on the character found of its workspace's composer. */
84
+ export type ComposerReach = 'focused' | 'not-ready' | 'none';
85
+ /**
86
+ * Its own workspace's composer: the nearest one around the character's place
87
+ * in the page, never another chat's on the same page (the landing's own, a
88
+ * panel kept mounted out of sight). The first ancestor of `from` that holds
89
+ * one; the page's first when `from` is not given.
90
+ */
91
+ export declare function ownComposer(from?: HTMLElement | null): HTMLElement | null;
92
+ /**
93
+ * Take the person to its workspace's composer: the caret in it, scrolled into
94
+ * view, when one is seen there (`focused`); `not-ready` while it cannot be
95
+ * typed in yet (its runtime is still being assigned); `none` when there is
96
+ * none it can reach — none on the page, or one out of sight in a frame or a
97
+ * closed panel — and the character's own prompt is offered instead.
98
+ */
99
+ export declare function focusComposer(from?: HTMLElement | null): ComposerReach;
100
+ /**
101
+ * How far from the window's bottom the character stands in its corner: at
102
+ * `CORNER`, or just above its own conversation's composer when that composer
103
+ * reaches the corner. Without this it stood over the composer, and stepped
104
+ * aside for it (T-27) for as long as the composer stayed there — after the
105
+ * first message, for good, as the composer moved down into its corner.
106
+ */
107
+ export declare function cornerBottomAbove(composers: readonly Pick<DOMRect, 'left' | 'right' | 'top' | 'bottom'>[], view: {
108
+ width: number;
109
+ height: number;
110
+ }, size: number): number;
83
111
  export declare function LoopAssistant({ app, person, appId, decisions, balloon: displayGiven, workspace, }: LoopAssistantConfig): JSX.Element | null;
84
112
  export declare const LoopAssistantPlugin: import("@datalayer/reactor").ReactorPlugin<LoopAssistantConfig, unknown, unknown>;
85
113
  export default LoopAssistantPlugin;
@@ -1,8 +1,8 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { definePlugin, signal } from '@datalayer/reactor';
4
4
  import { useContributions, useSignalValue } from '@datalayer/reactor/react';
5
- import { Text } from '@primer/react';
5
+ import { Button, Text, Textarea } from '@primer/react';
6
6
  import { Box } from '@datalayer/primer-addons';
7
7
  import { useIAMStore } from '@datalayer/core/lib/state/substates/IAMState.js';
8
8
  import { pageLayoutPanelOpen, togglePagePanel, } from '@datalayer/primer-addons/lib/reactor/index.js';
@@ -86,11 +86,152 @@ function WaitingApprovals({ appId, onWaiting, }) {
86
86
  useEffect(() => () => onWaiting(undefined), [onWaiting]);
87
87
  return null;
88
88
  }
89
- /** Take the person to the workspace's composer. */
90
- function focusComposer() {
91
- const composer = document.querySelector('[data-chat-composer] textarea, [data-chat-composer] [contenteditable="true"]');
92
- composer?.focus();
89
+ /** The composer's editable part: a textarea, or Lexical's editable root. */
90
+ const COMPOSER_EDITABLE = '[data-chat-composer] textarea, [data-chat-composer] [contenteditable]';
91
+ /**
92
+ * Its own workspace's composer: the nearest one around the character's place
93
+ * in the page, never another chat's on the same page (the landing's own, a
94
+ * panel kept mounted out of sight). The first ancestor of `from` that holds
95
+ * one; the page's first when `from` is not given.
96
+ */
97
+ export function ownComposer(from) {
98
+ for (let node = from?.parentElement; node; node = node.parentElement) {
99
+ const found = node.querySelector(COMPOSER_EDITABLE);
100
+ if (found) {
101
+ return found;
102
+ }
103
+ }
104
+ return from ? null : document.querySelector(COMPOSER_EDITABLE);
105
+ }
106
+ /** Whether a person sees the element: on screen and not covered there. */
107
+ function seen(element) {
108
+ // No boxes at all: a page without layout (a test's DOM); an element that
109
+ // is not displayed takes no focus, which the caller has already checked.
110
+ if (element.getClientRects().length === 0) {
111
+ return true;
112
+ }
113
+ const box = element.getBoundingClientRect();
114
+ if (box.width <= 0 || box.height <= 0) {
115
+ return false;
116
+ }
117
+ const x = box.left + Math.min(box.width / 2, 24);
118
+ const y = box.top + box.height / 2;
119
+ if (x < 0 || y < 0 || x > window.innerWidth || y > window.innerHeight) {
120
+ return false;
121
+ }
122
+ // Without layout (a test's DOM) nothing is said to cover it.
123
+ const top = document.elementFromPoint?.(x, y);
124
+ return !top || element.contains(top) || top.contains(element);
125
+ }
126
+ /**
127
+ * Take the person to its workspace's composer: the caret in it, scrolled into
128
+ * view, when one is seen there (`focused`); `not-ready` while it cannot be
129
+ * typed in yet (its runtime is still being assigned); `none` when there is
130
+ * none it can reach — none on the page, or one out of sight in a frame or a
131
+ * closed panel — and the character's own prompt is offered instead.
132
+ */
133
+ export function focusComposer(from) {
134
+ const editable = ownComposer(from);
135
+ if (!editable) {
136
+ return 'none';
137
+ }
138
+ const disabled = (editable instanceof HTMLTextAreaElement && editable.disabled) ||
139
+ editable.getAttribute('contenteditable') === 'false';
140
+ if (disabled) {
141
+ return 'not-ready';
142
+ }
143
+ editable.scrollIntoView?.({ block: 'nearest' });
144
+ editable.focus();
145
+ return document.activeElement === editable && seen(editable)
146
+ ? 'focused'
147
+ : 'none';
148
+ }
149
+ /** The room the character keeps from the window's edges, in pixels. */
150
+ const CORNER = 24;
151
+ /** The gap between the character and a composer it stands above. */
152
+ const ABOVE_COMPOSER_GAP = 8;
153
+ /**
154
+ * How far from the window's bottom the character stands in its corner: at
155
+ * `CORNER`, or just above its own conversation's composer when that composer
156
+ * reaches the corner. Without this it stood over the composer, and stepped
157
+ * aside for it (T-27) for as long as the composer stayed there — after the
158
+ * first message, for good, as the composer moved down into its corner.
159
+ */
160
+ export function cornerBottomAbove(composers, view, size) {
161
+ const left = view.width - CORNER - size;
162
+ const right = view.width - CORNER;
163
+ let bottom = CORNER;
164
+ for (const box of composers) {
165
+ const meets = box.right > left &&
166
+ box.left < right &&
167
+ box.bottom > view.height - CORNER - size &&
168
+ box.top < view.height - CORNER;
169
+ if (meets) {
170
+ bottom = Math.max(bottom, view.height - box.top + ABOVE_COMPOSER_GAP);
171
+ }
172
+ }
173
+ return Math.round(bottom);
93
174
  }
175
+ /** How often the composer's place is read: it grows as words are typed. */
176
+ const COMPOSER_CHECK_MS = 400;
177
+ /** `cornerBottomAbove`, read from the page while `enabled`. */
178
+ function useCornerBottom(enabled, size) {
179
+ const [bottom, setBottom] = useState(CORNER);
180
+ useEffect(() => {
181
+ if (!enabled) {
182
+ setBottom(CORNER);
183
+ return;
184
+ }
185
+ const check = () => {
186
+ const boxes = Array.from(document.querySelectorAll('[data-chat-composer]'))
187
+ .map(element => element.getBoundingClientRect())
188
+ .filter(box => box.width > 0 && box.height > 0);
189
+ setBottom(cornerBottomAbove(boxes, { width: window.innerWidth, height: window.innerHeight }, size));
190
+ };
191
+ check();
192
+ const timer = window.setInterval(check, COMPOSER_CHECK_MS);
193
+ window.addEventListener('resize', check);
194
+ return () => {
195
+ window.clearInterval(timer);
196
+ window.removeEventListener('resize', check);
197
+ };
198
+ }, [enabled, size]);
199
+ return bottom;
200
+ }
201
+ /** The height of the character's own prompt, for its place above a dragged character. */
202
+ const PROMPT_HEIGHT = 120;
203
+ /**
204
+ * The character's own prompt (13 November 2026): opened by a click when its
205
+ * page has no composer it can reach — the Playground's frame, a closed panel —
206
+ * so that a click always leads somewhere to type. Sent through the
207
+ * workspace's `submit`, as its composer sends; Escape closes it.
208
+ */
209
+ function AssistantPrompt({ place, label, send, onSend, onClose, }) {
210
+ const [text, setText] = useState('');
211
+ const ref = useRef(null);
212
+ useEffect(() => {
213
+ ref.current?.focus();
214
+ }, []);
215
+ const message = text.trim();
216
+ return (_jsxs(Box, { as: "form", "data-assistant-prompt": "", position: "fixed", ...place, zIndex: 1001, width: 320, maxWidth: "calc(100vw - 32px)", p: 2, borderRadius: 2, border: "1px solid", borderColor: "border.default", bg: "canvas.overlay", boxShadow: "shadow.large", onSubmit: (event) => {
217
+ event.preventDefault();
218
+ if (message) {
219
+ onSend(message);
220
+ }
221
+ }, children: [_jsx(Textarea, { ref: ref, block: true, rows: 3, resize: "none", "aria-label": label, placeholder: label, value: text, onChange: event => setText(event.target.value), onKeyDown: event => {
222
+ if (event.key === 'Escape') {
223
+ onClose();
224
+ }
225
+ else if (event.key === 'Enter' && !event.shiftKey) {
226
+ event.preventDefault();
227
+ if (message) {
228
+ onSend(message);
229
+ }
230
+ }
231
+ } }), _jsx(Box, { display: "flex", justifyContent: "flex-end", mt: 2, children: _jsx(Button, { type: "submit", size: "small", variant: "primary", disabled: !message, children: send }) })] }));
232
+ }
233
+ /** How long *You can write to me as soon as I am ready* stays, in ms. */
234
+ const NOT_READY_MS = 6000;
94
235
  export function LoopAssistant({ app, person, appId, decisions, balloon: displayGiven = 'history', workspace, }) {
95
236
  const chatText = useChatWords();
96
237
  // The balloon's display, as its menu chose it; the Appspec's until then.
@@ -188,6 +329,20 @@ export function LoopAssistant({ app, person, appId, decisions, balloon: displayG
188
329
  }, [sandboxService, target, snapshot, agentId]);
189
330
  const stageRef = useRef(null);
190
331
  const drag = useViewportDrag(stageRef, { whole: true });
332
+ // In its corner, above its own conversation's composer when that reaches
333
+ // the corner (the conversation on the page, not in a panel).
334
+ const cornerBottom = useCornerBottom(!onPageLayout && !drag.position, SIZE);
335
+ // Clicked while its composer cannot be typed in yet: said in its balloon.
336
+ const [notReady, setNotReady] = useState(false);
337
+ // Its own prompt is open: the page has no composer it can reach.
338
+ const [asking, setAsking] = useState(false);
339
+ useEffect(() => {
340
+ if (!notReady) {
341
+ return;
342
+ }
343
+ const timer = setTimeout(() => setNotReady(false), NOT_READY_MS);
344
+ return () => clearTimeout(timer);
345
+ }, [notReady]);
191
346
  // Offered only when the agent decides: the runtime says it.
192
347
  const decide = useDecisionAsker(decisions?.serverUrl
193
348
  ? {
@@ -247,20 +402,40 @@ export function LoopAssistant({ app, person, appId, decisions, balloon: displayG
247
402
  setFresh(false);
248
403
  },
249
404
  })
250
- : withHistory({ text: 'Click me to open the conversation.' });
405
+ : notReady
406
+ ? { text: chatText.notReadyToWrite }
407
+ : withHistory({
408
+ // On a page layout the conversation opens in its
409
+ // panel; elsewhere it is on the page, its composer
410
+ // below, where a click puts the caret.
411
+ text: onPageLayout
412
+ ? chatText.clickToOpen
413
+ : chatText.clickToWrite,
414
+ });
251
415
  const insist = state === 'greeting' ||
252
416
  presence === 'waiting' ||
253
417
  (!!approval && state !== 'paused') ||
254
418
  !!tool ||
255
419
  (current && atWork) ||
256
- (unheard && (state === 'speaking' || fresh));
420
+ (unheard && (state === 'speaking' || fresh)) ||
421
+ notReady;
257
422
  const onToggle = () => {
258
423
  if (onPageLayout) {
259
424
  togglePagePanel();
425
+ return;
426
+ }
427
+ // Its words heard once the caret is in the composer.
428
+ if (saying) {
429
+ setHeardId(saying.id);
260
430
  }
261
- else {
262
- focusComposer();
431
+ if (asking) {
432
+ setAsking(false);
433
+ return;
263
434
  }
435
+ const reach = focusComposer(stageRef.current);
436
+ setNotReady(reach === 'not-ready');
437
+ // No composer of its own in sight: its own prompt, beside it.
438
+ setAsking(reach === 'none' && Boolean(workspace?.submit));
264
439
  };
265
440
  const onDismiss = (next) => {
266
441
  keepAway(next);
@@ -270,9 +445,23 @@ export function LoopAssistant({ app, person, appId, decisions, balloon: displayG
270
445
  setAway(next);
271
446
  }, 600);
272
447
  };
273
- return (_jsxs(_Fragment, { children: [appId && signedIn ? (_jsx(WaitingApprovals, { appId: appId, onWaiting: setApproval })) : null, _jsx(AssistantStage, { character: chosen.character, state: state, size: SIZE, place: drag.position
448
+ return (_jsxs(_Fragment, { children: [appId && signedIn ? (_jsx(WaitingApprovals, { appId: appId, onWaiting: setApproval })) : null, asking && workspace?.submit ? (_jsx(AssistantPrompt, { place: drag.position
449
+ ? {
450
+ left: `${drag.position.left}px`,
451
+ top: `${Math.max(8, drag.position.top - PROMPT_HEIGHT - 8)}px`,
452
+ }
453
+ : {
454
+ right: `${CORNER}px`,
455
+ bottom: `${cornerBottom + SIZE + 8}px`,
456
+ }, label: chatText.writeToMe, send: chatText.send, onSend: message => {
457
+ setAsking(false);
458
+ void workspace.submit(message);
459
+ }, onClose: () => setAsking(false) })) : null, _jsx(AssistantStage, { character: chosen.character, state: state, size: SIZE, place: drag.position
274
460
  ? { left: `${drag.position.left}px`, top: `${drag.position.top}px` }
275
- : { right: '24px', bottom: '24px' }, stageRef: stageRef, onDragStart: drag.onHandlePointerDown, open: open, onToggle: onToggle, balloon: balloon, balloonDisplay: display, insist: insist, onDismiss: onDismiss, decide: decide, onResetPosition: drag.position ? drag.reset : undefined, onBalloonDisplayChange: setChosenDisplay, about: agentAbout, sandbox: agentSandbox, contextMenu: menuContributions })] }));
461
+ : { right: `${CORNER}px`, bottom: `${cornerBottom}px` }, stageRef: stageRef, onDragStart: drag.onHandlePointerDown, open: open || asking, onToggle: onToggle, balloon: balloon, balloonDisplay: display, insist: insist, onDismiss: onDismiss,
462
+ // Its × hides the balloon; sending it away is in its menu, so the
463
+ // way back to the conversation is never taken by a click on the ×.
464
+ dismissHidesBalloon: true, decide: decide, onResetPosition: drag.position ? drag.reset : undefined, onBalloonDisplayChange: setChosenDisplay, about: agentAbout, sandbox: agentSandbox, contextMenu: menuContributions })] }));
276
465
  }
277
466
  export const LoopAssistantPlugin = definePlugin({
278
467
  name: LOOP_ASSISTANT_PLUGIN_NAME,
@@ -289,6 +289,13 @@ export interface AssistantStageProps {
289
289
  * and its neighbours, not a page somebody is working on.
290
290
  */
291
291
  stayPut?: boolean;
292
+ /**
293
+ * The × beside the character hides its balloon while one is shown, rather
294
+ * than sending the character away: the way back to the conversation
295
+ * stays on the page. The balloon comes back with new words, or when the
296
+ * pointer comes back to the character; sending it away stays in its menu.
297
+ */
298
+ dismissHidesBalloon?: boolean;
292
299
  /**
293
300
  * The agent's own name, used in place of the character's by its menu and
294
301
  * its *Send … away*: `Sales`, where the character is a paper clip.
@@ -307,5 +314,5 @@ export { mouthOpening };
307
314
  * `data-assistant-mouth`, each frame, without drawing the character again.
308
315
  */
309
316
  export declare function useMouth(stageRef: RefObject<HTMLElement | null>, mouthLevel: (() => number) | undefined, speaking: boolean): void;
310
- export declare function AssistantStage({ character, state, size, replay, place, stageRef, onDragStart, open, onToggle, onCharacterClick, onCharacterKeyDown, balloon, insist, onDismiss, ownRef, decide, mouthLevel, stayPut, balloonDisplay, expandTarget, expandOnArrival, suggestions, onSuggestion, inspector, inspectAgent, conversationLabel, onBalloonDisplayChange, onStop, onNewChat, onClear, onChangeCharacter, speech, onResetPosition, about, sandbox, contextMenu, agentName, label, }: AssistantStageProps): JSX.Element;
317
+ export declare function AssistantStage({ character, state, size, replay, place, stageRef, onDragStart, open, onToggle, onCharacterClick, onCharacterKeyDown, balloon, insist, onDismiss, ownRef, decide, mouthLevel, stayPut, dismissHidesBalloon, balloonDisplay, expandTarget, expandOnArrival, suggestions, onSuggestion, inspector, inspectAgent, conversationLabel, onBalloonDisplayChange, onStop, onNewChat, onClear, onChangeCharacter, speech, onResetPosition, about, sandbox, contextMenu, agentName, label, }: AssistantStageProps): JSX.Element;
311
318
  export default AssistantStage;
@@ -371,7 +371,7 @@ export function useMouth(stageRef, mouthLevel, speaking) {
371
371
  };
372
372
  }, [stageRef, mouthLevel, speaking]);
373
373
  }
374
- export function AssistantStage({ character, state, size = 88, replay, place, stageRef, onDragStart, open, onToggle, onCharacterClick, onCharacterKeyDown, balloon, insist = false, onDismiss, ownRef, decide, mouthLevel, stayPut = false, balloonDisplay = 'history', expandTarget, expandOnArrival = false, suggestions, onSuggestion, inspector, inspectAgent, conversationLabel, onBalloonDisplayChange, onStop, onNewChat, onClear, onChangeCharacter, speech, onResetPosition, about, sandbox, contextMenu, agentName, label, }) {
374
+ export function AssistantStage({ character, state, size = 88, replay, place, stageRef, onDragStart, open, onToggle, onCharacterClick, onCharacterKeyDown, balloon, insist = false, onDismiss, ownRef, decide, mouthLevel, stayPut = false, dismissHidesBalloon = false, balloonDisplay = 'history', expandTarget, expandOnArrival = false, suggestions, onSuggestion, inspector, inspectAgent, conversationLabel, onBalloonDisplayChange, onStop, onNewChat, onClear, onChangeCharacter, speech, onResetPosition, about, sandbox, contextMenu, agentName, label, }) {
375
375
  const chatText = useChatWords();
376
376
  // A shipped one by id, a drawing contributed by a plugin (T-24), a
377
377
  // character read from a file (T-26), or a 3D model.
@@ -463,7 +463,21 @@ export function AssistantStage({ character, state, size = 88, replay, place, sta
463
463
  useMouth(stageRef, mouthLevel, state === 'speaking');
464
464
  // A decision being asked, or its answer, keeps the balloon up.
465
465
  const [deciding, setDeciding] = useState(false);
466
- const showBalloon = !aside && !open && !!balloon && (hovered || insist || deciding);
466
+ // The words whose balloon the × hid: hidden until the words change or the
467
+ // pointer comes back to the character.
468
+ const [hushed, setHushed] = useState(null);
469
+ const wasHovered = useRef(hovered);
470
+ useEffect(() => {
471
+ if (hovered && !wasHovered.current) {
472
+ setHushed(null);
473
+ }
474
+ wasHovered.current = hovered;
475
+ }, [hovered]);
476
+ const showBalloon = !aside &&
477
+ !open &&
478
+ !!balloon &&
479
+ !(hushed !== null && balloon.text === hushed && !deciding) &&
480
+ (hovered || insist || deciding);
467
481
  // Suggestions while it waits for a question.
468
482
  const waitsForQuestion = (state === 'idle' || state === 'greeting') &&
469
483
  !balloon?.tool &&
@@ -704,11 +718,19 @@ export function AssistantStage({ character, state, size = 88, replay, place, sta
704
718
  outlineColor: 'var(--focus-outlineColor, var(--fgColor-accent))',
705
719
  outlineOffset: 2,
706
720
  borderRadius: '50%',
707
- }, touchAction: "none", children: [described && (_jsx(Box, { as: "span", id: describedBy, position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", children: `Its avatar: ${characterName}` })), shipped ? (_jsx(shipped.Drawing, { size: size, mode: colorMode, state: state, mouthLevel: mouthLevel })) : model ? (_jsx(Suspense, { fallback: _jsx("span", { "aria-busy": "true", style: { display: 'block', width: size, height: size } }), children: _jsx(Avatar3D, { avatar: model, state: state, size: size, mouthLevel: mouthLevel, aside: aside !== undefined, replay: replay }) })) : (_jsx(SpriteCharacter, { character: character, state: state, size: size, sounds: soundsOn, mouthLevel: mouthLevel }))] }), (hovered || menuOpen) && !aside && state !== 'goodbye' && (_jsx(Box, { position: "absolute", top: "-6px", right: "-6px", children: _jsxs(ActionMenu, { open: menuOpen, onOpenChange: setMenuOpen, children: [_jsx(ActionMenu.Anchor, { children: _jsx(IconButton, { icon: XIcon, "aria-label": `Send ${name} away`, size: "small", variant: "invisible", "data-assistant-dismiss": "", sx: {
721
+ }, touchAction: "none", children: [described && (_jsx(Box, { as: "span", id: describedBy, position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", children: `Its avatar: ${characterName}` })), shipped ? (_jsx(shipped.Drawing, { size: size, mode: colorMode, state: state, mouthLevel: mouthLevel })) : model ? (_jsx(Suspense, { fallback: _jsx("span", { "aria-busy": "true", style: { display: 'block', width: size, height: size } }), children: _jsx(Avatar3D, { avatar: model, state: state, size: size, mouthLevel: mouthLevel, aside: aside !== undefined, replay: replay }) })) : (_jsx(SpriteCharacter, { character: character, state: state, size: size, sounds: soundsOn, mouthLevel: mouthLevel }))] }), dismissHidesBalloon &&
722
+ showBalloon &&
723
+ !menuOpen &&
724
+ balloon &&
725
+ state !== 'goodbye' ? (_jsx(Box, { position: "absolute", top: "-6px", right: "-6px", children: _jsx(IconButton, { icon: XIcon, "aria-label": chatText.hideBalloon, size: "small", variant: "invisible", "data-assistant-hide-balloon": "", onClick: () => setHushed(balloon.text), sx: {
726
+ bg: 'canvas.default',
727
+ borderRadius: '50%',
728
+ boxShadow: 'shadow.small',
729
+ } }) })) : (hovered || menuOpen) && !aside && state !== 'goodbye' ? (_jsx(Box, { position: "absolute", top: "-6px", right: "-6px", children: _jsxs(ActionMenu, { open: menuOpen, onOpenChange: setMenuOpen, children: [_jsx(ActionMenu.Anchor, { children: _jsx(IconButton, { icon: XIcon, "aria-label": `Send ${name} away`, size: "small", variant: "invisible", "data-assistant-dismiss": "", sx: {
708
730
  bg: 'canvas.default',
709
731
  borderRadius: '50%',
710
732
  boxShadow: 'shadow.small',
711
- } }) }), _jsx(ActionMenu.Overlay, { width: "auto", children: _jsx(ActionList, { children: AWAY_CHOICES.map(choice => (_jsx(ActionList.Item, { "data-assistant-away": choice.away, onSelect: () => onDismiss(choice.away), children: choice.label }, choice.away))) }) })] }) })), _jsx(AssistantContextMenu, { at: menuAt, items: menuItems, onClose: closeMenu, returnFocusRef: characterRef, label: `${name}\u2019s menu` }), inspecting && (_jsx(Suspense, { fallback: null, children: _jsx(AgentInspectorDialog, { tracer: inspector ?? null, agent: inspectAgent, title: `${about?.name ?? name} \u00b7 Agent Inspector`, onClose: () => {
733
+ } }) }), _jsx(ActionMenu.Overlay, { width: "auto", children: _jsx(ActionList, { children: AWAY_CHOICES.map(choice => (_jsx(ActionList.Item, { "data-assistant-away": choice.away, onSelect: () => onDismiss(choice.away), children: choice.label }, choice.away))) }) })] }) })) : null, _jsx(AssistantContextMenu, { at: menuAt, items: menuItems, onClose: closeMenu, returnFocusRef: characterRef, label: `${name}\u2019s menu` }), inspecting && (_jsx(Suspense, { fallback: null, children: _jsx(AgentInspectorDialog, { tracer: inspector ?? null, agent: inspectAgent, title: `${about?.name ?? name} \u00b7 Agent Inspector`, onClose: () => {
712
734
  setInspecting(false);
713
735
  characterRef.current?.focus();
714
736
  } }) })), detailing === 'agent' && about && (_jsx(Suspense, { fallback: null, children: _jsx(AgentDetailsDialog, { about: about, name: name, onClose: () => {
@@ -89,6 +89,16 @@ export type ChatWords = {
89
89
  decline: string;
90
90
  /** An approval waits and cannot be answered in the balloon itself. */
91
91
  waitingOpen: string;
92
+ /** Its invitation when the conversation opens in a panel. */
93
+ clickToOpen: string;
94
+ /** Its invitation when the conversation is on the page, its composer below. */
95
+ clickToWrite: string;
96
+ /** Clicked while its composer cannot be typed in yet. */
97
+ notReadyToWrite: string;
98
+ /** The × that hides the balloon. */
99
+ hideBalloon: string;
100
+ /** Its own prompt, opened when no composer is in reach. */
101
+ writeToMe: string;
92
102
  /** It waits on the person's yes. */
93
103
  waitingForYou: string;
94
104
  /** Its deployment is paused. */
package/lib/chat/words.js CHANGED
@@ -83,6 +83,11 @@ export const CHAT_WORDS = {
83
83
  connect: 'Connect',
84
84
  decline: 'Decline',
85
85
  waitingOpen: 'Waiting for you — open the conversation to answer.',
86
+ clickToOpen: 'Click me to open the conversation.',
87
+ clickToWrite: 'Click me to write to me.',
88
+ notReadyToWrite: 'You can write to me as soon as I am ready.',
89
+ hideBalloon: 'Hide the balloon',
90
+ writeToMe: 'Write to me…',
86
91
  waitingForYou: 'Waiting for you',
87
92
  paused: 'Paused — it answers again once it is resumed.',
88
93
  moreWaiting: count => `${count} more`,
@@ -162,6 +167,11 @@ export const CHAT_WORDS = {
162
167
  connect: 'Connecter',
163
168
  decline: 'Refuser',
164
169
  waitingOpen: 'Il vous attend — ouvrez la conversation pour répondre.',
170
+ clickToOpen: 'Cliquez sur moi pour ouvrir la conversation.',
171
+ clickToWrite: 'Cliquez sur moi pour m’écrire.',
172
+ notReadyToWrite: 'Vous pourrez m’écrire dès que je serai prêt.',
173
+ hideBalloon: 'Masquer la bulle',
174
+ writeToMe: 'Écrivez-moi…',
165
175
  waitingForYou: 'Il vous attend',
166
176
  paused: 'En pause — il répondra de nouveau une fois relancé.',
167
177
  moreWaiting: count => `${count} de plus`,
@@ -241,6 +251,11 @@ export const CHAT_WORDS = {
241
251
  connect: 'Conectar',
242
252
  decline: 'Rechazar',
243
253
  waitingOpen: 'Te está esperando: abre la conversación para responder.',
254
+ clickToOpen: 'Haz clic en mí para abrir la conversación.',
255
+ clickToWrite: 'Haz clic en mí para escribirme.',
256
+ notReadyToWrite: 'Podrás escribirme en cuanto esté listo.',
257
+ hideBalloon: 'Ocultar el globo',
258
+ writeToMe: 'Escríbeme…',
244
259
  waitingForYou: 'Te está esperando',
245
260
  paused: 'En pausa: responderá de nuevo cuando se reanude.',
246
261
  moreWaiting: count => `${count} más`,
@@ -320,6 +335,11 @@ export const CHAT_WORDS = {
320
335
  connect: 'Verbinden',
321
336
  decline: 'Ablehnen',
322
337
  waitingOpen: 'Wartet auf dich – öffne das Gespräch, um zu antworten.',
338
+ clickToOpen: 'Klick mich an, um das Gespräch zu öffnen.',
339
+ clickToWrite: 'Klick mich an, um mir zu schreiben.',
340
+ notReadyToWrite: 'Du kannst mir schreiben, sobald ich bereit bin.',
341
+ hideBalloon: 'Sprechblase ausblenden',
342
+ writeToMe: 'Schreib mir…',
323
343
  waitingForYou: 'Wartet auf dich',
324
344
  paused: 'Pausiert – antwortet wieder, sobald es fortgesetzt wird.',
325
345
  moreWaiting: count => `${count} weitere`,
@@ -399,6 +419,11 @@ export const CHAT_WORDS = {
399
419
  connect: 'Collega',
400
420
  decline: 'Rifiuta',
401
421
  waitingOpen: 'Ti sta aspettando: apri la conversazione per rispondere.',
422
+ clickToOpen: 'Cliccami per aprire la conversazione.',
423
+ clickToWrite: 'Cliccami per scrivermi.',
424
+ notReadyToWrite: 'Potrai scrivermi appena sarò pronto.',
425
+ hideBalloon: 'Nascondi il fumetto',
426
+ writeToMe: 'Scrivimi…',
402
427
  waitingForYou: 'Ti sta aspettando',
403
428
  paused: 'In pausa: risponderà di nuovo quando verrà ripreso.',
404
429
  moreWaiting: count => `altri ${count}`,
@@ -478,6 +503,11 @@ export const CHAT_WORDS = {
478
503
  connect: 'Conectar',
479
504
  decline: 'Recusar',
480
505
  waitingOpen: 'Esperando por você — abra a conversa para responder.',
506
+ clickToOpen: 'Clique em mim para abrir a conversa.',
507
+ clickToWrite: 'Clique em mim para me escrever.',
508
+ notReadyToWrite: 'Você poderá me escrever assim que eu estiver pronto.',
509
+ hideBalloon: 'Ocultar o balão',
510
+ writeToMe: 'Escreva para mim…',
481
511
  waitingForYou: 'Esperando por você',
482
512
  paused: 'Em pausa — volta a responder quando for retomado.',
483
513
  moreWaiting: count => `mais ${count}`,
@@ -63,6 +63,16 @@ export interface UseAgentOptions {
63
63
  }
64
64
  /** What an application's launch carries besides its environment (R-19). */
65
65
  export type AppLaunch = Required<Pick<IRuntimeOptions, 'appSpec'>> & Pick<IRuntimeOptions, 'appUid' | 'deploymentUid' | 'runtimeEngine'>;
66
+ /**
67
+ * Whether a listed runtime is one an application's deployment goes on with:
68
+ * launched for that deployment (its secrets given at launch, R-19) and not
69
+ * expired. One per visitor: the listing is the caller's own runtimes.
70
+ */
71
+ export declare function reusesAppRuntime(runtime: {
72
+ deployment_uid?: string | null;
73
+ expired_at?: string | number | null;
74
+ ingress?: string;
75
+ }, deploymentUid: string, nowSeconds: number): boolean;
66
76
  /**
67
77
  * Return type for the useAgents hook.
68
78
  */
@@ -27,6 +27,18 @@ import { disposeSandboxServiceManagers } from '../services/sandboxServiceManager
27
27
  import { agentDeletionUrl, launchesOwnRoutesOnly, runtimeStatusUrl, } from './ownRoutes.js';
28
28
  import { runtimeUrl, runtimesUrl } from '../runtimes/lifecycle.js';
29
29
  import { legacyTargetOf, locationOf, runsInBrowser, toAgentRuntimeVariant, } from '../runtimes/variants.js';
30
+ /**
31
+ * Whether a listed runtime is one an application's deployment goes on with:
32
+ * launched for that deployment (its secrets given at launch, R-19) and not
33
+ * expired. One per visitor: the listing is the caller's own runtimes.
34
+ */
35
+ export function reusesAppRuntime(runtime, deploymentUid, nowSeconds) {
36
+ if (!runtime.ingress || runtime.deployment_uid !== deploymentUid) {
37
+ return false;
38
+ }
39
+ const expires = Number(runtime.expired_at ?? 0);
40
+ return !expires || expires > nowSeconds + 60;
41
+ }
30
42
  // ═══════════════════════════════════════════════════════════════════════════
31
43
  // Constants
32
44
  // ═══════════════════════════════════════════════════════════════════════════
@@ -660,9 +672,13 @@ export function useAgentRuntimes(options = {}) {
660
672
  if (!hasSpec || runtime || lifecycleStatus !== 'idle') {
661
673
  return;
662
674
  }
663
- if (appLaunch) {
664
- // An application's runtime is launched for it (R-19): a running one
665
- // was not given its connections' secrets, so none is looked for.
675
+ // An application's runtime is launched for it (R-19), given its
676
+ // connections' secrets: a running one launched for another spec was not,
677
+ // so only one launched for the same deployment is gone on with. Each
678
+ // visit used to launch its own, and a reload while the first was still
679
+ // being assigned paid for two (13 November 2026).
680
+ const deploymentUid = appLaunch?.deploymentUid;
681
+ if (appLaunch && !deploymentUid) {
666
682
  setLookedForExisting(true);
667
683
  return;
668
684
  }
@@ -676,10 +692,14 @@ export function useAgentRuntimes(options = {}) {
676
692
  const { listRuntimes } = await import('../api/runtimes/runtimes.js');
677
693
  const runtimesResponse = await listRuntimes(token, runtimesUrl);
678
694
  const runtimes = runtimesResponse.runtimes || [];
695
+ const nowSeconds = Date.now() / 1000;
679
696
  const aiAgentRuntimes = runtimes.filter(rt => {
680
697
  if (rt.environment?.name !== 'ai-agents-env') {
681
698
  return false;
682
699
  }
700
+ if (deploymentUid) {
701
+ return reusesAppRuntime(rt, deploymentUid, nowSeconds);
702
+ }
683
703
  if (!agentSpecId) {
684
704
  return true;
685
705
  }
@@ -765,6 +785,10 @@ export function useAgentRuntimes(options = {}) {
765
785
  // race it: two runtimes for one spec, and whichever answered last wins.
766
786
  lookedForExisting &&
767
787
  !runtime &&
788
+ // Another mount's launch still in flight (the workspace rebuilt while
789
+ // its runtime was being assigned): its runtime is this one's too, read
790
+ // from the store once it lands, never a second launch.
791
+ !isLaunching &&
768
792
  !hasAutoStarted.current &&
769
793
  lifecycleStatus === 'idle') {
770
794
  hasAutoStarted.current = true;
@@ -775,6 +799,7 @@ export function useAgentRuntimes(options = {}) {
775
799
  autoStart,
776
800
  lookedForExisting,
777
801
  runtime,
802
+ isLaunching,
778
803
  lifecycleStatus,
779
804
  launchRuntime,
780
805
  ]);
@@ -59,12 +59,15 @@ export type Place = Readonly<{
59
59
  /**
60
60
  * Where a turn comes from, as the session API takes it on the turn itself
61
61
  * (`provenance`, at most 1 KiB): the host's
62
- * kind, the place, the thread and the message.
62
+ * kind, the place, the thread and the message. A host whose place names its
63
+ * conversation (a WhatsApp chat or group) sends no thread, as the session
64
+ * API's own `TurnProvenance` (a `thread` of `""` by default) and this kit's
65
+ * WhatsApp contract say.
63
66
  */
64
67
  export type TurnProvenance = Readonly<{
65
68
  host_kind: string;
66
69
  place: Place;
67
- thread: string;
70
+ thread?: string;
68
71
  message_id: string;
69
72
  }>;
70
73
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/agent-runtimes",
3
- "version": "1.6.40",
3
+ "version": "1.6.42",
4
4
  "type": "module",
5
5
  "workspaces": [
6
6
  ".",