@tambo-ai/react 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/context-helpers/__tests__/context-helpers-provider.test.d.ts +15 -0
  2. package/dist/context-helpers/__tests__/context-helpers-provider.test.d.ts.map +1 -0
  3. package/dist/context-helpers/__tests__/context-helpers-provider.test.js +147 -0
  4. package/dist/context-helpers/__tests__/context-helpers-provider.test.js.map +1 -0
  5. package/dist/context-helpers/__tests__/context-helpers.test.js +30 -35
  6. package/dist/context-helpers/__tests__/context-helpers.test.js.map +1 -1
  7. package/dist/context-helpers/current-page-context-helper.d.ts +7 -0
  8. package/dist/context-helpers/current-page-context-helper.d.ts.map +1 -0
  9. package/dist/context-helpers/current-page-context-helper.js +24 -0
  10. package/dist/context-helpers/current-page-context-helper.js.map +1 -0
  11. package/dist/context-helpers/current-time-context-helper.d.ts +7 -0
  12. package/dist/context-helpers/current-time-context-helper.d.ts.map +1 -0
  13. package/dist/context-helpers/current-time-context-helper.js +21 -0
  14. package/dist/context-helpers/current-time-context-helper.js.map +1 -0
  15. package/dist/context-helpers/index.d.ts +2 -7
  16. package/dist/context-helpers/index.d.ts.map +1 -1
  17. package/dist/context-helpers/index.js +2 -20
  18. package/dist/context-helpers/index.js.map +1 -1
  19. package/dist/context-helpers/registry.d.ts +35 -0
  20. package/dist/context-helpers/registry.d.ts.map +1 -0
  21. package/dist/context-helpers/registry.js +64 -0
  22. package/dist/context-helpers/registry.js.map +1 -0
  23. package/dist/context-helpers/types.d.ts +6 -16
  24. package/dist/context-helpers/types.d.ts.map +1 -1
  25. package/dist/context-helpers/types.js.map +1 -1
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +3 -4
  29. package/dist/index.js.map +1 -1
  30. package/dist/providers/__tests__/tambo-context-helpers-provider.test.js +278 -137
  31. package/dist/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
  32. package/dist/providers/__tests__/tambo-thread-provider.test.js +29 -7
  33. package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  34. package/dist/providers/tambo-context-helpers-provider.d.ts +24 -15
  35. package/dist/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  36. package/dist/providers/tambo-context-helpers-provider.js +56 -39
  37. package/dist/providers/tambo-context-helpers-provider.js.map +1 -1
  38. package/dist/providers/tambo-interactable-provider.js +1 -1
  39. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  40. package/esm/context-helpers/__tests__/context-helpers-provider.test.d.ts +15 -0
  41. package/esm/context-helpers/__tests__/context-helpers-provider.test.d.ts.map +1 -0
  42. package/esm/context-helpers/__tests__/context-helpers-provider.test.js +142 -0
  43. package/esm/context-helpers/__tests__/context-helpers-provider.test.js.map +1 -0
  44. package/esm/context-helpers/__tests__/context-helpers.test.js +31 -36
  45. package/esm/context-helpers/__tests__/context-helpers.test.js.map +1 -1
  46. package/esm/context-helpers/current-page-context-helper.d.ts +7 -0
  47. package/esm/context-helpers/current-page-context-helper.d.ts.map +1 -0
  48. package/esm/context-helpers/current-page-context-helper.js +20 -0
  49. package/esm/context-helpers/current-page-context-helper.js.map +1 -0
  50. package/esm/context-helpers/current-time-context-helper.d.ts +7 -0
  51. package/esm/context-helpers/current-time-context-helper.d.ts.map +1 -0
  52. package/esm/context-helpers/current-time-context-helper.js +17 -0
  53. package/esm/context-helpers/current-time-context-helper.js.map +1 -0
  54. package/esm/context-helpers/index.d.ts +2 -7
  55. package/esm/context-helpers/index.d.ts.map +1 -1
  56. package/esm/context-helpers/index.js +2 -19
  57. package/esm/context-helpers/index.js.map +1 -1
  58. package/esm/context-helpers/registry.d.ts +35 -0
  59. package/esm/context-helpers/registry.d.ts.map +1 -0
  60. package/esm/context-helpers/registry.js +57 -0
  61. package/esm/context-helpers/registry.js.map +1 -0
  62. package/esm/context-helpers/types.d.ts +6 -16
  63. package/esm/context-helpers/types.d.ts.map +1 -1
  64. package/esm/context-helpers/types.js.map +1 -1
  65. package/esm/index.d.ts +2 -2
  66. package/esm/index.d.ts.map +1 -1
  67. package/esm/index.js +1 -1
  68. package/esm/index.js.map +1 -1
  69. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js +279 -105
  70. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
  71. package/esm/providers/__tests__/tambo-thread-provider.test.js +29 -7
  72. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  73. package/esm/providers/tambo-context-helpers-provider.d.ts +24 -15
  74. package/esm/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  75. package/esm/providers/tambo-context-helpers-provider.js +57 -40
  76. package/esm/providers/tambo-context-helpers-provider.js.map +1 -1
  77. package/esm/providers/tambo-interactable-provider.js +1 -1
  78. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  79. package/package.json +6 -6
  80. package/dist/context-helpers/user-page.d.ts +0 -7
  81. package/dist/context-helpers/user-page.d.ts.map +0 -1
  82. package/dist/context-helpers/user-page.js +0 -31
  83. package/dist/context-helpers/user-page.js.map +0 -1
  84. package/dist/context-helpers/user-time.d.ts +0 -7
  85. package/dist/context-helpers/user-time.d.ts.map +0 -1
  86. package/dist/context-helpers/user-time.js +0 -20
  87. package/dist/context-helpers/user-time.js.map +0 -1
  88. package/esm/context-helpers/user-page.d.ts +0 -7
  89. package/esm/context-helpers/user-page.d.ts.map +0 -1
  90. package/esm/context-helpers/user-page.js +0 -28
  91. package/esm/context-helpers/user-page.js.map +0 -1
  92. package/esm/context-helpers/user-time.d.ts +0 -7
  93. package/esm/context-helpers/user-time.d.ts.map +0 -1
  94. package/esm/context-helpers/user-time.js +0 -17
  95. package/esm/context-helpers/user-time.js.map +0 -1
