@tambo-ai/react 0.72.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.
- package/dist/v1/hooks/use-tambo-v1-messages.test.js +22 -9
- package/dist/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.js +9 -2
- package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js +22 -9
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts +91 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.js +152 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js +511 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts +6 -57
- package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.js +7 -67
- package/dist/v1/hooks/use-tambo-v1-thread-input.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +201 -72
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts +6 -4
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.js +2 -2
- package/dist/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js +2 -2
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.test.js +16 -7
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/dist/v1/index.d.ts +22 -13
- package/dist/v1/index.d.ts.map +1 -1
- package/dist/v1/index.js +31 -39
- package/dist/v1/index.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.d.ts +27 -9
- package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.js +22 -11
- package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.test.js +27 -10
- package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.d.ts +19 -10
- package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.js +43 -53
- package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.test.js +94 -19
- package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts +74 -0
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-stub-provider.js +212 -0
- package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -0
- package/dist/v1/providers/tambo-v1-stub-provider.test.d.ts +2 -0
- package/dist/v1/providers/tambo-v1-stub-provider.test.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-stub-provider.test.js +162 -0
- package/dist/v1/providers/tambo-v1-stub-provider.test.js.map +1 -0
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts +105 -0
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-thread-input-provider.js +191 -0
- package/dist/v1/providers/tambo-v1-thread-input-provider.js.map +1 -0
- package/dist/v1/utils/component-renderer.d.ts +15 -67
- package/dist/v1/utils/component-renderer.d.ts.map +1 -1
- package/dist/v1/utils/component-renderer.js +3 -149
- package/dist/v1/utils/component-renderer.js.map +1 -1
- package/dist/v1/utils/component-renderer.test.js +15 -350
- package/dist/v1/utils/component-renderer.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.test.js +22 -9
- package/esm/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.js +9 -2
- package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js +22 -9
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts +91 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.js +149 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js +506 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts +6 -57
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.js +5 -66
- package/esm/v1/hooks/use-tambo-v1-thread-input.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +199 -73
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts +6 -4
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.js +2 -2
- package/esm/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js +2 -2
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.test.js +16 -7
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/esm/v1/index.d.ts +22 -13
- package/esm/v1/index.d.ts.map +1 -1
- package/esm/v1/index.js +23 -18
- package/esm/v1/index.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.d.ts +27 -9
- package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.js +20 -10
- package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.test.js +28 -11
- package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.d.ts +19 -10
- package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.js +44 -54
- package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.test.js +95 -20
- package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts +74 -0
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-stub-provider.js +176 -0
- package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -0
- package/esm/v1/providers/tambo-v1-stub-provider.test.d.ts +2 -0
- package/esm/v1/providers/tambo-v1-stub-provider.test.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-stub-provider.test.js +157 -0
- package/esm/v1/providers/tambo-v1-stub-provider.test.js.map +1 -0
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts +105 -0
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-thread-input-provider.js +153 -0
- package/esm/v1/providers/tambo-v1-thread-input-provider.js.map +1 -0
- package/esm/v1/utils/component-renderer.d.ts +15 -67
- package/esm/v1/utils/component-renderer.d.ts.map +1 -1
- package/esm/v1/utils/component-renderer.js +4 -146
- package/esm/v1/utils/component-renderer.js.map +1 -1
- package/esm/v1/utils/component-renderer.test.js +16 -351
- package/esm/v1/utils/component-renderer.test.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { type PropsWithChildren } from "react";
|
|
2
|
+
import type { TamboComponent, TamboTool } from "../../model/component-metadata";
|
|
3
|
+
import type { TamboV1Message } from "../types/message";
|
|
4
|
+
import type { TamboV1Thread } from "../types/thread";
|
|
5
|
+
/**
|
|
6
|
+
* Props for TamboV1StubProvider
|
|
7
|
+
*/
|
|
8
|
+
export interface TamboV1StubProviderProps {
|
|
9
|
+
/**
|
|
10
|
+
* Thread data to display.
|
|
11
|
+
* Can be a full TamboV1Thread or just an array of messages.
|
|
12
|
+
*/
|
|
13
|
+
thread?: TamboV1Thread | {
|
|
14
|
+
messages: TamboV1Message[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Optional thread ID. Defaults to "stub_thread" or thread.id if provided.
|
|
18
|
+
*/
|
|
19
|
+
threadId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Components to register with the registry.
|
|
22
|
+
*/
|
|
23
|
+
components?: TamboComponent[];
|
|
24
|
+
/**
|
|
25
|
+
* Tools to register with the registry.
|
|
26
|
+
*/
|
|
27
|
+
tools?: TamboTool[];
|
|
28
|
+
/**
|
|
29
|
+
* User key for the config context.
|
|
30
|
+
*/
|
|
31
|
+
userKey?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Initial input value for the thread input context.
|
|
34
|
+
*/
|
|
35
|
+
inputValue?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the thread is currently streaming.
|
|
38
|
+
*/
|
|
39
|
+
isStreaming?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Override for the submit function.
|
|
42
|
+
* If not provided, submit will be a no-op that returns the threadId.
|
|
43
|
+
*/
|
|
44
|
+
onSubmit?: () => Promise<{
|
|
45
|
+
threadId: string;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Override for the setValue function.
|
|
49
|
+
*/
|
|
50
|
+
onSetValue?: (value: string | ((prev: string) => string)) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Override for startNewThread.
|
|
53
|
+
*/
|
|
54
|
+
onStartNewThread?: () => string;
|
|
55
|
+
/**
|
|
56
|
+
* Override for switchThread.
|
|
57
|
+
*/
|
|
58
|
+
onSwitchThread?: (threadId: string | null) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Override for initThread.
|
|
61
|
+
*/
|
|
62
|
+
onInitThread?: (threadId: string) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* TamboV1StubProvider provides mock implementations of all v1 contexts
|
|
66
|
+
* for testing components that use Tambo hooks.
|
|
67
|
+
*
|
|
68
|
+
* All operations are no-ops by default, returning stub data.
|
|
69
|
+
* Override specific behaviors via props as needed for testing.
|
|
70
|
+
* Stream state is derived once from props and is not updated by thread management.
|
|
71
|
+
* @returns A provider wrapper suitable for tests
|
|
72
|
+
*/
|
|
73
|
+
export declare function TamboV1StubProvider({ children, thread: threadData, threadId: providedThreadId, components, tools, userKey, inputValue: initialInputValue, isStreaming, onSubmit, onSetValue, onStartNewThread, onSwitchThread, onInitThread, }: PropsWithChildren<TamboV1StubProviderProps>): React.JSX.Element;
|
|
74
|
+
//# sourceMappingURL=tambo-v1-stub-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tambo-v1-stub-provider.d.ts","sourceRoot":"","sources":["../../../src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;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,UAAe,EACf,KAAU,EACV,OAAO,EACP,UAAU,EAAE,iBAAsB,EAClC,WAAmB,EACnB,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,YAAY,GACb,EAAE,iBAAiB,CAAC,wBAAwB,CAAC,qBAwL7C"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
+
import React, { useMemo } from "react";
|
|
4
|
+
import { TamboClientContext } from "../../providers/tambo-client-provider";
|
|
5
|
+
import { TamboRegistryContext } from "../../providers/tambo-registry-provider";
|
|
6
|
+
import { TamboV1ConfigContext } from "./tambo-v1-provider";
|
|
7
|
+
import { TamboV1StreamProvider, } from "./tambo-v1-stream-context";
|
|
8
|
+
import { TamboV1ThreadInputContext, } from "./tambo-v1-thread-input-provider";
|
|
9
|
+
/**
|
|
10
|
+
* Creates a default TamboV1Thread from messages or returns the full thread.
|
|
11
|
+
* @returns A normalized thread object
|
|
12
|
+
*/
|
|
13
|
+
function normalizeThread(threadData, threadId) {
|
|
14
|
+
if (!threadData) {
|
|
15
|
+
return {
|
|
16
|
+
id: threadId,
|
|
17
|
+
messages: [],
|
|
18
|
+
status: "idle",
|
|
19
|
+
createdAt: new Date().toISOString(),
|
|
20
|
+
updatedAt: new Date().toISOString(),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if ("id" in threadData && "status" in threadData) {
|
|
24
|
+
return threadData;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
id: threadId,
|
|
28
|
+
messages: threadData.messages,
|
|
29
|
+
status: "idle",
|
|
30
|
+
createdAt: new Date().toISOString(),
|
|
31
|
+
updatedAt: new Date().toISOString(),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* TamboV1StubProvider provides mock implementations of all v1 contexts
|
|
36
|
+
* for testing components that use Tambo hooks.
|
|
37
|
+
*
|
|
38
|
+
* All operations are no-ops by default, returning stub data.
|
|
39
|
+
* Override specific behaviors via props as needed for testing.
|
|
40
|
+
* Stream state is derived once from props and is not updated by thread management.
|
|
41
|
+
* @returns A provider wrapper suitable for tests
|
|
42
|
+
*/
|
|
43
|
+
export function TamboV1StubProvider({ children, thread: threadData, threadId: providedThreadId, components = [], tools = [], userKey, inputValue: initialInputValue = "", isStreaming = false, onSubmit, onSetValue, onStartNewThread, onSwitchThread, onInitThread, }) {
|
|
44
|
+
// Determine thread ID
|
|
45
|
+
const threadId = providedThreadId ??
|
|
46
|
+
(threadData && "id" in threadData ? threadData.id : "stub_thread");
|
|
47
|
+
// Normalize thread data
|
|
48
|
+
const thread = normalizeThread(threadData, threadId);
|
|
49
|
+
// Create stub QueryClient
|
|
50
|
+
const queryClient = useMemo(() => new QueryClient({
|
|
51
|
+
defaultOptions: {
|
|
52
|
+
queries: { retry: false },
|
|
53
|
+
mutations: { retry: false },
|
|
54
|
+
},
|
|
55
|
+
}), []);
|
|
56
|
+
// Create stub client
|
|
57
|
+
const stubClient = useMemo(() => ({}), []);
|
|
58
|
+
// Build component registry
|
|
59
|
+
const componentList = useMemo(() => {
|
|
60
|
+
const list = {};
|
|
61
|
+
for (const component of components) {
|
|
62
|
+
list[component.name] = {
|
|
63
|
+
component: component.component,
|
|
64
|
+
loadingComponent: component.loadingComponent,
|
|
65
|
+
name: component.name,
|
|
66
|
+
description: component.description,
|
|
67
|
+
props: component.propsDefinition ?? {},
|
|
68
|
+
contextTools: [],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return list;
|
|
72
|
+
}, [components]);
|
|
73
|
+
// Build tool registry
|
|
74
|
+
const toolRegistry = useMemo(() => {
|
|
75
|
+
return tools.reduce((acc, tool) => {
|
|
76
|
+
acc[tool.name] = tool;
|
|
77
|
+
return acc;
|
|
78
|
+
}, {});
|
|
79
|
+
}, [tools]);
|
|
80
|
+
// Stream state
|
|
81
|
+
const streamState = useMemo(() => {
|
|
82
|
+
const threadState = {
|
|
83
|
+
thread,
|
|
84
|
+
streaming: {
|
|
85
|
+
status: isStreaming ? "streaming" : "idle",
|
|
86
|
+
},
|
|
87
|
+
accumulatingToolArgs: new Map(),
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
threadMap: { [threadId]: threadState },
|
|
91
|
+
currentThreadId: threadId,
|
|
92
|
+
};
|
|
93
|
+
}, [thread, threadId, isStreaming]);
|
|
94
|
+
// Stream dispatch (no-op)
|
|
95
|
+
const streamDispatch = useMemo(() => () => { }, []);
|
|
96
|
+
// Thread management
|
|
97
|
+
const threadManagement = useMemo(() => ({
|
|
98
|
+
initThread: onInitThread ?? (() => { }),
|
|
99
|
+
switchThread: onSwitchThread ?? (() => { }),
|
|
100
|
+
startNewThread: onStartNewThread ??
|
|
101
|
+
(() => {
|
|
102
|
+
const newId = `stub_${crypto.randomUUID()}`;
|
|
103
|
+
return newId;
|
|
104
|
+
}),
|
|
105
|
+
}), [onInitThread, onSwitchThread, onStartNewThread]);
|
|
106
|
+
// Config context
|
|
107
|
+
const config = useMemo(() => ({ userKey }), [userKey]);
|
|
108
|
+
// Input state (managed internally for stub)
|
|
109
|
+
const [inputValue, setInputValueInternal] = React.useState(initialInputValue);
|
|
110
|
+
// Thread input context
|
|
111
|
+
const threadInputContext = useMemo(() => {
|
|
112
|
+
const setValue = onSetValue ?? setInputValueInternal;
|
|
113
|
+
const submit = onSubmit ??
|
|
114
|
+
(async () => {
|
|
115
|
+
return { threadId };
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
value: inputValue,
|
|
119
|
+
setValue,
|
|
120
|
+
submit,
|
|
121
|
+
threadId,
|
|
122
|
+
setThreadId: () => { },
|
|
123
|
+
images: [],
|
|
124
|
+
addImage: async () => { },
|
|
125
|
+
addImages: async () => { },
|
|
126
|
+
removeImage: () => { },
|
|
127
|
+
clearImages: () => { },
|
|
128
|
+
isPending: false,
|
|
129
|
+
isError: false,
|
|
130
|
+
error: null,
|
|
131
|
+
isIdle: true,
|
|
132
|
+
isSuccess: false,
|
|
133
|
+
status: "idle",
|
|
134
|
+
data: undefined,
|
|
135
|
+
variables: undefined,
|
|
136
|
+
failureCount: 0,
|
|
137
|
+
failureReason: null,
|
|
138
|
+
reset: () => { },
|
|
139
|
+
context: undefined,
|
|
140
|
+
submittedAt: 0,
|
|
141
|
+
isPaused: false,
|
|
142
|
+
};
|
|
143
|
+
}, [inputValue, threadId, onSubmit, onSetValue, setInputValueInternal]);
|
|
144
|
+
// Registry context
|
|
145
|
+
const registryContext = useMemo(() => ({
|
|
146
|
+
componentList,
|
|
147
|
+
toolRegistry,
|
|
148
|
+
componentToolAssociations: {},
|
|
149
|
+
mcpServerInfos: [],
|
|
150
|
+
resources: [],
|
|
151
|
+
resourceSource: null,
|
|
152
|
+
onCallUnregisteredTool: undefined,
|
|
153
|
+
registerComponent: () => { },
|
|
154
|
+
registerTool: () => { },
|
|
155
|
+
registerTools: () => { },
|
|
156
|
+
addToolAssociation: () => { },
|
|
157
|
+
registerMcpServer: () => { },
|
|
158
|
+
registerMcpServers: () => { },
|
|
159
|
+
registerResource: () => { },
|
|
160
|
+
registerResources: () => { },
|
|
161
|
+
registerResourceSource: () => { },
|
|
162
|
+
}), [componentList, toolRegistry]);
|
|
163
|
+
// Client context
|
|
164
|
+
const clientContext = useMemo(() => ({
|
|
165
|
+
client: stubClient,
|
|
166
|
+
queryClient,
|
|
167
|
+
isUpdatingToken: false,
|
|
168
|
+
}), [stubClient, queryClient]);
|
|
169
|
+
return (React.createElement(QueryClientProvider, { client: queryClient },
|
|
170
|
+
React.createElement(TamboClientContext.Provider, { value: clientContext },
|
|
171
|
+
React.createElement(TamboRegistryContext.Provider, { value: registryContext },
|
|
172
|
+
React.createElement(TamboV1ConfigContext.Provider, { value: config },
|
|
173
|
+
React.createElement(TamboV1StreamProvider, { state: streamState, dispatch: streamDispatch, threadManagement: threadManagement },
|
|
174
|
+
React.createElement(TamboV1ThreadInputContext.Provider, { value: threadInputContext }, children)))))));
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=tambo-v1-stub-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tambo-v1-stub-provider.js","sourceRoot":"","sources":["../../../src/v1/providers/tambo-v1-stub-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AA+Bb,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,KAAK,EAAE,EAAE,OAAO,EAA0B,MAAM,OAAO,CAAC;AAM/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAQ/E,OAAO,EAAE,oBAAoB,EAAsB,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,yBAAyB,GAE1B,MAAM,kCAAkC,CAAC;AAqE1C;;;GAGG;AACH,SAAS,eAAe,CACtB,UAAsE,EACtE,QAAgB;IAEhB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;YACL,EAAE,EAAE,QAAQ;YACZ,QAAQ,EAAE,EAAE;YACZ,MAAM,EAAE,MAAM;YACd,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,IAAI,UAAU,IAAI,QAAQ,IAAI,UAAU,EAAE,CAAC;QACjD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO;QACL,EAAE,EAAE,QAAQ;QACZ,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,MAAM,EAAE,MAAM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AE,KAAK;KACvB,CAAC,EACF,CAAC,UAAU,EAAE,WAAW,CAAC,CAC1B,CAAC;IAEF,OAAO,CACL,oBAAC,mBAAmB,IAAC,MAAM,EAAE,WAAW;QACtC,oBAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,aAAa;YAC/C,oBAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe;gBACnD,oBAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,MAAM;oBAC1C,oBAAC,qBAAqB,IACpB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,cAAc,EACxB,gBAAgB,EAAE,gBAAgB;wBAElC,oBAAC,yBAAyB,CAAC,QAAQ,IAAC,KAAK,EAAE,kBAAkB,IAC1D,QAAQ,CAC0B,CACf,CACM,CACF,CACJ,CACV,CACvB,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\n/**\n * TamboV1StubProvider - Mock Provider for Testing\n *\n * Provides stubbed versions of all v1 contexts for testing components\n * that use Tambo hooks without making real API calls.\n * @example\n * ```tsx\n * const mockThread = {\n * id: \"thread_123\",\n * messages: [\n * { id: \"msg_1\", role: \"user\", content: [{ type: \"text\", text: \"Hello\" }], createdAt: \"...\" },\n * { id: \"msg_2\", role: \"assistant\", content: [{ type: \"text\", text: \"Hi!\" }], createdAt: \"...\" },\n * ],\n * status: \"idle\",\n * createdAt: \"2024-01-01T00:00:00Z\",\n * updatedAt: \"2024-01-01T00:00:00Z\",\n * };\n *\n * function TestComponent() {\n * return (\n * <TamboV1StubProvider thread={mockThread}>\n * <MyComponent />\n * </TamboV1StubProvider>\n * );\n * }\n * ```\n */\n\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport React, { useMemo, type PropsWithChildren } from \"react\";\nimport type {\n TamboComponent,\n TamboTool,\n TamboToolRegistry,\n} from \"../../model/component-metadata\";\nimport { TamboClientContext } from \"../../providers/tambo-client-provider\";\nimport { TamboRegistryContext } from \"../../providers/tambo-registry-provider\";\nimport type { TamboV1Message } from \"../types/message\";\nimport type { TamboV1Thread } from \"../types/thread\";\nimport type {\n StreamAction,\n StreamState,\n ThreadState,\n} from \"../utils/event-accumulator\";\nimport { TamboV1ConfigContext, type TamboV1Config } from \"./tambo-v1-provider\";\nimport {\n TamboV1StreamProvider,\n type ThreadManagement,\n} from \"./tambo-v1-stream-context\";\nimport {\n TamboV1ThreadInputContext,\n type TamboV1ThreadInputContextProps,\n} from \"./tambo-v1-thread-input-provider\";\n\n/**\n * Props for TamboV1StubProvider\n */\nexport interface TamboV1StubProviderProps {\n /**\n * Thread data to display.\n * Can be a full TamboV1Thread or just an array of messages.\n */\n thread?: TamboV1Thread | { messages: TamboV1Message[] };\n\n /**\n * Optional thread ID. Defaults to \"stub_thread\" or thread.id if provided.\n */\n threadId?: string;\n\n /**\n * Components to register with the registry.\n */\n components?: TamboComponent[];\n\n /**\n * Tools to register with the registry.\n */\n tools?: TamboTool[];\n\n /**\n * User key for the config context.\n */\n userKey?: string;\n\n /**\n * Initial input value for the thread input context.\n */\n inputValue?: string;\n\n /**\n * Whether the thread is currently streaming.\n */\n isStreaming?: boolean;\n\n /**\n * Override for the submit function.\n * If not provided, submit will be a no-op that returns the threadId.\n */\n onSubmit?: () => Promise<{ threadId: string }>;\n\n /**\n * Override for the setValue function.\n */\n onSetValue?: (value: string | ((prev: string) => string)) => void;\n\n /**\n * Override for startNewThread.\n */\n onStartNewThread?: () => string;\n\n /**\n * Override for switchThread.\n */\n onSwitchThread?: (threadId: string | null) => void;\n\n /**\n * Override for initThread.\n */\n onInitThread?: (threadId: string) => void;\n}\n\n/**\n * Creates a default TamboV1Thread from messages or returns the full thread.\n * @returns A normalized thread object\n */\nfunction normalizeThread(\n threadData: TamboV1Thread | { messages: TamboV1Message[] } | undefined,\n threadId: string,\n): TamboV1Thread {\n if (!threadData) {\n return {\n id: threadId,\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n };\n }\n\n if (\"id\" in threadData && \"status\" in threadData) {\n return threadData;\n }\n\n return {\n id: threadId,\n messages: threadData.messages,\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n };\n}\n\n/**\n * TamboV1StubProvider provides mock implementations of all v1 contexts\n * for testing components that use Tambo hooks.\n *\n * All operations are no-ops by default, returning stub data.\n * Override specific behaviors via props as needed for testing.\n * Stream state is derived once from props and is not updated by thread management.\n * @returns A provider wrapper suitable for tests\n */\nexport function TamboV1StubProvider({\n children,\n thread: threadData,\n threadId: providedThreadId,\n components = [],\n tools = [],\n userKey,\n inputValue: initialInputValue = \"\",\n isStreaming = false,\n onSubmit,\n onSetValue,\n onStartNewThread,\n onSwitchThread,\n onInitThread,\n}: PropsWithChildren<TamboV1StubProviderProps>) {\n // Determine thread ID\n const threadId =\n providedThreadId ??\n (threadData && \"id\" in threadData ? threadData.id : \"stub_thread\");\n\n // Normalize thread data\n const thread = normalizeThread(threadData, threadId);\n\n // Create stub QueryClient\n const queryClient = useMemo(\n () =>\n new QueryClient({\n defaultOptions: {\n queries: { retry: false },\n mutations: { retry: false },\n },\n }),\n [],\n );\n\n // Create stub client\n const stubClient = useMemo(() => ({}) as TamboAI, []);\n\n // Build component registry\n const componentList = useMemo(() => {\n const list: TamboRegistryContext[\"componentList\"] = {};\n\n for (const component of components) {\n list[component.name] = {\n component: component.component,\n loadingComponent: component.loadingComponent,\n name: component.name,\n description: component.description,\n props: component.propsDefinition ?? {},\n contextTools: [],\n };\n }\n\n return list;\n }, [components]);\n\n // Build tool registry\n const toolRegistry = useMemo(() => {\n return tools.reduce((acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n }, {} as TamboToolRegistry);\n }, [tools]);\n\n // Stream state\n const streamState = useMemo<StreamState>(() => {\n const threadState: ThreadState = {\n thread,\n streaming: {\n status: isStreaming ? \"streaming\" : \"idle\",\n },\n accumulatingToolArgs: new Map(),\n };\n\n return {\n threadMap: { [threadId]: threadState },\n currentThreadId: threadId,\n };\n }, [thread, threadId, isStreaming]);\n\n // Stream dispatch (no-op)\n const streamDispatch = useMemo<React.Dispatch<StreamAction>>(\n () => () => {},\n [],\n );\n\n // Thread management\n const threadManagement = useMemo<ThreadManagement>(\n () => ({\n initThread: onInitThread ?? (() => {}),\n switchThread: onSwitchThread ?? (() => {}),\n startNewThread:\n onStartNewThread ??\n (() => {\n const newId = `stub_${crypto.randomUUID()}`;\n return newId;\n }),\n }),\n [onInitThread, onSwitchThread, onStartNewThread],\n );\n\n // Config context\n const config = useMemo<TamboV1Config>(() => ({ userKey }), [userKey]);\n\n // Input state (managed internally for stub)\n const [inputValue, setInputValueInternal] = React.useState(initialInputValue);\n\n // Thread input context\n const threadInputContext = useMemo<TamboV1ThreadInputContextProps>(() => {\n const setValue: React.Dispatch<React.SetStateAction<string>> =\n onSetValue ?? setInputValueInternal;\n\n const submit: TamboV1ThreadInputContextProps[\"submit\"] =\n onSubmit ??\n (async () => {\n return { threadId };\n });\n\n return {\n value: inputValue,\n setValue,\n submit,\n threadId,\n setThreadId: () => {},\n images: [],\n addImage: async () => {},\n addImages: async () => {},\n removeImage: () => {},\n clearImages: () => {},\n isPending: false,\n isError: false,\n error: null,\n isIdle: true,\n isSuccess: false,\n status: \"idle\",\n data: undefined,\n variables: undefined,\n failureCount: 0,\n failureReason: null,\n reset: () => {},\n context: undefined,\n submittedAt: 0,\n isPaused: false,\n };\n }, [inputValue, threadId, onSubmit, onSetValue, setInputValueInternal]);\n\n // Registry context\n const registryContext = useMemo<TamboRegistryContext>(\n () => ({\n componentList,\n toolRegistry,\n componentToolAssociations: {},\n mcpServerInfos: [],\n resources: [],\n resourceSource: null,\n onCallUnregisteredTool: undefined,\n registerComponent: () => {},\n registerTool: () => {},\n registerTools: () => {},\n addToolAssociation: () => {},\n registerMcpServer: () => {},\n registerMcpServers: () => {},\n registerResource: () => {},\n registerResources: () => {},\n registerResourceSource: () => {},\n }),\n [componentList, toolRegistry],\n );\n\n // Client context\n const clientContext = useMemo(\n () => ({\n client: stubClient,\n queryClient,\n isUpdatingToken: false,\n }),\n [stubClient, queryClient],\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <TamboClientContext.Provider value={clientContext}>\n <TamboRegistryContext.Provider value={registryContext}>\n <TamboV1ConfigContext.Provider value={config}>\n <TamboV1StreamProvider\n state={streamState}\n dispatch={streamDispatch}\n threadManagement={threadManagement}\n >\n <TamboV1ThreadInputContext.Provider value={threadInputContext}>\n {children}\n </TamboV1ThreadInputContext.Provider>\n </TamboV1StreamProvider>\n </TamboV1ConfigContext.Provider>\n </TamboRegistryContext.Provider>\n </TamboClientContext.Provider>\n </QueryClientProvider>\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tambo-v1-stub-provider.test.d.ts","sourceRoot":"","sources":["../../../src/v1/providers/tambo-v1-stub-provider.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { TamboV1StubProvider } from "./tambo-v1-stub-provider";
|
|
4
|
+
import { useTamboV1 } from "../hooks/use-tambo-v1";
|
|
5
|
+
import { useTamboV1ThreadInput } from "../hooks/use-tambo-v1-thread-input";
|
|
6
|
+
import { useTamboRegistry } from "../../providers/tambo-registry-provider";
|
|
7
|
+
import { useTamboClient } from "../../providers/tambo-client-provider";
|
|
8
|
+
describe("TamboV1StubProvider", () => {
|
|
9
|
+
const mockThread = {
|
|
10
|
+
id: "thread_123",
|
|
11
|
+
messages: [
|
|
12
|
+
{
|
|
13
|
+
id: "msg_1",
|
|
14
|
+
role: "user",
|
|
15
|
+
content: [{ type: "text", text: "Hello" }],
|
|
16
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "msg_2",
|
|
20
|
+
role: "assistant",
|
|
21
|
+
content: [{ type: "text", text: "Hi there!" }],
|
|
22
|
+
createdAt: "2024-01-01T00:00:01Z",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
status: "idle",
|
|
26
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
27
|
+
updatedAt: "2024-01-01T00:00:01Z",
|
|
28
|
+
};
|
|
29
|
+
describe("useTamboV1", () => {
|
|
30
|
+
it("provides thread data via useTamboV1", () => {
|
|
31
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread }, children));
|
|
32
|
+
const { result } = renderHook(() => useTamboV1("thread_123"), {
|
|
33
|
+
wrapper,
|
|
34
|
+
});
|
|
35
|
+
expect(result.current.messages).toHaveLength(2);
|
|
36
|
+
expect(result.current.messages[0].id).toBe("msg_1");
|
|
37
|
+
expect(result.current.messages[1].id).toBe("msg_2");
|
|
38
|
+
expect(result.current.isIdle).toBe(true);
|
|
39
|
+
expect(result.current.isStreaming).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
it("returns empty messages when no thread provided", () => {
|
|
42
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, null, children));
|
|
43
|
+
const { result } = renderHook(() => useTamboV1("stub_thread"), {
|
|
44
|
+
wrapper,
|
|
45
|
+
});
|
|
46
|
+
expect(result.current.messages).toHaveLength(0);
|
|
47
|
+
expect(result.current.isIdle).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
it("shows streaming state when isStreaming prop is true", () => {
|
|
50
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread, isStreaming: true }, children));
|
|
51
|
+
const { result } = renderHook(() => useTamboV1("thread_123"), {
|
|
52
|
+
wrapper,
|
|
53
|
+
});
|
|
54
|
+
expect(result.current.isStreaming).toBe(true);
|
|
55
|
+
expect(result.current.isIdle).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe("useTamboV1ThreadInput", () => {
|
|
59
|
+
it("provides thread input context", () => {
|
|
60
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread }, children));
|
|
61
|
+
const { result } = renderHook(() => useTamboV1ThreadInput(), { wrapper });
|
|
62
|
+
expect(result.current.value).toBe("");
|
|
63
|
+
expect(result.current.threadId).toBe("thread_123");
|
|
64
|
+
expect(typeof result.current.setValue).toBe("function");
|
|
65
|
+
expect(typeof result.current.submit).toBe("function");
|
|
66
|
+
});
|
|
67
|
+
it("uses initial input value when provided", () => {
|
|
68
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread, inputValue: "Hello world" }, children));
|
|
69
|
+
const { result } = renderHook(() => useTamboV1ThreadInput(), { wrapper });
|
|
70
|
+
expect(result.current.value).toBe("Hello world");
|
|
71
|
+
});
|
|
72
|
+
it("calls custom onSubmit when provided", async () => {
|
|
73
|
+
const mockOnSubmit = jest
|
|
74
|
+
.fn()
|
|
75
|
+
.mockResolvedValue({ threadId: "new_thread" });
|
|
76
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread, onSubmit: mockOnSubmit }, children));
|
|
77
|
+
const { result } = renderHook(() => useTamboV1ThreadInput(), { wrapper });
|
|
78
|
+
const response = await result.current.submit();
|
|
79
|
+
expect(mockOnSubmit).toHaveBeenCalled();
|
|
80
|
+
expect(response.threadId).toBe("new_thread");
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe("Registry", () => {
|
|
84
|
+
it("registers provided components", () => {
|
|
85
|
+
const TestComponent = () => React.createElement("div", null, "Test");
|
|
86
|
+
const components = [
|
|
87
|
+
{
|
|
88
|
+
name: "TestComponent",
|
|
89
|
+
description: "A test component",
|
|
90
|
+
component: TestComponent,
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread, components: components }, children));
|
|
94
|
+
const { result } = renderHook(() => useTamboRegistry(), { wrapper });
|
|
95
|
+
expect(result.current.componentList.TestComponent).toBeDefined();
|
|
96
|
+
expect(result.current.componentList.TestComponent.name).toBe("TestComponent");
|
|
97
|
+
});
|
|
98
|
+
it("registers provided tools", () => {
|
|
99
|
+
const tools = [
|
|
100
|
+
{
|
|
101
|
+
name: "testTool",
|
|
102
|
+
description: "A test tool",
|
|
103
|
+
tool: async () => "result",
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread, tools: tools }, children));
|
|
107
|
+
const { result } = renderHook(() => useTamboRegistry(), { wrapper });
|
|
108
|
+
expect(result.current.toolRegistry.testTool).toBeDefined();
|
|
109
|
+
expect(result.current.toolRegistry.testTool.name).toBe("testTool");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe("Client", () => {
|
|
113
|
+
it("provides stub client", () => {
|
|
114
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread }, children));
|
|
115
|
+
const { result } = renderHook(() => useTamboClient(), { wrapper });
|
|
116
|
+
expect(result.current).toBeDefined();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe("Thread management", () => {
|
|
120
|
+
it("provides thread management functions", () => {
|
|
121
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread }, children));
|
|
122
|
+
const { result } = renderHook(() => useTamboV1("thread_123"), {
|
|
123
|
+
wrapper,
|
|
124
|
+
});
|
|
125
|
+
expect(typeof result.current.startNewThread).toBe("function");
|
|
126
|
+
expect(typeof result.current.switchThread).toBe("function");
|
|
127
|
+
expect(typeof result.current.initThread).toBe("function");
|
|
128
|
+
});
|
|
129
|
+
it("calls custom onStartNewThread when provided", () => {
|
|
130
|
+
const mockStartNewThread = jest.fn().mockReturnValue("custom_thread_id");
|
|
131
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: mockThread, onStartNewThread: mockStartNewThread }, children));
|
|
132
|
+
const { result } = renderHook(() => useTamboV1("thread_123"), {
|
|
133
|
+
wrapper,
|
|
134
|
+
});
|
|
135
|
+
const newThreadId = result.current.startNewThread();
|
|
136
|
+
expect(mockStartNewThread).toHaveBeenCalled();
|
|
137
|
+
expect(newThreadId).toBe("custom_thread_id");
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe("Messages-only thread", () => {
|
|
141
|
+
it("accepts just messages array instead of full thread", () => {
|
|
142
|
+
const messages = [
|
|
143
|
+
{
|
|
144
|
+
id: "msg_1",
|
|
145
|
+
role: "user",
|
|
146
|
+
content: [{ type: "text", text: "Hello" }],
|
|
147
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
const wrapper = ({ children }) => (React.createElement(TamboV1StubProvider, { thread: { messages }, threadId: "custom_id" }, children));
|
|
151
|
+
const { result } = renderHook(() => useTamboV1("custom_id"), { wrapper });
|
|
152
|
+
expect(result.current.messages).toHaveLength(1);
|
|
153
|
+
expect(result.current.messages[0].id).toBe("msg_1");
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
//# sourceMappingURL=tambo-v1-stub-provider.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tambo-v1-stub-provider.test.js","sourceRoot":"","sources":["../../../src/v1/providers/tambo-v1-stub-provider.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAGvE,QAAQ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CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport React from \"react\";\nimport { TamboV1StubProvider } from \"./tambo-v1-stub-provider\";\nimport { useTamboV1 } from \"../hooks/use-tambo-v1\";\nimport { useTamboV1ThreadInput } from \"../hooks/use-tambo-v1-thread-input\";\nimport { useTamboRegistry } from \"../../providers/tambo-registry-provider\";\nimport { useTamboClient } from \"../../providers/tambo-client-provider\";\nimport type { TamboV1Thread } from \"../types/thread\";\n\ndescribe(\"TamboV1StubProvider\", () => {\n const mockThread: TamboV1Thread = {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"user\",\n content: [{ type: \"text\", text: \"Hello\" }],\n createdAt: \"2024-01-01T00:00:00Z\",\n },\n {\n id: \"msg_2\",\n role: \"assistant\",\n content: [{ type: \"text\", text: \"Hi there!\" }],\n createdAt: \"2024-01-01T00:00:01Z\",\n },\n ],\n status: \"idle\",\n createdAt: \"2024-01-01T00:00:00Z\",\n updatedAt: \"2024-01-01T00:00:01Z\",\n };\n\n describe(\"useTamboV1\", () => {\n it(\"provides thread data via useTamboV1\", () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread}>\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1(\"thread_123\"), {\n wrapper,\n });\n\n expect(result.current.messages).toHaveLength(2);\n expect(result.current.messages[0].id).toBe(\"msg_1\");\n expect(result.current.messages[1].id).toBe(\"msg_2\");\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n });\n\n it(\"returns empty messages when no thread provided\", () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider>{children}</TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1(\"stub_thread\"), {\n wrapper,\n });\n\n expect(result.current.messages).toHaveLength(0);\n expect(result.current.isIdle).toBe(true);\n });\n\n it(\"shows streaming state when isStreaming prop is true\", () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread} isStreaming>\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1(\"thread_123\"), {\n wrapper,\n });\n\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.isIdle).toBe(false);\n });\n });\n\n describe(\"useTamboV1ThreadInput\", () => {\n it(\"provides thread input context\", () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread}>\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1ThreadInput(), { wrapper });\n\n expect(result.current.value).toBe(\"\");\n expect(result.current.threadId).toBe(\"thread_123\");\n expect(typeof result.current.setValue).toBe(\"function\");\n expect(typeof result.current.submit).toBe(\"function\");\n });\n\n it(\"uses initial input value when provided\", () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread} inputValue=\"Hello world\">\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1ThreadInput(), { wrapper });\n\n expect(result.current.value).toBe(\"Hello world\");\n });\n\n it(\"calls custom onSubmit when provided\", async () => {\n const mockOnSubmit = jest\n .fn()\n .mockResolvedValue({ threadId: \"new_thread\" });\n\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread} onSubmit={mockOnSubmit}>\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1ThreadInput(), { wrapper });\n\n const response = await result.current.submit();\n\n expect(mockOnSubmit).toHaveBeenCalled();\n expect(response.threadId).toBe(\"new_thread\");\n });\n });\n\n describe(\"Registry\", () => {\n it(\"registers provided components\", () => {\n const TestComponent = () => <div>Test</div>;\n const components = [\n {\n name: \"TestComponent\",\n description: \"A test component\",\n component: TestComponent,\n },\n ];\n\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread} components={components}>\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboRegistry(), { wrapper });\n\n expect(result.current.componentList.TestComponent).toBeDefined();\n expect(result.current.componentList.TestComponent.name).toBe(\n \"TestComponent\",\n );\n });\n\n it(\"registers provided tools\", () => {\n const tools = [\n {\n name: \"testTool\",\n description: \"A test tool\",\n tool: async () => \"result\",\n },\n ];\n\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread} tools={tools as any}>\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboRegistry(), { wrapper });\n\n expect(result.current.toolRegistry.testTool).toBeDefined();\n expect(result.current.toolRegistry.testTool.name).toBe(\"testTool\");\n });\n });\n\n describe(\"Client\", () => {\n it(\"provides stub client\", () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread}>\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboClient(), { wrapper });\n\n expect(result.current).toBeDefined();\n });\n });\n\n describe(\"Thread management\", () => {\n it(\"provides thread management functions\", () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={mockThread}>\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1(\"thread_123\"), {\n wrapper,\n });\n\n expect(typeof result.current.startNewThread).toBe(\"function\");\n expect(typeof result.current.switchThread).toBe(\"function\");\n expect(typeof result.current.initThread).toBe(\"function\");\n });\n\n it(\"calls custom onStartNewThread when provided\", () => {\n const mockStartNewThread = jest.fn().mockReturnValue(\"custom_thread_id\");\n\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider\n thread={mockThread}\n onStartNewThread={mockStartNewThread}\n >\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1(\"thread_123\"), {\n wrapper,\n });\n\n const newThreadId = result.current.startNewThread();\n\n expect(mockStartNewThread).toHaveBeenCalled();\n expect(newThreadId).toBe(\"custom_thread_id\");\n });\n });\n\n describe(\"Messages-only thread\", () => {\n it(\"accepts just messages array instead of full thread\", () => {\n const messages = [\n {\n id: \"msg_1\",\n role: \"user\" as const,\n content: [{ type: \"text\" as const, text: \"Hello\" }],\n createdAt: \"2024-01-01T00:00:00Z\",\n },\n ];\n\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboV1StubProvider thread={{ messages }} threadId=\"custom_id\">\n {children}\n </TamboV1StubProvider>\n );\n\n const { result } = renderHook(() => useTamboV1(\"custom_id\"), { wrapper });\n\n expect(result.current.messages).toHaveLength(1);\n expect(result.current.messages[0].id).toBe(\"msg_1\");\n });\n });\n});\n"]}
|
|
@@ -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,CAA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