@tambo-ai/typescript-sdk 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/CHANGELOG.md +389 -0
  2. package/LICENSE +201 -0
  3. package/README.md +434 -0
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +14 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +89 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +78 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +241 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +914 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +882 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +47 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +113 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +97 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +124 -0
  87. package/index.d.ts +124 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +140 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +94 -0
  92. package/index.mjs.map +1 -0
  93. package/lib/advance-stream.d.ts +5 -0
  94. package/lib/advance-stream.d.ts.map +1 -0
  95. package/lib/advance-stream.js +35 -0
  96. package/lib/advance-stream.js.map +1 -0
  97. package/lib/advance-stream.mjs +31 -0
  98. package/lib/advance-stream.mjs.map +1 -0
  99. package/lib/streaming-components.d.ts +7 -0
  100. package/lib/streaming-components.d.ts.map +1 -0
  101. package/lib/streaming-components.js +48 -0
  102. package/lib/streaming-components.js.map +1 -0
  103. package/lib/streaming-components.mjs +43 -0
  104. package/lib/streaming-components.mjs.map +1 -0
  105. package/package.json +122 -0
  106. package/pagination.d.ts +20 -0
  107. package/pagination.d.ts.map +1 -0
  108. package/pagination.js +46 -0
  109. package/pagination.js.map +1 -0
  110. package/pagination.mjs +42 -0
  111. package/pagination.mjs.map +1 -0
  112. package/resource.d.ts +6 -0
  113. package/resource.d.ts.map +1 -0
  114. package/resource.js +11 -0
  115. package/resource.js.map +1 -0
  116. package/resource.mjs +7 -0
  117. package/resource.mjs.map +1 -0
  118. package/resources/beta/beta.d.ts +22 -0
  119. package/resources/beta/beta.d.ts.map +1 -0
  120. package/resources/beta/beta.js +52 -0
  121. package/resources/beta/beta.js.map +1 -0
  122. package/resources/beta/beta.mjs +25 -0
  123. package/resources/beta/beta.mjs.map +1 -0
  124. package/resources/beta/components.d.ts +44 -0
  125. package/resources/beta/components.d.ts.map +1 -0
  126. package/resources/beta/components.js +29 -0
  127. package/resources/beta/components.js.map +1 -0
  128. package/resources/beta/components.mjs +25 -0
  129. package/resources/beta/components.mjs.map +1 -0
  130. package/resources/beta/index.d.ts +6 -0
  131. package/resources/beta/index.d.ts.map +1 -0
  132. package/resources/beta/index.js +16 -0
  133. package/resources/beta/index.js.map +1 -0
  134. package/resources/beta/index.mjs +7 -0
  135. package/resources/beta/index.mjs.map +1 -0
  136. package/resources/beta/projects/api-key.d.ts +24 -0
  137. package/resources/beta/projects/api-key.d.ts.map +1 -0
  138. package/resources/beta/projects/api-key.js +18 -0
  139. package/resources/beta/projects/api-key.js.map +1 -0
  140. package/resources/beta/projects/api-key.mjs +14 -0
  141. package/resources/beta/projects/api-key.mjs.map +1 -0
  142. package/resources/beta/projects/index.d.ts +5 -0
  143. package/resources/beta/projects/index.d.ts.map +1 -0
  144. package/resources/beta/projects/index.js +13 -0
  145. package/resources/beta/projects/index.js.map +1 -0
  146. package/resources/beta/projects/index.mjs +6 -0
  147. package/resources/beta/projects/index.mjs.map +1 -0
  148. package/resources/beta/projects/projects.d.ts +52 -0
  149. package/resources/beta/projects/projects.d.ts.map +1 -0
  150. package/resources/beta/projects/projects.js +62 -0
  151. package/resources/beta/projects/projects.js.map +1 -0
  152. package/resources/beta/projects/projects.mjs +35 -0
  153. package/resources/beta/projects/projects.mjs.map +1 -0
  154. package/resources/beta/projects/provider-key.d.ts +34 -0
  155. package/resources/beta/projects/provider-key.d.ts.map +1 -0
  156. package/resources/beta/projects/provider-key.js +18 -0
  157. package/resources/beta/projects/provider-key.js.map +1 -0
  158. package/resources/beta/projects/provider-key.mjs +14 -0
  159. package/resources/beta/projects/provider-key.mjs.map +1 -0
  160. package/resources/beta/projects/user.d.ts +17 -0
  161. package/resources/beta/projects/user.d.ts.map +1 -0
  162. package/resources/beta/projects/user.js +12 -0
  163. package/resources/beta/projects/user.js.map +1 -0
  164. package/resources/beta/projects/user.mjs +8 -0
  165. package/resources/beta/projects/user.mjs.map +1 -0
  166. package/resources/beta/registry.d.ts +10 -0
  167. package/resources/beta/registry.d.ts.map +1 -0
  168. package/resources/beta/registry.js +12 -0
  169. package/resources/beta/registry.js.map +1 -0
  170. package/resources/beta/registry.mjs +8 -0
  171. package/resources/beta/registry.mjs.map +1 -0
  172. package/resources/beta/threads/index.d.ts +4 -0
  173. package/resources/beta/threads/index.d.ts.map +1 -0
  174. package/resources/beta/threads/index.js +12 -0
  175. package/resources/beta/threads/index.js.map +1 -0
  176. package/resources/beta/threads/index.mjs +5 -0
  177. package/resources/beta/threads/index.mjs.map +1 -0
  178. package/resources/beta/threads/messages.d.ts +42 -0
  179. package/resources/beta/threads/messages.d.ts.map +1 -0
  180. package/resources/beta/threads/messages.js +28 -0
  181. package/resources/beta/threads/messages.js.map +1 -0
  182. package/resources/beta/threads/messages.mjs +24 -0
  183. package/resources/beta/threads/messages.mjs.map +1 -0
  184. package/resources/beta/threads/suggestions.d.ts +55 -0
  185. package/resources/beta/threads/suggestions.d.ts.map +1 -0
  186. package/resources/beta/threads/suggestions.js +21 -0
  187. package/resources/beta/threads/suggestions.js.map +1 -0
  188. package/resources/beta/threads/suggestions.mjs +17 -0
  189. package/resources/beta/threads/suggestions.mjs.map +1 -0
  190. package/resources/beta/threads/threads.d.ts +161 -0
  191. package/resources/beta/threads/threads.d.ts.map +1 -0
  192. package/resources/beta/threads/threads.js +79 -0
  193. package/resources/beta/threads/threads.js.map +1 -0
  194. package/resources/beta/threads/threads.mjs +51 -0
  195. package/resources/beta/threads/threads.mjs.map +1 -0
  196. package/resources/components.d.ts +57 -0
  197. package/resources/components.d.ts.map +1 -0
  198. package/resources/components.js +15 -0
  199. package/resources/components.js.map +1 -0
  200. package/resources/components.mjs +11 -0
  201. package/resources/components.mjs.map +1 -0
  202. package/resources/index.d.ts +4 -0
  203. package/resources/index.d.ts.map +1 -0
  204. package/resources/index.js +24 -0
  205. package/resources/index.js.map +1 -0
  206. package/resources/index.mjs +5 -0
  207. package/resources/index.mjs.map +1 -0
  208. package/resources/shared.d.ts +38 -0
  209. package/resources/shared.d.ts.map +1 -0
  210. package/resources/shared.js +4 -0
  211. package/resources/shared.js.map +1 -0
  212. package/resources/shared.mjs +3 -0
  213. package/resources/shared.mjs.map +1 -0
  214. package/shims/node.d.ts +30 -0
  215. package/shims/node.d.ts.map +1 -0
  216. package/shims/node.js +31 -0
  217. package/shims/node.js.map +1 -0
  218. package/shims/node.mjs +5 -0
  219. package/shims/node.mjs.map +1 -0
  220. package/shims/web.d.ts +26 -0
  221. package/shims/web.d.ts.map +1 -0
  222. package/shims/web.js +31 -0
  223. package/shims/web.js.map +1 -0
  224. package/shims/web.mjs +5 -0
  225. package/shims/web.mjs.map +1 -0
  226. package/src/_shims/MultipartBody.ts +9 -0
  227. package/src/_shims/README.md +46 -0
  228. package/src/_shims/auto/runtime-bun.ts +4 -0
  229. package/src/_shims/auto/runtime-node.ts +4 -0
  230. package/src/_shims/auto/runtime.ts +4 -0
  231. package/src/_shims/auto/types-node.ts +4 -0
  232. package/src/_shims/auto/types.d.ts +101 -0
  233. package/src/_shims/auto/types.js +3 -0
  234. package/src/_shims/auto/types.mjs +3 -0
  235. package/src/_shims/bun-runtime.ts +14 -0
  236. package/src/_shims/index.d.ts +81 -0
  237. package/src/_shims/index.js +13 -0
  238. package/src/_shims/index.mjs +7 -0
  239. package/src/_shims/manual-types.d.ts +12 -0
  240. package/src/_shims/manual-types.js +3 -0
  241. package/src/_shims/manual-types.mjs +3 -0
  242. package/src/_shims/node-runtime.ts +81 -0
  243. package/src/_shims/node-types.d.ts +42 -0
  244. package/src/_shims/node-types.js +3 -0
  245. package/src/_shims/node-types.mjs +3 -0
  246. package/src/_shims/registry.ts +67 -0
  247. package/src/_shims/web-runtime.ts +103 -0
  248. package/src/_shims/web-types.d.ts +83 -0
  249. package/src/_shims/web-types.js +3 -0
  250. package/src/_shims/web-types.mjs +3 -0
  251. package/src/core.ts +1208 -0
  252. package/src/error.ts +130 -0
  253. package/src/index.ts +229 -0
  254. package/src/lib/.keep +4 -0
  255. package/src/lib/advance-stream.ts +47 -0
  256. package/src/lib/streaming-components.ts +71 -0
  257. package/src/pagination.ts +73 -0
  258. package/src/resource.ts +11 -0
  259. package/src/resources/beta/beta.ts +96 -0
  260. package/src/resources/beta/components.ts +97 -0
  261. package/src/resources/beta/index.ts +38 -0
  262. package/src/resources/beta/projects/api-key.ts +48 -0
  263. package/src/resources/beta/projects/index.ts +26 -0
  264. package/src/resources/beta/projects/projects.ts +121 -0
  265. package/src/resources/beta/projects/provider-key.ts +71 -0
  266. package/src/resources/beta/projects/user.ts +26 -0
  267. package/src/resources/beta/registry.ts +16 -0
  268. package/src/resources/beta/threads/index.ts +32 -0
  269. package/src/resources/beta/threads/messages.ts +100 -0
  270. package/src/resources/beta/threads/suggestions.ts +89 -0
  271. package/src/resources/beta/threads/threads.ts +379 -0
  272. package/src/resources/components.ts +105 -0
  273. package/src/resources/index.ts +12 -0
  274. package/src/resources/shared.ts +59 -0
  275. package/src/shims/node.ts +50 -0
  276. package/src/shims/web.ts +50 -0
  277. package/src/tsconfig.json +16 -0
  278. package/src/uploads.ts +255 -0
  279. package/src/version.ts +1 -0
  280. package/uploads.d.ts +75 -0
  281. package/uploads.d.ts.map +1 -0
  282. package/uploads.js +171 -0
  283. package/uploads.js.map +1 -0
  284. package/uploads.mjs +158 -0
  285. package/uploads.mjs.map +1 -0
  286. package/version.d.ts +2 -0
  287. package/version.d.ts.map +1 -0
  288. package/version.js +5 -0
  289. package/version.js.map +1 -0
  290. package/version.mjs +2 -0
  291. package/version.mjs.map +1 -0
