@tambo-ai/react 0.71.0 → 0.73.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 (167) hide show
  1. package/dist/v1/hooks/use-tambo-v1-component-state.d.ts +44 -0
  2. package/dist/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -0
  3. package/dist/v1/hooks/use-tambo-v1-component-state.js +134 -0
  4. package/dist/v1/hooks/use-tambo-v1-component-state.js.map +1 -0
  5. package/dist/v1/hooks/use-tambo-v1-component-state.test.d.ts +2 -0
  6. package/dist/v1/hooks/use-tambo-v1-component-state.test.d.ts.map +1 -0
  7. package/dist/v1/hooks/use-tambo-v1-component-state.test.js +292 -0
  8. package/dist/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -0
  9. package/dist/v1/hooks/use-tambo-v1-messages.test.js +22 -9
  10. package/dist/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
  11. package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +1 -0
  12. package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
  13. package/dist/v1/hooks/use-tambo-v1-send-message.js +9 -2
  14. package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
  15. package/dist/v1/hooks/use-tambo-v1-send-message.test.js +22 -9
  16. package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
  17. package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts +91 -0
  18. package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -0
  19. package/dist/v1/hooks/use-tambo-v1-suggestions.js +152 -0
  20. package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -0
  21. package/dist/v1/hooks/use-tambo-v1-suggestions.test.d.ts +2 -0
  22. package/dist/v1/hooks/use-tambo-v1-suggestions.test.d.ts.map +1 -0
  23. package/dist/v1/hooks/use-tambo-v1-suggestions.test.js +511 -0
  24. package/dist/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -0
  25. package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts +11 -0
  26. package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -0
  27. package/dist/v1/hooks/use-tambo-v1-thread-input.js +16 -0
  28. package/dist/v1/hooks/use-tambo-v1-thread-input.js.map +1 -0
  29. package/dist/v1/hooks/use-tambo-v1-thread-input.test.d.ts +2 -0
  30. package/dist/v1/hooks/use-tambo-v1-thread-input.test.d.ts.map +1 -0
  31. package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +297 -0
  32. package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -0
  33. package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts +6 -4
  34. package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
  35. package/dist/v1/hooks/use-tambo-v1-thread-list.js +2 -2
  36. package/dist/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
  37. package/dist/v1/hooks/use-tambo-v1-thread-list.test.js +2 -2
  38. package/dist/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
  39. package/dist/v1/hooks/use-tambo-v1.test.js +16 -7
  40. package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
  41. package/dist/v1/index.d.ts +39 -19
  42. package/dist/v1/index.d.ts.map +1 -1
  43. package/dist/v1/index.js +60 -34
  44. package/dist/v1/index.js.map +1 -1
  45. package/dist/v1/providers/tambo-v1-provider.d.ts +61 -1
  46. package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
  47. package/dist/v1/providers/tambo-v1-provider.js +35 -3
  48. package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
  49. package/dist/v1/providers/tambo-v1-provider.test.js +78 -3
  50. package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -1
  51. package/dist/v1/providers/tambo-v1-stream-context.d.ts +19 -10
  52. package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
  53. package/dist/v1/providers/tambo-v1-stream-context.js +43 -53
  54. package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -1
  55. package/dist/v1/providers/tambo-v1-stream-context.test.js +94 -19
  56. package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
  57. package/dist/v1/providers/tambo-v1-stub-provider.d.ts +74 -0
  58. package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -0
  59. package/dist/v1/providers/tambo-v1-stub-provider.js +212 -0
  60. package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -0
  61. package/dist/v1/providers/tambo-v1-stub-provider.test.d.ts +2 -0
  62. package/dist/v1/providers/tambo-v1-stub-provider.test.d.ts.map +1 -0
  63. package/dist/v1/providers/tambo-v1-stub-provider.test.js +162 -0
  64. package/dist/v1/providers/tambo-v1-stub-provider.test.js.map +1 -0
  65. package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts +105 -0
  66. package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -0
  67. package/dist/v1/providers/tambo-v1-thread-input-provider.js +191 -0
  68. package/dist/v1/providers/tambo-v1-thread-input-provider.js.map +1 -0
  69. package/dist/v1/types/message.d.ts +27 -2
  70. package/dist/v1/types/message.d.ts.map +1 -1
  71. package/dist/v1/types/message.js.map +1 -1
  72. package/dist/v1/utils/component-renderer.d.ts +37 -0
  73. package/dist/v1/utils/component-renderer.d.ts.map +1 -0
  74. package/dist/v1/utils/component-renderer.js +70 -0
  75. package/dist/v1/utils/component-renderer.js.map +1 -0
  76. package/dist/v1/utils/component-renderer.test.d.ts +2 -0
  77. package/dist/v1/utils/component-renderer.test.d.ts.map +1 -0
  78. package/dist/v1/utils/component-renderer.test.js +45 -0
  79. package/dist/v1/utils/component-renderer.test.js.map +1 -0
  80. package/dist/v1/utils/event-accumulator.js +28 -8
  81. package/dist/v1/utils/event-accumulator.js.map +1 -1
  82. package/dist/v1/utils/event-accumulator.test.js +201 -6
  83. package/dist/v1/utils/event-accumulator.test.js.map +1 -1
  84. package/esm/v1/hooks/use-tambo-v1-component-state.d.ts +44 -0
  85. package/esm/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -0
  86. package/esm/v1/hooks/use-tambo-v1-component-state.js +131 -0
  87. package/esm/v1/hooks/use-tambo-v1-component-state.js.map +1 -0
  88. package/esm/v1/hooks/use-tambo-v1-component-state.test.d.ts +2 -0
  89. package/esm/v1/hooks/use-tambo-v1-component-state.test.d.ts.map +1 -0
  90. package/esm/v1/hooks/use-tambo-v1-component-state.test.js +290 -0
  91. package/esm/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -0
  92. package/esm/v1/hooks/use-tambo-v1-messages.test.js +22 -9
  93. package/esm/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
  94. package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +1 -0
  95. package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
  96. package/esm/v1/hooks/use-tambo-v1-send-message.js +9 -2
  97. package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
  98. package/esm/v1/hooks/use-tambo-v1-send-message.test.js +22 -9
  99. package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
  100. package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts +91 -0
  101. package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -0
  102. package/esm/v1/hooks/use-tambo-v1-suggestions.js +149 -0
  103. package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -0
  104. package/esm/v1/hooks/use-tambo-v1-suggestions.test.d.ts +2 -0
  105. package/esm/v1/hooks/use-tambo-v1-suggestions.test.d.ts.map +1 -0
  106. package/esm/v1/hooks/use-tambo-v1-suggestions.test.js +506 -0
  107. package/esm/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -0
  108. package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts +11 -0
  109. package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -0
  110. package/esm/v1/hooks/use-tambo-v1-thread-input.js +12 -0
  111. package/esm/v1/hooks/use-tambo-v1-thread-input.js.map +1 -0
  112. package/esm/v1/hooks/use-tambo-v1-thread-input.test.d.ts +2 -0
  113. package/esm/v1/hooks/use-tambo-v1-thread-input.test.d.ts.map +1 -0
  114. package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +292 -0
  115. package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -0
  116. package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts +6 -4
  117. package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
  118. package/esm/v1/hooks/use-tambo-v1-thread-list.js +2 -2
  119. package/esm/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
  120. package/esm/v1/hooks/use-tambo-v1-thread-list.test.js +2 -2
  121. package/esm/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
  122. package/esm/v1/hooks/use-tambo-v1.test.js +16 -7
  123. package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
  124. package/esm/v1/index.d.ts +39 -19
  125. package/esm/v1/index.d.ts.map +1 -1
  126. package/esm/v1/index.js +43 -19
  127. package/esm/v1/index.js.map +1 -1
  128. package/esm/v1/providers/tambo-v1-provider.d.ts +61 -1
  129. package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
  130. package/esm/v1/providers/tambo-v1-provider.js +34 -4
  131. package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
  132. package/esm/v1/providers/tambo-v1-provider.test.js +79 -4
  133. package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -1
  134. package/esm/v1/providers/tambo-v1-stream-context.d.ts +19 -10
  135. package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
  136. package/esm/v1/providers/tambo-v1-stream-context.js +44 -54
  137. package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -1
  138. package/esm/v1/providers/tambo-v1-stream-context.test.js +95 -20
  139. package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
  140. package/esm/v1/providers/tambo-v1-stub-provider.d.ts +74 -0
  141. package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -0
  142. package/esm/v1/providers/tambo-v1-stub-provider.js +176 -0
  143. package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -0
  144. package/esm/v1/providers/tambo-v1-stub-provider.test.d.ts +2 -0
  145. package/esm/v1/providers/tambo-v1-stub-provider.test.d.ts.map +1 -0
  146. package/esm/v1/providers/tambo-v1-stub-provider.test.js +157 -0
  147. package/esm/v1/providers/tambo-v1-stub-provider.test.js.map +1 -0
  148. package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts +105 -0
  149. package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -0
  150. package/esm/v1/providers/tambo-v1-thread-input-provider.js +153 -0
  151. package/esm/v1/providers/tambo-v1-thread-input-provider.js.map +1 -0
  152. package/esm/v1/types/message.d.ts +27 -2
  153. package/esm/v1/types/message.d.ts.map +1 -1
  154. package/esm/v1/types/message.js.map +1 -1
  155. package/esm/v1/utils/component-renderer.d.ts +37 -0
  156. package/esm/v1/utils/component-renderer.d.ts.map +1 -0
  157. package/esm/v1/utils/component-renderer.js +33 -0
  158. package/esm/v1/utils/component-renderer.js.map +1 -0
  159. package/esm/v1/utils/component-renderer.test.d.ts +2 -0
  160. package/esm/v1/utils/component-renderer.test.d.ts.map +1 -0
  161. package/esm/v1/utils/component-renderer.test.js +40 -0
  162. package/esm/v1/utils/component-renderer.test.js.map +1 -0
  163. package/esm/v1/utils/event-accumulator.js +28 -8
  164. package/esm/v1/utils/event-accumulator.js.map +1 -1
  165. package/esm/v1/utils/event-accumulator.test.js +201 -6
  166. package/esm/v1/utils/event-accumulator.test.js.map +1 -1
  167. package/package.json +2 -2
