@alquimia-ai/tools 1.13.2 → 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 -17
- package/dist/actions/index.d.ts +2 -17
- package/dist/actions/index.js +47 -152
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/index.mjs +47 -152
- package/dist/actions/index.mjs.map +1 -1
- package/dist/adapters/fetch.d.mts +12 -0
- package/dist/adapters/fetch.d.ts +12 -0
- package/dist/adapters/fetch.js +44 -0
- package/dist/adapters/fetch.js.map +1 -0
- package/dist/adapters/fetch.mjs +23 -0
- package/dist/adapters/fetch.mjs.map +1 -0
- package/dist/adapters/index.d.mts +11 -0
- package/dist/adapters/index.d.ts +11 -0
- package/dist/adapters/index.js +19 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +1 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/adapters/next.d.mts +10 -0
- package/dist/adapters/next.d.ts +10 -0
- package/dist/adapters/next.js +42 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/next.mjs +21 -0
- package/dist/adapters/next.mjs.map +1 -0
- package/dist/hooks/index.d.mts +23 -4
- package/dist/hooks/index.d.ts +23 -4
- package/dist/hooks/index.js +292 -57
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +283 -58
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.d.mts +46 -0
- package/dist/next/index.d.ts +46 -0
- package/dist/next/index.js +337 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/index.mjs +314 -0
- package/dist/next/index.mjs.map +1 -0
- package/dist/providers/index.d.mts +7 -3
- package/dist/providers/index.d.ts +7 -3
- package/dist/providers/index.js +15 -14
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +15 -14
- package/dist/providers/index.mjs.map +1 -1
- package/dist/proxy.d.mts +15 -0
- package/dist/proxy.d.ts +15 -0
- package/dist/proxy.js +170 -0
- package/dist/proxy.js.map +1 -0
- package/dist/proxy.mjs +149 -0
- package/dist/proxy.mjs.map +1 -0
- package/dist/sdk/index.d.mts +22 -20
- package/dist/sdk/index.d.ts +22 -20
- package/dist/sdk/index.js +85 -66
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +85 -66
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/services/index.d.mts +25 -3
- package/dist/services/index.d.ts +25 -3
- 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 +35 -5
- package/dist/providers/elastic/index.d.mts +0 -23
- package/dist/providers/elastic/index.d.ts +0 -23
- package/dist/providers/elastic/index.js +0 -102
- package/dist/providers/elastic/index.js.map +0 -1
- package/dist/providers/elastic/index.mjs +0 -69
- package/dist/providers/elastic/index.mjs.map +0 -1
- package/dist/services/apm/index.d.mts +0 -26
- package/dist/services/apm/index.d.ts +0 -26
- package/dist/services/apm/index.js +0 -86
- package/dist/services/apm/index.js.map +0 -1
- package/dist/services/apm/index.mjs +0 -63
- package/dist/services/apm/index.mjs.map +0 -1
package/dist/proxy.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface ProxyConfig {
|
|
2
|
+
assistantBaseUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
inferRoute?: string;
|
|
5
|
+
streamRoute?: string;
|
|
6
|
+
blobUploadRoute?: string;
|
|
7
|
+
}
|
|
8
|
+
interface AlquimiaProxyHandler {
|
|
9
|
+
handleInfer(request: Request, pathSuffix: string): Promise<Response>;
|
|
10
|
+
handleStream(request: Request, pathSuffix: string): Promise<Response>;
|
|
11
|
+
handleBlobUpload(request: Request): Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
declare function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler;
|
|
14
|
+
|
|
15
|
+
export { type AlquimiaProxyHandler, type ProxyConfig, createAlquimiaProxyHandler };
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface ProxyConfig {
|
|
2
|
+
assistantBaseUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
inferRoute?: string;
|
|
5
|
+
streamRoute?: string;
|
|
6
|
+
blobUploadRoute?: string;
|
|
7
|
+
}
|
|
8
|
+
interface AlquimiaProxyHandler {
|
|
9
|
+
handleInfer(request: Request, pathSuffix: string): Promise<Response>;
|
|
10
|
+
handleStream(request: Request, pathSuffix: string): Promise<Response>;
|
|
11
|
+
handleBlobUpload(request: Request): 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,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/proxy.ts
|
|
21
|
+
var proxy_exports = {};
|
|
22
|
+
__export(proxy_exports, {
|
|
23
|
+
createAlquimiaProxyHandler: () => createAlquimiaProxyHandler
|
|
24
|
+
});
|
|
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
|
+
}
|
|
44
|
+
function createAlquimiaProxyHandler(config) {
|
|
45
|
+
const baseUrl = config.assistantBaseUrl.replace(/\/$/, "");
|
|
46
|
+
const inferRoute = config.inferRoute ?? "event/infer";
|
|
47
|
+
const streamRoute = config.streamRoute ?? "event/stream";
|
|
48
|
+
const blobUploadRoute = config.blobUploadRoute ?? "context/blob/upload";
|
|
49
|
+
const authHeader = { Authorization: `Bearer ${config.apiKey}` };
|
|
50
|
+
return {
|
|
51
|
+
async handleInfer(request, pathSuffix) {
|
|
52
|
+
try {
|
|
53
|
+
const body = await request.json();
|
|
54
|
+
const url = new URL(request.url);
|
|
55
|
+
const querySuffix = url.searchParams.toString() ? `?${url.searchParams.toString()}` : "";
|
|
56
|
+
const slug = pathSuffix.replace(/^\/+|\/+$/g, "");
|
|
57
|
+
const targetUrl = `${baseUrl}/${inferRoute}/${slug}${querySuffix}`;
|
|
58
|
+
const response = await fetch(targetUrl, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
...authHeader
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify(body)
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const errorJson = await response.json().catch(() => ({}));
|
|
68
|
+
console.error("AlquimiaProxy handleInfer error:", {
|
|
69
|
+
status: response.status,
|
|
70
|
+
statusText: response.statusText,
|
|
71
|
+
body: errorJson
|
|
72
|
+
});
|
|
73
|
+
return new Response(
|
|
74
|
+
JSON.stringify({
|
|
75
|
+
status: response.status,
|
|
76
|
+
statusText: response.statusText,
|
|
77
|
+
...errorJson
|
|
78
|
+
}),
|
|
79
|
+
{ status: response.status, headers: { "Content-Type": "application/json" } }
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return new Response(response.body, {
|
|
83
|
+
status: 200,
|
|
84
|
+
headers: {
|
|
85
|
+
"Access-Control-Allow-Origin": "*",
|
|
86
|
+
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
87
|
+
"Access-Control-Allow-Headers": "Content-Type, Content-Encoding"
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error("AlquimiaProxy handleInfer exception:", error);
|
|
92
|
+
return new Response(
|
|
93
|
+
JSON.stringify({ error: "Failed to forward infer request" }),
|
|
94
|
+
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
async handleStream(request, pathSuffix) {
|
|
99
|
+
try {
|
|
100
|
+
const targetUrl = `${baseUrl}/${streamRoute}/${pathSuffix}`;
|
|
101
|
+
const response = await fetch(targetUrl, {
|
|
102
|
+
headers: { "Content-Type": "application/json", ...authHeader }
|
|
103
|
+
});
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
const errorJson = await response.json().catch(() => ({}));
|
|
106
|
+
console.error("AlquimiaProxy handleStream error:", {
|
|
107
|
+
status: response.status,
|
|
108
|
+
statusText: response.statusText,
|
|
109
|
+
body: errorJson
|
|
110
|
+
});
|
|
111
|
+
return new Response(
|
|
112
|
+
JSON.stringify({
|
|
113
|
+
error: errorJson.message || response.statusText || "Failed to forward stream",
|
|
114
|
+
...errorJson
|
|
115
|
+
}),
|
|
116
|
+
{ status: response.status, headers: { "Content-Type": "application/json" } }
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return new Response(response.body, {
|
|
120
|
+
status: 200,
|
|
121
|
+
headers: {
|
|
122
|
+
"Content-Type": "text/event-stream",
|
|
123
|
+
"Cache-Control": "no-cache",
|
|
124
|
+
Connection: "keep-alive"
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error("AlquimiaProxy handleStream exception:", error);
|
|
129
|
+
return new Response(
|
|
130
|
+
JSON.stringify({ error: "Failed to forward stream request" }),
|
|
131
|
+
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
async handleBlobUpload(request) {
|
|
136
|
+
try {
|
|
137
|
+
const targetUrl = `${baseUrl}/${blobUploadRoute}`;
|
|
138
|
+
const contentType = request.headers.get("Content-Type") ?? "";
|
|
139
|
+
const response = await fetch(targetUrl, {
|
|
140
|
+
method: "POST",
|
|
141
|
+
headers: {
|
|
142
|
+
...authHeader,
|
|
143
|
+
...contentType && { "Content-Type": contentType },
|
|
144
|
+
...pickIdentityHeaders(request)
|
|
145
|
+
},
|
|
146
|
+
body: request.body,
|
|
147
|
+
duplex: "half"
|
|
148
|
+
});
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
return new Response(
|
|
151
|
+
JSON.stringify({ error: "Failed to upload blob", status: response.status }),
|
|
152
|
+
{ status: response.status, headers: { "Content-Type": "application/json" } }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const responseText = await response.text();
|
|
156
|
+
return new Response(responseText, {
|
|
157
|
+
status: 200,
|
|
158
|
+
headers: { "Content-Type": "application/json" }
|
|
159
|
+
});
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error("AlquimiaProxy handleBlobUpload exception:", error);
|
|
162
|
+
return new Response(
|
|
163
|
+
JSON.stringify({ error: "Failed to forward blob upload request" }),
|
|
164
|
+
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//# 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 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,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M,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,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
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
}
|
|
20
|
+
function createAlquimiaProxyHandler(config) {
|
|
21
|
+
const baseUrl = config.assistantBaseUrl.replace(/\/$/, "");
|
|
22
|
+
const inferRoute = config.inferRoute ?? "event/infer";
|
|
23
|
+
const streamRoute = config.streamRoute ?? "event/stream";
|
|
24
|
+
const blobUploadRoute = config.blobUploadRoute ?? "context/blob/upload";
|
|
25
|
+
const authHeader = { Authorization: `Bearer ${config.apiKey}` };
|
|
26
|
+
return {
|
|
27
|
+
async handleInfer(request, pathSuffix) {
|
|
28
|
+
try {
|
|
29
|
+
const body = await request.json();
|
|
30
|
+
const url = new URL(request.url);
|
|
31
|
+
const querySuffix = url.searchParams.toString() ? `?${url.searchParams.toString()}` : "";
|
|
32
|
+
const slug = pathSuffix.replace(/^\/+|\/+$/g, "");
|
|
33
|
+
const targetUrl = `${baseUrl}/${inferRoute}/${slug}${querySuffix}`;
|
|
34
|
+
const response = await fetch(targetUrl, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
...authHeader
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify(body)
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
const errorJson = await response.json().catch(() => ({}));
|
|
44
|
+
console.error("AlquimiaProxy handleInfer error:", {
|
|
45
|
+
status: response.status,
|
|
46
|
+
statusText: response.statusText,
|
|
47
|
+
body: errorJson
|
|
48
|
+
});
|
|
49
|
+
return new Response(
|
|
50
|
+
JSON.stringify({
|
|
51
|
+
status: response.status,
|
|
52
|
+
statusText: response.statusText,
|
|
53
|
+
...errorJson
|
|
54
|
+
}),
|
|
55
|
+
{ status: response.status, headers: { "Content-Type": "application/json" } }
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return new Response(response.body, {
|
|
59
|
+
status: 200,
|
|
60
|
+
headers: {
|
|
61
|
+
"Access-Control-Allow-Origin": "*",
|
|
62
|
+
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
63
|
+
"Access-Control-Allow-Headers": "Content-Type, Content-Encoding"
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error("AlquimiaProxy handleInfer exception:", error);
|
|
68
|
+
return new Response(
|
|
69
|
+
JSON.stringify({ error: "Failed to forward infer request" }),
|
|
70
|
+
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
async handleStream(request, pathSuffix) {
|
|
75
|
+
try {
|
|
76
|
+
const targetUrl = `${baseUrl}/${streamRoute}/${pathSuffix}`;
|
|
77
|
+
const response = await fetch(targetUrl, {
|
|
78
|
+
headers: { "Content-Type": "application/json", ...authHeader }
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
const errorJson = await response.json().catch(() => ({}));
|
|
82
|
+
console.error("AlquimiaProxy handleStream error:", {
|
|
83
|
+
status: response.status,
|
|
84
|
+
statusText: response.statusText,
|
|
85
|
+
body: errorJson
|
|
86
|
+
});
|
|
87
|
+
return new Response(
|
|
88
|
+
JSON.stringify({
|
|
89
|
+
error: errorJson.message || response.statusText || "Failed to forward stream",
|
|
90
|
+
...errorJson
|
|
91
|
+
}),
|
|
92
|
+
{ status: response.status, headers: { "Content-Type": "application/json" } }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return new Response(response.body, {
|
|
96
|
+
status: 200,
|
|
97
|
+
headers: {
|
|
98
|
+
"Content-Type": "text/event-stream",
|
|
99
|
+
"Cache-Control": "no-cache",
|
|
100
|
+
Connection: "keep-alive"
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error("AlquimiaProxy handleStream exception:", error);
|
|
105
|
+
return new Response(
|
|
106
|
+
JSON.stringify({ error: "Failed to forward stream request" }),
|
|
107
|
+
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
async handleBlobUpload(request) {
|
|
112
|
+
try {
|
|
113
|
+
const targetUrl = `${baseUrl}/${blobUploadRoute}`;
|
|
114
|
+
const contentType = request.headers.get("Content-Type") ?? "";
|
|
115
|
+
const response = await fetch(targetUrl, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
...authHeader,
|
|
119
|
+
...contentType && { "Content-Type": contentType },
|
|
120
|
+
...pickIdentityHeaders(request)
|
|
121
|
+
},
|
|
122
|
+
body: request.body,
|
|
123
|
+
duplex: "half"
|
|
124
|
+
});
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
return new Response(
|
|
127
|
+
JSON.stringify({ error: "Failed to upload blob", status: response.status }),
|
|
128
|
+
{ status: response.status, headers: { "Content-Type": "application/json" } }
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const responseText = await response.text();
|
|
132
|
+
return new Response(responseText, {
|
|
133
|
+
status: 200,
|
|
134
|
+
headers: { "Content-Type": "application/json" }
|
|
135
|
+
});
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.error("AlquimiaProxy handleBlobUpload exception:", error);
|
|
138
|
+
return new Response(
|
|
139
|
+
JSON.stringify({ error: "Failed to forward blob upload request" }),
|
|
140
|
+
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
createAlquimiaProxyHandler
|
|
148
|
+
};
|
|
149
|
+
//# 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 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":";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;AAE9D,SAAO;AAAA,IACL,MAAM,YAAY,SAAkB,YAAuC;AACzE,UAAI;AACF,cAAM,OAAO,MAAM,QAAQ,KAAK;AAChC,cAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,cAAM,cAAc,IAAI,aAAa,SAAS,IAC1C,IAAI,IAAI,aAAa,SAAS,CAAC,KAC/B;AACJ,cAAM,OAAO,WAAW,QAAQ,cAAc,EAAE;AAChD,cAAM,YAAY,GAAG,OAAO,IAAI,UAAU,IAAI,IAAI,GAAG,WAAW;AAGhE,cAAM,WAAW,MAAM,MAAM,WAAW;AAAA,UACtC,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,gBAAgB;AAAA,YAChB,GAAG;AAAA,UACL;AAAA,UACA,MAAM,KAAK,UAAU,IAAI;AAAA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e,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/sdk/index.d.mts
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
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
|
|
8
|
+
private adapter;
|
|
9
|
+
private assistantId;
|
|
15
10
|
private axiosInstance;
|
|
16
11
|
private conversationId;
|
|
17
12
|
private sessionId;
|
|
18
13
|
private streamId;
|
|
19
|
-
private evaluationStrategy;
|
|
20
14
|
private tools;
|
|
21
|
-
private
|
|
15
|
+
private extraInstructions;
|
|
22
16
|
private assistantConfig;
|
|
23
|
-
private forceProfile;
|
|
24
17
|
private userId;
|
|
25
18
|
private whisperProvider?;
|
|
26
19
|
private stableDiffusionProvider?;
|
|
@@ -30,34 +23,43 @@ declare class AlquimiaSDK {
|
|
|
30
23
|
private enforceCharacterization?;
|
|
31
24
|
private attachments;
|
|
32
25
|
private attachmentResponses;
|
|
33
|
-
constructor(
|
|
34
|
-
|
|
35
|
-
widthConversationId(conversationId: string): AlquimiaSDK;
|
|
26
|
+
constructor(assistantId: string, adapter: AlquimiaAdapter, options?: AlquimiaSDKOptions);
|
|
27
|
+
withConversationId(conversationId: string): AlquimiaSDK;
|
|
36
28
|
withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK;
|
|
37
29
|
withWhisperProvider(provider: WhisperProvider): AlquimiaSDK;
|
|
38
30
|
withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK;
|
|
39
31
|
withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK;
|
|
40
32
|
withRatingsProvider(provider: RatingsProvider): AlquimiaSDK;
|
|
41
33
|
withLoggerProvider(provider: LoggerProvider): AlquimiaSDK;
|
|
42
|
-
getEnforceCharacterization(): boolean;
|
|
43
|
-
getEvaluationStrategy(): string | null;
|
|
44
34
|
withTools(tools: any): AlquimiaSDK;
|
|
45
|
-
|
|
46
|
-
withForceProfile(forceProfile: any): AlquimiaSDK;
|
|
35
|
+
withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK;
|
|
47
36
|
withAssistantConfig(assistantConfig: any): AlquimiaSDK;
|
|
48
37
|
withUserId(userId: string): AlquimiaSDK;
|
|
38
|
+
getEnforceCharacterization(): boolean;
|
|
49
39
|
textToSpeech(text: string): Promise<TTSResult>;
|
|
50
40
|
speechToText(audio: string): Promise<string>;
|
|
51
|
-
sendMessage(query: string, traceParent?: string): Promise<
|
|
41
|
+
sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK>;
|
|
52
42
|
generateImage(query: string): Promise<string>;
|
|
53
43
|
analyzeCharacterization(text: string): Promise<Record<string, any>>;
|
|
54
44
|
rate(data: any): Promise<Record<string, any>>;
|
|
55
45
|
logInfo(message: string, data: any): Promise<void>;
|
|
56
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
|
+
*/
|
|
57
52
|
getAttachmentResponses(): string[];
|
|
58
|
-
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;
|
|
59
59
|
getUrlStream(): string;
|
|
60
60
|
getStreamId(): string | null;
|
|
61
|
+
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
62
|
+
getTaskId(): string | null;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
export { AlquimiaSDK };
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
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
|
|
8
|
+
private adapter;
|
|
9
|
+
private assistantId;
|
|
15
10
|
private axiosInstance;
|
|
16
11
|
private conversationId;
|
|
17
12
|
private sessionId;
|
|
18
13
|
private streamId;
|
|
19
|
-
private evaluationStrategy;
|
|
20
14
|
private tools;
|
|
21
|
-
private
|
|
15
|
+
private extraInstructions;
|
|
22
16
|
private assistantConfig;
|
|
23
|
-
private forceProfile;
|
|
24
17
|
private userId;
|
|
25
18
|
private whisperProvider?;
|
|
26
19
|
private stableDiffusionProvider?;
|
|
@@ -30,34 +23,43 @@ declare class AlquimiaSDK {
|
|
|
30
23
|
private enforceCharacterization?;
|
|
31
24
|
private attachments;
|
|
32
25
|
private attachmentResponses;
|
|
33
|
-
constructor(
|
|
34
|
-
|
|
35
|
-
widthConversationId(conversationId: string): AlquimiaSDK;
|
|
26
|
+
constructor(assistantId: string, adapter: AlquimiaAdapter, options?: AlquimiaSDKOptions);
|
|
27
|
+
withConversationId(conversationId: string): AlquimiaSDK;
|
|
36
28
|
withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK;
|
|
37
29
|
withWhisperProvider(provider: WhisperProvider): AlquimiaSDK;
|
|
38
30
|
withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK;
|
|
39
31
|
withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK;
|
|
40
32
|
withRatingsProvider(provider: RatingsProvider): AlquimiaSDK;
|
|
41
33
|
withLoggerProvider(provider: LoggerProvider): AlquimiaSDK;
|
|
42
|
-
getEnforceCharacterization(): boolean;
|
|
43
|
-
getEvaluationStrategy(): string | null;
|
|
44
34
|
withTools(tools: any): AlquimiaSDK;
|
|
45
|
-
|
|
46
|
-
withForceProfile(forceProfile: any): AlquimiaSDK;
|
|
35
|
+
withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK;
|
|
47
36
|
withAssistantConfig(assistantConfig: any): AlquimiaSDK;
|
|
48
37
|
withUserId(userId: string): AlquimiaSDK;
|
|
38
|
+
getEnforceCharacterization(): boolean;
|
|
49
39
|
textToSpeech(text: string): Promise<TTSResult>;
|
|
50
40
|
speechToText(audio: string): Promise<string>;
|
|
51
|
-
sendMessage(query: string, traceParent?: string): Promise<
|
|
41
|
+
sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK>;
|
|
52
42
|
generateImage(query: string): Promise<string>;
|
|
53
43
|
analyzeCharacterization(text: string): Promise<Record<string, any>>;
|
|
54
44
|
rate(data: any): Promise<Record<string, any>>;
|
|
55
45
|
logInfo(message: string, data: any): Promise<void>;
|
|
56
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
|
+
*/
|
|
57
52
|
getAttachmentResponses(): string[];
|
|
58
|
-
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;
|
|
59
59
|
getUrlStream(): string;
|
|
60
60
|
getStreamId(): string | null;
|
|
61
|
+
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
62
|
+
getTaskId(): string | null;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
export { AlquimiaSDK };
|