@datalayer/agent-runtimes 1.6.62 → 1.6.64

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.
Files changed (67) hide show
  1. package/dist-embed/chunks/ChatView-Bg-IvVbM.js +32 -0
  2. package/dist-embed/datalayer-app-main.js +94 -94
  3. package/lib/apps/agentUiPlugins.d.ts +39 -10
  4. package/lib/apps/agentUiPlugins.js +159 -50
  5. package/lib/apps/apps/AppRenderer.js +3 -1
  6. package/lib/apps/apps/appspec.js +22 -4
  7. package/lib/apps/apps/checks.js +9 -0
  8. package/lib/apps/core/index.d.ts +6 -0
  9. package/lib/apps/core/index.js +6 -0
  10. package/lib/apps/embed/LoopEmbed.js +1 -1
  11. package/lib/apps/plugins/aws-savings/index.d.ts +10 -5
  12. package/lib/apps/plugins/aws-savings/index.js +35 -21
  13. package/lib/apps/plugins/aws-savings-badge/index.d.ts +28 -0
  14. package/lib/apps/plugins/aws-savings-badge/index.js +58 -0
  15. package/lib/apps/plugins/bank-reconciliation/index.d.ts +19 -7
  16. package/lib/apps/plugins/bank-reconciliation/index.js +68 -63
  17. package/lib/apps/plugins/basket-total/index.d.ts +25 -0
  18. package/lib/apps/plugins/basket-total/index.js +41 -0
  19. package/lib/apps/plugins/chat/ChatView.js +4 -1
  20. package/lib/apps/plugins/earth-area/index.d.ts +27 -0
  21. package/lib/apps/plugins/earth-area/index.js +50 -0
  22. package/lib/apps/plugins/earth-index/index.d.ts +8 -3
  23. package/lib/apps/plugins/earth-index/index.js +39 -27
  24. package/lib/apps/plugins/earth-scenes/index.d.ts +8 -3
  25. package/lib/apps/plugins/earth-scenes/index.js +30 -31
  26. package/lib/apps/plugins/linkedin-link/index.d.ts +5 -4
  27. package/lib/apps/plugins/linkedin-link/index.js +7 -16
  28. package/lib/apps/plugins/odoo-context/index.d.ts +30 -0
  29. package/lib/apps/plugins/odoo-context/index.js +54 -0
  30. package/lib/apps/plugins/product-comparison/index.d.ts +7 -1
  31. package/lib/apps/plugins/product-comparison/index.js +37 -30
  32. package/lib/apps/plugins/shopping-basket/index.d.ts +19 -5
  33. package/lib/apps/plugins/shopping-basket/index.js +69 -24
  34. package/lib/apps/plugins/social-accounts/index.d.ts +10 -0
  35. package/lib/apps/plugins/social-accounts/index.js +51 -1
  36. package/lib/apps/plugins/trip-options/index.d.ts +15 -5
  37. package/lib/apps/plugins/trip-options/index.js +67 -21
  38. package/lib/apps/plugins/trip-summary/index.d.ts +26 -0
  39. package/lib/apps/plugins/trip-summary/index.js +59 -0
  40. package/lib/apps/plugins/x-budget/index.d.ts +3 -2
  41. package/lib/apps/plugins/x-budget/index.js +8 -17
  42. package/lib/apps/presets.d.ts +2 -1
  43. package/lib/apps/presets.js +2 -2
  44. package/lib/apps/toolCards/a2uiCard.d.ts +63 -0
  45. package/lib/apps/toolCards/a2uiCard.js +104 -0
  46. package/lib/apps/toolCards/chrome.d.ts +50 -0
  47. package/lib/apps/toolCards/chrome.js +57 -0
  48. package/lib/apps/toolCards/postPreview.d.ts +6 -2
  49. package/lib/apps/toolCards/postPreview.js +28 -18
  50. package/lib/apps/toolCards/toolResults.d.ts +37 -0
  51. package/lib/apps/toolCards/toolResults.js +85 -0
  52. package/lib/chat/Chat.js +47 -36
  53. package/lib/chat/base/ChatBase.js +2 -2
  54. package/lib/chat/messages/ChatMessageList.js +7 -0
  55. package/lib/specs/actions.js +32 -0
  56. package/lib/specs/agents/agents.js +1 -1
  57. package/lib/specs/appspecSchema.js +18 -0
  58. package/lib/specs/backendTools.js +29 -14
  59. package/lib/specs/mcpServers.js +19 -10
  60. package/lib/specs/skills.js +7 -3
  61. package/lib/specs/ui.d.ts +5 -0
  62. package/lib/specs/ui.js +172 -11
  63. package/lib/types/agentspecs.d.ts +8 -0
  64. package/lib/types/chat.d.ts +5 -0
  65. package/package.json +1 -1
  66. package/scripts/codegen/generate_ui.py +2 -0
  67. package/dist-embed/chunks/ChatView-LldnraOq.js +0 -32
