@tambo-ai/react 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -15
- package/dist/context-helpers/__tests__/context-helpers.test.d.ts +2 -0
- package/dist/context-helpers/__tests__/context-helpers.test.d.ts.map +1 -0
- package/dist/context-helpers/__tests__/context-helpers.test.js +44 -0
- package/dist/context-helpers/__tests__/context-helpers.test.js.map +1 -0
- package/dist/context-helpers/index.d.ts +9 -0
- package/dist/context-helpers/index.d.ts.map +1 -0
- package/dist/context-helpers/index.js +38 -0
- package/dist/context-helpers/index.js.map +1 -0
- package/dist/context-helpers/types.d.ts +30 -0
- package/dist/context-helpers/types.d.ts.map +1 -0
- package/dist/context-helpers/types.js +3 -0
- package/dist/context-helpers/types.js.map +1 -0
- package/dist/context-helpers/user-page.d.ts +7 -0
- package/dist/context-helpers/user-page.d.ts.map +1 -0
- package/dist/context-helpers/user-page.js +31 -0
- package/dist/context-helpers/user-page.js.map +1 -0
- package/dist/context-helpers/user-time.d.ts +7 -0
- package/dist/context-helpers/user-time.d.ts.map +1 -0
- package/dist/context-helpers/user-time.js +20 -0
- package/dist/context-helpers/user-time.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/__tests__/tambo-context-helpers-provider.test.d.ts +2 -0
- package/dist/providers/__tests__/tambo-context-helpers-provider.test.d.ts.map +1 -0
- package/dist/providers/__tests__/tambo-context-helpers-provider.test.js +194 -0
- package/dist/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -0
- package/dist/providers/__tests__/tambo-thread-provider.test.js +51 -31
- package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +4 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/tambo-context-helpers-provider.d.ts +28 -0
- package/dist/providers/tambo-context-helpers-provider.d.ts.map +1 -0
- package/dist/providers/tambo-context-helpers-provider.js +98 -0
- package/dist/providers/tambo-context-helpers-provider.js.map +1 -0
- package/dist/providers/tambo-provider.d.ts +4 -2
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +10 -5
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-stubs.d.ts +4 -0
- package/dist/providers/tambo-stubs.d.ts.map +1 -1
- package/dist/providers/tambo-stubs.js +6 -3
- package/dist/providers/tambo-stubs.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +10 -1
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/dist/util/registry.d.ts +0 -8
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/registry.js +1 -15
- package/dist/util/registry.js.map +1 -1
- package/esm/context-helpers/__tests__/context-helpers.test.d.ts +2 -0
- package/esm/context-helpers/__tests__/context-helpers.test.d.ts.map +1 -0
- package/esm/context-helpers/__tests__/context-helpers.test.js +42 -0
- package/esm/context-helpers/__tests__/context-helpers.test.js.map +1 -0
- package/esm/context-helpers/index.d.ts +9 -0
- package/esm/context-helpers/index.d.ts.map +1 -0
- package/esm/context-helpers/index.js +21 -0
- package/esm/context-helpers/index.js.map +1 -0
- package/esm/context-helpers/types.d.ts +30 -0
- package/esm/context-helpers/types.d.ts.map +1 -0
- package/esm/context-helpers/types.js +2 -0
- package/esm/context-helpers/types.js.map +1 -0
- package/esm/context-helpers/user-page.d.ts +7 -0
- package/esm/context-helpers/user-page.d.ts.map +1 -0
- package/esm/context-helpers/user-page.js +28 -0
- package/esm/context-helpers/user-page.js.map +1 -0
- package/esm/context-helpers/user-time.d.ts +7 -0
- package/esm/context-helpers/user-time.d.ts.map +1 -0
- package/esm/context-helpers/user-time.js +17 -0
- package/esm/context-helpers/user-time.js.map +1 -0
- package/esm/index.d.ts +3 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -1
- package/esm/index.js.map +1 -1
- package/esm/providers/__tests__/tambo-context-helpers-provider.test.d.ts +2 -0
- package/esm/providers/__tests__/tambo-context-helpers-provider.test.d.ts.map +1 -0
- package/esm/providers/__tests__/tambo-context-helpers-provider.test.js +156 -0
- package/esm/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -0
- package/esm/providers/__tests__/tambo-thread-provider.test.js +51 -31
- package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/esm/providers/index.d.ts +1 -0
- package/esm/providers/index.d.ts.map +1 -1
- package/esm/providers/index.js +1 -0
- package/esm/providers/index.js.map +1 -1
- package/esm/providers/tambo-context-helpers-provider.d.ts +28 -0
- package/esm/providers/tambo-context-helpers-provider.d.ts.map +1 -0
- package/esm/providers/tambo-context-helpers-provider.js +60 -0
- package/esm/providers/tambo-context-helpers-provider.js.map +1 -0
- package/esm/providers/tambo-provider.d.ts +4 -2
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +10 -5
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-stubs.d.ts +4 -0
- package/esm/providers/tambo-stubs.d.ts.map +1 -1
- package/esm/providers/tambo-stubs.js +6 -3
- package/esm/providers/tambo-stubs.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +11 -2
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/esm/util/registry.d.ts +0 -8
- package/esm/util/registry.d.ts.map +1 -1
- package/esm/util/registry.js +0 -13
- package/esm/util/registry.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
# Tambo React SDK
|
|
1
|
+
# Tambo AI React SDK
|
|
2
2
|
|
|
3
3
|
Tambo allows AI models to dynamically render React components in response to user messages, enabling AI assistants to display interactive widgets, charts, forms, and other UI elements instead of just text. Tambo is a great way to add generative UI to your AI assistant, copilot, or agent.
|
|
4
4
|
|
|
5
5
|
This package provides react hooks to talk to the Tambo API and render custom components inline, but does not provide any UI components on its own. For pre-built UI components that use this package, see [tambo-ui](https://ui.tambo.co).
|
|
6
6
|
|
|
7
|
-
## Build with
|
|
7
|
+
## Build apps with Generative UI and MCP
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+

|
|
10
10
|
|
|
11
|
-
[
|
|
12
|
-
|
|
13
|
-
### Creating a new project
|
|
14
|
-
|
|
15
|
-
You can create a new project using our MCP template:
|
|
11
|
+
Get started using our [AI chat template](https://github.com/tambo-ai/tambo-template):
|
|
16
12
|
|
|
17
13
|
```bash
|
|
18
|
-
npx tambo create-app -
|
|
14
|
+
npx tambo create-app my-tambo-app
|
|
19
15
|
```
|
|
20
16
|
|
|
21
|
-
This will create a new
|
|
17
|
+
This will create a new NextJS project with Tambo pre-configured, and then step you through the process of setting up a Tambo project, including signing up for an API key, and adding it to `.env.local`.
|
|
22
18
|
|
|
23
19
|
### Adding components to an existing project
|
|
24
20
|
|
|
@@ -188,11 +184,10 @@ function ChatInterface() {
|
|
|
188
184
|
|
|
189
185
|
### Templates
|
|
190
186
|
|
|
191
|
-
| App
|
|
192
|
-
|
|
|
193
|
-
| [
|
|
194
|
-
| [
|
|
195
|
-
| [Conversational Form](https://github.com/tambo-ai/conversational-form) | Collect information with generative UX |
|
|
187
|
+
| App | Description |
|
|
188
|
+
| ------------------------------------------------------------------------ | ---------------------------------------------- |
|
|
189
|
+
| [AI Chat with Generative UI](https://github.com/tambo-ai/tambo-template) | Get started with Generative UX, tools, and MCP |
|
|
190
|
+
| [Conversational Form](https://github.com/tambo-ai/conversational-form) | Collect information with generative UX |
|
|
196
191
|
|
|
197
192
|
Check out our UI library [tambo-ui](https://ui.tambo.co) for components that leverage tambo.
|
|
198
193
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-helpers.test.d.ts","sourceRoot":"","sources":["../../../src/context-helpers/__tests__/context-helpers.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
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");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=context-helpers.test.js.map
|
|
@@ -0,0 +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,OAAO,CAAC,OAAO,CAA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D,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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AdditionalContextHelper } from "./types";
|
|
2
|
+
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
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
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");
|
|
20
|
+
__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
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for additional context that can be added to messages
|
|
3
|
+
*/
|
|
4
|
+
export interface AdditionalContext {
|
|
5
|
+
/** The name of the context type */
|
|
6
|
+
name: string;
|
|
7
|
+
/** The context data */
|
|
8
|
+
context: any;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Interface for a context helper that can generate additional context
|
|
12
|
+
*/
|
|
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
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for context helpers
|
|
23
|
+
*/
|
|
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
|
+
}
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AdditionalContext } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Context helper that provides information about the user's current page
|
|
4
|
+
* @returns Additional context with current page information
|
|
5
|
+
*/
|
|
6
|
+
export declare function getUserPageContext(): AdditionalContext;
|
|
7
|
+
//# sourceMappingURL=user-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-page.d.ts","sourceRoot":"","sources":["../../src/context-helpers/user-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,iBAAiB,CAuBtD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUserPageContext = getUserPageContext;
|
|
4
|
+
/**
|
|
5
|
+
* Context helper that provides information about the user's current page
|
|
6
|
+
* @returns Additional context with current page information
|
|
7
|
+
*/
|
|
8
|
+
function getUserPageContext() {
|
|
9
|
+
// Only run in browser environment
|
|
10
|
+
if (typeof window === "undefined") {
|
|
11
|
+
return {
|
|
12
|
+
name: "userPage",
|
|
13
|
+
context: {
|
|
14
|
+
error: "Not in browser environment",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
name: "userPage",
|
|
20
|
+
context: {
|
|
21
|
+
url: window.location.href,
|
|
22
|
+
pathname: window.location.pathname,
|
|
23
|
+
hostname: window.location.hostname,
|
|
24
|
+
search: window.location.search,
|
|
25
|
+
hash: window.location.hash,
|
|
26
|
+
title: document.title,
|
|
27
|
+
referrer: document.referrer,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=user-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-page.js","sourceRoot":"","sources":["../../src/context-helpers/user-page.ts"],"names":[],"mappings":";;AAMA,gDAuBC;AA3BD;;;GAGG;AACH,SAAgB,kBAAkB;IAChC,kCAAkC;IAClC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE;gBACP,KAAK,EAAE,4BAA4B;aACpC;SACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;YAClC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;YAClC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;YAC1B,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;SAC5B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { AdditionalContext } from \"./types\";\n\n/**\n * Context helper that provides information about the user's current page\n * @returns Additional context with current page information\n */\nexport function getUserPageContext(): AdditionalContext {\n // Only run in browser environment\n if (typeof window === \"undefined\") {\n return {\n name: \"userPage\",\n context: {\n error: \"Not in browser environment\",\n },\n };\n }\n\n return {\n name: \"userPage\",\n context: {\n url: window.location.href,\n pathname: window.location.pathname,\n hostname: window.location.hostname,\n search: window.location.search,\n hash: window.location.hash,\n title: document.title,\n referrer: document.referrer,\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AdditionalContext } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Context helper that provides the user's current time and timezone
|
|
4
|
+
* @returns Additional context with user's time information
|
|
5
|
+
*/
|
|
6
|
+
export declare function getUserTimeContext(): AdditionalContext;
|
|
7
|
+
//# sourceMappingURL=user-time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-time.d.ts","sourceRoot":"","sources":["../../src/context-helpers/user-time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,iBAAiB,CAYtD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUserTimeContext = getUserTimeContext;
|
|
4
|
+
/**
|
|
5
|
+
* Context helper that provides the user's current time and timezone
|
|
6
|
+
* @returns Additional context with user's time information
|
|
7
|
+
*/
|
|
8
|
+
function getUserTimeContext() {
|
|
9
|
+
const now = new Date();
|
|
10
|
+
return {
|
|
11
|
+
name: "userTime",
|
|
12
|
+
context: {
|
|
13
|
+
localTime: now.toLocaleString(),
|
|
14
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
15
|
+
timestamp: now.toISOString(),
|
|
16
|
+
offsetMinutes: now.getTimezoneOffset(),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=user-time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-time.js","sourceRoot":"","sources":["../../src/context-helpers/user-time.ts"],"names":[],"mappings":";;AAMA,gDAYC;AAhBD;;;GAGG;AACH,SAAgB,kBAAkB;IAChC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IAEvB,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP,SAAS,EAAE,GAAG,CAAC,cAAc,EAAE;YAC/B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC,QAAQ;YAC1D,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE;YAC5B,aAAa,EAAE,GAAG,CAAC,iBAAiB,EAAE;SACvC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { AdditionalContext } from \"./types\";\n\n/**\n * Context helper that provides the user's current time and timezone\n * @returns Additional context with user's time information\n */\nexport function getUserTimeContext(): AdditionalContext {\n const now = new Date();\n\n return {\n name: \"userTime\",\n context: {\n localTime: now.toLocaleString(),\n timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n timestamp: now.toISOString(),\n offsetMinutes: now.getTimezoneOffset(),\n },\n };\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { useTamboStreamingProps } from "./hooks/use-streaming-props";
|
|
|
5
5
|
export * from "./hooks/use-suggestions";
|
|
6
6
|
export { useTamboStreamStatus, type PropStatus, type StreamStatus, } from "./hooks/use-tambo-stream-status";
|
|
7
7
|
export { useTamboThreadInput } from "./hooks/use-thread-input";
|
|
8
|
-
export { TamboClientProvider, TamboComponentProvider, TamboPropStreamProvider, TamboProvider, TamboStubProvider, TamboThreadProvider, useTambo, useTamboClient, useTamboStream, useTamboThread, type TamboComponent, type TamboRegistryContext, type TamboStubProviderProps, } from "./providers";
|
|
8
|
+
export { TamboClientProvider, TamboComponentProvider, TamboContextHelpersProvider, TamboPropStreamProvider, TamboProvider, TamboStubProvider, TamboThreadProvider, useTambo, useTamboClient, useTamboContextHelpers, useTamboStream, useTamboThread, type TamboComponent, type TamboContextHelpersContextProps, type TamboContextHelpersProviderProps, type TamboRegistryContext, type TamboStubProviderProps, } from "./providers";
|
|
9
9
|
export type { APIError, RateLimitError, TamboAIError, } from "@tambo-ai/typescript-sdk";
|
|
10
10
|
export type { Suggestion, SuggestionGenerateParams, SuggestionGenerateResponse, SuggestionListResponse, } from "@tambo-ai/typescript-sdk/resources/beta/threads/suggestions";
|
|
11
11
|
export { useTamboThreadList } from "./hooks/use-tambo-threads";
|
|
@@ -15,4 +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
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBA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AY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,YAAY,EACV,0BAA0B,IAAI,qBAAqB,EACnD,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,IAAI,gBAAgB,EACzC,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,GAChC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAG/E,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.useTamboInteractable = exports.withInteractable = exports.GenerationStage = exports.useTamboThreadList = exports.useTamboThread = exports.useTamboStream = exports.useTamboClient = exports.useTambo = exports.TamboThreadProvider = exports.TamboStubProvider = exports.TamboProvider = exports.TamboPropStreamProvider = exports.TamboComponentProvider = exports.TamboClientProvider = exports.useTamboThreadInput = exports.useTamboStreamStatus = exports.useTamboStreamingProps = exports.useTamboMessageContext = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.useTamboComponentState = void 0;
|
|
18
|
+
exports.getUserTimeContext = exports.getUserPageContext = exports.DEFAULT_CONTEXT_HELPERS = exports.useTamboInteractable = exports.withInteractable = exports.GenerationStage = exports.useTamboThreadList = exports.useTamboThread = exports.useTamboStream = exports.useTamboContextHelpers = exports.useTamboClient = exports.useTambo = exports.TamboThreadProvider = exports.TamboStubProvider = exports.TamboProvider = exports.TamboPropStreamProvider = exports.TamboContextHelpersProvider = exports.TamboComponentProvider = exports.TamboClientProvider = exports.useTamboThreadInput = exports.useTamboStreamStatus = exports.useTamboStreamingProps = exports.useTamboMessageContext = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.useTamboComponentState = void 0;
|
|
19
19
|
var use_component_state_1 = require("./hooks/use-component-state");
|
|
20
20
|
Object.defineProperty(exports, "useTamboComponentState", { enumerable: true, get: function () { return use_component_state_1.useTamboComponentState; } });
|
|
21
21
|
var use_current_message_1 = require("./hooks/use-current-message");
|
|
@@ -33,12 +33,14 @@ Object.defineProperty(exports, "useTamboThreadInput", { enumerable: true, get: f
|
|
|
33
33
|
var providers_1 = require("./providers");
|
|
34
34
|
Object.defineProperty(exports, "TamboClientProvider", { enumerable: true, get: function () { return providers_1.TamboClientProvider; } });
|
|
35
35
|
Object.defineProperty(exports, "TamboComponentProvider", { enumerable: true, get: function () { return providers_1.TamboComponentProvider; } });
|
|
36
|
+
Object.defineProperty(exports, "TamboContextHelpersProvider", { enumerable: true, get: function () { return providers_1.TamboContextHelpersProvider; } });
|
|
36
37
|
Object.defineProperty(exports, "TamboPropStreamProvider", { enumerable: true, get: function () { return providers_1.TamboPropStreamProvider; } });
|
|
37
38
|
Object.defineProperty(exports, "TamboProvider", { enumerable: true, get: function () { return providers_1.TamboProvider; } });
|
|
38
39
|
Object.defineProperty(exports, "TamboStubProvider", { enumerable: true, get: function () { return providers_1.TamboStubProvider; } });
|
|
39
40
|
Object.defineProperty(exports, "TamboThreadProvider", { enumerable: true, get: function () { return providers_1.TamboThreadProvider; } });
|
|
40
41
|
Object.defineProperty(exports, "useTambo", { enumerable: true, get: function () { return providers_1.useTambo; } });
|
|
41
42
|
Object.defineProperty(exports, "useTamboClient", { enumerable: true, get: function () { return providers_1.useTamboClient; } });
|
|
43
|
+
Object.defineProperty(exports, "useTamboContextHelpers", { enumerable: true, get: function () { return providers_1.useTamboContextHelpers; } });
|
|
42
44
|
Object.defineProperty(exports, "useTamboStream", { enumerable: true, get: function () { return providers_1.useTamboStream; } });
|
|
43
45
|
Object.defineProperty(exports, "useTamboThread", { enumerable: true, get: function () { return providers_1.useTamboThread; } });
|
|
44
46
|
var use_tambo_threads_1 = require("./hooks/use-tambo-threads");
|
|
@@ -49,4 +51,9 @@ var with_tambo_interactable_1 = require("./providers/hoc/with-tambo-interactable
|
|
|
49
51
|
Object.defineProperty(exports, "withInteractable", { enumerable: true, get: function () { return with_tambo_interactable_1.withTamboInteractable; } });
|
|
50
52
|
var tambo_interactable_provider_1 = require("./providers/tambo-interactable-provider");
|
|
51
53
|
Object.defineProperty(exports, "useTamboInteractable", { enumerable: true, get: function () { return tambo_interactable_provider_1.useTamboInteractable; } });
|
|
54
|
+
// Context helpers exports
|
|
55
|
+
var context_helpers_1 = require("./context-helpers");
|
|
56
|
+
Object.defineProperty(exports, "DEFAULT_CONTEXT_HELPERS", { enumerable: true, get: function () { return context_helpers_1.DEFAULT_CONTEXT_HELPERS; } });
|
|
57
|
+
Object.defineProperty(exports, "getUserPageContext", { enumerable: true, get: function () { return context_helpers_1.getUserPageContext; } });
|
|
58
|
+
Object.defineProperty(exports, "getUserTimeContext", { enumerable: true, get: function () { return context_helpers_1.getUserTimeContext; } });
|
|
52
59
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],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B;AAI3C,uFAA+E;AAAtE,mIAAA,oBAAoB,OAAA;AAE7B,0BAA0B;AAC1B,qDAI2B;AAHzB,0HAAA,uBAAuB,OAAA;AACvB,qHAAA,kBAAkB,OAAA;AAClB,qHAAA,kBAAkB,OAAA","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tambo-context-helpers-provider.test.d.ts","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-context-helpers-provider.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const react_1 = require("@testing-library/react");
|
|
40
|
+
const react_2 = __importDefault(require("react"));
|
|
41
|
+
const contextHelpers = __importStar(require("../../context-helpers"));
|
|
42
|
+
const context_helpers_1 = require("../../context-helpers");
|
|
43
|
+
const tambo_context_helpers_provider_1 = require("../tambo-context-helpers-provider");
|
|
44
|
+
describe("TamboContextHelpersProvider", () => {
|
|
45
|
+
// Create a wrapper component that provides the context for testing hooks
|
|
46
|
+
const wrapper = ({ children }) => (react_2.default.createElement(tambo_context_helpers_provider_1.TamboContextHelpersProvider, null, children));
|
|
47
|
+
describe("useTamboContextHelpers", () => {
|
|
48
|
+
/**
|
|
49
|
+
* Test: Hook throws error when used outside of provider
|
|
50
|
+
* This ensures developers get a clear error message if they forget to wrap
|
|
51
|
+
* their components with the TamboContextHelpersProvider
|
|
52
|
+
*/
|
|
53
|
+
it("should throw error when used outside provider", () => {
|
|
54
|
+
// Mock console.error to prevent error output in test logs
|
|
55
|
+
const consoleSpy = jest
|
|
56
|
+
.spyOn(console, "error")
|
|
57
|
+
.mockImplementation(() => { });
|
|
58
|
+
// Verify that using the hook without a provider throws the expected error
|
|
59
|
+
expect(() => {
|
|
60
|
+
(0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)());
|
|
61
|
+
}).toThrow("useTamboContextHelpers must be used within a TamboContextHelpersProvider");
|
|
62
|
+
// Restore console.error to its original implementation
|
|
63
|
+
consoleSpy.mockRestore();
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Test: Hook provides the expected API functions
|
|
67
|
+
* Verifies that all required functions are available when the hook is used
|
|
68
|
+
* within the provider context
|
|
69
|
+
*/
|
|
70
|
+
it("should provide context helpers functions", () => {
|
|
71
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
|
|
72
|
+
wrapper,
|
|
73
|
+
});
|
|
74
|
+
// Verify all expected functions are present in the hook's return value
|
|
75
|
+
expect(result.current).toHaveProperty("getAdditionalContext");
|
|
76
|
+
expect(result.current).toHaveProperty("getContextHelpers");
|
|
77
|
+
expect(result.current).toHaveProperty("setContextHelperEnabled");
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Test: Default configuration is applied correctly
|
|
81
|
+
* Ensures that the default context helpers are loaded with their
|
|
82
|
+
* expected enabled/disabled states
|
|
83
|
+
*/
|
|
84
|
+
it("should return default context helpers configuration", () => {
|
|
85
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
|
|
86
|
+
wrapper,
|
|
87
|
+
});
|
|
88
|
+
const helpers = result.current.getContextHelpers();
|
|
89
|
+
// Verify we have the expected number of default helpers
|
|
90
|
+
expect(helpers).toHaveLength(context_helpers_1.DEFAULT_CONTEXT_HELPERS.length);
|
|
91
|
+
// Check specific helpers have their expected default states
|
|
92
|
+
const userTimeHelper = helpers.find((h) => h.name === "userTime");
|
|
93
|
+
const userPageHelper = helpers.find((h) => h.name === "userPage");
|
|
94
|
+
// userTime should be disabled by default
|
|
95
|
+
expect(userTimeHelper?.enabled).toBe(false);
|
|
96
|
+
// userPage should be disabled by default
|
|
97
|
+
expect(userPageHelper?.enabled).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* Test: Context helper enabled state can be toggled
|
|
101
|
+
* Verifies that the setContextHelperEnabled function correctly updates
|
|
102
|
+
* the enabled state of individual helpers
|
|
103
|
+
*/
|
|
104
|
+
it("should allow toggling context helper enabled state", () => {
|
|
105
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
|
|
106
|
+
wrapper,
|
|
107
|
+
});
|
|
108
|
+
// Enable the userPage helper using the provided function
|
|
109
|
+
(0, react_1.act)(() => {
|
|
110
|
+
result.current.setContextHelperEnabled("userPage", true);
|
|
111
|
+
});
|
|
112
|
+
// Verify the helper's state was updated
|
|
113
|
+
const helpers = result.current.getContextHelpers();
|
|
114
|
+
const userPageHelper = helpers.find((h) => h.name === "userPage");
|
|
115
|
+
expect(userPageHelper?.enabled).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Test: Only enabled helpers contribute to additional context
|
|
119
|
+
* Verifies that getAdditionalContext only runs and returns data from
|
|
120
|
+
* helpers that are currently enabled
|
|
121
|
+
*/
|
|
122
|
+
it("should get additional context from enabled helpers", async () => {
|
|
123
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
|
|
124
|
+
wrapper,
|
|
125
|
+
});
|
|
126
|
+
const contexts = await result.current.getAdditionalContext();
|
|
127
|
+
// By default, no context helpers are enabled, so we should get no contexts
|
|
128
|
+
expect(contexts).toHaveLength(0);
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* Test: Provider respects configuration prop
|
|
132
|
+
* Verifies that initial configuration can be customized through the
|
|
133
|
+
* contextHelpers prop on the provider
|
|
134
|
+
*/
|
|
135
|
+
it("should respect contextHelpers configuration prop", () => {
|
|
136
|
+
// Create a custom wrapper with specific configuration
|
|
137
|
+
const customWrapper = ({ children }) => (react_2.default.createElement(tambo_context_helpers_provider_1.TamboContextHelpersProvider, { contextHelpers: {
|
|
138
|
+
userTime: false, // Disable userTime
|
|
139
|
+
userPage: true, // Enable userPage
|
|
140
|
+
} }, children));
|
|
141
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
|
|
142
|
+
wrapper: customWrapper,
|
|
143
|
+
});
|
|
144
|
+
// Verify the custom configuration is applied
|
|
145
|
+
const helpers = result.current.getContextHelpers();
|
|
146
|
+
const userTimeHelper = helpers.find((h) => h.name === "userTime");
|
|
147
|
+
const userPageHelper = helpers.find((h) => h.name === "userPage");
|
|
148
|
+
expect(userTimeHelper?.enabled).toBe(false);
|
|
149
|
+
expect(userPageHelper?.enabled).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* Test: Errors in context helpers are handled gracefully
|
|
153
|
+
* Verifies that if a context helper throws an error, it doesn't crash
|
|
154
|
+
* the entire system and other helpers continue to work
|
|
155
|
+
*/
|
|
156
|
+
it("should handle errors in context helper functions gracefully", async () => {
|
|
157
|
+
// Mock console.error to capture error logs
|
|
158
|
+
const consoleErrorSpy = jest
|
|
159
|
+
.spyOn(console, "error")
|
|
160
|
+
.mockImplementation(() => { });
|
|
161
|
+
// Create a helper that will throw an error when run
|
|
162
|
+
const errorHelper = {
|
|
163
|
+
name: "errorHelper",
|
|
164
|
+
enabled: true,
|
|
165
|
+
run: () => {
|
|
166
|
+
throw new Error("Test error");
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
// Temporarily add the error helper to the default helpers
|
|
170
|
+
// Store original helpers to restore later
|
|
171
|
+
const originalHelpers = context_helpers_1.DEFAULT_CONTEXT_HELPERS;
|
|
172
|
+
Object.defineProperty(contextHelpers, "DEFAULT_CONTEXT_HELPERS", {
|
|
173
|
+
value: [...originalHelpers, errorHelper],
|
|
174
|
+
writable: true,
|
|
175
|
+
});
|
|
176
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(), {
|
|
177
|
+
wrapper,
|
|
178
|
+
});
|
|
179
|
+
// Call getAdditionalContext, which should handle the error gracefully
|
|
180
|
+
const contexts = await result.current.getAdditionalContext();
|
|
181
|
+
// Should have no contexts because the error helper should be skipped
|
|
182
|
+
expect(contexts.length).toBe(0);
|
|
183
|
+
// Verify that the error was logged appropriately
|
|
184
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("Error running context helper errorHelper"), expect.any(Error));
|
|
185
|
+
// Restore the original helpers and console.error
|
|
186
|
+
Object.defineProperty(contextHelpers, "DEFAULT_CONTEXT_HELPERS", {
|
|
187
|
+
value: originalHelpers,
|
|
188
|
+
writable: true,
|
|
189
|
+
});
|
|
190
|
+
consoleErrorSpy.mockRestore();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
//# sourceMappingURL=tambo-context-helpers-provider.test.js.map
|