@gram-ai/elements 1.24.2 → 1.25.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.
Files changed (48) hide show
  1. package/README.md +24 -0
  2. package/README.typedoc.md +14 -0
  3. package/dist/compat-plugin.cjs +2 -0
  4. package/dist/compat-plugin.cjs.map +1 -0
  5. package/dist/compat-plugin.d.ts +3 -0
  6. package/dist/compat-plugin.js +26 -0
  7. package/dist/compat-plugin.js.map +1 -0
  8. package/dist/compat-shims-BPJ7Q68c.js +38 -0
  9. package/dist/compat-shims-BPJ7Q68c.js.map +1 -0
  10. package/dist/compat-shims-CO9JXXV4.cjs +2 -0
  11. package/dist/compat-shims-CO9JXXV4.cjs.map +1 -0
  12. package/dist/compat-shims.d.ts +27 -0
  13. package/dist/compat.d.ts +8 -0
  14. package/dist/compat.test.d.ts +0 -0
  15. package/dist/components/Replay.stories.d.ts +16 -0
  16. package/dist/elements.cjs +1 -1
  17. package/dist/elements.js +1 -1
  18. package/dist/{index-EMjYCXA1.cjs → index-C3UbmFRR.cjs} +50 -50
  19. package/dist/index-C3UbmFRR.cjs.map +1 -0
  20. package/dist/{index-B9hEyUXQ.js → index-DxJwZ5Kc.js} +4637 -4631
  21. package/dist/index-DxJwZ5Kc.js.map +1 -0
  22. package/dist/lib/messageConverter.d.ts +1 -1
  23. package/dist/lib/messageConverter.test.d.ts +1 -0
  24. package/dist/{profiler-DFrzs1Rd.js → profiler-CijCgLrw.js} +2 -2
  25. package/dist/{profiler-DFrzs1Rd.js.map → profiler-CijCgLrw.js.map} +1 -1
  26. package/dist/{profiler-DUyotQcs.cjs → profiler-DAT0DL1W.cjs} +2 -2
  27. package/dist/{profiler-DUyotQcs.cjs.map → profiler-DAT0DL1W.cjs.map} +1 -1
  28. package/dist/react-shim.cjs +2 -0
  29. package/dist/react-shim.cjs.map +1 -0
  30. package/dist/react-shim.d.ts +9 -0
  31. package/dist/react-shim.js +78 -0
  32. package/dist/react-shim.js.map +1 -0
  33. package/dist/{startRecording-CbzZg6Ct.cjs → startRecording-DotsE8QT.cjs} +2 -2
  34. package/dist/{startRecording-CbzZg6Ct.cjs.map → startRecording-DotsE8QT.cjs.map} +1 -1
  35. package/dist/{startRecording-CNklkzCM.js → startRecording-gmhENmf0.js} +2 -2
  36. package/dist/{startRecording-CNklkzCM.js.map → startRecording-gmhENmf0.js.map} +1 -1
  37. package/package.json +10 -5
  38. package/src/compat-plugin.ts +38 -0
  39. package/src/compat-shims.ts +75 -0
  40. package/src/compat.test.ts +80 -0
  41. package/src/compat.ts +19 -0
  42. package/src/components/Replay.stories.tsx +230 -0
  43. package/src/index.ts +3 -0
  44. package/src/lib/messageConverter.test.ts +242 -0
  45. package/src/lib/messageConverter.ts +22 -10
  46. package/src/react-shim.ts +54 -0
  47. package/dist/index-B9hEyUXQ.js.map +0 -1
  48. package/dist/index-EMjYCXA1.cjs.map +0 -1
@@ -146,17 +146,15 @@ function buildAssistantContentParts(
146
146
  return []
147
147
  }
148
148
 
149
+ const parts: ThreadAssistantMessagePart[] = []
150
+
149
151
  if (typeof msg.content === 'string' || !msg.content) {
150
- return [
151
- {
152
- type: 'text',
153
- text: msg.content ?? '',
154
- },
155
- ]
152
+ parts.push({
153
+ type: 'text',
154
+ text: msg.content ?? '',
155
+ })
156
156
  }
157
157
 
158
- const parts: ThreadAssistantMessagePart[] = []
159
-
160
158
  const toolCallsJSON = (msg as any).tool_calls as FIXME<
