@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
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Tests for the Context Helpers API.
3
+ *
4
+ * The new API treats a context helper as a plain function that returns a value
5
+ * to include in context, or null/undefined to skip. The provider wraps each
6
+ * value with its key name as { name, context } before sending with messages.
7
+ *
8
+ * This test suite validates that:
9
+ * - Helper functions can return sync/async values.
10
+ * - Returning null/undefined causes the helper to be skipped.
11
+ * - Errors in helpers are caught and skipped.
12
+ * - The provider aggregates helpers passed in its props and returns AdditionalContext[].
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=context-helpers-provider.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-helpers-provider.test.d.ts","sourceRoot":"","sources":["../../../src/context-helpers/__tests__/context-helpers-provider.test.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ /**
3
+ * Tests for the Context Helpers API.
4
+ *
5
+ * The new API treats a context helper as a plain function that returns a value
6
+ * to include in context, or null/undefined to skip. The provider wraps each
7
+ * value with its key name as { name, context } before sending with messages.
8
+ *
9
+ * This test suite validates that:
10
+ * - Helper functions can return sync/async values.
11
+ * - Returning null/undefined causes the helper to be skipped.
12
+ * - Errors in helpers are caught and skipped.
13
+ * - The provider aggregates helpers passed in its props and returns AdditionalContext[].
14
+ */
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ const react_1 = require("@testing-library/react");
20
+ const react_2 = __importDefault(require("react"));
21
+ const registry_1 = require("../../context-helpers/registry");
22
+ const tambo_context_helpers_provider_1 = require("../../providers/tambo-context-helpers-provider");
23
+ const index_1 = require("../index");
24
+ /**
25
+ * Test wrapper to provide the TamboContextHelpersProvider for hooks.
26
+ * @param helpers - A dictionary of context helper functions.
27
+ * @returns A wrapper component that provides the TamboContextHelpersProvider.
28
+ */
29
+ function wrapper(helpers) {
30
+ // eslint-disable-next-line react/display-name
31
+ return ({ children }) => react_2.default.createElement(tambo_context_helpers_provider_1.TamboContextHelpersProvider, {
32
+ contextHelpers: helpers,
33
+ }, children);
34
+ }
35
+ describe("Context Helpers API", () => {
36
+ // Ensure the global registry doesn't leak state between tests
37
+ beforeEach(() => {
38
+ (0, registry_1.setHelpers)({});
39
+ jest.clearAllMocks();
40
+ });
41
+ test("returns empty array when no helpers provided", async () => {
42
+ const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
43
+ wrapper: wrapper(),
44
+ });
45
+ const contexts = await result.current.getAdditionalContext();
46
+ expect(Array.isArray(contexts)).toBe(true);
47
+ expect(contexts).toHaveLength(0);
48
+ });
49
+ test("collects sync and async helper results", async () => {
50
+ const syncHelper = () => ({ a: 1 });
51
+ const asyncHelper = async () => ({ b: 2 });
52
+ const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
53
+ wrapper: wrapper({
54
+ sync: syncHelper,
55
+ async: asyncHelper,
56
+ }),
57
+ });
58
+ const contexts = await result.current.getAdditionalContext();
59
+ // Validate shape and presence
60
+ const byName = new Map(contexts.map((c) => [c.name, c.context]));
61
+ expect(byName.get("sync")).toEqual({ a: 1 });
62
+ expect(byName.get("async")).toEqual({ b: 2 });
63
+ });
64
+ test("skips null and undefined results", async () => {
65
+ const nullHelper = () => null;
66
+ const undefinedHelper = () => undefined;
67
+ const validHelper = () => ({ ok: true });
68
+ const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
69
+ wrapper: wrapper({
70
+ nullHelper,
71
+ undefinedHelper,
72
+ validHelper,
73
+ }),
74
+ });
75
+ const contexts = await result.current.getAdditionalContext();
76
+ const names = contexts.map((c) => c.name);
77
+ expect(names).toContain("validHelper");
78
+ expect(names).not.toContain("nullHelper");
79
+ expect(names).not.toContain("undefinedHelper");
80
+ });
81
+ test("errors in helpers are caught and skipped", async () => {
82
+ const consoleSpy = jest.spyOn(console, "error").mockImplementation(() => {
83
+ // silence expected error
84
+ });
85
+ const badHelper = () => {
86
+ throw new Error("boom");
87
+ };
88
+ const goodHelper = () => ({ ok: 1 });
89
+ const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
90
+ wrapper: wrapper({ badHelper, goodHelper }),
91
+ });
92
+ const contexts = await result.current.getAdditionalContext();
93
+ expect(contexts).toHaveLength(1);
94
+ expect(contexts[0]).toEqual({
95
+ name: "goodHelper",
96
+ context: { ok: 1 },
97
+ });
98
+ consoleSpy.mockRestore();
99
+ });
100
+ test("dynamic add/remove helpers works", async () => {
101
+ const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
102
+ wrapper: wrapper(),
103
+ });
104
+ // Initially empty
105
+ expect(await result.current.getAdditionalContext()).toHaveLength(0);
106
+ // Add
107
+ result.current.addContextHelper("dyn", () => ({ x: 10 }));
108
+ let contexts = await result.current.getAdditionalContext();
109
+ expect(contexts).toHaveLength(1);
110
+ expect(contexts[0]).toEqual({
111
+ name: "dyn",
112
+ context: { x: 10 },
113
+ });
114
+ // Update
115
+ result.current.addContextHelper("dyn", () => ({ x: 20 }));
116
+ contexts = await result.current.getAdditionalContext();
117
+ expect(contexts).toHaveLength(1);
118
+ expect(contexts[0]).toEqual({
119
+ name: "dyn",
120
+ context: { x: 20 },
121
+ });
122
+ // Remove
123
+ result.current.removeContextHelper("dyn");
124
+ contexts = await result.current.getAdditionalContext();
125
+ expect(contexts).toHaveLength(0);
126
+ });
127
+ test("prebuilt helpers can be passed directly", async () => {
128
+ const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
129
+ wrapper: wrapper({
130
+ userTime: index_1.currentTimeContextHelper,
131
+ userPage: index_1.currentPageContextHelper,
132
+ }),
133
+ });
134
+ const contexts = await result.current.getAdditionalContext();
135
+ // Should include both entries unless environment prevents userPage (SSR)
136
+ const names = contexts.map((c) => c.name);
137
+ expect(names).toContain("userTime");
138
+ // userPage may be null on non-browser envs; allow either outcome:
139
+ // if present, ensure expected keys exist
140
+ if (names.includes("userPage")) {
141
+ const userPage = contexts.find((c) => c.name === "userPage").context;
142
+ expect(typeof userPage.url === "string" || userPage.url === undefined).toBe(true);
143
+ expect(typeof userPage.title === "string" || userPage.title === undefined).toBe(true);
144
+ }
145
+ });
146
+ });
147
+ //# sourceMappingURL=context-helpers-provider.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-helpers-provider.test.js","sourceRoot":"","sources":["../../../src/context-helpers/__tests__/context-helpers-provider.test.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;AAEH,kDAAoD;AACpD,kDAAiD;AACjD,6DAA4D;AAC5D,mGAGwD;AACxD,oCAKkB;AAElB;;;;GAIG;AACH,SAAS,OAAO,CAAC,OAAyC;IACxD,8CAA8C;IAC9C,OAAO,CAAC,EAAE,QAAQ,EAAqB,EAAE,EAAE,CACzC,eAAK,CAAC,aAAa,CACjB,4DAA2B,EAC3B;QACE,cAAc,EAAE,OAAO;KACxB,EACD,QAAQ,CACT,CAAC;AACN,CAAC;AAED,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,8DAA8D;IAC9D,UAAU,CAAC,GAAG,EAAE;QACd,IAAA,qBAAU,EAAC,EAAE,CAAC,CAAC;QACf,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC9D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,uDAAsB,GAAE,EAAE;YAC5D,OAAO,EAAE,OAAO,EAAE;SACnB,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAC7D,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,CAAC,QAAQ,CAAC,CAAC,YAAY,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,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAE,CAAC,OAG7D,CAAC;YACF,MAAM,CACJ,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ,IAAI,QAAQ,CAAC,GAAG,KAAK,SAAS,CAC/D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,MAAM,CACJ,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,CACnE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Tests for the Context Helpers API.\n *\n * The new API treats a context helper as a plain function that returns a value\n * to include in context, or null/undefined to skip. The provider wraps each\n * value with its key name as { name, context } before sending with messages.\n *\n * This test suite validates that:\n * - Helper functions can return sync/async values.\n * - Returning null/undefined causes the helper to be skipped.\n * - Errors in helpers are caught and skipped.\n * - The provider aggregates helpers passed in its props and returns AdditionalContext[].\n */\n\nimport { renderHook } from \"@testing-library/react\";\nimport React, { PropsWithChildren } from \"react\";\nimport { setHelpers } from \"../../context-helpers/registry\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"../../providers/tambo-context-helpers-provider\";\nimport {\n type AdditionalContext,\n type ContextHelperFn,\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"../index\";\n\n/**\n * Test wrapper to provide the TamboContextHelpersProvider for hooks.\n * @param helpers - A dictionary of context helper functions.\n * @returns A wrapper component that provides the TamboContextHelpersProvider.\n */\nfunction wrapper(helpers?: Record<string, ContextHelperFn>) {\n // eslint-disable-next-line react/display-name\n return ({ children }: PropsWithChildren) =>\n React.createElement(\n TamboContextHelpersProvider,\n {\n contextHelpers: helpers,\n },\n children,\n );\n}\n\ndescribe(\"Context Helpers API\", () => {\n // Ensure the global registry doesn't leak state between tests\n beforeEach(() => {\n setHelpers({});\n jest.clearAllMocks();\n });\n\n test(\"returns empty array when no helpers provided\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper(),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(Array.isArray(contexts)).toBe(true);\n expect(contexts).toHaveLength(0);\n });\n\n test(\"collects sync and async helper results\", async () => {\n const syncHelper: ContextHelperFn = () => ({ a: 1 });\n const asyncHelper: ContextHelperFn = async () => ({ b: 2 });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n sync: syncHelper,\n async: asyncHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n\n // Validate shape and presence\n const byName = new Map(contexts.map((c) => [c.name, c.context]));\n expect(byName.get(\"sync\")).toEqual({ a: 1 });\n expect(byName.get(\"async\")).toEqual({ b: 2 });\n });\n\n test(\"skips null and undefined results\", async () => {\n const nullHelper: ContextHelperFn = () => null;\n const undefinedHelper: ContextHelperFn = () => undefined;\n const validHelper: ContextHelperFn = () => ({ ok: true });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n nullHelper,\n undefinedHelper,\n validHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n const names = contexts.map((c) => c.name);\n\n expect(names).toContain(\"validHelper\");\n expect(names).not.toContain(\"nullHelper\");\n expect(names).not.toContain(\"undefinedHelper\");\n });\n\n test(\"errors in helpers are caught and skipped\", async () => {\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation(() => {\n // silence expected error\n });\n\n const badHelper: ContextHelperFn = () => {\n throw new Error(\"boom\");\n };\n const goodHelper: ContextHelperFn = () => ({ ok: 1 });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({ badHelper, goodHelper }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"goodHelper\",\n context: { ok: 1 },\n });\n\n consoleSpy.mockRestore();\n });\n\n test(\"dynamic add/remove helpers works\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper(),\n });\n\n // Initially empty\n expect(await result.current.getAdditionalContext()).toHaveLength(0);\n\n // Add\n result.current.addContextHelper(\"dyn\", () => ({ x: 10 }));\n let contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"dyn\",\n context: { x: 10 },\n });\n\n // Update\n result.current.addContextHelper(\"dyn\", () => ({ x: 20 }));\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"dyn\",\n context: { x: 20 },\n });\n\n // Remove\n result.current.removeContextHelper(\"dyn\");\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(0);\n });\n\n test(\"prebuilt helpers can be passed directly\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n userTime: currentTimeContextHelper,\n userPage: currentPageContextHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n\n // Should include both entries unless environment prevents userPage (SSR)\n const names = contexts.map((c) => c.name);\n expect(names).toContain(\"userTime\");\n // userPage may be null on non-browser envs; allow either outcome:\n // if present, ensure expected keys exist\n if (names.includes(\"userPage\")) {\n const userPage = contexts.find((c) => c.name === \"userPage\")!.context as {\n url?: string;\n title?: string;\n };\n expect(\n typeof userPage.url === \"string\" || userPage.url === undefined,\n ).toBe(true);\n expect(\n typeof userPage.title === \"string\" || userPage.title === undefined,\n ).toBe(true);\n }\n });\n});\n"]}
@@ -1,43 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_1 = require("../index");
4
- describe("Context Helpers", () => {
5
- describe("getUserTimeContext", () => {
6
- it("should return user time context with all required fields", () => {
7
- const context = (0, index_1.getUserTimeContext)();
8
- expect(context.name).toBe("userTime");
9
- expect(context.context).toHaveProperty("localTime");
10
- expect(context.context).toHaveProperty("timezone");
11
- expect(context.context).toHaveProperty("timestamp");
12
- expect(context.context).toHaveProperty("offsetMinutes");
13
- // Verify data types
14
- expect(typeof context.context.localTime).toBe("string");
15
- expect(typeof context.context.timezone).toBe("string");
16
- expect(typeof context.context.timestamp).toBe("string");
17
- expect(typeof context.context.offsetMinutes).toBe("number");
18
- // Verify timestamp is valid ISO string
19
- expect(() => new Date(context.context.timestamp)).not.toThrow();
4
+ /**
5
+ * Tests for prebuilt context helper functions.
6
+ *
7
+ * These helpers now return raw values (or null) instead of { name, context }.
8
+ * The provider is responsible for wrapping values as { name, context }.
9
+ */
10
+ describe("Context Helpers (prebuilt functions)", () => {
11
+ describe("currentTimeContextHelper", () => {
12
+ it("should return user time context with required fields", () => {
13
+ const context = (0, index_1.currentTimeContextHelper)();
14
+ // Should not be null (error case)
15
+ expect(context).not.toBeNull();
16
+ // Shape: { timestamp: string }
17
+ expect(context).toHaveProperty("timestamp");
18
+ expect(typeof context.timestamp).toBe("string");
19
+ // Verify timestamp string parses
20
+ expect(() => new Date(context.timestamp)).not.toThrow();
20
21
  });
21
22
  });
22
- describe("getUserPageContext", () => {
23
- it("should return page context with default values in test environment", () => {
24
- const context = (0, index_1.getUserPageContext)();
25
- expect(context.name).toBe("userPage");
26
- expect(context.context).toHaveProperty("url");
27
- expect(context.context).toHaveProperty("pathname");
28
- expect(context.context).toHaveProperty("hostname");
29
- expect(context.context).toHaveProperty("search");
30
- expect(context.context).toHaveProperty("hash");
31
- expect(context.context).toHaveProperty("title");
32
- expect(context.context).toHaveProperty("referrer");
33
- // Verify data types
34
- expect(typeof context.context.url).toBe("string");
35
- expect(typeof context.context.pathname).toBe("string");
36
- expect(typeof context.context.hostname).toBe("string");
37
- expect(typeof context.context.search).toBe("string");
38
- expect(typeof context.context.hash).toBe("string");
39
- expect(typeof context.context.title).toBe("string");
40
- expect(typeof context.context.referrer).toBe("string");
23
+ describe("currentPageContextHelper", () => {
24
+ it("should return page context in browser, or null otherwise", () => {
25
+ const context = (0, index_1.currentPageContextHelper)();
26
+ if (context === null) {
27
+ // Non-browser environments should return null to skip
28
+ expect(context).toBeNull();
29
+ return;
30
+ }
31
+ // Shape: { url: string, title: string }
32
+ expect(context).toHaveProperty("url");
33
+ expect(context).toHaveProperty("title");
34
+ expect(typeof context.url).toBe("string");
35
+ expect(typeof context.title).toBe("string");
41
36
  });
42
37
  });
43
38
  });
@@ -1 +1 @@
1
- {"version":3,"file":"context-helpers.test.js","sourceRoot":"","sources":["../../../src/context-helpers/__tests__/context-helpers.test.ts"],"names":[],"mappings":";;AAAA,oCAAkE;AAElE,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;YAClE,MAAM,OAAO,GAAG,IAAA,0BAAkB,GAAE,CAAC;YAErC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACtC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YACpD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;YACnD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YACpD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;YAExD,oBAAoB;YACpB,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxD,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO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QAAQ,CAAC,CAAC;YAClD,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACrD,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnD,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpD,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { getUserPageContext, getUserTimeContext } from \"../index\";\n\ndescribe(\"Context Helpers\", () => {\n describe(\"getUserTimeContext\", () => {\n it(\"should return user time context with all required fields\", () => {\n const context = getUserTimeContext();\n\n expect(context.name).toBe(\"userTime\");\n expect(context.context).toHaveProperty(\"localTime\");\n expect(context.context).toHaveProperty(\"timezone\");\n expect(context.context).toHaveProperty(\"timestamp\");\n expect(context.context).toHaveProperty(\"offsetMinutes\");\n\n // Verify data types\n expect(typeof context.context.localTime).toBe(\"string\");\n expect(typeof context.context.timezone).toBe(\"string\");\n expect(typeof context.context.timestamp).toBe(\"string\");\n expect(typeof context.context.offsetMinutes).toBe(\"number\");\n\n // Verify timestamp is valid ISO string\n expect(() => new Date(context.context.timestamp)).not.toThrow();\n });\n });\n\n describe(\"getUserPageContext\", () => {\n it(\"should return page context with default values in test environment\", () => {\n const context = getUserPageContext();\n\n expect(context.name).toBe(\"userPage\");\n expect(context.context).toHaveProperty(\"url\");\n expect(context.context).toHaveProperty(\"pathname\");\n expect(context.context).toHaveProperty(\"hostname\");\n expect(context.context).toHaveProperty(\"search\");\n expect(context.context).toHaveProperty(\"hash\");\n expect(context.context).toHaveProperty(\"title\");\n expect(context.context).toHaveProperty(\"referrer\");\n\n // Verify data types\n expect(typeof context.context.url).toBe(\"string\");\n expect(typeof context.context.pathname).toBe(\"string\");\n expect(typeof context.context.hostname).toBe(\"string\");\n expect(typeof context.context.search).toBe(\"string\");\n expect(typeof context.context.hash).toBe(\"string\");\n expect(typeof context.context.title).toBe(\"string\");\n expect(typeof context.context.referrer).toBe(\"string\");\n });\n });\n});\n"]}
1
+ {"version":3,"file":"context-helpers.test.js","sourceRoot":"","sources":["../../../src/context-helpers/__tests__/context-helpers.test.ts"],"names":[],"mappings":";;AAAA,oCAA8E;AAE9E;;;;;GAKG;AACH,QAAQ,CAAC,sCAAsC,EAAE,GAAG,EAAE;IACpD,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACxC,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;YAC9D,MAAM,OAAO,GAAG,IAAA,gCAAwB,GAAE,CAAC;YAE3C,kCAAkC;YAClC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAE/B,+BAA+B;YAC/B,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YAC5C,MAAM,CAAC,OAAO,OAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAEjD,iCAAiC;YACjC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,OAAQ,CAAC,SAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACrE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACxC,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;YAClE,MAAM,OAAO,GAAG,IAAA,gCAAwB,GAAE,CAAC;YAE3C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBACrB,sDAAsD;gBACtD,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;gBAC3B,OAAO;YACT,CAAC;YAED,wCAAwC;YACxC,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YACtC,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAExC,MAAM,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1C,MAAM,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { currentPageContextHelper, currentTimeContextHelper } from \"../index\";\n\n/**\n * Tests for prebuilt context helper functions.\n *\n * These helpers now return raw values (or null) instead of { name, context }.\n * The provider is responsible for wrapping values as { name, context }.\n */\ndescribe(\"Context Helpers (prebuilt functions)\", () => {\n describe(\"currentTimeContextHelper\", () => {\n it(\"should return user time context with required fields\", () => {\n const context = currentTimeContextHelper();\n\n // Should not be null (error case)\n expect(context).not.toBeNull();\n\n // Shape: { timestamp: string }\n expect(context).toHaveProperty(\"timestamp\");\n expect(typeof context!.timestamp).toBe(\"string\");\n\n // Verify timestamp string parses\n expect(() => new Date(context!.timestamp as string)).not.toThrow();\n });\n });\n\n describe(\"currentPageContextHelper\", () => {\n it(\"should return page context in browser, or null otherwise\", () => {\n const context = currentPageContextHelper();\n\n if (context === null) {\n // Non-browser environments should return null to skip\n expect(context).toBeNull();\n return;\n }\n\n // Shape: { url: string, title: string }\n expect(context).toHaveProperty(\"url\");\n expect(context).toHaveProperty(\"title\");\n\n expect(typeof context.url).toBe(\"string\");\n expect(typeof context.title).toBe(\"string\");\n });\n });\n});\n"]}
@@ -0,0 +1,7 @@
1
+ import { ContextHelperFn } from "./types";
2
+ /**
3
+ * Prebuilt context helper that provides information about the user's current page.
4
+ * @returns a value to include it, or null/undefined to skip.
5
+ */
6
+ export declare const currentPageContextHelper: ContextHelperFn;
7
+ //# sourceMappingURL=current-page-context-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-page-context-helper.d.ts","sourceRoot":"","sources":["../../src/context-helpers/current-page-context-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,eAatC,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.currentPageContextHelper = void 0;
4
+ /**
5
+ * Prebuilt context helper that provides information about the user's current page.
6
+ * @returns a value to include it, or null/undefined to skip.
7
+ */
8
+ const currentPageContextHelper = () => {
9
+ try {
10
+ if (typeof window === "undefined") {
11
+ return null;
12
+ }
13
+ return {
14
+ url: window.location.href,
15
+ title: document.title,
16
+ };
17
+ }
18
+ catch (e) {
19
+ console.error("prebuiltUserPage failed:", e);
20
+ return null;
21
+ }
22
+ };
23
+ exports.currentPageContextHelper = currentPageContextHelper;
24
+ //# sourceMappingURL=current-page-context-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-page-context-helper.js","sourceRoot":"","sources":["../../src/context-helpers/current-page-context-helper.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,wBAAwB,GAAoB,GAAG,EAAE;IAC5D,IAAI,CAAC;QACH,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO;YACL,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;YACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;SACtB,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,CAAC,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAbW,QAAA,wBAAwB,4BAanC","sourcesContent":["import { ContextHelperFn } from \"./types\";\n\n/**\n * Prebuilt context helper that provides information about the user's current page.\n * @returns a value to include it, or null/undefined to skip.\n */\nexport const currentPageContextHelper: ContextHelperFn = () => {\n try {\n if (typeof window === \"undefined\") {\n return null;\n }\n return {\n url: window.location.href,\n title: document.title,\n };\n } catch (e) {\n console.error(\"prebuiltUserPage failed:\", e);\n return null;\n }\n};\n"]}
@@ -0,0 +1,7 @@
1
+ import { ContextHelperFn } from "./types";
2
+ /**
3
+ * Prebuilt context helper that provides information about the user's current time.
4
+ * @returns a value to include it, or null/undefined to skip.
5
+ */
6
+ export declare const currentTimeContextHelper: ContextHelperFn;
7
+ //# sourceMappingURL=current-time-context-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-time-context-helper.d.ts","sourceRoot":"","sources":["../../src/context-helpers/current-time-context-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,eAUtC,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.currentTimeContextHelper = void 0;
4
+ /**
5
+ * Prebuilt context helper that provides information about the user's current time.
6
+ * @returns a value to include it, or null/undefined to skip.
7
+ */
8
+ const currentTimeContextHelper = () => {
9
+ try {
10
+ const now = new Date();
11
+ return {
12
+ timestamp: now.toString(),
13
+ };
14
+ }
15
+ catch (e) {
16
+ console.error("prebuiltUserTime failed:", e);
17
+ return null;
18
+ }
19
+ };
20
+ exports.currentTimeContextHelper = currentTimeContextHelper;
21
+ //# sourceMappingURL=current-time-context-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-time-context-helper.js","sourceRoot":"","sources":["../../src/context-helpers/current-time-context-helper.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,wBAAwB,GAAoB,GAAG,EAAE;IAC5D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,OAAO;YACL,SAAS,EAAE,GAAG,CAAC,QAAQ,EAAE;SAC1B,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,CAAC,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,wBAAwB,4BAUnC","sourcesContent":["import { ContextHelperFn } from \"./types\";\n\n/**\n * Prebuilt context helper that provides information about the user's current time.\n * @returns a value to include it, or null/undefined to skip.\n */\nexport const currentTimeContextHelper: ContextHelperFn = () => {\n try {\n const now = new Date();\n return {\n timestamp: now.toString(),\n };\n } catch (e) {\n console.error(\"prebuiltUserTime failed:\", e);\n return null;\n }\n};\n"]}
@@ -1,9 +1,4 @@
1
- import { AdditionalContextHelper } from "./types";
1
+ export * from "./current-page-context-helper";
2
+ export * from "./current-time-context-helper";
2
3
  export * from "./types";
3
- export * from "./user-page";
4
- export * from "./user-time";
5
- /**
6
- * Pre-built context helpers that can be enabled/disabled
7
- */
8
- export declare const DEFAULT_CONTEXT_HELPERS: AdditionalContextHelper[];
9
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIlD,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,uBAAuB,EAW5D,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC"}
@@ -14,25 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.DEFAULT_CONTEXT_HELPERS = void 0;
18
- const user_page_1 = require("./user-page");
19
- const user_time_1 = require("./user-time");
17
+ __exportStar(require("./current-page-context-helper"), exports);
18
+ __exportStar(require("./current-time-context-helper"), exports);
20
19
  __exportStar(require("./types"), exports);
21
- __exportStar(require("./user-page"), exports);
22
- __exportStar(require("./user-time"), exports);
23
- /**
24
- * Pre-built context helpers that can be enabled/disabled
25
- */
26
- exports.DEFAULT_CONTEXT_HELPERS = [
27
- {
28
- name: "userTime",
29
- enabled: false, // Default to disabled
30
- run: user_time_1.getUserTimeContext,
31
- },
32
- {
33
- name: "userPage",
34
- enabled: false, // Default to disabled
35
- run: user_page_1.getUserPageContext,
36
- },
37
- ];
38
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,2CAAiD;AACjD,2CAAiD;AAEjD,0CAAwB;AACxB,8CAA4B;AAC5B,8CAA4B;AAE5B;;GAEG;AACU,QAAA,uBAAuB,GAA8B;IAChE;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,KAAK,EAAE,sBAAsB;QACtC,GAAG,EAAE,8BAAkB;KACxB;IACD;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,KAAK,EAAE,sBAAsB;QACtC,GAAG,EAAE,8BAAkB;KACxB;CACF,CAAC","sourcesContent":["import { AdditionalContextHelper } from \"./types\";\nimport { getUserPageContext } from \"./user-page\";\nimport { getUserTimeContext } from \"./user-time\";\n\nexport * from \"./types\";\nexport * from \"./user-page\";\nexport * from \"./user-time\";\n\n/**\n * Pre-built context helpers that can be enabled/disabled\n */\nexport const DEFAULT_CONTEXT_HELPERS: AdditionalContextHelper[] = [\n {\n name: \"userTime\",\n enabled: false, // Default to disabled\n run: getUserTimeContext,\n },\n {\n name: \"userPage\",\n enabled: false, // Default to disabled\n run: getUserPageContext,\n },\n];\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,gEAA8C;AAC9C,0CAAwB","sourcesContent":["export * from \"./current-page-context-helper\";\nexport * from \"./current-time-context-helper\";\nexport * from \"./types\";\n"]}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Global context helpers registry.
3
+ * Consumers can add/remove helpers and resolve additional context anywhere.
4
+ */
5
+ export type HelperFn = () => any | null | undefined | Promise<any | null | undefined>;
6
+ /**
7
+ * Get the current helpers map (by reference).
8
+ * @returns The current helpers map.
9
+ */
10
+ export declare function getHelpers(): Record<string, HelperFn>;
11
+ /**
12
+ * Replace the entire helpers map (used for hydration/reset in tests).
13
+ * @param next - The new helpers map.
14
+ */
15
+ export declare function setHelpers(next: Record<string, HelperFn>): void;
16
+ /**
17
+ * Add or replace a helper.
18
+ * @param name - The name of the helper.
19
+ * @param fn - The helper function.
20
+ */
21
+ export declare function addHelper(name: string, fn: HelperFn): void;
22
+ /**
23
+ * Remove a helper by name.
24
+ * @param name - The name of the helper.
25
+ */
26
+ export declare function removeHelper(name: string): void;
27
+ /**
28
+ * Resolve all helpers to AdditionalContext entries, skipping null/undefined and errors.
29
+ * @returns The resolved additional context.
30
+ */
31
+ export declare function resolveAdditionalContext(): Promise<{
32
+ name: string;
33
+ context: any;
34
+ }[]>;
35
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAAG,MACnB,GAAG,GACH,IAAI,GACJ,SAAS,GACT,OAAO,CAAC,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAIpC;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAErD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAExD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,QAEnD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,QAExC;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CACvD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,EAAE,CACjC,CAkBA"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * Global context helpers registry.
4
+ * Consumers can add/remove helpers and resolve additional context anywhere.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getHelpers = getHelpers;
8
+ exports.setHelpers = setHelpers;
9
+ exports.addHelper = addHelper;
10
+ exports.removeHelper = removeHelper;
11
+ exports.resolveAdditionalContext = resolveAdditionalContext;
12
+ let helpers = {};
13
+ /**
14
+ * Get the current helpers map (by reference).
15
+ * @returns The current helpers map.
16
+ */
17
+ function getHelpers() {
18
+ return helpers;
19
+ }
20
+ /**
21
+ * Replace the entire helpers map (used for hydration/reset in tests).
22
+ * @param next - The new helpers map.
23
+ */
24
+ function setHelpers(next) {
25
+ helpers = next;
26
+ }
27
+ /**
28
+ * Add or replace a helper.
29
+ * @param name - The name of the helper.
30
+ * @param fn - The helper function.
31
+ */
32
+ function addHelper(name, fn) {
33
+ helpers[name] = fn;
34
+ }
35
+ /**
36
+ * Remove a helper by name.
37
+ * @param name - The name of the helper.
38
+ */
39
+ function removeHelper(name) {
40
+ delete helpers[name];
41
+ }
42
+ /**
43
+ * Resolve all helpers to AdditionalContext entries, skipping null/undefined and errors.
44
+ * @returns The resolved additional context.
45
+ */
46
+ async function resolveAdditionalContext() {
47
+ const entries = Object.entries(helpers);
48
+ if (entries.length === 0)
49
+ return [];
50
+ const results = await Promise.all(entries.map(async ([name, fn]) => {
51
+ try {
52
+ const value = await fn();
53
+ if (value == null)
54
+ return null;
55
+ return { name, context: value };
56
+ }
57
+ catch (error) {
58
+ console.error(`Error running context helper ${name}:`, error);
59
+ return null;
60
+ }
61
+ }));
62
+ return results.filter(Boolean);
63
+ }
64
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAcH,gCAEC;AAMD,gCAEC;AAOD,8BAEC;AAMD,oCAEC;AAMD,4DAoBC;AA3DD,IAAI,OAAO,GAA6B,EAAE,CAAC;AAE3C;;;GAGG;AACH,SAAgB,UAAU;IACxB,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU,CAAC,IAA8B;IACvD,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS,CAAC,IAAY,EAAE,EAAY;IAClD,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,IAAY;IACvC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,wBAAwB;IAG5C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;QAC/B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,EAAE,EAAE,CAAC;YACzB,IAAI,KAAK,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAC;YAC/B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAqC,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Global context helpers registry.\n * Consumers can add/remove helpers and resolve additional context anywhere.\n */\n\nexport type HelperFn = () =>\n | any\n | null\n | undefined\n | Promise<any | null | undefined>;\n\nlet helpers: Record<string, HelperFn> = {};\n\n/**\n * Get the current helpers map (by reference).\n * @returns The current helpers map.\n */\nexport function getHelpers(): Record<string, HelperFn> {\n return helpers;\n}\n\n/**\n * Replace the entire helpers map (used for hydration/reset in tests).\n * @param next - The new helpers map.\n */\nexport function setHelpers(next: Record<string, HelperFn>) {\n helpers = next;\n}\n\n/**\n * Add or replace a helper.\n * @param name - The name of the helper.\n * @param fn - The helper function.\n */\nexport function addHelper(name: string, fn: HelperFn) {\n helpers[name] = fn;\n}\n\n/**\n * Remove a helper by name.\n * @param name - The name of the helper.\n */\nexport function removeHelper(name: string) {\n delete helpers[name];\n}\n\n/**\n * Resolve all helpers to AdditionalContext entries, skipping null/undefined and errors.\n * @returns The resolved additional context.\n */\nexport async function resolveAdditionalContext(): Promise<\n { name: string; context: any }[]\n> {\n const entries = Object.entries(helpers);\n if (entries.length === 0) return [];\n\n const results = await Promise.all(\n entries.map(async ([name, fn]) => {\n try {\n const value = await fn();\n if (value == null) return null;\n return { name, context: value };\n } catch (error) {\n console.error(`Error running context helper ${name}:`, error);\n return null;\n }\n }),\n );\n\n return results.filter(Boolean) as { name: string; context: any }[];\n}\n"]}
@@ -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/dist/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,O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