@tambo-ai/react 0.42.1 → 0.43.1

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 (91) 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/esm/context-helpers/__tests__/context-helpers-provider.test.d.ts +15 -0
  39. package/esm/context-helpers/__tests__/context-helpers-provider.test.d.ts.map +1 -0
  40. package/esm/context-helpers/__tests__/context-helpers-provider.test.js +142 -0
  41. package/esm/context-helpers/__tests__/context-helpers-provider.test.js.map +1 -0
  42. package/esm/context-helpers/__tests__/context-helpers.test.js +31 -36
  43. package/esm/context-helpers/__tests__/context-helpers.test.js.map +1 -1
  44. package/esm/context-helpers/current-page-context-helper.d.ts +7 -0
  45. package/esm/context-helpers/current-page-context-helper.d.ts.map +1 -0
  46. package/esm/context-helpers/current-page-context-helper.js +20 -0
  47. package/esm/context-helpers/current-page-context-helper.js.map +1 -0
  48. package/esm/context-helpers/current-time-context-helper.d.ts +7 -0
  49. package/esm/context-helpers/current-time-context-helper.d.ts.map +1 -0
  50. package/esm/context-helpers/current-time-context-helper.js +17 -0
  51. package/esm/context-helpers/current-time-context-helper.js.map +1 -0
  52. package/esm/context-helpers/index.d.ts +2 -7
  53. package/esm/context-helpers/index.d.ts.map +1 -1
  54. package/esm/context-helpers/index.js +2 -19
  55. package/esm/context-helpers/index.js.map +1 -1
  56. package/esm/context-helpers/registry.d.ts +35 -0
  57. package/esm/context-helpers/registry.d.ts.map +1 -0
  58. package/esm/context-helpers/registry.js +57 -0
  59. package/esm/context-helpers/registry.js.map +1 -0
  60. package/esm/context-helpers/types.d.ts +6 -16
  61. package/esm/context-helpers/types.d.ts.map +1 -1
  62. package/esm/context-helpers/types.js.map +1 -1
  63. package/esm/index.d.ts +2 -2
  64. package/esm/index.d.ts.map +1 -1
  65. package/esm/index.js +1 -1
  66. package/esm/index.js.map +1 -1
  67. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js +279 -105
  68. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
  69. package/esm/providers/__tests__/tambo-thread-provider.test.js +29 -7
  70. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  71. package/esm/providers/tambo-context-helpers-provider.d.ts +24 -15
  72. package/esm/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  73. package/esm/providers/tambo-context-helpers-provider.js +57 -40
  74. package/esm/providers/tambo-context-helpers-provider.js.map +1 -1
  75. package/package.json +3 -3
  76. package/dist/context-helpers/user-page.d.ts +0 -7
  77. package/dist/context-helpers/user-page.d.ts.map +0 -1
  78. package/dist/context-helpers/user-page.js +0 -31
  79. package/dist/context-helpers/user-page.js.map +0 -1
  80. package/dist/context-helpers/user-time.d.ts +0 -7
  81. package/dist/context-helpers/user-time.d.ts.map +0 -1
  82. package/dist/context-helpers/user-time.js +0 -20
  83. package/dist/context-helpers/user-time.js.map +0 -1
  84. package/esm/context-helpers/user-page.d.ts +0 -7
  85. package/esm/context-helpers/user-page.d.ts.map +0 -1
  86. package/esm/context-helpers/user-page.js +0 -28
  87. package/esm/context-helpers/user-page.js.map +0 -1
  88. package/esm/context-helpers/user-time.d.ts +0 -7
  89. package/esm/context-helpers/user-time.d.ts.map +0 -1
  90. package/esm/context-helpers/user-time.js +0 -17
  91. package/esm/context-helpers/user-time.js.map +0 -1
