@tambo-ai/react 0.43.1 → 0.44.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 (89) hide show
  1. package/dist/hooks/__tests__/use-suggestions.test.js +55 -27
  2. package/dist/hooks/__tests__/use-suggestions.test.js.map +1 -1
  3. package/dist/hooks/__tests__/use-tambo-stream-status.test.js +82 -39
  4. package/dist/hooks/__tests__/use-tambo-stream-status.test.js.map +1 -1
  5. package/dist/hooks/index.d.ts +2 -2
  6. package/dist/hooks/index.d.ts.map +1 -1
  7. package/dist/hooks/index.js +2 -3
  8. package/dist/hooks/index.js.map +1 -1
  9. package/dist/hooks/use-component-state.d.ts.map +1 -1
  10. package/dist/hooks/use-component-state.js +2 -2
  11. package/dist/hooks/use-component-state.js.map +1 -1
  12. package/dist/hooks/use-current-message.d.ts +12 -27
  13. package/dist/hooks/use-current-message.d.ts.map +1 -1
  14. package/dist/hooks/use-current-message.js +16 -36
  15. package/dist/hooks/use-current-message.js.map +1 -1
  16. package/dist/hooks/use-tambo-stream-status.js +1 -1
  17. package/dist/hooks/use-tambo-stream-status.js.map +1 -1
  18. package/dist/hooks/use-thread-input.js +3 -2
  19. package/dist/hooks/use-thread-input.js.map +1 -1
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/providers/__tests__/tambo-prop-stream-provider.test.js +79 -9
  25. package/dist/providers/__tests__/tambo-prop-stream-provider.test.js.map +1 -1
  26. package/dist/providers/__tests__/tambo-thread-provider.test.js +0 -7
  27. package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  28. package/dist/providers/index.d.ts +1 -1
  29. package/dist/providers/index.d.ts.map +1 -1
  30. package/dist/providers/index.js +2 -1
  31. package/dist/providers/index.js.map +1 -1
  32. package/dist/providers/tambo-provider.d.ts +2 -2
  33. package/dist/providers/tambo-provider.d.ts.map +1 -1
  34. package/dist/providers/tambo-provider.js.map +1 -1
  35. package/dist/providers/tambo-stubs.d.ts.map +1 -1
  36. package/dist/providers/tambo-stubs.js +6 -6
  37. package/dist/providers/tambo-stubs.js.map +1 -1
  38. package/dist/providers/tambo-thread-provider.d.ts +29 -11
  39. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  40. package/dist/providers/tambo-thread-provider.js +59 -28
  41. package/dist/providers/tambo-thread-provider.js.map +1 -1
  42. package/dist/util/generate-component.d.ts.map +1 -1
  43. package/dist/util/generate-component.js +6 -2
  44. package/dist/util/generate-component.js.map +1 -1
  45. package/esm/hooks/__tests__/use-suggestions.test.js +55 -27
  46. package/esm/hooks/__tests__/use-suggestions.test.js.map +1 -1
  47. package/esm/hooks/__tests__/use-tambo-stream-status.test.js +82 -39
  48. package/esm/hooks/__tests__/use-tambo-stream-status.test.js.map +1 -1
  49. package/esm/hooks/index.d.ts +2 -2
  50. package/esm/hooks/index.d.ts.map +1 -1
  51. package/esm/hooks/index.js +2 -2
  52. package/esm/hooks/index.js.map +1 -1
  53. package/esm/hooks/use-component-state.d.ts.map +1 -1
  54. package/esm/hooks/use-component-state.js +3 -3
  55. package/esm/hooks/use-component-state.js.map +1 -1
  56. package/esm/hooks/use-current-message.d.ts +12 -27
  57. package/esm/hooks/use-current-message.d.ts.map +1 -1
  58. package/esm/hooks/use-current-message.js +15 -34
  59. package/esm/hooks/use-current-message.js.map +1 -1
  60. package/esm/hooks/use-tambo-stream-status.js +2 -2
  61. package/esm/hooks/use-tambo-stream-status.js.map +1 -1
  62. package/esm/hooks/use-thread-input.js +4 -3
  63. package/esm/hooks/use-thread-input.js.map +1 -1
  64. package/esm/index.d.ts +2 -2
  65. package/esm/index.d.ts.map +1 -1
  66. package/esm/index.js +2 -2
  67. package/esm/index.js.map +1 -1
  68. package/esm/providers/__tests__/tambo-prop-stream-provider.test.js +80 -10
  69. package/esm/providers/__tests__/tambo-prop-stream-provider.test.js.map +1 -1
  70. package/esm/providers/__tests__/tambo-thread-provider.test.js +0 -7
  71. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  72. package/esm/providers/index.d.ts +1 -1
  73. package/esm/providers/index.d.ts.map +1 -1
  74. package/esm/providers/index.js +1 -1
  75. package/esm/providers/index.js.map +1 -1
  76. package/esm/providers/tambo-provider.d.ts +2 -2
  77. package/esm/providers/tambo-provider.d.ts.map +1 -1
  78. package/esm/providers/tambo-provider.js.map +1 -1
  79. package/esm/providers/tambo-stubs.d.ts.map +1 -1
  80. package/esm/providers/tambo-stubs.js +7 -7
  81. package/esm/providers/tambo-stubs.js.map +1 -1
  82. package/esm/providers/tambo-thread-provider.d.ts +29 -11
  83. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  84. package/esm/providers/tambo-thread-provider.js +56 -27
  85. package/esm/providers/tambo-thread-provider.js.map +1 -1
  86. package/esm/util/generate-component.d.ts.map +1 -1
  87. package/esm/util/generate-component.js +6 -2
  88. package/esm/util/generate-component.js.map +1 -1
  89. package/package.json +8 -8