161
159
  string | undefined,
162
160
  'Fixed by switching to Gram TS SDK.'
@@ -331,6 +329,11 @@ export function convertGramMessagesToUIMessages(messages: GramChatMessage[]): {
331
329
  const uiMessages: { parentId: string | null; message: UIMessage }[] = []
332
330
  let prevId: string | null = null
333
331
 
332
+ // Track tool call IDs across messages to deduplicate. The server accumulates
333
+ // all tool calls from a turn into each message, so without this, every
334
+ // assistant message in a multi-step tool use flow would show the full count.
335
+ const seenToolCallIds = new Set<string>()
336
+
334
337
  for (const msg of messages) {
335
338
  switch (msg.role) {
336
339
  case 'developer':
@@ -361,6 +364,7 @@ export function convertGramMessagesToUIMessages(messages: GramChatMessage[]): {
361
364
  break
362
365
  }
363
366
  case 'user': {
367
+ seenToolCallIds.clear()
364
368
  uiMessages.push({
365
369
  parentId: prevId,
366
370
  message: {
@@ -382,7 +386,8 @@ export function convertGramMessagesToUIMessages(messages: GramChatMessage[]): {
382
386
  role: 'assistant',
383
387
  parts: convertGramMessagePartsToUIMessageParts(
384
388
  msg,
385
- toolCallResults
389
+ toolCallResults,
390
+ seenToolCallIds
386
391
  ),
387
392
  } satisfies UIMessage,
388
393
  }
@@ -403,7 +408,8 @@ export function convertGramMessagesToUIMessages(messages: GramChatMessage[]): {
403
408
 
404
409
  export function convertGramMessagePartsToUIMessageParts(
405
410
  msg: UserMessage | AssistantMessage,
406
- toolResults: Map<string, ToolResponseMessage>
411
+ toolResults: Map<string, ToolResponseMessage>,
412
+ seenToolCallIds?: Set<string>
407
413
  ): UIMessage['parts'] {
408
414
  const uiparts: UIMessage['parts'] = []
409
415
 
@@ -480,6 +486,12 @@ export function convertGramMessagePartsToUIMessageParts(
480
486
  }
481
487
 
482
488
  for (const tc of toolCalls) {
489
+ // The server accumulates all tool calls from a turn into each message's
490
+ // tool_calls field. Deduplicate across messages so each tool call only
491
+ // appears in the first message that references it.
492
+ if (seenToolCallIds?.has(tc.id)) continue
493
+ seenToolCallIds?.add(tc.id)
494
+
483
495
  const content = toolResults.get(tc.id)?.content
484
496
  uiparts.push({
485
497
  type: 'dynamic-tool',
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Bundler-level React shim for React 16/17. The reactCompat() Vite plugin
3
+ * aliases 'react' to this file so named imports get polyfilled APIs.
4
+ * NOT meant to be imported directly.
5
+ */
6
+
7
+ // @ts-expect-error — resolved by the Vite plugin to the real react package
8
+ import * as ReactOriginal from 'react-original'
9
+ import { createShims } from './compat-shims'
10
+
11
+ const Shimmed = { ...ReactOriginal, ...createShims(ReactOriginal) }
12
+
13
+ // React internals required by react-dom
14
+ export const __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED =
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ (ReactOriginal as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
17
+
18
+ export const {
19
+ Children,
20
+ Component,
21
+ Fragment,
22
+ Profiler,
23
+ PureComponent,
24
+ StrictMode,
25
+ Suspense,
26
+ cloneElement,
27
+ createContext,
28
+ createElement,
29
+ createFactory,
30
+ createRef,
31
+ forwardRef,
32
+ isValidElement,
33
+ lazy,
34
+ memo,
35
+ startTransition,
36
+ useCallback,
37
+ useContext,
38
+ useDebugValue,
39
+ useDeferredValue,
40
+ useEffect,
41
+ useId,
42
+ useImperativeHandle,
43
+ useInsertionEffect,
44
+ useLayoutEffect,
45
+ useMemo,
46
+ useReducer,
47
+ useRef,
48
+ useState,
49
+ useSyncExternalStore,
50
+ useTransition,
51
+ version,
52
+ } = Shimmed
53
+
54
+ export default Shimmed