@@ -1,8 +1,7 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
- import { Button, Heading, Link, Text } from '@primer/react';
4
- import { Box } from '@datalayer/primer-addons';
5
3
  import { CardSkeleton, cardData, defineToolCardPlugin, money, submitCard, useToolCardSend, } from '../../toolCards/kit.js';
4
+ import { A2uiCard } from '../../toolCards/a2uiCard.js';
6
5
  import { readTripOptions } from './read.js';
7
6
  export const TRIP_OPTIONS_PLUGIN_NAME = '@datalayer/loop-plugin-trip-options';
8
7
  export const TRIP_OPTIONS_WORDS = {
@@ -10,10 +9,58 @@ export const TRIP_OPTIONS_WORDS = {
10
9
  writing: 'Looking for trips…',
11
10
  nights: (nights) => (nights === 1 ? '1 night' : `${nights} nights`),
12
11
  choose: 'Choose this one',
13
- chosen: 'Chosen',
12
+ chosen: (title) => `Chosen: ${title}`,
14
13
  offer: 'See the offer',
15
14
  nothingBooked: 'Nothing is booked until you say so.',
16
15
  };
16
+ /** The action **Choose this one** sends. */
17
+ export const CHOOSE_TRIP_ACTION = 'choose_trip';
18
+ /** The options as an A2UI card: a section each, with its choice. */
19
+ export function tripOptionsCard(options, id, state = {}) {
20
+ const chosen = options.find(option => option.id === state.chosen);
21
+ return {
22
+ id: `trips-${id}`,
23
+ title: TRIP_OPTIONS_WORDS.label,
24
+ captions: [
25
+ chosen
26
+ ? TRIP_OPTIONS_WORDS.chosen(chosen.title)
27
+ : TRIP_OPTIONS_WORDS.nothingBooked,
28
+ ],
29
+ sections: options.map(option => ({
30
+ id: option.id,
31
+ title: option.title,
32
+ ...(option.image
33
+ ? { image: { url: option.image, alt: option.title } }
34
+ : {}),
35
+ lines: [
36
+ [
37
+ option.dates,
38
+ option.nights !== undefined
39
+ ? TRIP_OPTIONS_WORDS.nights(option.nights)
40
+ : '',
41
+ ]
42
+ .filter(Boolean)
43
+ .join(' · '),
44
+ ...(option.price !== undefined
45
+ ? [`**${money(option.price, option.currency)}**`]
46
+ : []),
47
+ ...(option.summary ? [option.summary] : []),
48
+ ...option.highlights.map(highlight => `- ${highlight}`),
49
+ ...(option.url ? [`[${TRIP_OPTIONS_WORDS.offer}](${option.url})`] : []),
50
+ ].filter(Boolean),
51
+ actions: state.choose && !chosen
52
+ ? [
53
+ {
54
+ name: CHOOSE_TRIP_ACTION,
55
+ label: TRIP_OPTIONS_WORDS.choose,
56
+ context: { id: option.id },
57
+ primary: true,
58
+ },
59
+ ]
60
+ : [],
61
+ })),
62
+ };
63
+ }
17
64
  export function TripOptionsCard({ context, }) {
18
65
  const send = useToolCardSend();
19
66
  const [chosen, setChosen] = useState('');
@@ -25,23 +72,22 @@ export function TripOptionsCard({ context, }) {
25
72
  if (options.length === 0) {
26
73
  return read.done ? (_jsx(_Fragment, { children: context.defaultUI })) : (_jsx(CardSkeleton, { label: TRIP_OPTIONS_WORDS.writing }));
27
74
  }
28
- return (_jsxs(Box, { as: "section", "aria-label": TRIP_OPTIONS_WORDS.label, my: 2, width: "100%", children: [_jsx(Box, { display: "grid", gridTemplateColumns: ['1fr', 'repeat(auto-fit, minmax(200px, 1fr))'], gridGap: 2, children: options.map(option => (_jsxs(Box, { as: "article", "aria-label": option.title, p: 3, border: "1px solid", borderColor: chosen === option.id ? 'accent.emphasis' : 'border.default', borderRadius: 2, bg: "canvas.subtle", display: "flex", flexDirection: "column", gap: 1, children: [option.image ? (_jsx(Box, { as: "img", src: option.image, alt: "", width: "100%", height: 120, borderRadius: 2, sx: { objectFit: 'cover' } })) : null, _jsx(Heading, { as: "h4", sx: { fontSize: 2 }, children: option.title }), _jsx(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [
29
- option.dates,
30
- option.nights !== undefined
31
- ? TRIP_OPTIONS_WORDS.nights(option.nights)
32
- : '',
33
- ]
34
- .filter(Boolean)
35
- .join(' · ') }), option.price !== undefined ? (_jsx(Text, { sx: { fontSize: 3, fontWeight: 'bold' }, children: money(option.price, option.currency) })) : null, option.summary ? (_jsx(Text, { sx: { fontSize: 1 }, children: option.summary })) : null, option.highlights.length > 0 ? (_jsx(Box, { as: "ul", pl: 3, my: 1, sx: { fontSize: 1 }, children: option.highlights.map(highlight => (_jsx("li", { children: highlight }, highlight))) })) : null, _jsxs(Box, { mt: "auto", display: "flex", gap: 2, alignItems: "center", flexWrap: "wrap", children: [send && read.done ? (_jsx(Button, { size: "small", variant: chosen === option.id ? 'primary' : 'default', disabled: Boolean(chosen), onClick: () => {
36
- if (submitCard(send, {
37
- title: TRIP_OPTIONS_WORDS.label,
38
- values: { chosen: option.title, id: option.id },
39
- })) {
40
- setChosen(option.id);
41
- }
42
- }, children: chosen === option.id
43
- ? TRIP_OPTIONS_WORDS.chosen
44
- : TRIP_OPTIONS_WORDS.choose })) : null, option.url ? (_jsx(Link, { href: option.url, target: "_blank", rel: "noreferrer", sx: { fontSize: 1 }, children: TRIP_OPTIONS_WORDS.offer })) : null] })] }, option.id))) }), _jsx(Text, { as: "p", sx: { mt: 1, mb: 0, fontSize: 0, color: 'fg.muted' }, children: TRIP_OPTIONS_WORDS.nothingBooked })] }));
75
+ const onAction = (action) => {
76
+ const option = options.find(each => each.id === String((action.context ?? {}).id ?? ''));
77
+ if (action.name !== CHOOSE_TRIP_ACTION || !option || !send) {
78
+ return;
79
+ }
80
+ if (submitCard(send, {
81
+ title: TRIP_OPTIONS_WORDS.label,
82
+ values: { chosen: option.title, id: option.id },
83
+ })) {
84
+ setChosen(option.id);
85
+ }
86
+ };
87
+ return (_jsx(A2uiCard, { spec: tripOptionsCard(options, context.toolCallId, {
88
+ choose: Boolean(send) && read.done,
89
+ chosen,
90
+ }), onAction: onAction, maxWidth: 720 }));
45
91
  }
46
92
  export const TripOptionsPlugin = defineToolCardPlugin({
47
93
  id: 'trip-options',
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `@datalayer/loop-plugin-trip-summary` — the trip the Voyager is planning,
3
+ * in the chat's title bar: where and when, from the last itinerary it showed
4
+ * (`show_itinerary`: its title, its first and last days), and its budget so
5
+ * far (`show_trip_budget`'s total). Nothing before either. Brought by the
6
+ * `travel-planning` skill.
7
+ *
8
+ * @module apps/plugins/trip-summary
9
+ */
10
+ import type { JSX } from 'react';
11
+ export declare const TRIP_SUMMARY_WORDS: {
12
+ readonly short: (parts: string[]) => string;
13
+ readonly title: (parts: string[]) => string;
14
+ };
15
+ /** Where and when, and the budget so far, from the cards shown; empty when none. */
16
+ export declare function tripSummaryOf(itinerary: {
17
+ args: Record<string, unknown>;
18
+ result: unknown;
19
+ } | undefined, budget: {
20
+ args: Record<string, unknown>;
21
+ result: unknown;
22
+ } | undefined): string[];
23
+ export declare function TripSummaryChip(): JSX.Element | null;
24
+ export declare const tripSummaryPlugin: (placement: import("../../agentUiPlugins").ChromePlacement) => import("@datalayer/reactor").ReactorPlugin<Record<string, never>, unknown, unknown>;
25
+ export declare const TripSummaryPlugin: import("@datalayer/reactor").ReactorPlugin<Record<string, never>, unknown, unknown>;
26
+ export default TripSummaryPlugin;
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Chip, defineChromePlugin } from '../../toolCards/chrome.js';
3
+ import { useLatestToolCall } from '../../toolCards/toolResults.js';
4
+ import { money, record } from '../../toolCards/kit.js';
5
+ import { readItinerary } from '../trip-itinerary/read.js';
6
+ import { readTripBudget } from '../trip-budget/read.js';
7
+ export const TRIP_SUMMARY_WORDS = {
8
+ short: (parts) => `Trip: ${parts.join(' · ')}`,
9
+ title: (parts) => `The trip being planned: ${parts.join(', ')}. Nothing is booked.`,
10
+ };
11
+ const dataOf = (call) => {
12
+ if (!call) {
13
+ return undefined;
14
+ }
15
+ const answered = record(call.result);
16
+ return answered && 'shown' in answered ? answered : call.args;
17
+ };
18
+ /** Where and when, and the budget so far, from the cards shown; empty when none. */
19
+ export function tripSummaryOf(itinerary, budget) {
20
+ const parts = [];
21
+ const days = dataOf(itinerary);
22
+ if (days) {
23
+ const read = readItinerary(days);
24
+ const dates = read.days.map(day => day.date).filter(Boolean);
25
+ if (read.title) {
26
+ parts.push(read.title);
27
+ }
28
+ if (dates.length > 0) {
29
+ parts.push(dates.length > 1
30
+ ? `${dates[0]} – ${dates[dates.length - 1]}`
31
+ : dates[0]);
32
+ }
33
+ }
34
+ const lines = dataOf(budget);
35
+ if (lines) {
36
+ const trip = readTripBudget(lines);
37
+ if (trip.lines.length > 0) {
38
+ parts.push(money(trip.total, trip.currency));
39
+ }
40
+ }
41
+ return parts;
42
+ }
43
+ export function TripSummaryChip() {
44
+ const parts = tripSummaryOf(useLatestToolCall(['show_itinerary']), useLatestToolCall(['show_trip_budget']));
45
+ if (parts.length === 0) {
46
+ return null;
47
+ }
48
+ return (_jsx(Chip, { title: TRIP_SUMMARY_WORDS.title(parts), data: "trip-summary", children: TRIP_SUMMARY_WORDS.short(parts) }));
49
+ }
50
+ export const tripSummaryPlugin = defineChromePlugin({
51
+ id: 'trip-summary',
52
+ displayName: 'Trip being planned',
53
+ description: 'The trip being planned, in the chat’s title bar: where and when, and its budget so far.',
54
+ octicon: 'paper-airplane',
55
+ emoji: '\u{1F9ED}',
56
+ Component: TripSummaryChip,
57
+ });
58
+ export const TripSummaryPlugin = tripSummaryPlugin('header');
59
+ export default TripSummaryPlugin;
@@ -1,6 +1,7 @@
1
- import type { ReactorPlugin } from '@datalayer/reactor';
2
1
  export declare const X_BUDGET_PLUGIN_NAME = "@datalayer/loop-plugin-x-budget";
3
- export declare const XBudgetPlugin: ReactorPlugin<Record<string, never>, unknown, unknown>;
2
+ /** The plugin for a placement: `header` (its default) or `footer`. */
3
+ export declare const xBudgetPlugin: (placement: import("../../agentUiPlugins").ChromePlacement) => import("@datalayer/reactor").ReactorPlugin<Record<string, never>, unknown, unknown>;
4
+ export declare const XBudgetPlugin: import("@datalayer/reactor").ReactorPlugin<Record<string, never>, unknown, unknown>;
4
5
  export { XBudgetChip, XBudgetSlot, X_BUDGET_REFRESH_MS } from './XBudgetChip';
5
6
  export * from './xBudget';
6
7
  export default XBudgetPlugin;
@@ -4,7 +4,7 @@
4
4
  */
5
5
  /**
6
6
  * `@datalayer/loop-plugin-x-budget` — what is left of the person's X budget
7
- * today, in the chat's title bar (`LoopSlots.chatHeader`; `Chat`'s
7
+ * today, in the chat's title bar or under the prompt (its placement; `Chat`'s
8
8
  * `uiPlugins` with `x-budget` draws the same chip). It reads the Marketer's
9
9
  * `x-api-budget` guardrail back from the runtimes service and counts
10
10
  * nothing itself: the guardrail prices each X call and refuses one past the
@@ -12,28 +12,19 @@
12
12
  *
13
13
  * @module apps/plugins/x-budget
14
14
  */
15
- import { definePlugin } from '@datalayer/reactor';
16
- import { LoopSlots } from '../../core/index.js';
17
- import { XBudgetSlot } from './XBudgetChip.js';
15
+ import { defineChromePlugin } from '../../toolCards/chrome.js';
16
+ import { XBudgetChip } from './XBudgetChip.js';
18
17
  export const X_BUDGET_PLUGIN_NAME = '@datalayer/loop-plugin-x-budget';
19
- export const XBudgetPlugin = definePlugin({
20
- name: X_BUDGET_PLUGIN_NAME,
18
+ /** The plugin for a placement: `header` (its default) or `footer`. */
19
+ export const xBudgetPlugin = defineChromePlugin({
20
+ id: 'x-budget',
21
21
  displayName: 'X budget',
22
22
  description: 'What is left of the person’s X budget today, read from the agent’s X budget guardrail.',
23
23
  octicon: 'meter',
24
24
  emoji: '\u{1F4B2}',
25
- build() {
26
- return {
27
- components: [
28
- {
29
- slot: LoopSlots.chatHeader,
30
- id: 'x-budget',
31
- Component: XBudgetSlot,
32
- },
33
- ],
34
- };
35
- },
25
+ Component: () => XBudgetChip({}),
36
26
  });
27
+ export const XBudgetPlugin = xBudgetPlugin('header');
37
28
  export { XBudgetChip, XBudgetSlot, X_BUDGET_REFRESH_MS } from './XBudgetChip.js';
38
29
  export * from './xBudget.js';
39
30
  export default XBudgetPlugin;
@@ -29,6 +29,7 @@ import { type AgentsConfig, type SandboxTarget } from './plugins/agents';
29
29
  import { type ChatPluginConfig, type ChatPresence } from './plugins/chat';
30
30
  import { type PageSize } from './plugins/page-layout';
31
31
  import type { ResumedThread, ThemeOverrides } from '../types/chat';
32
+ import type { UiChoice } from '../types/agentspecs';
32
33
  export type LoopPresetOptions = {
33
34
  /** Where the agent runtimes service is. */
34
35
  serverUrl?: string;
@@ -253,7 +254,7 @@ export type LoopPresetOptions = {
253
254
  * (`runAsAnonymous`, `datalayerVisitors`) gets only those that need no
254
255
  * connection of theirs.
255
256
  */
256
- uiPlugins?: readonly string[];
257
+ uiPlugins?: ReadonlyArray<string | UiChoice>;
257
258
  };
258
259
  /**
259
260
  * The standard set, with the options a host usually varies.
@@ -56,7 +56,7 @@ import { WindowFramePlugin } from './plugins/window-frame/index.js';
56
56
  import { DocumentExtension, NotebookExtension } from './extensions.js';
57
57
  import { LoopPageLayoutPlugin } from './plugins/page-layout/index.js';
58
58
  import { maxTurnsOf } from '../chat/anonymous/anonymousMode.js';
59
- import { agentUiPluginsFor, uiPluginIdsOfSpec } from './agentUiPlugins.js';
59
+ import { agentUiChoicesOf, agentUiPluginsFor } from './agentUiPlugins.js';
60
60
  /**
61
61
  * The standard set, with the options a host usually varies.
62
62
  *
@@ -135,7 +135,7 @@ export function loopPlugins(options = {}) {
135
135
  ShieldDisplaysPlugin,
136
136
  // The agent's own: what its spec names under `ui` — each draws one of
137
137
  // its tools or one fact, so every other chat stays as it was.
138
- ...agentUiPluginsFor(uiPlugins ?? uiPluginIdsOfSpec(datalayerAgentSpecId ?? localAgentSpec), { anonymous: runAsAnonymous || Boolean(datalayerVisitors) }),
138
+ ...agentUiPluginsFor(uiPlugins ?? agentUiChoicesOf(datalayerAgentSpecId ?? localAgentSpec), { anonymous: runAsAnonymous || Boolean(datalayerVisitors) }),
139
139
  // An XLSX the agent gives, read-only in Cells in its message: the
140
140
  // renderer loads Cells when a workbook is drawn, so it costs a chat
141
141
  // with none nothing.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A card in the conversation drawn by the A2UI renderer (the user, 15
3
+ * November 2026: "make sure ui can be used to be injected … as chat message
4
+ * (a2ui)"): the seed agents' message UIs — the post previews, the
5
+ * comparison, the basket, the reconciliation, the trip options, the scenes,
6
+ * the index, the savings — say what they show as a `CardSpec`, written here
7
+ * as A2UI v0.9 messages in the chat's catalogue (a title, captions, a
8
+ * `Table`, markdown lines, images, sections each with its buttons) and drawn
9
+ * by `InlineSurface`, the renderer the agents' own surfaces use. A button's
10
+ * press comes back as its action's name and context.
11
+ *
12
+ * @module apps/toolCards/a2uiCard
13
+ */
14
+ import type { JSX } from 'react';
15
+ import type { A2uiClientAction, A2uiMessage } from '@a2ui/web_core/v0_9';
16
+ export type CardAction = {
17
+ /** The event's name, as `onAction` receives it. */
18
+ name: string;
19
+ label: string;
20
+ context?: Record<string, unknown>;
21
+ primary?: boolean;
22
+ };
23
+ export type CardSection = {
24
+ id: string;
25
+ title?: string;
26
+ /** Lines of markdown (a link as `[words](https://…)`). */
27
+ lines?: string[];
28
+ image?: {
29
+ url: string;
30
+ alt: string;
31
+ };
32
+ actions?: CardAction[];
33
+ };
34
+ export type CardSpec = {
35
+ /** Unique within the conversation: the tool call's id. */
36
+ id: string;
37
+ title: string;
38
+ /** Captions under the title. */
39
+ captions?: string[];
40
+ table?: {
41
+ columns: string[];
42
+ rows: Record<string, string>[];
43
+ };
44
+ image?: {
45
+ url: string;
46
+ alt: string;
47
+ };
48
+ /** Lines of markdown after the table. */
49
+ lines?: string[];
50
+ sections?: CardSection[];
51
+ actions?: CardAction[];
52
+ };
53
+ /** The card as A2UI v0.9 messages in a catalogue. */
54
+ export declare function cardMessages(spec: CardSpec, catalogId?: string): A2uiMessage[];
55
+ /**
56
+ * The card, drawn by the A2UI renderer. Drawn anew when what it shows
57
+ * changes: the renderer takes one set of messages per surface.
58
+ */
59
+ export declare function A2uiCard({ spec, onAction, maxWidth, }: {
60
+ spec: CardSpec;
61
+ onAction?: (action: A2uiClientAction) => void;
62
+ maxWidth?: number;
63
+ }): JSX.Element;
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { Box } from '@datalayer/primer-addons';
4
+ import { InlineSurface, SURFACE_CATALOG_ID, } from '../plugins/a2ui-surface/InlineSurface.js';
5
+ const safeId = (value) => value.replace(/[^A-Za-z0-9_-]/g, '-');
6
+ /** The card as A2UI v0.9 messages in a catalogue. */
7
+ export function cardMessages(spec, catalogId = SURFACE_CATALOG_ID) {
8
+ const surfaceId = `card-${safeId(spec.id)}`;
9
+ const nodes = [];
10
+ const body = [];
11
+ const text = (id, words, variant) => {
12
+ nodes.push({
13
+ id,
14
+ component: 'Text',
15
+ text: words,
16
+ ...(variant ? { variant } : {}),
17
+ });
18
+ return id;
19
+ };
20
+ const buttons = (prefix, actions) => {
21
+ const ids = actions.map((action, index) => {
22
+ const id = `${prefix}-button-${index}`;
23
+ text(`${id}-label`, action.label);
24
+ nodes.push({
25
+ id,
26
+ component: 'Button',
27
+ variant: action.primary ? 'primary' : 'default',
28
+ child: `${id}-label`,
29
+ action: { event: { name: action.name, context: action.context ?? {} } },
30
+ });
31
+ return id;
32
+ });
33
+ nodes.push({ id: `${prefix}-buttons`, component: 'Row', children: ids });
34
+ return `${prefix}-buttons`;
35
+ };
36
+ body.push(text('title', spec.title, 'h3'));
37
+ (spec.captions ?? []).forEach((caption, index) => {
38
+ body.push(text(`caption-${index}`, caption, 'caption'));
39
+ });
40
+ if (spec.image) {
41
+ nodes.push({
42
+ id: 'image',
43
+ component: 'Image',
44
+ url: spec.image.url,
45
+ description: spec.image.alt,
46
+ });
47
+ body.push('image');
48
+ }
49
+ if (spec.table && spec.table.rows.length > 0) {
50
+ nodes.push({
51
+ id: 'table',
52
+ component: 'Table',
53
+ columns: spec.table.columns,
54
+ rows: spec.table.rows,
55
+ });
56
+ body.push('table');
57
+ }
58
+ (spec.lines ?? []).forEach((line, index) => {
59
+ body.push(text(`line-${index}`, line));
60
+ });
61
+ (spec.sections ?? []).forEach((section, index) => {
62
+ const prefix = `section-${index}`;
63
+ const children = [];
64
+ if (section.title) {
65
+ children.push(text(`${prefix}-title`, section.title, 'h4'));
66
+ }
67
+ if (section.image) {
68
+ nodes.push({
69
+ id: `${prefix}-image`,
70
+ component: 'Image',
71
+ url: section.image.url,
72
+ description: section.image.alt,
73
+ });
74
+ children.push(`${prefix}-image`);
75
+ }
76
+ (section.lines ?? []).forEach((line, lineIndex) => {
77
+ children.push(text(`${prefix}-line-${lineIndex}`, line));
78
+ });
79
+ if (section.actions && section.actions.length > 0) {
80
+ children.push(buttons(prefix, section.actions));
81
+ }
82
+ nodes.push({ id: `${prefix}-column`, component: 'Column', children });
83
+ nodes.push({ id: prefix, component: 'Card', child: `${prefix}-column` });
84
+ body.push(prefix);
85
+ });
86
+ if (spec.actions && spec.actions.length > 0) {
87
+ body.push(buttons('card', spec.actions));
88
+ }
89
+ nodes.push({ id: 'body', component: 'Column', children: body });
90
+ nodes.unshift({ id: 'root', component: 'Card', child: 'body' });
91
+ return [
92
+ { version: 'v0.9', createSurface: { surfaceId, catalogId } },
93
+ { version: 'v0.9', updateComponents: { surfaceId, components: nodes } },
94
+ ];
95
+ }
96
+ /**
97
+ * The card, drawn by the A2UI renderer. Drawn anew when what it shows
98
+ * changes: the renderer takes one set of messages per surface.
99
+ */
100
+ export function A2uiCard({ spec, onAction, maxWidth = 640, }) {
101
+ const messages = useMemo(() => cardMessages(spec), [spec]);
102
+ const key = useMemo(() => JSON.stringify(spec), [spec]);
103
+ return (_jsx(Box, { my: 2, width: "100%", maxWidth: maxWidth, "data-a2ui-card": spec.id, children: _jsx(InlineSurface, { messages: messages, onAction: onAction ?? (() => undefined) }, key) }));
104
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The agents' UI in the chat's own chrome (the user, 15 November 2026:
3
+ * "make sure ui can be used to be injected in the chat itself (toolbar,
4
+ * header...)"). A UI spec says its `placements`; a chrome UI is one
5
+ * component, mounted where its declaration places it:
6
+ *
7
+ * | Placement | A Loop workspace | `Chat` |
8
+ * |-----------|---------------------------|--------------------------------------|
9
+ * | `header` | `loop.chatHeader` | its header actions |
10
+ * | `toolbar` | `loop.promptAction` | the input toolbar (`toolbarExtras`) |
11
+ * | `footer` | `loop.status` | the band over the prompt (`footerContent`) |
12
+ * | `banner` | `loop.chatBanner` | under the title (`headerContent`) |
13
+ * | `panel` | none yet | none yet |
14
+ *
15
+ * A `message` UI is a card in the conversation (`defineToolCardPlugin`).
16
+ *
17
+ * @module apps/toolCards/chrome
18
+ */
19
+ import type { ComponentType, JSX, ReactNode } from 'react';
20
+ import type { ReactorPlugin } from '@datalayer/reactor';
21
+ export type UiPlacement = 'header' | 'toolbar' | 'footer' | 'banner' | 'panel' | 'message';
22
+ export type ChromePlacement = Exclude<UiPlacement, 'message'>;
23
+ export declare const CHROME_PLACEMENTS: readonly ChromePlacement[];
24
+ /** The Loop slot of each chrome placement; none where the chat has none. */
25
+ export declare const CHROME_SLOTS: Record<ChromePlacement, string | undefined>;
26
+ export declare const isChromePlacement: (placement: string | undefined) => placement is ChromePlacement;
27
+ export type ChromeComponentProps = {
28
+ placement: ChromePlacement;
29
+ };
30
+ export type ChromePluginOptions = {
31
+ id: string;
32
+ displayName: string;
33
+ description: string;
34
+ octicon: string;
35
+ emoji: string;
36
+ /** What it draws; nothing when it has nothing true to say. */
37
+ Component: ComponentType<ChromeComponentProps>;
38
+ };
39
+ /**
40
+ * A chrome UI's plugin, for a placement: its component in that placement's
41
+ * slot, under the plugin's one name (`@datalayer/loop-plugin-<id>`).
42
+ */
43
+ export declare function defineChromePlugin(options: ChromePluginOptions): (placement: ChromePlacement) => ReactorPlugin<Record<string, never>, unknown, unknown>;
44
+ /** A chip: a few words, the whole sentence as its title. */
45
+ export declare function Chip({ children, title, attention, data, }: {
46
+ children: ReactNode;
47
+ title: string;
48
+ attention?: boolean;
49
+ data?: string;
50
+ }): JSX.Element;
@@ -0,0 +1,57 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Label } from '@primer/react';
3
+ import { definePlugin } from '@datalayer/reactor';
4
+ import { LoopSlots } from '../core/index.js';
5
+ export const CHROME_PLACEMENTS = [
6
+ 'header',
7
+ 'toolbar',
8
+ 'footer',
9
+ 'banner',
10
+ 'panel',
11
+ ];
12
+ /** The Loop slot of each chrome placement; none where the chat has none. */
13
+ export const CHROME_SLOTS = {
14
+ header: LoopSlots.chatHeader,
15
+ toolbar: LoopSlots.promptAction,
16
+ footer: LoopSlots.status,
17
+ banner: LoopSlots.chatBanner,
18
+ panel: undefined,
19
+ };
20
+ export const isChromePlacement = (placement) => CHROME_PLACEMENTS.includes(placement);
21
+ /**
22
+ * A chrome UI's plugin, for a placement: its component in that placement's
23
+ * slot, under the plugin's one name (`@datalayer/loop-plugin-<id>`).
24
+ */
25
+ export function defineChromePlugin(options) {
26
+ const { Component } = options;
27
+ return placement => {
28
+ const slot = CHROME_SLOTS[placement];
29
+ function Slotted() {
30
+ return _jsx(Component, { placement: placement });
31
+ }
32
+ return definePlugin({
33
+ name: `@datalayer/loop-plugin-${options.id}`,
34
+ displayName: options.displayName,
35
+ description: options.description,
36
+ octicon: options.octicon,
37
+ emoji: options.emoji,
38
+ build() {
39
+ return {
40
+ components: slot
41
+ ? [
42
+ {
43
+ slot,
44
+ id: `${options.id}-${placement}`,
45
+ Component: Slotted,
46
+ },
47
+ ]
48
+ : [],
49
+ };
50
+ },
51
+ });
52
+ };
53
+ }
54
+ /** A chip: a few words, the whole sentence as its title. */
55
+ export function Chip({ children, title, attention = false, data, }) {
56
+ return (_jsx(Label, { variant: attention ? 'attention' : 'secondary', title: title, "aria-label": title, "data-chrome-chip": data, children: children }));
57
+ }
@@ -5,13 +5,15 @@
5
5
  * `x-post-preview`, `bluesky-post-preview` and `linkedin-post-preview`,
6
6
  * one plugin per network so that an agent declares only where it posts.
7
7
  *
8
- * The Approve and Reject stay the chat's (`defaultUI`): this card shows what
9
- * is approved, it never decides.
8
+ * Drawn by the A2UI renderer (`a2uiCard`). The Approve and Reject stay the
9
+ * chat's (`defaultUI`), under it: this card shows what is approved, it never
10
+ * decides.
10
11
  *
11
12
  * @module apps/toolCards/postPreview
12
13
  */
13
14
  import type { JSX } from 'react';
14
15
  import type { ToolCallRenderContext } from '../../types/chat';
16
+ import { type CardSpec } from './a2uiCard';
15
17
  export type PostNetwork = 'x' | 'bluesky' | 'linkedin';
16
18
  /** What each network takes, as the runtime's tools refuse past it. */
17
19
  export declare const POST_LIMITS: Record<PostNetwork, {
@@ -43,6 +45,8 @@ export type PostPreview = {
43
45
  };
44
46
  /** The post a call carries, and where it went once out. */
45
47
  export declare function readPostPreview(network: PostNetwork, toolName: string, args: unknown, result: unknown): PostPreview;
48
+ /** The post as an A2UI card: what it says, how long, what it answers, where it went. */
49
+ export declare function postPreviewCard(preview: PostPreview, id: string): CardSpec;
46
50
  export declare function PostPreviewCard({ network, context, }: {
47
51
  network: PostNetwork;
48
52
  context: ToolCallRenderContext;