@alquimia-ai/tools 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.d.mts +2 -7
- package/dist/actions/index.d.ts +2 -7
- package/dist/actions/index.js +10 -8
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/index.mjs +10 -8
- package/dist/actions/index.mjs.map +1 -1
- package/dist/adapters/fetch.d.mts +1 -1
- package/dist/adapters/fetch.d.ts +1 -1
- package/dist/adapters/fetch.js +3 -3
- package/dist/adapters/fetch.js.map +1 -1
- package/dist/adapters/fetch.mjs +3 -3
- package/dist/adapters/fetch.mjs.map +1 -1
- package/dist/adapters/index.d.mts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/next.d.mts +1 -1
- package/dist/adapters/next.d.ts +1 -1
- package/dist/adapters/next.js +4 -4
- package/dist/adapters/next.js.map +1 -1
- package/dist/adapters/next.mjs +4 -4
- package/dist/adapters/next.mjs.map +1 -1
- package/dist/hooks/index.d.mts +2 -3
- package/dist/hooks/index.d.ts +2 -3
- package/dist/hooks/index.js +77 -45
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +77 -45
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.d.mts +6 -9
- package/dist/next/index.d.ts +6 -9
- package/dist/next/index.js +69 -64
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +69 -64
- package/dist/next/index.mjs.map +1 -1
- package/dist/proxy.d.mts +2 -2
- package/dist/proxy.d.ts +2 -2
- package/dist/proxy.js +32 -9
- package/dist/proxy.js.map +1 -1
- package/dist/proxy.mjs +32 -9
- package/dist/proxy.mjs.map +1 -1
- package/dist/sdk/index.d.mts +15 -7
- package/dist/sdk/index.d.ts +15 -7
- package/dist/sdk/index.js +45 -26
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +45 -26
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/session.action-DirvOWt0.d.mts +3 -0
- package/dist/session.action-DirvOWt0.d.ts +3 -0
- package/dist/types/index.d.mts +79 -18
- package/dist/types/index.d.ts +79 -18
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/proxy.js
CHANGED
|
@@ -23,11 +23,29 @@ __export(proxy_exports, {
|
|
|
23
23
|
createAlquimiaProxyHandler: () => createAlquimiaProxyHandler
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(proxy_exports);
|
|
26
|
+
var IDENTITY_HEADER_NAMES = [
|
|
27
|
+
"task-id",
|
|
28
|
+
"parent-task-id",
|
|
29
|
+
"session-id",
|
|
30
|
+
"user-id",
|
|
31
|
+
"assistant-id",
|
|
32
|
+
"agentspace-id",
|
|
33
|
+
"channel-id",
|
|
34
|
+
"depth"
|
|
35
|
+
];
|
|
36
|
+
function pickIdentityHeaders(request) {
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const name of IDENTITY_HEADER_NAMES) {
|
|
39
|
+
const value = request.headers.get(name);
|
|
40
|
+
if (value) out[name] = value;
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
26
44
|
function createAlquimiaProxyHandler(config) {
|
|
27
45
|
const baseUrl = config.assistantBaseUrl.replace(/\/$/, "");
|
|
28
46
|
const inferRoute = config.inferRoute ?? "event/infer";
|
|
29
47
|
const streamRoute = config.streamRoute ?? "event/stream";
|
|
30
|
-
const
|
|
48
|
+
const blobUploadRoute = config.blobUploadRoute ?? "context/blob/upload";
|
|
31
49
|
const authHeader = { Authorization: `Bearer ${config.apiKey}` };
|
|
32
50
|
return {
|
|
33
51
|
async handleInfer(request, pathSuffix) {
|
|
@@ -35,10 +53,14 @@ function createAlquimiaProxyHandler(config) {
|
|
|
35
53
|
const body = await request.json();
|
|
36
54
|
const url = new URL(request.url);
|
|
37
55
|
const querySuffix = url.searchParams.toString() ? `?${url.searchParams.toString()}` : "";
|
|
38
|
-
const
|
|
56
|
+
const slug = pathSuffix.replace(/^\/+|\/+$/g, "");
|
|
57
|
+
const targetUrl = `${baseUrl}/${inferRoute}/${slug}${querySuffix}`;
|
|
39
58
|
const response = await fetch(targetUrl, {
|
|
40
59
|
method: "POST",
|
|
41
|
-
headers: {
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
...authHeader
|
|
63
|
+
},
|
|
42
64
|
body: JSON.stringify(body)
|
|
43
65
|
});
|
|
44
66
|
if (!response.ok) {
|
|
@@ -110,22 +132,23 @@ function createAlquimiaProxyHandler(config) {
|
|
|
110
132
|
);
|
|
111
133
|
}
|
|
112
134
|
},
|
|
113
|
-
async
|
|
135
|
+
async handleBlobUpload(request) {
|
|
114
136
|
try {
|
|
115
|
-
const targetUrl = `${baseUrl}/${
|
|
137
|
+
const targetUrl = `${baseUrl}/${blobUploadRoute}`;
|
|
116
138
|
const contentType = request.headers.get("Content-Type") ?? "";
|
|
117
139
|
const response = await fetch(targetUrl, {
|
|
118
140
|
method: "POST",
|
|
119
141
|
headers: {
|
|
120
142
|
...authHeader,
|
|
121
|
-
...contentType && { "Content-Type": contentType }
|
|
143
|
+
...contentType && { "Content-Type": contentType },
|
|
144
|
+
...pickIdentityHeaders(request)
|
|
122
145
|
},
|
|
123
146
|
body: request.body,
|
|
124
147
|
duplex: "half"
|
|
125
148
|
});
|
|
126
149
|
if (!response.ok) {
|
|
127
150
|
return new Response(
|
|
128
|
-
JSON.stringify({ error: "Failed to upload
|
|
151
|
+
JSON.stringify({ error: "Failed to upload blob", status: response.status }),
|
|
129
152
|
{ status: response.status, headers: { "Content-Type": "application/json" } }
|
|
130
153
|
);
|
|
131
154
|
}
|
|
@@ -135,9 +158,9 @@ function createAlquimiaProxyHandler(config) {
|
|
|
135
158
|
headers: { "Content-Type": "application/json" }
|
|
136
159
|
});
|
|
137
160
|
} catch (error) {
|
|
138
|
-
console.error("AlquimiaProxy
|
|
161
|
+
console.error("AlquimiaProxy handleBlobUpload exception:", error);
|
|
139
162
|
return new Response(
|
|
140
|
-
JSON.stringify({ error: "Failed to forward
|
|
163
|
+
JSON.stringify({ error: "Failed to forward blob upload request" }),
|
|
141
164
|
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
142
165
|
);
|
|
143
166
|
}
|
package/dist/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/proxy.ts"],"sourcesContent":["export interface ProxyConfig {\n assistantBaseUrl: string;\n apiKey: string;\n inferRoute?: string;
|
|
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 blobUploadRoute?: string; // default: 'context/blob/upload'\n}\n\nexport interface AlquimiaProxyHandler {\n handleInfer(request: Request, pathSuffix: string): Promise<Response>;\n handleStream(request: Request, pathSuffix: string): Promise<Response>;\n handleBlobUpload(request: Request): Promise<Response>;\n}\n\nconst IDENTITY_HEADER_NAMES = [\n 'task-id',\n 'parent-task-id',\n 'session-id',\n 'user-id',\n 'assistant-id',\n 'agentspace-id',\n 'channel-id',\n 'depth',\n] as const;\n\nfunction pickIdentityHeaders(request: Request): Record<string, string> {\n const out: Record<string, string> = {};\n for (const name of IDENTITY_HEADER_NAMES) {\n const value = request.headers.get(name);\n if (value) out[name] = value;\n }\n return out;\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 blobUploadRoute = config.blobUploadRoute ?? 'context/blob/upload';\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 slug = pathSuffix.replace(/^\\/+|\\/+$/g, '');\n const targetUrl = `${baseUrl}/${inferRoute}/${slug}${querySuffix}`;\n\n\n const response = await fetch(targetUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...authHeader,\n },\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 handleBlobUpload(request: Request): Promise<Response> {\n try {\n const targetUrl = `${baseUrl}/${blobUploadRoute}`;\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 ...pickIdentityHeaders(request),\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 blob', 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 handleBlobUpload exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward blob upload request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,IAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,oBAAoB,SAA0C;AACrE,QAAM,MAA8B,CAAC;AACrC,aAAW,QAAQ,uBAAuB;AACxC,UAAM,QAAQ,QAAQ,QAAQ,IAAI,IAAI;AACtC,QAAI,MAAO,KAAI,IAAI,IAAI;AAAA,EACzB;AACA,SAAO;AACT;AAEO,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;AAE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,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,YACjD,GAAG,oBAAoB,OAAO;AAAA,UAChC;AAAA,UACA,MAAM,QAAQ;AAAA,UACd,QAAQ;AAAA,QACV,CAAgB;AAEhB,YAAI,CAAC,SAAS,IAAI;AAChB,iBAAO,IAAI;AAAA,YACT,KAAK,UAAU,EAAE,OAAO,yBAAyB,QAAQ,SAAS,OAAO,CAAC;AAAA,YAC1E,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,wCAAwC,CAAC;AAAA,UACjE,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/proxy.mjs
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
// src/proxy.ts
|
|
2
|
+
var IDENTITY_HEADER_NAMES = [
|
|
3
|
+
"task-id",
|
|
4
|
+
"parent-task-id",
|
|
5
|
+
"session-id",
|
|
6
|
+
"user-id",
|
|
7
|
+
"assistant-id",
|
|
8
|
+
"agentspace-id",
|
|
9
|
+
"channel-id",
|
|
10
|
+
"depth"
|
|
11
|
+
];
|
|
12
|
+
function pickIdentityHeaders(request) {
|
|
13
|
+
const out = {};
|
|
14
|
+
for (const name of IDENTITY_HEADER_NAMES) {
|
|
15
|
+
const value = request.headers.get(name);
|
|
16
|
+
if (value) out[name] = value;
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
2
20
|
function createAlquimiaProxyHandler(config) {
|
|
3
21
|
const baseUrl = config.assistantBaseUrl.replace(/\/$/, "");
|
|
4
22
|
const inferRoute = config.inferRoute ?? "event/infer";
|
|
5
23
|
const streamRoute = config.streamRoute ?? "event/stream";
|
|
6
|
-
const
|
|
24
|
+
const blobUploadRoute = config.blobUploadRoute ?? "context/blob/upload";
|
|
7
25
|
const authHeader = { Authorization: `Bearer ${config.apiKey}` };
|
|
8
26
|
return {
|
|
9
27
|
async handleInfer(request, pathSuffix) {
|
|
@@ -11,10 +29,14 @@ function createAlquimiaProxyHandler(config) {
|
|
|
11
29
|
const body = await request.json();
|
|
12
30
|
const url = new URL(request.url);
|
|
13
31
|
const querySuffix = url.searchParams.toString() ? `?${url.searchParams.toString()}` : "";
|
|
14
|
-
const
|
|
32
|
+
const slug = pathSuffix.replace(/^\/+|\/+$/g, "");
|
|
33
|
+
const targetUrl = `${baseUrl}/${inferRoute}/${slug}${querySuffix}`;
|
|
15
34
|
const response = await fetch(targetUrl, {
|
|
16
35
|
method: "POST",
|
|
17
|
-
headers: {
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
...authHeader
|
|
39
|
+
},
|
|
18
40
|
body: JSON.stringify(body)
|
|
19
41
|
});
|
|
20
42
|
if (!response.ok) {
|
|
@@ -86,22 +108,23 @@ function createAlquimiaProxyHandler(config) {
|
|
|
86
108
|
);
|
|
87
109
|
}
|
|
88
110
|
},
|
|
89
|
-
async
|
|
111
|
+
async handleBlobUpload(request) {
|
|
90
112
|
try {
|
|
91
|
-
const targetUrl = `${baseUrl}/${
|
|
113
|
+
const targetUrl = `${baseUrl}/${blobUploadRoute}`;
|
|
92
114
|
const contentType = request.headers.get("Content-Type") ?? "";
|
|
93
115
|
const response = await fetch(targetUrl, {
|
|
94
116
|
method: "POST",
|
|
95
117
|
headers: {
|
|
96
118
|
...authHeader,
|
|
97
|
-
...contentType && { "Content-Type": contentType }
|
|
119
|
+
...contentType && { "Content-Type": contentType },
|
|
120
|
+
...pickIdentityHeaders(request)
|
|
98
121
|
},
|
|
99
122
|
body: request.body,
|
|
100
123
|
duplex: "half"
|
|
101
124
|
});
|
|
102
125
|
if (!response.ok) {
|
|
103
126
|
return new Response(
|
|
104
|
-
JSON.stringify({ error: "Failed to upload
|
|
127
|
+
JSON.stringify({ error: "Failed to upload blob", status: response.status }),
|
|
105
128
|
{ status: response.status, headers: { "Content-Type": "application/json" } }
|
|
106
129
|
);
|
|
107
130
|
}
|
|
@@ -111,9 +134,9 @@ function createAlquimiaProxyHandler(config) {
|
|
|
111
134
|
headers: { "Content-Type": "application/json" }
|
|
112
135
|
});
|
|
113
136
|
} catch (error) {
|
|
114
|
-
console.error("AlquimiaProxy
|
|
137
|
+
console.error("AlquimiaProxy handleBlobUpload exception:", error);
|
|
115
138
|
return new Response(
|
|
116
|
-
JSON.stringify({ error: "Failed to forward
|
|
139
|
+
JSON.stringify({ error: "Failed to forward blob upload request" }),
|
|
117
140
|
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
118
141
|
);
|
|
119
142
|
}
|
package/dist/proxy.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/proxy.ts"],"sourcesContent":["export interface ProxyConfig {\n assistantBaseUrl: string;\n apiKey: string;\n inferRoute?: string;
|
|
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 blobUploadRoute?: string; // default: 'context/blob/upload'\n}\n\nexport interface AlquimiaProxyHandler {\n handleInfer(request: Request, pathSuffix: string): Promise<Response>;\n handleStream(request: Request, pathSuffix: string): Promise<Response>;\n handleBlobUpload(request: Request): Promise<Response>;\n}\n\nconst IDENTITY_HEADER_NAMES = [\n 'task-id',\n 'parent-task-id',\n 'session-id',\n 'user-id',\n 'assistant-id',\n 'agentspace-id',\n 'channel-id',\n 'depth',\n] as const;\n\nfunction pickIdentityHeaders(request: Request): Record<string, string> {\n const out: Record<string, string> = {};\n for (const name of IDENTITY_HEADER_NAMES) {\n const value = request.headers.get(name);\n if (value) out[name] = value;\n }\n return out;\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 blobUploadRoute = config.blobUploadRoute ?? 'context/blob/upload';\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 slug = pathSuffix.replace(/^\\/+|\\/+$/g, '');\n const targetUrl = `${baseUrl}/${inferRoute}/${slug}${querySuffix}`;\n\n\n const response = await fetch(targetUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...authHeader,\n },\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 handleBlobUpload(request: Request): Promise<Response> {\n try {\n const targetUrl = `${baseUrl}/${blobUploadRoute}`;\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 ...pickIdentityHeaders(request),\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 blob', 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 handleBlobUpload exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward blob upload request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n };\n}\n"],"mappings":";AA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A,UACT,KAAK,UAAU,EAAE,OAAO,wCAAwC,CAAC;AAAA,UACjE,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/sdk/index.d.mts
CHANGED
|
@@ -11,11 +11,9 @@ declare class AlquimiaSDK {
|
|
|
11
11
|
private conversationId;
|
|
12
12
|
private sessionId;
|
|
13
13
|
private streamId;
|
|
14
|
-
private evaluationStrategy;
|
|
15
14
|
private tools;
|
|
16
|
-
private
|
|
15
|
+
private extraInstructions;
|
|
17
16
|
private assistantConfig;
|
|
18
|
-
private forceProfile;
|
|
19
17
|
private userId;
|
|
20
18
|
private whisperProvider?;
|
|
21
19
|
private stableDiffusionProvider?;
|
|
@@ -34,12 +32,10 @@ declare class AlquimiaSDK {
|
|
|
34
32
|
withRatingsProvider(provider: RatingsProvider): AlquimiaSDK;
|
|
35
33
|
withLoggerProvider(provider: LoggerProvider): AlquimiaSDK;
|
|
36
34
|
withTools(tools: any): AlquimiaSDK;
|
|
37
|
-
|
|
38
|
-
withForceProfile(forceProfile: any): AlquimiaSDK;
|
|
35
|
+
withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK;
|
|
39
36
|
withAssistantConfig(assistantConfig: any): AlquimiaSDK;
|
|
40
37
|
withUserId(userId: string): AlquimiaSDK;
|
|
41
38
|
getEnforceCharacterization(): boolean;
|
|
42
|
-
getEvaluationStrategy(): string | null;
|
|
43
39
|
textToSpeech(text: string): Promise<TTSResult>;
|
|
44
40
|
speechToText(audio: string): Promise<string>;
|
|
45
41
|
sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK>;
|
|
@@ -48,10 +44,22 @@ declare class AlquimiaSDK {
|
|
|
48
44
|
rate(data: any): Promise<Record<string, any>>;
|
|
49
45
|
logInfo(message: string, data: any): Promise<void>;
|
|
50
46
|
logError(message: string, error: Error, data: any): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated The runtime no longer returns attachment IDs from the infer
|
|
49
|
+
* response — attachments are uploaded as standalone blobs and linked to the
|
|
50
|
+
* session via headers. Always returns `[]`; kept for source compatibility.
|
|
51
|
+
*/
|
|
51
52
|
getAttachmentResponses(): string[];
|
|
52
|
-
uploadAttachment(file: File,
|
|
53
|
+
uploadAttachment(file: File, _attachmentId?: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
56
|
+
* the rest of the runtime's internal endpoints introduced in v0.2.0→next.
|
|
57
|
+
*/
|
|
58
|
+
private buildIdentityHeaders;
|
|
53
59
|
getUrlStream(): string;
|
|
54
60
|
getStreamId(): string | null;
|
|
61
|
+
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
62
|
+
getTaskId(): string | null;
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
export { AlquimiaSDK };
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -11,11 +11,9 @@ declare class AlquimiaSDK {
|
|
|
11
11
|
private conversationId;
|
|
12
12
|
private sessionId;
|
|
13
13
|
private streamId;
|
|
14
|
-
private evaluationStrategy;
|
|
15
14
|
private tools;
|
|
16
|
-
private
|
|
15
|
+
private extraInstructions;
|
|
17
16
|
private assistantConfig;
|
|
18
|
-
private forceProfile;
|
|
19
17
|
private userId;
|
|
20
18
|
private whisperProvider?;
|
|
21
19
|
private stableDiffusionProvider?;
|
|
@@ -34,12 +32,10 @@ declare class AlquimiaSDK {
|
|
|
34
32
|
withRatingsProvider(provider: RatingsProvider): AlquimiaSDK;
|
|
35
33
|
withLoggerProvider(provider: LoggerProvider): AlquimiaSDK;
|
|
36
34
|
withTools(tools: any): AlquimiaSDK;
|
|
37
|
-
|
|
38
|
-
withForceProfile(forceProfile: any): AlquimiaSDK;
|
|
35
|
+
withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK;
|
|
39
36
|
withAssistantConfig(assistantConfig: any): AlquimiaSDK;
|
|
40
37
|
withUserId(userId: string): AlquimiaSDK;
|
|
41
38
|
getEnforceCharacterization(): boolean;
|
|
42
|
-
getEvaluationStrategy(): string | null;
|
|
43
39
|
textToSpeech(text: string): Promise<TTSResult>;
|
|
44
40
|
speechToText(audio: string): Promise<string>;
|
|
45
41
|
sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK>;
|
|
@@ -48,10 +44,22 @@ declare class AlquimiaSDK {
|
|
|
48
44
|
rate(data: any): Promise<Record<string, any>>;
|
|
49
45
|
logInfo(message: string, data: any): Promise<void>;
|
|
50
46
|
logError(message: string, error: Error, data: any): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated The runtime no longer returns attachment IDs from the infer
|
|
49
|
+
* response — attachments are uploaded as standalone blobs and linked to the
|
|
50
|
+
* session via headers. Always returns `[]`; kept for source compatibility.
|
|
51
|
+
*/
|
|
51
52
|
getAttachmentResponses(): string[];
|
|
52
|
-
uploadAttachment(file: File,
|
|
53
|
+
uploadAttachment(file: File, _attachmentId?: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
56
|
+
* the rest of the runtime's internal endpoints introduced in v0.2.0→next.
|
|
57
|
+
*/
|
|
58
|
+
private buildIdentityHeaders;
|
|
53
59
|
getUrlStream(): string;
|
|
54
60
|
getStreamId(): string | null;
|
|
61
|
+
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
62
|
+
getTaskId(): string | null;
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
export { AlquimiaSDK };
|
package/dist/sdk/index.js
CHANGED
|
@@ -40,12 +40,11 @@ var AlquimiaSDK = class {
|
|
|
40
40
|
constructor(assistantId, adapter, options = {}) {
|
|
41
41
|
this.conversationId = null;
|
|
42
42
|
this.sessionId = null;
|
|
43
|
+
// Internal subscription id from infer (`taskid` on the wire).
|
|
43
44
|
this.streamId = null;
|
|
44
|
-
this.evaluationStrategy = null;
|
|
45
45
|
this.tools = [];
|
|
46
|
-
this.
|
|
46
|
+
this.extraInstructions = null;
|
|
47
47
|
this.assistantConfig = null;
|
|
48
|
-
this.forceProfile = {};
|
|
49
48
|
this.userId = null;
|
|
50
49
|
this.attachments = [];
|
|
51
50
|
this.attachmentResponses = [];
|
|
@@ -111,12 +110,8 @@ var AlquimiaSDK = class {
|
|
|
111
110
|
this.tools = tools;
|
|
112
111
|
return this;
|
|
113
112
|
}
|
|
114
|
-
|
|
115
|
-
this.
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
withForceProfile(forceProfile) {
|
|
119
|
-
this.forceProfile = forceProfile;
|
|
113
|
+
withExtraInstructions(extraInstructions) {
|
|
114
|
+
this.extraInstructions = extraInstructions;
|
|
120
115
|
return this;
|
|
121
116
|
}
|
|
122
117
|
withAssistantConfig(assistantConfig) {
|
|
@@ -130,9 +125,6 @@ var AlquimiaSDK = class {
|
|
|
130
125
|
getEnforceCharacterization() {
|
|
131
126
|
return this.enforceCharacterization ?? true;
|
|
132
127
|
}
|
|
133
|
-
getEvaluationStrategy() {
|
|
134
|
-
return this.evaluationStrategy;
|
|
135
|
-
}
|
|
136
128
|
textToSpeech(text) {
|
|
137
129
|
if (!this.whisperProvider) {
|
|
138
130
|
throw new Error("Whisper provider not initialized");
|
|
@@ -153,25 +145,29 @@ var AlquimiaSDK = class {
|
|
|
153
145
|
}
|
|
154
146
|
const inferUrl = this.adapter.resolveInferUrl(this.assistantId);
|
|
155
147
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
148
|
+
const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;
|
|
156
149
|
const initMessage = {
|
|
157
150
|
query,
|
|
158
151
|
session_id: this.conversationId,
|
|
159
|
-
...this.extraData && { extra_data: this.extraData },
|
|
160
|
-
force_profile: this.forceProfile,
|
|
161
|
-
...this.assistantConfig && { config: this.assistantConfig },
|
|
162
|
-
tools: this.tools,
|
|
163
152
|
user_id: this.userId,
|
|
164
|
-
|
|
153
|
+
...this.extraInstructions && { extra_instructions: this.extraInstructions },
|
|
154
|
+
...this.assistantConfig && { config: this.assistantConfig },
|
|
155
|
+
...hasClientTools && {
|
|
156
|
+
evaluation_strategy: {
|
|
157
|
+
evaluation_strategy_id: "native",
|
|
158
|
+
tool_schemas: this.tools
|
|
159
|
+
}
|
|
160
|
+
}
|
|
165
161
|
};
|
|
166
162
|
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
167
163
|
headers: {
|
|
168
164
|
"Content-Type": "application/json",
|
|
169
165
|
"x-trace-parent": traceParent || "",
|
|
170
|
-
...adapterHeaders
|
|
166
|
+
...adapterHeaders,
|
|
167
|
+
...this.buildIdentityHeaders()
|
|
171
168
|
}
|
|
172
169
|
})).data;
|
|
173
|
-
this.
|
|
174
|
-
this.streamId = result.stream_id;
|
|
170
|
+
this.streamId = result.taskid ?? null;
|
|
175
171
|
this.attachmentResponses = result.attachments ?? [];
|
|
176
172
|
this.attachments = [];
|
|
177
173
|
return this;
|
|
@@ -206,21 +202,40 @@ var AlquimiaSDK = class {
|
|
|
206
202
|
}
|
|
207
203
|
return this.loggerProvider.logError(message, error, data);
|
|
208
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated The runtime no longer returns attachment IDs from the infer
|
|
207
|
+
* response — attachments are uploaded as standalone blobs and linked to the
|
|
208
|
+
* session via headers. Always returns `[]`; kept for source compatibility.
|
|
209
|
+
*/
|
|
209
210
|
getAttachmentResponses() {
|
|
210
211
|
return this.attachmentResponses;
|
|
211
212
|
}
|
|
212
|
-
async uploadAttachment(file,
|
|
213
|
-
|
|
214
|
-
throw new Error("Stream or attachment ID not initialized");
|
|
215
|
-
}
|
|
216
|
-
const url = this.adapter.resolveAttachmentUrl(this.streamId, attachmentId);
|
|
213
|
+
async uploadAttachment(file, _attachmentId) {
|
|
214
|
+
const url = this.adapter.resolveBlobUploadUrl();
|
|
217
215
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
218
216
|
const formData = new FormData();
|
|
219
217
|
formData.append("file", file);
|
|
220
218
|
await this.axiosInstance.post(url, formData, {
|
|
221
|
-
headers: {
|
|
219
|
+
headers: {
|
|
220
|
+
"Content-Type": "multipart/form-data",
|
|
221
|
+
...adapterHeaders,
|
|
222
|
+
...this.buildIdentityHeaders()
|
|
223
|
+
}
|
|
222
224
|
});
|
|
223
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
228
|
+
* the rest of the runtime's internal endpoints introduced in v0.2.0→next.
|
|
229
|
+
*/
|
|
230
|
+
buildIdentityHeaders() {
|
|
231
|
+
const headers = {
|
|
232
|
+
"assistant-id": this.assistantId
|
|
233
|
+
};
|
|
234
|
+
if (this.conversationId) headers["session-id"] = this.conversationId;
|
|
235
|
+
if (this.userId) headers["user-id"] = this.userId;
|
|
236
|
+
if (this.streamId) headers["task-id"] = this.streamId;
|
|
237
|
+
return headers;
|
|
238
|
+
}
|
|
224
239
|
getUrlStream() {
|
|
225
240
|
if (!this.streamId) {
|
|
226
241
|
throw new Error("Stream ID not initialized. Call sendMessage() first");
|
|
@@ -230,6 +245,10 @@ var AlquimiaSDK = class {
|
|
|
230
245
|
getStreamId() {
|
|
231
246
|
return this.streamId;
|
|
232
247
|
}
|
|
248
|
+
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
249
|
+
getTaskId() {
|
|
250
|
+
return this.streamId;
|
|
251
|
+
}
|
|
233
252
|
};
|
|
234
253
|
var alquimia_sdk_default = AlquimiaSDK;
|
|
235
254
|
//# sourceMappingURL=index.js.map
|
package/dist/sdk/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sdk/index.ts","../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["export { default as AlquimiaSDK } from './alquimia-sdk';","import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n private streamId: string | null = null;\n private evaluationStrategy: string | null = null;\n private tools: any = [];\n private extraData: any = null;\n private assistantConfig: any = null;\n private forceProfile: any = {};\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraData(extraData: any): AlquimiaSDK {\n this.extraData = extraData;\n return this;\n }\n\n withForceProfile(forceProfile: any): AlquimiaSDK {\n this.forceProfile = forceProfile;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n getEvaluationStrategy(): string | null {\n return this.evaluationStrategy;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const initMessage = {\n query,\n session_id: this.conversationId,\n ...(this.extraData && { extra_data: this.extraData }),\n force_profile: this.forceProfile,\n ...(this.assistantConfig && { config: this.assistantConfig }),\n tools: this.tools,\n user_id: this.userId,\n attachments: this.attachments,\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n },\n })\n ).data;\n\n this.evaluationStrategy =\n result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id ?? null;\n this.streamId = result.stream_id;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, attachmentId: string): Promise<void> {\n if (!this.streamId || !attachmentId) {\n throw new Error('Stream or attachment ID not initialized');\n }\n const url = this.adapter.resolveAttachmentUrl(this.streamId, attachmentId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: { 'Content-Type': 'multipart/form-data', ...adapterHeaders },\n });\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUr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sdk/index.ts","../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["export { default as AlquimiaSDK } from './alquimia-sdk';","import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult, type CommonAttributes } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n // Internal subscription id from infer (`taskid` on the wire).\n private streamId: string | null = null;\n private tools: any = [];\n private extraInstructions: Record<string, string> | null = null;\n private assistantConfig: any = null;\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK {\n this.extraInstructions = extraInstructions;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;\n\n const initMessage: Record<string, unknown> = {\n query,\n session_id: this.conversationId,\n user_id: this.userId,\n ...(this.extraInstructions && { extra_instructions: this.extraInstructions }),\n ...(this.assistantConfig && { config: this.assistantConfig }),\n ...(hasClientTools && {\n evaluation_strategy: {\n evaluation_strategy_id: 'native',\n tool_schemas: this.tools,\n },\n }),\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.streamId = result.taskid ?? null;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n /**\n * @deprecated The runtime no longer returns attachment IDs from the infer\n * response — attachments are uploaded as standalone blobs and linked to the\n * session via headers. Always returns `[]`; kept for source compatibility.\n */\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, _attachmentId?: string): Promise<void> {\n void _attachmentId;\n const url = this.adapter.resolveBlobUploadUrl();\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n }\n\n /**\n * Identity headers (kebab-case) required by `/context/blob/upload` and\n * the rest of the runtime's internal endpoints introduced in v0.2.0→next.\n */\n private buildIdentityHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n 'assistant-id': this.assistantId,\n };\n if (this.conversationId) headers['session-id'] = this.conversationId;\n if (this.userId) headers['user-id'] = this.userId;\n if (this.streamId) headers['task-id'] = this.streamId;\n return headers;\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n\n /** Alias for {@link getStreamId} — same value as infer `taskid`. */\n getTaskId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;AAWrC,IAAM,cAAN,MAAkB;AAAA,EAqBhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AArBF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AAEnC;AAAA,SAAQ,WAA0B;AAClC,SAAQ,QAAa,CAAC;AACtB,SAAQ,oBAAmD;AAC3D,SAAQ,kBAAuB;AAC/B,SAAQ,SAAwB;AAOhC,SAAQ,cAAmC,CAAC;AAC5C,SAAQ,sBAAgC,CAAC;AAOvC,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,sCAAsC;AAAA,IACxD;AACA,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,cAAc;AACnB,SAAK,UAAU;AACf,SAAK,0BAA0B,QAAQ,2BAA2B;AAElE,SAAK,g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