package/README.md ADDED
@@ -0,0 +1,434 @@
1
+ # Tambo Typescript API Library
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@tambo-ai/typescript-sdk.svg)](https://npmjs.org/package/@tambo-ai/typescript-sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@tambo-ai/typescript-sdk)
4
+
5
+ This library provides convenient access to the Tambo AI REST API from server-side TypeScript or JavaScript.
6
+
7
+ The REST API documentation can be found on [tambo.co](https://tambo.co/docs). The full API of this library can be found in [api.md](api.md).
8
+
9
+ It is generated with [Stainless](https://www.stainless.com/).
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ npm install @tambo-ai/typescript-sdk
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ The full API of this library can be found in [api.md](api.md).
20
+
21
+ <!-- prettier-ignore -->
22
+ ```js
23
+ import TamboAI from '@tambo-ai/typescript-sdk';
24
+
25
+ const client = new TamboAI({
26
+ apiKey: process.env['TAMBO_API_KEY'], // This is the default and can be omitted
27
+ });
28
+
29
+ async function main() {
30
+ const response = await client.components.generate({
31
+ availableComponents: {
32
+ foo: {
33
+ contextTools: [
34
+ {
35
+ description: 'description',
36
+ name: 'name',
37
+ parameters: [{ description: 'description', isRequired: true, name: 'name', type: 'type' }],
38
+ },
39
+ ],
40
+ description: 'description',
41
+ name: 'name',
42
+ props: { foo: 'bar' },
43
+ },
44
+ },
45
+ messageHistory: [{ message: 'message', sender: 'hydra' }],
46
+ });
47
+
48
+ console.log(response.componentName);
49
+ }
50
+
51
+ main();
52
+ ```
53
+
54
+ ### Request & Response types
55
+
56
+ This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
57
+
58
+ <!-- prettier-ignore -->
59
+ ```ts
60
+ import TamboAI from '@tambo-ai/typescript-sdk';
61
+
62
+ const client = new TamboAI({
63
+ apiKey: process.env['TAMBO_API_KEY'], // This is the default and can be omitted
64
+ });
65
+
66
+ async function main() {
67
+ const params: TamboAI.ComponentGenerateParams = {
68
+ availableComponents: {
69
+ foo: {
70
+ contextTools: [
71
+ {
72
+ description: 'description',
73
+ name: 'name',
74
+ parameters: [{ description: 'description', isRequired: true, name: 'name', type: 'type' }],
75
+ },
76
+ ],
77
+ description: 'description',
78
+ name: 'name',
79
+ props: { foo: 'bar' },
80
+ },
81
+ },
82
+ messageHistory: [{ message: 'message', sender: 'hydra' }],
83
+ };
84
+ const response: TamboAI.ComponentGenerateResponse = await client.components.generate(params);
85
+ }
86
+
87
+ main();
88
+ ```
89
+
90
+ Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
91
+
92
+ ## Handling errors
93
+
94
+ When the library is unable to connect to the API,
95
+ or if the API returns a non-success status code (i.e., 4xx or 5xx response),
96
+ a subclass of `APIError` will be thrown:
97
+
98
+ <!-- prettier-ignore -->
99
+ ```ts
100
+ async function main() {
101
+ const response = await client.components
102
+ .generate({
103
+ availableComponents: {
104
+ foo: {
105
+ contextTools: [
106
+ {
107
+ description: 'description',
108
+ name: 'name',
109
+ parameters: [{ description: 'description', isRequired: true, name: 'name', type: 'type' }],
110
+ },
111
+ ],
112
+ description: 'description',
113
+ name: 'name',
114
+ props: { foo: 'bar' },
115
+ },
116
+ },
117
+ messageHistory: [{ message: 'message', sender: 'hydra' }],
118
+ })
119
+ .catch(async (err) => {
120
+ if (err instanceof TamboAI.APIError) {
121
+ console.log(err.status); // 400
122
+ console.log(err.name); // BadRequestError
123
+ console.log(err.headers); // {server: 'nginx', ...}
124
+ } else {
125
+ throw err;
126
+ }
127
+ });
128
+ }
129
+
130
+ main();
131
+ ```
132
+
133
+ Error codes are as followed:
134
+
135
+ | Status Code | Error Type |
136
+ | ----------- | -------------------------- |
137
+ | 400 | `BadRequestError` |
138
+ | 401 | `AuthenticationError` |
139
+ | 403 | `PermissionDeniedError` |
140
+ | 404 | `NotFoundError` |
141
+ | 422 | `UnprocessableEntityError` |
142
+ | 429 | `RateLimitError` |
143
+ | >=500 | `InternalServerError` |
144
+ | N/A | `APIConnectionError` |
145
+
146
+ ### Retries
147
+
148
+ Certain errors will be automatically retried 0 times by default, with a short exponential backoff.
149
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
150
+ 429 Rate Limit, and >=500 Internal errors will all be retried by default.
151
+
152
+ You can use the `maxRetries` option to configure or disable this:
153
+
154
+ <!-- prettier-ignore -->
155
+ ```js
156
+ // Configure the default for all requests:
157
+ const client = new TamboAI({
158
+ maxRetries: 0, // default is 2
159
+ });
160
+
161
+ // Or, configure per-request:
162
+ await client.components.generate({ availableComponents: { foo: { contextTools: [{ description: 'description', name: 'name', parameters: [{ description: 'description', isRequired: true, name: 'name', type: 'type' }] }], description: 'description', name: 'name', props: { foo: 'bar' } } }, messageHistory: [{ message: 'message', sender: 'hydra' }] }, {
163
+ maxRetries: 5,
164
+ });
165
+ ```
166
+
167
+ ### Timeouts
168
+
169
+ Requests time out after 1 minute by default. You can configure this with a `timeout` option:
170
+
171
+ <!-- prettier-ignore -->
172
+ ```ts
173
+ // Configure the default for all requests:
174
+ const client = new TamboAI({
175
+ timeout: 20 * 1000, // 20 seconds (default is 1 minute)
176
+ });
177
+
178
+ // Override per-request:
179
+ await client.components.generate({ availableComponents: { foo: { contextTools: [{ description: 'description', name: 'name', parameters: [{ description: 'description', isRequired: true, name: 'name', type: 'type' }] }], description: 'description', name: 'name', props: { foo: 'bar' } } }, messageHistory: [{ message: 'message', sender: 'hydra' }] }, {
180
+ timeout: 5 * 1000,
181
+ });
182
+ ```
183
+
184
+ On timeout, an `APIConnectionTimeoutError` is thrown.
185
+
186
+ Note that requests which time out will be [retried twice by default](#retries).
187
+
188
+ ## Auto-pagination
189
+
190
+ List methods in the TamboAI API are paginated.
191
+ You can use the `for await … of` syntax to iterate through items across all pages:
192
+
193
+ ```ts
194
+ async function fetchAllBetaThreads(params) {
195
+ const allBetaThreads = [];
196
+ // Automatically fetches more pages as needed.
197
+ for await (const thread of client.beta.threads.list('projectId')) {
198
+ allBetaThreads.push(thread);
199
+ }
200
+ return allBetaThreads;
201
+ }
202
+ ```
203
+
204
+ Alternatively, you can request a single page at a time:
205
+
206
+ ```ts
207
+ let page = await client.beta.threads.list('projectId');
208
+ for (const thread of page.items) {
209
+ console.log(thread);
210
+ }
211
+
212
+ // Convenience methods are provided for manually paginating:
213
+ while (page.hasNextPage()) {
214
+ page = await page.getNextPage();
215
+ // ...
216
+ }
217
+ ```
218
+
219
+ ## Advanced Usage
220
+
221
+ ### Accessing raw Response data (e.g., headers)
222
+
223
+ The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.
224
+
225
+ You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.
226
+
227
+ <!-- prettier-ignore -->
228
+ ```ts
229
+ const client = new TamboAI();
230
+
231
+ const response = await client.components
232
+ .generate({
233
+ availableComponents: {
234
+ foo: {
235
+ contextTools: [
236
+ {
237
+ description: 'description',
238
+ name: 'name',
239
+ parameters: [{ description: 'description', isRequired: true, name: 'name', type: 'type' }],
240
+ },
241
+ ],
242
+ description: 'description',
243
+ name: 'name',
244
+ props: { foo: 'bar' },
245
+ },
246
+ },
247
+ messageHistory: [{ message: 'message', sender: 'hydra' }],
248
+ })
249
+ .asResponse();
250
+ console.log(response.headers.get('X-My-Header'));
251
+ console.log(response.statusText); // access the underlying Response object
252
+
253
+ const { data: response, response: raw } = await client.components
254
+ .generate({
255
+ availableComponents: {
256
+ foo: {
257
+ contextTools: [
258
+ {
259
+ description: 'description',
260
+ name: 'name',
261
+ parameters: [{ description: 'description', isRequired: true, name: 'name', type: 'type' }],
262
+ },
263
+ ],
264
+ description: 'description',
265
+ name: 'name',
266
+ props: { foo: 'bar' },
267
+ },
268
+ },
269
+ messageHistory: [{ message: 'message', sender: 'hydra' }],
270
+ })
271
+ .withResponse();
272
+ console.log(raw.headers.get('X-My-Header'));
273
+ console.log(response.componentName);
274
+ ```
275
+
276
+ ### Making custom/undocumented requests
277
+
278
+ This library is typed for convenient access to the documented API. If you need to access undocumented
279
+ endpoints, params, or response properties, the library can still be used.
280
+
281
+ #### Undocumented endpoints
282
+
283
+ To make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.
284
+ Options on the client, such as retries, will be respected when making these requests.
285
+
286
+ ```ts
287
+ await client.post('/some/path', {
288
+ body: { some_prop: 'foo' },
289
+ query: { some_query_arg: 'bar' },
290
+ });
291
+ ```
292
+
293
+ #### Undocumented request params
294
+
295
+ To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
296
+ parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
297
+ send will be sent as-is.
298
+
299
+ ```ts
300
+ client.foo.create({
301
+ foo: 'my_param',
302
+ bar: 12,
303
+ // @ts-expect-error baz is not yet public
304
+ baz: 'undocumented option',
305
+ });
306
+ ```
307
+
308
+ For requests with the `GET` verb, any extra params will be in the query, all other requests will send the
309
+ extra param in the body.
310
+
311
+ If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
312
+ options.
313
+
314
+ #### Undocumented response properties
315
+
316
+ To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
317
+ the response object, or cast the response object to the requisite type. Like the request params, we do not
318
+ validate or strip extra properties from the response from the API.
319
+
320
+ ### Customizing the fetch client
321
+
322
+ By default, this library uses `node-fetch` in Node, and expects a global `fetch` function in other environments.
323
+
324
+ If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
325
+ (for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
326
+ add the following import before your first import `from "TamboAI"`:
327
+
328
+ ```ts
329
+ // Tell TypeScript and the package to use the global web fetch instead of node-fetch.
330
+ // Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
331
+ import '@tambo-ai/typescript-sdk/shims/web';
332
+ import TamboAI from '@tambo-ai/typescript-sdk';
333
+ ```
334
+
335
+ To do the inverse, add `import "@tambo-ai/typescript-sdk/shims/node"` (which does import polyfills).
336
+ This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/tambo-ai/typescript-sdk/tree/main/src/_shims#readme)).
337
+
338
+ ### Logging and middleware
339
+
340
+ You may also provide a custom `fetch` function when instantiating the client,
341
+ which can be used to inspect or alter the `Request` or `Response` before/after each request:
342
+
343
+ ```ts
344
+ import { fetch } from 'undici'; // as one example
345
+ import TamboAI from '@tambo-ai/typescript-sdk';
346
+
347
+ const client = new TamboAI({
348
+ fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
349
+ console.log('About to make a request', url, init);
350
+ const response = await fetch(url, init);
351
+ console.log('Got response', response);
352
+ return response;
353
+ },
354
+ });
355
+ ```
356
+
357
+ Note that if given a `DEBUG=true` environment variable, this library will log all requests and responses automatically.
358
+ This is intended for debugging purposes only and may change in the future without notice.
359
+
360
+ ### Configuring an HTTP(S) Agent (e.g., for proxies)
361
+
362
+ By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
363
+
364
+ If you would like to disable or customize this behavior, for example to use the API behind a proxy, you can pass an `httpAgent` which is used for all requests (be they http or https), for example:
365
+
366
+ <!-- prettier-ignore -->
367
+ ```ts
368
+ import http from 'http';
369
+ import { HttpsProxyAgent } from 'https-proxy-agent';
370
+
371
+ // Configure the default for all requests:
372
+ const client = new TamboAI({
373
+ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
374
+ });
375
+
376
+ // Override per-request:
377
+ await client.components.generate(
378
+ {
379
+ availableComponents: {
380
+ foo: {
381
+ contextTools: [
382
+ {
383
+ description: 'description',
384
+ name: 'name',
385
+ parameters: [{ description: 'description', isRequired: true, name: 'name', type: 'type' }],
386
+ },
387
+ ],
388
+ description: 'description',
389
+ name: 'name',
390
+ props: { foo: 'bar' },
391
+ },
392
+ },
393
+ messageHistory: [{ message: 'message', sender: 'hydra' }],
394
+ },
395
+ {
396
+ httpAgent: new http.Agent({ keepAlive: false }),
397
+ },
398
+ );
399
+ ```
400
+
401
+ ## Semantic versioning
402
+
403
+ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
404
+
405
+ 1. Changes that only affect static types, without breaking runtime behavior.
406
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
407
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
408
+
409
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
410
+
411
+ We are keen for your feedback; please open an [issue](https://www.github.com/tambo-ai/typescript-sdk/issues) with questions, bugs, or suggestions.
412
+
413
+ ## Requirements
414
+
415
+ TypeScript >= 4.5 is supported.
416
+
417
+ The following runtimes are supported:
418
+
419
+ - Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
420
+ - Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
421
+ - Deno v1.28.0 or higher.
422
+ - Bun 1.0 or later.
423
+ - Cloudflare Workers.
424
+ - Vercel Edge Runtime.
425
+ - Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
426
+ - Nitro v2.6 or greater.
427
+
428
+ Note that React Native is not supported at this time.
429
+
430
+ If you are interested in other runtime environments, please open or upvote an issue on GitHub.
431
+
432
+ ## Contributing
433
+
434
+ See [the contributing documentation](./CONTRIBUTING.md).
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export declare class MultipartBody {
5
+ body: any;
6
+ constructor(body: any);
7
+ get [Symbol.toStringTag](): string;
8
+ }
9
+ //# sourceMappingURL=MultipartBody.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultipartBody.d.ts","sourceRoot":"","sources":["../src/_shims/MultipartBody.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAa;IACL,IAAI,EAAE,GAAG;gBAAT,IAAI,EAAE,GAAG;IAC5B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;CACF"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultipartBody = void 0;
4
+ /**
5
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
6
+ */
7
+ class MultipartBody {
8
+ constructor(body) {
9
+ this.body = body;
10
+ }
11
+ get [Symbol.toStringTag]() {
12
+ return 'MultipartBody';
13
+ }
14
+ }
15
+ exports.MultipartBody = MultipartBody;
16
+ //# sourceMappingURL=MultipartBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultipartBody.js","sourceRoot":"","sources":["../src/_shims/MultipartBody.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,aAAa;IACxB,YAAmB,IAAS;QAAT,SAAI,GAAJ,IAAI,CAAK;IAAG,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AALD,sCAKC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export class MultipartBody {
5
+ constructor(body) {
6
+ this.body = body;
7
+ }
8
+ get [Symbol.toStringTag]() {
9
+ return 'MultipartBody';
10
+ }
11
+ }
12
+ //# sourceMappingURL=MultipartBody.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultipartBody.mjs","sourceRoot":"","sources":["../src/_shims/MultipartBody.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,YAAmB,IAAS;QAAT,SAAI,GAAJ,IAAI,CAAK;IAAG,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,eAAe,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,46 @@
1
+ # 👋 Wondering what everything in here does?
2
+
3
+ `@tambo-ai/typescript-sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
4
+ edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM).
5
+
6
+ To do this, `@tambo-ai/typescript-sdk` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.
7
+
8
+ It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
9
+ automatically select the correct shims for each environment. However, conditional exports are a fairly new
10
+ feature and not supported everywhere. For instance, the TypeScript `"moduleResolution": "node"`
11
+
12
+ setting doesn't consult the `exports` map, compared to `"moduleResolution": "nodeNext"`, which does.
13
+ Unfortunately that's still the default setting, and it can result in errors like
14
+ getting the wrong raw `Response` type from `.asResponse()`, for example.
15
+
16
+ The user can work around these issues by manually importing one of:
17
+
18
+ - `import '@tambo-ai/typescript-sdk/shims/node'`
19
+ - `import '@tambo-ai/typescript-sdk/shims/web'`
20
+
21
+ All of the code here in `_shims` handles selecting the automatic default shims or manual overrides.
22
+
23
+ ### How it works - Runtime
24
+
25
+ Runtime shims get installed by calling `setShims` exported by `@tambo-ai/typescript-sdk/_shims/registry`.
26
+
27
+ Manually importing `@tambo-ai/typescript-sdk/shims/node` or `@tambo-ai/typescript-sdk/shims/web`, calls `setShims` with the respective runtime shims.
28
+
29
+ All client code imports shims from `@tambo-ai/typescript-sdk/_shims/index`, which:
30
+
31
+ - checks if shims have been set manually
32
+ - if not, calls `setShims` with the shims from `@tambo-ai/typescript-sdk/_shims/auto/runtime`
33
+ - re-exports the installed shims from `@tambo-ai/typescript-sdk/_shims/registry`.
34
+
35
+ `@tambo-ai/typescript-sdk/_shims/auto/runtime` exports web runtime shims.
36
+ If the `node` export condition is set, the export map replaces it with `@tambo-ai/typescript-sdk/_shims/auto/runtime-node`.
37
+
38
+ ### How it works - Type time
39
+
40
+ All client code imports shim types from `@tambo-ai/typescript-sdk/_shims/index`, which selects the manual types from `@tambo-ai/typescript-sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@tambo-ai/typescript-sdk/_shims/auto/types`.
41
+
42
+ `@tambo-ai/typescript-sdk/_shims/manual-types` exports an empty namespace.
43
+ Manually importing `@tambo-ai/typescript-sdk/shims/node` or `@tambo-ai/typescript-sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@tambo-ai/typescript-sdk/_shims/index`.
44
+
45
+ `@tambo-ai/typescript-sdk/_shims/auto/types` exports web type definitions.
46
+ If the `node` export condition is set, the export map replaces it with `@tambo-ai/typescript-sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export * from "../bun-runtime.js";
5
+ //# sourceMappingURL=runtime-bun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-bun.d.ts","sourceRoot":"","sources":["../../src/_shims/auto/runtime-bun.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,21 @@
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
+ /**
18
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
19
+ */
20
+ __exportStar(require("../bun-runtime.js"), exports);
21
+ //# sourceMappingURL=runtime-bun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-bun.js","sourceRoot":"","sources":["../../src/_shims/auto/runtime-bun.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,oDAA+B"}
@@ -0,0 +1,2 @@
1
+ export * from "../bun-runtime.mjs";
2
+ //# sourceMappingURL=runtime-bun.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-bun.mjs","sourceRoot":"","sources":["../../src/_shims/auto/runtime-bun.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export * from "../node-runtime.js";
5
+ //# sourceMappingURL=runtime-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-node.d.ts","sourceRoot":"","sources":["../../src/_shims/auto/runtime-node.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,21 @@
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
+ /**
18
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
19
+ */
20
+ __exportStar(require("../node-runtime.js"), exports);
21
+ //# sourceMappingURL=runtime-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-node.js","sourceRoot":"","sources":["../../src/_shims/auto/runtime-node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,qDAAgC"}
@@ -0,0 +1,2 @@
1
+ export * from "../node-runtime.mjs";
2
+ //# sourceMappingURL=runtime-node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-node.mjs","sourceRoot":"","sources":["../../src/_shims/auto/runtime-node.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export * from "../web-runtime.js";
5
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/_shims/auto/runtime.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,21 @@
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
+ /**
18
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
19
+ */
20
+ __exportStar(require("../web-runtime.js"), exports);
21
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/_shims/auto/runtime.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,oDAA+B"}
@@ -0,0 +1,2 @@
1
+ export * from "../web-runtime.mjs";
2
+ //# sourceMappingURL=runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.mjs","sourceRoot":"","sources":["../../src/_shims/auto/runtime.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export * from "../node-types.js";
5
+ //# sourceMappingURL=types-node.d.ts.map