@@ -1 +1 @@
1
- {"version":3,"file":"use-tambo-stream-status.test.js","sourceRoot":"","sources":["../../../src/hooks/__tests__/use-tambo-stream-status.test.tsx"],"names":[],"mappings":";;AAAA,kDAAoD;AACpD,yFAGiD;AACjD,iFAG+C;AAC/C,gEAAgE;AAChE,wEAAkE;AAElE,8BAA8B;AAC9B,IAAI,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxD,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;CAC1B,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC;IACzC,sBAAsB,EAAE,IAAI,CAAC,EAAE,EAAE;CAClC,CAAC,CAAC,CAAC;AAEJ,4BAA4B;AAC5B,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;AAErC,qDAAqD;AACrD,MAAM,mBAAmB,GAAG,CAAC,QAAi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YACX,iCAAiC;YACjC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE7D,sEAAsE;YACtE,IAAI,CAAC,MAAM,CAAC,sCAAc,CAAC,CAAC,eAAe,CAAC;gBAC1C,eAAe,EAAE,6CAAe,CAAC,kBAAkB;aACzB,CAAC,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,4CAAsB,CAAC,CAAC,eAAe,CACjD,iBAAiB,CAAC;gBAChB,EAAE,EAAE,gBAAgB,EAAE,wCAAwC;gBAC9D,SAAS,EAAE,mBAAmB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;aAC9C,CAAC,CACH,CAAC;YACF,QAAQ,EAAE,CAAC;YACX,0BAA0B;YAC1B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport {\n GenerationStage,\n TamboThreadMessage,\n} from \"../../model/generate-component-response\";\nimport {\n TamboThreadContextProps,\n useTamboThread,\n} from \"../../providers/tambo-thread-provider\";\nimport { useTamboCurrentMessage } from \"../use-current-message\";\nimport { useTamboStreamStatus } from \"../use-tambo-stream-status\";\n\n// Mock the required providers\njest.mock(\"../../providers/tambo-thread-provider\", () => ({\n useTamboThread: jest.fn(),\n}));\n\njest.mock(\"../use-current-message\", () => ({\n useTamboCurrentMessage: jest.fn(),\n}));\n\n// Mock window for SSR tests\nconst originalWindow = global.window;\n\n// Helper function to create mock ComponentDecisionV2\nconst createMockComponent = (props: Record<string, unknown> = {}): any => ({\n componentName: \"TestComponent\",\n componentState: {},\n message: \"Component generated\",\n props,\n reasoning: \"Test reasoning\",\n});\n\n// Helper function to create mock TamboThreadMessage\nconst createMockMessage = (\n overrides: Partial<TamboThreadMessage> = {},\n): TamboThreadMessage => ({\n id: \"test-message\",\n componentState: {},\n content: [{ type: \"text\", text: \"test content\" }],\n createdAt: new Date().toISOString(),\n role: \"assistant\",\n threadId: \"test-thread\",\n ...overrides,\n});\n\ndescribe(\"useTamboStreamStatus\", () => {\n beforeEach(() => {\n // Restore window for client-side tests\n global.window = originalWindow;\n\n // Default mock implementations\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.IDLE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue({\n id: \"test-message\",\n component: {\n props: {},\n },\n } as TamboThreadMessage);\n });\n\n afterEach(() => {\n jest.clearAllMocks();\n });\n\n describe(\"Initial State\", () => {\n it(\"should start with all flags as pending when idle and no props\", () => {\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.IDLE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\" }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n expect(result.current.streamStatus).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n isError: false,\n streamError: undefined,\n });\n\n expect(result.current.propStatus.title).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n error: undefined,\n });\n\n expect(result.current.propStatus.body).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n error: undefined,\n });\n });\n });\n\n describe(\"Generation vs Props Streaming\", () => {\n it(\"should show generation streaming but props still pending when STREAMING_RESPONSE with no prop content\", () => {\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\" }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Global streaming should be false because no props are actually streaming yet\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isPending).toBe(false);\n\n // Individual props should be pending because they haven't started streaming yet\n expect(result.current.propStatus.title.isPending).toBe(true);\n expect(result.current.propStatus.title.isStreaming).toBe(false);\n expect(result.current.propStatus.body.isPending).toBe(true);\n expect(result.current.propStatus.body.isStreaming).toBe(false);\n });\n\n it(\"should show prop streaming when props receive content during STREAMING_RESPONSE\", () => {\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"Hello\", body: \"\" }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Title prop should be streaming since it has content\n expect(result.current.propStatus.title.isStreaming).toBe(true);\n expect(result.current.propStatus.title.isPending).toBe(false);\n\n // Body prop should still be pending since it has no content\n expect(result.current.propStatus.body.isStreaming).toBe(false);\n expect(result.current.propStatus.body.isPending).toBe(true);\n\n // Global should be streaming because at least one prop is streaming\n expect(result.current.streamStatus.isStreaming).toBe(true);\n });\n });\n\n describe(\"Boolean Lifecycle\", () => {\n it(\"should transition through Init -> Streaming -> Success lifecycle\", () => {\n // Start with IDLE (Init phase)\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.IDLE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\" }),\n }),\n );\n\n const { result, rerender } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Phase 1: Init - isPending = true\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n\n // Phase 2: Streaming - move to STREAMING_RESPONSE with content\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Hello World\",\n body: \"Some content\",\n }),\n }),\n );\n\n rerender();\n\n expect(result.current.streamStatus.isPending).toBe(false);\n expect(result.current.streamStatus.isStreaming).toBe(true);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n\n // Phase 3: Complete - move to COMPLETE\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n } as TamboThreadContextProps);\n\n rerender();\n\n expect(result.current.streamStatus.isPending).toBe(false);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(true);\n });\n\n it(\"should handle error state correctly\", () => {\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.ERROR,\n } as TamboThreadContextProps);\n\n const errorMessage = \"Generation failed\";\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\" }),\n error: errorMessage,\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n expect(result.current.streamStatus.isError).toBe(true);\n expect(result.current.streamStatus.streamError?.message).toBe(\n errorMessage,\n );\n });\n });\n\n describe(\"Derivation Rules\", () => {\n it(\"should derive isPending correctly (no generation activity AND all props pending)\", () => {\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.IDLE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\", footer: \"\" }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{\n title: string;\n body: string;\n footer: string;\n }>(),\n );\n\n // All props are pending and no generation activity\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus.title.isPending).toBe(true);\n expect(result.current.propStatus.body.isPending).toBe(true);\n expect(result.current.propStatus.footer.isPending).toBe(true);\n });\n\n it(\"should derive isStreaming correctly (generation streaming OR any prop streaming)\", () => {\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n } as TamboThreadContextProps);\n\n // One prop still streaming\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Complete Title\",\n body: \"Still streaming...\",\n }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Should be streaming because at least one prop is streaming\n expect(result.current.streamStatus.isStreaming).toBe(false); // Note: this will be false in our implementation because props are considered complete when generation is COMPLETE\n });\n\n it(\"should derive isSuccess correctly (generation complete AND all props successful)\", () => {\n // Step 1: Start with streaming, props empty\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"\",\n body: \"\",\n }),\n }),\n );\n\n const { result, rerender } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Step 2: Simulate streaming in title\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Complete Title\",\n body: \"\",\n }),\n }),\n );\n rerender();\n\n // Step 3: Simulate streaming in body\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Complete Title\",\n body: \"Complete Body\",\n }),\n }),\n );\n rerender();\n\n // Step 4: Generation complete\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n } as TamboThreadContextProps);\n rerender();\n\n // Now both props should be successful\n expect(result.current.propStatus.title.isSuccess).toBe(true);\n expect(result.current.propStatus.body.isSuccess).toBe(true);\n expect(result.current.streamStatus.isSuccess).toBe(true);\n });\n\n it(\"should derive isError correctly (generation error OR any prop error)\", () => {\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n } as TamboThreadContextProps);\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Good Title\",\n body: \"Good Body\",\n }),\n error: \"Something went wrong\",\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n expect(result.current.streamStatus.isError).toBe(true);\n expect(result.current.streamStatus.streamError?.message).toBe(\n \"Something went wrong\",\n );\n });\n });\n\n describe(\"Type Safety\", () => {\n it(\"should provide strongly typed prop status based on generic\", () => {\n interface TestProps {\n title: string;\n description: string;\n count: number;\n }\n\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Test\",\n description: \"Test desc\",\n count: 42,\n }),\n }),\n );\n\n const { result } = renderHook(() => useTamboStreamStatus<TestProps>());\n\n // TypeScript should infer these keys correctly\n expect(result.current.propStatus.title).toBeDefined();\n expect(result.current.propStatus.description).toBeDefined();\n expect(result.current.propStatus.count).toBeDefined();\n\n // This would cause a TypeScript error if uncommented:\n // expect(result.current.propStatus.nonExistentProp).toBeDefined();\n });\n\n it(\"should work without generic type parameter\", () => {\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ dynamicProp: \"value\" }),\n }),\n );\n\n const { result } = renderHook(() => useTamboStreamStatus());\n\n expect(result.current.streamStatus).toBeDefined();\n expect(result.current.propStatus).toBeDefined();\n });\n });\n\n describe(\"Edge Cases\", () => {\n it(\"should handle missing message gracefully\", () => {\n jest.mocked(useTamboCurrentMessage).mockReturnValue(undefined);\n\n const { result } = renderHook(() => useTamboStreamStatus());\n\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus).toEqual({});\n });\n\n it(\"should handle missing component props gracefully\", () => {\n jest.mocked(useTamboCurrentMessage).mockReturnValue({\n id: \"test-message\",\n // Missing component property\n } as TamboThreadMessage);\n\n const { result } = renderHook(() => useTamboStreamStatus());\n\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus).toEqual({});\n });\n\n it(\"should reset prop tracking when generation restarts\", () => {\n // Step 1: Complete a message\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n } as TamboThreadContextProps);\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\" }),\n }),\n );\n const { result, rerender } = renderHook(() =>\n useTamboStreamStatus<{ title: string }>(),\n );\n // Simulate streaming in title\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"First Title\" }),\n }),\n );\n rerender();\n // Complete generation\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n } as TamboThreadContextProps);\n rerender();\n // Should be successful initially\n expect(result.current.propStatus.title.isSuccess).toBe(true);\n\n // Step 2: Start new generation with a new message ID to trigger reset\n jest.mocked(useTamboThread).mockReturnValue({\n generationStage: GenerationStage.CHOOSING_COMPONENT,\n } as TamboThreadContextProps);\n jest.mocked(useTamboCurrentMessage).mockReturnValue(\n createMockMessage({\n id: \"new-message-id\", // Different message ID to trigger reset\n component: createMockComponent({ title: \"\" }),\n }),\n );\n rerender();\n // Should reset to pending\n expect(result.current.propStatus.title.isPending).toBe(true);\n expect(result.current.propStatus.title.isSuccess).toBe(false);\n });\n });\n});\n"]}
1
+ {"version":3,"file":"use-tambo-stream-status.test.js","sourceRoot":"","sources":["../../../src/hooks/__tests__/use-tambo-stream-status.test.tsx"],"names":[],"mappings":";;AAAA,kDAAoD;AACpD,yFAGiD;AACjD,wEAAkE;AAElE,8BAA8B;AAC9B,IAAI,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxD,uBAAuB,EAAE,IAAI,CAAC,EAAE,EAAE;CACnC,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC;IACzC,sBAAsB,EAAE,IAAI,CAAC,EAAE,EAAE;CAClC,CAAC,CAAC,CAAC;AAEJ,8BAA8B;AAC9B,iFAAgF;AAChF,gEAAgE;AAEhE,4BAA4B;AAC5B,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;AAErC,qDAAqD;AACrD,MAAM,mBAAmB,GAAG,CAAC,QAAiC,EAAE,EAAO,EAAE,CAAC,CAAC;IACzE,aAAa,EAAE,eAAe;IAC9B,cAAc,EAAE,EAAE;IAClB,OAAO,EAAE,qBAAqB;IAC9B,KAAK;IACL,SAAS,EAAE,gBAAgB;CAC5B,CAAC,CAAC;AAEH,oDAAoD;AACpD,MAAM,iBAAiB,GAAG,CACxB,YAAyC,EAAE,EACvB,EAAE,CAAC,CAAC;IACxB,EAAE,EAAE,cAAc;IAClB,cAAc,EAAE,EAAE;IAClB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IACjD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;IACnC,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,aAAa;IACvB,GAAG,SAAS;CACb,CAAC,CAAC;AAEH,2BAA2B;AAC3B,MAAM,2BAA2B,GAAG,IAAI,CAAC,MAAM,CAAC,+CAAuB,CAAC,CAAC;AACzE,MAAM,0BAA0B,GAAG,IAAI,CAAC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AC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport {\n GenerationStage,\n TamboThreadMessage,\n} from \"../../model/generate-component-response\";\nimport { useTamboStreamStatus } from \"../use-tambo-stream-status\";\n\n// Mock the required providers\njest.mock(\"../../providers/tambo-thread-provider\", () => ({\n useTamboGenerationStage: jest.fn(),\n}));\n\njest.mock(\"../use-current-message\", () => ({\n useTamboCurrentMessage: jest.fn(),\n}));\n\n// Import the mocked functions\nimport { useTamboGenerationStage } from \"../../providers/tambo-thread-provider\";\nimport { useTamboCurrentMessage } from \"../use-current-message\";\n\n// Mock window for SSR tests\nconst originalWindow = global.window;\n\n// Helper function to create mock ComponentDecisionV2\nconst createMockComponent = (props: Record<string, unknown> = {}): any => ({\n componentName: \"TestComponent\",\n componentState: {},\n message: \"Component generated\",\n props,\n reasoning: \"Test reasoning\",\n});\n\n// Helper function to create mock TamboThreadMessage\nconst createMockMessage = (\n overrides: Partial<TamboThreadMessage> = {},\n): TamboThreadMessage => ({\n id: \"test-message\",\n componentState: {},\n content: [{ type: \"text\", text: \"test content\" }],\n createdAt: new Date().toISOString(),\n role: \"assistant\",\n threadId: \"test-thread\",\n ...overrides,\n});\n\n// Get the mocked functions\nconst mockUseTamboGenerationStage = jest.mocked(useTamboGenerationStage);\nconst mockUseTamboCurrentMessage = jest.mocked(useTamboCurrentMessage);\n\ndescribe(\"useTamboStreamStatus\", () => {\n beforeEach(() => {\n // Restore window for client-side tests\n global.window = originalWindow;\n\n // Default mock implementations\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.IDLE,\n generationStatusMessage: \"\",\n isIdle: true,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue({\n id: \"test-message\",\n component: {\n props: {},\n },\n } as TamboThreadMessage);\n });\n\n afterEach(() => {\n jest.clearAllMocks();\n });\n\n describe(\"Initial State\", () => {\n it(\"should start with all flags as pending when idle and no props\", () => {\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.IDLE,\n generationStatusMessage: \"\",\n isIdle: true,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\" }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n expect(result.current.streamStatus).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n isError: false,\n streamError: undefined,\n });\n\n expect(result.current.propStatus.title).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n error: undefined,\n });\n\n expect(result.current.propStatus.body).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n error: undefined,\n });\n });\n });\n\n describe(\"Generation vs Props Streaming\", () => {\n it(\"should show generation streaming but props still pending when STREAMING_RESPONSE with no prop content\", () => {\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\" }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Global streaming should be false because no props are actually streaming yet\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isPending).toBe(false);\n\n // Individual props should be pending because they haven't started streaming yet\n expect(result.current.propStatus.title.isPending).toBe(true);\n expect(result.current.propStatus.title.isStreaming).toBe(false);\n expect(result.current.propStatus.body.isPending).toBe(true);\n expect(result.current.propStatus.body.isStreaming).toBe(false);\n });\n\n it(\"should show prop streaming when props receive content during STREAMING_RESPONSE\", () => {\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"Hello\", body: \"\" }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Title prop should be streaming since it has content\n expect(result.current.propStatus.title.isStreaming).toBe(true);\n expect(result.current.propStatus.title.isPending).toBe(false);\n\n // Body prop should still be pending since it has no content\n expect(result.current.propStatus.body.isStreaming).toBe(false);\n expect(result.current.propStatus.body.isPending).toBe(true);\n\n // Global should be streaming because at least one prop is streaming\n expect(result.current.streamStatus.isStreaming).toBe(true);\n });\n });\n\n describe(\"Boolean Lifecycle\", () => {\n it(\"should transition through Init -> Streaming -> Success lifecycle\", () => {\n // Start with IDLE (Init phase)\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.IDLE,\n generationStatusMessage: \"\",\n isIdle: true,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\" }),\n }),\n );\n\n const { result, rerender } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Phase 1: Init - isPending = true\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n\n // Phase 2: Streaming - move to STREAMING_RESPONSE with content\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Hello World\",\n body: \"Some content\",\n }),\n }),\n );\n\n rerender();\n\n expect(result.current.streamStatus.isPending).toBe(false);\n expect(result.current.streamStatus.isStreaming).toBe(true);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n\n // Phase 3: Complete - move to COMPLETE\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n\n rerender();\n\n expect(result.current.streamStatus.isPending).toBe(false);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(true);\n });\n\n it(\"should handle error state correctly\", () => {\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.ERROR,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n\n const errorMessage = \"Generation failed\";\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\" }),\n error: errorMessage,\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n expect(result.current.streamStatus.isError).toBe(true);\n expect(result.current.streamStatus.streamError?.message).toBe(\n errorMessage,\n );\n });\n });\n\n describe(\"Derivation Rules\", () => {\n it(\"should derive isPending correctly (no generation activity AND all props pending)\", () => {\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.IDLE,\n generationStatusMessage: \"\",\n isIdle: true,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\", body: \"\", footer: \"\" }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{\n title: string;\n body: string;\n footer: string;\n }>(),\n );\n\n // All props are pending and no generation activity\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus.title.isPending).toBe(true);\n expect(result.current.propStatus.body.isPending).toBe(true);\n expect(result.current.propStatus.footer.isPending).toBe(true);\n });\n\n it(\"should derive isStreaming correctly (generation streaming OR any prop streaming)\", () => {\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n\n // One prop still streaming\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Complete Title\",\n body: \"Still streaming...\",\n }),\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Should be streaming because at least one prop is streaming\n expect(result.current.streamStatus.isStreaming).toBe(false); // Note: this will be false in our implementation because props are considered complete when generation is COMPLETE\n });\n\n it(\"should derive isSuccess correctly (generation complete AND all props successful)\", () => {\n // Step 1: Start with streaming, props empty\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"\",\n body: \"\",\n }),\n }),\n );\n\n const { result, rerender } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n // Step 2: Simulate streaming in title\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Complete Title\",\n body: \"\",\n }),\n }),\n );\n rerender();\n\n // Step 3: Simulate streaming in body\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Complete Title\",\n body: \"Complete Body\",\n }),\n }),\n );\n rerender();\n\n // Step 4: Generation complete\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n rerender();\n\n // Now both props should be successful\n expect(result.current.propStatus.title.isSuccess).toBe(true);\n expect(result.current.propStatus.body.isSuccess).toBe(true);\n expect(result.current.streamStatus.isSuccess).toBe(true);\n });\n\n it(\"should derive isError correctly (generation error OR any prop error)\", () => {\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Good Title\",\n body: \"Good Body\",\n }),\n error: \"Something went wrong\",\n }),\n );\n\n const { result } = renderHook(() =>\n useTamboStreamStatus<{ title: string; body: string }>(),\n );\n\n expect(result.current.streamStatus.isError).toBe(true);\n expect(result.current.streamStatus.streamError?.message).toBe(\n \"Something went wrong\",\n );\n });\n });\n\n describe(\"Type Safety\", () => {\n it(\"should provide strongly typed prop status based on generic\", () => {\n interface TestProps {\n title: string;\n description: string;\n count: number;\n }\n\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({\n title: \"Test\",\n description: \"Test desc\",\n count: 42,\n }),\n }),\n );\n\n const { result } = renderHook(() => useTamboStreamStatus<TestProps>());\n\n // TypeScript should infer these keys correctly\n expect(result.current.propStatus.title).toBeDefined();\n expect(result.current.propStatus.description).toBeDefined();\n expect(result.current.propStatus.count).toBeDefined();\n\n // This would cause a TypeScript error if uncommented:\n // expect(result.current.propStatus.nonExistentProp).toBeDefined();\n });\n\n it(\"should work without generic type parameter\", () => {\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ dynamicProp: \"value\" }),\n }),\n );\n\n const { result } = renderHook(() => useTamboStreamStatus());\n\n expect(result.current.streamStatus).toBeDefined();\n expect(result.current.propStatus).toBeDefined();\n });\n });\n\n describe(\"Edge Cases\", () => {\n it(\"should handle missing message gracefully\", () => {\n mockUseTamboCurrentMessage.mockReturnValue({\n id: \"test-message\",\n role: \"user\",\n content: [],\n componentState: {},\n createdAt: \"\",\n threadId: \"\",\n } as TamboThreadMessage);\n\n const { result } = renderHook(() => useTamboStreamStatus());\n\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus).toEqual({});\n });\n\n it(\"should handle missing component props gracefully\", () => {\n mockUseTamboCurrentMessage.mockReturnValue({\n id: \"test-message\",\n // Missing component property\n } as TamboThreadMessage);\n\n const { result } = renderHook(() => useTamboStreamStatus());\n\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus).toEqual({});\n });\n\n it(\"should reset prop tracking when generation restarts\", () => {\n // Step 1: Complete a message\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.STREAMING_RESPONSE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"\" }),\n }),\n );\n const { result, rerender } = renderHook(() =>\n useTamboStreamStatus<{ title: string }>(),\n );\n // Simulate streaming in title\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n component: createMockComponent({ title: \"First Title\" }),\n }),\n );\n rerender();\n // Complete generation\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.COMPLETE,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n rerender();\n // Should be successful initially\n expect(result.current.propStatus.title.isSuccess).toBe(true);\n\n // Step 2: Start new generation with a new message ID to trigger reset\n mockUseTamboGenerationStage.mockReturnValue({\n generationStage: GenerationStage.CHOOSING_COMPONENT,\n generationStatusMessage: \"\",\n isIdle: false,\n });\n mockUseTamboCurrentMessage.mockReturnValue(\n createMockMessage({\n id: \"new-message-id\", // Different message ID to trigger reset\n component: createMockComponent({ title: \"\" }),\n }),\n );\n rerender();\n // Should reset to pending\n expect(result.current.propStatus.title.isPending).toBe(true);\n expect(result.current.propStatus.title.isSuccess).toBe(false);\n });\n });\n});\n"]}
@@ -1,9 +1,9 @@
1
1
  export * from "./react-query-hooks";
