chat 4.6.0 → 4.7.1

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.
@@ -236,9 +236,28 @@ function childToFallbackText(child) {
236
236
  }
237
237
 
238
238
  // src/modals.ts
239
+ var VALID_MODAL_CHILD_TYPES = [
240
+ "text_input",
241
+ "select",
242
+ "text",
243
+ "fields"
244
+ ];
239
245
  function isModalElement(value) {
240
246
  return typeof value === "object" && value !== null && "type" in value && value.type === "modal";
241
247
  }
248
+ function filterModalChildren(children) {
249
+ const validChildren = children.filter(
250
+ (c) => typeof c === "object" && c !== null && "type" in c && VALID_MODAL_CHILD_TYPES.includes(
251
+ c.type
252
+ )
253
+ );
254
+ if (validChildren.length < children.length) {
255
+ console.warn(
256
+ "[chat] Modal contains unsupported child elements that were ignored"
257
+ );
258
+ }
259
+ return validChildren;
260
+ }
242
261
  function Modal(options) {
243
262
  return {
244
263
  type: "modal",
@@ -247,7 +266,6 @@ function Modal(options) {
247
266
  submitLabel: options.submitLabel,
248
267
  closeLabel: options.closeLabel,
249
268
  notifyOnClose: options.notifyOnClose,
250
- privateMetadata: options.privateMetadata,
251
269
  children: options.children ?? []
252
270
  };
253
271
  }
@@ -324,10 +342,7 @@ function fromReactModalElement(element) {
324
342
  submitLabel: props.submitLabel,
325
343
  closeLabel: props.closeLabel,
326
344
  notifyOnClose: props.notifyOnClose,
327
- privateMetadata: props.privateMetadata,
328
- children: convertedChildren.filter(
329
- (c) => c !== null && "type" in c && (c.type === "text_input" || c.type === "select")
330
- )
345
+ children: filterModalChildren(convertedChildren)
331
346
  });
332
347
  case "TextInput":
333
348
  return TextInput({
@@ -501,8 +516,7 @@ function resolveJSXElement(element) {
501
516
  submitLabel: props.submitLabel,
502
517
  closeLabel: props.closeLabel,
503
518
  notifyOnClose: props.notifyOnClose,
504
- privateMetadata: props.privateMetadata,
505
- children: processedChildren
519
+ children: filterModalChildren(processedChildren)
506
520
  });
507
521
  }
