@gram-ai/elements 1.33.2 → 1.34.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.
Files changed (47) hide show
  1. package/dist/components/ui/time-range-picker.d.ts +17 -1
  2. package/dist/components/ui/time-range-picker.test.d.ts +1 -0
  3. package/dist/elements.cjs +1 -1
  4. package/dist/elements.js +19 -16
  5. package/dist/hooks/useGramThreadListAdapter.d.ts +13 -0
  6. package/dist/{index-CGoLfO5p.js → index-B5lZrrO2.js} +52 -37
  7. package/dist/index-B5lZrrO2.js.map +1 -0
  8. package/dist/{index-reVrRxP1.js → index-BFU6NvbL.js} +6854 -6807
  9. package/dist/index-BFU6NvbL.js.map +1 -0
  10. package/dist/{index-DAWGW1Nj.cjs → index-C08dvTEo.cjs} +43 -43
  11. package/dist/index-C08dvTEo.cjs.map +1 -0
  12. package/dist/index-DzZ1-jQY.cjs +194 -0
  13. package/dist/index-DzZ1-jQY.cjs.map +1 -0
  14. package/dist/index.d.ts +4 -1
  15. package/dist/lib/messageConverter.d.ts +58 -8
  16. package/dist/lib/models.d.ts +1 -1
  17. package/dist/lib/utils.d.ts +2 -0
  18. package/dist/plugins.cjs +1 -1
  19. package/dist/plugins.js +1 -1
  20. package/dist/{profiler-B3tfiOx4.cjs → profiler-BRnyr1GA.cjs} +2 -2
  21. package/dist/{profiler-B3tfiOx4.cjs.map → profiler-BRnyr1GA.cjs.map} +1 -1
  22. package/dist/{profiler-noho3NG9.js → profiler-KLSTpp6I.js} +2 -2
  23. package/dist/{profiler-noho3NG9.js.map → profiler-KLSTpp6I.js.map} +1 -1
  24. package/dist/{startRecording-mkmig-2n.js → startRecording-BfxB1xxR.js} +2 -2
  25. package/dist/{startRecording-mkmig-2n.js.map → startRecording-BfxB1xxR.js.map} +1 -1
  26. package/dist/{startRecording-7Oy6wM18.cjs → startRecording-CKx-YWbq.cjs} +2 -2
  27. package/dist/{startRecording-7Oy6wM18.cjs.map → startRecording-CKx-YWbq.cjs.map} +1 -1
  28. package/dist/types/index.d.ts +64 -1
  29. package/package.json +4 -2
  30. package/src/components/assistant-ui/thread.tsx +7 -3
  31. package/src/components/ui/time-range-picker.test.ts +57 -0
  32. package/src/components/ui/time-range-picker.tsx +29 -4
  33. package/src/contexts/ElementsProvider.tsx +57 -8
  34. package/src/hooks/useGramThreadListAdapter.tsx +68 -6
  35. package/src/index.ts +16 -0
  36. package/src/lib/cassette.ts +1 -19
  37. package/src/lib/contextCompaction.test.ts +2 -2
  38. package/src/lib/contextCompaction.ts +20 -8
  39. package/src/lib/messageConverter.ts +94 -56
  40. package/src/lib/models.ts +19 -7
  41. package/src/lib/utils.ts +20 -0
  42. package/src/types/index.ts +73 -1
  43. package/dist/index-BCV7Zf9E.cjs +0 -194
  44. package/dist/index-BCV7Zf9E.cjs.map +0 -1
  45. package/dist/index-CGoLfO5p.js.map +0 -1
  46. package/dist/index-DAWGW1Nj.cjs.map +0 -1
  47. package/dist/index-reVrRxP1.js.map +0 -1
@@ -7,7 +7,7 @@ import {
7
7
  TextMessagePartComponent,
8
8
  ToolCallMessagePartComponent,
9
9
  } from "@assistant-ui/react";
