@assistant-ui/react-generative-ui 0.0.24 → 0.1.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.
- package/README.md +2 -0
- package/dist/a2ui.d.ts +1 -4
- package/dist/a2ui.d.ts.map +1 -1
- package/dist/a2ui.js +1 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.server.d.ts +1 -2
- package/dist/index.server.d.ts.map +1 -1
- package/dist/index.server.js +1 -10
- package/dist/ir.d.ts +1 -111
- package/dist/ir.d.ts.map +1 -1
- package/dist/ir.js +1 -175
- package/dist/slack.d.ts +1 -4
- package/dist/slack.d.ts.map +1 -1
- package/dist/slack.js +1 -4
- package/dist/teams.d.ts +1 -4
- package/dist/teams.d.ts.map +1 -1
- package/dist/teams.js +1 -4
- package/package.json +4 -5
- package/src/a2ui.ts +1 -22
- package/src/index.server.ts +1 -2
- package/src/index.test.ts +75 -0
- package/src/index.ts +1 -2
- package/src/ir.ts +1 -279
- package/src/slack.ts +1 -39
- package/src/teams.ts +1 -35
- package/dist/JSONGenerativeUI.client.d.ts +0 -28
- package/dist/JSONGenerativeUI.client.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.client.js +0 -101
- package/dist/JSONGenerativeUI.client.js.map +0 -1
- package/dist/JSONGenerativeUI.server.d.ts +0 -21
- package/dist/JSONGenerativeUI.server.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.server.js +0 -32
- package/dist/JSONGenerativeUI.server.js.map +0 -1
- package/dist/JSONGenerativeUI.shared.d.ts +0 -63
- package/dist/JSONGenerativeUI.shared.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.shared.js +0 -31
- package/dist/JSONGenerativeUI.shared.js.map +0 -1
- package/dist/RadioGroupScope.d.ts +0 -6
- package/dist/RadioGroupScope.d.ts.map +0 -1
- package/dist/RadioGroupScope.js +0 -25
- package/dist/RadioGroupScope.js.map +0 -1
- package/dist/a2ui/BindingContext.d.ts +0 -11
- package/dist/a2ui/BindingContext.d.ts.map +0 -1
- package/dist/a2ui/BindingContext.js +0 -12
- package/dist/a2ui/BindingContext.js.map +0 -1
- package/dist/a2ui/PresentRenderer.d.ts +0 -11
- package/dist/a2ui/PresentRenderer.d.ts.map +0 -1
- package/dist/a2ui/PresentRenderer.js +0 -39
- package/dist/a2ui/PresentRenderer.js.map +0 -1
- package/dist/a2ui/convert.d.ts +0 -15
- package/dist/a2ui/convert.d.ts.map +0 -1
- package/dist/a2ui/convert.js +0 -728
- package/dist/a2ui/convert.js.map +0 -1
- package/dist/a2ui/dataModel.d.ts +0 -9
- package/dist/a2ui/dataModel.d.ts.map +0 -1
- package/dist/a2ui/dataModel.js +0 -44
- package/dist/a2ui/dataModel.js.map +0 -1
- package/dist/a2ui/reducer.d.ts +0 -8
- package/dist/a2ui/reducer.d.ts.map +0 -1
- package/dist/a2ui/reducer.js +0 -242
- package/dist/a2ui/reducer.js.map +0 -1
- package/dist/a2ui/snapshot.d.ts +0 -3
- package/dist/a2ui/snapshot.d.ts.map +0 -1
- package/dist/a2ui/snapshot.js +0 -33
- package/dist/a2ui/snapshot.js.map +0 -1
- package/dist/a2ui/types.d.ts +0 -88
- package/dist/a2ui/types.d.ts.map +0 -1
- package/dist/a2ui/types.js +0 -6
- package/dist/a2ui/types.js.map +0 -1
- package/dist/a2ui/valueFunctions.d.ts +0 -16
- package/dist/a2ui/valueFunctions.d.ts.map +0 -1
- package/dist/a2ui/valueFunctions.js +0 -332
- package/dist/a2ui/valueFunctions.js.map +0 -1
- package/dist/actionRegistry.d.ts +0 -29
- package/dist/actionRegistry.d.ts.map +0 -1
- package/dist/actionRegistry.js +0 -41
- package/dist/actionRegistry.js.map +0 -1
- package/dist/answeredValues.d.ts +0 -16
- package/dist/answeredValues.d.ts.map +0 -1
- package/dist/answeredValues.js +0 -37
- package/dist/answeredValues.js.map +0 -1
- package/dist/buildPresentParameters.d.ts +0 -21
- package/dist/buildPresentParameters.d.ts.map +0 -1
- package/dist/buildPresentParameters.js +0 -95
- package/dist/buildPresentParameters.js.map +0 -1
- package/dist/constants.d.ts +0 -15
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -19
- package/dist/constants.js.map +0 -1
- package/dist/convert/boundSpec.d.ts +0 -48
- package/dist/convert/boundSpec.d.ts.map +0 -1
- package/dist/convert/boundSpec.js +0 -108
- package/dist/convert/boundSpec.js.map +0 -1
- package/dist/convert/copyBounded.d.ts +0 -25
- package/dist/convert/copyBounded.d.ts.map +0 -1
- package/dist/convert/copyBounded.js +0 -38
- package/dist/convert/copyBounded.js.map +0 -1
- package/dist/convert/isElement.d.ts +0 -3
- package/dist/convert/isElement.d.ts.map +0 -1
- package/dist/convert/isElement.js +0 -6
- package/dist/convert/isElement.js.map +0 -1
- package/dist/convert/takeRun.d.ts +0 -6
- package/dist/convert/takeRun.d.ts.map +0 -1
- package/dist/convert/takeRun.js +0 -20
- package/dist/convert/takeRun.js.map +0 -1
- package/dist/defineGenerativeComponents.d.ts +0 -29
- package/dist/defineGenerativeComponents.d.ts.map +0 -1
- package/dist/defineGenerativeComponents.js +0 -34
- package/dist/defineGenerativeComponents.js.map +0 -1
- package/dist/fieldReferences.d.ts +0 -9
- package/dist/fieldReferences.d.ts.map +0 -1
- package/dist/fieldReferences.js +0 -53
- package/dist/fieldReferences.js.map +0 -1
- package/dist/generativeUIToJSX.d.ts +0 -18
- package/dist/generativeUIToJSX.d.ts.map +0 -1
- package/dist/generativeUIToJSX.js +0 -76
- package/dist/generativeUIToJSX.js.map +0 -1
- package/dist/index.shared.d.ts +0 -15
- package/dist/index.shared.d.ts.map +0 -1
- package/dist/index.shared.js +0 -9
- package/dist/ir.js.map +0 -1
- package/dist/renderGenerativeUI.d.ts +0 -14
- package/dist/renderGenerativeUI.d.ts.map +0 -1
- package/dist/renderGenerativeUI.js +0 -83
- package/dist/renderGenerativeUI.js.map +0 -1
- package/dist/scopeSchema.d.ts +0 -6
- package/dist/scopeSchema.d.ts.map +0 -1
- package/dist/scopeSchema.js +0 -56
- package/dist/scopeSchema.js.map +0 -1
- package/dist/slack/constants.d.ts +0 -93
- package/dist/slack/constants.d.ts.map +0 -1
- package/dist/slack/constants.js +0 -146
- package/dist/slack/constants.js.map +0 -1
- package/dist/slack/decodeBlockAction.d.ts +0 -10
- package/dist/slack/decodeBlockAction.d.ts.map +0 -1
- package/dist/slack/decodeBlockAction.js +0 -129
- package/dist/slack/decodeBlockAction.js.map +0 -1
- package/dist/slack/fromSlackBlocks.d.ts +0 -27
- package/dist/slack/fromSlackBlocks.d.ts.map +0 -1
- package/dist/slack/fromSlackBlocks.js +0 -483
- package/dist/slack/fromSlackBlocks.js.map +0 -1
- package/dist/slack/toSlackBlocks.d.ts +0 -4
- package/dist/slack/toSlackBlocks.d.ts.map +0 -1
- package/dist/slack/toSlackBlocks.js +0 -901
- package/dist/slack/toSlackBlocks.js.map +0 -1
- package/dist/slack/types.d.ts +0 -204
- package/dist/slack/types.d.ts.map +0 -1
- package/dist/slack/types.js +0 -0
- package/dist/teams/constants.d.ts +0 -34
- package/dist/teams/constants.d.ts.map +0 -1
- package/dist/teams/constants.js +0 -68
- package/dist/teams/constants.js.map +0 -1
- package/dist/teams/decodeSubmitData.d.ts +0 -26
- package/dist/teams/decodeSubmitData.d.ts.map +0 -1
- package/dist/teams/decodeSubmitData.js +0 -70
- package/dist/teams/decodeSubmitData.js.map +0 -1
- package/dist/teams/temporalId.d.ts +0 -5
- package/dist/teams/temporalId.d.ts.map +0 -1
- package/dist/teams/temporalId.js +0 -28
- package/dist/teams/temporalId.js.map +0 -1
- package/dist/teams/toAdaptiveCard.d.ts +0 -45
- package/dist/teams/toAdaptiveCard.d.ts.map +0 -1
- package/dist/teams/toAdaptiveCard.js +0 -642
- package/dist/teams/toAdaptiveCard.js.map +0 -1
- package/dist/teams/toTeamsAttachments.d.ts +0 -10
- package/dist/teams/toTeamsAttachments.d.ts.map +0 -1
- package/dist/teams/toTeamsAttachments.js +0 -99
- package/dist/teams/toTeamsAttachments.js.map +0 -1
- package/dist/teams/types.d.ts +0 -224
- package/dist/teams/types.d.ts.map +0 -1
- package/dist/teams/types.js +0 -0
- package/dist/temporal.d.ts +0 -33
- package/dist/temporal.d.ts.map +0 -1
- package/dist/temporal.js +0 -153
- package/dist/temporal.js.map +0 -1
- package/dist/types.d.ts +0 -99
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -0
- package/dist/vocabulary/alert.d.ts +0 -32
- package/dist/vocabulary/alert.d.ts.map +0 -1
- package/dist/vocabulary/alert.js +0 -160
- package/dist/vocabulary/alert.js.map +0 -1
- package/dist/vocabulary/collectFormValues.d.ts +0 -23
- package/dist/vocabulary/collectFormValues.d.ts.map +0 -1
- package/dist/vocabulary/collectFormValues.js +0 -44
- package/dist/vocabulary/collectFormValues.js.map +0 -1
- package/dist/vocabulary/data.d.ts +0 -66
- package/dist/vocabulary/data.d.ts.map +0 -1
- package/dist/vocabulary/data.js +0 -503
- package/dist/vocabulary/data.js.map +0 -1
- package/dist/vocabulary/dispatch.d.ts +0 -9
- package/dist/vocabulary/dispatch.d.ts.map +0 -1
- package/dist/vocabulary/dispatch.js +0 -50
- package/dist/vocabulary/dispatch.js.map +0 -1
- package/dist/vocabulary/fact.d.ts +0 -19
- package/dist/vocabulary/fact.d.ts.map +0 -1
- package/dist/vocabulary/fact.js +0 -51
- package/dist/vocabulary/fact.js.map +0 -1
- package/dist/vocabulary/form.d.ts +0 -11
- package/dist/vocabulary/form.d.ts.map +0 -1
- package/dist/vocabulary/form.js +0 -23
- package/dist/vocabulary/form.js.map +0 -1
- package/dist/vocabulary/formatValue.d.ts +0 -7
- package/dist/vocabulary/formatValue.d.ts.map +0 -1
- package/dist/vocabulary/formatValue.js +0 -76
- package/dist/vocabulary/formatValue.js.map +0 -1
- package/dist/vocabulary/icon.d.ts +0 -41
- package/dist/vocabulary/icon.d.ts.map +0 -1
- package/dist/vocabulary/icon.js +0 -272
- package/dist/vocabulary/icon.js.map +0 -1
- package/dist/vocabulary/index.d.ts +0 -12
- package/dist/vocabulary/index.d.ts.map +0 -1
- package/dist/vocabulary/index.js +0 -36
- package/dist/vocabulary/index.js.map +0 -1
- package/dist/vocabulary/interactive.d.ts +0 -230
- package/dist/vocabulary/interactive.d.ts.map +0 -1
- package/dist/vocabulary/interactive.js +0 -584
- package/dist/vocabulary/interactive.js.map +0 -1
- package/dist/vocabulary/layout.d.ts +0 -79
- package/dist/vocabulary/layout.d.ts.map +0 -1
- package/dist/vocabulary/layout.js +0 -139
- package/dist/vocabulary/layout.js.map +0 -1
- package/dist/vocabulary/list.d.ts +0 -14
- package/dist/vocabulary/list.d.ts.map +0 -1
- package/dist/vocabulary/list.js +0 -50
- package/dist/vocabulary/list.js.map +0 -1
- package/dist/vocabulary/media.d.ts +0 -25
- package/dist/vocabulary/media.d.ts.map +0 -1
- package/dist/vocabulary/media.js +0 -42
- package/dist/vocabulary/media.js.map +0 -1
- package/dist/vocabulary/text.d.ts +0 -57
- package/dist/vocabulary/text.d.ts.map +0 -1
- package/dist/vocabulary/text.js +0 -49
- package/dist/vocabulary/text.js.map +0 -1
- package/dist/vocabulary/toTextContent.d.ts +0 -2
- package/dist/vocabulary/toTextContent.d.ts.map +0 -1
- package/dist/vocabulary/toTextContent.js +0 -6
- package/dist/vocabulary/toTextContent.js.map +0 -1
- package/src/JSONGenerativeUI.client.tsx +0 -168
- package/src/JSONGenerativeUI.server.tsx +0 -39
- package/src/JSONGenerativeUI.shared.ts +0 -90
- package/src/JSONGenerativeUI.test.tsx +0 -1298
- package/src/RadioGroupScope.server.test.tsx +0 -24
- package/src/RadioGroupScope.tsx +0 -34
- package/src/a2ui/BindingContext.ts +0 -26
- package/src/a2ui/PresentRenderer.tsx +0 -83
- package/src/a2ui/convert.test.ts +0 -2923
- package/src/a2ui/convert.ts +0 -1207
- package/src/a2ui/dataModel.ts +0 -69
- package/src/a2ui/reducer.test.ts +0 -422
- package/src/a2ui/reducer.ts +0 -363
- package/src/a2ui/snapshot.test.ts +0 -52
- package/src/a2ui/snapshot.ts +0 -52
- package/src/a2ui/types.ts +0 -114
- package/src/a2ui/valueFunctions.test.ts +0 -271
- package/src/a2ui/valueFunctions.ts +0 -523
- package/src/actionRegistry.test.ts +0 -90
- package/src/actionRegistry.ts +0 -88
- package/src/answeredValues.test.ts +0 -33
- package/src/answeredValues.tsx +0 -70
- package/src/buildPresentParameters.test.ts +0 -246
- package/src/buildPresentParameters.ts +0 -130
- package/src/constants.ts +0 -17
- package/src/convert/boundSpec.test.ts +0 -192
- package/src/convert/boundSpec.ts +0 -134
- package/src/convert/copyBounded.test.ts +0 -131
- package/src/convert/copyBounded.ts +0 -38
- package/src/convert/isElement.ts +0 -6
- package/src/convert/takeRun.test.ts +0 -64
- package/src/convert/takeRun.ts +0 -19
- package/src/defineGenerativeComponents.ts +0 -38
- package/src/fieldReferences.test.ts +0 -66
- package/src/fieldReferences.ts +0 -83
- package/src/generativeUIToJSX.test.ts +0 -268
- package/src/generativeUIToJSX.ts +0 -152
- package/src/index.server.test.ts +0 -106
- package/src/index.shared.ts +0 -61
- package/src/ir.test.ts +0 -203
- package/src/renderGenerativeUI.test.tsx +0 -373
- package/src/renderGenerativeUI.tsx +0 -165
- package/src/scopeSchema.test.ts +0 -72
- package/src/scopeSchema.ts +0 -71
- package/src/slack/a2uiSlack.test.ts +0 -198
- package/src/slack/constants.ts +0 -194
- package/src/slack/datePicker.test.ts +0 -612
- package/src/slack/decodeBlockAction.test.ts +0 -233
- package/src/slack/decodeBlockAction.ts +0 -232
- package/src/slack/fromSlackBlocks.test.ts +0 -1465
- package/src/slack/fromSlackBlocks.ts +0 -789
- package/src/slack/toSlackBlocks.test.ts +0 -3065
- package/src/slack/toSlackBlocks.ts +0 -1818
- package/src/slack/types.ts +0 -264
- package/src/teams/constants.ts +0 -93
- package/src/teams/decodeSubmitData.test.ts +0 -397
- package/src/teams/decodeSubmitData.ts +0 -110
- package/src/teams/temporal.test.ts +0 -766
- package/src/teams/temporalId.ts +0 -56
- package/src/teams/toAdaptiveCard.test.ts +0 -1897
- package/src/teams/toAdaptiveCard.ts +0 -1057
- package/src/teams/toTeamsAttachments.test.ts +0 -74
- package/src/teams/toTeamsAttachments.ts +0 -133
- package/src/teams/types.ts +0 -266
- package/src/temporal.test.ts +0 -337
- package/src/temporal.ts +0 -263
- package/src/types.ts +0 -119
- package/src/vocabulary/alert.test.tsx +0 -427
- package/src/vocabulary/alert.tsx +0 -217
- package/src/vocabulary/collectFormValues.test.ts +0 -389
- package/src/vocabulary/collectFormValues.ts +0 -116
- package/src/vocabulary/data.test.tsx +0 -858
- package/src/vocabulary/data.tsx +0 -819
- package/src/vocabulary/datepicker.dom.test.tsx +0 -1457
- package/src/vocabulary/dispatch.ts +0 -83
- package/src/vocabulary/fact.test.tsx +0 -94
- package/src/vocabulary/fact.tsx +0 -54
- package/src/vocabulary/form.test.tsx +0 -113
- package/src/vocabulary/form.tsx +0 -39
- package/src/vocabulary/formatValue.test.ts +0 -72
- package/src/vocabulary/formatValue.ts +0 -127
- package/src/vocabulary/icon.test.tsx +0 -64
- package/src/vocabulary/icon.tsx +0 -174
- package/src/vocabulary/index.test.ts +0 -65
- package/src/vocabulary/index.ts +0 -33
- package/src/vocabulary/interactive.dispatch.test.tsx +0 -454
- package/src/vocabulary/interactive.dom.test.tsx +0 -1747
- package/src/vocabulary/interactive.test.tsx +0 -377
- package/src/vocabulary/interactive.tsx +0 -1109
- package/src/vocabulary/layout.test.tsx +0 -323
- package/src/vocabulary/layout.tsx +0 -247
- package/src/vocabulary/list.test.tsx +0 -222
- package/src/vocabulary/list.tsx +0 -50
- package/src/vocabulary/media.test.tsx +0 -85
- package/src/vocabulary/media.tsx +0 -56
- package/src/vocabulary/text.test.tsx +0 -102
- package/src/vocabulary/text.tsx +0 -60
- package/src/vocabulary/toTextContent.ts +0 -2
package/src/ir.ts
CHANGED
|
@@ -1,279 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* The generative-ui intermediate representation: a model-emitted, cross-platform
|
|
3
|
-
* UI tree. React-free, so converters and non-web runtimes consume it without
|
|
4
|
-
* pulling React. The flat `$type` shape is the canonical form; the legacy
|
|
5
|
-
* `component` shape is accepted as a backward-compatible alias.
|
|
6
|
-
*
|
|
7
|
-
* Reserved keys are partitioned off from component props so the component prop
|
|
8
|
-
* namespace stays fully free:
|
|
9
|
-
*
|
|
10
|
-
* - `$`-prefixed keys are framework-reserved (`$type`, `$key`, `$action`,
|
|
11
|
-
* `$status`). Components never declare `$`-prefixed props, so a component
|
|
12
|
-
* can use `type`, `status`, `variant`, etc. as ordinary props without
|
|
13
|
-
* colliding with the framework.
|
|
14
|
-
* - `children` is additionally reserved (the JSX convention).
|
|
15
|
-
* - every other key is an inline prop passed straight to the component.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { TYPE_KEY } from "./constants";
|
|
19
|
-
|
|
20
|
-
export const TEXT_SIZES = ["sm", "md", "lg", "xl", "2xl", "3xl"] as const;
|
|
21
|
-
export type TextSize = (typeof TEXT_SIZES)[number];
|
|
22
|
-
|
|
23
|
-
export const IMAGE_SIZE_TOKENS = ["sm", "md", "lg"] as const;
|
|
24
|
-
export type ImageSize = (typeof IMAGE_SIZE_TOKENS)[number] | number;
|
|
25
|
-
|
|
26
|
-
export const WEIGHTS = ["normal", "medium", "semibold", "bold"] as const;
|
|
27
|
-
export type Weight = (typeof WEIGHTS)[number];
|
|
28
|
-
|
|
29
|
-
export const COLORS = [
|
|
30
|
-
"emphasis",
|
|
31
|
-
"secondary",
|
|
32
|
-
"alpha-70",
|
|
33
|
-
"white",
|
|
34
|
-
"white-70",
|
|
35
|
-
"white-50",
|
|
36
|
-
] as const;
|
|
37
|
-
export type Color = (typeof COLORS)[number];
|
|
38
|
-
|
|
39
|
-
export const ALIGNS = ["start", "center", "end"] as const;
|
|
40
|
-
export type Align = (typeof ALIGNS)[number];
|
|
41
|
-
|
|
42
|
-
export const JUSTIFIES = ["start", "center", "end", "between"] as const;
|
|
43
|
-
export type Justify = (typeof JUSTIFIES)[number];
|
|
44
|
-
|
|
45
|
-
export const BUTTON_STYLES = [
|
|
46
|
-
"primary",
|
|
47
|
-
"secondary",
|
|
48
|
-
"outline",
|
|
49
|
-
"ghost",
|
|
50
|
-
"danger",
|
|
51
|
-
] as const;
|
|
52
|
-
export type ButtonStyle = (typeof BUTTON_STYLES)[number];
|
|
53
|
-
|
|
54
|
-
export const ALERT_TONES = ["info", "success", "warning", "danger"] as const;
|
|
55
|
-
/** A severity level, from informational to destructive. */
|
|
56
|
-
export type AlertTone = (typeof ALERT_TONES)[number];
|
|
57
|
-
|
|
58
|
-
export const ICON_NAMES = [
|
|
59
|
-
"sun",
|
|
60
|
-
"moon",
|
|
61
|
-
"cloud",
|
|
62
|
-
"rain",
|
|
63
|
-
"snow",
|
|
64
|
-
"wind",
|
|
65
|
-
"play",
|
|
66
|
-
"pause",
|
|
67
|
-
"check",
|
|
68
|
-
"x",
|
|
69
|
-
"star",
|
|
70
|
-
"heart",
|
|
71
|
-
"arrow-right",
|
|
72
|
-
"arrow-up-right",
|
|
73
|
-
"chevron-right",
|
|
74
|
-
"calendar",
|
|
75
|
-
"clock",
|
|
76
|
-
"map-pin",
|
|
77
|
-
"plane",
|
|
78
|
-
"truck",
|
|
79
|
-
"credit-card",
|
|
80
|
-
"user",
|
|
81
|
-
"search",
|
|
82
|
-
"bell",
|
|
83
|
-
] as const;
|
|
84
|
-
/** A name from the built-in icon set; the closed enum lets the model see exactly which icons exist. */
|
|
85
|
-
export type IconName = (typeof ICON_NAMES)[number];
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Behavior payload carried by an interactive node. `type` is resolved by the host's action registry, not the renderer; keeping behavior as data keeps the tree serializable, so the same node renders on web while converters may bind the type to a native action id on other platforms. A `{ "$field": name }` value anywhere in the payload refers to the current value of the control with that `name`, resolved when the action fires, and `{ "$field": name, "fallback": value }` resolves to `fallback` when no control holds a value.
|
|
89
|
-
*/
|
|
90
|
-
export interface Action {
|
|
91
|
-
readonly type: string;
|
|
92
|
-
readonly [payload: string]: unknown;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Anything renderable as generative UI, as the model emits it. The renderer
|
|
97
|
-
* also accepts `number`, `boolean`, `null`, `undefined`, and arrays at the
|
|
98
|
-
* input boundary (numbers render as text, falsy/boolean as nothing, arrays as
|
|
99
|
-
* lists); {@link normalizeUINode} accepts that full range.
|
|
100
|
-
*/
|
|
101
|
-
export type UINode = string | number | UIElement | LegacyComponentNode;
|
|
102
|
-
|
|
103
|
-
export type UIChildren = UINode | readonly UINode[];
|
|
104
|
-
|
|
105
|
-
/** The flat node shape: inline props keep the tree compact and natural for a
|
|
106
|
-
* model to emit, instead of a nested `{ type, props }` bag. Reserved keys are
|
|
107
|
-
* stripped before props reach the component (see the module header). */
|
|
108
|
-
export interface UIElement {
|
|
109
|
-
readonly $type: string;
|
|
110
|
-
readonly $key?: string | number;
|
|
111
|
-
readonly children?: UIChildren;
|
|
112
|
-
readonly $action?: Action;
|
|
113
|
-
readonly [prop: string]: unknown;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* The legacy node shape: a `component` name plus a nested `props` bag. Kept
|
|
118
|
-
* for backward compatibility. New code authors the flat {@link UIElement}
|
|
119
|
-
* shape instead.
|
|
120
|
-
*/
|
|
121
|
-
export interface LegacyComponentNode {
|
|
122
|
-
readonly component: string;
|
|
123
|
-
readonly props?: Record<string, unknown>;
|
|
124
|
-
readonly children?: UIChildren;
|
|
125
|
-
readonly key?: string;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export type UISpec = UINode | readonly UINode[];
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* A node normalized to a single canonical shape: a `type` string, an inline
|
|
132
|
-
* `props` bag, recursive `children`, an optional `key`, and an optional
|
|
133
|
-
* `action`. Renderers and platform converters consume this form, so they never
|
|
134
|
-
* branch on whether the model emitted the flat `$type` shape or the legacy
|
|
135
|
-
* `component` shape, and they never see the reserved `$`-prefixed keys leak
|
|
136
|
-
* into component props.
|
|
137
|
-
*/
|
|
138
|
-
export interface NormalizedUIElement {
|
|
139
|
-
readonly type: string;
|
|
140
|
-
readonly props: Readonly<Record<string, unknown>>;
|
|
141
|
-
readonly children?: NormalizedUINode | undefined;
|
|
142
|
-
readonly key?: string | number | undefined;
|
|
143
|
-
readonly action?: Action | undefined;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export type NormalizedUINode =
|
|
147
|
-
| string
|
|
148
|
-
| number
|
|
149
|
-
| readonly NormalizedUINode[]
|
|
150
|
-
| NormalizedUIElement
|
|
151
|
-
| null;
|
|
152
|
-
|
|
153
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
154
|
-
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
155
|
-
|
|
156
|
-
type LegacyNodeRecord = { component: string } & Record<string, unknown>;
|
|
157
|
-
|
|
158
|
-
const isLegacyNode = (
|
|
159
|
-
node: Record<string, unknown>,
|
|
160
|
-
): node is LegacyNodeRecord => typeof node["component"] === "string";
|
|
161
|
-
|
|
162
|
-
const isTypeNode = (node: Record<string, unknown>): node is UIElement =>
|
|
163
|
-
typeof node[TYPE_KEY] === "string";
|
|
164
|
-
|
|
165
|
-
/** Bounds recursion so a runaway or adversarial model response cannot overflow
|
|
166
|
-
* the stack; past this depth (far beyond any real UI) we stop. */
|
|
167
|
-
const MAX_DEPTH = 64;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Steps a streaming partial path down into `key`. `partialPath` is the remaining
|
|
171
|
-
* segment of the parse meta's partial path relative to `node` (`undefined` once
|
|
172
|
-
* the walk leaves the partial frontier, i.e. everything below is complete).
|
|
173
|
-
*/
|
|
174
|
-
function descend(
|
|
175
|
-
partialPath: readonly string[] | undefined,
|
|
176
|
-
key: string,
|
|
177
|
-
): readonly string[] | undefined {
|
|
178
|
-
return partialPath?.[0] === key ? partialPath.slice(1) : undefined;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Normalizes a generative-ui input to {@link NormalizedUINode}. The flat
|
|
183
|
-
* `$type` shape and the legacy `component` shape both map to the same canonical
|
|
184
|
-
* element, with reserved keys (`$type`, `$key`, `$action`, `children`) stripped
|
|
185
|
-
* from the prop bag. A node that carries neither a `$type` nor a `component`
|
|
186
|
-
* string is not renderable and resolves to `null` rather than throwing, so a
|
|
187
|
-
* partially-streamed or malformed node degrades to "render nothing".
|
|
188
|
-
*
|
|
189
|
-
* `partialPath` carries streaming state from the tool-args parse meta: a node
|
|
190
|
-
* whose `$type` is still mid-arrival is held back (resolves to `null`) until it
|
|
191
|
-
* completes, and the path is threaded into `children` so a nested streaming
|
|
192
|
-
* node is held back while completed siblings render. Omit it for a
|
|
193
|
-
* non-streaming (converter) normalize.
|
|
194
|
-
*/
|
|
195
|
-
export function normalizeUINode(
|
|
196
|
-
node: unknown,
|
|
197
|
-
partialPath?: readonly string[] | undefined,
|
|
198
|
-
depth = 0,
|
|
199
|
-
): NormalizedUINode {
|
|
200
|
-
if (depth > MAX_DEPTH) return null;
|
|
201
|
-
if (node == null || typeof node === "boolean") return null;
|
|
202
|
-
if (typeof node === "string" || typeof node === "number") return node;
|
|
203
|
-
if (Array.isArray(node))
|
|
204
|
-
return node.map((child, index) =>
|
|
205
|
-
normalizeUINode(child, descend(partialPath, String(index)), depth + 1),
|
|
206
|
-
);
|
|
207
|
-
if (!isRecord(node)) return null;
|
|
208
|
-
|
|
209
|
-
// The flat `$type` shape is the canonical form; detect it first so a flat
|
|
210
|
-
// node that happens to use `component` as an ordinary prop is not swallowed
|
|
211
|
-
// by the legacy `component`-shape branch.
|
|
212
|
-
if (isTypeNode(node)) {
|
|
213
|
-
if (partialPath?.length === 1 && partialPath[0] === TYPE_KEY) return null;
|
|
214
|
-
const { [TYPE_KEY]: type, $key, $action, children, ...rest } = node;
|
|
215
|
-
// The `$`-prefixed namespace is framework-reserved (see the module header),
|
|
216
|
-
// so any model-supplied `$`-prefixed key is stripped from the prop bag the
|
|
217
|
-
// component sees. `$type`/`$key`/`$action` are pulled above; sweep the rest
|
|
218
|
-
// (e.g. a stray `$status`) so it never leaks to converters or components.
|
|
219
|
-
const props = stripReservedProps(rest);
|
|
220
|
-
return {
|
|
221
|
-
type,
|
|
222
|
-
props,
|
|
223
|
-
children: normalizeChildren(children, partialPath, depth),
|
|
224
|
-
key: $key,
|
|
225
|
-
action: $action,
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (isLegacyNode(node)) {
|
|
230
|
-
const props = stripReservedProps(
|
|
231
|
-
(node.props ?? {}) as Record<string, unknown>,
|
|
232
|
-
);
|
|
233
|
-
return {
|
|
234
|
-
type: node.component,
|
|
235
|
-
props,
|
|
236
|
-
children: normalizeChildren(node.children, partialPath, depth),
|
|
237
|
-
key: node.key as string | undefined,
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function stripReservedProps(
|
|
245
|
-
props: Record<string, unknown>,
|
|
246
|
-
): Record<string, unknown> {
|
|
247
|
-
let out: Record<string, unknown> | undefined;
|
|
248
|
-
for (const key of Object.keys(props)) {
|
|
249
|
-
if (key.startsWith("$")) {
|
|
250
|
-
out ??= { ...props };
|
|
251
|
-
delete out[key];
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return out ?? props;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function normalizeChildren(
|
|
258
|
-
children: unknown,
|
|
259
|
-
partialPath: readonly string[] | undefined,
|
|
260
|
-
depth: number,
|
|
261
|
-
): NormalizedUINode | undefined {
|
|
262
|
-
if (children === undefined) return undefined;
|
|
263
|
-
return normalizeUINode(children, descend(partialPath, "children"), depth + 1);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Normalizes the root of a {@link UISpec}, preserving whether the root was a
|
|
268
|
-
* single node or a list.
|
|
269
|
-
*/
|
|
270
|
-
export function normalizeSpec(spec: UISpec): {
|
|
271
|
-
readonly root: NormalizedUINode | readonly NormalizedUINode[];
|
|
272
|
-
} {
|
|
273
|
-
if (Array.isArray(spec)) {
|
|
274
|
-
return {
|
|
275
|
-
root: (spec as readonly UINode[]).map((node) => normalizeUINode(node)),
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
return { root: normalizeUINode(spec) };
|
|
279
|
-
}
|
|
1
|
+
export * from "@assistant-ui/generative-ui";
|
package/src/slack.ts
CHANGED
|
@@ -1,39 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { fromSlackBlocks } from "./slack/fromSlackBlocks";
|
|
3
|
-
export { toSlackBlocks } from "./slack/toSlackBlocks";
|
|
4
|
-
export type {
|
|
5
|
-
FromSlackBlocksResult,
|
|
6
|
-
SlackActionElement,
|
|
7
|
-
SlackActionsBlock,
|
|
8
|
-
SlackAlertBlock,
|
|
9
|
-
SlackAlertLevel,
|
|
10
|
-
SlackBlock,
|
|
11
|
-
SlackBlocksResult,
|
|
12
|
-
SlackButtonElement,
|
|
13
|
-
SlackCardBlock,
|
|
14
|
-
SlackCarouselBlock,
|
|
15
|
-
SlackCheckboxesElement,
|
|
16
|
-
SlackContextBlock,
|
|
17
|
-
SlackConversionWarning,
|
|
18
|
-
SlackDataTableBlock,
|
|
19
|
-
SlackDataTableCell,
|
|
20
|
-
SlackDataTableRawNumberCell,
|
|
21
|
-
SlackDataTableRawTextCell,
|
|
22
|
-
SlackDatePickerElement,
|
|
23
|
-
SlackDateTimePickerElement,
|
|
24
|
-
SlackDividerBlock,
|
|
25
|
-
SlackHeaderBlock,
|
|
26
|
-
SlackImageBlock,
|
|
27
|
-
SlackInputBlock,
|
|
28
|
-
SlackMarkdownBlock,
|
|
29
|
-
SlackMrkdwnText,
|
|
30
|
-
SlackOption,
|
|
31
|
-
SlackPlainText,
|
|
32
|
-
SlackPlainTextInputElement,
|
|
33
|
-
SlackRadioButtonsElement,
|
|
34
|
-
SlackSectionBlock,
|
|
35
|
-
SlackStaticSelectElement,
|
|
36
|
-
SlackTextObject,
|
|
37
|
-
SlackTimePickerElement,
|
|
38
|
-
ToSlackBlocksOptions,
|
|
39
|
-
} from "./slack/types";
|
|
1
|
+
export * from "@assistant-ui/generative-ui/slack";
|
package/src/teams.ts
CHANGED
|
@@ -1,35 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { toAdaptiveCard } from "./teams/toAdaptiveCard";
|
|
3
|
-
export { toTeamsAttachments } from "./teams/toTeamsAttachments";
|
|
4
|
-
export type {
|
|
5
|
-
AdaptiveCardResult,
|
|
6
|
-
TeamsAdaptiveCard,
|
|
7
|
-
TeamsActionSet,
|
|
8
|
-
TeamsAttachmentsResult,
|
|
9
|
-
TeamsCardAction,
|
|
10
|
-
TeamsCardAttachment,
|
|
11
|
-
TeamsCardElement,
|
|
12
|
-
TeamsColumn,
|
|
13
|
-
TeamsColumnSet,
|
|
14
|
-
TeamsContainer,
|
|
15
|
-
TeamsContainerStyle,
|
|
16
|
-
TeamsConversionWarning,
|
|
17
|
-
TeamsFact,
|
|
18
|
-
TeamsFactSet,
|
|
19
|
-
TeamsImage,
|
|
20
|
-
TeamsInputChoice,
|
|
21
|
-
TeamsInputChoiceSet,
|
|
22
|
-
TeamsInputDate,
|
|
23
|
-
TeamsInputText,
|
|
24
|
-
TeamsInputTime,
|
|
25
|
-
TeamsInputToggle,
|
|
26
|
-
TeamsSubmitAction,
|
|
27
|
-
TeamsSubmitData,
|
|
28
|
-
TeamsTable,
|
|
29
|
-
TeamsTableCell,
|
|
30
|
-
TeamsTableColumnDefinition,
|
|
31
|
-
TeamsTableRow,
|
|
32
|
-
TeamsTextBlock,
|
|
33
|
-
TeamsTextSize,
|
|
34
|
-
ToAdaptiveCardOptions,
|
|
35
|
-
} from "./teams/types";
|
|
1
|
+
export * from "@assistant-ui/generative-ui/teams";
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type JSONGenerativeUIOptions, type PresentTool, type PresentToolOptions, type PromptUserTool } from "./JSONGenerativeUI.shared.js";
|
|
2
|
-
/**
|
|
3
|
-
* Client build of {@link JSONGenerativeUI}, resolved through the package's
|
|
4
|
-
* `default` export condition (browser and SSR).
|
|
5
|
-
*
|
|
6
|
-
* `present` is a frontend tool that renders the model's `{ $type, ...props }`
|
|
7
|
-
* tree against the library and resolves immediately. `prompt_user` is a
|
|
8
|
-
* human-in-the-loop tool: the model pauses and the rendered UI supplies the
|
|
9
|
-
* result. Both draw the tree the same way, so they share one `render`. The
|
|
10
|
-
* `actions` registry (if provided) is threaded into the render context so
|
|
11
|
-
* interactive components can fire `$action` through `$dispatch`.
|
|
12
|
-
*/
|
|
13
|
-
export declare class JSONGenerativeUI {
|
|
14
|
-
private readonly library;
|
|
15
|
-
private readonly parameters;
|
|
16
|
-
private readonly actions;
|
|
17
|
-
private readonly completedPromptToolCallIds;
|
|
18
|
-
constructor(options: JSONGenerativeUIOptions);
|
|
19
|
-
/**
|
|
20
|
-
* The surface a `present` call paints into. It owns the vertical rhythm
|
|
21
|
-
* between top-level blocks, which the host's message container does not
|
|
22
|
-
* provide, and stays out of the way while it has nothing to show.
|
|
23
|
-
*/
|
|
24
|
-
private readonly render;
|
|
25
|
-
present(options?: PresentToolOptions): PresentTool;
|
|
26
|
-
promptUser(): PromptUserTool;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=JSONGenerativeUI.client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JSONGenerativeUI.client.d.ts","sourceRoot":"","sources":["../src/JSONGenerativeUI.client.tsx"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,uBAAuB,EAE5B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,qCAAkC;AAiBnC;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAqB;gBAEpD,OAAO,EAAE,uBAAuB;IAM5C;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CA0FrB;IAEF,OAAO,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW;IASlD,UAAU,IAAI,cAAc;CAO7B"}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { renderGenerativeUI } from "./renderGenerativeUI.js";
|
|
2
|
-
import { A2uiPresentRenderer } from "./a2ui/PresentRenderer.js";
|
|
3
|
-
import { AnsweredValuesProvider, findAnsweredValues } from "./answeredValues.js";
|
|
4
|
-
import { buildPresentParameters } from "./buildPresentParameters.js";
|
|
5
|
-
import { presentToolBase, promptUserToolBase } from "./JSONGenerativeUI.shared.js";
|
|
6
|
-
import { getPartialJsonObjectMeta } from "assistant-stream/utils";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
//#region src/JSONGenerativeUI.client.tsx
|
|
9
|
-
function uiStatus(status, args) {
|
|
10
|
-
return status.type === "complete" || status.type === "requires-action" && getPartialJsonObjectMeta(args)?.state !== "partial" ? "done" : "streaming";
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Client build of {@link JSONGenerativeUI}, resolved through the package's
|
|
14
|
-
* `default` export condition (browser and SSR).
|
|
15
|
-
*
|
|
16
|
-
* `present` is a frontend tool that renders the model's `{ $type, ...props }`
|
|
17
|
-
* tree against the library and resolves immediately. `prompt_user` is a
|
|
18
|
-
* human-in-the-loop tool: the model pauses and the rendered UI supplies the
|
|
19
|
-
* result. Both draw the tree the same way, so they share one `render`. The
|
|
20
|
-
* `actions` registry (if provided) is threaded into the render context so
|
|
21
|
-
* interactive components can fire `$action` through `$dispatch`.
|
|
22
|
-
*/
|
|
23
|
-
var JSONGenerativeUI = class {
|
|
24
|
-
library;
|
|
25
|
-
parameters;
|
|
26
|
-
actions;
|
|
27
|
-
completedPromptToolCallIds = /* @__PURE__ */ new Set();
|
|
28
|
-
constructor(options) {
|
|
29
|
-
this.library = options.library;
|
|
30
|
-
this.parameters = buildPresentParameters(options.library);
|
|
31
|
-
this.actions = options.actions;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* The surface a `present` call paints into. It owns the vertical rhythm
|
|
35
|
-
* between top-level blocks, which the host's message container does not
|
|
36
|
-
* provide, and stays out of the way while it has nothing to show.
|
|
37
|
-
*/
|
|
38
|
-
render = ({ args, status, addResult, result, toolCallId, artifact, unstable_recordInteraction, unstable_interactions }, completesPrompt = false) => {
|
|
39
|
-
const answered = completesPrompt && result !== void 0;
|
|
40
|
-
const actions = this.actions;
|
|
41
|
-
const dispatch = !answered && actions ? (action) => {
|
|
42
|
-
if (unstable_recordInteraction) try {
|
|
43
|
-
unstable_recordInteraction({
|
|
44
|
-
type: "action",
|
|
45
|
-
payload: action
|
|
46
|
-
}).catch(() => {});
|
|
47
|
-
} catch {}
|
|
48
|
-
const actionResult = actions.dispatch(action);
|
|
49
|
-
if (completesPrompt && actionResult !== void 0 && result === void 0) Promise.resolve(actionResult).then((response) => {
|
|
50
|
-
if (response !== void 0 && !this.completedPromptToolCallIds.has(toolCallId)) {
|
|
51
|
-
this.completedPromptToolCallIds.add(toolCallId);
|
|
52
|
-
addResult(response);
|
|
53
|
-
}
|
|
54
|
-
}).catch(() => {});
|
|
55
|
-
return actionResult;
|
|
56
|
-
} : void 0;
|
|
57
|
-
const artifactValue = artifact !== null && typeof artifact === "object" ? artifact["a2ui"] : void 0;
|
|
58
|
-
const surfaceId = typeof toolCallId === "string" && toolCallId.startsWith("a2ui:") ? toolCallId.slice(5) : void 0;
|
|
59
|
-
const rendered = surfaceId && Array.isArray(artifactValue) ? /* @__PURE__ */ jsx(A2uiPresentRenderer, {
|
|
60
|
-
surfaceId,
|
|
61
|
-
operations: artifactValue,
|
|
62
|
-
fallback: args,
|
|
63
|
-
library: this.library,
|
|
64
|
-
status: uiStatus(status, args),
|
|
65
|
-
...dispatch ? { dispatch } : {}
|
|
66
|
-
}, surfaceId) : renderGenerativeUI(args, this.library, {
|
|
67
|
-
status: uiStatus(status, args),
|
|
68
|
-
...dispatch ? { dispatch } : {}
|
|
69
|
-
});
|
|
70
|
-
return /* @__PURE__ */ jsx("div", {
|
|
71
|
-
"data-aui": "root",
|
|
72
|
-
children: answered ? /* @__PURE__ */ jsx(AnsweredValuesProvider, {
|
|
73
|
-
values: findAnsweredValues(unstable_interactions),
|
|
74
|
-
children: /* @__PURE__ */ jsx("fieldset", {
|
|
75
|
-
disabled: true,
|
|
76
|
-
"data-aui": "answered",
|
|
77
|
-
children: rendered
|
|
78
|
-
})
|
|
79
|
-
}) : rendered
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
present(options) {
|
|
83
|
-
return {
|
|
84
|
-
...presentToolBase(this.parameters, options),
|
|
85
|
-
unstable_backendDefault: { parameters: true },
|
|
86
|
-
execute: async () => ({}),
|
|
87
|
-
render: this.render
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
promptUser() {
|
|
91
|
-
return {
|
|
92
|
-
...promptUserToolBase(this.parameters),
|
|
93
|
-
unstable_backendDefault: { parameters: true },
|
|
94
|
-
render: (props) => this.render(props, true)
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
//#endregion
|
|
99
|
-
export { JSONGenerativeUI };
|
|
100
|
-
|
|
101
|
-
//# sourceMappingURL=JSONGenerativeUI.client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JSONGenerativeUI.client.js","names":[],"sources":["../src/JSONGenerativeUI.client.tsx"],"sourcesContent":["import type { ToolCallMessagePartProps } from \"@assistant-ui/react\";\nimport { getPartialJsonObjectMeta } from \"assistant-stream/utils\";\nimport type { ReactNode } from \"react\";\nimport { A2uiPresentRenderer } from \"./a2ui/PresentRenderer\";\nimport { AnsweredValuesProvider, findAnsweredValues } from \"./answeredValues\";\nimport { buildPresentParameters } from \"./buildPresentParameters\";\nimport {\n presentToolBase,\n promptUserToolBase,\n type JSONGenerativeUIOptions,\n type PresentParameters,\n type PresentTool,\n type PresentToolOptions,\n type PromptUserTool,\n} from \"./JSONGenerativeUI.shared\";\nimport { type ActionRegistry } from \"./actionRegistry\";\nimport { renderGenerativeUI } from \"./renderGenerativeUI\";\nimport type { GenerativeUILibrary, GenerativeUIStatus } from \"./types\";\n\n// A cancelled argument stream can leave a tool waiting with partial arguments.\nfunction uiStatus(\n status: { type: string },\n args: Record<string, unknown>,\n): GenerativeUIStatus {\n return status.type === \"complete\" ||\n (status.type === \"requires-action\" &&\n getPartialJsonObjectMeta(args)?.state !== \"partial\")\n ? \"done\"\n : \"streaming\";\n}\n\n/**\n * Client build of {@link JSONGenerativeUI}, resolved through the package's\n * `default` export condition (browser and SSR).\n *\n * `present` is a frontend tool that renders the model's `{ $type, ...props }`\n * tree against the library and resolves immediately. `prompt_user` is a\n * human-in-the-loop tool: the model pauses and the rendered UI supplies the\n * result. Both draw the tree the same way, so they share one `render`. The\n * `actions` registry (if provided) is threaded into the render context so\n * interactive components can fire `$action` through `$dispatch`.\n */\nexport class JSONGenerativeUI {\n private readonly library: GenerativeUILibrary;\n private readonly parameters: PresentParameters;\n private readonly actions: ActionRegistry | undefined;\n private readonly completedPromptToolCallIds = new Set<string>();\n\n constructor(options: JSONGenerativeUIOptions) {\n this.library = options.library;\n this.parameters = buildPresentParameters(options.library);\n this.actions = options.actions;\n }\n\n /**\n * The surface a `present` call paints into. It owns the vertical rhythm\n * between top-level blocks, which the host's message container does not\n * provide, and stays out of the way while it has nothing to show.\n */\n private readonly render = (\n {\n args,\n status,\n addResult,\n result,\n toolCallId,\n artifact,\n unstable_recordInteraction,\n unstable_interactions,\n }: ToolCallMessagePartProps<Record<string, unknown>, any>,\n completesPrompt = false,\n ): ReactNode => {\n const answered = completesPrompt && result !== undefined;\n const actions = this.actions;\n const dispatch =\n !answered && actions\n ? (action: Parameters<ActionRegistry[\"dispatch\"]>[0]) => {\n if (unstable_recordInteraction) {\n try {\n void unstable_recordInteraction({\n type: \"action\",\n payload: action,\n }).catch(() => {});\n } catch {}\n }\n\n const actionResult = actions.dispatch(action);\n if (\n completesPrompt &&\n actionResult !== undefined &&\n result === undefined\n ) {\n void Promise.resolve(actionResult)\n .then((response) => {\n if (\n response !== undefined &&\n !this.completedPromptToolCallIds.has(toolCallId)\n ) {\n this.completedPromptToolCallIds.add(toolCallId);\n addResult(response);\n }\n })\n .catch(() => {});\n }\n return actionResult;\n }\n : undefined;\n\n const artifactValue =\n artifact !== null && typeof artifact === \"object\"\n ? (artifact as Record<string, unknown>)[\"a2ui\"]\n : undefined;\n const surfaceId =\n typeof toolCallId === \"string\" && toolCallId.startsWith(\"a2ui:\")\n ? toolCallId.slice(\"a2ui:\".length)\n : undefined;\n const rendered =\n surfaceId && Array.isArray(artifactValue) ? (\n <A2uiPresentRenderer\n key={surfaceId}\n surfaceId={surfaceId}\n operations={artifactValue}\n fallback={args}\n library={this.library}\n status={uiStatus(status, args)}\n {...(dispatch ? { dispatch } : {})}\n />\n ) : (\n renderGenerativeUI(args, this.library, {\n status: uiStatus(status, args),\n ...(dispatch ? { dispatch } : {}),\n })\n );\n\n return (\n <div data-aui=\"root\">\n {answered ? (\n <AnsweredValuesProvider\n values={findAnsweredValues(unstable_interactions)}\n >\n <fieldset disabled data-aui=\"answered\">\n {rendered}\n </fieldset>\n </AnsweredValuesProvider>\n ) : (\n rendered\n )}\n </div>\n );\n };\n\n present(options?: PresentToolOptions): PresentTool {\n return {\n ...presentToolBase(this.parameters, options),\n unstable_backendDefault: { parameters: true },\n execute: async () => ({}),\n render: this.render,\n };\n }\n\n promptUser(): PromptUserTool {\n return {\n ...promptUserToolBase(this.parameters),\n unstable_backendDefault: { parameters: true },\n render: (props) => this.render(props, true),\n };\n }\n}\n"],"mappings":";;;;;;;;AAoBA,SAAS,SACP,QACA,MACoB;CACpB,OAAO,OAAO,SAAS,cACpB,OAAO,SAAS,qBACf,yBAAyB,IAAI,CAAC,EAAE,UAAU,YAC1C,SACA;AACN;;;;;;;;;;;;AAaA,IAAa,mBAAb,MAA8B;CAC5B;CACA;CACA;CACA,6CAA8C,IAAI,IAAY;CAE9D,YAAY,SAAkC;EAC5C,KAAK,UAAU,QAAQ;EACvB,KAAK,aAAa,uBAAuB,QAAQ,OAAO;EACxD,KAAK,UAAU,QAAQ;CACzB;;;;;;CAOA,UACE,EACE,MACA,QACA,WACA,QACA,YACA,UACA,4BACA,yBAEF,kBAAkB,UACJ;EACd,MAAM,WAAW,mBAAmB,WAAW,KAAA;EAC/C,MAAM,UAAU,KAAK;EACrB,MAAM,WACJ,CAAC,YAAY,WACR,WAAsD;GACrD,IAAI,4BACF,IAAI;IACF,2BAAgC;KAC9B,MAAM;KACN,SAAS;IACX,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;GACnB,QAAQ,CAAC;GAGX,MAAM,eAAe,QAAQ,SAAS,MAAM;GAC5C,IACE,mBACA,iBAAiB,KAAA,KACjB,WAAW,KAAA,GAEX,QAAa,QAAQ,YAAY,CAAC,CAC/B,MAAM,aAAa;IAClB,IACE,aAAa,KAAA,KACb,CAAC,KAAK,2BAA2B,IAAI,UAAU,GAC/C;KACA,KAAK,2BAA2B,IAAI,UAAU;KAC9C,UAAU,QAAQ;IACpB;GACF,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;GAEnB,OAAO;EACT,IACA,KAAA;EAEN,MAAM,gBACJ,aAAa,QAAQ,OAAO,aAAa,WACpC,SAAqC,UACtC,KAAA;EACN,MAAM,YACJ,OAAO,eAAe,YAAY,WAAW,WAAW,OAAO,IAC3D,WAAW,MAAM,CAAc,IAC/B,KAAA;EACN,MAAM,WACJ,aAAa,MAAM,QAAQ,aAAa,IACtC,oBAAC,qBAAD;GAEa;GACX,YAAY;GACZ,UAAU;GACV,SAAS,KAAK;GACd,QAAQ,SAAS,QAAQ,IAAI;GAC7B,GAAK,WAAW,EAAE,SAAS,IAAI,CAAC;EACjC,GAPM,SAON,IAED,mBAAmB,MAAM,KAAK,SAAS;GACrC,QAAQ,SAAS,QAAQ,IAAI;GAC7B,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;EACjC,CAAC;EAGL,OACE,oBAAC,OAAD;GAAK,YAAS;GACX,UAAA,WACC,oBAAC,wBAAD;IACE,QAAQ,mBAAmB,qBAAqB;IAEhD,UAAA,oBAAC,YAAD;KAAU,UAAA;KAAS,YAAS;KACzB,UAAA;IACO,CAAA;GACY,CAAA,IAExB;EAEC,CAAA;CAET;CAEA,QAAQ,SAA2C;EACjD,OAAO;GACL,GAAG,gBAAgB,KAAK,YAAY,OAAO;GAC3C,yBAAyB,EAAE,YAAY,KAAK;GAC5C,SAAS,aAAa,CAAC;GACvB,QAAQ,KAAK;EACf;CACF;CAEA,aAA6B;EAC3B,OAAO;GACL,GAAG,mBAAmB,KAAK,UAAU;GACrC,yBAAyB,EAAE,YAAY,KAAK;GAC5C,SAAS,UAAU,KAAK,OAAO,OAAO,IAAI;EAC5C;CACF;AACF"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type JSONGenerativeUIOptions, type PresentTool, type PresentToolOptions, type PromptUserTool } from "./JSONGenerativeUI.shared.js";
|
|
2
|
-
/**
|
|
3
|
-
* Server build of {@link JSONGenerativeUI}, resolved through the package's
|
|
4
|
-
* `react-server` export condition.
|
|
5
|
-
*
|
|
6
|
-
* The model only needs each tool's `type`, `description`, and `parameters` on
|
|
7
|
-
* the server, so `present`/`prompt_user` return exactly that — no `execute` and
|
|
8
|
-
* no `render`, keeping the renderer (and React) out of the server graph. The
|
|
9
|
-
* client build adds those back. The two builds share one set of public types, so
|
|
10
|
-
* consumers see a single {@link JSONGenerativeUI} either way.
|
|
11
|
-
*
|
|
12
|
-
* `as` casts here because the tool types require a `render` for frontend/human
|
|
13
|
-
* tools; on the server it is structurally absent and never read.
|
|
14
|
-
*/
|
|
15
|
-
export declare class JSONGenerativeUI {
|
|
16
|
-
private readonly parameters;
|
|
17
|
-
constructor(options: JSONGenerativeUIOptions);
|
|
18
|
-
present(options?: PresentToolOptions): PresentTool;
|
|
19
|
-
promptUser(): PromptUserTool;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=JSONGenerativeUI.server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JSONGenerativeUI.server.d.ts","sourceRoot":"","sources":["../src/JSONGenerativeUI.server.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,uBAAuB,EAE5B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,qCAAkC;AAEnC;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,OAAO,EAAE,uBAAuB;IAI5C,OAAO,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW;IAIlD,UAAU,IAAI,cAAc;CAG7B"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { buildPresentParameters } from "./buildPresentParameters.js";
|
|
2
|
-
import { presentToolBase, promptUserToolBase } from "./JSONGenerativeUI.shared.js";
|
|
3
|
-
//#region src/JSONGenerativeUI.server.tsx
|
|
4
|
-
/**
|
|
5
|
-
* Server build of {@link JSONGenerativeUI}, resolved through the package's
|
|
6
|
-
* `react-server` export condition.
|
|
7
|
-
*
|
|
8
|
-
* The model only needs each tool's `type`, `description`, and `parameters` on
|
|
9
|
-
* the server, so `present`/`prompt_user` return exactly that — no `execute` and
|
|
10
|
-
* no `render`, keeping the renderer (and React) out of the server graph. The
|
|
11
|
-
* client build adds those back. The two builds share one set of public types, so
|
|
12
|
-
* consumers see a single {@link JSONGenerativeUI} either way.
|
|
13
|
-
*
|
|
14
|
-
* `as` casts here because the tool types require a `render` for frontend/human
|
|
15
|
-
* tools; on the server it is structurally absent and never read.
|
|
16
|
-
*/
|
|
17
|
-
var JSONGenerativeUI = class {
|
|
18
|
-
parameters;
|
|
19
|
-
constructor(options) {
|
|
20
|
-
this.parameters = buildPresentParameters(options.library);
|
|
21
|
-
}
|
|
22
|
-
present(options) {
|
|
23
|
-
return presentToolBase(this.parameters, options);
|
|
24
|
-
}
|
|
25
|
-
promptUser() {
|
|
26
|
-
return promptUserToolBase(this.parameters);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
export { JSONGenerativeUI };
|
|
31
|
-
|
|
32
|
-
//# sourceMappingURL=JSONGenerativeUI.server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JSONGenerativeUI.server.js","names":[],"sources":["../src/JSONGenerativeUI.server.tsx"],"sourcesContent":["import { buildPresentParameters } from \"./buildPresentParameters\";\nimport {\n presentToolBase,\n promptUserToolBase,\n type JSONGenerativeUIOptions,\n type PresentParameters,\n type PresentTool,\n type PresentToolOptions,\n type PromptUserTool,\n} from \"./JSONGenerativeUI.shared\";\n\n/**\n * Server build of {@link JSONGenerativeUI}, resolved through the package's\n * `react-server` export condition.\n *\n * The model only needs each tool's `type`, `description`, and `parameters` on\n * the server, so `present`/`prompt_user` return exactly that — no `execute` and\n * no `render`, keeping the renderer (and React) out of the server graph. The\n * client build adds those back. The two builds share one set of public types, so\n * consumers see a single {@link JSONGenerativeUI} either way.\n *\n * `as` casts here because the tool types require a `render` for frontend/human\n * tools; on the server it is structurally absent and never read.\n */\nexport class JSONGenerativeUI {\n private readonly parameters: PresentParameters;\n\n constructor(options: JSONGenerativeUIOptions) {\n this.parameters = buildPresentParameters(options.library);\n }\n\n present(options?: PresentToolOptions): PresentTool {\n return presentToolBase(this.parameters, options) as PresentTool;\n }\n\n promptUser(): PromptUserTool {\n return promptUserToolBase(this.parameters) as PromptUserTool;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,IAAa,mBAAb,MAA8B;CAC5B;CAEA,YAAY,SAAkC;EAC5C,KAAK,aAAa,uBAAuB,QAAQ,OAAO;CAC1D;CAEA,QAAQ,SAA2C;EACjD,OAAO,gBAAgB,KAAK,YAAY,OAAO;CACjD;CAEA,aAA6B;EAC3B,OAAO,mBAAmB,KAAK,UAAU;CAC3C;AACF"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from "@assistant-ui/react";
|
|
2
|
-
import type { JSONSchema7 } from "json-schema";
|
|
3
|
-
import type { ActionRegistry } from "./actionRegistry.js";
|
|
4
|
-
import type { GenerativeUILibrary } from "./types.js";
|
|
5
|
-
/** Options for {@link JSONGenerativeUI}. */
|
|
6
|
-
export type JSONGenerativeUIOptions = {
|
|
7
|
-
/**
|
|
8
|
-
* The components the model is allowed to render, keyed by the `$type` it
|
|
9
|
-
* selects them with. Author it with `defineGenerativeComponents({ ... })` so a
|
|
10
|
-
* `"use generative"` build can split each `render` from its `properties`.
|
|
11
|
-
*/
|
|
12
|
-
library: GenerativeUILibrary;
|
|
13
|
-
/**
|
|
14
|
-
* Host-provided map from `$action.type` to its handler. Interactive
|
|
15
|
-
* components (`Button`/`Select`/`Input`/`DatePicker`) call `$dispatch($action)`
|
|
16
|
-
* on their event, which resolves through this registry. Omit it for a
|
|
17
|
-
* read-only render where model-emitted actions degrade to a no-op.
|
|
18
|
-
*/
|
|
19
|
-
actions?: ActionRegistry;
|
|
20
|
-
};
|
|
21
|
-
/** Options for {@link JSONGenerativeUI.present}. */
|
|
22
|
-
export type PresentToolOptions = {
|
|
23
|
-
/**
|
|
24
|
-
* Set `"standalone"` to render the component on its own surface (outside the
|
|
25
|
-
* chain-of-thought trace), e.g. a full-bleed artifact like a card. Omit it for
|
|
26
|
-
* the default inline rendering — there is no `"inline"` value because that is
|
|
27
|
-
* already the default.
|
|
28
|
-
*/
|
|
29
|
-
display?: "standalone";
|
|
30
|
-
};
|
|
31
|
-
type BackendDefaultMetadata = {
|
|
32
|
-
unstable_backendDefault?: {
|
|
33
|
-
parameters?: boolean;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
/** The `present` tool, as the model sees it (no client `render`/`execute`). */
|
|
37
|
-
export type PresentTool = ToolDefinition<Record<string, unknown>, Record<string, never>> & BackendDefaultMetadata;
|
|
38
|
-
/** The `prompt_user` tool, as the model sees it (no client `render`). */
|
|
39
|
-
export type PromptUserTool = ToolDefinition<Record<string, unknown>, unknown> & BackendDefaultMetadata;
|
|
40
|
-
/** The tool `parameters` schema, built once per instance (see `buildPresentParameters`). */
|
|
41
|
-
export type PresentParameters = JSONSchema7;
|
|
42
|
-
/**
|
|
43
|
-
* The schema-only half of the `present` tool, shared by both builds. The server
|
|
44
|
-
* build returns exactly this; the client build adds `execute` and `render`.
|
|
45
|
-
* Takes the already-built `parameters` so it isn't recomputed per tool.
|
|
46
|
-
*/
|
|
47
|
-
export declare function presentToolBase(parameters: PresentParameters, options?: PresentToolOptions): {
|
|
48
|
-
display?: "standalone";
|
|
49
|
-
type: "frontend";
|
|
50
|
-
description: string;
|
|
51
|
-
parameters: JSONSchema7;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* The schema-only half of the `prompt_user` tool, shared by both builds. The
|
|
55
|
-
* server build returns exactly this; the client build adds `render`.
|
|
56
|
-
*/
|
|
57
|
-
export declare function promptUserToolBase(parameters: PresentParameters): {
|
|
58
|
-
type: "human";
|
|
59
|
-
description: string;
|
|
60
|
-
parameters: JSONSchema7;
|
|
61
|
-
};
|
|
62
|
-
export {};
|
|
63
|
-
//# sourceMappingURL=JSONGenerativeUI.shared.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JSONGenerativeUI.shared.d.ts","sourceRoot":"","sources":["../src/JSONGenerativeUI.shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,4BAAyB;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAgB;AAEnD,4CAA4C;AAC5C,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;OAIG;IACH,OAAO,EAAE,mBAAmB,CAAC;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B,CAAC;AAEF,oDAAoD;AACpD,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,uBAAuB,CAAC,EAAE;QACxB,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB,CAAC;CACH,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,WAAW,GAAG,cAAc,CACtC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CACtB,GACC,sBAAsB,CAAC;AAEzB,yEAAyE;AACzE,MAAM,MAAM,cAAc,GAAG,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,GAC3E,sBAAsB,CAAC;AAWzB,4FAA4F;AAC5F,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,iBAAiB,EAC7B,OAAO,CAAC,EAAE,kBAAkB;;;;;EAQ7B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,iBAAiB;;;;EAM/D"}
|