2
2
  export { useTamboComponentState } from "./use-component-state";
3
- export { useTamboCurrentMessage, useTamboMessageContext, } from "./use-current-message";
3
+ export { useTamboCurrentMessage } from "./use-current-message";
4
4
  export { useTamboStreamingProps } from "./use-streaming-props";
5
- export { useTamboStreamStatus, type StreamStatus, type PropStatus, } from "./use-tambo-stream-status";
6
5
  export * from "./use-suggestions";
6
+ export { useTamboStreamStatus, type PropStatus, type StreamStatus, } from "./use-tambo-stream-status";
7
7
  export { useTamboThreadList } from "./use-tambo-threads";
8
8
  export { useTamboThreadInput } from "./use-thread-input";
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EACL,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,UAAU,GAChB,MAAM,2BAA2B,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -14,19 +14,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.useTamboThreadInput = exports.useTamboThreadList = exports.useTamboStreamStatus = exports.useTamboStreamingProps = exports.useTamboMessageContext = exports.useTamboCurrentMessage = exports.useTamboComponentState = void 0;
17
+ exports.useTamboThreadInput = exports.useTamboThreadList = exports.useTamboStreamStatus = exports.useTamboStreamingProps = exports.useTamboCurrentMessage = exports.useTamboComponentState = void 0;
18
18
  // Export all hooks from this directory
