@alquimia-ai/tools 1.13.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/actions/index.d.mts +7 -17
  2. package/dist/actions/index.d.ts +7 -17
  3. package/dist/actions/index.js +45 -152
  4. package/dist/actions/index.js.map +1 -1
  5. package/dist/actions/index.mjs +45 -152
  6. package/dist/actions/index.mjs.map +1 -1
  7. package/dist/adapters/fetch.d.mts +12 -0
  8. package/dist/adapters/fetch.d.ts +12 -0
  9. package/dist/adapters/fetch.js +44 -0
  10. package/dist/adapters/fetch.js.map +1 -0
  11. package/dist/adapters/fetch.mjs +23 -0
  12. package/dist/adapters/fetch.mjs.map +1 -0
  13. package/dist/adapters/index.d.mts +11 -0
  14. package/dist/adapters/index.d.ts +11 -0
  15. package/dist/adapters/index.js +19 -0
  16. package/dist/adapters/index.js.map +1 -0
  17. package/dist/adapters/index.mjs +1 -0
  18. package/dist/adapters/index.mjs.map +1 -0
  19. package/dist/adapters/next.d.mts +10 -0
  20. package/dist/adapters/next.d.ts +10 -0
  21. package/dist/adapters/next.js +42 -0
  22. package/dist/adapters/next.js.map +1 -0
  23. package/dist/adapters/next.mjs +21 -0
  24. package/dist/adapters/next.mjs.map +1 -0
  25. package/dist/hooks/index.d.mts +22 -2
  26. package/dist/hooks/index.d.ts +22 -2
  27. package/dist/hooks/index.js +243 -40
  28. package/dist/hooks/index.js.map +1 -1
  29. package/dist/hooks/index.mjs +234 -41
  30. package/dist/hooks/index.mjs.map +1 -1
  31. package/dist/next/index.d.mts +49 -0
  32. package/dist/next/index.d.ts +49 -0
  33. package/dist/next/index.js +332 -0
  34. package/dist/next/index.js.map +1 -0
  35. package/dist/next/index.mjs +309 -0
  36. package/dist/next/index.mjs.map +1 -0
  37. package/dist/providers/index.d.mts +7 -3
  38. package/dist/providers/index.d.ts +7 -3
  39. package/dist/providers/index.js +15 -14
  40. package/dist/providers/index.js.map +1 -1
  41. package/dist/providers/index.mjs +15 -14
  42. package/dist/providers/index.mjs.map +1 -1
  43. package/dist/proxy.d.mts +15 -0
  44. package/dist/proxy.d.ts +15 -0
  45. package/dist/proxy.js +147 -0
  46. package/dist/proxy.js.map +1 -0
  47. package/dist/proxy.mjs +126 -0
  48. package/dist/proxy.mjs.map +1 -0
  49. package/dist/sdk/index.d.mts +8 -14
  50. package/dist/sdk/index.d.ts +8 -14
  51. package/dist/sdk/index.js +47 -47
  52. package/dist/sdk/index.js.map +1 -1
  53. package/dist/sdk/index.mjs +47 -47
  54. package/dist/sdk/index.mjs.map +1 -1
  55. package/dist/services/index.d.mts +25 -3
  56. package/dist/services/index.d.ts +25 -3
  57. package/package.json +35 -5
  58. package/dist/providers/elastic/index.d.mts +0 -23
  59. package/dist/providers/elastic/index.d.ts +0 -23
  60. package/dist/providers/elastic/index.js +0 -102
  61. package/dist/providers/elastic/index.js.map +0 -1
  62. package/dist/providers/elastic/index.mjs +0 -69
  63. package/dist/providers/elastic/index.mjs.map +0 -1
  64. package/dist/services/apm/index.d.mts +0 -26
  65. package/dist/services/apm/index.d.ts +0 -26
  66. package/dist/services/apm/index.js +0 -86
  67. package/dist/services/apm/index.js.map +0 -1
  68. package/dist/services/apm/index.mjs +0 -63
  69. package/dist/services/apm/index.mjs.map +0 -1
