@tambo-ai/react 0.43.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/__tests__/use-suggestions.test.js +55 -27
- package/dist/hooks/__tests__/use-suggestions.test.js.map +1 -1
- package/dist/hooks/__tests__/use-tambo-stream-status.test.js +82 -39
- package/dist/hooks/__tests__/use-tambo-stream-status.test.js.map +1 -1
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/use-component-state.d.ts.map +1 -1
- package/dist/hooks/use-component-state.js +2 -2
- package/dist/hooks/use-component-state.js.map +1 -1
- package/dist/hooks/use-current-message.d.ts +12 -27
- package/dist/hooks/use-current-message.d.ts.map +1 -1
- package/dist/hooks/use-current-message.js +16 -36
- package/dist/hooks/use-current-message.js.map +1 -1
- package/dist/hooks/use-tambo-stream-status.js +1 -1
- package/dist/hooks/use-tambo-stream-status.js.map +1 -1
- package/dist/hooks/use-thread-input.js +3 -2
- package/dist/hooks/use-thread-input.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/providers/__tests__/tambo-prop-stream-provider.test.js +79 -9
- package/dist/providers/__tests__/tambo-prop-stream-provider.test.js.map +1 -1
- package/dist/providers/__tests__/tambo-thread-provider.test.js +0 -7
- package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/tambo-provider.d.ts +2 -2
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-stubs.d.ts.map +1 -1
- package/dist/providers/tambo-stubs.js +6 -6
- package/dist/providers/tambo-stubs.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts +29 -11
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +59 -28
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/dist/util/generate-component.d.ts.map +1 -1
- package/dist/util/generate-component.js +6 -2
- package/dist/util/generate-component.js.map +1 -1
- package/esm/hooks/__tests__/use-suggestions.test.js +55 -27
- package/esm/hooks/__tests__/use-suggestions.test.js.map +1 -1
- package/esm/hooks/__tests__/use-tambo-stream-status.test.js +82 -39
- package/esm/hooks/__tests__/use-tambo-stream-status.test.js.map +1 -1
- package/esm/hooks/index.d.ts +2 -2
- package/esm/hooks/index.d.ts.map +1 -1
- package/esm/hooks/index.js +2 -2
- package/esm/hooks/index.js.map +1 -1
- package/esm/hooks/use-component-state.d.ts.map +1 -1
- package/esm/hooks/use-component-state.js +3 -3
- package/esm/hooks/use-component-state.js.map +1 -1
- package/esm/hooks/use-current-message.d.ts +12 -27
- package/esm/hooks/use-current-message.d.ts.map +1 -1
- package/esm/hooks/use-current-message.js +15 -34
- package/esm/hooks/use-current-message.js.map +1 -1
- package/esm/hooks/use-tambo-stream-status.js +2 -2
- package/esm/hooks/use-tambo-stream-status.js.map +1 -1
- package/esm/hooks/use-thread-input.js +4 -3
- package/esm/hooks/use-thread-input.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/providers/__tests__/tambo-prop-stream-provider.test.js +80 -10
- package/esm/providers/__tests__/tambo-prop-stream-provider.test.js.map +1 -1
- package/esm/providers/__tests__/tambo-thread-provider.test.js +0 -7
- package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/esm/providers/index.d.ts +1 -1
- package/esm/providers/index.d.ts.map +1 -1
- package/esm/providers/index.js +1 -1
- package/esm/providers/index.js.map +1 -1
- package/esm/providers/tambo-provider.d.ts +2 -2
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-stubs.d.ts.map +1 -1
- package/esm/providers/tambo-stubs.js +7 -7
- package/esm/providers/tambo-stubs.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts +29 -11
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +56 -27
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/esm/util/generate-component.d.ts.map +1 -1
- package/esm/util/generate-component.js +6 -2
- package/esm/util/generate-component.js.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAEL,mBAAmB,EAEnB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,2BAA2B,EAE3B,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAEL,mBAAmB,EAEnB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sB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AAG,cAAc,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,MAAM,iBAAiB,GAAG,iBAAiB,EAAE,CAAC;IAC9C,MAAM,sBAAsB,GAAG,oBAAoB,EAAE,CAAC;IACtD,MAAM,cAAc,GAAG,sBAAsB,EAAE,CAAC;IAEhD,OAAO,CACL,oBAAC,YAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;SAClB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, the current thread context, and interactable components.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n contextHelpers,\n}) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider components={components} tools={tools}>\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider streaming={streaming}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-stubs.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAE/C,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpD,OAAO,EAEL,gCAAgC,EACjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"tambo-stubs.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAE/C,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpD,OAAO,EAEL,gCAAgC,EACjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAQ1B;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IACxE,2CAA2C;IAC3C,MAAM,EAAE,WAAW,CAAC;IACpB,wDAAwD;IACxD,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,mDAAmD;IACnD,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC9D,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,gCAAgC,CAAC,gBAAgB,CAAC,CAAC;CACrE;AAiJD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CACtC,iBAAiB,CAAC,sBAAsB,CAAC,CAiH1C,CAAC"}
|
|
@@ -7,7 +7,7 @@ import { TamboComponentProvider, } from "./tambo-component-provider";
|
|
|
7
7
|
import { TamboContextHelpersProvider, } from "./tambo-context-helpers-provider";
|
|
8
8
|
import { TamboCompositeProvider, } from "./tambo-provider";
|
|
9
9
|
import { TamboRegistryContext } from "./tambo-registry-provider";
|
|
10
|
-
import { TamboThreadContext, } from "./tambo-thread-provider";
|
|
10
|
+
import { TamboGenerationStageProvider, TamboThreadContext, } from "./tambo-thread-provider";
|
|
11
11
|
/**
|
|
12
12
|
* Stub client provider that accepts a client and queryClient as props
|
|
13
13
|
* @returns The TamboStubClientProvider component
|
|
@@ -44,7 +44,12 @@ const TamboStubRegistryProvider = ({ children, componentList, toolRegistry, comp
|
|
|
44
44
|
* @returns The TamboStubThreadProvider component
|
|
45
45
|
*/
|
|
46
46
|
const TamboStubThreadProvider = ({ children, ...threadContextProps }) => {
|
|
47
|
-
|
|
47
|
+
// Extract generation stage info from the thread
|
|
48
|
+
const generationStage = threadContextProps.thread?.generationStage ??
|
|
49
|
+
GenerationStage.IDLE;
|
|
50
|
+
const statusMessage = threadContextProps.thread?.statusMessage ?? "";
|
|
51
|
+
return (React.createElement(TamboThreadContext.Provider, { value: threadContextProps },
|
|
52
|
+
React.createElement(TamboGenerationStageProvider, { generationStage: generationStage, statusMessage: statusMessage }, children)));
|
|
48
53
|
};
|
|
49
54
|
/**
|
|
50
55
|
* Default no-op functions that throw errors - used when callbacks are not provided
|
|
@@ -193,13 +198,8 @@ export const TamboStubProvider = ({ children, thread, components = [], tools = [
|
|
|
193
198
|
generateThreadName: overrides.generateThreadName ?? defaults.generateThreadName,
|
|
194
199
|
addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,
|
|
195
200
|
updateThreadMessage: overrides.updateThreadMessage ?? defaults.updateThreadMessage,
|
|
196
|
-
inputValue: overrides.inputValue ?? "",
|
|
197
201
|
streaming: overrides.streaming ?? true,
|
|
198
|
-
setInputValue: overrides.setInputValue ?? defaults.setInputValue,
|
|
199
202
|
sendThreadMessage: overrides.sendThreadMessage ?? defaults.sendThreadMessage,
|
|
200
|
-
generationStage: overrides.generationStage ?? GenerationStage.IDLE,
|
|
201
|
-
generationStatusMessage: overrides.generationStatusMessage ?? "",
|
|
202
|
-
isIdle: overrides.isIdle ?? true,
|
|
203
203
|
cancel: overrides.cancel ?? defaults.cancel,
|
|
204
204
|
};
|
|
205
205
|
const componentContextProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,EAAqB,SAAS,EAAE,MAAM,OAA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,IAAC,cAAc,EAAE,cAAc;oBACzD,oBAAC,sBAAsB;wBACrB,oBAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACG,CACN,CACA,CACJ,CAC3B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport {\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: TamboTool[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n /** Optional: Configuration for which context helpers are enabled/disabled */\n contextHelpers?: TamboContextHelpersProviderProps[\"contextHelpers\"];\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({ children, client, queryClient, threads, projectId, contextKey }) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider value={{ client, queryClient }}>\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<{\n componentList: Record<string, any>;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n }>\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n {children}\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n cancel: () => {\n throw new Error(\"cancel not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n contextHelpers,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[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 return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n },\n {} as Record<string, TamboTool>,\n );\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n inputValue: overrides.inputValue ?? \"\",\n streaming: overrides.streaming ?? true,\n setInputValue: overrides.setInputValue ?? defaults.setInputValue,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n generationStage: overrides.generationStage ?? GenerationStage.IDLE,\n generationStatusMessage: overrides.generationStatusMessage ?? \"\",\n isIdle: overrides.isIdle ?? true,\n cancel: overrides.cancel ?? defaults.cancel,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboContextHelpersProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,EA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kB;gBAC7C,oBAAC,2BAA2B,IAAC,cAAc,EAAE,cAAc;oBACzD,oBAAC,sBAAsB;wBACrB,oBAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACG,CACN,CACA,CACJ,CAC3B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport {\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboGenerationStageProvider,\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: TamboTool[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n /** Optional: Configuration for which context helpers are enabled/disabled */\n contextHelpers?: TamboContextHelpersProviderProps[\"contextHelpers\"];\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({ children, client, queryClient, threads, projectId, contextKey }) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider value={{ client, queryClient }}>\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<{\n componentList: Record<string, any>;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n }>\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n // Extract generation stage info from the thread\n const generationStage =\n (threadContextProps.thread?.generationStage as GenerationStage) ??\n GenerationStage.IDLE;\n const statusMessage = threadContextProps.thread?.statusMessage ?? \"\";\n\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n <TamboGenerationStageProvider\n generationStage={generationStage}\n statusMessage={statusMessage}\n >\n {children}\n </TamboGenerationStageProvider>\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n cancel: () => {\n throw new Error(\"cancel not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n contextHelpers,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[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 return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n },\n {} as Record<string, TamboTool>,\n );\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n streaming: overrides.streaming ?? true,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n cancel: overrides.cancel ?? defaults.cancel,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboContextHelpersProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\n};\n"]}
|
|
@@ -3,6 +3,25 @@ import { Thread } from "@tambo-ai/typescript-sdk/resources/beta/threads/threads"
|
|
|
3
3
|
import React, { PropsWithChildren } from "react";
|
|
4
4
|
import { GenerationStage, TamboThreadMessage } from "../model/generate-component-response";
|
|
5
5
|
import { TamboThread } from "../model/tambo-thread";
|
|
6
|
+
export interface TamboGenerationStageContextProps {
|
|
7
|
+
generationStage: GenerationStage;
|
|
8
|
+
generationStatusMessage: string;
|
|
9
|
+
isIdle: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface TamboGenerationStageProviderProps {
|
|
12
|
+
generationStage: GenerationStage;
|
|
13
|
+
statusMessage: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* This provider is used to provide the generation stage context to the descendants of the provider.
|
|
18
|
+
* @param props - The props for the GenerationStageProvider
|
|
19
|
+
* @param props.children - The children to wrap
|
|
20
|
+
* @param props.generationStage - The generation stage to provide
|
|
21
|
+
* @param props.statusMessage - The status message to provide
|
|
22
|
+
* @returns The GenerationStageProvider component
|
|
23
|
+
*/
|
|
24
|
+
export declare const TamboGenerationStageProvider: React.FC<PropsWithChildren<TamboGenerationStageProviderProps>>;
|
|
6
25
|
export interface TamboThreadContextProps {
|
|
7
26
|
/** The current thread */
|
|
8
27
|
thread: TamboThread;
|
|
@@ -20,12 +39,8 @@ export interface TamboThreadContextProps {
|
|
|
20
39
|
updateThreadMessage: (id: string, message: TamboThreadMessage, sendToServer: boolean) => Promise<void>;
|
|
21
40
|
/** Cancel a thread */
|
|
22
41
|
cancel: (threadId?: string) => Promise<void>;
|
|
23
|
-
/** The input value of the current thread */
|
|
24
|
-
inputValue: string;
|
|
25
42
|
/** Whether the thread is streaming */
|
|
26
43
|
streaming: boolean;
|
|
27
|
-
/** Set the input value of the current thread */
|
|
28
|
-
setInputValue: (value: string) => void;
|
|
29
44
|
/** Send a message to the current thread */
|
|
30
45
|
sendThreadMessage: (message: string, options?: {
|
|
31
46
|
threadId?: string;
|
|
@@ -34,12 +49,8 @@ export interface TamboThreadContextProps {
|
|
|
34
49
|
forceToolChoice?: string;
|
|
35
50
|
additionalContext?: Record<string, any>;
|
|
36
51
|
}) => Promise<TamboThreadMessage>;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/** The generation status message of the current thread - updated as the thread progresses */
|
|
40
|
-
generationStatusMessage: string;
|
|
41
|
-
/** Whether the thread is idle */
|
|
42
|
-
isIdle: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface CombinedTamboThreadContextProps extends TamboThreadContextProps, TamboGenerationStageContextProps {
|
|
43
54
|
}
|
|
44
55
|
/**
|
|
45
56
|
* This is a stub entry for when the thread is not yet created, the first time
|
|
@@ -63,10 +74,17 @@ export interface TamboThreadProviderProps {
|
|
|
63
74
|
* @returns The TamboThreadProvider component
|
|
64
75
|
*/
|
|
65
76
|
export declare const TamboThreadProvider: React.FC<PropsWithChildren<TamboThreadProviderProps>>;
|
|
77
|
+
/**
|
|
78
|
+
* The useTamboGenerationStage hook provides access to the generation stage context
|
|
79
|
+
* to the descendants of the TamboThreadProvider.
|
|
80
|
+
* @returns The generation stage context
|
|
81
|
+
*/
|
|
82
|
+
export declare const useTamboGenerationStage: () => TamboGenerationStageContextProps;
|
|
66
83
|
/**
|
|
67
84
|
* The useTamboThread hook provides access to the current thread context
|
|
68
85
|
* to the descendants of the TamboThreadProvider.
|
|
69
86
|
* @returns All state and actions for the current thread
|
|
70
87
|
*/
|
|
71
|
-
export declare const useTamboThread: () =>
|
|
88
|
+
export declare const useTamboThread: () => CombinedTamboThreadContextProps;
|
|
89
|
+
export {};
|
|
72
90
|
//# sourceMappingURL=tambo-thread-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-thread-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":"AACA,OAAO,OAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,yDAAyD,CAAC;AACjF,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,eAAe,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AAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAO,+BAgBjC,CAAC"}
|
|
@@ -8,6 +8,27 @@ import { handleToolCall } from "../util/tool-caller";
|
|
|
8
8
|
import { useTamboClient } from "./tambo-client-provider";
|
|
9
9
|
import { useTamboContextHelpers } from "./tambo-context-helpers-provider";
|
|
10
10
|
import { useTamboRegistry } from "./tambo-registry-provider";
|
|
11
|
+
const TamboGenerationStageContext = createContext(undefined);
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* This provider is used to provide the generation stage context to the descendants of the provider.
|
|
15
|
+
* @param props - The props for the GenerationStageProvider
|
|
16
|
+
* @param props.children - The children to wrap
|
|
17
|
+
* @param props.generationStage - The generation stage to provide
|
|
18
|
+
* @param props.statusMessage - The status message to provide
|
|
19
|
+
* @returns The GenerationStageProvider component
|
|
20
|
+
*/
|
|
21
|
+
export const TamboGenerationStageProvider = ({ children, generationStage, statusMessage }) => {
|
|
22
|
+
const isIdle = isIdleStage(generationStage);
|
|
23
|
+
const contextValue = useMemo(() => {
|
|
24
|
+
return {
|
|
25
|
+
generationStage,
|
|
26
|
+
generationStatusMessage: statusMessage,
|
|
27
|
+
isIdle,
|
|
28
|
+
};
|
|
29
|
+
}, [generationStage, statusMessage, isIdle]);
|
|
30
|
+
return (React.createElement(TamboGenerationStageContext.Provider, { value: contextValue }, children));
|
|
31
|
+
};
|
|
11
32
|
/**
|
|
12
33
|
* This is a stub entry for when the thread is not yet created, the first time
|
|
13
34
|
* the user sends a message
|
|
@@ -55,14 +76,7 @@ export const TamboThreadContext = createContext({
|
|
|
55
76
|
addThreadMessage: () => {
|
|
56
77
|
throw new Error("updateThreadMessageHistory not implemented");
|
|
57
78
|
},
|
|
58
|
-
inputValue: "",
|
|
59
79
|
streaming: true,
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
*/
|
|
63
|
-
setInputValue: () => {
|
|
64
|
-
throw new Error("setInputValue not implemented");
|
|
65
|
-
},
|
|
66
80
|
/**
|
|
67
81
|
*
|
|
68
82
|
*/
|
|
@@ -73,11 +87,11 @@ export const TamboThreadContext = createContext({
|
|
|
73
87
|
*
|
|
74
88
|
*/
|
|
75
89
|
sendThreadMessage: () => {
|
|
76
|
-
throw new Error("
|
|
90
|
+
throw new Error("sendThreadMessage not implemented");
|
|
77
91
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
81
95
|
cancel: () => {
|
|
82
96
|
throw new Error("cancel not implemented");
|
|
83
97
|
},
|
|
@@ -97,11 +111,13 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
|
|
|
97
111
|
const client = useTamboClient();
|
|
98
112
|
const { componentList, toolRegistry, componentToolAssociations } = useTamboRegistry();
|
|
99
113
|
const { getAdditionalContext } = useTamboContextHelpers();
|
|
100
|
-
const [inputValue, setInputValue] = useState("");
|
|
101
114
|
const [ignoreResponse, setIgnoreResponse] = useState(false);
|
|
102
115
|
const ignoreResponseRef = useRef(ignoreResponse);
|
|
103
116
|
const [currentThreadId, setCurrentThreadId] = useState(PLACEHOLDER_THREAD.id);
|
|
104
117
|
const currentThread = threadMap[currentThreadId];
|
|
118
|
+
// Generation stage props for GenerationStageProvider
|
|
119
|
+
const currentGenerationStage = currentThread?.generationStage ?? GenerationStage.IDLE;
|
|
120
|
+
const currentStatusMessage = currentThread?.statusMessage ?? "";
|
|
105
121
|
// Use existing messages from the current thread to avoid re-generating any components
|
|
106
122
|
const currentMessageCache = useMemo(() => {
|
|
107
123
|
const messageCache = new Map();
|
|
@@ -115,8 +131,6 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
|
|
|
115
131
|
useEffect(() => {
|
|
116
132
|
ignoreResponseRef.current = ignoreResponse;
|
|
117
133
|
}, [ignoreResponse]);
|
|
118
|
-
const isIdle = useMemo(() => isIdleStage((currentThread?.generationStage ??
|
|
119
|
-
GenerationStage.IDLE)), [currentThread?.generationStage]);
|
|
120
134
|
const fetchThread = useCallback(async (threadId, includeInternalMessages = true) => {
|
|
121
135
|
const thread = await client.beta.threads.retrieve(threadId, {
|
|
122
136
|
includeInternal: includeInternalMessages,
|
|
@@ -317,7 +331,8 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
|
|
|
317
331
|
}, []);
|
|
318
332
|
const cancel = useCallback(async (threadId) => {
|
|
319
333
|
threadId ??= currentThreadId;
|
|
320
|
-
|
|
334
|
+
const currentGenerationStage = currentThread?.generationStage ?? GenerationStage.IDLE;
|
|
335
|
+
if (isIdleStage(currentGenerationStage)) {
|
|
321
336
|
return;
|
|
322
337
|
}
|
|
323
338
|
setIgnoreResponse(true);
|
|
@@ -344,7 +359,7 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
|
|
|
344
359
|
};
|
|
345
360
|
});
|
|
346
361
|
await client.beta.threads.cancel(threadId);
|
|
347
|
-
}, [client.beta.threads, currentThreadId,
|
|
362
|
+
}, [client.beta.threads, currentThreadId, currentThread?.generationStage]);
|
|
348
363
|
const handleAdvanceStream = useCallback(async (stream, params, threadId) => {
|
|
349
364
|
if (ignoreResponseRef.current) {
|
|
350
365
|
setIgnoreResponse(false);
|
|
@@ -601,16 +616,23 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
|
|
|
601
616
|
generateThreadName,
|
|
602
617
|
addThreadMessage,
|
|
603
618
|
updateThreadMessage,
|
|
604
|
-
inputValue,
|
|
605
|
-
setInputValue,
|
|
606
|
-
sendThreadMessage,
|
|
607
619
|
streaming,
|
|
608
|
-
generationStage: (currentThread?.generationStage ??
|
|
609
|
-
GenerationStage.IDLE),
|
|
610
|
-
generationStatusMessage: currentThread?.statusMessage ?? "",
|
|
611
|
-
isIdle,
|
|
612
620
|
cancel,
|
|
613
|
-
|
|
621
|
+
sendThreadMessage,
|
|
622
|
+
} },
|
|
623
|
+
React.createElement(TamboGenerationStageProvider, { generationStage: currentGenerationStage, statusMessage: currentStatusMessage }, children)));
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* The useTamboGenerationStage hook provides access to the generation stage context
|
|
627
|
+
* to the descendants of the TamboThreadProvider.
|
|
628
|
+
* @returns The generation stage context
|
|
629
|
+
*/
|
|
630
|
+
export const useTamboGenerationStage = () => {
|
|
631
|
+
const generationStageContext = useContext(TamboGenerationStageContext);
|
|
632
|
+
if (generationStageContext === undefined) {
|
|
633
|
+
throw new Error("useTamboGenerationStage must be used within a TamboThreadProvider");
|
|
634
|
+
}
|
|
635
|
+
return generationStageContext;
|
|
614
636
|
};
|
|
615
637
|
/**
|
|
616
638
|
* The useTamboThread hook provides access to the current thread context
|
|
@@ -618,10 +640,17 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
|
|
|
618
640
|
* @returns All state and actions for the current thread
|
|
619
641
|
*/
|
|
620
642
|
export const useTamboThread = () => {
|
|
621
|
-
const
|
|
622
|
-
|
|
643
|
+
const threadContext = useContext(TamboThreadContext);
|
|
644
|
+
const generationStageContext = useContext(TamboGenerationStageContext);
|
|
645
|
+
if (threadContext === undefined) {
|
|
646
|
+
throw new Error("useTamboThread must be used within a TamboThreadProvider");
|
|
647
|
+
}
|
|
648
|
+
if (generationStageContext === undefined) {
|
|
623
649
|
throw new Error("useTamboThread must be used within a TamboThreadProvider");
|
|
624
650
|
}
|
|
625
|
-
return
|
|
651
|
+
return {
|
|
652
|
+
...threadContext,
|
|
653
|
+
...generationStageContext,
|
|
654
|
+
};
|
|
626
655
|
};
|
|
627
656
|
//# sourceMappingURL=tambo-thread-provider.js.map
|