@elevasis/ui 2.59.0 → 2.60.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.
@@ -82,6 +82,25 @@ type MessageEvent = {
82
82
  error?: string;
83
83
  };
84
84
 
85
+ /**
86
+ * A single intake field definition stored in agent_access_grants.capture_fields.
87
+ *
88
+ * - key: machine identifier (e.g. "name", "company")
89
+ * - label: display label shown to the visitor
90
+ * - type: input type hint; defaults to "text" when absent
91
+ * - required: whether the visitor must fill this field; defaults to false
92
+ */
93
+ declare const CaptureFieldSchema: z.ZodObject<{
94
+ key: z.ZodString;
95
+ label: z.ZodString;
96
+ type: z.ZodOptional<z.ZodEnum<{
97
+ email: "email";
98
+ text: "text";
99
+ tel: "tel";
100
+ }>>;
101
+ required: z.ZodOptional<z.ZodBoolean>;
102
+ }, z.core.$strict>;
103
+ type CaptureField = z.infer<typeof CaptureFieldSchema>;
85
104
  /**
86
105
  * The public-facing grant shape returned by /authorize and /metadata endpoints.
87
106
  *
@@ -162,7 +181,32 @@ interface PublicAgentChatConnectionState {
162
181
 
163
182
  /**
164
183
  * Context passed to the `renderIntro` render-prop. Provides the start action,
165
- * loading state, resolved display strings, raw branding, and the agent slug.
184
+ * loading state, resolved display strings, raw branding, the agent slug, and the
185
+ * grant's intake (`captureFields`) surface so a custom intro can render the same
186
+ * welcome form the default intro draws.
187
+ *
188
+ * A minimal custom intro that renders the intake form looks like:
189
+ *
190
+ * ```tsx
191
+ * renderIntro={({ start, starting, captureFields, intakeValues, setIntakeValue }) => (
192
+ * <Stack>
193
+ * <Title>Welcome!</Title>
194
+ * {captureFields.map((field) => (
195
+ * <TextInput
196
+ * key={field.key}
197
+ * label={field.label}
198
+ * required={field.required ?? false}
199
+ * value={intakeValues[field.key] ?? ''}
200
+ * onChange={(e) => setIntakeValue(field.key, e.currentTarget.value)}
201
+ * />
202
+ * ))}
203
+ * <Button onClick={start} loading={starting}>Start</Button>
204
+ * </Stack>
205
+ * )}
206
+ * ```
207
+ *
208
+ * Values written via `setIntakeValue` flow into the session `metadata` on `start()`
209
+ * exactly as the default intro's form does (so `name` titles the session).
166
210
  */
167
211
  interface PublicAgentIntroRenderContext {
168
212
  /** Begins the authorize → session flow (the same action the default CTA runs). */
@@ -175,6 +219,12 @@ interface PublicAgentIntroRenderContext {
175
219
  /** Raw grant branding record, so a custom intro can still read intro/instructions/etc. if it wants. */
176
220
  branding: Record<string, unknown>;
177
221
  slug: string;
222
+ /** The grant's resolved, validated intake fields (`[]` when none). Map these to inputs. */
223
+ captureFields: CaptureField[];
224
+ /** Current collected intake values, keyed by `CaptureField.key`. */
225
+ intakeValues: Record<string, string>;
226
+ /** Writes a single intake value; flows into session metadata on `start()`. */
227
+ setIntakeValue: (key: string, value: string) => void;
178
228
  }
179
229
  interface PublicAgentChatProps {
180
230
  apiUrl: string;
@@ -232,4 +282,4 @@ declare const publicAgentChatKeys: {
232
282
  };
233
283
 
234
284
  export { PublicAgentChat, PublicAgentChatRoutePage, publicAgentChatKeys, usePublicAgentChatMessages, usePublicAgentChatWebSocket };
235
- export type { PublicAgentChatAuthorizeResponse, PublicAgentChatConnectionState, PublicAgentChatGrant, PublicAgentChatMessagesResponse, PublicAgentChatMetadataResponse, PublicAgentChatProps, PublicAgentChatRoutePageProps, PublicAgentChatSessionResponse, PublicAgentIntroRenderContext };
285
+ export type { CaptureField, PublicAgentChatAuthorizeResponse, PublicAgentChatConnectionState, PublicAgentChatGrant, PublicAgentChatMessagesResponse, PublicAgentChatMetadataResponse, PublicAgentChatProps, PublicAgentChatRoutePageProps, PublicAgentChatSessionResponse, PublicAgentIntroRenderContext };
@@ -483,6 +483,9 @@ function PublicAgentChat({
483
483
  const [input, setInput] = useState("");
484
484
  const [isCreatingSession, setIsCreatingSession] = useState(false);
485
485
  const [intakeValues, setIntakeValues] = useState({});
486
+ const setIntakeValue = useCallback((key, value) => {
487
+ setIntakeValues((prev) => ({ ...prev, [key]: value }));
488
+ }, []);
486
489
  const autoStartedRef = useRef(false);
487
490
  const greetingTimeRef = useRef(/* @__PURE__ */ new Date());
488
491
  const displayTitle = resolveAgentTitle(title, slug, grant);
@@ -734,7 +737,10 @@ function PublicAgentChat({
734
737
  title: displayTitle,
735
738
  subtitle: displaySubtitle,
736
739
  branding,
737
- slug
740
+ slug,
741
+ captureFields: resolveCaptureFields(grant),
742
+ intakeValues,
743
+ setIntakeValue
738
744
  };
739
745
  return /* @__PURE__ */ jsx(
740
746
  PublicAgentChatFrame,
@@ -784,10 +790,7 @@ function PublicAgentChat({
784
790
  type: field.type ?? "text",
785
791
  required: field.required ?? false,
786
792
  value: intakeValues[field.key] ?? "",
787
- onChange: (event) => {
788
- const value = event.currentTarget.value;
789
- setIntakeValues((prev) => ({ ...prev, [field.key]: value }));
790
- },
793
+ onChange: (event) => setIntakeValue(field.key, event.currentTarget.value),
791
794
  autoComplete: field.type === "email" ? "email" : field.type === "tel" ? "tel" : "off"
792
795
  },
793
796
  field.key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elevasis/ui",
3
- "version": "2.59.0",
3
+ "version": "2.60.0",
4
4
  "description": "UI components and platform-aware hooks for building custom frontends on the Elevasis platform",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -274,11 +274,11 @@
274
274
  "typescript": "5.9.2",
275
275
  "vite": "^7.0.0",
276
276
  "vitest": "^3.2.4",
277
- "@elevasis/sdk": "1.36.5",
278
277
  "@repo/core": "0.52.0",
279
278
  "@repo/elevasis-core": "1.0.0",
280
279
  "@repo/typescript-config": "0.0.0",
281
- "@repo/eslint-config": "0.0.0"
280
+ "@repo/eslint-config": "0.0.0",
281
+ "@elevasis/sdk": "1.36.5"
282
282
  },
283
283
  "dependencies": {
284
284
  "@dagrejs/dagre": "^1.1.4",