@@ -0,0 +1,105 @@
1
+ /**
2
+ * TamboV1ThreadInputProvider - Shared Thread Input Context for v1 API
3
+ *
4
+ * Provides shared input state across all components, enabling features like
5
+ * suggestions to update the input field directly.
6
+ *
7
+ * This mirrors the beta SDK's TamboThreadInputProvider pattern.
8
+ */
9
+ import React, { type PropsWithChildren } from "react";
10
+ import { type StagedImage } from "../../hooks/use-message-images";
11
+ import { type UseTamboMutationResult } from "../../hooks/react-query-hooks";
12
+ export declare const INPUT_ERROR_MESSAGES: {
13
+ readonly EMPTY: "Message cannot be empty";
14
+ readonly VALIDATION: "Invalid message format";
15
+ };
16
+ /**
17
+ * Options for submitting a message
18
+ */
19
+ export interface SubmitOptions {
20
+ /**
21
+ * Enable debug logging for the stream
22
+ */
23
+ debug?: boolean;
24
+ }
25
+ /**
26
+ * Context props for thread input state
27
+ */
28
+ export interface TamboV1ThreadInputContextProps extends Omit<UseTamboMutationResult<{
29
+ threadId: string | undefined;
30
+ }, Error, SubmitOptions | undefined>, "mutate" | "mutateAsync"> {
31
+ /** Current value of the input field */
32
+ value: string;
33
+ /**
34
+ * Function to update the input value
35
+ * @param value - New value for the input field
36
+ */
37
+ setValue: React.Dispatch<React.SetStateAction<string>>;
38
+ /**
39
+ * Function to submit the current input value
40
+ * @param options - Submission options
41
+ * @returns Promise with the threadId
42
+ */
43
+ submit: (options?: SubmitOptions) => Promise<{
44
+ threadId: string | undefined;
45
+ }>;
46
+ /** Currently staged images */
47
+ images: StagedImage[];
48
+ /** Add a single image */
49
+ addImage: (file: File) => Promise<void>;
50
+ /** Add multiple images */
51
+ addImages: (files: File[]) => Promise<void>;
52
+ /** Remove an image by id */
53
+ removeImage: (id: string) => void;
54
+ /** Clear all staged images */
55
+ clearImages: () => void;
56
+ /** Current thread ID being used for input */
57
+ threadId: string | undefined;
58
+ /**
59
+ * Set the thread ID for input submission.
60
+ * If not set, a new thread will be created on submit.
61
+ */
62
+ setThreadId: React.Dispatch<React.SetStateAction<string | undefined>>;
63
+ }
64
+ /**
65
+ * Context for thread input state.
66
+ * @internal
67
+ */
68
+ export declare const TamboV1ThreadInputContext: React.Context<TamboV1ThreadInputContextProps | undefined>;
69
+ /**
70
+ * Provider that manages shared thread input state across all components.
71
+ *
72
+ * This ensures that useTamboV1ThreadInput, useTamboV1Suggestions, and other components
73
+ * all share the same input state.
74
+ * @param props - Provider props
75
+ * @param props.children - Child components
76
+ * @returns Thread input context provider
77
+ */
78
+ export declare function TamboV1ThreadInputProvider({ children }: PropsWithChildren): React.JSX.Element;
79
+ /**
80
+ * Hook to access the shared thread input state.
81
+ *
82
+ * All components using this hook share the same input state, enabling
83
+ * features like suggestions to update the input field directly.
84
+ * @returns The shared thread input context
85
+ * @throws {Error} If used outside TamboV1ThreadInputProvider
86
+ * @example
87
+ * ```tsx
88
+ * function ChatInput() {
89
+ * const { value, setValue, submit, isPending } = useTamboV1ThreadInput();
90
+ *
91
+ * return (
92
+ * <form onSubmit={(e) => { e.preventDefault(); submit(); }}>
93
+ * <input
94
+ * value={value}
95
+ * onChange={(e) => setValue(e.target.value)}
96
+ * disabled={isPending}
97
+ * />
98
+ * <button type="submit" disabled={isPending}>Send</button>
99
+ * </form>
100
+ * );
101
+ * }
102
+ * ```
103
+ */
104
+ export declare function useTamboV1ThreadInput(): TamboV1ThreadInputContextProps;
105
+ //# sourceMappingURL=tambo-v1-thread-input-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-v1-thread-input-provider.d.ts","sourceRoot":"","sources":["../../../src/v1/providers/tambo-v1-thread-input-provider.tsx"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,EAKZ,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,+BAA+B,CAAC;AASvC,eAAO,MAAM,oBAAoB;;;CAGvB,CAAC;AAkCX;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,8BAA+B,SAAQ,IAAI,CAC1D,sBAAsB,CACpB;IAAE,QAAQ,EAAE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__createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.TamboV1ThreadInputContext = exports.INPUT_ERROR_MESSAGES = void 0;
38
+ exports.TamboV1ThreadInputProvider = TamboV1ThreadInputProvider;
39
+ exports.useTamboV1ThreadInput = useTamboV1ThreadInput;
40
+ /**
41
+ * TamboV1ThreadInputProvider - Shared Thread Input Context for v1 API
42
+ *
43
+ * Provides shared input state across all components, enabling features like
44
+ * suggestions to update the input field directly.
45
+ *
46
+ * This mirrors the beta SDK's TamboThreadInputProvider pattern.
47
+ */
48
+ const react_1 = __importStar(require("react"));
49
+ const use_message_images_1 = require("../../hooks/use-message-images");
50
+ const react_query_hooks_1 = require("../../hooks/react-query-hooks");
51
+ const use_tambo_v1_send_message_1 = require("../hooks/use-tambo-v1-send-message");
52
+ const tambo_v1_stream_context_1 = require("./tambo-v1-stream-context");
53
+ // Error messages for various input-related error scenarios.
54
+ // TODO: Reintroduce explicit `NETWORK` and `SERVER` keys once `submit()` maps
55
+ // failures into a small, stable set of user-facing error codes (at minimum:
56
+ // connectivity failures vs non-2xx responses).
57
+ exports.INPUT_ERROR_MESSAGES = {
58
+ EMPTY: "Message cannot be empty",
59
+ VALIDATION: "Invalid message format",
60
+ };
61
+ function stagedImageToResourceContent(image) {
62
+ if (!image.dataUrl.startsWith("data:")) {
63
+ throw new Error(exports.INPUT_ERROR_MESSAGES.VALIDATION);
64
+ }
65
+ const commaIndex = image.dataUrl.indexOf(",");
66
+ if (commaIndex === -1) {
67
+ throw new Error(exports.INPUT_ERROR_MESSAGES.VALIDATION);
68
+ }
69
+ const header = image.dataUrl.slice("data:".length, commaIndex);
70
+ const [mimeType, ...params] = header.split(";");
71
+ const isBase64 = params.includes("base64");
72
+ if (mimeType !== image.type || !isBase64) {
73
+ throw new Error(exports.INPUT_ERROR_MESSAGES.VALIDATION);
74
+ }
75
+ return {
76
+ type: "resource",
77
+ resource: {
78
+ name: image.name,
79
+ mimeType: image.type,
80
+ // Shared.Resource.blob expects base64-encoded data; this is the base64
81
+ // payload from the `data:` URL.
82
+ blob: image.dataUrl.slice(commaIndex + 1),
83
+ },
84
+ };
85
+ }
86
+ /**
87
+ * Context for thread input state.
88
+ * @internal
89
+ */
90
+ exports.TamboV1ThreadInputContext = (0, react_1.createContext)(undefined);
91
+ /**
92
+ * Provider that manages shared thread input state across all components.
93
+ *
94
+ * This ensures that useTamboV1ThreadInput, useTamboV1Suggestions, and other components
95
+ * all share the same input state.
96
+ * @param props - Provider props
97
+ * @param props.children - Child components
98
+ * @returns Thread input context provider
99
+ */
100
+ function TamboV1ThreadInputProvider({ children }) {
101
+ const [inputValue, setInputValue] = (0, react_1.useState)("");
102
+ const [threadId, setThreadId] = (0, react_1.useState)(undefined);
103
+ const imageState = (0, use_message_images_1.useMessageImages)();
104
+ const streamState = (0, tambo_v1_stream_context_1.useStreamState)();
105
+ // Use the current thread from stream state if no explicit threadId is set
106
+ const inheritedThreadId = streamState.currentThreadId ?? undefined;
107
+ const effectiveThreadId = threadId ?? inheritedThreadId;
108
+ const shouldAdoptThreadId = threadId === undefined && inheritedThreadId === undefined;
109
+ const sendMessage = (0, use_tambo_v1_send_message_1.useTamboV1SendMessage)(effectiveThreadId);
110
+ const submitFn = (0, react_1.useCallback)(async (options) => {
111
+ const trimmedValue = inputValue.trim();
112
+ // Check if we have content to send
113
+ if (!trimmedValue && imageState.images.length === 0) {
114
+ throw new Error(exports.INPUT_ERROR_MESSAGES.EMPTY);
115
+ }
116
+ const content = [];
117
+ if (trimmedValue) {
118
+ content.push({ type: "text", text: trimmedValue });
119
+ }
120
+ for (const image of imageState.images) {
121
+ content.push(stagedImageToResourceContent(image));
122
+ }
123
+ const result = await sendMessage.mutateAsync({
124
+ message: {
125
+ role: "user",
126
+ content,
127
+ },
128
+ debug: options?.debug,
129
+ });
130
+ // Clear input and images after successful submission
131
+ setInputValue("");
132
+ imageState.clearImages();
133
+ // Update threadId if a new thread was created
134
+ if (result.threadId && shouldAdoptThreadId) {
135
+ setThreadId(result.threadId);
136
+ }
137
+ return result;
138
+ },
139
+ // `stagedImageToResourceContent` is a pure module-level helper (not a hook value).
140
+ [inputValue, imageState, sendMessage, shouldAdoptThreadId]);
141
+ const { mutateAsync: submitAsync, mutate: _unusedSubmit, ...mutationState } = (0, react_query_hooks_1.useTamboMutation)({
142
+ mutationFn: submitFn,
143
+ });
144
+ const contextValue = {
145
+ ...mutationState,
146
+ value: inputValue,
147
+ setValue: setInputValue,
148
+ submit: submitAsync,
149
+ images: imageState.images,
150
+ addImage: imageState.addImage,
151
+ addImages: imageState.addImages,
152
+ removeImage: imageState.removeImage,
153
+ clearImages: imageState.clearImages,
154
+ threadId: effectiveThreadId,
155
+ setThreadId,
156
+ };
157
+ return (react_1.default.createElement(exports.TamboV1ThreadInputContext.Provider, { value: contextValue }, children));
158
+ }
159
+ /**
160
+ * Hook to access the shared thread input state.
161
+ *
162
+ * All components using this hook share the same input state, enabling
163
+ * features like suggestions to update the input field directly.
164
+ * @returns The shared thread input context
165
+ * @throws {Error} If used outside TamboV1ThreadInputProvider
166
+ * @example
167
+ * ```tsx
168
+ * function ChatInput() {
169
+ * const { value, setValue, submit, isPending } = useTamboV1ThreadInput();
170
+ *
171
+ * return (
172
+ * <form onSubmit={(e) => { e.preventDefault(); submit(); }}>
173
+ * <input
174
+ * value={value}
175
+ * onChange={(e) => setValue(e.target.value)}
176
+ * disabled={isPending}
177
+ * />
178
+ * <button type="submit" disabled={isPending}>Send</button>
179
+ * </form>
180
+ * );
181
+ * }
182
+ * ```
183
+ */
184
+ function useTamboV1ThreadInput() {
185
+ const context = (0, react_1.useContext)(exports.TamboV1ThreadInputContext);
186
+ if (!context) {
187
+ throw new Error("useTamboV1ThreadInput must be used within TamboV1ThreadInputProvider");
188
+ }
189
+ return context;
190
+ }
191
+ //# sourceMappingURL=tambo-v1-thread-input-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-v1-thread-input-provider.js","sourceRoot":"","sources":["../../../src/v1/providers/tambo-v1-thread-input-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwJb,gEAoFC;AA2BD,sDAQC;AA7QD;;;;;;;GAOG;AAEH,+CAMe;AACf,uEAGwC;AACxC,qEAGuC;AACvC,kFAA2E;AAE3E,uEAA2D;AAE3D,4DAA4D;AAC5D,8EAA8E;AAC9E,4EAA4E;AAC5E,+CAA+C;AAClC,QAAA,oBAAoB,GAAG;IAClC,KAAK,EAAE,yBAAyB;IAChC,UAAU,EAAE,wBAAwB;CAC5B,CAAC;AAEX,SAAS,4BAA4B,CACnC,KAAkB;IAElB,IAAI,C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,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["\"use client\";\n\n/**\n * TamboV1ThreadInputProvider - Shared Thread Input Context for v1 API\n *\n * Provides shared input state across all components, enabling features like\n * suggestions to update the input field directly.\n *\n * This mirrors the beta SDK's TamboThreadInputProvider pattern.\n */\n\nimport React, {\n createContext,\n useCallback,\n useContext,\n useState,\n type PropsWithChildren,\n} from \"react\";\nimport {\n useMessageImages,\n type StagedImage,\n} from \"../../hooks/use-message-images\";\nimport {\n useTamboMutation,\n type UseTamboMutationResult,\n} from \"../../hooks/react-query-hooks\";\nimport { useTamboV1SendMessage } from \"../hooks/use-tambo-v1-send-message\";\nimport type { InputMessage } from \"../types/message\";\nimport { useStreamState } from \"./tambo-v1-stream-context\";\n\n// Error messages for various input-related error scenarios.\n// TODO: Reintroduce explicit `NETWORK` and `SERVER` keys once `submit()` maps\n// failures into a small, stable set of user-facing error codes (at minimum:\n// connectivity failures vs non-2xx responses).\nexport const INPUT_ERROR_MESSAGES = {\n EMPTY: \"Message cannot be empty\",\n VALIDATION: \"Invalid message format\",\n} as const;\n\nfunction stagedImageToResourceContent(\n image: StagedImage,\n): InputMessage[\"content\"][number] {\n if (!image.dataUrl.startsWith(\"data:\")) {\n throw new Error(INPUT_ERROR_MESSAGES.VALIDATION);\n }\n\n const commaIndex = image.dataUrl.indexOf(\",\");\n if (commaIndex === -1) {\n throw new Error(INPUT_ERROR_MESSAGES.VALIDATION);\n }\n\n const header = image.dataUrl.slice(\"data:\".length, commaIndex);\n const [mimeType, ...params] = header.split(\";\");\n const isBase64 = params.includes(\"base64\");\n\n if (mimeType !== image.type || !isBase64) {\n throw new Error(INPUT_ERROR_MESSAGES.VALIDATION);\n }\n\n return {\n type: \"resource\",\n resource: {\n name: image.name,\n mimeType: image.type,\n // Shared.Resource.blob expects base64-encoded data; this is the base64\n // payload from the `data:` URL.\n blob: image.dataUrl.slice(commaIndex + 1),\n },\n };\n}\n\n/**\n * Options for submitting a message\n */\nexport interface SubmitOptions {\n /**\n * Enable debug logging for the stream\n */\n debug?: boolean;\n}\n\n/**\n * Context props for thread input state\n */\nexport interface TamboV1ThreadInputContextProps extends Omit<\n UseTamboMutationResult<\n { threadId: string | undefined },\n Error,\n SubmitOptions | undefined\n >,\n \"mutate\" | \"mutateAsync\"\n> {\n /** Current value of the input field */\n value: string;\n\n /**\n * Function to update the input value\n * @param value - New value for the input field\n */\n setValue: React.Dispatch<React.SetStateAction<string>>;\n\n /**\n * Function to submit the current input value\n * @param options - Submission options\n * @returns Promise with the threadId\n */\n submit: (\n options?: SubmitOptions,\n ) => Promise<{ threadId: string | undefined }>;\n\n /** Currently staged images */\n images: StagedImage[];\n\n /** Add a single image */\n addImage: (file: File) => Promise<void>;\n\n /** Add multiple images */\n addImages: (files: File[]) => Promise<void>;\n\n /** Remove an image by id */\n removeImage: (id: string) => void;\n\n /** Clear all staged images */\n clearImages: () => void;\n\n /** Current thread ID being used for input */\n threadId: string | undefined;\n\n /**\n * Set the thread ID for input submission.\n * If not set, a new thread will be created on submit.\n */\n setThreadId: React.Dispatch<React.SetStateAction<string | undefined>>;\n}\n\n/**\n * Context for thread input state.\n * @internal\n */\nexport const TamboV1ThreadInputContext = createContext<\n TamboV1ThreadInputContextProps | undefined\n>(undefined);\n\n/**\n * Provider that manages shared thread input state across all components.\n *\n * This ensures that useTamboV1ThreadInput, useTamboV1Suggestions, and other components\n * all share the same input state.\n * @param props - Provider props\n * @param props.children - Child components\n * @returns Thread input context provider\n */\nexport function TamboV1ThreadInputProvider({ children }: PropsWithChildren) {\n const [inputValue, setInputValue] = useState(\"\");\n const [threadId, setThreadId] = useState<string | undefined>(undefined);\n const imageState = useMessageImages();\n const streamState = useStreamState();\n\n // Use the current thread from stream state if no explicit threadId is set\n const inheritedThreadId = streamState.currentThreadId ?? undefined;\n const effectiveThreadId = threadId ?? inheritedThreadId;\n const shouldAdoptThreadId =\n threadId === undefined && inheritedThreadId === undefined;\n const sendMessage = useTamboV1SendMessage(effectiveThreadId);\n\n const submitFn = useCallback(\n async (\n options?: SubmitOptions,\n ): Promise<{ threadId: string | undefined }> => {\n const trimmedValue = inputValue.trim();\n\n // Check if we have content to send\n if (!trimmedValue && imageState.images.length === 0) {\n throw new Error(INPUT_ERROR_MESSAGES.EMPTY);\n }\n\n const content: InputMessage[\"content\"] = [];\n\n if (trimmedValue) {\n content.push({ type: \"text\", text: trimmedValue });\n }\n\n for (const image of imageState.images) {\n content.push(stagedImageToResourceContent(image));\n }\n\n const result = await sendMessage.mutateAsync({\n message: {\n role: \"user\",\n content,\n },\n debug: options?.debug,\n });\n\n // Clear input and images after successful submission\n setInputValue(\"\");\n imageState.clearImages();\n\n // Update threadId if a new thread was created\n if (result.threadId && shouldAdoptThreadId) {\n setThreadId(result.threadId);\n }\n\n return result;\n },\n // `stagedImageToResourceContent` is a pure module-level helper (not a hook value).\n [inputValue, imageState, sendMessage, shouldAdoptThreadId],\n );\n\n const {\n mutateAsync: submitAsync,\n mutate: _unusedSubmit,\n ...mutationState\n } = useTamboMutation({\n mutationFn: submitFn,\n });\n\n const contextValue: TamboV1ThreadInputContextProps = {\n ...mutationState,\n value: inputValue,\n setValue: setInputValue,\n submit: submitAsync,\n images: imageState.images,\n addImage: imageState.addImage,\n addImages: imageState.addImages,\n removeImage: imageState.removeImage,\n clearImages: imageState.clearImages,\n threadId: effectiveThreadId,\n setThreadId,\n };\n\n return (\n <TamboV1ThreadInputContext.Provider value={contextValue}>\n {children}\n </TamboV1ThreadInputContext.Provider>\n );\n}\n\n/**\n * Hook to access the shared thread input state.\n *\n * All components using this hook share the same input state, enabling\n * features like suggestions to update the input field directly.\n * @returns The shared thread input context\n * @throws {Error} If used outside TamboV1ThreadInputProvider\n * @example\n * ```tsx\n * function ChatInput() {\n * const { value, setValue, submit, isPending } = useTamboV1ThreadInput();\n *\n * return (\n * <form onSubmit={(e) => { e.preventDefault(); submit(); }}>\n * <input\n * value={value}\n * onChange={(e) => setValue(e.target.value)}\n * disabled={isPending}\n * />\n * <button type=\"submit\" disabled={isPending}>Send</button>\n * </form>\n * );\n * }\n * ```\n */\nexport function useTamboV1ThreadInput(): TamboV1ThreadInputContextProps {\n const context = useContext(TamboV1ThreadInputContext);\n if (!context) {\n throw new Error(\n \"useTamboV1ThreadInput must be used within TamboV1ThreadInputProvider\",\n );\n }\n return context;\n}\n"]}
@@ -5,18 +5,43 @@
5
5
  * Messages use Anthropic-style content blocks pattern where a message