10
- import { LanguageModel } from "ai";
10
+ import { ChatTransport, LanguageModel, UIMessage } from "ai";
11
11
  import {
12
12
  ComponentType,
13
13
  Dispatch,
@@ -49,6 +49,39 @@ export interface MCPServerEntry {
49
49
  export const VARIANTS = ["widget", "sidecar", "standalone"] as const;
50
50
  export type Variant = (typeof VARIANTS)[number];
51
51
 
52
+ /**
53
+ * Live chat context handed to a {@link ElementsTransportFactory}.
54
+ */
55
+ export interface ElementsTransportContext {
56
+ /**
57
+ * The active conversation's persisted chat id, or null when the current
58
+ * thread has no server-side chat yet (a brand-new, not-yet-sent thread).
59
+ * Sourced from the thread-list runtime, so it stays current as the user
60
+ * switches conversations.
61
+ */
62
+ getChatId: () => string | null;
63
+
64
+ /**
65
+ * Adopt a chat id assigned out-of-band (e.g. a server-minted id a consumer
66
+ * transport receives on the first send). Call at the START of an async send
67
+ * to capture the active conversation, then invoke the returned function with
68
+ * the server's id once it's known. The closure binds to the conversation the
69
+ * send originated from, so a thread switch or a parallel send on another
70
+ * thread during the round-trip can't mis-associate the id.
71
+ */
72
+ adoptChatId: () => (chatId: string) => void;
73
+ }
74
+
75
+ /**
76
+ * A factory for a {@link ChatTransport}. When `ElementsConfig.transport` is a
77
+ * function, Elements invokes it once inside the provider and passes the live
78
+ * chat context, letting the transport read the current chat id at send time
79
+ * without reaching into Elements internals.
80
+ */
81
+ export type ElementsTransportFactory = (
82
+ ctx: ElementsTransportContext,
83
+ ) => ChatTransport<UIMessage>;
84
+
52
85
  /**
53
86
  * The top level configuration object for the Elements library.
54
87
  *
@@ -65,6 +98,29 @@ export interface ElementsConfig {
65
98
  */
66
99
  systemPrompt?: string;
67
100
 
101
+ /**
102
+ * Optional chat transport override. When provided, Elements uses this
103
+ * transport instead of its built-in client-side streaming transport — e.g.
104
+ * to route the conversation through a persistent server-side assistant that
105
+ * generates replies and is polled for them. When omitted, the default
106
+ * client-side transport is used.
107
+ *
108
+ * May be a {@link ChatTransport} directly, or an {@link ElementsTransportFactory}
109
+ * that Elements invokes inside the provider with the live chat context — use
110
+ * the factory form when the transport needs the active chat id at send time.
111
+ */
112
+ transport?: ChatTransport<UIMessage> | ElementsTransportFactory;
113
+
114
+ /**
115
+ * Whether to expose the inline message-edit affordance on user messages.
116
+ * Edit relies on assistant-ui's local branch rewriting; transports backed by a
117
+ * persistent server-side assistant typically can't honour that, so the
118
+ * sidebar uses this to hide the action rather than offer a broken control.
119
+ *
120
+ * @default true
121
+ */
122
+ allowMessageEdit?: boolean;
123
+
68
124
  /**
69
125
  * Any plugins to use for the Elements library.
70
126
  *
@@ -1003,6 +1059,22 @@ export interface HistoryConfig {
1003
1059
  */
1004
1060
  enabled: boolean;
1005
1061
 
1062
+ /**
1063
+ * Extra query parameters forwarded to the thread-list request, used to
1064
+ * filter which conversations are shown. Opaque to Elements — the consumer
1065
+ * decides the keys (e.g. a search term, or a backend-specific scope). When
1066
+ * omitted, all of the caller's chats are listed.
1067
+ */
1068
+ threadListFilters?: Record<string, string>;
1069
+
1070
+ /**
1071
+ * Let the backend own chat-id creation. When true, a brand-new thread does not
1072
+ * get a client-generated id; instead the transport assigns the id (e.g. one
1073
+ * the server minted on the first send, reported via the transport context's
1074
+ * `adoptChatId`). Use with a server-backed `transport`.
1075
+ */
1076
+ deferThreadIdMinting?: boolean;
1077
+
1006
1078
  /**
1007
1079
  * Whether to show the thread list sidebar/panel.
1008
1080
  * Only applicable for widget and sidecar variants.