@@ -8,23 +8,13 @@ export interface AdditionalContext {
8
8
  context: any;
9
9
  }
10
10
  /**
11
- * Interface for a context helper that can generate additional context
11
+ * A context helper is a function that returns data to include in the context,
12
+ * or null/undefined to skip including anything.
12
13
  */
13
- export interface AdditionalContextHelper {
14
- /** The name of the context helper */
15
- name: string;
16
- /** Whether this helper is enabled */
17
- enabled: boolean;
18
- /** Function that generates the additional context */
19
- run: () => AdditionalContext | Promise<AdditionalContext>;
20
- }
14
+ export type ContextHelperFn = () => any | null | undefined | Promise<any | null | undefined>;
21
15
  /**
22
- * Configuration for context helpers
16
+ * A collection of context helpers keyed by their context name.
17
+ * The key becomes the AdditionalContext.name sent to the model.
23
18
  */
24
- export interface ContextHelpersConfig {
25
- /** Enable/disable user time context helper */
26
- userTime?: boolean;
27
- /** Enable/disable user page context helper */
28
- userPage?: boolean;
29
- }
19
+ export type ContextHelpers = Record<string, ContextHelperFn>;
30
20
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/context-helpers/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,OAAO,EAAE,GAAG,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,qDAAqD;IACrD,GAAG,EAAE,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC3D;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/context-helpers/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,OAAO,EAAE,GAAG,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAC1B,GAAG,GACH,IAAI,GACJ,SAAS,GACT,OAAO,CAAC,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAEpC;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/context-helpers/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Interface for additional context that can be added to messages\n */\nexport interface AdditionalContext {\n /** The name of the context type */\n name: string;\n /** The context data */\n context: any;\n}\n\n/**\n * Interface for a context helper that can generate additional context\n */\nexport interface AdditionalContextHelper {\n /** The name of the context helper */\n name: string;\n /** Whether this helper is enabled */\n enabled: boolean;\n /** Function that generates the additional context */\n run: () => AdditionalContext | Promise<AdditionalContext>;\n}\n\n/**\n * Configuration for context helpers\n */\nexport interface ContextHelpersConfig {\n /** Enable/disable user time context helper */\n userTime?: boolean;\n /** Enable/disable user page context helper */\n userPage?: boolean;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/context-helpers/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Interface for additional context that can be added to messages\n */\nexport interface AdditionalContext {\n /** The name of the context type */\n name: string;\n /** The context data */\n context: any;\n}\n\n/**\n * A context helper is a function that returns data to include in the context,\n * or null/undefined to skip including anything.\n */\nexport type ContextHelperFn = () =>\n | any\n | null\n | undefined\n | Promise<any | null | undefined>;\n\n/**\n * A collection of context helpers keyed by their context name.\n * The key becomes the AdditionalContext.name sent to the model.\n */\nexport type ContextHelpers = Record<string, ContextHelperFn>;\n"]}
package/esm/index.d.ts CHANGED
@@ -15,6 +15,6 @@ export { type TamboThread } from "./model/tambo-thread";
15
15
  export type { TamboInteractableComponent as InteractableComponent, TamboInteractableContext, } from "./model/tambo-interactable";
16
16
  export { withTamboInteractable as withInteractable, type InteractableConfig, type WithTamboInteractableProps, } from "./providers/hoc/with-tambo-interactable";
17
17
  export { useTamboInteractable } from "./providers/tambo-interactable-provider";
18
- export { DEFAULT_CONTEXT_HELPERS, getUserPageContext, getUserTimeContext, } from "./context-helpers";
19
- export type { AdditionalContext, AdditionalContextHelper, ContextHelpersConfig, } from "./context-helpers";
18
+ export { currentPageContextHelper, currentTimeContextHelper, } from "./context-helpers";
19
+ export type { AdditionalContext, ContextHelperFn, ContextHelpers, } from "./context-helpers";
20
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AAExK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,+BAA+B,EACpC,KAAK,gCAAgC,EACrC,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,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AAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,+BAA+B,EACpC,KAAK,gCAAgC,EACrC,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,YAAY,EACV,0BAA0B,IAAI,qBAAqB,EACnD,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,IAAI,gBAAgB,EACzC,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,GAChC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAG/E,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,mBAAmB,CAAC"}
package/esm/index.js CHANGED
@@ -12,5 +12,5 @@ export { GenerationStage, } from "./model/generate-component-response";
12
12
  export { withTamboInteractable as withInteractable, } from "./providers/hoc/with-tambo-interactable";
13
13
  export { useTamboInteractable } from "./providers/tambo-interactable-provider";
14
14
  // Context helpers exports
15
- export { DEFAULT_CONTEXT_HELPERS, getUserPageContext, getUserTimeContext, } from "./context-helpers";
15
+ export { currentPageContextHelper, currentTimeContextHelper, } from "./context-helpers";
16
16
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AAExK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,oBAAoB,GAGrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,cAAc,GAMf,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EACL,qBAAqB,IAAI,gBAAgB,GAG1C,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,0BAA0B;AAC1B,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\n\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./hooks/use-tambo-stream-status\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboContextHelpersProvider,\n TamboPropStreamProvider,\n TamboProvider,\n TamboStubProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboContextHelpers,\n useTamboStream,\n useTamboThread,\n type TamboComponent,\n type TamboContextHelpersContextProps,\n type TamboContextHelpersProviderProps,\n type TamboRegistryContext,\n type TamboStubProviderProps,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n\nexport type {\n TamboInteractableComponent as InteractableComponent,\n TamboInteractableContext,\n} from \"./model/tambo-interactable\";\nexport {\n withTamboInteractable as withInteractable,\n type InteractableConfig,\n type WithTamboInteractableProps,\n} from \"./providers/hoc/with-tambo-interactable\";\nexport { useTamboInteractable } from \"./providers/tambo-interactable-provider\";\n\n// Context helpers exports\nexport {\n DEFAULT_CONTEXT_HELPERS,\n getUserPageContext,\n getUserTimeContext,\n} from \"./context-helpers\";\nexport type {\n AdditionalContext,\n AdditionalContextHelper,\n ContextHelpersConfig,\n} from \"./context-helpers\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AAExK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,oBAAoB,GAGrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,cAAc,GAMf,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EACL,qBAAqB,IAAI,gBAAgB,GAG1C,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,0BAA0B;AAC1B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\n\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./hooks/use-tambo-stream-status\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboContextHelpersProvider,\n TamboPropStreamProvider,\n TamboProvider,\n TamboStubProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboContextHelpers,\n useTamboStream,\n useTamboThread,\n type TamboComponent,\n type TamboContextHelpersContextProps,\n type TamboContextHelpersProviderProps,\n type TamboRegistryContext,\n type TamboStubProviderProps,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n\nexport type {\n TamboInteractableComponent as InteractableComponent,\n TamboInteractableContext,\n} from \"./model/tambo-interactable\";\nexport {\n withTamboInteractable as withInteractable,\n type InteractableConfig,\n type WithTamboInteractableProps,\n} from \"./providers/hoc/with-tambo-interactable\";\nexport { useTamboInteractable } from \"./providers/tambo-interactable-provider\";\n\n// Context helpers exports\nexport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"./context-helpers\";\nexport type {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"./context-helpers\";\n"]}
@@ -1,156 +1,330 @@
1
1
  import { act, renderHook } from "@testing-library/react";