6
6
  * contains an array of content blocks (text, tool calls, tool results, components).
7
7
  */
8
+ import type { ReactElement } from "react";
8
9
  export type { TextContent, ToolUseContent, ToolResultContent, ComponentContent, ResourceContent, } from "@tambo-ai/typescript-sdk/resources/threads/threads";
9
10
  export type { InputMessage } from "@tambo-ai/typescript-sdk/resources/threads/runs";
10
11
  export type { MessageListResponse, MessageGetResponse, } from "@tambo-ai/typescript-sdk/resources/threads/messages";
11
12
  import type { TextContent, ToolUseContent, ToolResultContent, ComponentContent, ResourceContent } from "@tambo-ai/typescript-sdk/resources/threads/threads";
13
+ /**
14
+ * Streaming state for component content blocks.
15
+ * Tracks the lifecycle of component prop/state streaming.
16
+ */
17
+ export type ComponentStreamingState = "started" | "streaming" | "done";
18
+ /**
19
+ * Extended ComponentContent with streaming state and rendered element.
20
+ * Used by the v1 SDK to track component rendering lifecycle.
21
+ */
22
+ export interface V1ComponentContent extends ComponentContent {
23
+ /**
24
+ * Current streaming state of this component's props.
25
+ * - 'started': Component block created, awaiting props
26
+ * - 'streaming': Props are being streamed
27
+ * - 'done': Props streaming complete
28
+ */
29
+ streamingState: ComponentStreamingState;
30
+ /**
31
+ * The rendered React element for this component.
32
+ * undefined if not yet rendered, null if the component couldn't be found in the registry.
33
+ */
34
+ renderedComponent?: ReactElement | null;
35
+ }
12
36
  /**
13
37
  * Message role (from SDK)
14
38
  */