508
522
  if (type === TextInput) {
@@ -634,4 +648,4 @@ export {
634
648
  toModalElement,
635
649
  isJSX
636
650
  };
637
- //# sourceMappingURL=chunk-5AEQCOSP.js.map
651
+ //# sourceMappingURL=chunk-RRTA7C5H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cards.ts","../src/modals.ts","../src/jsx-runtime.ts"],"sourcesContent":["/**\n * Card elements for cross-platform rich messaging.\n *\n * Provides a builder API for creating rich cards that automatically\n * convert to platform-specific formats:\n * - Slack: Block Kit\n * - Teams: Adaptive Cards\n * - Google Chat: Card v2\n *\n * Supports both function-call and JSX syntax:\n *\n * @example Function API\n * ```ts\n * import { Card, Text, Actions, Button } from \"chat\";\n *\n * await thread.post(\n * Card({\n * title: \"Order #1234\",\n * children: [\n * Text(\"Total: $50.00\"),\n * Actions([\n * Button({ id: \"approve\", label: \"Approve\", style: \"primary\" }),\n * Button({ id: \"reject\", label: \"Reject\", style: \"danger\" }),\n * ]),\n * ],\n * })\n * );\n * ```\n *\n * @example JSX API (requires jsxImportSource: \"chat\" in tsconfig)\n * ```tsx\n * /** @jsxImportSource chat *\\/\n * import { Card, Text, Actions, Button } from \"chat\";\n *\n * await thread.post(\n * <Card title=\"Order #1234\">\n * <Text>Total: $50.00</Text>\n * <Actions>\n * <Button id=\"approve\" style=\"primary\">Approve</Button>\n * <Button id=\"reject\" style=\"danger\">Reject</Button>\n * </Actions>\n * </Card>\n * );\n * ```\n */\n\n// ============================================================================\n// Card Element Types\n// ============================================================================\n\n/** Button style options */\nexport type ButtonStyle = \"primary\" | \"danger\" | \"default\";\n\n/** Text style options */\nexport type TextStyle = \"plain\" | \"bold\" | \"muted\";\n\n/** Button element for interactive actions */\nexport interface ButtonElement {\n type: \"button\";\n /** Unique action ID for callback routing */\n id: string;\n /** Button label text */\n label: string;\n /** Visual style */\n style?: ButtonStyle;\n /** Optional payload value sent with action callback */\n value?: string;\n}\n\n/** Link button element that opens a URL */\nexport interface LinkButtonElement {\n type: \"link-button\";\n /** URL to open when clicked */\n url: string;\n /** Button label text */\n label: string;\n /** Visual style */\n style?: ButtonStyle;\n}\n\n/** Text content element */\nexport interface TextElement {\n type: \"text\";\n /** Text content (supports markdown in some platforms) */\n content: string;\n /** Text style */\n style?: TextStyle;\n}\n\n/** Image element */\nexport interface ImageElement {\n type: \"image\";\n /** Image URL */\n url: string;\n /** Alt text for accessibility */\n alt?: string;\n}\n\n/** Visual divider/separator */\nexport interface DividerElement {\n type: \"divider\";\n}\n\n/** Container for action buttons */\nexport interface ActionsElement {\n type: \"actions\";\n /** Button and link button elements */\n children: (ButtonElement | LinkButtonElement)[];\n}\n\n/** Section container for grouping elements */\nexport interface SectionElement {\n type: \"section\";\n /** Section children */\n children: CardChild[];\n}\n\n/** Field for key-value display */\nexport interface FieldElement {\n type: \"field\";\n /** Field label */\n label: string;\n /** Field value */\n value: string;\n}\n\n/** Fields container for multi-column layout */\nexport interface FieldsElement {\n type: \"fields\";\n /** Field elements */\n children: FieldElement[];\n}\n\n/** Union of all card child element types */\nexport type CardChild =\n | TextElement\n | ImageElement\n | DividerElement\n | ActionsElement\n | SectionElement\n | FieldsElement;\n\n/** Union of all element types (including nested children) */\ntype AnyCardElement =\n | CardChild\n | CardElement\n | ButtonElement\n | LinkButtonElement\n | FieldElement;\n\n/** Root card element */\nexport interface CardElement {\n type: \"card\";\n /** Card title */\n title?: string;\n /** Card subtitle */\n subtitle?: string;\n /** Header image URL */\n imageUrl?: string;\n /** Card content */\n children: CardChild[];\n}\n\n/** Type guard for CardElement */\nexport function isCardElement(value: unknown): value is CardElement {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"type\" in value &&\n (value as CardElement).type === \"card\"\n );\n}\n\n// ============================================================================\n// Builder Functions\n// ============================================================================\n\n/** Options for Card */\nexport interface CardOptions {\n title?: string;\n subtitle?: string;\n imageUrl?: string;\n children?: CardChild[];\n}\n\n/**\n * Create a Card element.\n *\n * @example\n * ```ts\n * Card({\n * title: \"Welcome\",\n * children: [Text(\"Hello!\")],\n * })\n * ```\n */\nexport function Card(options: CardOptions = {}): CardElement {\n return {\n type: \"card\",\n title: options.title,\n subtitle: options.subtitle,\n imageUrl: options.imageUrl,\n children: options.children ?? [],\n };\n}\n\n/**\n * Create a Text element.\n *\n * @example\n * ```ts\n * Text(\"Hello, world!\")\n * Text(\"Important\", { style: \"bold\" })\n * ```\n */\nexport function Text(\n content: string,\n options: { style?: TextStyle } = {},\n): TextElement {\n return {\n type: \"text\",\n content,\n style: options.style,\n };\n}\n\n/**\n * Alias for Text that avoids conflicts with DOM's global Text constructor.\n * Use this when importing in environments where `Text` would conflict.\n *\n * @example\n * ```ts\n * import { CardText } from \"chat\";\n * CardText(\"Hello, world!\")\n * ```\n */\nexport const CardText = Text;\n\n/**\n * Create an Image element.\n *\n * @example\n * ```ts\n * Image({ url: \"https://example.com/image.png\", alt: \"Description\" })\n * ```\n */\nexport function Image(options: { url: string; alt?: string }): ImageElement {\n return {\n type: \"image\",\n url: options.url,\n alt: options.alt,\n };\n}\n\n/**\n * Create a Divider element.\n *\n * @example\n * ```ts\n * Divider()\n * ```\n */\nexport function Divider(): DividerElement {\n return { type: \"divider\" };\n}\n\n/**\n * Create a Section container.\n *\n * @example\n * ```ts\n * Section([\n * Text(\"Grouped content\"),\n * Image({ url: \"...\" }),\n * ])\n * ```\n */\nexport function Section(children: CardChild[]): SectionElement {\n return {\n type: \"section\",\n children,\n };\n}\n\n/**\n * Create an Actions container for buttons.\n *\n * @example\n * ```ts\n * Actions([\n * Button({ id: \"ok\", label: \"OK\" }),\n * Button({ id: \"cancel\", label: \"Cancel\" }),\n * LinkButton({ url: \"https://example.com\", label: \"Learn More\" }),\n * ])\n * ```\n */\nexport function Actions(\n children: (ButtonElement | LinkButtonElement)[],\n): ActionsElement {\n return {\n type: \"actions\",\n children,\n };\n}\n\n/** Options for Button */\nexport interface ButtonOptions {\n /** Unique action ID for callback routing */\n id: string;\n /** Button label text */\n label: string;\n /** Visual style */\n style?: ButtonStyle;\n /** Optional payload value sent with action callback */\n value?: string;\n}\n\n/**\n * Create a Button element.\n *\n * @example\n * ```ts\n * Button({ id: \"submit\", label: \"Submit\", style: \"primary\" })\n * Button({ id: \"delete\", label: \"Delete\", style: \"danger\", value: \"item-123\" })\n * ```\n */\nexport function Button(options: ButtonOptions): ButtonElement {\n return {\n type: \"button\",\n id: options.id,\n label: options.label,\n style: options.style,\n value: options.value,\n };\n}\n\n/** Options for LinkButton */\nexport interface LinkButtonOptions {\n /** URL to open when clicked */\n url: string;\n /** Button label text */\n label: string;\n /** Visual style */\n style?: ButtonStyle;\n}\n\n/**\n * Create a LinkButton element that opens a URL when clicked.\n *\n * @example\n * ```ts\n * LinkButton({ url: \"https://example.com\", label: \"View Docs\" })\n * LinkButton({ url: \"https://example.com\", label: \"Learn More\", style: \"primary\" })\n * ```\n */\nexport function LinkButton(options: LinkButtonOptions): LinkButtonElement {\n return {\n type: \"link-button\",\n url: options.url,\n label: options.label,\n style: options.style,\n };\n}\n\n/**\n * Create a Field element for key-value display.\n *\n * @example\n * ```ts\n * Field({ label: \"Status\", value: \"Active\" })\n * ```\n */\nexport function Field(options: { label: string; value: string }): FieldElement {\n return {\n type: \"field\",\n label: options.label,\n value: options.value,\n };\n}\n\n/**\n * Create a Fields container for multi-column layout.\n *\n * @example\n * ```ts\n * Fields([\n * Field({ label: \"Name\", value: \"John\" }),\n * Field({ label: \"Email\", value: \"john@example.com\" }),\n * ])\n * ```\n */\nexport function Fields(children: FieldElement[]): FieldsElement {\n return {\n type: \"fields\",\n children,\n };\n}\n\n// ============================================================================\n// React Element Support\n// ============================================================================\n\n/** React element shape (minimal typing to avoid React dependency) */\ninterface ReactElement {\n $$typeof: symbol;\n type: unknown;\n props: Record<string, unknown>;\n}\n\n/**\n * Check if a value is a React element.\n */\nfunction isReactElement(value: unknown): value is ReactElement {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const maybeElement = value as { $$typeof?: unknown };\n if (typeof maybeElement.$$typeof !== \"symbol\") {\n return false;\n }\n const symbolStr = maybeElement.$$typeof.toString();\n return (\n symbolStr.includes(\"react.element\") ||\n symbolStr.includes(\"react.transitional.element\")\n );\n}\n\n/**\n * Map of component functions to their names for React element conversion.\n */\nconst componentMap = new Map<unknown, string>([\n [Card, \"Card\"],\n [Text, \"Text\"],\n [Image, \"Image\"],\n [Divider, \"Divider\"],\n [Section, \"Section\"],\n [Actions, \"Actions\"],\n [Button, \"Button\"],\n [LinkButton, \"LinkButton\"],\n [Field, \"Field\"],\n [Fields, \"Fields\"],\n]);\n\n/**\n * Convert a React element tree to a CardElement tree.\n * This allows using React's JSX with our card components.\n *\n * @example\n * ```tsx\n * import React from \"react\";\n * import { Card, Text, fromReactElement } from \"chat\";\n *\n * const element = (\n * <Card title=\"Hello\">\n * <Text>World</Text>\n * </Card>\n * );\n *\n * const card = fromReactElement(element);\n * await thread.post(card);\n * ```\n */\nexport function fromReactElement(element: unknown): AnyCardElement | null {\n if (!isReactElement(element)) {\n // Already a card element or primitive\n if (isCardElement(element)) {\n return element;\n }\n if (typeof element === \"object\" && element !== null && \"type\" in element) {\n return element as CardChild;\n }\n return null;\n }\n\n const { type, props } = element;\n const componentName = componentMap.get(type);\n\n if (!componentName) {\n // Check if it's an HTML element (string type like \"div\", \"a\", \"span\")\n if (typeof type === \"string\") {\n throw new Error(\n `HTML element <${type}> is not supported in card elements. ` +\n `Use Card, Text, Section, Actions, Button, Fields, Field, Image, or Divider components instead.`,\n );\n }\n\n // Unknown custom component - try to extract children\n if (props.children) {\n return convertChildren(props.children)[0] ?? null;\n }\n return null;\n }\n\n // Convert children recursively\n const convertedChildren = props.children\n ? convertChildren(props.children)\n : [];\n\n // Helper to filter for CardChild elements\n const isCardChild = (el: AnyCardElement): el is CardChild =>\n el.type !== \"card\" &&\n el.type !== \"button\" &&\n el.type !== \"link-button\" &&\n el.type !== \"field\";\n\n // Call the appropriate builder function based on component type\n switch (componentName) {\n case \"Card\":\n return Card({\n title: props.title as string | undefined,\n subtitle: props.subtitle as string | undefined,\n imageUrl: props.imageUrl as string | undefined,\n children: convertedChildren.filter(isCardChild),\n });\n\n case \"Text\": {\n // JSX: <Text style=\"bold\">content</Text>\n const content = extractTextContent(props.children);\n return Text(content, { style: props.style as TextStyle | undefined });\n }\n\n case \"Image\":\n return Image({\n url: props.url as string,\n alt: props.alt as string | undefined,\n });\n\n case \"Divider\":\n return Divider();\n\n case \"Section\":\n return Section(convertedChildren.filter(isCardChild));\n\n case \"Actions\":\n return Actions(\n convertedChildren.filter(\n (c): c is ButtonElement | LinkButtonElement =>\n c.type === \"button\" || c.type === \"link-button\",\n ),\n );\n\n case \"Button\": {\n // JSX: <Button id=\"x\" style=\"primary\">Label</Button>\n const label = extractTextContent(props.children);\n return Button({\n id: props.id as string,\n label: (props.label as string | undefined) ?? label,\n style: props.style as ButtonStyle | undefined,\n value: props.value as string | undefined,\n });\n }\n\n case \"LinkButton\": {\n // JSX: <LinkButton url=\"https://...\" style=\"primary\">Label</LinkButton>\n const label = extractTextContent(props.children);\n return LinkButton({\n url: props.url as string,\n label: (props.label as string | undefined) ?? label,\n style: props.style as ButtonStyle | undefined,\n });\n }\n\n case \"Field\":\n return Field({\n label: props.label as string,\n value: props.value as string,\n });\n\n case \"Fields\":\n return Fields(\n convertedChildren.filter((c): c is FieldElement => c.type === \"field\"),\n );\n\n default:\n return null;\n }\n}\n\n/**\n * Convert React children to card elements.\n */\nfunction convertChildren(children: unknown): AnyCardElement[] {\n if (children == null) {\n return [];\n }\n\n if (Array.isArray(children)) {\n return children.flatMap(convertChildren);\n }\n\n const converted = fromReactElement(children);\n if (converted && typeof converted === \"object\" && \"type\" in converted) {\n // If it's a card, extract its children\n if (converted.type === \"card\") {\n return (converted as CardElement).children;\n }\n return [converted];\n }\n\n return [];\n}\n\n/**\n * Extract text content from React children.\n */\nfunction extractTextContent(children: unknown): string {\n if (typeof children === \"string\") {\n return children;\n }\n if (typeof children === \"number\") {\n return String(children);\n }\n if (Array.isArray(children)) {\n return children.map(extractTextContent).join(\"\");\n }\n return \"\";\n}\n\n// ============================================================================\n// Fallback Text Generation\n// ============================================================================\n\n/**\n * Generate plain text fallback from a CardElement.\n * Used for platforms/clients that can't render rich cards,\n * and for the SentMessage.text property.\n */\nexport function cardToFallbackText(card: CardElement): string {\n const parts: string[] = [];\n\n if (card.title) {\n parts.push(card.title);\n }\n\n if (card.subtitle) {\n parts.push(card.subtitle);\n }\n\n for (const child of card.children) {\n const text = childToFallbackText(child);\n if (text) {\n parts.push(text);\n }\n }\n\n return parts.join(\"\\n\");\n}\n\n/**\n * Generate fallback text from a card child element.\n */\nfunction childToFallbackText(child: CardChild): string | null {\n switch (child.type) {\n case \"text\":\n return child.content;\n case \"fields\":\n return child.children.map((f) => `${f.label}: ${f.value}`).join(\"\\n\");\n case \"actions\":\n return `[${child.children.map((b) => b.label).join(\"] [\")}]`;\n case \"section\":\n return child.children\n .map((c) => childToFallbackText(c))\n .filter(Boolean)\n .join(\"\\n\");\n default:\n return null;\n }\n}\n","/**\n * Modal elements for form dialogs.\n */\n\nimport type { FieldsElement, TextElement } from \"./cards\";\n\n// ============================================================================\n// Modal Element Types\n// ============================================================================\n\nexport const VALID_MODAL_CHILD_TYPES = [\n \"text_input\",\n \"select\",\n \"text\",\n \"fields\",\n] as const;\n\nexport type ModalChild =\n | TextInputElement\n | SelectElement\n | TextElement\n | FieldsElement;\n\nexport interface ModalElement {\n type: \"modal\";\n callbackId: string;\n title: string;\n submitLabel?: string;\n closeLabel?: string;\n notifyOnClose?: boolean;\n children: ModalChild[];\n}\n\nexport interface TextInputElement {\n type: \"text_input\";\n id: string;\n label: string;\n placeholder?: string;\n initialValue?: string;\n multiline?: boolean;\n optional?: boolean;\n maxLength?: number;\n}\n\nexport interface SelectElement {\n type: \"select\";\n id: string;\n label: string;\n placeholder?: string;\n options: SelectOptionElement[];\n initialOption?: string;\n optional?: boolean;\n}\n\nexport interface SelectOptionElement {\n label: string;\n value: string;\n}\n\nexport function isModalElement(value: unknown): value is ModalElement {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"type\" in value &&\n (value as ModalElement).type === \"modal\"\n );\n}\n\nexport function filterModalChildren(children: unknown[]): ModalChild[] {\n const validChildren = children.filter(\n (c): c is ModalChild =>\n typeof c === \"object\" &&\n c !== null &&\n \"type\" in c &&\n VALID_MODAL_CHILD_TYPES.includes(\n (c as { type: string })\n .type as (typeof VALID_MODAL_CHILD_TYPES)[number],\n ),\n );\n if (validChildren.length < children.length) {\n console.warn(\n \"[chat] Modal contains unsupported child elements that were ignored\",\n );\n }\n return validChildren;\n}\n\n// ============================================================================\n// Builder Functions\n// ============================================================================\n\nexport interface ModalOptions {\n callbackId: string;\n title: string;\n submitLabel?: string;\n closeLabel?: string;\n notifyOnClose?: boolean;\n children?: ModalChild[];\n}\n\nexport function Modal(options: ModalOptions): ModalElement {\n return {\n type: \"modal\",\n callbackId: options.callbackId,\n title: options.title,\n submitLabel: options.submitLabel,\n closeLabel: options.closeLabel,\n notifyOnClose: options.notifyOnClose,\n children: options.children ?? [],\n };\n}\n\nexport interface TextInputOptions {\n id: string;\n label: string;\n placeholder?: string;\n initialValue?: string;\n multiline?: boolean;\n optional?: boolean;\n maxLength?: number;\n}\n\nexport function TextInput(options: TextInputOptions): TextInputElement {\n return {\n type: \"text_input\",\n id: options.id,\n label: options.label,\n placeholder: options.placeholder,\n initialValue: options.initialValue,\n multiline: options.multiline,\n optional: options.optional,\n maxLength: options.maxLength,\n };\n}\n\nexport interface SelectOptions {\n id: string;\n label: string;\n placeholder?: string;\n options: SelectOptionElement[];\n initialOption?: string;\n optional?: boolean;\n}\n\nexport function Select(options: SelectOptions): SelectElement {\n return {\n type: \"select\",\n id: options.id,\n label: options.label,\n placeholder: options.placeholder,\n options: options.options,\n initialOption: options.initialOption,\n optional: options.optional,\n };\n}\n\nexport function SelectOption(options: {\n label: string;\n value: string;\n}): SelectOptionElement {\n return {\n label: options.label,\n value: options.value,\n };\n}\n\n// ============================================================================\n// JSX Support\n// ============================================================================\n\ninterface ReactElement {\n $$typeof: symbol;\n type: unknown;\n props: Record<string, unknown>;\n}\n\nfunction isReactElement(value: unknown): value is ReactElement {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const maybeElement = value as { $$typeof?: unknown };\n if (typeof maybeElement.$$typeof !== \"symbol\") {\n return false;\n }\n const symbolStr = maybeElement.$$typeof.toString();\n return (\n symbolStr.includes(\"react.element\") ||\n symbolStr.includes(\"react.transitional.element\")\n );\n}\n\ntype AnyModalElement = ModalElement | ModalChild | SelectOptionElement;\n\nconst modalComponentMap = new Map<unknown, string>([\n [Modal, \"Modal\"],\n [TextInput, \"TextInput\"],\n [Select, \"Select\"],\n [SelectOption, \"SelectOption\"],\n]);\n\nexport function fromReactModalElement(\n element: unknown,\n): AnyModalElement | null {\n if (!isReactElement(element)) {\n if (isModalElement(element)) {\n return element;\n }\n if (typeof element === \"object\" && element !== null && \"type\" in element) {\n return element as ModalChild;\n }\n return null;\n }\n\n const { type, props } = element;\n const componentName = modalComponentMap.get(type);\n\n if (!componentName) {\n if (props.children) {\n return convertModalChildren(props.children)[0] ?? null;\n }\n return null;\n }\n\n const convertedChildren = props.children\n ? convertModalChildren(props.children)\n : [];\n\n switch (componentName) {\n case \"Modal\":\n return Modal({\n callbackId: props.callbackId as string,\n title: props.title as string,\n submitLabel: props.submitLabel as string | undefined,\n closeLabel: props.closeLabel as string | undefined,\n notifyOnClose: props.notifyOnClose as boolean | undefined,\n children: filterModalChildren(convertedChildren),\n });\n\n case \"TextInput\":\n return TextInput({\n id: props.id as string,\n label: props.label as string,\n placeholder: props.placeholder as string | undefined,\n initialValue: props.initialValue as string | undefined,\n multiline: props.multiline as boolean | undefined,\n optional: props.optional as boolean | undefined,\n maxLength: props.maxLength as number | undefined,\n });\n\n case \"Select\":\n return Select({\n id: props.id as string,\n label: props.label as string,\n placeholder: props.placeholder as string | undefined,\n options: convertedChildren.filter(\n (c): c is SelectOptionElement =>\n c !== null && \"label\" in c && \"value\" in c && !(\"type\" in c),\n ),\n initialOption: props.initialOption as string | undefined,\n optional: props.optional as boolean | undefined,\n });\n\n case \"SelectOption\":\n return SelectOption({\n label: props.label as string,\n value: props.value as string,\n });\n\n default:\n return null;\n }\n}\n\nfunction convertModalChildren(children: unknown): AnyModalElement[] {\n if (children == null) {\n return [];\n }\n\n if (Array.isArray(children)) {\n return children.flatMap(convertModalChildren);\n }\n\n const converted = fromReactModalElement(children);\n if (converted) {\n if (isModalElement(converted)) {\n return converted.children;\n }\n return [converted];\n }\n\n return [];\n}\n","/**\n * Custom JSX runtime for chat cards.\n *\n * This allows using JSX syntax without React. Configure your bundler:\n *\n * tsconfig.json:\n * {\n * \"compilerOptions\": {\n * \"jsx\": \"react-jsx\",\n * \"jsxImportSource\": \"chat\"\n * }\n * }\n *\n * Or per-file:\n * /** @jsxImportSource chat *\\/\n *\n * Usage:\n * ```tsx\n * import { Card, Text, Button, Actions } from \"chat\";\n *\n * const card = (\n * <Card title=\"Order #1234\">\n * <Text>Your order is ready!</Text>\n * <Actions>\n * <Button id=\"pickup\" style=\"primary\">Schedule Pickup</Button>\n * </Actions>\n * </Card>\n * );\n * ```\n */\n\nimport {\n Actions,\n Button,\n type ButtonElement,\n type ButtonStyle,\n Card,\n type CardChild,\n type CardElement,\n Divider,\n Field,\n type FieldElement,\n Fields,\n Image,\n LinkButton,\n type LinkButtonElement,\n Section,\n Text,\n type TextStyle,\n} from \"./cards\";\n\nimport {\n filterModalChildren,\n isModalElement,\n Modal,\n type ModalChild,\n type ModalElement,\n Select,\n SelectOption,\n type SelectOptionElement,\n TextInput,\n} from \"./modals\";\n\n// Symbol to identify our JSX elements before they're processed\nconst JSX_ELEMENT = Symbol.for(\"chat.jsx.element\");\n\n// ============================================================================\n// JSX Props Types - Strongly typed props for each component\n// ============================================================================\n\n/** Props for Card component in JSX */\nexport interface CardProps {\n title?: string;\n subtitle?: string;\n imageUrl?: string;\n children?: unknown;\n}\n\n/** Props for Text component in JSX */\nexport interface TextProps {\n style?: TextStyle;\n children?: string | number;\n}\n\n/** Props for Button component in JSX */\nexport interface ButtonProps {\n id: string;\n label?: string;\n style?: ButtonStyle;\n value?: string;\n children?: string | number;\n}\n\n/** Props for LinkButton component in JSX */\nexport interface LinkButtonProps {\n url: string;\n label?: string;\n style?: ButtonStyle;\n children?: string | number;\n}\n\n/** Props for Image component in JSX */\nexport interface ImageProps {\n url: string;\n alt?: string;\n}\n\n/** Props for Field component in JSX */\nexport interface FieldProps {\n label: string;\n value: string;\n}\n\n/** Props for container components (Section, Actions, Fields) */\nexport interface ContainerProps {\n children?: unknown;\n}\n\n/** Props for Divider component (no props) */\nexport type DividerProps = Record<string, never>;\n\n/** Props for Modal component in JSX */\nexport interface ModalProps {\n callbackId: string;\n title: string;\n submitLabel?: string;\n closeLabel?: string;\n notifyOnClose?: boolean;\n children?: unknown;\n}\n\n/** Props for TextInput component in JSX */\nexport interface TextInputProps {\n id: string;\n label: string;\n placeholder?: string;\n initialValue?: string;\n multiline?: boolean;\n optional?: boolean;\n maxLength?: number;\n}\n\n/** Props for Select component in JSX */\nexport interface SelectProps {\n id: string;\n label: string;\n placeholder?: string;\n initialOption?: string;\n optional?: boolean;\n children?: unknown;\n}\n\n/** Props for SelectOption component in JSX */\nexport interface SelectOptionProps {\n label: string;\n value: string;\n}\n\n/** Union of all valid JSX props */\nexport type CardJSXProps =\n | CardProps\n | TextProps\n | ButtonProps\n | LinkButtonProps\n | ImageProps\n | FieldProps\n | ContainerProps\n | DividerProps\n | ModalProps\n | TextInputProps\n | SelectProps\n | SelectOptionProps;\n\n/** Component function type with proper overloads */\ntype CardComponentFunction =\n | typeof Card\n | typeof Text\n | typeof Button\n | typeof LinkButton\n | typeof Image\n | typeof Field\n | typeof Divider\n | typeof Section\n | typeof Actions\n | typeof Fields\n | typeof Modal\n | typeof TextInput\n | typeof Select\n | typeof SelectOption;\n\n/**\n * Represents a JSX element from the chat JSX runtime.\n * This is the type returned when using JSX syntax with chat components.\n */\nexport interface CardJSXElement<P extends CardJSXProps = CardJSXProps> {\n $$typeof: typeof JSX_ELEMENT;\n type: CardComponentFunction;\n props: P;\n children: unknown[];\n}\n\n// Internal alias for backwards compatibility\ntype JSXElement = CardJSXElement;\n\n/**\n * Check if a value is a JSX element from our runtime.\n */\nfunction isJSXElement(value: unknown): value is JSXElement {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as JSXElement).$$typeof === JSX_ELEMENT\n );\n}\n\n/** Non-null card element for children arrays */\ntype CardChildOrNested =\n | CardChild\n | ButtonElement\n | LinkButtonElement\n | FieldElement;\n\n/**\n * Process children, converting JSX elements to card elements.\n */\nfunction processChildren(children: unknown): CardChildOrNested[] {\n if (children == null) {\n return [];\n }\n\n if (Array.isArray(children)) {\n return children.flatMap(processChildren);\n }\n\n // If it's a JSX element, resolve it\n if (isJSXElement(children)) {\n const resolved = resolveJSXElement(children);\n if (resolved) {\n return [resolved as CardChildOrNested];\n }\n return [];\n }\n\n // If it's already a card element, return it\n if (typeof children === \"object\" && \"type\" in children) {\n return [children as CardChildOrNested];\n }\n\n // If it's a string or number, it might be text content for a Button or Text\n if (typeof children === \"string\" || typeof children === \"number\") {\n // Return as string, the component will handle it\n return [String(children) as unknown as CardChildOrNested];\n }\n\n return [];\n}\n\n/** Any card element type that can be created */\ntype AnyCardElement =\n | CardElement\n | CardChild\n | ButtonElement\n | LinkButtonElement\n | FieldElement\n | ModalElement\n | ModalChild\n | SelectOptionElement\n | null;\n\n/**\n * Type guard to check if props match TextProps\n */\nfunction isTextProps(props: CardJSXProps): props is TextProps {\n return !(\"id\" in props) && !(\"url\" in props) && !(\"label\" in props);\n}\n\n/**\n * Type guard to check if props match ButtonProps\n */\nfunction isButtonProps(props: CardJSXProps): props is ButtonProps {\n return \"id\" in props && typeof props.id === \"string\" && !(\"url\" in props);\n}\n\n/**\n * Type guard to check if props match LinkButtonProps\n */\nfunction isLinkButtonProps(props: CardJSXProps): props is LinkButtonProps {\n return \"url\" in props && typeof props.url === \"string\" && !(\"id\" in props);\n}\n\n/**\n * Type guard to check if props match ImageProps\n */\nfunction isImageProps(props: CardJSXProps): props is ImageProps {\n return \"url\" in props && typeof props.url === \"string\";\n}\n\n/**\n * Type guard to check if props match FieldProps\n */\nfunction isFieldProps(props: CardJSXProps): props is FieldProps {\n return (\n \"label\" in props &&\n \"value\" in props &&\n typeof props.label === \"string\" &&\n typeof props.value === \"string\"\n );\n}\n\n/**\n * Type guard to check if props match CardProps\n */\nfunction isCardProps(props: CardJSXProps): props is CardProps {\n return (\n !(\"id\" in props) &&\n !(\"url\" in props) &&\n !(\"callbackId\" in props) &&\n (\"title\" in props || \"subtitle\" in props || \"imageUrl\" in props)\n );\n}\n\n/**\n * Type guard to check if props match ModalProps\n */\nfunction isModalProps(props: CardJSXProps): props is ModalProps {\n return \"callbackId\" in props && \"title\" in props;\n}\n\n/**\n * Type guard to check if props match TextInputProps\n */\nfunction isTextInputProps(props: CardJSXProps): props is TextInputProps {\n return (\n \"id\" in props &&\n \"label\" in props &&\n !(\"options\" in props) &&\n !(\"value\" in props)\n );\n}\n\n/**\n * Type guard to check if props match SelectProps\n */\nfunction isSelectProps(props: CardJSXProps): props is SelectProps {\n return \"id\" in props && \"label\" in props && !(\"value\" in props);\n}\n\n/**\n * Type guard to check if props match SelectOptionProps\n */\nfunction isSelectOptionProps(props: CardJSXProps): props is SelectOptionProps {\n return \"label\" in props && \"value\" in props && !(\"id\" in props);\n}\n\n/**\n * Resolve a JSX element by calling its component function.\n * Transforms JSX props into the format each builder function expects.\n */\nfunction resolveJSXElement(element: JSXElement): AnyCardElement {\n const { type, props, children } = element;\n\n // Process children first\n const processedChildren = processChildren(children);\n\n // Use identity comparison to determine which builder function this is\n // This is necessary because function names get minified in production builds\n if (type === Text) {\n // Text(content: string, options?: { style })\n // JSX children become the content string\n const textProps = isTextProps(props) ? props : { style: undefined };\n const content =\n processedChildren.length > 0\n ? String(processedChildren[0])\n : String(textProps.children ?? \"\");\n return Text(content, { style: textProps.style });\n }\n\n if (type === Section) {\n // Section takes array as first argument\n return Section(processedChildren as CardChild[]);\n }\n\n if (type === Actions) {\n // Actions takes array of ButtonElements and LinkButtonElements\n return Actions(processedChildren as (ButtonElement | LinkButtonElement)[]);\n }\n\n if (type === Fields) {\n // Fields takes array of FieldElements\n return Fields(processedChildren as FieldElement[]);\n }\n\n if (type === Button) {\n // Button({ id, label, style, value })\n // JSX children become the label\n if (!isButtonProps(props)) {\n throw new Error(\"Button requires an 'id' prop\");\n }\n const label =\n processedChildren.length > 0\n ? String(processedChildren[0])\n : (props.label ?? \"\");\n return Button({\n id: props.id,\n label,\n style: props.style,\n value: props.value,\n });\n }\n\n if (type === LinkButton) {\n // LinkButton({ url, label, style })\n // JSX children become the label\n if (!isLinkButtonProps(props)) {\n throw new Error(\"LinkButton requires a 'url' prop\");\n }\n const label =\n processedChildren.length > 0\n ? String(processedChildren[0])\n : (props.label ?? \"\");\n return LinkButton({\n url: props.url,\n label,\n style: props.style,\n });\n }\n\n if (type === Image) {\n // Image({ url, alt })\n if (!isImageProps(props)) {\n throw new Error(\"Image requires a 'url' prop\");\n }\n return Image({ url: props.url, alt: props.alt });\n }\n\n if (type === Field) {\n // Field({ label, value })\n if (!isFieldProps(props)) {\n throw new Error(\"Field requires 'label' and 'value' props\");\n }\n return Field({\n label: props.label,\n value: props.value,\n });\n }\n\n if (type === Divider) {\n // Divider() - no args\n return Divider();\n }\n\n // Modal components\n if (type === Modal) {\n if (!isModalProps(props)) {\n throw new Error(\"Modal requires 'callbackId' and 'title' props\");\n }\n return Modal({\n callbackId: props.callbackId,\n title: props.title,\n submitLabel: props.submitLabel,\n closeLabel: props.closeLabel,\n notifyOnClose: props.notifyOnClose,\n children: filterModalChildren(processedChildren),\n });\n }\n\n if (type === TextInput) {\n if (!isTextInputProps(props)) {\n throw new Error(\"TextInput requires 'id' and 'label' props\");\n }\n return TextInput({\n id: props.id,\n label: props.label,\n placeholder: props.placeholder,\n initialValue: props.initialValue,\n multiline: props.multiline,\n optional: props.optional,\n maxLength: props.maxLength,\n });\n }\n\n if (type === Select) {\n if (!isSelectProps(props)) {\n throw new Error(\"Select requires 'id' and 'label' props\");\n }\n return Select({\n id: props.id,\n label: props.label,\n placeholder: props.placeholder,\n initialOption: props.initialOption,\n optional: props.optional,\n options: processedChildren as SelectOptionElement[],\n });\n }\n\n if (type === SelectOption) {\n if (!isSelectOptionProps(props)) {\n throw new Error(\"SelectOption requires 'label' and 'value' props\");\n }\n return SelectOption({\n label: props.label,\n value: props.value,\n });\n }\n\n // Default: Card({ title, subtitle, imageUrl, children })\n const cardProps = isCardProps(props) ? props : {};\n return Card({\n title: cardProps.title,\n subtitle: cardProps.subtitle,\n imageUrl: cardProps.imageUrl,\n children: processedChildren as CardChild[],\n });\n}\n\n/**\n * JSX factory function (used by the JSX transform).\n * Creates a lazy JSX element that will be resolved when needed.\n */\nexport function jsx<P extends CardJSXProps>(\n type: CardComponentFunction,\n props: P & { children?: unknown },\n _key?: string,\n): CardJSXElement<P> {\n const { children, ...restProps } = props;\n return {\n $$typeof: JSX_ELEMENT,\n type,\n props: restProps as P,\n children: children != null ? [children] : [],\n };\n}\n\n/**\n * JSX factory for elements with multiple children.\n */\nexport function jsxs<P extends CardJSXProps>(\n type: CardComponentFunction,\n props: P & { children?: unknown },\n _key?: string,\n): CardJSXElement<P> {\n const { children, ...restProps } = props;\n return {\n $$typeof: JSX_ELEMENT,\n type,\n props: restProps as P,\n children: Array.isArray(children)\n ? children\n : children != null\n ? [children]\n : [],\n };\n}\n\n/**\n * Development JSX factory (same as jsx, but called in dev mode).\n */\nexport const jsxDEV = jsx;\n\n/**\n * Fragment support (flattens children).\n */\nexport function Fragment(props: { children?: unknown }): CardChild[] {\n return processChildren(props.children) as CardChild[];\n}\n\n/**\n * Convert a JSX element tree to a CardElement.\n * Call this on the root JSX element to get a usable CardElement.\n */\nexport function toCardElement(jsxElement: unknown): CardElement | null {\n if (isJSXElement(jsxElement)) {\n const resolved = resolveJSXElement(jsxElement);\n if (\n resolved &&\n typeof resolved === \"object\" &&\n \"type\" in resolved &&\n resolved.type === \"card\"\n ) {\n return resolved as CardElement;\n }\n }\n\n // Already a CardElement\n if (\n typeof jsxElement === \"object\" &&\n jsxElement !== null &&\n \"type\" in jsxElement &&\n (jsxElement as CardElement).type === \"card\"\n ) {\n return jsxElement as CardElement;\n }\n\n return null;\n}\n\nexport function toModalElement(jsxElement: unknown): ModalElement | null {\n if (isJSXElement(jsxElement)) {\n const resolved = resolveJSXElement(jsxElement);\n if (\n resolved &&\n typeof resolved === \"object\" &&\n \"type\" in resolved &&\n resolved.type === \"modal\"\n ) {\n return resolved as ModalElement;\n }\n }\n if (isModalElement(jsxElement)) {\n return jsxElement;\n }\n return null;\n}\n\n/**\n * Check if a value is a JSX element (from our runtime or React).\n */\nexport function isJSX(value: unknown): boolean {\n if (isJSXElement(value)) {\n return true;\n }\n // Check for React elements\n if (\n typeof value === \"object\" &&\n value !== null &&\n \"$$typeof\" in value &&\n typeof (value as { $$typeof: unknown }).$$typeof === \"symbol\"\n ) {\n const symbolStr = (value as { $$typeof: symbol }).$$typeof.toString();\n return (\n symbolStr.includes(\"react.element\") ||\n symbolStr.includes(\"react.transitional.element\")\n );\n }\n return false;\n}\n\n// Re-export for JSX namespace\nexport namespace JSX {\n export interface Element extends JSXElement {}\n // biome-ignore lint/complexity/noBannedTypes: Required for JSX namespace\n export type IntrinsicElements = {};\n export interface ElementChildrenAttribute {\n // biome-ignore lint/complexity/noBannedTypes: Required for JSX children attribute\n children: {};\n }\n}\n"],"mappings":";AAoKO,SAAS,cAAc,OAAsC;AAClE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAAsB,SAAS;AAEpC;AAyBO,SAAS,KAAK,UAAuB,CAAC,GAAgB;AAC3D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO,QAAQ;AAAA,IACf,UAAU,QAAQ;AAAA,IAClB,UAAU,QAAQ;AAAA,IAClB,UAAU,QAAQ,YAAY,CAAC;AAAA,EACj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AAA,IACT;AAAA,EACF;AAGA,MACE,OAAO,eAAe,YACtB,eAAe,QACf,UAAU,cACT,WAA2B,SAAS,QACrC;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,SAAS,eAAe,YAA0C;AACvE,MAAI,aAAa,UAAU,GAAG;AAC5B,UAAM,WAAW,kBAAkB,UAAU;AAC7C,QACE,YACA,OAAO,aAAa,YACpB,UAAU,YACV,SAAS,SAAS,SAClB;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACA,MAAI,eAAe,UAAU,GAAG;AAC9B,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAKO,SAAS,MAAM,OAAyB;AAC7C,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,MACE,OAAO,UAAU,YACjB,UAAU,QACV,cAAc,SACd,OAAQ,MAAgC,aAAa,UACrD;AACA,UAAM,YAAa,MAA+B,SAAS,SAAS;AACpE,WACE,UAAU,SAAS,eAAe,KAClC,UAAU,SAAS,4BAA4B;AAAA,EAEnD;AACA,SAAO;AACT;","names":["isReactElement"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CardElement, a as CardJSXElement, M as ModalElement, b as CardChild, A as Actions$1, B as Button$1, c as Card$1, T as Text$1, D as Divider$1, F as Field$1, d as Fields$1, f as fromReactElement$1, I as Image$1, i as isCardElement$1, e as isJSX$1, L as LinkButton$1, S as Section$1, t as toCardElement$1, g as toModalElement$1, h as fromReactModalElement$1, j as isModalElement$1, k as Modal$1, l as Select$1, m as SelectOption$1, n as TextInput$1 } from './jsx-runtime-C5nsk859.js';
2
- export { y as ActionsElement, z as ButtonElement, E as ButtonOptions, o as ButtonProps, G as ButtonStyle, p as CardJSXProps, H as CardOptions, q as CardProps, r as ContainerProps, J as DividerElement, s as DividerProps, K as FieldElement, u as FieldProps, N as FieldsElement, O as ImageElement, v as ImageProps, P as LinkButtonElement, Q as LinkButtonOptions, w as LinkButtonProps, W as ModalChild, X as ModalOptions, R as SectionElement, Y as SelectElement, Z as SelectOptionElement, _ as SelectOptions, U as TextElement, $ as TextInputElement, a0 as TextInputOptions, x as TextProps, V as TextStyle } from './jsx-runtime-C5nsk859.js';
1
+ import { C as CardElement, a as CardJSXElement, M as ModalElement, b as CardChild, A as Actions$1, B as Button$1, c as Card$1, T as Text$1, D as Divider$1, F as Field$1, d as Fields$1, f as fromReactElement$1, I as Image$1, i as isCardElement$1, e as isJSX$1, L as LinkButton$1, S as Section$1, t as toCardElement$1, g as toModalElement$1, h as fromReactModalElement$1, j as isModalElement$1, k as Modal$1, l as Select$1, m as SelectOption$1, n as TextInput$1 } from './jsx-runtime-DXLQwmKr.js';
2
+ export { y as ActionsElement, z as ButtonElement, E as ButtonOptions, o as ButtonProps, G as ButtonStyle, p as CardJSXProps, H as CardOptions, q as CardProps, r as ContainerProps, J as DividerElement, s as DividerProps, K as FieldElement, u as FieldProps, N as FieldsElement, O as ImageElement, v as ImageProps, P as LinkButtonElement, Q as LinkButtonOptions, w as LinkButtonProps, W as ModalChild, X as ModalOptions, R as SectionElement, Y as SelectElement, Z as SelectOptionElement, _ as SelectOptions, U as TextElement, $ as TextInputElement, a0 as TextInputOptions, x as TextProps, V as TextStyle } from './jsx-runtime-DXLQwmKr.js';
3
3
  import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
4
4
  import { Root, Content, Blockquote, Code, Emphasis, InlineCode, Delete, Link, ListItem, List, Paragraph, Strong, Text } from 'mdast';
5
5
  export { Blockquote, Code, Content, Delete, Emphasis, InlineCode, Link, List, ListItem, Paragraph, Root, Strong, Text } from 'mdast';
@@ -156,6 +156,15 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
156
156
  fetchMessages(threadId: string, options?: FetchOptions): Promise<FetchResult<TRawMessage>>;
157
157
  /** Fetch thread metadata */
158
158
  fetchThread(threadId: string): Promise<ThreadInfo>;
159
+ /**
160
+ * Fetch a single message by ID.
161
+ * Optional - adapters that don't implement this will return null.
162
+ *
163
+ * @param threadId - The thread ID containing the message
164
+ * @param messageId - The platform-specific message ID
165
+ * @returns The message, or null if not found/not supported
166
+ */
167
+ fetchMessage?(threadId: string, messageId: string): Promise<Message<TRawMessage> | null>;
159
168
  /** Encode platform-specific data into a thread ID string */
160
169
  encodeThreadId(platformData: TThreadId): string;
161
170
  /** Decode thread ID string back to platform-specific data */
@@ -207,9 +216,10 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
207
216
  *
208
217
  * @param triggerId - Platform-specific trigger ID from the action event
209
218
  * @param modal - The modal element to display
219
+ * @param contextId - Optional context ID for server-side stored thread/message context
210
220
  * @returns The view/dialog ID
211
221
  */
212
- openModal?(triggerId: string, modal: ModalElement): Promise<{
222
+ openModal?(triggerId: string, modal: ModalElement, contextId?: string): Promise<{
213
223
  viewId: string;
214
224
  }>;
215
225
  /**
@@ -273,8 +283,22 @@ interface ChatInstance {
273
283
  processAction(event: Omit<ActionEvent, "thread" | "openModal"> & {
274
284
  adapter: Adapter;
275
285
  }, options?: WebhookOptions): void;
276
- processModalSubmit(event: Omit<ModalSubmitEvent, "thread">, options?: WebhookOptions): Promise<ModalResponse | undefined>;
277
- processModalClose(event: Omit<ModalCloseEvent, "thread">, options?: WebhookOptions): void;
286
+ /**
287
+ * Process a modal submit event from an adapter.
288
+ *
289
+ * @param event - The modal submit event (without relatedThread/relatedMessage)
290
+ * @param contextId - Context ID for retrieving stored thread/message context
291
+ * @param options - Webhook options
292
+ */
293
+ processModalSubmit(event: Omit<ModalSubmitEvent, "relatedThread" | "relatedMessage">, contextId?: string, options?: WebhookOptions): Promise<ModalResponse | undefined>;
294
+ /**
295
+ * Process a modal close event from an adapter.
296
+ *
297
+ * @param event - The modal close event (without relatedThread/relatedMessage)
298
+ * @param contextId - Context ID for retrieving stored thread/message context
299
+ * @param options - Webhook options
300
+ */
301
+ processModalClose(event: Omit<ModalCloseEvent, "relatedThread" | "relatedMessage">, contextId?: string, options?: WebhookOptions): void;
278
302
  getState(): StateAdapter;
279
303
  getUserName(): string;
280
304
  /** Get the configured logger, optionally with a child prefix */
@@ -472,6 +496,11 @@ interface Thread<TState = Record<string, unknown>, TRawMessage = unknown> {
472
496
  * Fetches the latest 50 messages and updates `recentMessages`.
473
497
  */
474
498
  refresh(): Promise<void>;
499
+ /**
500
+ * Wrap a Message object as a SentMessage with edit/delete capabilities.
501
+ * Used internally for reconstructing messages from serialized data.
502
+ */
503
+ createSentMessageFromMessage(message: Message<TRawMessage>): SentMessage<TRawMessage>;
475
504
  /**
476
505
  * Get a platform-specific mention string for a user.
477
506
  * Use this to @-mention a user in a message.
@@ -953,22 +982,59 @@ interface ActionEvent<TRawMessage = unknown> {
953
982
  * ```
954
983
  */
955
984
  type ActionHandler = (event: ActionEvent) => Promise<void>;
956
- interface ModalSubmitEvent {
985
+ /**
986
+ * Event emitted when a user submits a modal form.
987
+ */
988
+ interface ModalSubmitEvent<TRawMessage = unknown> {
989
+ /** The callback ID specified when creating the modal */
957
990
  callbackId: string;
991
+ /** Platform-specific view/dialog ID */
958
992
  viewId: string;
993
+ /** Form field values keyed by input ID */
959
994
  values: Record<string, string>;
960
- privateMetadata?: string;
995
+ /** The user who submitted the modal */
961
996
  user: Author;
997
+ /** The adapter that received this event */
962
998
  adapter: Adapter;
999
+ /** Raw platform-specific payload */
963
1000
  raw: unknown;
1001
+ /**
1002
+ * The thread where the modal was originally triggered from.
1003
+ * Available when the modal was opened via ActionEvent.openModal().
1004
+ */
1005
+ relatedThread?: Thread<Record<string, unknown>, TRawMessage>;
1006
+ /**
1007
+ * The message that contained the action which opened the modal.
1008
+ * Available when the modal was opened from a message action via ActionEvent.openModal().
1009
+ * This is a SentMessage with edit/delete capabilities.
1010
+ */
1011
+ relatedMessage?: SentMessage<TRawMessage>;
964
1012
  }
965
- interface ModalCloseEvent {
1013
+ /**
1014
+ * Event emitted when a user closes/cancels a modal (requires notifyOnClose).
1015
+ */
1016
+ interface ModalCloseEvent<TRawMessage = unknown> {
1017
+ /** The callback ID specified when creating the modal */
966
1018
  callbackId: string;
1019
+ /** Platform-specific view/dialog ID */
967
1020
  viewId: string;
968
- privateMetadata?: string;
1021
+ /** The user who closed the modal */
969
1022
  user: Author;
1023
+ /** The adapter that received this event */
970
1024
  adapter: Adapter;
1025
+ /** Raw platform-specific payload */
971
1026
  raw: unknown;
1027
+ /**
1028
+ * The thread where the modal was originally triggered from.
1029
+ * Available when the modal was opened via ActionEvent.openModal().
1030
+ */
1031
+ relatedThread?: Thread<Record<string, unknown>, TRawMessage>;
1032
+ /**
1033
+ * The message that contained the action which opened the modal.
1034
+ * Available when the modal was opened from a message action via ActionEvent.openModal().
1035
+ * This is a SentMessage with edit/delete capabilities.
1036
+ */
1037
+ relatedMessage?: SentMessage<TRawMessage>;
972
1038
  }
973
1039
  type ModalErrorsResponse = {
974
1040
  action: "errors";
@@ -1413,8 +1479,18 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
1413
1479
  processAction(event: Omit<ActionEvent, "thread" | "openModal"> & {
1414
1480
  adapter: Adapter;
1415
1481
  }, options?: WebhookOptions): void;
1416
- processModalSubmit(event: Omit<ModalSubmitEvent, "thread">, _options?: WebhookOptions): Promise<ModalResponse | undefined>;
1417
- processModalClose(event: Omit<ModalCloseEvent, "thread">, options?: WebhookOptions): void;
1482
+ processModalSubmit(event: Omit<ModalSubmitEvent, "relatedThread" | "relatedMessage">, contextId?: string, _options?: WebhookOptions): Promise<ModalResponse | undefined>;
1483
+ processModalClose(event: Omit<ModalCloseEvent, "relatedThread" | "relatedMessage">, contextId?: string, options?: WebhookOptions): void;
1484
+ /**
1485
+ * Store modal context server-side and return a context ID.
1486
+ * Called when opening a modal to preserve thread/message for the submit handler.
1487
+ */
1488
+ private storeModalContext;
1489
+ /**
1490
+ * Retrieve and delete modal context from server-side storage.
1491
+ * Called when processing modal submit/close to reconstruct thread/message.
1492
+ */
1493
+ private retrieveModalContext;
1418
1494
  /**
1419
1495
  * Handle an action event internally.
1420
1496
  */
@@ -1608,7 +1684,7 @@ declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TSt
1608
1684
  * const thread = ThreadImpl.fromJSON(serializedThread);
1609
1685
  * ```
1610
1686
  */
1611
- static fromJSON<TState = Record<string, unknown>>(json: SerializedThread): ThreadImpl<TState>;
1687
+ static fromJSON<TState = Record<string, unknown>>(json: SerializedThread, adapter?: Adapter): ThreadImpl<TState>;
1612
1688
  /**
1613
1689
  * Serialize a ThreadImpl instance for @workflow/serde.
1614
1690
  * This static method is automatically called by workflow serialization.
@@ -1621,6 +1697,7 @@ declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TSt
1621
1697
  */
1622
1698
  static [WORKFLOW_DESERIALIZE](data: SerializedThread): ThreadImpl;
1623
1699
  private createSentMessage;
1700
+ createSentMessageFromMessage(message: Message): SentMessage;
1624
1701
  }
1625
1702
 
1626
1703
  /**
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  isModalElement,
22
22
  toCardElement,
23
23
  toModalElement
24
- } from "./chunk-5AEQCOSP.js";
24
+ } from "./chunk-RRTA7C5H.js";
25
25
 
26
26
  // src/chat-singleton.ts
27
27
  var _singleton = null;
@@ -766,13 +766,17 @@ var ThreadImpl = class _ThreadImpl {
766
766
  * const thread = ThreadImpl.fromJSON(serializedThread);
767
767
  * ```
768
768
  */
769
- static fromJSON(json) {
770
- return new _ThreadImpl({
769
+ static fromJSON(json, adapter) {
770
+ const thread = new _ThreadImpl({
771
771
  id: json.id,
772
772
  adapterName: json.adapterName,
773
773
  channelId: json.channelId,
774
774
  isDM: json.isDM
775
775
  });
776
+ if (adapter) {
777
+ thread._adapter = adapter;
778
+ }
779
+ return thread;
776
780
  }
777
781
  /**
778
782
  * Serialize a ThreadImpl instance for @workflow/serde.
@@ -840,6 +844,46 @@ var ThreadImpl = class _ThreadImpl {
840
844
  };
841
845
  return sentMessage;
842
846
  }
847
+ createSentMessageFromMessage(message) {
848
+ const adapter = this.adapter;
849
+ const threadId = this.id;
850
+ const messageId = message.id;
851
+ const self = this;
852
+ return {
853
+ id: message.id,
854
+ threadId: message.threadId,
855
+ text: message.text,
856
+ formatted: message.formatted,
857
+ raw: message.raw,
858
+ author: message.author,
859
+ metadata: message.metadata,
860
+ attachments: message.attachments,
861
+ isMention: message.isMention,
862
+ toJSON() {
863
+ return message.toJSON();
864
+ },
865
+ async edit(newContent) {
866
+ let postable = newContent;
867
+ if (isJSX(newContent)) {
868
+ const card = toCardElement(newContent);
869
+ if (!card)
870
+ throw new Error("Invalid JSX element: must be a Card element");
871
+ postable = card;
872
+ }
873
+ await adapter.editMessage(threadId, messageId, postable);
874
+ return self.createSentMessage(messageId, postable, threadId);
875
+ },
876
+ async delete() {
877
+ await adapter.deleteMessage(threadId, messageId);
878
+ },
879
+ async addReaction(emoji2) {
880
+ await adapter.addReaction(threadId, messageId, emoji2);
881
+ },
882
+ async removeReaction(emoji2) {
883
+ await adapter.removeReaction(threadId, messageId, emoji2);
884
+ }
885
+ };
886
+ }
843
887
  };
844
888
  function extractMessageContent(message) {
845
889
  if (typeof message === "string") {
@@ -893,6 +937,7 @@ function extractMessageContent(message) {
893
937
  // src/chat.ts
894
938
  var DEFAULT_LOCK_TTL_MS = 3e4;
895
939
  var DEDUPE_TTL_MS = 6e4;
940
+ var MODAL_CONTEXT_TTL_MS = 24 * 60 * 60 * 1e3;
896
941
  var Chat = class {
897
942
  /**
898
943
  * Register this Chat instance as the global singleton.
@@ -1239,20 +1284,21 @@ var Chat = class {
1239
1284
  options.waitUntil(task);
1240
1285
  }
1241
1286
  }
1242
- async processModalSubmit(event, _options) {
1243
- this.logger.debug("Incoming modal submit", {
1244
- adapter: event.adapter.name,
1245
- callbackId: event.callbackId,
1246
- viewId: event.viewId,
1247
- user: event.user.userName
1248
- });
1287
+ async processModalSubmit(event, contextId, _options) {
1288
+ const { relatedThread, relatedMessage } = await this.retrieveModalContext(
1289
+ event.adapter.name,
1290
+ contextId
1291
+ );
1292
+ const fullEvent = {
1293
+ ...event,
1294
+ relatedThread,
1295
+ relatedMessage
1296
+ };
1249
1297
  for (const { callbackIds, handler } of this.modalSubmitHandlers) {
1250
1298
  if (callbackIds.length === 0 || callbackIds.includes(event.callbackId)) {
1251
1299
  try {
1252
- const response = await handler(event);
1253
- if (response) {
1254
- return response;
1255
- }
1300
+ const response = await handler(fullEvent);
1301
+ if (response) return response;
1256
1302
  } catch (err) {
1257
1303
  this.logger.error("Modal submit handler error", {
1258
1304
  error: err,
@@ -1262,17 +1308,20 @@ var Chat = class {
1262
1308
  }
1263
1309
  }
1264
1310
  }
1265
- processModalClose(event, options) {
1311
+ processModalClose(event, contextId, options) {
1266
1312
  const task = (async () => {
1267
- this.logger.debug("Incoming modal close", {
1268
- adapter: event.adapter.name,
1269
- callbackId: event.callbackId,
1270
- viewId: event.viewId,
1271
- user: event.user.userName
1272
- });
1313
+ const { relatedThread, relatedMessage } = await this.retrieveModalContext(
1314
+ event.adapter.name,
1315
+ contextId
1316
+ );
1317
+ const fullEvent = {
1318
+ ...event,
1319
+ relatedThread,
1320
+ relatedMessage
1321
+ };
1273
1322
  for (const { callbackIds, handler } of this.modalCloseHandlers) {
1274
1323
  if (callbackIds.length === 0 || callbackIds.includes(event.callbackId)) {
1275
- await handler(event);
1324
+ await handler(fullEvent);
1276
1325
  }
1277
1326
  }
1278
1327
  })().catch((err) => {
@@ -1285,6 +1334,42 @@ var Chat = class {
1285
1334
  options.waitUntil(task);
1286
1335
  }
1287
1336
  }
1337
+ /**
1338
+ * Store modal context server-side and return a context ID.
1339
+ * Called when opening a modal to preserve thread/message for the submit handler.
1340
+ */
1341
+ async storeModalContext(adapterName, thread, message) {
1342
+ const contextId = crypto.randomUUID();
1343
+ const key = `modal-context:${adapterName}:${contextId}`;
1344
+ const context = {
1345
+ thread: thread.toJSON(),
1346
+ message: message?.toJSON()
1347
+ };
1348
+ await this._stateAdapter.set(key, context, MODAL_CONTEXT_TTL_MS);
1349
+ return contextId;
1350
+ }
1351
+ /**
1352
+ * Retrieve and delete modal context from server-side storage.
1353
+ * Called when processing modal submit/close to reconstruct thread/message.
1354
+ */
1355
+ async retrieveModalContext(adapterName, contextId) {
1356
+ if (!contextId) {
1357
+ return { relatedThread: void 0, relatedMessage: void 0 };
1358
+ }
1359
+ const key = `modal-context:${adapterName}:${contextId}`;
1360
+ const stored = await this._stateAdapter.get(key);
1361
+ if (!stored) {
1362
+ return { relatedThread: void 0, relatedMessage: void 0 };
1363
+ }
1364
+ const adapter = this.adapters.get(adapterName);
1365
+ const thread = ThreadImpl.fromJSON(stored.thread, adapter);
1366
+ let relatedMessage;
1367
+ if (stored.message) {
1368
+ const message = Message.fromJSON(stored.message);
1369
+ relatedMessage = thread.createSentMessageFromMessage(message);
1370
+ }
1371
+ return { relatedThread: thread, relatedMessage };
1372
+ }
1288
1373
  /**
1289
1374
  * Handle an action event internally.
1290
1375
  */
@@ -1303,11 +1388,20 @@ var Chat = class {
1303
1388
  });
1304
1389
  return;
1305
1390
  }
1306
- const isSubscribed = await this._stateAdapter.isSubscribed(event.threadId);
1391
+ const [isSubscribed, fetchedMessage] = await Promise.all([
1392
+ this._stateAdapter.isSubscribed(event.threadId),
1393
+ event.messageId && event.adapter.fetchMessage ? event.adapter.fetchMessage(event.threadId, event.messageId).catch((err) => {
1394
+ this.logger.warn("Failed to fetch message for action event", {
1395
+ messageId: event.messageId,
1396
+ error: err
1397
+ });
1398
+ return null;
1399
+ }) : Promise.resolve(null)
1400
+ ]);
1307
1401
  const thread = await this.createThread(
1308
1402
  event.adapter,
1309
1403
  event.threadId,
1310
- {},
1404
+ fetchedMessage ?? {},
1311
1405
  isSubscribed
1312
1406
  );
1313
1407
  const fullEvent = {
@@ -1332,7 +1426,18 @@ var Chat = class {
1332
1426
  }
1333
1427
  modalElement = converted;
1334
1428
  }
1335
- return event.adapter.openModal(event.triggerId, modalElement);
1429
+ const recentMessage = thread.recentMessages[0];
1430
+ const message = recentMessage && typeof recentMessage.toJSON === "function" ? recentMessage : void 0;
1431
+ const contextId = await this.storeModalContext(
1432
+ event.adapter.name,
1433
+ thread,
1434
+ message
1435
+ );
1436
+ return event.adapter.openModal(
1437
+ event.triggerId,
1438
+ modalElement,
1439
+ contextId
1440
+ );
1336
1441
  }
1337
1442
  };
1338
1443
  this.logger.debug("Checking action handlers", {