2
2
  import React from "react";
3
- import * as contextHelpers from "../../context-helpers";
4
- import { DEFAULT_CONTEXT_HELPERS } from "../../context-helpers";
3
+ import { currentPageContextHelper, currentTimeContextHelper, } from "../../context-helpers";
4
+ import { setHelpers } from "../../context-helpers/registry";
5
5
  import { TamboContextHelpersProvider, useTamboContextHelpers, } from "../tambo-context-helpers-provider";
6
+ /**
7
+ * Test suite for TamboContextHelpersProvider (simplified API, registry-backed)
8
+ *
9
+ * The simplified API:
10
+ * - Accepts a plain map of { key: () => any | null | undefined | Promise<any | null | undefined> }.
11
+ * - The key becomes the context name sent to the model.
12
+ * - Returning null/undefined from a helper skips inclusion.
13
+ * - Prebuilt helpers are just functions (e.g., prebuiltUserTime, prebuiltUserPage).
14
+ *
15
+ * The hook is now registry-backed and safe to call outside a provider. When used
16
+ * outside a provider, it proxies to a global registry and still works.
17
+ */
6
18
  describe("TamboContextHelpersProvider", () => {
7
- // Create a wrapper component that provides the context for testing hooks
19
+ // Ensure registry is clean for each test to avoid cross-test contamination
20
+ beforeEach(() => {
21
+ setHelpers({});
22
+ jest.clearAllMocks();
23
+ });
24
+ // Base wrapper with no helpers provided
8
25
  const wrapper = ({ children }) => (React.createElement(TamboContextHelpersProvider, null, children));
9
26
  describe("useTamboContextHelpers", () => {
10
27
  /**
11
- * Test: Hook throws error when used outside of provider
12
- * This ensures developers get a clear error message if they forget to wrap
13
- * their components with the TamboContextHelpersProvider
28
+ * NOTE: The hook is registry-backed and safe outside provider. It should not throw.
29
+ * This replaces the previous behavior that threw without a provider.
14
30
  */
15
- it("should throw error when used outside provider", () => {
16
- // Mock console.error to prevent error output in test logs
31
+ it("should be safe outside provider (registry-backed no provider)", async () => {
17
32
  const consoleSpy = jest
18
33
  .spyOn(console, "error")
19
34
  .mockImplementation(() => { });
20
- // Verify that using the hook without a provider throws the expected error
21
- expect(() => {
22
- renderHook(() => useTamboContextHelpers());
23
- }).toThrow("useTamboContextHelpers must be used within a TamboContextHelpersProvider");
24
- // Restore console.error to its original implementation
35
+ const { result } = renderHook(() => useTamboContextHelpers());
36
+ // Should return callable functions
37
+ expect(typeof result.current.getAdditionalContext).toBe("function");
38
+ expect(typeof result.current.getContextHelpers).toBe("function");
39
+ expect(typeof result.current.addContextHelper).toBe("function");
40
+ expect(typeof result.current.removeContextHelper).toBe("function");
41
+ // Starts empty
42
+ expect(await result.current.getAdditionalContext()).toHaveLength(0);
43
+ // Add a helper and verify
44
+ act(() => {
45
+ result.current.addContextHelper("outsideHelper", () => ({ ok: true }));
46
+ });
47
+ const contexts = await result.current.getAdditionalContext();
48
+ expect(contexts).toContainEqual({
49
+ name: "outsideHelper",
50
+ context: { ok: true },
51
+ });
52
+ // Cleanup
53
+ act(() => {
54
+ result.current.removeContextHelper("outsideHelper");
55
+ });
25
56
  consoleSpy.mockRestore();
26
57
  });
27
58
  /**
28
- * Test: Hook provides the expected API functions
29
- * Verifies that all required functions are available when the hook is used
30
- * within the provider context
59
+ * Verifies that the hook returns the expected API functions when used within a provider.
31
60
  */
32
- it("should provide context helpers functions", () => {
61
+ it("should provide context helpers functions (inside provider)", () => {
33
62
  const { result } = renderHook(() => useTamboContextHelpers(), {
34
63
  wrapper,
35
64
  });
36
- // Verify all expected functions are present in the hook's return value
37
65
  expect(result.current).toHaveProperty("getAdditionalContext");
38
66
  expect(result.current).toHaveProperty("getContextHelpers");
39
- expect(result.current).toHaveProperty("setContextHelperEnabled");
40
- });
41
- /**
42
- * Test: Default configuration is applied correctly
43
- * Ensures that the default context helpers are loaded with their
44
- * expected enabled/disabled states
45
- */
46
- it("should return default context helpers configuration", () => {
47
- const { result } = renderHook(() => useTamboContextHelpers(), {
48
- wrapper,
49
- });
50
- const helpers = result.current.getContextHelpers();
51
- // Verify we have the expected number of default helpers
52
- expect(helpers).toHaveLength(DEFAULT_CONTEXT_HELPERS.length);
53
- // Check specific helpers have their expected default states
54
- const userTimeHelper = helpers.find((h) => h.name === "userTime");
55
- const userPageHelper = helpers.find((h) => h.name === "userPage");
56
- // userTime should be disabled by default
57
- expect(userTimeHelper?.enabled).toBe(false);
58
- // userPage should be disabled by default
59
- expect(userPageHelper?.enabled).toBe(false);
67
+ expect(result.current).toHaveProperty("addContextHelper");
68
+ expect(result.current).toHaveProperty("removeContextHelper");
60
69
  });
61
70
  /**
62
- * Test: Context helper enabled state can be toggled
63
- * Verifies that the setContextHelperEnabled function correctly updates
64
- * the enabled state of individual helpers
71
+ * With no helpers provided, no additional context should be returned.
65
72
  */
66
- it("should allow toggling context helper enabled state", () => {
67
- const { result } = renderHook(() => useTamboContextHelpers(), {
68
- wrapper,
69
- });
70
- // Enable the userPage helper using the provided function
71
- act(() => {
72
- result.current.setContextHelperEnabled("userPage", true);
73
- });
74
- // Verify the helper's state was updated
75
- const helpers = result.current.getContextHelpers();
76
- const userPageHelper = helpers.find((h) => h.name === "userPage");
77
- expect(userPageHelper?.enabled).toBe(true);
78
- });
79
- /**
80
- * Test: Only enabled helpers contribute to additional context
81
- * Verifies that getAdditionalContext only runs and returns data from
82
- * helpers that are currently enabled
83
- */
84
- it("should get additional context from enabled helpers", async () => {
73
+ it("should return no additional context when no helpers are provided", async () => {
85
74
  const { result } = renderHook(() => useTamboContextHelpers(), {
86
75
  wrapper,
87
76
  });
88
77
  const contexts = await result.current.getAdditionalContext();
89
- // By default, no context helpers are enabled, so we should get no contexts
90
78
  expect(contexts).toHaveLength(0);
91
79
  });
92
80
  /**
93
- * Test: Provider respects configuration prop
94
- * Verifies that initial configuration can be customized through the
95
- * contextHelpers prop on the provider
81
+ * When helpers are provided, getAdditionalContext should aggregate them.
82
+ * Note: prebuiltUserPage may be null in non-browser envs, so we only assert userTime when present.
96
83
  */
97
- it("should respect contextHelpers configuration prop", () => {
98
- // Create a custom wrapper with specific configuration
99
- const customWrapper = ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
100
- userTime: false, // Disable userTime
101
- userPage: true, // Enable userPage
84
+ it("should get additional context when helpers are provided", async () => {
85
+ const withHelpers = ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
86
+ userTime: currentTimeContextHelper,
87
+ userPage: currentPageContextHelper,
102
88
  } }, children));
103
89
  const { result } = renderHook(() => useTamboContextHelpers(), {
104
- wrapper: customWrapper,
90
+ wrapper: withHelpers,
105
91
  });
106
- // Verify the custom configuration is applied
107
- const helpers = result.current.getContextHelpers();
108
- const userTimeHelper = helpers.find((h) => h.name === "userTime");
109
- const userPageHelper = helpers.find((h) => h.name === "userPage");
110
- expect(userTimeHelper?.enabled).toBe(false);
111
- expect(userPageHelper?.enabled).toBe(true);
92
+ const contexts = await result.current.getAdditionalContext();
93
+ const names = contexts.map((c) => c.name);
94
+ // userTime should be present from prebuilt helper
95
+ expect(names).toContain("userTime");
96
+ // userPage may be absent on server; do not assert strictly
112
97
  });
113
98
  /**
114
- * Test: Errors in context helpers are handled gracefully
115
- * Verifies that if a context helper throws an error, it doesn't crash
116
- * the entire system and other helpers continue to work
99
+ * Errors thrown by helper functions should be caught and skipped, not crash the system.
117
100
  */
118
101
  it("should handle errors in context helper functions gracefully", async () => {
119
- // Mock console.error to capture error logs
120
102
  const consoleErrorSpy = jest
121
103
  .spyOn(console, "error")
122
104
  .mockImplementation(() => { });
123
- // Create a helper that will throw an error when run
124
- const errorHelper = {
125
- name: "errorHelper",
126
- enabled: true,
127
- run: () => {
128
- throw new Error("Test error");
129
- },
105
+ const badHelper = () => {
106
+ throw new Error("Test error");
130
107
  };
131
- // Temporarily add the error helper to the default helpers
132
- // Store original helpers to restore later
133
- const originalHelpers = DEFAULT_CONTEXT_HELPERS;
134
- Object.defineProperty(contextHelpers, "DEFAULT_CONTEXT_HELPERS", {
135
- value: [...originalHelpers, errorHelper],
136
- writable: true,
137
- });
108
+ const withBadHelper = ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: { badHelper } }, children));
138
109
  const { result } = renderHook(() => useTamboContextHelpers(), {
139
- wrapper,
110
+ wrapper: withBadHelper,
140
111
  });
141
- // Call getAdditionalContext, which should handle the error gracefully
142
112
  const contexts = await result.current.getAdditionalContext();
143
- // Should have no contexts because the error helper should be skipped
144
113
  expect(contexts.length).toBe(0);
145
- // Verify that the error was logged appropriately
146
- expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Error running context helper errorHelper"), expect.any(Error));
147
- // Restore the original helpers and console.error
148
- Object.defineProperty(contextHelpers, "DEFAULT_CONTEXT_HELPERS", {
149
- value: originalHelpers,
150
- writable: true,
151
- });
114
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Error running context helper badHelper"), expect.any(Error));
152
115
  consoleErrorSpy.mockRestore();
153
116
  });
154
117
  });
155
118
  });
119
+ /**
120
+ * Test suite for Custom Context Helpers using the simplified API.
121
+ *
122
+ * Focuses on:
123
+ * - Passing custom helpers via the provider prop.
124
+ * - Overriding prebuilt helpers with custom implementations.
125
+ * - Dynamic add/remove helper management at runtime.
126
+ * - Supporting both sync and async helpers.
127
+ * - Using the config key as the context name.
128
+ * - Graceful error handling for custom helpers.
129
+ */
130
+ describe("Custom Context Helpers via contextHelpers config", () => {
131
+ beforeEach(() => {
132
+ setHelpers({});
133
+ jest.clearAllMocks();
134
+ });
135
+ /**
136
+ * Custom helpers can be added through the provider configuration.
137
+ * The key becomes the context name and the function returns the raw value.
138
+ */
139
+ it("should accept custom helpers through contextHelpers config", async () => {
140
+ const { result } = renderHook(() => useTamboContextHelpers(), {
141
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
142
+ customData: async () => ({ custom: "value" }),
143
+ } }, children)),
144
+ });
145
+ const contexts = await result.current.getAdditionalContext();
146
+ expect(contexts).toContainEqual({
147
+ name: "customData",
148
+ context: { custom: "value" },
149
+ });
150
+ });
151
+ /**
152
+ * Built-in helpers can be overridden by providing a function under the same key.
153
+ */
154
+ it("should allow custom helpers to override built-in ones", async () => {
155
+ const { result } = renderHook(() => useTamboContextHelpers(), {
156
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
157
+ userTime: async () => ({ customTime: "override" }),
158
+ } }, children)),
159
+ });
160
+ const contexts = await result.current.getAdditionalContext();
161
+ const userTimeContext = contexts.find((c) => c.name === "userTime");
162
+ expect(userTimeContext?.context).toEqual({ customTime: "override" });
163
+ });
164
+ /**
165
+ * Helpers can be added dynamically at runtime via addContextHelper.
166
+ */
167
+ it("should handle dynamic addition of custom helpers", async () => {
168
+ const { result } = renderHook(() => useTamboContextHelpers(), {
169
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {} }, children)),
170
+ });
171
+ // Initially none
172
+ expect(await result.current.getAdditionalContext()).toHaveLength(0);
173
+ act(() => {
174
+ result.current.addContextHelper("dynamicHelper", async () => ({
175
+ dynamic: true,
176
+ }));
177
+ });
178
+ const contexts = await result.current.getAdditionalContext();
179
+ expect(contexts).toContainEqual({
180
+ name: "dynamicHelper",
181
+ context: { dynamic: true },
182
+ });
183
+ });
184
+ /**
185
+ * Helpers can be removed dynamically via removeContextHelper.
186
+ */
187
+ it("should handle dynamic removal of context helpers", async () => {
188
+ const { result } = renderHook(() => useTamboContextHelpers(), {
189
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
190
+ customHelper: async () => ({ test: "data" }),
191
+ } }, children)),
192
+ });
193
+ // Verify exists
194
+ let contexts = await result.current.getAdditionalContext();
195
+ expect(contexts.find((c) => c.name === "customHelper")).toBeDefined();
196
+ // Remove
197
+ act(() => {
198
+ result.current.removeContextHelper("customHelper");
199
+ });
200
+ // Verify removed
201
+ contexts = await result.current.getAdditionalContext();
202
+ expect(contexts.find((c) => c.name === "customHelper")).toBeUndefined();
203
+ });
204
+ /**
205
+ * Multiple custom helpers should be supported; helpers returning null/undefined are skipped.
206
+ */
207
+ it("should handle multiple custom helpers", async () => {
208
+ const { result } = renderHook(() => useTamboContextHelpers(), {
209
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
210
+ helper1: async () => ({ data: "one" }),
211
+ helper2: async () => ({ data: "two" }),
212
+ helper3: () => null, // disabled by returning null
213
+ } }, children)),
214
+ });
215
+ const contexts = await result.current.getAdditionalContext();
216
+ expect(contexts).toContainEqual({
217
+ name: "helper1",
218
+ context: { data: "one" },
219
+ });
220
+ expect(contexts).toContainEqual({
221
+ name: "helper2",
222
+ context: { data: "two" },
223
+ });
224
+ expect(contexts.find((c) => c.name === "helper3")).toBeUndefined();
225
+ });
226
+ /**
227
+ * Both synchronous and asynchronous helpers should be supported.
228
+ */
229
+ it("should handle sync and async custom helpers", async () => {
230
+ const { result } = renderHook(() => useTamboContextHelpers(), {
231
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
232
+ syncHelper: () => ({ sync: true }),
233
+ asyncHelper: async () => {
234
+ await new Promise((resolve) => setTimeout(resolve, 10));
235
+ return { async: true };
236
+ },
237
+ } }, children)),
238
+ });
239
+ const contexts = await result.current.getAdditionalContext();
240
+ expect(contexts).toContainEqual({
241
+ name: "syncHelper",
242
+ context: { sync: true },
243
+ });
244
+ expect(contexts).toContainEqual({
245
+ name: "asyncHelper",
246
+ context: { async: true },
247
+ });
248
+ });
249
+ /**
250
+ * The key used in the contextHelpers map becomes the context name.
251
+ */
252
+ it("should use key name as context name for custom helpers", async () => {
253
+ const { result } = renderHook(() => useTamboContextHelpers(), {
254
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
255
+ myCustomKey: async () => ({ value: "test" }),
256
+ } }, children)),
257
+ });
258
+ const contexts = await result.current.getAdditionalContext();
259
+ expect(contexts).toContainEqual({
260
+ name: "myCustomKey",
261
+ context: { value: "test" },
262
+ });
263
+ });
264
+ /**
265
+ * Errors thrown by custom helpers should be logged and skipped, not crash the system.
266
+ */
267
+ it("should handle errors in custom helpers gracefully", async () => {
268
+ const consoleErrorSpy = jest
269
+ .spyOn(console, "error")
270
+ .mockImplementation(() => { });
271
+ const { result } = renderHook(() => useTamboContextHelpers(), {
272
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
273
+ errorHelper: async () => {
274
+ throw new Error("Custom helper error");
275
+ },
276
+ goodHelper: async () => ({ good: "data" }),
277
+ } }, children)),
278
+ });
279
+ const contexts = await result.current.getAdditionalContext();
280
+ expect(contexts).toContainEqual({
281
+ name: "goodHelper",
282
+ context: { good: "data" },
283
+ });
284
+ expect(contexts.find((c) => c.name === "errorHelper")).toBeUndefined();
285
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Error running context helper errorHelper"), expect.any(Error));
286
+ consoleErrorSpy.mockRestore();
287
+ });
288
+ /**
289
+ * Removing non-existent helpers should be a no-op without throwing errors.
290
+ */
291
+ it("should handle removing non-existent helper gracefully", () => {
292
+ const { result } = renderHook(() => useTamboContextHelpers(), {
293
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {} }, children)),
294
+ });
295
+ expect(() => {
296
+ act(() => {
297
+ result.current.removeContextHelper("nonExistent");
298
+ });
299
+ }).not.toThrow();
300
+ });
301
+ /**
302
+ * Adding with an existing name should update/replace the helper implementation.
303
+ */
304
+ it("should allow updating existing helper via addContextHelper", async () => {
305
+ const { result } = renderHook(() => useTamboContextHelpers(), {
306
+ wrapper: ({ children }) => (React.createElement(TamboContextHelpersProvider, { contextHelpers: {
307
+ testHelper: async () => ({ original: true }),
308
+ } }, children)),
309
+ });
310
+ // Verify original helper
311
+ let contexts = await result.current.getAdditionalContext();
312
+ expect(contexts).toContainEqual({
313
+ name: "testHelper",
314
+ context: { original: true },
315
+ });
316
+ // Update the helper
317
+ act(() => {
318
+ result.current.addContextHelper("testHelper", async () => ({
319
+ updated: true,
320
+ }));
321
+ });
322
+ // Verify updated helper
323
+ contexts = await result.current.getAdditionalContext();
324
+ expect(contexts).toContainEqual({
325
+ name: "testHelper",
326
+ context: { updated: true },
327
+ });
328
+ });
329
+ });
156
330
  //# sourceMappingURL=tambo-context-helpers-provider.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-context-helpers-provider.test.js","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-context-helpers-provider.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,mCAAmC,CAAC;AAE3C,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,yEAAyE;IACzE,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE,CAAC,CAC/D,oBAAC,2BAA2B,QAAE,QAAQ,CAA+B,CACtE,CAAC;IAEF,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC;;;;WAIG;QACH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;YACvD,0DAA0D;YAC1D,MAAM,UAAU,GAAG,IAAI;iBACpB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC;iBACvB,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAEhC,0EAA0E;YAC1E,MAAM,CAAC,GAAG,EAAE;gBACV,UAAU,CAAC,GAAG,EAAE,CAAC,sBAAsB,EAAE,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC,OAAO,CACR,0EAA0E,CAC3E,CAAC;YAEF,uDAAuD;YACvD,UAAU,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH;;;;WAIG;QACH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAClD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,sBAAsB,EAAE,EAAE;gBAC5D,OAAO;aACR,CAAC,CAAC;YAEH,uEAAuE;YACvE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AAG,EAAE,CAAC,sBAAsB,EAAE,EAAE;gBAC5D,OAAO;aACR,CAAC,CAAC;YAEH,sEAAsE;YACtE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;YAE7D,qEAAqE;YACrE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAEhC,iDAAiD;YACjD,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC,0CAA0C,CAAC,EACnE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAClB,CAAC;YAEF,iDAAiD;YACjD,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,yBAAyB,EAAE;gBAC/D,KAAK,EAAE,eAAe;gBACtB,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YACH,eAAe,CAAC,WAAW,EAAE,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook } from \"@testing-library/react\";\nimport React from \"react\";\nimport * as contextHelpers from \"../../context-helpers\";\nimport { DEFAULT_CONTEXT_HELPERS } from \"../../context-helpers\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"../tambo-context-helpers-provider\";\n\ndescribe(\"TamboContextHelpersProvider\", () => {\n // Create a wrapper component that provides the context for testing hooks\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider>{children}</TamboContextHelpersProvider>\n );\n\n describe(\"useTamboContextHelpers\", () => {\n /**\n * Test: Hook throws error when used outside of provider\n * This ensures developers get a clear error message if they forget to wrap\n * their components with the TamboContextHelpersProvider\n */\n it(\"should throw error when used outside provider\", () => {\n // Mock console.error to prevent error output in test logs\n const consoleSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n\n // Verify that using the hook without a provider throws the expected error\n expect(() => {\n renderHook(() => useTamboContextHelpers());\n }).toThrow(\n \"useTamboContextHelpers must be used within a TamboContextHelpersProvider\",\n );\n\n // Restore console.error to its original implementation\n consoleSpy.mockRestore();\n });\n\n /**\n * Test: Hook provides the expected API functions\n * Verifies that all required functions are available when the hook is used\n * within the provider context\n */\n it(\"should provide context helpers functions\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n\n // Verify all expected functions are present in the hook's return value\n expect(result.current).toHaveProperty(\"getAdditionalContext\");\n expect(result.current).toHaveProperty(\"getContextHelpers\");\n expect(result.current).toHaveProperty(\"setContextHelperEnabled\");\n });\n\n /**\n * Test: Default configuration is applied correctly\n * Ensures that the default context helpers are loaded with their\n * expected enabled/disabled states\n */\n it(\"should return default context helpers configuration\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n\n const helpers = result.current.getContextHelpers();\n\n // Verify we have the expected number of default helpers\n expect(helpers).toHaveLength(DEFAULT_CONTEXT_HELPERS.length);\n\n // Check specific helpers have their expected default states\n const userTimeHelper = helpers.find((h) => h.name === \"userTime\");\n const userPageHelper = helpers.find((h) => h.name === \"userPage\");\n\n // userTime should be disabled by default\n expect(userTimeHelper?.enabled).toBe(false);\n // userPage should be disabled by default\n expect(userPageHelper?.enabled).toBe(false);\n });\n\n /**\n * Test: Context helper enabled state can be toggled\n * Verifies that the setContextHelperEnabled function correctly updates\n * the enabled state of individual helpers\n */\n it(\"should allow toggling context helper enabled state\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n\n // Enable the userPage helper using the provided function\n act(() => {\n result.current.setContextHelperEnabled(\"userPage\", true);\n });\n\n // Verify the helper's state was updated\n const helpers = result.current.getContextHelpers();\n const userPageHelper = helpers.find((h) => h.name === \"userPage\");\n\n expect(userPageHelper?.enabled).toBe(true);\n });\n\n /**\n * Test: Only enabled helpers contribute to additional context\n * Verifies that getAdditionalContext only runs and returns data from\n * helpers that are currently enabled\n */\n it(\"should get additional context from enabled helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n\n const contexts = await result.current.getAdditionalContext();\n\n // By default, no context helpers are enabled, so we should get no contexts\n expect(contexts).toHaveLength(0);\n });\n\n /**\n * Test: Provider respects configuration prop\n * Verifies that initial configuration can be customized through the\n * contextHelpers prop on the provider\n */\n it(\"should respect contextHelpers configuration prop\", () => {\n // Create a custom wrapper with specific configuration\n const customWrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n userTime: false, // Disable userTime\n userPage: true, // Enable userPage\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n );\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: customWrapper,\n });\n\n // Verify the custom configuration is applied\n const helpers = result.current.getContextHelpers();\n const userTimeHelper = helpers.find((h) => h.name === \"userTime\");\n const userPageHelper = helpers.find((h) => h.name === \"userPage\");\n\n expect(userTimeHelper?.enabled).toBe(false);\n expect(userPageHelper?.enabled).toBe(true);\n });\n\n /**\n * Test: Errors in context helpers are handled gracefully\n * Verifies that if a context helper throws an error, it doesn't crash\n * the entire system and other helpers continue to work\n */\n it(\"should handle errors in context helper functions gracefully\", async () => {\n // Mock console.error to capture error logs\n const consoleErrorSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n\n // Create a helper that will throw an error when run\n const errorHelper = {\n name: \"errorHelper\",\n enabled: true,\n run: () => {\n throw new Error(\"Test error\");\n },\n };\n\n // Temporarily add the error helper to the default helpers\n // Store original helpers to restore later\n const originalHelpers = DEFAULT_CONTEXT_HELPERS;\n Object.defineProperty(contextHelpers, \"DEFAULT_CONTEXT_HELPERS\", {\n value: [...originalHelpers, errorHelper],\n writable: true,\n });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n\n // Call getAdditionalContext, which should handle the error gracefully\n const contexts = await result.current.getAdditionalContext();\n\n // Should have no contexts because the error helper should be skipped\n expect(contexts.length).toBe(0);\n\n // Verify that the error was logged appropriately\n expect(consoleErrorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"Error running context helper errorHelper\"),\n expect.any(Error),\n );\n\n // Restore the original helpers and console.error\n Object.defineProperty(contextHelpers, \"DEFAULT_CONTEXT_HELPERS\", {\n value: originalHelpers,\n writable: true,\n });\n consoleErrorSpy.mockRestore();\n });\n });\n});\n"]}