15
39
  export type MessageRole = "user" | "assistant";
16
40
  /**
17
- * Union type of all content block types
41
+ * Union type of all content block types.
42
+ * Uses V1ComponentContent which includes streaming state and rendered component.
18
43
  */
19
- export type Content = TextContent | ToolUseContent | ToolResultContent | ComponentContent | ResourceContent;
44
+ export type Content = TextContent | ToolUseContent | ToolResultContent | V1ComponentContent | ResourceContent;
20
45
  /**
21
46
  * Message in a thread (simplified from SDK's MessageGetResponse)
22
47
  */
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/v1/types/message.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,oDAAoD,CAAC;AAG5D,YAAY,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAEpF,YAAY,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,qDAAqD,CAAC;AAG7D,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,oDAAoD,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,OAAO,GACf,WAAW,GACX,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IAEX,uCAAuC;IACvC,IAAI,EAAE,WAAW,CAAC;IAElB,oCAAoC;IACpC,OAAO,EAAE,OAAO,EAAE,CAAC;IAEnB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAElB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/v1/types/message.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,YAAY,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,oDAAoD,CAAC;AAG5D,YAAY,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAEpF,YAAY,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,qDAAqD,CAAC;AAG7D,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,oDAAoD,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;AAEvE;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D;;;;;OAKG;IACH,cAAc,EAAE,uBAAuB,CAAC;IAExC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,OAAO,GACf,WAAW,GACX,cAAc,GACd,iBAAiB,GACjB,kBAAkB,GAClB,eAAe,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IAEX,uCAAuC;IACvC,IAAI,EAAE,WAAW,CAAC;IAElB,oCAAoC;IACpC,OAAO,EAAE,OAAO,EAAE,CAAC;IAEnB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAElB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/v1/types/message.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Message and Content Types for v1 API\n *\n * Re-exports message and content types from `@tambo-ai/typescript-sdk`.\n * Messages use Anthropic-style content blocks pattern where a message\n * contains an array of content blocks (text, tool calls, tool results, components).\n */\n\n// Re-export content block types from TypeScript SDK\nexport type {\n TextContent,\n ToolUseContent,\n ToolResultContent,\n ComponentContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n// Re-export message types from TypeScript SDK\nexport type { InputMessage } from \"@tambo-ai/typescript-sdk/resources/threads/runs\";\n\nexport type {\n MessageListResponse,\n MessageGetResponse,\n} from \"@tambo-ai/typescript-sdk/resources/threads/messages\";\n\n// Import for Content union type\nimport type {\n TextContent,\n ToolUseContent,\n ToolResultContent,\n ComponentContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n/**\n * Message role (from SDK)\n */\nexport type MessageRole = \"user\" | \"assistant\";\n\n/**\n * Union type of all content block types\n */\nexport type Content =\n | TextContent\n | ToolUseContent\n | ToolResultContent\n | ComponentContent\n | ResourceContent;\n\n/**\n * Message in a thread (simplified from SDK's MessageGetResponse)\n */\nexport interface TamboV1Message {\n /** Unique message identifier */\n id: string;\n\n /** Message role (user or assistant) */\n role: MessageRole;\n\n /** Content blocks in the message */\n content: Content[];\n\n /** When the message was created */\n createdAt: string;\n\n /** Message metadata */\n metadata?: Record<string, unknown>;\n}\n"]}
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/v1/types/message.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Message and Content Types for v1 API\n *\n * Re-exports message and content types from `@tambo-ai/typescript-sdk`.\n * Messages use Anthropic-style content blocks pattern where a message\n * contains an array of content blocks (text, tool calls, tool results, components).\n */\n\nimport type { ReactElement } from \"react\";\n\n// Re-export content block types from TypeScript SDK\nexport type {\n TextContent,\n ToolUseContent,\n ToolResultContent,\n ComponentContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n// Re-export message types from TypeScript SDK\nexport type { InputMessage } from \"@tambo-ai/typescript-sdk/resources/threads/runs\";\n\nexport type {\n MessageListResponse,\n MessageGetResponse,\n} from \"@tambo-ai/typescript-sdk/resources/threads/messages\";\n\n// Import for Content union type\nimport type {\n TextContent,\n ToolUseContent,\n ToolResultContent,\n ComponentContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n/**\n * Streaming state for component content blocks.\n * Tracks the lifecycle of component prop/state streaming.\n */\nexport type ComponentStreamingState = \"started\" | \"streaming\" | \"done\";\n\n/**\n * Extended ComponentContent with streaming state and rendered element.\n * Used by the v1 SDK to track component rendering lifecycle.\n */\nexport interface V1ComponentContent extends ComponentContent {\n /**\n * Current streaming state of this component's props.\n * - 'started': Component block created, awaiting props\n * - 'streaming': Props are being streamed\n * - 'done': Props streaming complete\n */\n streamingState: ComponentStreamingState;\n\n /**\n * The rendered React element for this component.\n * undefined if not yet rendered, null if the component couldn't be found in the registry.\n */\n renderedComponent?: ReactElement | null;\n}\n\n/**\n * Message role (from SDK)\n */\nexport type MessageRole = \"user\" | \"assistant\";\n\n/**\n * Union type of all content block types.\n * Uses V1ComponentContent which includes streaming state and rendered component.\n */\nexport type Content =\n | TextContent\n | ToolUseContent\n | ToolResultContent\n | V1ComponentContent\n | ResourceContent;\n\n/**\n * Message in a thread (simplified from SDK's MessageGetResponse)\n */\nexport interface TamboV1Message {\n /** Unique message identifier */\n id: string;\n\n /** Message role (user or assistant) */\n role: MessageRole;\n\n /** Content blocks in the message */\n content: Content[];\n\n /** When the message was created */\n createdAt: string;\n\n /** Message metadata */\n metadata?: Record<string, unknown>;\n}\n"]}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Component Renderer Utility for v1 API
3
+ *
4
+ * Provides the component content context for rendered components.
5
+ * Components can use useV1ComponentContent() to access their context.
6
+ */
7
+ import React from "react";
8
+ /**
9
+ * Context for component content blocks.
10
+ * Provides access to the component ID and thread ID for component state hooks.
11
+ */
12
+ export interface V1ComponentContentContext {
13
+ /** Component instance ID */
14
+ componentId: string;
15
+ /** Thread ID the component belongs to */
16
+ threadId: string;
17
+ /** Message ID the component belongs to */
18
+ messageId: string;
19
+ /** Component name */
20
+ componentName: string;
21
+ }
22
+ /**
23
+ * Provider for component content context.
24
+ * Wraps rendered components to provide access to component metadata.
25
+ * @returns Provider component with memoized context value
26
+ */
27
+ export declare function V1ComponentContentProvider({ children, componentId, threadId, messageId, componentName, }: V1ComponentContentContext & {
28
+ children: React.ReactNode;
29
+ }): React.JSX.Element;
30
+ /**
31
+ * Hook to access the current component content context.
32
+ * Must be used within a rendered component.
33
+ * @returns Component content context
34
+ * @throws {Error} If used outside a rendered component
35
+ */
36
+ export declare function useV1ComponentContent(): V1ComponentContentContext;
37
+ //# sourceMappingURL=component-renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-renderer.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/component-renderer.tsx"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,OAAO,KAA6C,MAAM,OAAO,CAAC;AAElE;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAMD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,SAAS,EACT,aAAa,GACd,EAAE,yBAAyB,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,qBAY3D;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,yBAAyB,CAQjE"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ "use client";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.V1ComponentContentProvider = V1ComponentContentProvider;
38
+ exports.useV1ComponentContent = useV1ComponentContent;
39
+ /**
40
+ * Component Renderer Utility for v1 API
41
+ *
42
+ * Provides the component content context for rendered components.
43
+ * Components can use useV1ComponentContent() to access their context.
44
+ */
45
+ const react_1 = __importStar(require("react"));
46
+ const ComponentContentContext = (0, react_1.createContext)(null);
47
+ /**
48
+ * Provider for component content context.
49
+ * Wraps rendered components to provide access to component metadata.
50
+ * @returns Provider component with memoized context value
51
+ */
52
+ function V1ComponentContentProvider({ children, componentId, threadId, messageId, componentName, }) {
53
+ // Memoize context value to prevent unnecessary re-renders of consumers
54
+ const value = (0, react_1.useMemo)(() => ({ componentId, threadId, messageId, componentName }), [componentId, threadId, messageId, componentName]);
55
+ return (react_1.default.createElement(ComponentContentContext.Provider, { value: value }, children));
56
+ }
57
+ /**
58
+ * Hook to access the current component content context.
59
+ * Must be used within a rendered component.
60
+ * @returns Component content context
61
+ * @throws {Error} If used outside a rendered component
62
+ */
63
+ function useV1ComponentContent() {
64
+ const context = (0, react_1.useContext)(ComponentContentContext);
65
+ if (!context) {
66
+ throw new Error("useV1ComponentContent must be used within a rendered component");
67
+ }
68
+ return context;
69
+ }
70
+ //# sourceMappingURL=component-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-renderer.js","sourceRoot":"","sources":["../../../src/v1/utils/component-renderer.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCb,gEAkBC;AAQD,sDAQC;AAnED;;;;;GAKG;AAEH,+CAAkE;AAiBlE,MAAM,uBAAuB,GAAG,IAAA,qBAAa,EAC3C,IAAI,CACL,CAAC;AAEF;;;;GAIG;AACH,SAAgB,0BAA0B,CAAC,EACzC,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,SAAS,EACT,aAAa,GAC6C;IAC1D,uEAAuE;IACvE,MAAM,KAAK,GAAG,IAAA,eAAO,EACnB,GAAG,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,EAC3D,CAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,CAAC,CAClD,CAAC;IAEF,OAAO,CACL,8BAAC,uBAAuB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC3C,QAAQ,CACwB,CACpC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB;IACnC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,uBAAuB,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["\"use client\";\n\n/**\n * Component Renderer Utility for v1 API\n *\n * Provides the component content context for rendered components.\n * Components can use useV1ComponentContent() to access their context.\n */\n\nimport React, { createContext, useContext, useMemo } from \"react\";\n\n/**\n * Context for component content blocks.\n * Provides access to the component ID and thread ID for component state hooks.\n */\nexport interface V1ComponentContentContext {\n /** Component instance ID */\n componentId: string;\n /** Thread ID the component belongs to */\n threadId: string;\n /** Message ID the component belongs to */\n messageId: string;\n /** Component name */\n componentName: string;\n}\n\nconst ComponentContentContext = createContext<V1ComponentContentContext | null>(\n null,\n);\n\n/**\n * Provider for component content context.\n * Wraps rendered components to provide access to component metadata.\n * @returns Provider component with memoized context value\n */\nexport function V1ComponentContentProvider({\n children,\n componentId,\n threadId,\n messageId,\n componentName,\n}: V1ComponentContentContext & { children: React.ReactNode }) {\n // Memoize context value to prevent unnecessary re-renders of consumers\n const value = useMemo(\n () => ({ componentId, threadId, messageId, componentName }),\n [componentId, threadId, messageId, componentName],\n );\n\n return (\n <ComponentContentContext.Provider value={value}>\n {children}\n </ComponentContentContext.Provider>\n );\n}\n\n/**\n * Hook to access the current component content context.\n * Must be used within a rendered component.\n * @returns Component content context\n * @throws {Error} If used outside a rendered component\n */\nexport function useV1ComponentContent(): V1ComponentContentContext {\n const context = useContext(ComponentContentContext);\n if (!context) {\n throw new Error(\n \"useV1ComponentContent must be used within a rendered component\",\n );\n }\n return context;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=component-renderer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-renderer.test.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/component-renderer.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const react_2 = require("@testing-library/react");
8
+ const component_renderer_1 = require("./component-renderer");
9
+ // Test component that uses the content context
10
+ const ContextAwareComponent = () => {
11
+ const context = (0, component_renderer_1.useV1ComponentContent)();
12
+ return (react_1.default.createElement("div", { "data-testid": "context-aware" },
13
+ react_1.default.createElement("span", { "data-testid": "componentId" }, context.componentId),
14
+ react_1.default.createElement("span", { "data-testid": "threadId" }, context.threadId),
15
+ react_1.default.createElement("span", { "data-testid": "messageId" }, context.messageId),
16
+ react_1.default.createElement("span", { "data-testid": "componentName" }, context.componentName)));
17
+ };
18
+ describe("V1ComponentContentProvider", () => {
19
+ it("provides context to child components", () => {
20
+ (0, react_2.render)(react_1.default.createElement(component_renderer_1.V1ComponentContentProvider, { componentId: "comp_123", threadId: "thread_456", messageId: "msg_789", componentName: "TestComponent" },
21
+ react_1.default.createElement(ContextAwareComponent, null)));
22
+ expect(react_2.screen.getByTestId("componentId")).toHaveTextContent("comp_123");
23
+ expect(react_2.screen.getByTestId("threadId")).toHaveTextContent("thread_456");
24
+ expect(react_2.screen.getByTestId("messageId")).toHaveTextContent("msg_789");
25
+ expect(react_2.screen.getByTestId("componentName")).toHaveTextContent("TestComponent");
26
+ });
27
+ });
28
+ describe("useV1ComponentContent", () => {
29
+ it("throws when used outside provider", () => {
30
+ function TestConsumer() {
31
+ (0, component_renderer_1.useV1ComponentContent)();
32
+ return react_1.default.createElement("div", null, "Should not render");
33
+ }
34
+ // Suppress React error boundary logs
35
+ const consoleSpy = jest.spyOn(console, "error").mockImplementation();
36
+ expect(() => (0, react_2.render)(react_1.default.createElement(TestConsumer, null))).toThrow("useV1ComponentContent must be used within a rendered component");
37
+ consoleSpy.mockRestore();
38
+ });
39
+ it("returns context when used within provider", () => {
40
+ (0, react_2.render)(react_1.default.createElement(component_renderer_1.V1ComponentContentProvider, { componentId: "comp_test", threadId: "thread_test", messageId: "msg_test", componentName: "TestComp" },
41
+ react_1.default.createElement(ContextAwareComponent, null)));
42
+ expect(react_2.screen.getByTestId("componentId")).toHaveTextContent("comp_test");
43
+ });
44
+ });
45
+ //# sourceMappingURL=component-renderer.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-renderer.test.js","sourceRoot":"","sources":["../../../src/v1/utils/component-renderer.test.tsx"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,kDAAwD;AACxD,6DAG8B;AAE9B,+CAA+C;AAC/C,MAAM,qBAAqB,GAAa,GAAG,EAAE;IAC3C,MAAM,OAAO,GAAG,IAAA,0CAAqB,GAAE,CAAC;IACxC,OAAO,CACL,sDAAiB,eAAe;QAC9B,uDAAkB,aAAa,IAAE,OAAO,CAAC,WAAW,CAAQ;QAC5D,uDAAkB,UAAU,IAAE,OAAO,CAAC,QAAQ,CAAQ;QACtD,uDAAkB,WAAW,IAAE,OAAO,CAAC,SAAS,CAAQ;QACxD,uDAAkB,eAAe,IAAE,OAAO,CAAC,aAAa,CAAQ,CAC5D,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,IAAA,cAAM,EACJ,8BAAC,+CAA0B,IACzB,WAAW,EAAC,UAAU,EACtB,QAAQ,EAAC,YAAY,EACrB,SAAS,EAAC,SAAS,EACnB,aAAa,EAAC,eAAe;YAE7B,8BAAC,qBAAqB,OAAG,CACE,CAC9B,CAAC;QAEF,MAAM,CAAC,cAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACxE,MAAM,CAAC,cAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QACvE,MAAM,CAAC,cAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACrE,MAAM,CAAC,cAAM,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC,iBAAiB,CAC3D,eAAe,CAChB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,SAAS,YAAY;YACnB,IAAA,0CAAqB,GAAE,CAAC;YACxB,OAAO,+DAA4B,CAAC;QACtC,CAAC;QAED,qCAAqC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,kBAAkB,EAAE,CAAC;QAErE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,cAAM,EAAC,8BAAC,YAAY,OAAG,CAAC,CAAC,CAAC,OAAO,CAC5C,gEAAgE,CACjE,CAAC;QAEF,UAAU,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,IAAA,cAAM,EACJ,8BAAC,+CAA0B,IACzB,WAAW,EAAC,WAAW,EACvB,QAAQ,EAAC,aAAa,EACtB,SAAS,EAAC,UAAU,EACpB,aAAa,EAAC,UAAU;YAExB,8BAAC,qBAAqB,OAAG,CACE,CAC9B,CAAC;QAEF,MAAM,CAAC,cAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport { render, screen } from \"@testing-library/react\";\nimport {\n useV1ComponentContent,\n V1ComponentContentProvider,\n} from \"./component-renderer\";\n\n// Test component that uses the content context\nconst ContextAwareComponent: React.FC = () => {\n const context = useV1ComponentContent();\n return (\n <div data-testid=\"context-aware\">\n <span data-testid=\"componentId\">{context.componentId}</span>\n <span data-testid=\"threadId\">{context.threadId}</span>\n <span data-testid=\"messageId\">{context.messageId}</span>\n <span data-testid=\"componentName\">{context.componentName}</span>\n </div>\n );\n};\n\ndescribe(\"V1ComponentContentProvider\", () => {\n it(\"provides context to child components\", () => {\n render(\n <V1ComponentContentProvider\n componentId=\"comp_123\"\n threadId=\"thread_456\"\n messageId=\"msg_789\"\n componentName=\"TestComponent\"\n >\n <ContextAwareComponent />\n </V1ComponentContentProvider>,\n );\n\n expect(screen.getByTestId(\"componentId\")).toHaveTextContent(\"comp_123\");\n expect(screen.getByTestId(\"threadId\")).toHaveTextContent(\"thread_456\");\n expect(screen.getByTestId(\"messageId\")).toHaveTextContent(\"msg_789\");\n expect(screen.getByTestId(\"componentName\")).toHaveTextContent(\n \"TestComponent\",\n );\n });\n});\n\ndescribe(\"useV1ComponentContent\", () => {\n it(\"throws when used outside provider\", () => {\n function TestConsumer() {\n useV1ComponentContent();\n return <div>Should not render</div>;\n }\n\n // Suppress React error boundary logs\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation();\n\n expect(() => render(<TestConsumer />)).toThrow(\n \"useV1ComponentContent must be used within a rendered component\",\n );\n\n consoleSpy.mockRestore();\n });\n\n it(\"returns context when used within provider\", () => {\n render(\n <V1ComponentContentProvider\n componentId=\"comp_test\"\n threadId=\"thread_test\"\n messageId=\"msg_test\"\n componentName=\"TestComp\"\n >\n <ContextAwareComponent />\n </V1ComponentContentProvider>,\n );\n\n expect(screen.getByTestId(\"componentId\")).toHaveTextContent(\"comp_test\");\n });\n});\n"]}