@@ -0,0 +1,15 @@
1
+ interface ProxyConfig {
2
+ assistantBaseUrl: string;
3
+ apiKey: string;
4
+ inferRoute?: string;
5
+ streamRoute?: string;
6
+ attachmentRoute?: string;
7
+ }
8
+ interface AlquimiaProxyHandler {
9
+ handleInfer(request: Request, pathSuffix: string): Promise<Response>;
10
+ handleStream(request: Request, pathSuffix: string): Promise<Response>;
11
+ handleAttachment(request: Request, streamId: string, attachmentId: string): Promise<Response>;
12
+ }
13
+ declare function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler;
14
+
15
+ export { type AlquimiaProxyHandler, type ProxyConfig, createAlquimiaProxyHandler };
@@ -0,0 +1,15 @@
1
+ interface ProxyConfig {
2
+ assistantBaseUrl: string;
3
+ apiKey: string;
4
+ inferRoute?: string;
5
+ streamRoute?: string;
6
+ attachmentRoute?: string;
7
+ }
8
+ interface AlquimiaProxyHandler {
9
+ handleInfer(request: Request, pathSuffix: string): Promise<Response>;
10
+ handleStream(request: Request, pathSuffix: string): Promise<Response>;
11
+ handleAttachment(request: Request, streamId: string, attachmentId: string): Promise<Response>;
12
+ }
13
+ declare function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler;
14
+
15
+ export { type AlquimiaProxyHandler, type ProxyConfig, createAlquimiaProxyHandler };
package/dist/proxy.js ADDED
@@ -0,0 +1,147 @@
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/proxy.ts
21
+ var proxy_exports = {};
22
+ __export(proxy_exports, {
23
+ createAlquimiaProxyHandler: () => createAlquimiaProxyHandler
24
+ });
25
+ module.exports = __toCommonJS(proxy_exports);
26
+ function createAlquimiaProxyHandler(config) {
27
+ const baseUrl = config.assistantBaseUrl.replace(/\/$/, "");
28
+ const inferRoute = config.inferRoute ?? "event/infer";
29
+ const streamRoute = config.streamRoute ?? "event/stream";
30
+ const attachmentRoute = config.attachmentRoute ?? "event/attachment";
31
+ const authHeader = { Authorization: `Bearer ${config.apiKey}` };
32
+ return {
33
+ async handleInfer(request, pathSuffix) {
34
+ try {
35
+ const body = await request.json();
36
+ const url = new URL(request.url);
37
+ const querySuffix = url.searchParams.toString() ? `?${url.searchParams.toString()}` : "";
38
+ const targetUrl = `${baseUrl}/${inferRoute}/${pathSuffix}${querySuffix}`;
39
+ const response = await fetch(targetUrl, {
40
+ method: "POST",
41
+ headers: { "Content-Type": "application/json", ...authHeader },
42
+ body: JSON.stringify(body)
43
+ });
44
+ if (!response.ok) {
45
+ const errorJson = await response.json().catch(() => ({}));
46
+ console.error("AlquimiaProxy handleInfer error:", {
47
+ status: response.status,
48
+ statusText: response.statusText,
49
+ body: errorJson
50
+ });
51
+ return new Response(
52
+ JSON.stringify({
53
+ status: response.status,
54
+ statusText: response.statusText,
55
+ ...errorJson
56
+ }),
57
+ { status: response.status, headers: { "Content-Type": "application/json" } }
58
+ );
59
+ }
60
+ return new Response(response.body, {
61
+ status: 200,
62
+ headers: {
63
+ "Access-Control-Allow-Origin": "*",
64
+ "Access-Control-Allow-Methods": "POST, OPTIONS",
65
+ "Access-Control-Allow-Headers": "Content-Type, Content-Encoding"
66
+ }
67
+ });
68
+ } catch (error) {
69
+ console.error("AlquimiaProxy handleInfer exception:", error);
70
+ return new Response(
71
+ JSON.stringify({ error: "Failed to forward infer request" }),
72
+ { status: 500, headers: { "Content-Type": "application/json" } }
73
+ );
74
+ }
75
+ },
76
+ async handleStream(request, pathSuffix) {
77
+ try {
78
+ const targetUrl = `${baseUrl}/${streamRoute}/${pathSuffix}`;
79
+ const response = await fetch(targetUrl, {
80
+ headers: { "Content-Type": "application/json", ...authHeader }
81
+ });
82
+ if (!response.ok) {
83
+ const errorJson = await response.json().catch(() => ({}));
84
+ console.error("AlquimiaProxy handleStream error:", {
85
+ status: response.status,
86
+ statusText: response.statusText,
87
+ body: errorJson
88
+ });
89
+ return new Response(
90
+ JSON.stringify({
91
+ error: errorJson.message || response.statusText || "Failed to forward stream",
92
+ ...errorJson
93
+ }),
94
+ { status: response.status, headers: { "Content-Type": "application/json" } }
95
+ );
96
+ }
97
+ return new Response(response.body, {
98
+ status: 200,
99
+ headers: {
100
+ "Content-Type": "text/event-stream",
101
+ "Cache-Control": "no-cache",
102
+ Connection: "keep-alive"
103
+ }
104
+ });
105
+ } catch (error) {
106
+ console.error("AlquimiaProxy handleStream exception:", error);
107
+ return new Response(
108
+ JSON.stringify({ error: "Failed to forward stream request" }),
109
+ { status: 500, headers: { "Content-Type": "application/json" } }
110
+ );
111
+ }
112
+ },
113
+ async handleAttachment(request, streamId, attachmentId) {
114
+ try {
115
+ const targetUrl = `${baseUrl}/${attachmentRoute}/${streamId}/${attachmentId}`;
116
+ const contentType = request.headers.get("Content-Type") ?? "";
117
+ const response = await fetch(targetUrl, {
118
+ method: "POST",
119
+ headers: {
120
+ ...authHeader,
121
+ ...contentType && { "Content-Type": contentType }
122
+ },
123
+ body: request.body,
124
+ duplex: "half"
125
+ });
126
+ if (!response.ok) {
127
+ return new Response(
128
+ JSON.stringify({ error: "Failed to upload attachment", status: response.status }),
129
+ { status: response.status, headers: { "Content-Type": "application/json" } }
130
+ );
131
+ }
132
+ const responseText = await response.text();
133
+ return new Response(responseText, {
134
+ status: 200,
135
+ headers: { "Content-Type": "application/json" }
136
+ });
137
+ } catch (error) {
138
+ console.error("AlquimiaProxy handleAttachment exception:", error);
139
+ return new Response(
140
+ JSON.stringify({ error: "Failed to forward attachment request" }),
141
+ { status: 500, headers: { "Content-Type": "application/json" } }
142
+ );
143
+ }
144
+ }
145
+ };
146
+ }
147
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/proxy.ts"],"sourcesContent":["export interface ProxyConfig {\n assistantBaseUrl: string;\n apiKey: string;\n inferRoute?: string; // default: 'event/infer'\n streamRoute?: string; // default: 'event/stream'\n attachmentRoute?: string; // default: 'event/attachment'\n}\n\nexport interface AlquimiaProxyHandler {\n handleInfer(request: Request, pathSuffix: string): Promise<Response>;\n handleStream(request: Request, pathSuffix: string): Promise<Response>;\n handleAttachment(request: Request, streamId: string, attachmentId: string): Promise<Response>;\n}\n\nexport function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler {\n const baseUrl = config.assistantBaseUrl.replace(/\\/$/, '');\n const inferRoute = config.inferRoute ?? 'event/infer';\n const streamRoute = config.streamRoute ?? 'event/stream';\n const attachmentRoute = config.attachmentRoute ?? 'event/attachment';\n const authHeader = { Authorization: `Bearer ${config.apiKey}` };\n\n return {\n async handleInfer(request: Request, pathSuffix: string): Promise<Response> {\n try {\n const body = await request.json();\n const url = new URL(request.url);\n const querySuffix = url.searchParams.toString()\n ? `?${url.searchParams.toString()}`\n : '';\n const targetUrl = `${baseUrl}/${inferRoute}/${pathSuffix}${querySuffix}`;\n\n const response = await fetch(targetUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...authHeader },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorJson = await response.json().catch(() => ({}));\n console.error('AlquimiaProxy handleInfer error:', {\n status: response.status,\n statusText: response.statusText,\n body: errorJson,\n });\n return new Response(\n JSON.stringify({\n status: response.status,\n statusText: response.statusText,\n ...errorJson,\n }),\n { status: response.status, headers: { 'Content-Type': 'application/json' } }\n );\n }\n\n return new Response(response.body, {\n status: 200,\n headers: {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'POST, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Content-Encoding',\n },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleInfer exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward infer request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n\n async handleStream(request: Request, pathSuffix: string): Promise<Response> {\n try {\n const targetUrl = `${baseUrl}/${streamRoute}/${pathSuffix}`;\n\n const response = await fetch(targetUrl, {\n headers: { 'Content-Type': 'application/json', ...authHeader },\n });\n\n if (!response.ok) {\n const errorJson = await response.json().catch(() => ({}));\n console.error('AlquimiaProxy handleStream error:', {\n status: response.status,\n statusText: response.statusText,\n body: errorJson,\n });\n return new Response(\n JSON.stringify({\n error: errorJson.message || response.statusText || 'Failed to forward stream',\n ...errorJson,\n }),\n { status: response.status, headers: { 'Content-Type': 'application/json' } }\n );\n }\n\n return new Response(response.body, {\n status: 200,\n headers: {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache',\n Connection: 'keep-alive',\n },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleStream exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward stream request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n\n async handleAttachment(\n request: Request,\n streamId: string,\n attachmentId: string\n ): Promise<Response> {\n try {\n const targetUrl = `${baseUrl}/${attachmentRoute}/${streamId}/${attachmentId}`;\n const contentType = request.headers.get('Content-Type') ?? '';\n\n const response = await fetch(targetUrl, {\n method: 'POST',\n headers: {\n ...authHeader,\n ...(contentType && { 'Content-Type': contentType }),\n },\n body: request.body,\n duplex: 'half',\n } as RequestInit);\n\n if (!response.ok) {\n return new Response(\n JSON.stringify({ error: 'Failed to upload attachment', status: response.status }),\n { status: response.status, headers: { 'Content-Type': 'application/json' } }\n );\n }\n\n const responseText = await response.text();\n return new Response(responseText, {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleAttachment exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward attachment request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcO,SAAS,2BAA2B,QAA2C;AACpF,QAAM,UAAU,OAAO,iBAAiB,QAAQ,OAAO,EAAE;AACzD,QAAM,aAAa,OAAO,cAAc;AACxC,QAAM,cAAc,OAAO,eAAe;AAC1C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,eAAe,IAAI,QAAQ,IAAI,YAAY;AAC3E,cAAM,cAAc,QAAQ,QAAQ,IAAI,cAAc,KAAK;AAE3D,cAAM,WAAW,MAAM,MAAM,WAAW;AAAA,UACtC,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,GAAG;AAAA,YACH,GAAI,eAAe,EAAE,gBAAgB,YAAY;AAAA,UACnD;AAAA,UACA,MAAM,QAAQ;AAAA,UACd,QAAQ;AAAA,QACV,CAAgB;AAEhB,YAAI,CAAC,SAAS,IAAI;AAChB,iBAAO,IAAI;AAAA,YACT,KAAK,UAAU,EAAE,OAAO,+BAA+B,QAAQ,SAAS,OAAO,CAAC;AAAA,YAChF,EAAE,QAAQ,SAAS,QAAQ,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,UAC7E;AAAA,QACF;AAEA,cAAM,eAAe,MAAM,SAAS,KAAK;AACzC,eAAO,IAAI,SAAS,cAAc;AAAA,UAChC,QAAQ;AAAA,UACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,QAChD,CAAC;AAAA,MACH,SAAS,OAAO;AACd,gBAAQ,MAAM,6CAA6C,KAAK;AAChE,eAAO,IAAI;AAAA,UACT,KAAK,UAAU,EAAE,OAAO,uCAAuC,CAAC;AAAA,UAChE,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/dist/proxy.mjs ADDED
@@ -0,0 +1,126 @@
1
+ // src/proxy.ts
2
+ function createAlquimiaProxyHandler(config) {
3
+ const baseUrl = config.assistantBaseUrl.replace(/\/$/, "");
4
+ const inferRoute = config.inferRoute ?? "event/infer";
5
+ const streamRoute = config.streamRoute ?? "event/stream";
6
+ const attachmentRoute = config.attachmentRoute ?? "event/attachment";
7
+ const authHeader = { Authorization: `Bearer ${config.apiKey}` };
8
+ return {
9
+ async handleInfer(request, pathSuffix) {
10
+ try {
11
+ const body = await request.json();
12
+ const url = new URL(request.url);
13
+ const querySuffix = url.searchParams.toString() ? `?${url.searchParams.toString()}` : "";
14
+ const targetUrl = `${baseUrl}/${inferRoute}/${pathSuffix}${querySuffix}`;
15
+ const response = await fetch(targetUrl, {
16
+ method: "POST",
17
+ headers: { "Content-Type": "application/json", ...authHeader },
18
+ body: JSON.stringify(body)
19
+ });
20
+ if (!response.ok) {
21
+ const errorJson = await response.json().catch(() => ({}));
22
+ console.error("AlquimiaProxy handleInfer error:", {
23
+ status: response.status,
24
+ statusText: response.statusText,
25
+ body: errorJson
26
+ });
27
+ return new Response(
28
+ JSON.stringify({
29
+ status: response.status,
30
+ statusText: response.statusText,
31
+ ...errorJson
32
+ }),
33
+ { status: response.status, headers: { "Content-Type": "application/json" } }
34
+ );
35
+ }
36
+ return new Response(response.body, {
37
+ status: 200,
38
+ headers: {
39
+ "Access-Control-Allow-Origin": "*",
40
+ "Access-Control-Allow-Methods": "POST, OPTIONS",
41
+ "Access-Control-Allow-Headers": "Content-Type, Content-Encoding"
42
+ }
43
+ });
44
+ } catch (error) {
45
+ console.error("AlquimiaProxy handleInfer exception:", error);
46
+ return new Response(
47
+ JSON.stringify({ error: "Failed to forward infer request" }),
48
+ { status: 500, headers: { "Content-Type": "application/json" } }
49
+ );
50
+ }
51
+ },
52
+ async handleStream(request, pathSuffix) {
53
+ try {
54
+ const targetUrl = `${baseUrl}/${streamRoute}/${pathSuffix}`;
55
+ const response = await fetch(targetUrl, {
56
+ headers: { "Content-Type": "application/json", ...authHeader }
57
+ });
58
+ if (!response.ok) {
59
+ const errorJson = await response.json().catch(() => ({}));
60
+ console.error("AlquimiaProxy handleStream error:", {
61
+ status: response.status,
62
+ statusText: response.statusText,
63
+ body: errorJson
64
+ });
65
+ return new Response(
66
+ JSON.stringify({
67
+ error: errorJson.message || response.statusText || "Failed to forward stream",
68
+ ...errorJson
69
+ }),
70
+ { status: response.status, headers: { "Content-Type": "application/json" } }
71
+ );
72
+ }
73
+ return new Response(response.body, {
74
+ status: 200,
75
+ headers: {
76
+ "Content-Type": "text/event-stream",
77
+ "Cache-Control": "no-cache",
78
+ Connection: "keep-alive"
79
+ }
80
+ });
81
+ } catch (error) {
82
+ console.error("AlquimiaProxy handleStream exception:", error);
83
+ return new Response(
84
+ JSON.stringify({ error: "Failed to forward stream request" }),
85
+ { status: 500, headers: { "Content-Type": "application/json" } }
86
+ );
87
+ }
88
+ },
89
+ async handleAttachment(request, streamId, attachmentId) {
90
+ try {
91
+ const targetUrl = `${baseUrl}/${attachmentRoute}/${streamId}/${attachmentId}`;
92
+ const contentType = request.headers.get("Content-Type") ?? "";
93
+ const response = await fetch(targetUrl, {
94
+ method: "POST",
95
+ headers: {
96
+ ...authHeader,
97
+ ...contentType && { "Content-Type": contentType }
98
+ },
99
+ body: request.body,
100
+ duplex: "half"
101
+ });
102
+ if (!response.ok) {
103
+ return new Response(
104
+ JSON.stringify({ error: "Failed to upload attachment", status: response.status }),
105
+ { status: response.status, headers: { "Content-Type": "application/json" } }
106
+ );
107
+ }
108
+ const responseText = await response.text();
109
+ return new Response(responseText, {
110
+ status: 200,
111
+ headers: { "Content-Type": "application/json" }
112
+ });
113
+ } catch (error) {
114
+ console.error("AlquimiaProxy handleAttachment exception:", error);
115
+ return new Response(
116
+ JSON.stringify({ error: "Failed to forward attachment request" }),
117
+ { status: 500, headers: { "Content-Type": "application/json" } }
118
+ );
119
+ }
120
+ }
121
+ };
122
+ }
123
+ export {
124
+ createAlquimiaProxyHandler
125
+ };
126
+ //# sourceMappingURL=proxy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/proxy.ts"],"sourcesContent":["export interface ProxyConfig {\n assistantBaseUrl: string;\n apiKey: string;\n inferRoute?: string; // default: 'event/infer'\n streamRoute?: string; // default: 'event/stream'\n attachmentRoute?: string; // default: 'event/attachment'\n}\n\nexport interface AlquimiaProxyHandler {\n handleInfer(request: Request, pathSuffix: string): Promise<Response>;\n handleStream(request: Request, pathSuffix: string): Promise<Response>;\n handleAttachment(request: Request, streamId: string, attachmentId: string): Promise<Response>;\n}\n\nexport function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler {\n const baseUrl = config.assistantBaseUrl.replace(/\\/$/, '');\n const inferRoute = config.inferRoute ?? 'event/infer';\n const streamRoute = config.streamRoute ?? 'event/stream';\n const attachmentRoute = config.attachmentRoute ?? 'event/attachment';\n const authHeader = { Authorization: `Bearer ${config.apiKey}` };\n\n return {\n async handleInfer(request: Request, pathSuffix: string): Promise<Response> {\n try {\n const body = await request.json();\n const url = new URL(request.url);\n const querySuffix = url.searchParams.toString()\n ? `?${url.searchParams.toString()}`\n : '';\n const targetUrl = `${baseUrl}/${inferRoute}/${pathSuffix}${querySuffix}`;\n\n const response = await fetch(targetUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...authHeader },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorJson = await response.json().catch(() => ({}));\n console.error('AlquimiaProxy handleInfer error:', {\n status: response.status,\n statusText: response.statusText,\n body: errorJson,\n });\n return new Response(\n JSON.stringify({\n status: response.status,\n statusText: response.statusText,\n ...errorJson,\n }),\n { status: response.status, headers: { 'Content-Type': 'application/json' } }\n );\n }\n\n return new Response(response.body, {\n status: 200,\n headers: {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'POST, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Content-Encoding',\n },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleInfer exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward infer request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n\n async handleStream(request: Request, pathSuffix: string): Promise<Response> {\n try {\n const targetUrl = `${baseUrl}/${streamRoute}/${pathSuffix}`;\n\n const response = await fetch(targetUrl, {\n headers: { 'Content-Type': 'application/json', ...authHeader },\n });\n\n if (!response.ok) {\n const errorJson = await response.json().catch(() => ({}));\n console.error('AlquimiaProxy handleStream error:', {\n status: response.status,\n statusText: response.statusText,\n body: errorJson,\n });\n return new Response(\n JSON.stringify({\n error: errorJson.message || response.statusText || 'Failed to forward stream',\n ...errorJson,\n }),\n { status: response.status, headers: { 'Content-Type': 'application/json' } }\n );\n }\n\n return new Response(response.body, {\n status: 200,\n headers: {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache',\n Connection: 'keep-alive',\n },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleStream exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward stream request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n\n async handleAttachment(\n request: Request,\n streamId: string,\n attachmentId: string\n ): Promise<Response> {\n try {\n const targetUrl = `${baseUrl}/${attachmentRoute}/${streamId}/${attachmentId}`;\n const contentType = request.headers.get('Content-Type') ?? '';\n\n const response = await fetch(targetUrl, {\n method: 'POST',\n headers: {\n ...authHeader,\n ...(contentType && { 'Content-Type': contentType }),\n },\n body: request.body,\n duplex: 'half',\n } as RequestInit);\n\n if (!response.ok) {\n return new Response(\n JSON.stringify({ error: 'Failed to upload attachment', status: response.status }),\n { status: response.status, headers: { 'Content-Type': 'application/json' } }\n );\n }\n\n const responseText = await response.text();\n return new Response(responseText, {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleAttachment exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward attachment request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n };\n}\n"],"mappings":";AAcO,SAAS,2BAA2B,QAA2C;AACpF,QAAM,UAAU,OAAO,iBAAiB,QAAQ,OAAO,EAAE;AACzD,QAAM,aAAa,OAAO,cAAc;AACxC,QAAM,cAAc,OAAO,eAAe;AAC1C,QAAM,kBAAkB,OAAO,mBAAmB;AAClD,QAAM,aAAa,EAAE,eAAe,UAAU,OAAO,MAAM,GAAG;AAE9D,SAAO;AAAA,IACL,MAAM,YAAY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W;AAAA,UACtC,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,GAAG;AAAA,YACH,GAAI,eAAe,EAAE,gBAAgB,YAAY;AAAA,UACnD;AAAA,UACA,MAAM,QAAQ;AAAA,UACd,QAAQ;AAAA,QACV,CAAgB;AAEhB,YAAI,CAAC,SAAS,IAAI;AAChB,iBAAO,IAAI;AAAA,YACT,KAAK,UAAU,EAAE,OAAO,+BAA+B,QAAQ,SAAS,OAAO,CAAC;AAAA,YAChF,EAAE,QAAQ,SAAS,QAAQ,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,UAC7E;AAAA,QACF;AAEA,cAAM,eAAe,MAAM,SAAS,KAAK;AACzC,eAAO,IAAI,SAAS,cAAc;AAAA,UAChC,QAAQ;AAAA,UACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,QAChD,CAAC;AAAA,MACH,SAAS,OAAO;AACd,gBAAQ,MAAM,6CAA6C,KAAK;AAChE,eAAO,IAAI;AAAA,UACT,KAAK,UAAU,EAAE,OAAO,uCAAuC,CAAC;AAAA,UAChE,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,17 +1,12 @@
1
1
  import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-0Gi78uNQ.mjs';
2
2
  import { AttachmentPayload, TTSResult } from '../types/index.mjs';
3
+ import { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters/index.mjs';
3
4
  import '@elastic/apm-rum';
4
5
  import 'ai';
5
6
 
6
- interface AlquimiaSDKConfig {
7
- apiKey: string;
8
- chatUrl: string;
9
- streamUrl: string;
10
- attachmentUrl: string;
11
- assistantId: string;
12
- }
13
7
  declare class AlquimiaSDK {
14
- private config;
8
+ private adapter;
9
+ private assistantId;
15
10
  private axiosInstance;
16
11
  private conversationId;
17
12
  private sessionId;
@@ -30,25 +25,24 @@ declare class AlquimiaSDK {
30
25
  private enforceCharacterization?;
31
26
  private attachments;
32
27
  private attachmentResponses;
33
- constructor(config: AlquimiaSDKConfig, enforceCharacterization?: boolean);
34
- static configure(apiKey: string, inferUrl: string, streamUrl: string, attachmentUrl: string, assistantId: string): AlquimiaSDKConfig;
35
- widthConversationId(conversationId: string): AlquimiaSDK;
28
+ constructor(assistantId: string, adapter: AlquimiaAdapter, options?: AlquimiaSDKOptions);
29
+ withConversationId(conversationId: string): AlquimiaSDK;
36
30
  withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK;
37
31
  withWhisperProvider(provider: WhisperProvider): AlquimiaSDK;
38
32
  withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK;
39
33
  withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK;
40
34
  withRatingsProvider(provider: RatingsProvider): AlquimiaSDK;
41
35
  withLoggerProvider(provider: LoggerProvider): AlquimiaSDK;
42
- getEnforceCharacterization(): boolean;
43
- getEvaluationStrategy(): string | null;
44
36
  withTools(tools: any): AlquimiaSDK;
45
37
  withExtraData(extraData: any): AlquimiaSDK;
46
38
  withForceProfile(forceProfile: any): AlquimiaSDK;
47
39
  withAssistantConfig(assistantConfig: any): AlquimiaSDK;
48
40
  withUserId(userId: string): AlquimiaSDK;
41
+ getEnforceCharacterization(): boolean;
42
+ getEvaluationStrategy(): string | null;
49
43
  textToSpeech(text: string): Promise<TTSResult>;
50
44
  speechToText(audio: string): Promise<string>;
51
- sendMessage(query: string, traceParent?: string): Promise<this>;
45
+ sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK>;
52
46
  generateImage(query: string): Promise<string>;
53
47
  analyzeCharacterization(text: string): Promise<Record<string, any>>;
54
48
  rate(data: any): Promise<Record<string, any>>;
@@ -1,17 +1,12 @@
1
1
  import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-BJTXCtI3.js';
2
2
  import { AttachmentPayload, TTSResult } from '../types/index.js';
3
+ import { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters/index.js';
3
4
  import '@elastic/apm-rum';
4
5
  import 'ai';
5
6
 
6
- interface AlquimiaSDKConfig {
7
- apiKey: string;
8
- chatUrl: string;
9
- streamUrl: string;
10
- attachmentUrl: string;
11
- assistantId: string;
12
- }
13
7
  declare class AlquimiaSDK {
14
- private config;
8
+ private adapter;
9
+ private assistantId;
15
10
  private axiosInstance;
16
11
  private conversationId;
17
12
  private sessionId;
@@ -30,25 +25,24 @@ declare class AlquimiaSDK {
30
25
  private enforceCharacterization?;
31
26
  private attachments;
32
27
  private attachmentResponses;
33
- constructor(config: AlquimiaSDKConfig, enforceCharacterization?: boolean);
34
- static configure(apiKey: string, inferUrl: string, streamUrl: string, attachmentUrl: string, assistantId: string): AlquimiaSDKConfig;
35
- widthConversationId(conversationId: string): AlquimiaSDK;
28
+ constructor(assistantId: string, adapter: AlquimiaAdapter, options?: AlquimiaSDKOptions);
29
+ withConversationId(conversationId: string): AlquimiaSDK;
36
30
  withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK;
37
31
  withWhisperProvider(provider: WhisperProvider): AlquimiaSDK;
38
32
  withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK;
39
33
  withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK;
40
34
  withRatingsProvider(provider: RatingsProvider): AlquimiaSDK;
41
35
  withLoggerProvider(provider: LoggerProvider): AlquimiaSDK;
42
- getEnforceCharacterization(): boolean;
43
- getEvaluationStrategy(): string | null;
44
36
  withTools(tools: any): AlquimiaSDK;
45
37
  withExtraData(extraData: any): AlquimiaSDK;
46
38
  withForceProfile(forceProfile: any): AlquimiaSDK;
47
39
  withAssistantConfig(assistantConfig: any): AlquimiaSDK;
48
40
  withUserId(userId: string): AlquimiaSDK;
41
+ getEnforceCharacterization(): boolean;
42
+ getEvaluationStrategy(): string | null;
49
43
  textToSpeech(text: string): Promise<TTSResult>;
50
44
  speechToText(audio: string): Promise<string>;
51
- sendMessage(query: string, traceParent?: string): Promise<this>;
45
+ sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK>;
52
46
  generateImage(query: string): Promise<string>;
53
47
  analyzeCharacterization(text: string): Promise<Record<string, any>>;
54
48
  rate(data: any): Promise<Record<string, any>>;
package/dist/sdk/index.js CHANGED
@@ -37,7 +37,7 @@ module.exports = __toCommonJS(sdk_exports);
37
37
  // src/sdk/alquimia-sdk.ts
38
38
  var import_axios = __toESM(require("axios"));
39
39
  var AlquimiaSDK = class {
40
- constructor(config, enforceCharacterization = true) {
40
+ constructor(assistantId, adapter, options = {}) {
41
41
  this.conversationId = null;
42
42
  this.sessionId = null;
43
43
  this.streamId = null;
@@ -49,26 +49,29 @@ var AlquimiaSDK = class {
49
49
  this.userId = null;
50
50
  this.attachments = [];
51
51
  this.attachmentResponses = [];
52
- this.config = config;
53
- this.enforceCharacterization = enforceCharacterization;
52
+ if (!assistantId) {
53
+ throw new Error("AlquimiaSDK: assistantId is required");
54
+ }
55
+ if (!adapter) {
56
+ throw new Error(
57
+ "AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()"
58
+ );
59
+ }
60
+ this.assistantId = assistantId;
61
+ this.adapter = adapter;
62
+ this.enforceCharacterization = options.enforceCharacterization ?? true;
54
63
  this.axiosInstance = import_axios.default.create();
55
64
  this.axiosInstance.interceptors.response.use(
56
65
  (response) => response,
57
66
  async (error) => {
58
- if (error.response?.status) {
59
- if (this.loggerProvider) {
60
- await this.loggerProvider.logError(
61
- "Server Error",
62
- error,
63
- {
64
- url: error.config.url,
65
- method: error.config.method,
66
- data: error.config.data,
67
- status: error.response.status,
68
- responseData: error.response.data
69
- }
70
- );
71
- }
67
+ if (error.response?.status && this.loggerProvider) {
68
+ await this.loggerProvider.logError("Server Error", error, {
69
+ url: error.config.url,
70
+ method: error.config.method,
71
+ data: error.config.data,
72
+ status: error.response.status,
73
+ responseData: error.response.data
74
+ });
72
75
  }
73
76
  return Promise.reject(error);
74
77
  }
@@ -76,16 +79,7 @@ var AlquimiaSDK = class {
76
79
  this.textToSpeech = this.textToSpeech.bind(this);
77
80
  this.speechToText = this.speechToText.bind(this);
78
81
  }
79
- static configure(apiKey, inferUrl, streamUrl, attachmentUrl, assistantId) {
80
- return {
81
- apiKey,
82
- chatUrl: `${inferUrl}/chat/${assistantId}`,
83
- streamUrl: `${streamUrl}`,
84
- attachmentUrl,
85
- assistantId
86
- };
87
- }
88
- widthConversationId(conversationId) {
82
+ withConversationId(conversationId) {
89
83
  this.conversationId = conversationId;
90
84
  return this;
91
85
  }
@@ -113,12 +107,6 @@ var AlquimiaSDK = class {
113
107
  this.loggerProvider = provider;
114
108
  return this;
115
109
  }
116
- getEnforceCharacterization() {
117
- return this.enforceCharacterization ?? true;
118
- }
119
- getEvaluationStrategy() {
120
- return this.evaluationStrategy;
121
- }
122
110
  withTools(tools) {
123
111
  this.tools = tools;
124
112
  return this;
@@ -139,6 +127,12 @@ var AlquimiaSDK = class {
139
127
  this.userId = userId;
140
128
  return this;
141
129
  }
130
+ getEnforceCharacterization() {
131
+ return this.enforceCharacterization ?? true;
132
+ }
133
+ getEvaluationStrategy() {
134
+ return this.evaluationStrategy;
135
+ }
142
136
  textToSpeech(text) {
143
137
  if (!this.whisperProvider) {
144
138
  throw new Error("Whisper provider not initialized");
@@ -153,8 +147,12 @@ var AlquimiaSDK = class {
153
147
  }
154
148
  async sendMessage(query, traceParent) {
155
149
  if (!this.conversationId) {
156
- throw new Error("Conversation not initialized");
150
+ throw new Error(
151
+ "Conversation not initialized. Call withConversationId() before sendMessage()"
152
+ );
157
153
  }
154
+ const inferUrl = this.adapter.resolveInferUrl(this.assistantId);
155
+ const adapterHeaders = this.adapter.getHeaders?.() ?? {};
158
156
  const initMessage = {
159
157
  query,
160
158
  session_id: this.conversationId,
@@ -165,13 +163,14 @@ var AlquimiaSDK = class {
165
163
  user_id: this.userId,
166
164
  attachments: this.attachments
167
165
  };
168
- const result = (await this.axiosInstance.post(this.config.chatUrl, initMessage, {
166
+ const result = (await this.axiosInstance.post(inferUrl, initMessage, {
169
167
  headers: {
170
168
  "Content-Type": "application/json",
171
- "x-trace-parent": traceParent || ""
169
+ "x-trace-parent": traceParent || "",
170
+ ...adapterHeaders
172
171
  }
173
172
  })).data;
174
- this.evaluationStrategy = result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id || null;
173
+ this.evaluationStrategy = result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id ?? null;
175
174
  this.streamId = result.stream_id;
176
175
  this.attachmentResponses = result.attachments ?? [];
177
176
  this.attachments = [];
@@ -185,25 +184,25 @@ var AlquimiaSDK = class {
185
184
  }
186
185
  async analyzeCharacterization(text) {
187
186
  if (!this.analyzeCharacterizationProvider) {
188
- throw new Error("analyze characterization provider not initialized");
187
+ throw new Error("Analyze characterization provider not initialized");
189
188
  }
190
189
  return this.analyzeCharacterizationProvider.analyzeCharacterization(text);
191
190
  }
192
191
  async rate(data) {
193
192
  if (!this.ratingsProvider) {
194
- throw new Error("ratings provider not initialized");
193
+ throw new Error("Ratings provider not initialized");
195
194
  }
196
195
  return this.ratingsProvider.rate(data);
197
196
  }
198
197
  async logInfo(message, data) {
199
198
  if (!this.loggerProvider) {
200
- throw new Error("logger provider not initialized");
199
+ throw new Error("Logger provider not initialized");
201
200
  }
202
201
  return this.loggerProvider.logInfo(message, data);
203
202
  }
204
203
  async logError(message, error, data) {
205
204
  if (!this.loggerProvider) {
206
- throw new Error("logger provider not initialized");
205
+ throw new Error("Logger provider not initialized");
207
206
  }
208
207
  return this.loggerProvider.logError(message, error, data);
209
208
  }
@@ -211,21 +210,22 @@ var AlquimiaSDK = class {
211
210
  return this.attachmentResponses;
212
211
  }
213
212
  async uploadAttachment(file, attachmentId) {
214
- if (!this.config.attachmentUrl) {
215
- throw new Error("Attachment URL not configured");
216
- }
217
213
  if (!this.streamId || !attachmentId) {
218
214
  throw new Error("Stream or attachment ID not initialized");
219
215
  }
220
- const url = `${this.config.attachmentUrl}/${this.streamId}/${attachmentId}`;
216
+ const url = this.adapter.resolveAttachmentUrl(this.streamId, attachmentId);
217
+ const adapterHeaders = this.adapter.getHeaders?.() ?? {};
221
218
  const formData = new FormData();
222
219
  formData.append("file", file);
223
220
  await this.axiosInstance.post(url, formData, {
224
- headers: { "Content-Type": "multipart/form-data" }
221
+ headers: { "Content-Type": "multipart/form-data", ...adapterHeaders }
225
222
  });
226
223
  }
227
224
  getUrlStream() {
228
- return `${this.config.streamUrl}/${this.streamId}`;
225
+ if (!this.streamId) {
226
+ throw new Error("Stream ID not initialized. Call sendMessage() first");
227
+ }
228
+ return this.adapter.resolveStreamUrl(this.streamId);
229
229
  }
230
230
  getStreamId() {
231
231
  return this.streamId;