1
+ {"version":3,"file":"tambo-context-helpers-provider.test.js","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-context-helpers-provider.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,mCAAmC,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,2EAA2E;IAC3E,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,CAAC,EAAE,CAAC,CAAC;QACf,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,wCAAwC;IACxC,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE,CAAC,CAC/D,oBAAC,2BAA2B,QAAE,QAAQ,CAA+B,CACtE,CAAC;IAEF,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC;;;WAGG;QACH,EAAE,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;YAC7E,MAAM,UAAU,GAAG,IAAI;iBACpB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC;iBACvB,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YA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aACd,CAAC,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,wBAAwB;QACxB,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QACvD,MAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC;YAC9B,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;SAC3B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook } from \"@testing-library/react\";\nimport React from \"react\";\nimport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"../../context-helpers\";\nimport { setHelpers } from \"../../context-helpers/registry\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"../tambo-context-helpers-provider\";\n\n/**\n * Test suite for TamboContextHelpersProvider (simplified API, registry-backed)\n *\n * The simplified API:\n * - Accepts a plain map of { key: () => any | null | undefined | Promise<any | null | undefined> }.\n * - The key becomes the context name sent to the model.\n * - Returning null/undefined from a helper skips inclusion.\n * - Prebuilt helpers are just functions (e.g., prebuiltUserTime, prebuiltUserPage).\n *\n * The hook is now registry-backed and safe to call outside a provider. When used\n * outside a provider, it proxies to a global registry and still works.\n */\ndescribe(\"TamboContextHelpersProvider\", () => {\n // Ensure registry is clean for each test to avoid cross-test contamination\n beforeEach(() => {\n setHelpers({});\n jest.clearAllMocks();\n });\n\n // Base wrapper with no helpers provided\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider>{children}</TamboContextHelpersProvider>\n );\n\n describe(\"useTamboContextHelpers\", () => {\n /**\n * NOTE: The hook is registry-backed and safe outside provider. It should not throw.\n * This replaces the previous behavior that threw without a provider.\n */\n it(\"should be safe outside provider (registry-backed no provider)\", async () => {\n const consoleSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n const { result } = renderHook(() => useTamboContextHelpers());\n\n // Should return callable functions\n expect(typeof result.current.getAdditionalContext).toBe(\"function\");\n expect(typeof result.current.getContextHelpers).toBe(\"function\");\n expect(typeof result.current.addContextHelper).toBe(\"function\");\n expect(typeof result.current.removeContextHelper).toBe(\"function\");\n\n // Starts empty\n expect(await result.current.getAdditionalContext()).toHaveLength(0);\n\n // Add a helper and verify\n act(() => {\n result.current.addContextHelper(\"outsideHelper\", () => ({ ok: true }));\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"outsideHelper\",\n context: { ok: true },\n });\n\n // Cleanup\n act(() => {\n result.current.removeContextHelper(\"outsideHelper\");\n });\n consoleSpy.mockRestore();\n });\n\n /**\n * Verifies that the hook returns the expected API functions when used within a provider.\n */\n it(\"should provide context helpers functions (inside provider)\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n expect(result.current).toHaveProperty(\"getAdditionalContext\");\n expect(result.current).toHaveProperty(\"getContextHelpers\");\n expect(result.current).toHaveProperty(\"addContextHelper\");\n expect(result.current).toHaveProperty(\"removeContextHelper\");\n });\n\n /**\n * With no helpers provided, no additional context should be returned.\n */\n it(\"should return no additional context when no helpers are provided\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(0);\n });\n\n /**\n * When helpers are provided, getAdditionalContext should aggregate them.\n * Note: prebuiltUserPage may be null in non-browser envs, so we only assert userTime when present.\n */\n it(\"should get additional context when helpers are provided\", async () => {\n const withHelpers = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n userTime: currentTimeContextHelper,\n userPage: currentPageContextHelper,\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n );\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: withHelpers,\n });\n\n const contexts = await result.current.getAdditionalContext();\n const names = contexts.map((c) => c.name);\n\n // userTime should be present from prebuilt helper\n expect(names).toContain(\"userTime\");\n // userPage may be absent on server; do not assert strictly\n });\n\n /**\n * Errors thrown by helper functions should be caught and skipped, not crash the system.\n */\n it(\"should handle errors in context helper functions gracefully\", async () => {\n const consoleErrorSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n\n const badHelper = () => {\n throw new Error(\"Test error\");\n };\n\n const withBadHelper = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider contextHelpers={{ badHelper }}>\n {children}\n </TamboContextHelpersProvider>\n );\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: withBadHelper,\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts.length).toBe(0);\n expect(consoleErrorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"Error running context helper badHelper\"),\n expect.any(Error),\n );\n consoleErrorSpy.mockRestore();\n });\n });\n});\n\n/**\n * Test suite for Custom Context Helpers using the simplified API.\n *\n * Focuses on:\n * - Passing custom helpers via the provider prop.\n * - Overriding prebuilt helpers with custom implementations.\n * - Dynamic add/remove helper management at runtime.\n * - Supporting both sync and async helpers.\n * - Using the config key as the context name.\n * - Graceful error handling for custom helpers.\n */\ndescribe(\"Custom Context Helpers via contextHelpers config\", () => {\n beforeEach(() => {\n setHelpers({});\n jest.clearAllMocks();\n });\n\n /**\n * Custom helpers can be added through the provider configuration.\n * The key becomes the context name and the function returns the raw value.\n */\n it(\"should accept custom helpers through contextHelpers config\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n customData: async () => ({ custom: \"value\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"customData\",\n context: { custom: \"value\" },\n });\n });\n\n /**\n * Built-in helpers can be overridden by providing a function under the same key.\n */\n it(\"should allow custom helpers to override built-in ones\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n userTime: async () => ({ customTime: \"override\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n const userTimeContext = contexts.find((c) => c.name === \"userTime\");\n expect(userTimeContext?.context).toEqual({ customTime: \"override\" });\n });\n\n /**\n * Helpers can be added dynamically at runtime via addContextHelper.\n */\n it(\"should handle dynamic addition of custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider contextHelpers={{}}>\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Initially none\n expect(await result.current.getAdditionalContext()).toHaveLength(0);\n\n act(() => {\n result.current.addContextHelper(\"dynamicHelper\", async () => ({\n dynamic: true,\n }));\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"dynamicHelper\",\n context: { dynamic: true },\n });\n });\n\n /**\n * Helpers can be removed dynamically via removeContextHelper.\n */\n it(\"should handle dynamic removal of context helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n customHelper: async () => ({ test: \"data\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Verify exists\n let contexts = await result.current.getAdditionalContext();\n expect(contexts.find((c) => c.name === \"customHelper\")).toBeDefined();\n\n // Remove\n act(() => {\n result.current.removeContextHelper(\"customHelper\");\n });\n\n // Verify removed\n contexts = await result.current.getAdditionalContext();\n expect(contexts.find((c) => c.name === \"customHelper\")).toBeUndefined();\n });\n\n /**\n * Multiple custom helpers should be supported; helpers returning null/undefined are skipped.\n */\n it(\"should handle multiple custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n helper1: async () => ({ data: \"one\" }),\n helper2: async () => ({ data: \"two\" }),\n helper3: () => null, // disabled by returning null\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"helper1\",\n context: { data: \"one\" },\n });\n expect(contexts).toContainEqual({\n name: \"helper2\",\n context: { data: \"two\" },\n });\n expect(contexts.find((c) => c.name === \"helper3\")).toBeUndefined();\n });\n\n /**\n * Both synchronous and asynchronous helpers should be supported.\n */\n it(\"should handle sync and async custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n syncHelper: () => ({ sync: true }),\n asyncHelper: async () => {\n await new Promise((resolve) => setTimeout(resolve, 10));\n return { async: true };\n },\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"syncHelper\",\n context: { sync: true },\n });\n expect(contexts).toContainEqual({\n name: \"asyncHelper\",\n context: { async: true },\n });\n });\n\n /**\n * The key used in the contextHelpers map becomes the context name.\n */\n it(\"should use key name as context name for custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n myCustomKey: async () => ({ value: \"test\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"myCustomKey\",\n context: { value: \"test\" },\n });\n });\n\n /**\n * Errors thrown by custom helpers should be logged and skipped, not crash the system.\n */\n it(\"should handle errors in custom helpers gracefully\", async () => {\n const consoleErrorSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n errorHelper: async () => {\n throw new Error(\"Custom helper error\");\n },\n goodHelper: async () => ({ good: \"data\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"goodHelper\",\n context: { good: \"data\" },\n });\n expect(contexts.find((c) => c.name === \"errorHelper\")).toBeUndefined();\n expect(consoleErrorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"Error running context helper errorHelper\"),\n expect.any(Error),\n );\n consoleErrorSpy.mockRestore();\n });\n\n /**\n * Removing non-existent helpers should be a no-op without throwing errors.\n */\n it(\"should handle removing non-existent helper gracefully\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider contextHelpers={{}}>\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n expect(() => {\n act(() => {\n result.current.removeContextHelper(\"nonExistent\");\n });\n }).not.toThrow();\n });\n\n /**\n * Adding with an existing name should update/replace the helper implementation.\n */\n it(\"should allow updating existing helper via addContextHelper\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n testHelper: async () => ({ original: true }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Verify original helper\n let contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"testHelper\",\n context: { original: true },\n });\n\n // Update the helper\n act(() => {\n result.current.addContextHelper(\"testHelper\", async () => ({\n updated: true,\n }));\n });\n\n // Verify updated helper\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"testHelper\",\n context: { updated: true },\n });\n });\n});\n"]}