@alquimia-ai/tools 1.0.1 → 1.0.2

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 (63) hide show
  1. package/dist/actions/alquimia.action.d.mts +3 -0
  2. package/dist/actions/alquimia.action.d.ts +3 -0
  3. package/dist/actions/alquimia.action.js +62 -0
  4. package/dist/actions/alquimia.action.js.map +1 -0
  5. package/dist/actions/alquimia.action.mjs +38 -0
  6. package/dist/actions/alquimia.action.mjs.map +1 -0
  7. package/dist/actions/baseApi.action.d.mts +20 -0
  8. package/dist/actions/baseApi.action.d.ts +20 -0
  9. package/dist/actions/baseApi.action.js +202 -0
  10. package/dist/actions/baseApi.action.js.map +1 -0
  11. package/dist/actions/baseApi.action.mjs +173 -0
  12. package/dist/actions/baseApi.action.mjs.map +1 -0
  13. package/dist/actions/index.d.mts +5 -0
  14. package/dist/actions/index.d.ts +5 -0
  15. package/dist/actions/index.js +236 -0
  16. package/dist/actions/index.js.map +1 -0
  17. package/dist/actions/index.mjs +205 -0
  18. package/dist/actions/index.mjs.map +1 -0
  19. package/dist/alquimia-sdk-DK0XLjol.d.mts +77 -0
  20. package/dist/alquimia-sdk-DK0XLjol.d.ts +77 -0
  21. package/dist/context/index.d.mts +22 -0
  22. package/dist/context/index.d.ts +22 -0
  23. package/dist/context/index.js +124 -0
  24. package/dist/context/index.js.map +1 -0
  25. package/dist/context/index.mjs +96 -0
  26. package/dist/context/index.mjs.map +1 -0
  27. package/dist/hooks/index.d.mts +54 -0
  28. package/dist/hooks/index.d.ts +54 -0
  29. package/dist/hooks/index.js +344 -0
  30. package/dist/hooks/index.js.map +1 -0
  31. package/dist/hooks/index.mjs +316 -0
  32. package/dist/hooks/index.mjs.map +1 -0
  33. package/dist/index.d.mts +14 -303
  34. package/dist/index.d.ts +14 -303
  35. package/dist/index.js +1143 -2448
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +1079 -2213
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/sdk/index.d.mts +74 -0
  40. package/dist/sdk/index.d.ts +74 -0
  41. package/dist/sdk/index.js +561 -0
  42. package/dist/sdk/index.js.map +1 -0
  43. package/dist/sdk/index.mjs +510 -0
  44. package/dist/sdk/index.mjs.map +1 -0
  45. package/dist/services/index.d.mts +26 -0
  46. package/dist/services/index.d.ts +26 -0
  47. package/dist/services/index.js +93 -0
  48. package/dist/services/index.js.map +1 -0
  49. package/dist/services/index.mjs +63 -0
  50. package/dist/services/index.mjs.map +1 -0
  51. package/dist/types/index.d.mts +105 -0
  52. package/dist/types/index.d.ts +105 -0
  53. package/dist/types/index.js +41 -0
  54. package/dist/types/index.js.map +1 -0
  55. package/dist/types/index.mjs +14 -0
  56. package/dist/types/index.mjs.map +1 -0
  57. package/dist/utils/index.d.mts +29 -0
  58. package/dist/utils/index.d.ts +29 -0
  59. package/dist/utils/index.js +170 -0
  60. package/dist/utils/index.js.map +1 -0
  61. package/dist/utils/index.mjs +133 -0
  62. package/dist/utils/index.mjs.map +1 -0
  63. package/package.json +42 -13
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/index.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ createMessageId: () => createMessageId,
24
+ defineAssistantId: () => defineAssistantId,
25
+ formatTimeWithUnit: () => formatTimeWithUnit,
26
+ generateHeaders: () => generateHeaders,
27
+ generateTranslatePrompt: () => generateTranslatePrompt,
28
+ getCookies: () => getCookies,
29
+ getQueryParam: () => getQueryParam,
30
+ getTopicSessionId: () => getTopicSessionId,
31
+ isTextContent: () => isTextContent,
32
+ parseConversationsMapCookie: () => parseConversationsMapCookie,
33
+ serializeAxiosError: () => serializeAxiosError
34
+ });
35
+ module.exports = __toCommonJS(utils_exports);
36
+
37
+ // src/utils/utils.ts
38
+ function generateTranslatePrompt(text) {
39
+ const prompt = `
40
+ Arrange the following text according to the given object structure and return it as plain json, values summarized to one word, no formatting:
41
+ {
42
+ restrictions: {
43
+ value: [''],
44
+ description: 'Restrictions to certain foods'
45
+ },
46
+ alergies: {
47
+ value: [''],
48
+ description: 'Alergies to certain foods'
49
+ },
50
+ wine_preference: {
51
+ value: [''],
52
+ description: 'Preferences for the wine'
53
+ },
54
+ meal_preference: {
55
+ value: [''],
56
+ description: 'Preferences for the meal'
57
+ }
58
+ }
59
+
60
+ Text: "${text}"
61
+
62
+ Output:
63
+ `;
64
+ return prompt;
65
+ }
66
+ function getCookies(name) {
67
+ if (typeof document === "undefined") return void 0;
68
+ const value = `; ${document.cookie}`;
69
+ const parts = value.split(`; ${name}=`);
70
+ if (parts.length === 2) return parts.pop()?.split(";").shift();
71
+ }
72
+ function generateHeaders(config) {
73
+ const headers = {
74
+ "Content-Type": "application/json"
75
+ };
76
+ if (config.token) {
77
+ headers["Authorization"] = `Bearer ${config.token}`;
78
+ }
79
+ if (config.headers) {
80
+ Object.entries(config.headers).forEach(([key, value]) => {
81
+ headers[key] = value;
82
+ });
83
+ }
84
+ return headers;
85
+ }
86
+ function isTextContent(buffer) {
87
+ try {
88
+ const text = new TextDecoder().decode(buffer);
89
+ return /^[\w\#\-\*]/.test(text.trim());
90
+ } catch {
91
+ return false;
92
+ }
93
+ }
94
+ function getQueryParam(param) {
95
+ if (typeof window !== "undefined") {
96
+ const urlParams = new URLSearchParams(window.location.search);
97
+ return urlParams.get(param);
98
+ }
99
+ return null;
100
+ }
101
+ function defineAssistantId(defaultId) {
102
+ if (typeof window !== "undefined" && window.location.pathname === "/") {
103
+ const queryAssistantId = getQueryParam("talkwith");
104
+ if (queryAssistantId) {
105
+ localStorage.setItem("assistantId", queryAssistantId);
106
+ return queryAssistantId;
107
+ }
108
+ const storedAssistantId = localStorage.getItem("assistantId");
109
+ return storedAssistantId || defaultId;
110
+ }
111
+ return defaultId;
112
+ }
113
+ function formatTimeWithUnit(timeMs) {
114
+ if (timeMs >= 1e3) {
115
+ return `${(timeMs / 1e3).toFixed(1)}s`;
116
+ }
117
+ return `${Math.round(timeMs)}ms`;
118
+ }
119
+ function serializeAxiosError(error) {
120
+ if (error instanceof Error) {
121
+ const customError = error;
122
+ return {
123
+ message: customError?.message,
124
+ name: customError?.name,
125
+ stack: customError?.stack,
126
+ code: customError?.code,
127
+ status: customError?.status
128
+ };
129
+ }
130
+ return {
131
+ message: String(error),
132
+ name: "Unknown Error"
133
+ };
134
+ }
135
+ function parseConversationsMapCookie(cookieValue) {
136
+ try {
137
+ const decodedValue = decodeURIComponent(cookieValue);
138
+ return JSON.parse(decodedValue);
139
+ } catch (e) {
140
+ console.error("Error parsing conversations cookie:", e);
141
+ return {};
142
+ }
143
+ }
144
+ function getTopicSessionId(topicId) {
145
+ const conversationsStr = getCookies("alquimia-sessions") || "{}";
146
+ if (!conversationsStr) {
147
+ const sessionCookie = getCookies("alquimia-session");
148
+ return sessionCookie || "";
149
+ }
150
+ const conversationsMap = parseConversationsMapCookie(conversationsStr);
151
+ return conversationsMap[topicId] || "";
152
+ }
153
+ function createMessageId() {
154
+ return Math.floor(Math.random() * 1e6).toString();
155
+ }
156
+ // Annotate the CommonJS export names for ESM import in node:
157
+ 0 && (module.exports = {
158
+ createMessageId,
159
+ defineAssistantId,
160
+ formatTimeWithUnit,
161
+ generateHeaders,
162
+ generateTranslatePrompt,
163
+ getCookies,
164
+ getQueryParam,
165
+ getTopicSessionId,
166
+ isTextContent,
167
+ parseConversationsMapCookie,
168
+ serializeAxiosError
169
+ });
170
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/index.ts","../../src/utils/utils.ts"],"sourcesContent":["export * from './utils';","import { BaseAPIConfig, ApiError, ConversationsMap } from \"../types/type\";\n\nexport function generateTranslatePrompt(text: string) {\n const prompt = `\n Arrange the following text according to the given object structure and return it as plain json, values summarized to one word, no formatting:\n {\n restrictions: {\n value: [''],\n description: 'Restrictions to certain foods'\n },\n alergies: {\n value: [''],\n description: 'Alergies to certain foods'\n },\n wine_preference: {\n value: [''],\n description: 'Preferences for the wine'\n },\n meal_preference: {\n value: [''],\n description: 'Preferences for the meal'\n }\n }\n\n Text: \"${text}\"\n\n Output:\n `;\n\n return prompt;\n}\n\nexport function getCookies(name: string) {\n if (typeof document === 'undefined') return undefined;\n const value = `; ${document.cookie}`;\n const parts = value.split(`; ${name}=`);\n if (parts.length === 2) return parts.pop()?.split(\";\").shift();\n}\n\nexport function generateHeaders(config: BaseAPIConfig): HeadersInit {\n const headers: HeadersInit = {\n \"Content-Type\": \"application/json\",\n };\n\n if (config.token) {\n headers[\"Authorization\"] = `Bearer ${config.token}`;\n }\n\n if (config.headers) {\n Object.entries(config.headers).forEach(([key, value]) => {\n headers[key] = value;\n });\n }\n\n return headers;\n}\n\nexport function isTextContent(buffer: ArrayBuffer): boolean {\n try {\n const text = new TextDecoder().decode(buffer);\n return /^[\\w\\#\\-\\*]/.test(text.trim());\n } catch {\n return false;\n }\n}\n\nexport function getQueryParam(param: string): string | null {\n if (typeof window !== 'undefined') {\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(param);\n }\n return null;\n}\n\nexport function defineAssistantId(defaultId: string): string {\n if (typeof window !== 'undefined' && window.location.pathname === '/') {\n const queryAssistantId = getQueryParam('talkwith');\n if (queryAssistantId) {\n localStorage.setItem('assistantId', queryAssistantId);\n return queryAssistantId;\n }\n const storedAssistantId = localStorage.getItem('assistantId');\n return storedAssistantId || defaultId;\n }\n return defaultId;\n}\n\nexport function formatTimeWithUnit(timeMs: number): string {\n if (timeMs >= 1000) {\n return `${(timeMs / 1000).toFixed(1)}s`;\n }\n return `${Math.round(timeMs)}ms`;\n};\n\nexport function serializeAxiosError(error: unknown){\n if (error instanceof Error) {\n const customError = error as ApiError;\n return {\n message: customError?.message, \n name: customError?.name,\n stack: customError?.stack,\n code: customError?.code,\n status: customError?.status,\n };\n }\n return {\n message: String(error),\n name: 'Unknown Error',\n };\n};\n\nexport function parseConversationsMapCookie(cookieValue: string): ConversationsMap {\n try {\n const decodedValue = decodeURIComponent(cookieValue);\n return JSON.parse(decodedValue) as ConversationsMap;\n } catch (e) {\n console.error('Error parsing conversations cookie:', e);\n return {};\n }\n}\n\nexport function getTopicSessionId(topicId: string): string {\n const conversationsStr = getCookies(\"alquimia-sessions\") || \"{}\";\n if (!conversationsStr) {\n const sessionCookie = getCookies(\"alquimia-session\");\n return sessionCookie || \"\";\n }\n\n const conversationsMap = parseConversationsMapCookie(conversationsStr);\n return conversationsMap[topicId] || \"\";\n}\n\nexport function createMessageId() {\n return Math.floor(Math.random() * 1000000).toString();\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,wBAAwB,MAAc;AACpD,QAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAqBA,IAAI;AAAA;AAAA;AAAA;AAKnB,SAAO;AACT;AAEO,SAAS,WAAW,MAAc;AACvC,MAAI,OAAO,aAAa,YAAa,QAAO;AAC5C,QAA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A,SAAO,GAAG,KAAK,MAAM,MAAM,CAAC;AAC9B;AAEO,SAAS,oBAAoB,OAAe;AACjD,MAAI,iBAAiB,OAAO;AAC1B,UAAM,cAAc;AACpB,WAAO;AAAA,MACL,SAAS,aAAa;AAAA,MACtB,MAAM,aAAa;AAAA,MACnB,OAAO,aAAa;AAAA,MACpB,MAAM,aAAa;AAAA,MACnB,QAAQ,aAAa;AAAA,IACvB;AAAA,EACF;AACA,SAAO;AAAA,IACL,SAAS,OAAO,KAAK;AAAA,IACrB,MAAM;AAAA,EACR;AACF;AAEO,SAAS,4BAA4B,aAAuC;AACjF,MAAI;AACF,UAAM,eAAe,mBAAmB,WAAW;AACnD,WAAO,KAAK,MAAM,YAAY;AAAA,EAChC,SAAS,GAAG;AACV,YAAQ,MAAM,uCAAuC,CAAC;AACtD,WAAO,CAAC;AAAA,EACV;AACF;AAEO,SAAS,kBAAkB,SAAyB;AACzD,QAAM,mBAAmB,WAAW,mBAAmB,KAAK;AAC5D,MAAI,CAAC,kBAAkB;AACrB,UAAM,gBAAgB,WAAW,kBAAkB;AACnD,WAAO,iBAAiB;AAAA,EAC1B;AAEA,QAAM,mBAAmB,4BAA4B,gBAAgB;AACrE,SAAO,iBAAiB,OAAO,KAAK;AACtC;AAEO,SAAS,kBAAkB;AAChC,SAAO,KAAK,MAAM,KAAK,OAAO,IAAI,GAAO,EAAE,SAAS;AACtD;","names":[]}
@@ -0,0 +1,133 @@
1
+ // src/utils/utils.ts
2
+ function generateTranslatePrompt(text) {
3
+ const prompt = `
4
+ Arrange the following text according to the given object structure and return it as plain json, values summarized to one word, no formatting:
5
+ {
6
+ restrictions: {
7
+ value: [''],
8
+ description: 'Restrictions to certain foods'
9
+ },
10
+ alergies: {
11
+ value: [''],
12
+ description: 'Alergies to certain foods'
13
+ },
14
+ wine_preference: {
15
+ value: [''],
16
+ description: 'Preferences for the wine'
17
+ },
18
+ meal_preference: {
19
+ value: [''],
20
+ description: 'Preferences for the meal'
21
+ }
22
+ }
23
+
24
+ Text: "${text}"
25
+
26
+ Output:
27
+ `;
28
+ return prompt;
29
+ }
30
+ function getCookies(name) {
31
+ if (typeof document === "undefined") return void 0;
32
+ const value = `; ${document.cookie}`;
33
+ const parts = value.split(`; ${name}=`);
34
+ if (parts.length === 2) return parts.pop()?.split(";").shift();
35
+ }
36
+ function generateHeaders(config) {
37
+ const headers = {
38
+ "Content-Type": "application/json"
39
+ };
40
+ if (config.token) {
41
+ headers["Authorization"] = `Bearer ${config.token}`;
42
+ }
43
+ if (config.headers) {
44
+ Object.entries(config.headers).forEach(([key, value]) => {
45
+ headers[key] = value;
46
+ });
47
+ }
48
+ return headers;
49
+ }
50
+ function isTextContent(buffer) {
51
+ try {
52
+ const text = new TextDecoder().decode(buffer);
53
+ return /^[\w\#\-\*]/.test(text.trim());
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+ function getQueryParam(param) {
59
+ if (typeof window !== "undefined") {
60
+ const urlParams = new URLSearchParams(window.location.search);
61
+ return urlParams.get(param);
62
+ }
63
+ return null;
64
+ }
65
+ function defineAssistantId(defaultId) {
66
+ if (typeof window !== "undefined" && window.location.pathname === "/") {
67
+ const queryAssistantId = getQueryParam("talkwith");
68
+ if (queryAssistantId) {
69
+ localStorage.setItem("assistantId", queryAssistantId);
70
+ return queryAssistantId;
71
+ }
72
+ const storedAssistantId = localStorage.getItem("assistantId");
73
+ return storedAssistantId || defaultId;
74
+ }
75
+ return defaultId;
76
+ }
77
+ function formatTimeWithUnit(timeMs) {
78
+ if (timeMs >= 1e3) {
79
+ return `${(timeMs / 1e3).toFixed(1)}s`;
80
+ }
81
+ return `${Math.round(timeMs)}ms`;
82
+ }
83
+ function serializeAxiosError(error) {
84
+ if (error instanceof Error) {
85
+ const customError = error;
86
+ return {
87
+ message: customError?.message,
88
+ name: customError?.name,
89
+ stack: customError?.stack,
90
+ code: customError?.code,
91
+ status: customError?.status
92
+ };
93
+ }
94
+ return {
95
+ message: String(error),
96
+ name: "Unknown Error"
97
+ };
98
+ }
99
+ function parseConversationsMapCookie(cookieValue) {
100
+ try {
101
+ const decodedValue = decodeURIComponent(cookieValue);
102
+ return JSON.parse(decodedValue);
103
+ } catch (e) {
104
+ console.error("Error parsing conversations cookie:", e);
105
+ return {};
106
+ }
107
+ }
108
+ function getTopicSessionId(topicId) {
109
+ const conversationsStr = getCookies("alquimia-sessions") || "{}";
110
+ if (!conversationsStr) {
111
+ const sessionCookie = getCookies("alquimia-session");
112
+ return sessionCookie || "";
113
+ }
114
+ const conversationsMap = parseConversationsMapCookie(conversationsStr);
115
+ return conversationsMap[topicId] || "";
116
+ }
117
+ function createMessageId() {
118
+ return Math.floor(Math.random() * 1e6).toString();
119
+ }
120
+ export {
121
+ createMessageId,
122
+ defineAssistantId,
123
+ formatTimeWithUnit,
124
+ generateHeaders,
125
+ generateTranslatePrompt,
126
+ getCookies,
127
+ getQueryParam,
128
+ getTopicSessionId,
129
+ isTextContent,
130
+ parseConversationsMapCookie,
131
+ serializeAxiosError
132
+ };
133
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/utils.ts"],"sourcesContent":["import { BaseAPIConfig, ApiError, ConversationsMap } from \"../types/type\";\n\nexport function generateTranslatePrompt(text: string) {\n const prompt = `\n Arrange the following text according to the given object structure and return it as plain json, values summarized to one word, no formatting:\n {\n restrictions: {\n value: [''],\n description: 'Restrictions to certain foods'\n },\n alergies: {\n value: [''],\n description: 'Alergies to certain foods'\n },\n wine_preference: {\n value: [''],\n description: 'Preferences for the wine'\n },\n meal_preference: {\n value: [''],\n description: 'Preferences for the meal'\n }\n }\n\n Text: \"${text}\"\n\n Output:\n `;\n\n return prompt;\n}\n\nexport function getCookies(name: string) {\n if (typeof document === 'undefined') return undefined;\n const value = `; ${document.cookie}`;\n const parts = value.split(`; ${name}=`);\n if (parts.length === 2) return parts.pop()?.split(\";\").shift();\n}\n\nexport function generateHeaders(config: BaseAPIConfig): HeadersInit {\n const headers: HeadersInit = {\n \"Content-Type\": \"application/json\",\n };\n\n if (config.token) {\n headers[\"Authorization\"] = `Bearer ${config.token}`;\n }\n\n if (config.headers) {\n Object.entries(config.headers).forEach(([key, value]) => {\n headers[key] = value;\n });\n }\n\n return headers;\n}\n\nexport function isTextContent(buffer: ArrayBuffer): boolean {\n try {\n const text = new TextDecoder().decode(buffer);\n return /^[\\w\\#\\-\\*]/.test(text.trim());\n } catch {\n return false;\n }\n}\n\nexport function getQueryParam(param: string): string | null {\n if (typeof window !== 'undefined') {\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(param);\n }\n return null;\n}\n\nexport function defineAssistantId(defaultId: string): string {\n if (typeof window !== 'undefined' && window.location.pathname === '/') {\n const queryAssistantId = getQueryParam('talkwith');\n if (queryAssistantId) {\n localStorage.setItem('assistantId', queryAssistantId);\n return queryAssistantId;\n }\n const storedAssistantId = localStorage.getItem('assistantId');\n return storedAssistantId || defaultId;\n }\n return defaultId;\n}\n\nexport function formatTimeWithUnit(timeMs: number): string {\n if (timeMs >= 1000) {\n return `${(timeMs / 1000).toFixed(1)}s`;\n }\n return `${Math.round(timeMs)}ms`;\n};\n\nexport function serializeAxiosError(error: unknown){\n if (error instanceof Error) {\n const customError = error as ApiError;\n return {\n message: customError?.message, \n name: customError?.name,\n stack: customError?.stack,\n code: customError?.code,\n status: customError?.status,\n };\n }\n return {\n message: String(error),\n name: 'Unknown Error',\n };\n};\n\nexport function parseConversationsMapCookie(cookieValue: string): ConversationsMap {\n try {\n const decodedValue = decodeURIComponent(cookieValue);\n return JSON.parse(decodedValue) as ConversationsMap;\n } catch (e) {\n console.error('Error parsing conversations cookie:', e);\n return {};\n }\n}\n\nexport function getTopicSessionId(topicId: string): string {\n const conversationsStr = getCookies(\"alquimia-sessions\") || \"{}\";\n if (!conversationsStr) {\n const sessionCookie = getCookies(\"alquimia-session\");\n return sessionCookie || \"\";\n }\n\n const conversationsMap = parseConversationsMapCookie(conversationsStr);\n return conversationsMap[topicId] || \"\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]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alquimia-ai/tools",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "author": "Alquimia AI",
5
5
  "description": "tools for Alquimia SDK",
6
6
  "private": false,
@@ -10,26 +10,55 @@
10
10
  "license": "MIT",
11
11
  "exports": {
12
12
  ".": {
13
+ "types": "./dist/index.d.ts",
13
14
  "import": "./dist/index.mjs",
14
15
  "require": "./dist/index.js"
15
16
  },
16
- "./button": "./src/button.tsx",
17
- "./card": "./src/card.tsx",
18
- "./code": "./src/code.tsx",
19
- "./sdk": "./src/sdk/index.ts",
20
- "./hooks": "./src/hooks/index.ts",
21
- "./actions": "./src/actions/index.ts",
22
- "./providers": "./src/sdk/providers/index.ts",
23
- "./utils": "./src/utils/index.ts",
24
- "./types": "./src/types/type.ts",
25
- "./context": "./src/context/index.ts",
26
- "./services": "./src/services/index.ts",
17
+ "./utils": {
18
+ "types": "./dist/utils/index.d.ts",
19
+ "import": "./dist/utils/index.mjs",
20
+ "require": "./dist/utils/index.js"
21
+ },
22
+ "./sdk": {
23
+ "types": "./dist/sdk/index.d.ts",
24
+ "import": "./dist/sdk/index.mjs",
25
+ "require": "./dist/sdk/index.js"
26
+ },
27
+ "./hooks": {
28
+ "types": "./dist/hooks/index.d.ts",
29
+ "import": "./dist/hooks/index.mjs",
30
+ "require": "./dist/hooks/index.js"
31
+ },
32
+ "./actions": {
33
+ "types": "./src/actions/index.ts",
34
+ "default": "./src/actions/index.ts"
35
+ },
36
+ "./providers": {
37
+ "types": "./dist/sdk/index.d.ts",
38
+ "import": "./dist/sdk/index.mjs",
39
+ "require": "./dist/sdk/index.js"
40
+ },
41
+ "./types": {
42
+ "types": "./dist/types/index.d.ts",
43
+ "import": "./dist/types/index.mjs",
44
+ "require": "./dist/types/index.js"
45
+ },
46
+ "./context": {
47
+ "types": "./dist/context/index.d.ts",
48
+ "import": "./dist/context/index.mjs",
49
+ "require": "./dist/context/index.js"
50
+ },
51
+ "./services": {
52
+ "types": "./dist/services/index.d.ts",
53
+ "import": "./dist/services/index.mjs",
54
+ "require": "./dist/services/index.js"
55
+ },
27
56
  "./package.json": "./package.json"
28
57
  },
29
58
  "scripts": {
30
59
  "lint": "eslint . --max-warnings 0",
31
60
  "generate:component": "turbo gen react-component",
32
- "build": "tsup src/index.ts --format esm,cjs --dts",
61
+ "build": "tsup src/index.ts src/**/index.ts src/**/*.action.ts --format esm,cjs --target es2020",
33
62
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
34
63
  "dev": "tsup src/index.ts --format esm,cjs --watch --dts"
35
64
  },