19
19
  __exportStar(require("./react-query-hooks"), exports);
20
20
  var use_component_state_1 = require("./use-component-state");
21
21
  Object.defineProperty(exports, "useTamboComponentState", { enumerable: true, get: function () { return use_component_state_1.useTamboComponentState; } });
22
22
  var use_current_message_1 = require("./use-current-message");
23
23
  Object.defineProperty(exports, "useTamboCurrentMessage", { enumerable: true, get: function () { return use_current_message_1.useTamboCurrentMessage; } });
24
- Object.defineProperty(exports, "useTamboMessageContext", { enumerable: true, get: function () { return use_current_message_1.useTamboMessageContext; } });
25
24
  var use_streaming_props_1 = require("./use-streaming-props");
26
25
  Object.defineProperty(exports, "useTamboStreamingProps", { enumerable: true, get: function () { return use_streaming_props_1.useTamboStreamingProps; } });
26
+ __exportStar(require("./use-suggestions"), exports);
27
27
  var use_tambo_stream_status_1 = require("./use-tambo-stream-status");
28
28
  Object.defineProperty(exports, "useTamboStreamStatus", { enumerable: true, get: function () { return use_tambo_stream_status_1.useTamboStreamStatus; } });
29
- __exportStar(require("./use-suggestions"), exports);
30
29
  var use_tambo_threads_1 = require("./use-tambo-threads");
31
30
  Object.defineProperty(exports, "useTamboThreadList", { enumerable: true, get: function () { return use_tambo_threads_1.useTamboThreadList; } });
32
31
  var use_thread_input_1 = require("./use-thread-input");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAuC;AACvC,sDAAoC;AACpC,6DAA+D;AAAtD,6HAAA,sBAAsB,OAAA;AAC/B,6DAG+B;AAF7B,6HAAA,sBAAsB,OAAA;AACtB,6HAAA,sBAAsB,OAAA;AAExB,6DAA+D;AAAtD,6HAAA,sBAAsB,OAAA;AAC/B,qEAImC;AAHjC,+HAAA,oBAAoB,OAAA;AAItB,oDAAkC;AAClC,yDAAyD;AAAhD,uHAAA,kBAAkB,OAAA;AAC3B,uDAAyD;AAAhD,uHAAA,mBAAmB,OAAA","sourcesContent":["// Export all hooks from this directory\nexport * from \"./react-query-hooks\";\nexport { useTamboComponentState } from \"./use-component-state\";\nexport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\nexport { useTamboStreamingProps } from \"./use-streaming-props\";\nexport {\n useTamboStreamStatus,\n type StreamStatus,\n type PropStatus,\n} from \"./use-tambo-stream-status\";\nexport * from \"./use-suggestions\";\nexport { useTamboThreadList } from \"./use-tambo-threads\";\nexport { useTamboThreadInput } from \"./use-thread-input\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAuC;AACvC,sDAAoC;AACpC,6DAA+D;AAAtD,6HAAA,sBAAsB,OAAA;AAC/B,6DAA+D;AAAtD,6HAAA,sBAAsB,OAAA;AAC/B,6DAA+D;AAAtD,6HAAA,sBAAsB,OAAA;AAC/B,oDAAkC;AAClC,qEAImC;AAHjC,+HAAA,oBAAoB,OAAA;AAItB,yDAAyD;AAAhD,uHAAA,kBAAkB,OAAA;AAC3B,uDAAyD;AAAhD,uHAAA,mBAAmB,OAAA","sourcesContent":["// Export all hooks from this directory\nexport * from \"./react-query-hooks\";\nexport { useTamboComponentState } from \"./use-component-state\";\nexport { useTamboCurrentMessage } from \"./use-current-message\";\nexport { useTamboStreamingProps } from \"./use-streaming-props\";\nexport * from \"./use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./use-tambo-stream-status\";\nexport { useTamboThreadList } from \"./use-tambo-threads\";\nexport { useTamboThreadInput } from \"./use-thread-input\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AASA,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAC1B,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI;IAC/B,IAAI,EAAE,kBAAkB;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AACpC,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AAMA,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAC1B,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI;IAC/B,IAAI,EAAE,kBAAkB;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AACpC,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
@@ -7,10 +7,10 @@ const use_debounce_1 = require("use-debounce");
7
7
  const providers_1 = require("../providers");
8
8
  const use_current_message_1 = require("./use-current-message");
