@alquimia-ai/tools 2.3.0 → 2.4.0

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.
@@ -0,0 +1,57 @@
1
+ import { S as SurfaceAction } from './types-DnfWUE9V.js';
2
+
3
+ type UIActionKind = "agent-bound" | "local";
4
+ interface UIAction {
5
+ surfaceId: string;
6
+ componentId: string;
7
+ action: string;
8
+ kind: UIActionKind;
9
+ payload?: Record<string, unknown>;
10
+ }
11
+ /**
12
+ * The `result` body posted to /event/tool-completion for an agent-bound action.
13
+ * Shape is part of the agent-facing contract — the prompt clause describes it.
14
+ */
15
+ interface SurfaceResult {
16
+ /** The action's semantic name. */
17
+ action: string;
18
+ /** Which surface it came from. */
19
+ surfaceId: string;
20
+ /**
21
+ * The id of the component that was acted on. This is what lets the agent tell WHICH
22
+ * element fired when several share one action name — e.g. a grid of option cards that
23
+ * all use `selectFlight`. Without it the agent has to ask the user what they just
24
+ * clicked, which reads as a broken assistant.
25
+ */
26
+ componentId: string;
27
+ /** The surface's collected data model (empty object when the surface binds no fields). */
28
+ data: Record<string, unknown>;
29
+ /**
30
+ * Present only when the user declined the surface and answered in words instead
31
+ * (see `buildDismissResult`). Absent on a normal submit or selection.
32
+ */
33
+ userMessage?: string;
34
+ }
35
+ /**
36
+ * Action name reported when the user dismisses an interactive surface rather than using it.
37
+ * Kept distinct from any model-authored action so the agent can tell the two apart.
38
+ */
39
+ declare const DISMISS_ACTION = "userDismissedSurface";
40
+ /**
41
+ * Complete a pending interactive surface *negatively*, optionally carrying the natural-language
42
+ * reply the user typed instead of interacting.
43
+ *
44
+ * Why this exists: an interactive surface parks the inference until a tool result arrives. If
45
+ * the UI is the only way to answer, a user who doesn't want any of the offered options is stuck
46
+ * — they cannot type, and the task never resumes. Completing with this result unparks the
47
+ * conversation and hands the agent the user's actual words, so it can respond to them.
48
+ */
49
+ declare function buildDismissResult(surfaceId: string, userMessage?: string): SurfaceResult;
50
+ /** Build the tool-completion `result` for an agent-bound action. */
51
+ declare function buildSurfaceResult(action: UIAction): SurfaceResult;
52
+ /** Agent-bound actions (wantResponse) return their payload to the agent; others stay local. */
53
+ declare function classifyAction(action: SurfaceAction): UIActionKind;
54
+ /** Actions are semantic names, never URLs. Reject anything scheme- or protocol-relative. */
55
+ declare function assertSafeActionName(name: string): void;
56
+
57
+ export { DISMISS_ACTION as D, type SurfaceResult as S, type UIAction as U, type UIActionKind as a, assertSafeActionName as b, buildDismissResult as c, buildSurfaceResult as d, classifyAction as e };
@@ -0,0 +1,57 @@
1
+ import { S as SurfaceAction } from './types-DnfWUE9V.mjs';
2
+
3
+ type UIActionKind = "agent-bound" | "local";
4
+ interface UIAction {
5
+ surfaceId: string;
6
+ componentId: string;
7
+ action: string;
8
+ kind: UIActionKind;
9
+ payload?: Record<string, unknown>;
10
+ }
11
+ /**
12
+ * The `result` body posted to /event/tool-completion for an agent-bound action.
13
+ * Shape is part of the agent-facing contract — the prompt clause describes it.
14
+ */
15
+ interface SurfaceResult {
16
+ /** The action's semantic name. */
17
+ action: string;
18
+ /** Which surface it came from. */
19
+ surfaceId: string;
20
+ /**
21
+ * The id of the component that was acted on. This is what lets the agent tell WHICH
22
+ * element fired when several share one action name — e.g. a grid of option cards that
23
+ * all use `selectFlight`. Without it the agent has to ask the user what they just
24
+ * clicked, which reads as a broken assistant.
25
+ */
26
+ componentId: string;
27
+ /** The surface's collected data model (empty object when the surface binds no fields). */
28
+ data: Record<string, unknown>;
29
+ /**
30
+ * Present only when the user declined the surface and answered in words instead
31
+ * (see `buildDismissResult`). Absent on a normal submit or selection.
32
+ */
33
+ userMessage?: string;
34
+ }
35
+ /**
36
+ * Action name reported when the user dismisses an interactive surface rather than using it.
37
+ * Kept distinct from any model-authored action so the agent can tell the two apart.
38
+ */
39
+ declare const DISMISS_ACTION = "userDismissedSurface";
40
+ /**
41
+ * Complete a pending interactive surface *negatively*, optionally carrying the natural-language
42
+ * reply the user typed instead of interacting.
43
+ *
44
+ * Why this exists: an interactive surface parks the inference until a tool result arrives. If
45
+ * the UI is the only way to answer, a user who doesn't want any of the offered options is stuck
46
+ * — they cannot type, and the task never resumes. Completing with this result unparks the
47
+ * conversation and hands the agent the user's actual words, so it can respond to them.
48
+ */
49
+ declare function buildDismissResult(surfaceId: string, userMessage?: string): SurfaceResult;
50
+ /** Build the tool-completion `result` for an agent-bound action. */
51
+ declare function buildSurfaceResult(action: UIAction): SurfaceResult;
52
+ /** Agent-bound actions (wantResponse) return their payload to the agent; others stay local. */
53
+ declare function classifyAction(action: SurfaceAction): UIActionKind;
54
+ /** Actions are semantic names, never URLs. Reject anything scheme- or protocol-relative. */
55
+ declare function assertSafeActionName(name: string): void;
56
+
57
+ export { DISMISS_ACTION as D, type SurfaceResult as S, type UIAction as U, type UIActionKind as a, assertSafeActionName as b, buildDismissResult as c, buildSurfaceResult as d, classifyAction as e };
@@ -3,7 +3,7 @@ export { S as SurfaceAction, T as ToolExecutionResponse } from '../types-DnfWUE9
3
3
  import { z } from 'zod';