@@ -0,0 +1,142 @@
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
+ import { renderHook } from "@testing-library/react";
15
+ import React from "react";
16
+ import { setHelpers } from "../../context-helpers/registry";
17
+ import { TamboContextHelpersProvider, useTamboContextHelpers, } from "../../providers/tambo-context-helpers-provider";
18
+ import { currentPageContextHelper, currentTimeContextHelper, } from "../index";
19
+ /**
20
+ * Test wrapper to provide the TamboContextHelpersProvider for hooks.
21
+ * @param helpers - A dictionary of context helper functions.
22
+ * @returns A wrapper component that provides the TamboContextHelpersProvider.
23
+ */
24
+ function wrapper(helpers) {
25
+ // eslint-disable-next-line react/display-name
26
+ return ({ children }) => React.createElement(TamboContextHelpersProvider, {
27
+ contextHelpers: helpers,
28
+ }, children);
29
+ }
30
+ describe("Context Helpers API", () => {
31
+ // Ensure the global registry doesn't leak state between tests
32
+ beforeEach(() => {
33
+ setHelpers({});
34
+ jest.clearAllMocks();
35
+ });
36
+ test("returns empty array when no helpers provided", async () => {
37
+ const { result } = renderHook(() => useTamboContextHelpers(), {
38
+ wrapper: wrapper(),
39
+ });
40
+ const contexts = await result.current.getAdditionalContext();
41
+ expect(Array.isArray(contexts)).toBe(true);
42
+ expect(contexts).toHaveLength(0);
43
+ });
44
+ test("collects sync and async helper results", async () => {
45
+ const syncHelper = () => ({ a: 1 });
46
+ const asyncHelper = async () => ({ b: 2 });
47
+ const { result } = renderHook(() => useTamboContextHelpers(), {
48
+ wrapper: wrapper({
49
+ sync: syncHelper,
50
+ async: asyncHelper,
51
+ }),
52
+ });
53
+ const contexts = await result.current.getAdditionalContext();
54
+ // Validate shape and presence
55
+ const byName = new Map(contexts.map((c) => [c.name, c.context]));
56
+ expect(byName.get("sync")).toEqual({ a: 1 });
57
+ expect(byName.get("async")).toEqual({ b: 2 });
58
+ });
59
+ test("skips null and undefined results", async () => {
60
+ const nullHelper = () => null;
61
+ const undefinedHelper = () => undefined;
62
+ const validHelper = () => ({ ok: true });
63
+ const { result } = renderHook(() => useTamboContextHelpers(), {
64
+ wrapper: wrapper({
65
+ nullHelper,
66
+ undefinedHelper,
67
+ validHelper,
68
+ }),
69
+ });
70
+ const contexts = await result.current.getAdditionalContext();
71
+ const names = contexts.map((c) => c.name);
72
+ expect(names).toContain("validHelper");
73
+ expect(names).not.toContain("nullHelper");
74
+ expect(names).not.toContain("undefinedHelper");
75
+ });
76
+ test("errors in helpers are caught and skipped", async () => {
77
+ const consoleSpy = jest.spyOn(console, "error").mockImplementation(() => {
78
+ // silence expected error
79
+ });
80
+ const badHelper = () => {
81
+ throw new Error("boom");
82
+ };
83
+ const goodHelper = () => ({ ok: 1 });
84
+ const { result } = renderHook(() => useTamboContextHelpers(), {
85
+ wrapper: wrapper({ badHelper, goodHelper }),
86
+ });
87
+ const contexts = await result.current.getAdditionalContext();
88
+ expect(contexts).toHaveLength(1);
89
+ expect(contexts[0]).toEqual({
90
+ name: "goodHelper",
91
+ context: { ok: 1 },
92
+ });
93
+ consoleSpy.mockRestore();
94
+ });
95
+ test("dynamic add/remove helpers works", async () => {
96
+ const { result } = renderHook(() => useTamboContextHelpers(), {
97
+ wrapper: wrapper(),
98
+ });
99
+ // Initially empty
100
+ expect(await result.current.getAdditionalContext()).toHaveLength(0);
101
+ // Add
102
+ result.current.addContextHelper("dyn", () => ({ x: 10 }));
103
+ let contexts = await result.current.getAdditionalContext();
104
+ expect(contexts).toHaveLength(1);
105
+ expect(contexts[0]).toEqual({
106
+ name: "dyn",
107
+ context: { x: 10 },
108
+ });
109
+ // Update
110
+ result.current.addContextHelper("dyn", () => ({ x: 20 }));
111
+ contexts = await result.current.getAdditionalContext();
112
+ expect(contexts).toHaveLength(1);
113
+ expect(contexts[0]).toEqual({
114
+ name: "dyn",
115
+ context: { x: 20 },
116
+ });
117
+ // Remove
118
+ result.current.removeContextHelper("dyn");
119
+ contexts = await result.current.getAdditionalContext();
120
+ expect(contexts).toHaveLength(0);
121
+ });
122
+ test("prebuilt helpers can be passed directly", async () => {
123
+ const { result } = renderHook(() => useTamboContextHelpers(), {
124
+ wrapper: wrapper({
125
+ userTime: currentTimeContextHelper,
126
+ userPage: currentPageContextHelper,
127
+ }),
128
+ });
129
+ const contexts = await result.current.getAdditionalContext();
130
+ // Should include both entries unless environment prevents userPage (SSR)
131
+ const names = contexts.map((c) => c.name);
132
+ expect(names).toContain("userTime");
133
+ // userPage may be null on non-browser envs; allow either outcome:
134
+ // if present, ensure expected keys exist
135
+ if (names.includes("userPage")) {
136
+ const userPage = contexts.find((c) => c.name === "userPage").context;
137
+ expect(typeof userPage.url === "string" || userPage.url === undefined).toBe(true);
138
+ expect(typeof userPage.title === "string" || userPage.title === undefined).toBe(true);
139
+ }
140
+ });
141
+ });
142
+ //# 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,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAGL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,UAAU,CAAC;AAElB;;;;GAIG;AACH,SAAS,OAAO,CAAC,OAAyC;IACxD,8CAA8C;IAC9C,OAAO,CAAC,EAAE,QAAQ,EAAqB,EAAE,EAAE,CACzC,KAAK,CAAC,aAAa,CACjB,2BAA2B,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,UAAU,CAAC,EAAE,CAAC,CAAC;QACf,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,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QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAE7D,yEAAyE;QACzE,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACpC,kEAAkE;QAClE,yCAAyC;QACzC,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,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,41 +1,36 @@
1
- import { getUserPageContext, getUserTimeContext } from "../index";
2
- describe("Context Helpers", () => {
3
- describe("getUserTimeContext", () => {
4
- it("should return user time context with all required fields", () => {
5
- const context = getUserTimeContext();
6
- expect(context.name).toBe("userTime");
7
- expect(context.context).toHaveProperty("localTime");
8
- expect(context.context).toHaveProperty("timezone");
9
- expect(context.context).toHaveProperty("timestamp");
10
- expect(context.context).toHaveProperty("offsetMinutes");
11
- // Verify data types
12
- expect(typeof context.context.localTime).toBe("string");
13
- expect(typeof context.context.timezone).toBe("string");
14
- expect(typeof context.context.timestamp).toBe("string");
15
- expect(typeof context.context.offsetMinutes).toBe("number");
16
- // Verify timestamp is valid ISO string
17
- expect(() => new Date(context.context.timestamp)).not.toThrow();
1
+ import { currentPageContextHelper, currentTimeContextHelper } from "../index";
2
+ /**
3
+ * Tests for prebuilt context helper functions.
4
+ *
5
+ * These helpers now return raw values (or null) instead of { name, context }.
6
+ * The provider is responsible for wrapping values as { name, context }.
7
+ */
8
+ describe("Context Helpers (prebuilt functions)", () => {
9
+ describe("currentTimeContextHelper", () => {
10
+ it("should return user time context with required fields", () => {
11
+ const context = currentTimeContextHelper();
12
+ // Should not be null (error case)
13
+ expect(context).not.toBeNull();
14
+ // Shape: { timestamp: string }
15
+ expect(context).toHaveProperty("timestamp");
16
+ expect(typeof context.timestamp).toBe("string");
17
+ // Verify timestamp string parses
18
+ expect(() => new Date(context.timestamp)).not.toThrow();
18
19
  });
19
20
  });
20
- describe("getUserPageContext", () => {
21
- it("should return page context with default values in test environment", () => {
22
- const context = getUserPageContext();
23
- expect(context.name).toBe("userPage");
24
- expect(context.context).toHaveProperty("url");
25
- expect(context.context).toHaveProperty("pathname");
26
- expect(context.context).toHaveProperty("hostname");
27
- expect(context.context).toHaveProperty("search");
28
- expect(context.context).toHaveProperty("hash");
29
- expect(context.context).toHaveProperty("title");
30
- expect(context.context).toHaveProperty("referrer");
31
- // Verify data types
32
- expect(typeof context.context.url).toBe("string");
33
- expect(typeof context.context.pathname).toBe("string");
34
- expect(typeof context.context.hostname).toBe("string");
35
- expect(typeof context.context.search).toBe("string");
36
- expect(typeof context.context.hash).toBe("string");
37
- expect(typeof context.context.title).toBe("string");
38
- expect(typeof context.context.referrer).toBe("string");
21
+ describe("currentPageContextHelper", () => {
22
+ it("should return page context in browser, or null otherwise", () => {
23
+ const context = currentPageContextHelper();
24
+ if (context === null) {
25
+ // Non-browser environments should return null to skip
26
+ expect(context).toBeNull();
27
+ return;
28
+ }
29
+ // Shape: { url: string, title: string }
30
+ expect(context).toHaveProperty("url");
31
+ expect(context).toHaveProperty("title");
32
+ expect(typeof context.url).toBe("string");
33
+ expect(typeof context.title).toBe("string");
39
34
  });
40
35
  });
41
36
  });
@@ -1 +1 @@
1
- {"version":3,"file":"context-helpers.test.js","sourceRoot":"","sources":["../../../src/context-helpers/__tests__/context-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;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,kBAAkB,EAAE,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,CAA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,CAAC,QAAQ,CAAC,CAAC;YACjD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAC/C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAChD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;YAEnD,oBAAoB;YACpB,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,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,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;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,wBAAwB,EAAE,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,wBAAwB,EAAE,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,20 @@
1
+ /**
2
+ * Prebuilt context helper that provides information about the user's current page.
3
+ * @returns a value to include it, or null/undefined to skip.
4
+ */
5
+ export const currentPageContextHelper = () => {
6
+ try {
7
+ if (typeof window === "undefined") {
8
+ return null;
9
+ }
10
+ return {
11
+ url: window.location.href,
12
+ title: document.title,
13
+ };
14
+ }
15
+ catch (e) {
16
+ console.error("prebuiltUserPage failed:", e);
17
+ return null;
18
+ }
19
+ };
20
+ //# 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;AACH,MAAM,CAAC,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","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,17 @@
1
+ /**
2
+ * Prebuilt context helper that provides information about the user's current time.
3
+ * @returns a value to include it, or null/undefined to skip.
4
+ */
5
+ export const currentTimeContextHelper = () => {
6
+ try {
7
+ const now = new Date();
8
+ return {
9
+ timestamp: now.toString(),
10
+ };
11
+ }
12
+ catch (e) {
13
+ console.error("prebuiltUserTime failed:", e);
14
+ return null;
15
+ }
16
+ };
17
+ //# 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;AACH,MAAM,CAAC,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","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"}
@@ -1,21 +1,4 @@
1
- import { getUserPageContext } from "./user-page";
2
- import { getUserTimeContext } from "./user-time";
1
+ export * from "./current-page-context-helper";
2
+ export * from "./current-time-context-helper";
3
3
  export * from "./types";
4
- export * from "./user-page";
5
- export * from "./user-time";
6
- /**
7
- * Pre-built context helpers that can be enabled/disabled
8
- */
9
- export const DEFAULT_CONTEXT_HELPERS = [
10
- {
11
- name: "userTime",
12
- enabled: false, // Default to disabled
13
- run: getUserTimeContext,
14
- },
15
- {
16
- name: "userPage",
17
- enabled: false, // Default to disabled
18
- run: getUserPageContext,
19
- },
20
- ];
21
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA8B;IAChE;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,KAAK,EAAE,sBAAsB;QACtC,GAAG,EAAE,kBAAkB;KACxB;IACD;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,KAAK,EAAE,sBAAsB;QACtC,GAAG,EAAE,kBAAkB;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,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC","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,57 @@
1
+ /**
2
+ * Global context helpers registry.
3
+ * Consumers can add/remove helpers and resolve additional context anywhere.
4
+ */
5
+ let helpers = {};
6
+ /**
7
+ * Get the current helpers map (by reference).
8
+ * @returns The current helpers map.
9
+ */
10
+ export function getHelpers() {
11
+ return helpers;
12
+ }
13
+ /**
14
+ * Replace the entire helpers map (used for hydration/reset in tests).
15
+ * @param next - The new helpers map.
16
+ */
17
+ export function setHelpers(next) {
18
+ helpers = next;
19
+ }
20
+ /**
21
+ * Add or replace a helper.
22
+ * @param name - The name of the helper.
23
+ * @param fn - The helper function.
24
+ */
25
+ export function addHelper(name, fn) {
26
+ helpers[name] = fn;
27
+ }
28
+ /**
29
+ * Remove a helper by name.
30
+ * @param name - The name of the helper.
31
+ */
32
+ export function removeHelper(name) {
33
+ delete helpers[name];
34
+ }
35
+ /**
36
+ * Resolve all helpers to AdditionalContext entries, skipping null/undefined and errors.
37
+ * @returns The resolved additional context.
38
+ */
39
+ export async function resolveAdditionalContext() {
40
+ const entries = Object.entries(helpers);
41
+ if (entries.length === 0)
42
+ return [];
43
+ const results = await Promise.all(entries.map(async ([name, fn]) => {
44
+ try {
45
+ const value = await fn();
46
+ if (value == null)
47
+ return null;
48
+ return { name, context: value };
49
+ }
50
+ catch (error) {
51
+ console.error(`Error running context helper ${name}:`, error);
52
+ return null;
53
+ }
54
+ }));
55
+ return results.filter(Boolean);
56
+ }
57
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,IAAI,OAAO,GAA6B,EAAE,CAAC;AAE3C;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAA8B;IACvD,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,EAAY;IAClD,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,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/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,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C,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"]}