9
9
  function useTamboComponentState(keyName, initialValue, debounceTime = 500) {
10
- const { messageId } = (0, use_current_message_1.useTamboMessageContext)();
10
+ const message = (0, use_current_message_1.useTamboCurrentMessage)();
11
11
  const { updateThreadMessage, thread } = (0, providers_1.useTamboThread)();
12
12
  const client = (0, providers_1.useTamboClient)();
13
- const message = (0, use_current_message_1.useTamboCurrentMessage)();
13
+ const messageId = message.id;
14
14
  const threadId = thread.id;
15
15
  // Initial value management
16
16
  const [cachedInitialValue] = (0, react_1.useState)(() => initialValue);
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AA2Db,wDA2KC;AArOD,iCAAyD;AACzD,+CAAoD;AACpD,4CAA8D;AAC9D,+DAG+B;AAoD/B,SAAgB,sBAAsB,CACpC,OAAe,EACf,YAAgB,EAChB,YAAY,GAAG,GAAG;IAElB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,4CAAsB,GAAE,CAAC;IAC/C,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,GAAG,IAAA,0BAAc,GAAE,CAAC;IACzD,MAAM,MAAM,GAAG,IAAA,0BAAc,GAAE,CAAC;IAChC,MAAM,OAAO,GAAG,IAAA,4CAAsB,GAAE,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;IAE3B,2BAA2B;IAC3B,MAAM,CAAC,kBAAkB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AAS,CAAC,CACzE,CAAC;IAEF,gDAAgD;IAChD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,oBAAoB,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAE3B,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\n\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 500,\n): StateUpdateResult<S> {\n const { messageId } = useTamboMessageContext();\n const { updateThreadMessage, thread } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n const threadId = thread.id;\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // Only update local state if we haven't had any user changes yet\n if (lastUserValue === null) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one and no user changes\n else if (\n cachedInitialValue !== undefined &&\n !localState &&\n lastUserValue === null\n ) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedServerWrite = useDebouncedCallback(async (newValue: S) => {\n setIsPending(true);\n try {\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n );\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedServerWrite(newValue);\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n updateThreadMessage(messageId, messageUpdate, false);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n }\n },\n [message, debouncedServerWrite, keyName, updateThreadMessage, messageId],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedServerWrite.flush();\n };\n }, [debouncedServerWrite]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
1
+ {"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAwDb,wDA2KC;AAlOD,iCAAyD;AACzD,+CAAoD;AACpD,4CAA8D;AAC9D,+DAA+D;AAoD/D,SAAgB,sBAAsB,CACpC,OAAe,EACf,YAAgB,EAChB,YAAY,GAAG,GAAG;IAElB,MAAM,OAAO,GAAG,IAA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AO,CAAC,EAAE,QAAQ;iBACpB;aACF,CAAC;YAEF,mBAAmB,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CACV,4CAA4C,SAAS,cAAc,OAAO,GAAG,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC,EACD,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,mBAAmB,EAAE,SAAS,CAAC,CACzE,CAAC;IAEF,gDAAgD;IAChD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,oBAAoB,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAE3B,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport { useTamboCurrentMessage } from \"./use-current-message\";\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\n\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 500,\n): StateUpdateResult<S> {\n const message = useTamboCurrentMessage();\n const { updateThreadMessage, thread } = useTamboThread();\n const client = useTamboClient();\n const messageId = message.id;\n const threadId = thread.id;\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // Only update local state if we haven't had any user changes yet\n if (lastUserValue === null) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one and no user changes\n else if (\n cachedInitialValue !== undefined &&\n !localState &&\n lastUserValue === null\n ) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedServerWrite = useDebouncedCallback(async (newValue: S) => {\n setIsPending(true);\n try {\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n );\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedServerWrite(newValue);\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n updateThreadMessage(messageId, messageUpdate, false);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n }\n },\n [message, debouncedServerWrite, keyName, updateThreadMessage, messageId],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedServerWrite.flush();\n };\n }, [debouncedServerWrite]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
@@ -1,42 +1,27 @@
1
1
  import React, { PropsWithChildren } from "react";
2
- interface TamboMessageContextProps {
3
- /**
4
- * The threadId of the thread
5
- * @deprecated Use the thread object from the TamboThreadProvider instead
6
- */
7
- threadId?: string;
8
- /** The messageId of the message */
9
- messageId: string;
10
- }
2
+ import { TamboThreadMessage } from "../model/generate-component-response";
11
3
  /**
12
- * Wraps all components, so that they can find what thread and message they are in
4
+ * Wraps all components, so that they can find what message they are in
13
5
  * @param props - props for the TamboMessageProvider
14
6
  * @param props.children - The children to wrap
15
- * @param props.messageId - The messageId of the message
7
+ * @param props.message - The message object
16
8
  * @returns The wrapped component
17
9
  */
18
- export declare const TamboMessageProvider: React.FC<PropsWithChildren<TamboMessageContextProps>>;
10
+ export declare const TamboMessageProvider: React.FC<PropsWithChildren<{
11
+ message: TamboThreadMessage;
12
+ }>>;
19
13
  /**
20
- * Wraps a component with a ComponentMessageProvider - this allows the provider
14
+ * Wraps a component with a TamboMessageProvider - this allows the provider
21
15
  * to be used outside of a TSX file
22
16
  * @param children - The children to wrap
23
- * @param threadId - The threadId of the thread
24
- * @param messageId - The messageId of the message
17
+ * @param message - The message object
25
18
  * @returns The wrapped component
26
19
  */
27
- export declare function wrapWithTamboMessageProvider(children: React.ReactNode, threadId: string, messageId: string): React.JSX.Element;
20
+ export declare function wrapWithTamboMessageProvider(children: React.ReactNode, message: TamboThreadMessage): React.JSX.Element;
28
21
  /**
29
- * Hook used inside a component wrapped with ComponentMessageProvider, to get
30
- * the threadId and messageId
31
- * @returns The threadId and messageId
32
- */
33
- export declare const useTamboMessageContext: () => TamboMessageContextProps;
34
- /**
35
- * Hook used inside a component wrapped with ComponentMessageProvider, to get
36
- * the current message. The current thread will be fetched from the server, if
37
- * it is not already in the cache.
22
+ * Hook used inside a component wrapped with TamboMessageProvider, to get
23
+ * the current message.
38
24
  * @returns The current message that is used to render the component
39
25
  */
40
- export declare const useTamboCurrentMessage: () => import("..").TamboThreadMessage | undefined;
41
- export {};
26
+ export declare const useTamboCurrentMessage: () => TamboThreadMessage;
42
27
  //# sourceMappingURL=use-current-message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAG5E,UAAU,wBAAwB;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC,wBAAwB,CAAC,CAU5C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,qBAOlB;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,gCAQlC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,mDASlC,CAAC"}
1
+ {"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAI1E;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAUnD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,OAAO,EAAE,kBAAkB,qBAK5B;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,0BAQlC,CAAC"}
@@ -34,64 +34,44 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  };
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.useTamboCurrentMessage = exports.useTamboMessageContext = exports.TamboMessageProvider = void 0;
37
+ exports.useTamboCurrentMessage = exports.TamboMessageProvider = void 0;
38
38
  exports.wrapWithTamboMessageProvider = wrapWithTamboMessageProvider;
39
39
  const react_1 = __importStar(require("react"));
40
- const providers_1 = require("../providers");
41
- const TamboMessageContext = (0, react_1.createContext)({
42
- messageId: "",
43
- });
40
+ const TamboMessageContext = (0, react_1.createContext)(null);
44
41
  /**
45
- * Wraps all components, so that they can find what thread and message they are in
42
+ * Wraps all components, so that they can find what message they are in
46
43
  * @param props - props for the TamboMessageProvider
47
44
  * @param props.children - The children to wrap
48
- * @param props.messageId - The messageId of the message
45
+ * @param props.message - The message object
49
46
  * @returns The wrapped component
50
47
  */
51
- const TamboMessageProvider = ({ children, messageId }) => {
52
- // Use a unique key={...} to force a re-render when the messageId changes - this
48
+ const TamboMessageProvider = ({ children, message }) => {
49
+ // Use a unique key={...} to force a re-render when the message changes - this
53
50
  // make sure that if the rendered component is swapped into a tree (like if
54
51
  // you always show the last rendered component) then the state/etc is correct
55
- return (react_1.default.createElement(TamboMessageContext.Provider, { value: { messageId }, key: messageId }, children));
52
+ return (react_1.default.createElement(TamboMessageContext.Provider, { value: message, key: message.id }, children));
56
53
  };
57
54
  exports.TamboMessageProvider = TamboMessageProvider;
58
55
  /**
59
- * Wraps a component with a ComponentMessageProvider - this allows the provider
56
+ * Wraps a component with a TamboMessageProvider - this allows the provider
60
57
  * to be used outside of a TSX file
61
58
  * @param children - The children to wrap
62
- * @param threadId - The threadId of the thread
63
- * @param messageId - The messageId of the message
59
+ * @param message - The message object
64
60
  * @returns The wrapped component
65
61
  */
66
- function wrapWithTamboMessageProvider(children, threadId, messageId) {
67
- return (react_1.default.createElement(exports.TamboMessageProvider, { threadId: threadId, messageId: messageId }, children));
62
+ function wrapWithTamboMessageProvider(children, message) {
63
+ return (react_1.default.createElement(exports.TamboMessageProvider, { message: message }, children));
68
64
  }
69
65
  /**
70
- * Hook used inside a component wrapped with ComponentMessageProvider, to get
71
- * the threadId and messageId
72
- * @returns The threadId and messageId
73
- */
74
- const useTamboMessageContext = () => {
75
- const context = (0, react_1.useContext)(TamboMessageContext);
76
- if (!context) {
77
- throw new Error("useTamboMessageContext must be used within a TamboMessageProvider");
78
- }
79
- return context;
80
- };
81
- exports.useTamboMessageContext = useTamboMessageContext;
82
- /**
83
- * Hook used inside a component wrapped with ComponentMessageProvider, to get
84
- * the current message. The current thread will be fetched from the server, if
85
- * it is not already in the cache.
66
+ * Hook used inside a component wrapped with TamboMessageProvider, to get
67
+ * the current message.
86
68
  * @returns The current message that is used to render the component
87
69
  */
88
70
  const useTamboCurrentMessage = () => {
89
- const { messageId, threadId } = (0, exports.useTamboMessageContext)();
90
- const { thread } = (0, providers_1.useTamboThread)();
91
- if (thread.id && threadId && thread.id !== threadId) {
92
- console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);
71
+ const message = (0, react_1.useContext)(TamboMessageContext);
72
+ if (!message) {
73
+ throw new Error("useTamboCurrentMessage must be used within a TamboMessageProvider");
93
74
  }
94
- const message = thread.messages.find((m) => m.id === messageId);
95
75
  return message;
96
76
  };
97
77
  exports.useTamboCurrentMessage = useTamboCurrentMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Cb,oEAUC;AAvDD,+CAA4E;AAC5E,4CAA8C;AAY9C,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAA2B;IAClE,SAAS,EAAE,EAAE;CACd,CAAC,CAAC;AAEH;;;;;;GAMG;AACI,MAAM,oBAAoB,GAE7B,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IAC9B,gF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E,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,sBAAsB,0BASjC","sourcesContent":["\"use client\";\nimport React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { useTamboThread } from \"../providers\";\n\ninterface TamboMessageContextProps {\n /**\n * The threadId of the thread\n * @deprecated Use the thread object from the TamboThreadProvider instead\n */\n threadId?: string;\n /** The messageId of the message */\n messageId: string;\n}\n\nconst TamboMessageContext = createContext<TamboMessageContextProps>({\n messageId: \"\",\n});\n\n/**\n * Wraps all components, so that they can find what thread and message they are in\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<TamboMessageContextProps>\n> = ({ children, messageId }) => {\n // Use a unique key={...} to force a re-render when the messageId changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider value={{ messageId }} key={messageId}>\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a ComponentMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param threadId - The threadId of the thread\n * @param messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n threadId: string,\n messageId: string,\n) {\n return (\n <TamboMessageProvider threadId={threadId} messageId={messageId}>\n {children}\n </TamboMessageProvider>\n );\n}\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the threadId and messageId\n * @returns The threadId and messageId\n */\nexport const useTamboMessageContext = () => {\n const context = useContext(TamboMessageContext);\n if (!context) {\n throw new Error(\n \"useTamboMessageContext must be used within a TamboMessageProvider\",\n );\n }\n return context;\n};\n\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the current message. The current thread will be fetched from the server, if\n * it is not already in the cache.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const { messageId, threadId } = useTamboMessageContext();\n const { thread } = useTamboThread();\n if (thread.id && threadId && thread.id !== threadId) {\n console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);\n }\n\n const message = thread.messages.find((m) => m.id === messageId);\n return message;\n};\n"]}
1
+ {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCb,oEAOC;AAvCD,+CAA4E;AAG5E,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAA4B,IAAI,CAAC,CAAC;AAE3E;;;;;;GAMG;AACI,MAAM,oBAAoB,GAE7B,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;IAC5B,8EAA8E;IAC9E,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,8BAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,IAC1D,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,oBAAoB,wBAW/B;AAEF;;;;;;GAMG;AACH,SAAgB,4BAA4B,CAC1C,QAAyB,EACzB,OAA2B;IAE3B,OAAO,CACL,8BAAC,4BAAoB,IAAC,OAAO,EAAE,OAAO,IAAG,QAAQ,CAAwB,CAC1E,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,mBAAmB,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC","sourcesContent":["\"use client\";\nimport React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { TamboThreadMessage } from \"../model/generate-component-response\";\n\nconst TamboMessageContext = createContext<TamboThreadMessage | null>(null);\n\n/**\n * Wraps all components, so that they can find what message they are in\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.message - The message object\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<{ message: TamboThreadMessage }>\n> = ({ children, message }) => {\n // Use a unique key={...} to force a re-render when the message changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider value={message} key={message.id}>\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a TamboMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param message - The message object\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n message: TamboThreadMessage,\n) {\n return (\n <TamboMessageProvider message={message}>{children}</TamboMessageProvider>\n );\n}\n\n/**\n * Hook used inside a component wrapped with TamboMessageProvider, to get\n * the current message.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const message = useContext(TamboMessageContext);\n if (!message) {\n throw new Error(\n \"useTamboCurrentMessage must be used within a TamboMessageProvider\",\n );\n }\n return message;\n};\n"]}
@@ -190,7 +190,7 @@ function deriveGlobalStreamStatus(generationStage, propStatus, hasComponent, gen
190
190
  function useTamboStreamStatus() {
191
191
  /** SSR Guard - ensure client-side only execution */
192
192
  assertClientSide();
193
- const { generationStage } = (0, tambo_thread_provider_1.useTamboThread)();
193
+ const { generationStage } = (0, tambo_thread_provider_1.useTamboGenerationStage)();
194
194
  const message = (0, use_current_message_1.useTamboCurrentMessage)();
195
195
  /** Get the current component props from the message */
196
196
  const componentProps = message?.component?.props || {};
@@ -1 +1 @@
1
- {"version":3,"file":"use-tambo-stream-status.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-stream-status.tsx"],"names":[],"mappings":";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;QACL,YAAY;QACZ,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { useTamboThread } from \"../providers/tambo-thread-provider\";\nimport { useTamboCurrentMessage } from \"./use-current-message\";\n\n/**\n * Global stream status flags for a specific component in a message.\n * Represents the aggregate state across all props for this component only.\n * Once a component completes, its status remains stable regardless of other generations.\n */\nexport interface StreamStatus {\n /**\n * Indicates no tokens have been received for any prop and generation is not active.\n * Useful for showing initial loading states before any data arrives.\n */\n isPending: boolean;\n\n /**\n * Indicates active streaming - either generation is streaming OR at least one prop is still streaming.\n * Use this to show loading animations or skeleton states during data transmission.\n */\n isStreaming: boolean;\n\n /**\n * Indicates successful completion - generation is complete AND every prop finished without error.\n * Safe to render the final component when this is true.\n */\n isSuccess: boolean;\n\n /**\n * Indicates a fatal error occurred in any prop or the stream itself.\n * Check streamError for details about what went wrong.\n */\n isError: boolean;\n\n /**\n * The first fatal error encountered during streaming (if any).\n * Will be undefined if no errors occurred.\n */\n streamError?: Error;\n}\n\n/**\n * Streaming status flags for individual component props.\n * Tracks the state of each prop as it streams from the LLM.\n */\nexport interface PropStatus {\n /**\n * Indicates no tokens have been received for this specific prop yet.\n * The prop value is still undefined, null, or empty string.\n */\n isPending: boolean;\n\n /**\n * Indicates at least one token has been received but streaming is not complete.\n * The prop has partial content that may still be updating.\n */\n isStreaming: boolean;\n\n /**\n * Indicates this prop has finished streaming successfully.\n * The prop value is complete and stable.\n */\n isSuccess: boolean;\n\n /**\n * The error that occurred during streaming (if any).\n * Will be undefined if no error occurred for this prop.\n */\n error?: Error;\n}\n\n/**\n * SSR Guard - throws during server-side rendering.\n * Ensures the hook is only used in browser contexts.\n * @throws {Error} When called during server-side rendering\n */\nfunction assertClientSide() {\n if (typeof window === \"undefined\") {\n throw new Error(\n \"useTamboStreamStatus can only be used in browser contexts. \" +\n \"This hook is not compatible with SSR/SSG. \" +\n \"Consider wrapping it in useEffect or using dynamic imports.\",\n );\n }\n}\n\n/**\n * Track streaming status for individual props by monitoring their values.\n * Monitors when props receive their first token and when they complete streaming.\n * Maintains stable state per message - once props complete for a message, they stay complete.\n * @template Props - The type of the component props being tracked\n * @param props - The current component props object\n * @param generationStage - The current generation stage from the LLM\n * @param messageId - The ID of the current message to track component-specific state\n * @returns A record mapping each prop key to its PropStatus\n */\nfunction usePropsStreamingStatus<Props extends Record<string, any>>(\n props: Props | undefined,\n generationStage: GenerationStage,\n messageId: string,\n): Record<keyof Props, PropStatus> {\n const [propTracking, setPropTracking] = useState<\n Record<\n string,\n {\n hasStarted: boolean;\n isComplete: boolean;\n error?: Error;\n messageId: string;\n }\n >\n >({});\n\n /** Reset tracking only when the message changes */\n useEffect(() => {\n setPropTracking((prev) => {\n // If we have tracking data for a different message, reset\n const hasOldMessageData = Object.values(prev).some(\n (track) => track.messageId && track.messageId !== messageId,\n );\n return hasOldMessageData ? {} : prev;\n });\n }, [messageId]);\n\n /** Track when props start streaming (receive first token) and when they complete */\n useEffect(() => {\n if (!props) return;\n\n setPropTracking((prev) => {\n const updated = { ...prev };\n let hasChanges = false;\n\n // First pass: identify which props are starting now\n const propsStartingNow: string[] = [];\n Object.entries(props).forEach(([key, value]) => {\n const current = prev[key] || {\n hasStarted: false,\n isComplete: false,\n };\n\n /** A prop starts streaming when it has a non-empty value for the first time */\n const hasContent =\n value !== undefined && value !== null && value !== \"\";\n const justStarted = hasContent && !current.hasStarted;\n\n if (justStarted) {\n propsStartingNow.push(key);\n }\n });\n\n // Second pass: update tracking and mark previous props as complete\n Object.entries(props).forEach(([key, value]) => {\n const current = prev[key] || {\n hasStarted: false,\n isComplete: false,\n };\n\n /** A prop starts streaming when it has a non-empty value for the first time */\n const hasContent =\n value !== undefined && value !== null && value !== \"\";\n const justStarted = hasContent && !current.hasStarted;\n\n /**\n * A prop is complete when it has started and either:\n * 1. A following prop has started, OR\n * 2. Generation is complete (for the final prop)\n */\n const hasFollowingPropStarted = propsStartingNow.some(\n (startingKey) => startingKey !== key,\n );\n const isGenerationComplete =\n generationStage === GenerationStage.COMPLETE;\n const isComplete =\n current.hasStarted &&\n (hasFollowingPropStarted || isGenerationComplete) &&\n !current.isComplete;\n\n // Once a prop is complete for this message, it stays complete\n if (current.isComplete && current.messageId === messageId) {\n // Skip - already complete for this message\n return;\n }\n\n if (justStarted || isComplete) {\n updated[key] = {\n ...current,\n hasStarted: justStarted ? true : current.hasStarted,\n isComplete: isComplete ? true : current.isComplete,\n messageId,\n };\n hasChanges = true;\n }\n });\n\n return hasChanges ? updated : prev;\n });\n }, [props, generationStage, messageId]);\n\n /** Convert tracking state to PropStatus objects */\n return useMemo(() => {\n if (!props) return {} as Record<keyof Props, PropStatus>;\n\n const result = {} as Record<keyof Props, PropStatus>;\n\n Object.keys(props).forEach((key) => {\n const tracking = propTracking[key] || {\n hasStarted: false,\n isComplete: false,\n messageId: \"\",\n };\n\n // If this prop is complete for this message, it stays complete\n const isCompleteForThisMessage =\n tracking.isComplete && tracking.messageId === messageId;\n\n // Only consider generation stage if this prop isn't already complete for this message\n const isGenerationStreaming =\n !isCompleteForThisMessage &&\n generationStage === GenerationStage.STREAMING_RESPONSE;\n\n result[key as keyof Props] = {\n isPending: !tracking.hasStarted && !isCompleteForThisMessage,\n isStreaming:\n tracking.hasStarted &&\n !isCompleteForThisMessage &&\n isGenerationStreaming,\n isSuccess: isCompleteForThisMessage,\n error: tracking.error,\n };\n });\n\n return result;\n }, [props, propTracking, generationStage, messageId]);\n}\n\n/**\n * Derives global StreamStatus from generation stage and individual prop statuses.\n * Aggregates individual prop states into a unified stream status.\n * @template Props - The type of the component props\n * @param generationStage - The current generation stage from the LLM\n * @param propStatus - Status record for each individual prop\n * @param hasComponent - Whether a component exists in the current message\n * @param generationError - Any error from the generation process itself\n * @returns The aggregated StreamStatus for the entire component\n */\nfunction deriveGlobalStreamStatus<Props extends Record<string, any>>(\n generationStage: GenerationStage,\n propStatus: Record<keyof Props, PropStatus>,\n hasComponent: boolean,\n generationError?: Error,\n): StreamStatus {\n const propStatuses = Object.values(propStatus) as PropStatus[];\n\n // If all props are already successful, the component is complete regardless of generation stage\n const allPropsSuccessful =\n propStatuses.length > 0 && propStatuses.every((p) => p.isSuccess);\n\n // Only consider generation stage if not all props are complete\n const isGenerationStreaming =\n !allPropsSuccessful &&\n generationStage === GenerationStage.STREAMING_RESPONSE;\n const isGenerationError = generationStage === GenerationStage.ERROR;\n\n /** Find first error from generation or any prop */\n const firstError =\n generationError ?? propStatuses.find((p) => p.error)?.error;\n\n return {\n /** isPending: no component yet OR (has component but no props have started) */\n isPending:\n !hasComponent ||\n (!isGenerationStreaming &&\n !allPropsSuccessful &&\n propStatuses.every((p) => p.isPending)),\n\n /** isStreaming: any prop is streaming (generation stage doesn't matter if props are complete) */\n isStreaming: propStatuses.some((p) => p.isStreaming),\n\n /** isSuccess: all props successful (component is stable once all props complete) */\n isSuccess: allPropsSuccessful,\n\n /** isError: generation error OR any prop error */\n isError:\n isGenerationError ||\n propStatuses.some((p) => p.error) ||\n !!generationError,\n\n streamError: firstError,\n };\n}\n\n/**\n * Hook that exposes per-prop and global streaming status for tambo-ai components.\n * Provides streaming readiness flags so consumers can show loaders, skeletons,\n * or errors while LLM-generated props stream in.\n * This hook tracks status for the specific component in the current message only.\n * Once a component's props complete streaming, they remain stable regardless of\n * other components being generated in the thread.\n * @template Props - The type of the component props being tracked (defaults to Record<string, any>)\n * @returns An object containing both global streamStatus and per-prop propStatus\n * @throws {Error} When used during SSR/SSG\n * @example\n * ```tsx\n * // Wait for entire stream\n * const { streamStatus } = useTamboStreamStatus();\n * if (!streamStatus.isSuccess) return <Spinner />;\n * return <Card {...props} />;\n * ```\n * @example\n * ```tsx\n * // Highlight in-flight props\n * const { propStatus } = useTamboStreamStatus<Props>();\n * <h2 className={propStatus.title.isStreaming ? \"animate-pulse\" : \"\"}>\n * {title}\n * </h2>\n * ```\n */\nexport function useTamboStreamStatus<\n Props extends Record<string, any> = Record<string, any>,\n>(): {\n streamStatus: StreamStatus;\n propStatus: Record<keyof Props, PropStatus>;\n} {\n /** SSR Guard - ensure client-side only execution */\n assertClientSide();\n\n const { generationStage } = useTamboThread();\n const message = useTamboCurrentMessage();\n\n /** Get the current component props from the message */\n const componentProps = (message?.component?.props as Props) || ({} as Props);\n\n /** Track per-prop streaming status */\n const propStatus = usePropsStreamingStatus(\n componentProps,\n generationStage,\n message?.id ?? \"\",\n );\n\n /** Derive global stream status from prop statuses and generation stage */\n const streamStatus = useMemo(() => {\n const generationError = message?.error\n ? new Error(message.error)\n : undefined;\n const hasComponent = !!message?.component;\n return deriveGlobalStreamStatus(\n generationStage,\n propStatus,\n hasComponent,\n generationError,\n );\n }, [generationStage, propStatus, message?.error, message?.component]);\n\n return {\n streamStatus,\n propStatus,\n };\n}\n"]}
1
+ {"version":3,"file":"use-tambo-stream-status.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-stream-status.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AA+Tb,oDAwCC;AAtWD,iCAAqD;AACrD,sFAAuE;AACvE,8EAA6E;AAC7E,+DAA+D;AAqE/D;;;;GAIG;AACH,SAAS,gBAAgB;IACvB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC3D,4CAA4C;YAC5C,6DAA6D,CAChE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,uBAAuB,CAC9B,KAAwB,EACxB,eAAgC,EAChC,SAAiB;IAEjB,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAU9C,EAAE,CAAC,CAAC;IAEN,mDAAmD;IACnD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE;YACvB,0DAA0D;YAC1D,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC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AAE,KAAe,IAAK,EAAY,CAAC;IAE7E,sCAAsC;IACtC,MAAM,UAAU,GAAG,uBAAuB,CACxC,cAAc,EACd,eAAe,EACf,OAAO,EAAE,EAAE,IAAI,EAAE,CAClB,CAAC;IAEF,0EAA0E;IAC1E,MAAM,YAAY,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAChC,MAAM,eAAe,GAAG,OAAO,EAAE,KAAK;YACpC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,YAAY,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC;QAC1C,OAAO,wBAAwB,CAC7B,eAAe,EACf,UAAU,EACV,YAAY,EACZ,eAAe,CAChB,CAAC;IACJ,CAAC,EAAE,CAAC,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IAEtE,OAAO;QACL,YAAY;QACZ,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { useTamboGenerationStage } from \"../providers/tambo-thread-provider\";\nimport { useTamboCurrentMessage } from \"./use-current-message\";\n\n/**\n * Global stream status flags for a specific component in a message.\n * Represents the aggregate state across all props for this component only.\n * Once a component completes, its status remains stable regardless of other generations.\n */\nexport interface StreamStatus {\n /**\n * Indicates no tokens have been received for any prop and generation is not active.\n * Useful for showing initial loading states before any data arrives.\n */\n isPending: boolean;\n\n /**\n * Indicates active streaming - either generation is streaming OR at least one prop is still streaming.\n * Use this to show loading animations or skeleton states during data transmission.\n */\n isStreaming: boolean;\n\n /**\n * Indicates successful completion - generation is complete AND every prop finished without error.\n * Safe to render the final component when this is true.\n */\n isSuccess: boolean;\n\n /**\n * Indicates a fatal error occurred in any prop or the stream itself.\n * Check streamError for details about what went wrong.\n */\n isError: boolean;\n\n /**\n * The first fatal error encountered during streaming (if any).\n * Will be undefined if no errors occurred.\n */\n streamError?: Error;\n}\n\n/**\n * Streaming status flags for individual component props.\n * Tracks the state of each prop as it streams from the LLM.\n */\nexport interface PropStatus {\n /**\n * Indicates no tokens have been received for this specific prop yet.\n * The prop value is still undefined, null, or empty string.\n */\n isPending: boolean;\n\n /**\n * Indicates at least one token has been received but streaming is not complete.\n * The prop has partial content that may still be updating.\n */\n isStreaming: boolean;\n\n /**\n * Indicates this prop has finished streaming successfully.\n * The prop value is complete and stable.\n */\n isSuccess: boolean;\n\n /**\n * The error that occurred during streaming (if any).\n * Will be undefined if no error occurred for this prop.\n */\n error?: Error;\n}\n\n/**\n * SSR Guard - throws during server-side rendering.\n * Ensures the hook is only used in browser contexts.\n * @throws {Error} When called during server-side rendering\n */\nfunction assertClientSide() {\n if (typeof window === \"undefined\") {\n throw new Error(\n \"useTamboStreamStatus can only be used in browser contexts. \" +\n \"This hook is not compatible with SSR/SSG. \" +\n \"Consider wrapping it in useEffect or using dynamic imports.\",\n );\n }\n}\n\n/**\n * Track streaming status for individual props by monitoring their values.\n * Monitors when props receive their first token and when they complete streaming.\n * Maintains stable state per message - once props complete for a message, they stay complete.\n * @template Props - The type of the component props being tracked\n * @param props - The current component props object\n * @param generationStage - The current generation stage from the LLM\n * @param messageId - The ID of the current message to track component-specific state\n * @returns A record mapping each prop key to its PropStatus\n */\nfunction usePropsStreamingStatus<Props extends Record<string, any>>(\n props: Props | undefined,\n generationStage: GenerationStage,\n messageId: string,\n): Record<keyof Props, PropStatus> {\n const [propTracking, setPropTracking] = useState<\n Record<\n string,\n {\n hasStarted: boolean;\n isComplete: boolean;\n error?: Error;\n messageId: string;\n }\n >\n >({});\n\n /** Reset tracking only when the message changes */\n useEffect(() => {\n setPropTracking((prev) => {\n // If we have tracking data for a different message, reset\n const hasOldMessageData = Object.values(prev).some(\n (track) => track.messageId && track.messageId !== messageId,\n );\n return hasOldMessageData ? {} : prev;\n });\n }, [messageId]);\n\n /** Track when props start streaming (receive first token) and when they complete */\n useEffect(() => {\n if (!props) return;\n\n setPropTracking((prev) => {\n const updated = { ...prev };\n let hasChanges = false;\n\n // First pass: identify which props are starting now\n const propsStartingNow: string[] = [];\n Object.entries(props).forEach(([key, value]) => {\n const current = prev[key] || {\n hasStarted: false,\n isComplete: false,\n };\n\n /** A prop starts streaming when it has a non-empty value for the first time */\n const hasContent =\n value !== undefined && value !== null && value !== \"\";\n const justStarted = hasContent && !current.hasStarted;\n\n if (justStarted) {\n propsStartingNow.push(key);\n }\n });\n\n // Second pass: update tracking and mark previous props as complete\n Object.entries(props).forEach(([key, value]) => {\n const current = prev[key] || {\n hasStarted: false,\n isComplete: false,\n };\n\n /** A prop starts streaming when it has a non-empty value for the first time */\n const hasContent =\n value !== undefined && value !== null && value !== \"\";\n const justStarted = hasContent && !current.hasStarted;\n\n /**\n * A prop is complete when it has started and either:\n * 1. A following prop has started, OR\n * 2. Generation is complete (for the final prop)\n */\n const hasFollowingPropStarted = propsStartingNow.some(\n (startingKey) => startingKey !== key,\n );\n const isGenerationComplete =\n generationStage === GenerationStage.COMPLETE;\n const isComplete =\n current.hasStarted &&\n (hasFollowingPropStarted || isGenerationComplete) &&\n !current.isComplete;\n\n // Once a prop is complete for this message, it stays complete\n if (current.isComplete && current.messageId === messageId) {\n // Skip - already complete for this message\n return;\n }\n\n if (justStarted || isComplete) {\n updated[key] = {\n ...current,\n hasStarted: justStarted ? true : current.hasStarted,\n isComplete: isComplete ? true : current.isComplete,\n messageId,\n };\n hasChanges = true;\n }\n });\n\n return hasChanges ? updated : prev;\n });\n }, [props, generationStage, messageId]);\n\n /** Convert tracking state to PropStatus objects */\n return useMemo(() => {\n if (!props) return {} as Record<keyof Props, PropStatus>;\n\n const result = {} as Record<keyof Props, PropStatus>;\n\n Object.keys(props).forEach((key) => {\n const tracking = propTracking[key] || {\n hasStarted: false,\n isComplete: false,\n messageId: \"\",\n };\n\n // If this prop is complete for this message, it stays complete\n const isCompleteForThisMessage =\n tracking.isComplete && tracking.messageId === messageId;\n\n // Only consider generation stage if this prop isn't already complete for this message\n const isGenerationStreaming =\n !isCompleteForThisMessage &&\n generationStage === GenerationStage.STREAMING_RESPONSE;\n\n result[key as keyof Props] = {\n isPending: !tracking.hasStarted && !isCompleteForThisMessage,\n isStreaming:\n tracking.hasStarted &&\n !isCompleteForThisMessage &&\n isGenerationStreaming,\n isSuccess: isCompleteForThisMessage,\n error: tracking.error,\n };\n });\n\n return result;\n }, [props, propTracking, generationStage, messageId]);\n}\n\n/**\n * Derives global StreamStatus from generation stage and individual prop statuses.\n * Aggregates individual prop states into a unified stream status.\n * @template Props - The type of the component props\n * @param generationStage - The current generation stage from the LLM\n * @param propStatus - Status record for each individual prop\n * @param hasComponent - Whether a component exists in the current message\n * @param generationError - Any error from the generation process itself\n * @returns The aggregated StreamStatus for the entire component\n */\nfunction deriveGlobalStreamStatus<Props extends Record<string, any>>(\n generationStage: GenerationStage,\n propStatus: Record<keyof Props, PropStatus>,\n hasComponent: boolean,\n generationError?: Error,\n): StreamStatus {\n const propStatuses = Object.values(propStatus) as PropStatus[];\n\n // If all props are already successful, the component is complete regardless of generation stage\n const allPropsSuccessful =\n propStatuses.length > 0 && propStatuses.every((p) => p.isSuccess);\n\n // Only consider generation stage if not all props are complete\n const isGenerationStreaming =\n !allPropsSuccessful &&\n generationStage === GenerationStage.STREAMING_RESPONSE;\n const isGenerationError = generationStage === GenerationStage.ERROR;\n\n /** Find first error from generation or any prop */\n const firstError =\n generationError ?? propStatuses.find((p) => p.error)?.error;\n\n return {\n /** isPending: no component yet OR (has component but no props have started) */\n isPending:\n !hasComponent ||\n (!isGenerationStreaming &&\n !allPropsSuccessful &&\n propStatuses.every((p) => p.isPending)),\n\n /** isStreaming: any prop is streaming (generation stage doesn't matter if props are complete) */\n isStreaming: propStatuses.some((p) => p.isStreaming),\n\n /** isSuccess: all props successful (component is stable once all props complete) */\n isSuccess: allPropsSuccessful,\n\n /** isError: generation error OR any prop error */\n isError:\n isGenerationError ||\n propStatuses.some((p) => p.error) ||\n !!generationError,\n\n streamError: firstError,\n };\n}\n\n/**\n * Hook that exposes per-prop and global streaming status for tambo-ai components.\n * Provides streaming readiness flags so consumers can show loaders, skeletons,\n * or errors while LLM-generated props stream in.\n * This hook tracks status for the specific component in the current message only.\n * Once a component's props complete streaming, they remain stable regardless of\n * other components being generated in the thread.\n * @template Props - The type of the component props being tracked (defaults to Record<string, any>)\n * @returns An object containing both global streamStatus and per-prop propStatus\n * @throws {Error} When used during SSR/SSG\n * @example\n * ```tsx\n * // Wait for entire stream\n * const { streamStatus } = useTamboStreamStatus();\n * if (!streamStatus.isSuccess) return <Spinner />;\n * return <Card {...props} />;\n * ```\n * @example\n * ```tsx\n * // Highlight in-flight props\n * const { propStatus } = useTamboStreamStatus<Props>();\n * <h2 className={propStatus.title.isStreaming ? \"animate-pulse\" : \"\"}>\n * {title}\n * </h2>\n * ```\n */\nexport function useTamboStreamStatus<\n Props extends Record<string, any> = Record<string, any>,\n>(): {\n streamStatus: StreamStatus;\n propStatus: Record<keyof Props, PropStatus>;\n} {\n /** SSR Guard - ensure client-side only execution */\n assertClientSide();\n\n const { generationStage } = useTamboGenerationStage();\n const message = useTamboCurrentMessage();\n\n /** Get the current component props from the message */\n const componentProps = (message?.component?.props as Props) || ({} as Props);\n\n /** Track per-prop streaming status */\n const propStatus = usePropsStreamingStatus(\n componentProps,\n generationStage,\n message?.id ?? \"\",\n );\n\n /** Derive global stream status from prop statuses and generation stage */\n const streamStatus = useMemo(() => {\n const generationError = message?.error\n ? new Error(message.error)\n : undefined;\n const hasComponent = !!message?.component;\n return deriveGlobalStreamStatus(\n generationStage,\n propStatus,\n hasComponent,\n generationError,\n );\n }, [generationStage, propStatus, message?.error, message?.component]);\n\n return {\n streamStatus,\n propStatus,\n };\n}\n"]}
@@ -27,7 +27,8 @@ exports.INPUT_ERROR_MESSAGES = {
27
27
  * @returns Interface for managing thread input state and submission
28
28
  */
29
29
  function useTamboThreadInput(contextKey) {
30
- const { thread, inputValue, setInputValue, sendThreadMessage } = (0, tambo_thread_provider_1.useTamboThread)();
30
+ const { thread, sendThreadMessage } = (0, tambo_thread_provider_1.useTamboThread)();
31
+ const [inputValue, setInputValue] = (0, react_1.useState)("");
31
32
  const submit = (0, react_1.useCallback)(async ({ contextKey: submitContextKey, streamResponse, forceToolChoice, additionalContext, } = {}) => {
32
33
  const validation = (0, validate_input_1.validateInput)(inputValue);
33
34
  if (!validation.isValid) {
@@ -40,7 +41,7 @@ function useTamboThreadInput(contextKey) {
40
41
  forceToolChoice: forceToolChoice,
41
42
  additionalContext: additionalContext,
42
43
  });
43
- setInputValue("");
44
+ setInputValue(""); // Clear local state
44
45
  }, [inputValue, sendThreadMessage, thread.id, contextKey, setInputValue]);
45
46
  const { mutateAsync: submitAsync, mutate: _unusedSubmit, ...mutationState } = (0, react_query_hooks_1.useTamboMutation)({
46
47
  mutationFn: submit,