4
4
  import { C as CatalogManifest, U as UIComponentDefinition } from '../registry-Bcu_ZYL1.mjs';
5
5
  export { a as UNKNOWN_COMPONENT, r as resolveComponent } from '../registry-Bcu_ZYL1.mjs';
6
- export { U as UIAction, a as UIActionKind, b as assertSafeActionName, c as classifyAction } from '../actions-Ca3ro-hX.mjs';
6
+ export { D as DISMISS_ACTION, S as SurfaceResult, U as UIAction, a as UIActionKind, b as assertSafeActionName, c as buildDismissResult, d as buildSurfaceResult, e as classifyAction } from '../actions-CZU_GRy5.mjs';
7
7
 
8
8
  /**
9
9
  * The agent-facing "style vocabulary" — enum-constrained semantic props that let
@@ -3,7 +3,7 @@ export { S as SurfaceAction, T as ToolExecutionResponse } from '../types-DnfWUE9
3
3
  import { z } from 'zod';
4
4
  import { C as CatalogManifest, U as UIComponentDefinition } from '../registry-Bcu_ZYL1.js';
5
5
  export { a as UNKNOWN_COMPONENT, r as resolveComponent } from '../registry-Bcu_ZYL1.js';
6
- export { U as UIAction, a as UIActionKind, b as assertSafeActionName, c as classifyAction } from '../actions-BebMyGqF.js';
6
+ export { D as DISMISS_ACTION, S as SurfaceResult, U as UIAction, a as UIActionKind, b as assertSafeActionName, c as buildDismissResult, d as buildSurfaceResult, e as classifyAction } from '../actions-B0hfoYRd.js';
7
7
 
8
8
  /**
9
9
  * The agent-facing "style vocabulary" — enum-constrained semantic props that let
@@ -23,13 +23,16 @@ __export(genui_exports, {
23
23
  ALIGNS: () => ALIGNS,
24
24
  CORE_CATALOG_ID: () => CORE_CATALOG_ID,
25
25
  DENSITIES: () => DENSITIES,
26
+ DISMISS_ACTION: () => DISMISS_ACTION,
26
27
  EMPHASES: () => EMPHASES,
27
28
  SIZES: () => SIZES,
28
29
  TONES: () => TONES,
29
30
  UNKNOWN_COMPONENT: () => UNKNOWN_COMPONENT,
30
31
  assertSafeActionName: () => assertSafeActionName,
32
+ buildDismissResult: () => buildDismissResult,
31
33
  buildGenuiClause: () => buildGenuiClause,
32
34
  buildRenderUiSchema: () => buildRenderUiSchema,
35
+ buildSurfaceResult: () => buildSurfaceResult,
33
36
  classifyAction: () => classifyAction,
34
37
  coreCatalog: () => coreCatalog,
35
38
  coreCatalogJson: () => core_v1_catalog_default,
@@ -219,6 +222,25 @@ function setPointer(model, pointer, value) {
219
222
  }
220
223
 
221
224
  // src/genui/actions.ts
225
+ var DISMISS_ACTION = "userDismissedSurface";
226
+ function buildDismissResult(surfaceId, userMessage) {
227
+ const said = typeof userMessage === "string" ? userMessage.trim() : "";
228
+ return {
229
+ action: DISMISS_ACTION,
230
+ surfaceId,
231
+ componentId: "",
232
+ data: {},
233
+ ...said ? { userMessage: said } : {}
234
+ };
235
+ }
236
+ function buildSurfaceResult(action) {
237
+ return {
238
+ action: action.action,
239
+ surfaceId: action.surfaceId,
240
+ componentId: action.componentId,
241
+ data: action.payload ?? {}
242
+ };
243
+ }
222
244
  function classifyAction(action) {
223
245
  return action.wantResponse === true ? "agent-bound" : "local";
224
246
  }
@@ -393,7 +415,9 @@ function buildGenuiClause(manifest, allowlist) {
393
415
  `Components: ${names.join(", ")}.`,
394
416
  `Style each component via the semantic vocabulary (never CSS, colors, or HTML): tone (${TONES.join("/")}), size (${SIZES.join("/")}), emphasis (low/medium/high), align (start/center/end), density (compact/comfortable), plus a component-specific variant where offered.`,
395
417
  "Data components MUST carry their data: Chart takes `data` (an array of row objects) + `series` (keys to plot) + `x` (the category key); Table takes `rows` (array of row objects) + `columns` ([{ key, header }] matching the row keys); List takes `items` (array); Stat takes `label`+`value`; KeyValue takes `data` (an object). Put the data inline on the component (or in dataModel referenced via `binding`).",
396
- "To collect input, add a Button with an action { name, wantResponse: true }; its result (the data model) is returned to you. A surface with no such button is display-only.",
418
+ "To collect input, add a Button with an action { name, wantResponse: true }. You get back { action, surfaceId, componentId, data } \u2014 `data` is the collected data model and `componentId` is the id of the component that was acted on. A surface with no such button is display-only.",
419
+ "When you render several options to choose from (a grid of cards, each with its own button), give every option component a MEANINGFUL id (e.g. flight-NH107, hotel-memmo-alfama): `componentId` tells you which one the user picked, so never ask them to repeat a choice they already made.",
420
+ 'The user may ignore an interactive surface and just type instead. You then receive action "userDismissedSurface" with their words in `userMessage` \u2014 treat it as their reply, answer it directly, and do not re-render the same surface or scold them for not using it.',
397
421
  "IMPORTANT: the rendered surface IS your reply \u2014 do NOT reproduce its content as text, markdown, or ASCII; a one-line intro at most.",
398
422
  "Prefer plain text for simple replies."
399
423
  ].join(" ");