@alquimia-ai/tools 2.4.0 → 2.7.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/README.md +529 -19
- package/dist/actions/index.d.mts +2 -2
- package/dist/actions/index.d.ts +2 -2
- package/dist/actions/index.js +1 -1
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/index.mjs +1 -1
- package/dist/actions/index.mjs.map +1 -1
- package/dist/{actions-CZU_GRy5.d.mts → actions-BjDPJdyA.d.mts} +1 -1
- package/dist/{actions-B0hfoYRd.d.ts → actions-CP1d4Ye1.d.ts} +1 -1
- package/dist/adapters/index.d.mts +2 -2
- package/dist/adapters/index.d.ts +2 -2
- package/dist/adapters/index.js.map +1 -1
- package/dist/genui/index.d.mts +3 -3
- package/dist/genui/index.d.ts +3 -3
- package/dist/genui/index.js +9 -1
- package/dist/genui/index.js.map +1 -1
- package/dist/genui/index.mjs +9 -1
- package/dist/genui/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +10 -10
- package/dist/hooks/index.d.ts +10 -10
- package/dist/hooks/index.js +88 -12
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +88 -12
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.js +23 -6
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +23 -6
- package/dist/next/index.mjs.map +1 -1
- package/dist/providers/index.d.mts +4 -4
- package/dist/providers/index.d.ts +4 -4
- package/dist/providers/index.js +111 -110
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +111 -110
- package/dist/providers/index.mjs.map +1 -1
- package/dist/{providers-BJTXCtI3.d.ts → providers-B4IOiGfr.d.mts} +8 -8
- package/dist/{providers-0Gi78uNQ.d.mts → providers-mx21gNgZ.d.ts} +8 -8
- package/dist/proxy.d.mts +4 -4
- package/dist/proxy.d.ts +4 -4
- package/dist/proxy.js +23 -6
- package/dist/proxy.js.map +1 -1
- package/dist/proxy.mjs +23 -6
- package/dist/proxy.mjs.map +1 -1
- package/dist/sdk/index.d.mts +39 -5
- package/dist/sdk/index.d.ts +39 -5
- package/dist/sdk/index.js +49 -6
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +49 -6
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/services/index.d.mts +3 -3
- package/dist/services/index.d.ts +3 -3
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs.map +1 -1
- package/dist/type-61gaZga-.d.mts +356 -0
- package/dist/type-D-JaSMkV.d.ts +356 -0
- package/dist/types/index.d.mts +80 -304
- package/dist/types/index.d.ts +80 -304
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/{types-DnfWUE9V.d.mts → types-CMVbyEv8.d.mts} +3 -2
- package/dist/{types-DnfWUE9V.d.ts → types-CMVbyEv8.d.ts} +3 -2
- package/dist/types-lOliroPw.d.mts +111 -0
- package/dist/types-lOliroPw.d.ts +111 -0
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/worklog/index.d.mts +5 -2
- package/dist/worklog/index.d.ts +5 -2
- package/dist/worklog/index.js +22 -1
- package/dist/worklog/index.js.map +1 -1
- package/dist/worklog/index.mjs +22 -1
- package/dist/worklog/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/types-Dvu9y4WM.d.mts +0 -53
- package/dist/types-Dvu9y4WM.d.ts +0 -53
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TTSResult } from './
|
|
1
|
+
import { T as TTSResult } from './type-61gaZga-.mjs';
|
|
2
2
|
|
|
3
3
|
declare abstract class GenerativeProvider {
|
|
4
4
|
private config;
|
|
@@ -7,29 +7,29 @@ declare abstract class GenerativeProvider {
|
|
|
7
7
|
declare abstract class WhisperProvider {
|
|
8
8
|
protected config: Record<string, any>;
|
|
9
9
|
constructor(config: Record<string, any>);
|
|
10
|
-
abstract textToSpeech(
|
|
11
|
-
abstract speechToText(
|
|
10
|
+
abstract textToSpeech(_text: string): Promise<TTSResult>;
|
|
11
|
+
abstract speechToText(_audio: string): Promise<string>;
|
|
12
12
|
}
|
|
13
13
|
declare abstract class StableDiffusionProvider {
|
|
14
14
|
protected config: Record<string, any>;
|
|
15
15
|
constructor(config: Record<string, any>);
|
|
16
|
-
abstract generateImage(
|
|
16
|
+
abstract generateImage(_query: string): Promise<string>;
|
|
17
17
|
}
|
|
18
18
|
declare abstract class CharacterizationProvider {
|
|
19
19
|
protected config: Record<string, any>;
|
|
20
20
|
constructor(config: Record<string, any>);
|
|
21
|
-
abstract analyzeCharacterization(
|
|
21
|
+
abstract analyzeCharacterization(_text: string): Promise<Record<string, any>>;
|
|
22
22
|
}
|
|
23
23
|
declare abstract class RatingsProvider {
|
|
24
24
|
protected config: Record<string, any>;
|
|
25
25
|
constructor(config: Record<string, any>);
|
|
26
|
-
abstract rate(
|
|
26
|
+
abstract rate(_data: Record<string, any>): Promise<Record<string, any>>;
|
|
27
27
|
}
|
|
28
28
|
declare abstract class LoggerProvider {
|
|
29
29
|
protected config: Record<string, any>;
|
|
30
30
|
constructor(config: Record<string, any>);
|
|
31
|
-
abstract logInfo(
|
|
32
|
-
abstract logError(
|
|
31
|
+
abstract logInfo(_message: string, _data?: Record<string, any>): void;
|
|
32
|
+
abstract logError(_message: string, _error: Error, _data?: Record<string, any>): void;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export { CharacterizationProvider as C, GenerativeProvider as G, LoggerProvider as L, RatingsProvider as R, StableDiffusionProvider as S, WhisperProvider as W };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TTSResult } from './
|
|
1
|
+
import { T as TTSResult } from './type-D-JaSMkV.js';
|
|
2
2
|
|
|
3
3
|
declare abstract class GenerativeProvider {
|
|
4
4
|
private config;
|
|
@@ -7,29 +7,29 @@ declare abstract class GenerativeProvider {
|
|
|
7
7
|
declare abstract class WhisperProvider {
|
|
8
8
|
protected config: Record<string, any>;
|
|
9
9
|
constructor(config: Record<string, any>);
|
|
10
|
-
abstract textToSpeech(
|
|
11
|
-
abstract speechToText(
|
|
10
|
+
abstract textToSpeech(_text: string): Promise<TTSResult>;
|
|
11
|
+
abstract speechToText(_audio: string): Promise<string>;
|
|
12
12
|
}
|
|
13
13
|
declare abstract class StableDiffusionProvider {
|
|
14
14
|
protected config: Record<string, any>;
|
|
15
15
|
constructor(config: Record<string, any>);
|
|
16
|
-
abstract generateImage(
|
|
16
|
+
abstract generateImage(_query: string): Promise<string>;
|
|
17
17
|
}
|
|
18
18
|
declare abstract class CharacterizationProvider {
|
|
19
19
|
protected config: Record<string, any>;
|
|
20
20
|
constructor(config: Record<string, any>);
|
|
21
|
-
abstract analyzeCharacterization(
|
|
21
|
+
abstract analyzeCharacterization(_text: string): Promise<Record<string, any>>;
|
|
22
22
|
}
|
|
23
23
|
declare abstract class RatingsProvider {
|
|
24
24
|
protected config: Record<string, any>;
|
|
25
25
|
constructor(config: Record<string, any>);
|
|
26
|
-
abstract rate(
|
|
26
|
+
abstract rate(_data: Record<string, any>): Promise<Record<string, any>>;
|
|
27
27
|
}
|
|
28
28
|
declare abstract class LoggerProvider {
|
|
29
29
|
protected config: Record<string, any>;
|
|
30
30
|
constructor(config: Record<string, any>);
|
|
31
|
-
abstract logInfo(
|
|
32
|
-
abstract logError(
|
|
31
|
+
abstract logInfo(_message: string, _data?: Record<string, any>): void;
|
|
32
|
+
abstract logError(_message: string, _error: Error, _data?: Record<string, any>): void;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export { CharacterizationProvider as C, GenerativeProvider as G, LoggerProvider as L, RatingsProvider as R, StableDiffusionProvider as S, WhisperProvider as W };
|
package/dist/proxy.d.mts
CHANGED
|
@@ -7,10 +7,10 @@ interface ProxyConfig {
|
|
|
7
7
|
toolCompletionRoute?: string;
|
|
8
8
|
}
|
|
9
9
|
interface AlquimiaProxyHandler {
|
|
10
|
-
handleInfer(
|
|
11
|
-
handleStream(
|
|
12
|
-
handleBlobUpload(
|
|
13
|
-
handleToolCompletion(
|
|
10
|
+
handleInfer(_request: Request, _pathSuffix: string): Promise<Response>;
|
|
11
|
+
handleStream(_request: Request, _pathSuffix: string): Promise<Response>;
|
|
12
|
+
handleBlobUpload(_request: Request): Promise<Response>;
|
|
13
|
+
handleToolCompletion(_request: Request): Promise<Response>;
|
|
14
14
|
}
|
|
15
15
|
declare function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler;
|
|
16
16
|
|
package/dist/proxy.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ interface ProxyConfig {
|
|
|
7
7
|
toolCompletionRoute?: string;
|
|
8
8
|
}
|
|
9
9
|
interface AlquimiaProxyHandler {
|
|
10
|
-
handleInfer(
|
|
11
|
-
handleStream(
|
|
12
|
-
handleBlobUpload(
|
|
13
|
-
handleToolCompletion(
|
|
10
|
+
handleInfer(_request: Request, _pathSuffix: string): Promise<Response>;
|
|
11
|
+
handleStream(_request: Request, _pathSuffix: string): Promise<Response>;
|
|
12
|
+
handleBlobUpload(_request: Request): Promise<Response>;
|
|
13
|
+
handleToolCompletion(_request: Request): Promise<Response>;
|
|
14
14
|
}
|
|
15
15
|
declare function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler;
|
|
16
16
|
|
package/dist/proxy.js
CHANGED
|
@@ -41,6 +41,13 @@ function pickIdentityHeaders(request) {
|
|
|
41
41
|
}
|
|
42
42
|
return out;
|
|
43
43
|
}
|
|
44
|
+
function pickTraceHeader(request) {
|
|
45
|
+
const fromHeader = request.headers.get("x-trace-parent");
|
|
46
|
+
if (fromHeader) return { "x-trace-parent": fromHeader };
|
|
47
|
+
const fromQuery = new URL(request.url).searchParams.get("trace_parent");
|
|
48
|
+
if (fromQuery) return { "x-trace-parent": fromQuery };
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
44
51
|
function createAlquimiaProxyHandler(config) {
|
|
45
52
|
const baseUrl = config.assistantBaseUrl.replace(/\/$/, "");
|
|
46
53
|
const inferRoute = config.inferRoute ?? "event/infer";
|
|
@@ -60,7 +67,9 @@ function createAlquimiaProxyHandler(config) {
|
|
|
60
67
|
method: "POST",
|
|
61
68
|
headers: {
|
|
62
69
|
"Content-Type": "application/json",
|
|
63
|
-
...authHeader
|
|
70
|
+
...authHeader,
|
|
71
|
+
...pickIdentityHeaders(request),
|
|
72
|
+
...pickTraceHeader(request)
|
|
64
73
|
},
|
|
65
74
|
body: JSON.stringify(body)
|
|
66
75
|
});
|
|
@@ -100,7 +109,12 @@ function createAlquimiaProxyHandler(config) {
|
|
|
100
109
|
try {
|
|
101
110
|
const targetUrl = `${baseUrl}/${streamRoute}/${pathSuffix}`;
|
|
102
111
|
const response = await fetch(targetUrl, {
|
|
103
|
-
headers: {
|
|
112
|
+
headers: {
|
|
113
|
+
"Content-Type": "application/json",
|
|
114
|
+
...authHeader,
|
|
115
|
+
...pickIdentityHeaders(request),
|
|
116
|
+
...pickTraceHeader(request)
|
|
117
|
+
}
|
|
104
118
|
});
|
|
105
119
|
if (!response.ok) {
|
|
106
120
|
const errorJson = await response.json().catch(() => ({}));
|
|
@@ -142,7 +156,8 @@ function createAlquimiaProxyHandler(config) {
|
|
|
142
156
|
headers: {
|
|
143
157
|
...authHeader,
|
|
144
158
|
...contentType && { "Content-Type": contentType },
|
|
145
|
-
...pickIdentityHeaders(request)
|
|
159
|
+
...pickIdentityHeaders(request),
|
|
160
|
+
...pickTraceHeader(request)
|
|
146
161
|
},
|
|
147
162
|
body: request.body,
|
|
148
163
|
duplex: "half"
|
|
@@ -181,14 +196,16 @@ function createAlquimiaProxyHandler(config) {
|
|
|
181
196
|
"assistantid",
|
|
182
197
|
"agentspaceid",
|
|
183
198
|
"channelid",
|
|
184
|
-
"depth"
|
|
199
|
+
"depth",
|
|
200
|
+
// Runtime v0.5.1: `CommonAttributes.version_tag` (alias `versiontag`)
|
|
201
|
+
// pins the tool-completion to the agentspace version that ran the turn.
|
|
202
|
+
"versiontag"
|
|
185
203
|
];
|
|
186
204
|
for (const name of CORRELATION_HEADERS) {
|
|
187
205
|
const value = request.headers.get(name);
|
|
188
206
|
if (value) headers[name] = value;
|
|
189
207
|
}
|
|
190
|
-
|
|
191
|
-
if (trace) headers["x-trace-parent"] = trace;
|
|
208
|
+
Object.assign(headers, pickTraceHeader(request));
|
|
192
209
|
const response = await fetch(`${baseUrl}/${toolCompletionRoute}`, {
|
|
193
210
|
method: "POST",
|
|
194
211
|
headers,
|
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; // default: 'event/infer'\n streamRoute?: string; // default: 'event/stream'\n blobUploadRoute?: string; // default: 'context/blob/upload'\n toolCompletionRoute?: string; // default: 'event/tool-completion'\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 handleToolCompletion(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 toolCompletionRoute = config.toolCompletionRoute ?? 'event/tool-completion';\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 async handleToolCompletion(request: Request): Promise<Response> {\n try {\n const body = await request.text();\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...authHeader,\n };\n // Forward the runtime's tool-completion correlation headers verbatim\n // (non-hyphenated names, per the runtime OpenAPI). These route the\n // completion to the parked task so the SSE stream resumes.\n const CORRELATION_HEADERS = [\n 'taskid',\n 'parenttaskid',\n 'sessionid',\n 'userid',\n 'assistantid',\n 'agentspaceid',\n 'channelid',\n 'depth',\n ];\n for (const name of CORRELATION_HEADERS) {\n const value = request.headers.get(name);\n if (value) headers[name] = value;\n }\n const trace = request.headers.get('x-trace-parent');\n if (trace) headers['x-trace-parent'] = trace;\n\n const response = await fetch(`${baseUrl}/${toolCompletionRoute}`, {\n method: 'POST',\n headers,\n body,\n });\n\n return new Response(await response.text(), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleToolCompletion exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward tool-completion request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,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,sBAAsB,OAAO,uBAAuB;AAC1D,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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ACH,SAAS,OAAO;AACd,gBAAQ,MAAM,iDAAiD,KAAK;AACpE,eAAO,IAAI;AAAA,UACT,KAAK,UAAU,EAAE,OAAO,4CAA4C,CAAC;AAAA,UACrE,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
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 toolCompletionRoute?: string; // default: 'event/tool-completion'\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 handleToolCompletion(_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\n/**\n * Trace-context propagation. The proxy builds a fresh request against the\n * runtime, so anything the caller set is dropped unless it is copied over\n * explicitly — which is how `x-trace-parent` stopped reaching the runtime when\n * the direct-to-runtime client was replaced by this proxy.\n *\n * The header is the transport wherever the caller can set one. `EventSource`\n * cannot, so the stream route also accepts the same value as a `trace_parent`\n * query param.\n */\nfunction pickTraceHeader(request: Request): Record<string, string> {\n const fromHeader = request.headers.get('x-trace-parent');\n if (fromHeader) return { 'x-trace-parent': fromHeader };\n\n const fromQuery = new URL(request.url).searchParams.get('trace_parent');\n if (fromQuery) return { 'x-trace-parent': fromQuery };\n\n return {};\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 toolCompletionRoute = config.toolCompletionRoute ?? 'event/tool-completion';\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 ...pickIdentityHeaders(request),\n ...pickTraceHeader(request),\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: {\n 'Content-Type': 'application/json',\n ...authHeader,\n ...pickIdentityHeaders(request),\n ...pickTraceHeader(request),\n },\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 ...pickTraceHeader(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 async handleToolCompletion(request: Request): Promise<Response> {\n try {\n const body = await request.text();\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...authHeader,\n };\n // Forward the runtime's tool-completion correlation headers verbatim\n // (non-hyphenated names, per the runtime OpenAPI). These route the\n // completion to the parked task so the SSE stream resumes.\n const CORRELATION_HEADERS = [\n 'taskid',\n 'parenttaskid',\n 'sessionid',\n 'userid',\n 'assistantid',\n 'agentspaceid',\n 'channelid',\n 'depth',\n // Runtime v0.5.1: `CommonAttributes.version_tag` (alias `versiontag`)\n // pins the tool-completion to the agentspace version that ran the turn.\n 'versiontag',\n ];\n for (const name of CORRELATION_HEADERS) {\n const value = request.headers.get(name);\n if (value) headers[name] = value;\n }\n Object.assign(headers, pickTraceHeader(request));\n\n const response = await fetch(`${baseUrl}/${toolCompletionRoute}`, {\n method: 'POST',\n headers,\n body,\n });\n\n return new Response(await response.text(), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleToolCompletion exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward tool-completion request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,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;AAYA,SAAS,gBAAgB,SAA0C;AACjE,QAAM,aAAa,QAAQ,QAAQ,IAAI,gBAAgB;AACvD,MAAI,WAAY,QAAO,EAAE,kBAAkB,WAAW;AAEtD,QAAM,YAAY,IAAI,IAAI,QAAQ,GAAG,EAAE,aAAa,IAAI,cAAc;AACtE,MAAI,UAAW,QAAO,EAAE,kBAAkB,UAAU;AAEpD,S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,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,qBAAqB,SAAqC;AAC9D,UAAI;AACF,cAAM,OAAO,MAAM,QAAQ,KAAK;AAChC,cAAM,UAAkC;AAAA,UACtC,gBAAgB;AAAA,UAChB,GAAG;AAAA,QACL;AAIA,cAAM,sBAAsB;AAAA,UAC1B;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA;AAAA;AAAA,UAGA;AAAA,QACF;AACA,mBAAW,QAAQ,qBAAqB;AACtC,gBAAM,QAAQ,QAAQ,QAAQ,IAAI,IAAI;AACtC,cAAI,MAAO,SAAQ,IAAI,IAAI;AAAA,QAC7B;AACA,eAAO,OAAO,SAAS,gBAAgB,OAAO,CAAC;AAE/C,cAAM,WAAW,MAAM,MAAM,GAAG,OAAO,IAAI,mBAAmB,IAAI;AAAA,UAChE,QAAQ;AAAA,UACR;AAAA,UACA;AAAA,QACF,CAAC;AAED,eAAO,IAAI,SAAS,MAAM,SAAS,KAAK,GAAG;AAAA,UACzC,QAAQ,SAAS;AAAA,UACjB,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,QAChD,CAAC;AAAA,MACH,SAAS,OAAO;AACd,gBAAQ,MAAM,iDAAiD,KAAK;AACpE,eAAO,IAAI;AAAA,UACT,KAAK,UAAU,EAAE,OAAO,4CAA4C,CAAC;AAAA,UACrE,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/proxy.mjs
CHANGED
|
@@ -17,6 +17,13 @@ function pickIdentityHeaders(request) {
|
|
|
17
17
|
}
|
|
18
18
|
return out;
|
|
19
19
|
}
|
|
20
|
+
function pickTraceHeader(request) {
|
|
21
|
+
const fromHeader = request.headers.get("x-trace-parent");
|
|
22
|
+
if (fromHeader) return { "x-trace-parent": fromHeader };
|
|
23
|
+
const fromQuery = new URL(request.url).searchParams.get("trace_parent");
|
|
24
|
+
if (fromQuery) return { "x-trace-parent": fromQuery };
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
20
27
|
function createAlquimiaProxyHandler(config) {
|
|
21
28
|
const baseUrl = config.assistantBaseUrl.replace(/\/$/, "");
|
|
22
29
|
const inferRoute = config.inferRoute ?? "event/infer";
|
|
@@ -36,7 +43,9 @@ function createAlquimiaProxyHandler(config) {
|
|
|
36
43
|
method: "POST",
|
|
37
44
|
headers: {
|
|
38
45
|
"Content-Type": "application/json",
|
|
39
|
-
...authHeader
|
|
46
|
+
...authHeader,
|
|
47
|
+
...pickIdentityHeaders(request),
|
|
48
|
+
...pickTraceHeader(request)
|
|
40
49
|
},
|
|
41
50
|
body: JSON.stringify(body)
|
|
42
51
|
});
|
|
@@ -76,7 +85,12 @@ function createAlquimiaProxyHandler(config) {
|
|
|
76
85
|
try {
|
|
77
86
|
const targetUrl = `${baseUrl}/${streamRoute}/${pathSuffix}`;
|
|
78
87
|
const response = await fetch(targetUrl, {
|
|
79
|
-
headers: {
|
|
88
|
+
headers: {
|
|
89
|
+
"Content-Type": "application/json",
|
|
90
|
+
...authHeader,
|
|
91
|
+
...pickIdentityHeaders(request),
|
|
92
|
+
...pickTraceHeader(request)
|
|
93
|
+
}
|
|
80
94
|
});
|
|
81
95
|
if (!response.ok) {
|
|
82
96
|
const errorJson = await response.json().catch(() => ({}));
|
|
@@ -118,7 +132,8 @@ function createAlquimiaProxyHandler(config) {
|
|
|
118
132
|
headers: {
|
|
119
133
|
...authHeader,
|
|
120
134
|
...contentType && { "Content-Type": contentType },
|
|
121
|
-
...pickIdentityHeaders(request)
|
|
135
|
+
...pickIdentityHeaders(request),
|
|
136
|
+
...pickTraceHeader(request)
|
|
122
137
|
},
|
|
123
138
|
body: request.body,
|
|
124
139
|
duplex: "half"
|
|
@@ -157,14 +172,16 @@ function createAlquimiaProxyHandler(config) {
|
|
|
157
172
|
"assistantid",
|
|
158
173
|
"agentspaceid",
|
|
159
174
|
"channelid",
|
|
160
|
-
"depth"
|
|
175
|
+
"depth",
|
|
176
|
+
// Runtime v0.5.1: `CommonAttributes.version_tag` (alias `versiontag`)
|
|
177
|
+
// pins the tool-completion to the agentspace version that ran the turn.
|
|
178
|
+
"versiontag"
|
|
161
179
|
];
|
|
162
180
|
for (const name of CORRELATION_HEADERS) {
|
|
163
181
|
const value = request.headers.get(name);
|
|
164
182
|
if (value) headers[name] = value;
|
|
165
183
|
}
|
|
166
|
-
|
|
167
|
-
if (trace) headers["x-trace-parent"] = trace;
|
|
184
|
+
Object.assign(headers, pickTraceHeader(request));
|
|
168
185
|
const response = await fetch(`${baseUrl}/${toolCompletionRoute}`, {
|
|
169
186
|
method: "POST",
|
|
170
187
|
headers,
|
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; // default: 'event/infer'\n streamRoute?: string; // default: 'event/stream'\n blobUploadRoute?: string; // default: 'context/blob/upload'\n toolCompletionRoute?: string; // default: 'event/tool-completion'\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 handleToolCompletion(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 toolCompletionRoute = config.toolCompletionRoute ?? 'event/tool-completion';\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 async handleToolCompletion(request: Request): Promise<Response> {\n try {\n const body = await request.text();\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...authHeader,\n };\n // Forward the runtime's tool-completion correlation headers verbatim\n // (non-hyphenated names, per the runtime OpenAPI). These route the\n // completion to the parked task so the SSE stream resumes.\n const CORRELATION_HEADERS = [\n 'taskid',\n 'parenttaskid',\n 'sessionid',\n 'userid',\n 'assistantid',\n 'agentspaceid',\n 'channelid',\n 'depth',\n ];\n for (const name of CORRELATION_HEADERS) {\n const value = request.headers.get(name);\n if (value) headers[name] = value;\n }\n const trace = request.headers.get('x-trace-parent');\n if (trace) headers['x-trace-parent'] = trace;\n\n const response = await fetch(`${baseUrl}/${toolCompletionRoute}`, {\n method: 'POST',\n headers,\n body,\n });\n\n return new Response(await response.text(), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleToolCompletion exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward tool-completion request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n };\n}\n"],"mappings":";AAgBA,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,sBAAsB,OAAO,uBAAuB;AAC1D,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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,KAAK,GAAG;AAAA,UACzC,QAAQ,SAAS;AAAA,UACjB,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,QAChD,CAAC;AAAA,MACH,SAAS,OAAO;AACd,gBAAQ,MAAM,iDAAiD,KAAK;AACpE,eAAO,IAAI;AAAA,UACT,KAAK,UAAU,EAAE,OAAO,4CAA4C,CAAC;AAAA,UACrE,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
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 toolCompletionRoute?: string; // default: 'event/tool-completion'\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 handleToolCompletion(_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\n/**\n * Trace-context propagation. The proxy builds a fresh request against the\n * runtime, so anything the caller set is dropped unless it is copied over\n * explicitly — which is how `x-trace-parent` stopped reaching the runtime when\n * the direct-to-runtime client was replaced by this proxy.\n *\n * The header is the transport wherever the caller can set one. `EventSource`\n * cannot, so the stream route also accepts the same value as a `trace_parent`\n * query param.\n */\nfunction pickTraceHeader(request: Request): Record<string, string> {\n const fromHeader = request.headers.get('x-trace-parent');\n if (fromHeader) return { 'x-trace-parent': fromHeader };\n\n const fromQuery = new URL(request.url).searchParams.get('trace_parent');\n if (fromQuery) return { 'x-trace-parent': fromQuery };\n\n return {};\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 toolCompletionRoute = config.toolCompletionRoute ?? 'event/tool-completion';\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 ...pickIdentityHeaders(request),\n ...pickTraceHeader(request),\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: {\n 'Content-Type': 'application/json',\n ...authHeader,\n ...pickIdentityHeaders(request),\n ...pickTraceHeader(request),\n },\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 ...pickTraceHeader(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 async handleToolCompletion(request: Request): Promise<Response> {\n try {\n const body = await request.text();\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...authHeader,\n };\n // Forward the runtime's tool-completion correlation headers verbatim\n // (non-hyphenated names, per the runtime OpenAPI). These route the\n // completion to the parked task so the SSE stream resumes.\n const CORRELATION_HEADERS = [\n 'taskid',\n 'parenttaskid',\n 'sessionid',\n 'userid',\n 'assistantid',\n 'agentspaceid',\n 'channelid',\n 'depth',\n // Runtime v0.5.1: `CommonAttributes.version_tag` (alias `versiontag`)\n // pins the tool-completion to the agentspace version that ran the turn.\n 'versiontag',\n ];\n for (const name of CORRELATION_HEADERS) {\n const value = request.headers.get(name);\n if (value) headers[name] = value;\n }\n Object.assign(headers, pickTraceHeader(request));\n\n const response = await fetch(`${baseUrl}/${toolCompletionRoute}`, {\n method: 'POST',\n headers,\n body,\n });\n\n return new Response(await response.text(), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n });\n } catch (error) {\n console.error('AlquimiaProxy handleToolCompletion exception:', error);\n return new Response(\n JSON.stringify({ error: 'Failed to forward tool-completion request' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } }\n );\n }\n },\n };\n}\n"],"mappings":";AAgBA,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;AAYA,SAAS,gBAAgB,SAA0C;AACjE,QAAM,aAAa,QAAQ,QAAQ,IAAI,gBAAgB;AACvD,MAAI,WAAY,QAAO,EAAE,kBAAkB,WAAW;AAEtD,QAAM,YAAY,IAAI,IAAI,QAAQ,GAAG,EAAE,aAAa,IAAI,cAAc;A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,EAAE,OAAO,wCAAwC,CAAC;AAAA,UACjE,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,qBAAqB,SAAqC;AAC9D,UAAI;AACF,cAAM,OAAO,MAAM,QAAQ,KAAK;AAChC,cAAM,UAAkC;AAAA,UACtC,gBAAgB;AAAA,UAChB,GAAG;AAAA,QACL;AAIA,cAAM,sBAAsB;AAAA,UAC1B;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA;AAAA;AAAA,UAGA;AAAA,QACF;AACA,mBAAW,QAAQ,qBAAqB;AACtC,gBAAM,QAAQ,QAAQ,QAAQ,IAAI,IAAI;AACtC,cAAI,MAAO,SAAQ,IAAI,IAAI;AAAA,QAC7B;AACA,eAAO,OAAO,SAAS,gBAAgB,OAAO,CAAC;AAE/C,cAAM,WAAW,MAAM,MAAM,GAAG,OAAO,IAAI,mBAAmB,IAAI;AAAA,UAChE,QAAQ;AAAA,UACR;AAAA,UACA;AAAA,QACF,CAAC;AAED,eAAO,IAAI,SAAS,MAAM,SAAS,KAAK,GAAG;AAAA,UACzC,QAAQ,SAAS;AAAA,UACjB,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,QAChD,CAAC;AAAA,MACH,SAAS,OAAO;AACd,gBAAQ,MAAM,iDAAiD,KAAK;AACpE,eAAO,IAAI;AAAA,UACT,KAAK,UAAU,EAAE,OAAO,4CAA4C,CAAC;AAAA,UACrE,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,10 +1,26 @@
|
|
|
1
|
-
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-
|
|
2
|
-
import { AttachmentPayload, TTSResult } from '../
|
|
1
|
+
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-B4IOiGfr.mjs';
|
|
2
|
+
import { i as AttachmentPayload, T as TTSResult, j as Content, w as RuntimeBlob } from '../type-61gaZga-.mjs';
|
|
3
|
+
import { T as ToolExecutionResponse } from '../types-CMVbyEv8.mjs';
|
|
3
4
|
import { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters/index.mjs';
|
|
4
|
-
import { T as ToolExecutionResponse } from '../types-DnfWUE9V.mjs';
|
|
5
5
|
import '@elastic/apm-rum';
|
|
6
6
|
import 'ai';
|
|
7
7
|
|
|
8
|
+
/** Per-turn options for {@link AlquimiaSDK.sendMessage}. */
|
|
9
|
+
interface SendMessageOptions {
|
|
10
|
+
/** W3C traceparent, so infer and stream share one trace. */
|
|
11
|
+
traceParent?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Audio input for this turn (runtime v0.5.1). Upload it with
|
|
14
|
+
* {@link AlquimiaSDK.uploadAttachment} first and pass the blob it returns.
|
|
15
|
+
* May be sent with or instead of `query`.
|
|
16
|
+
*/
|
|
17
|
+
inputAudio?: RuntimeBlob;
|
|
18
|
+
/**
|
|
19
|
+
* Set to `false` to force a text-only reply from an audio-enabled agent.
|
|
20
|
+
* The runtime defaults to `true`, so leaving this unset keeps its behaviour.
|
|
21
|
+
*/
|
|
22
|
+
outputAudio?: boolean;
|
|
23
|
+
}
|
|
8
24
|
declare class AlquimiaSDK {
|
|
9
25
|
private adapter;
|
|
10
26
|
private assistantId;
|
|
@@ -12,6 +28,8 @@ declare class AlquimiaSDK {
|
|
|
12
28
|
private conversationId;
|
|
13
29
|
private sessionId;
|
|
14
30
|
private streamId;
|
|
31
|
+
private traceParent;
|
|
32
|
+
private versionTag;
|
|
15
33
|
private tools;
|
|
16
34
|
private extraInstructions;
|
|
17
35
|
private assistantConfig;
|
|
@@ -36,10 +54,20 @@ declare class AlquimiaSDK {
|
|
|
36
54
|
withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK;
|
|
37
55
|
withAssistantConfig(assistantConfig: any): AlquimiaSDK;
|
|
38
56
|
withUserId(userId: string): AlquimiaSDK;
|
|
57
|
+
/**
|
|
58
|
+
* Pin inference to a cached registry version. Sent as the `version_tag`
|
|
59
|
+
* query parameter, which `POST /event/infer/{assistant_id}` accepts from
|
|
60
|
+
* **runtime v0.5.2** onward; older runtimes ignore it.
|
|
61
|
+
*
|
|
62
|
+
* Works on every version: pass a versioned assistant ref
|
|
63
|
+
* (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the
|
|
64
|
+
* runtime parses the tag out of the path itself.
|
|
65
|
+
*/
|
|
66
|
+
withVersionTag(versionTag: string): AlquimiaSDK;
|
|
39
67
|
getEnforceCharacterization(): boolean;
|
|
40
68
|
textToSpeech(text: string): Promise<TTSResult>;
|
|
41
69
|
speechToText(audio: string): Promise<string>;
|
|
42
|
-
sendMessage(query
|
|
70
|
+
sendMessage(query?: Content, options?: string | SendMessageOptions): Promise<AlquimiaSDK>;
|
|
43
71
|
/**
|
|
44
72
|
* Complete a pending client-tool execution (the missing "submit half" of the
|
|
45
73
|
* client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's
|
|
@@ -60,7 +88,11 @@ declare class AlquimiaSDK {
|
|
|
60
88
|
* session via headers. Always returns `[]`; kept for source compatibility.
|
|
61
89
|
*/
|
|
62
90
|
getAttachmentResponses(): string[];
|
|
63
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Upload a file into the session context. Returns the runtime {@link RuntimeBlob},
|
|
93
|
+
* which is what `sendMessage`'s `inputAudio` expects for audio inference.
|
|
94
|
+
*/
|
|
95
|
+
uploadAttachment(file: File, _attachmentId?: string): Promise<RuntimeBlob>;
|
|
64
96
|
/**
|
|
65
97
|
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
66
98
|
* the rest of the runtime's internal endpoints introduced in v0.2.0→next.
|
|
@@ -70,6 +102,8 @@ declare class AlquimiaSDK {
|
|
|
70
102
|
getStreamId(): string | null;
|
|
71
103
|
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
72
104
|
getTaskId(): string | null;
|
|
105
|
+
/** Registry version tag resolved by the runtime for the current task, if any. */
|
|
106
|
+
getVersionTag(): string | null;
|
|
73
107
|
}
|
|
74
108
|
|
|
75
109
|
export { AlquimiaSDK };
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-
|
|
2
|
-
import { AttachmentPayload, TTSResult } from '../
|
|
1
|
+
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-mx21gNgZ.js';
|
|
2
|
+
import { i as AttachmentPayload, T as TTSResult, j as Content, w as RuntimeBlob } from '../type-D-JaSMkV.js';
|
|
3
|
+
import { T as ToolExecutionResponse } from '../types-CMVbyEv8.js';
|
|
3
4
|
import { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters/index.js';
|
|
4
|
-
import { T as ToolExecutionResponse } from '../types-DnfWUE9V.js';
|
|
5
5
|
import '@elastic/apm-rum';
|
|
6
6
|
import 'ai';
|
|
7
7
|
|
|
8
|
+
/** Per-turn options for {@link AlquimiaSDK.sendMessage}. */
|
|
9
|
+
interface SendMessageOptions {
|
|
10
|
+
/** W3C traceparent, so infer and stream share one trace. */
|
|
11
|
+
traceParent?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Audio input for this turn (runtime v0.5.1). Upload it with
|
|
14
|
+
* {@link AlquimiaSDK.uploadAttachment} first and pass the blob it returns.
|
|
15
|
+
* May be sent with or instead of `query`.
|
|
16
|
+
*/
|
|
17
|
+
inputAudio?: RuntimeBlob;
|
|
18
|
+
/**
|
|
19
|
+
* Set to `false` to force a text-only reply from an audio-enabled agent.
|
|
20
|
+
* The runtime defaults to `true`, so leaving this unset keeps its behaviour.
|
|
21
|
+
*/
|
|
22
|
+
outputAudio?: boolean;
|
|
23
|
+
}
|
|
8
24
|
declare class AlquimiaSDK {
|
|
9
25
|
private adapter;
|
|
10
26
|
private assistantId;
|
|
@@ -12,6 +28,8 @@ declare class AlquimiaSDK {
|
|
|
12
28
|
private conversationId;
|
|
13
29
|
private sessionId;
|
|
14
30
|
private streamId;
|
|
31
|
+
private traceParent;
|
|
32
|
+
private versionTag;
|
|
15
33
|
private tools;
|
|
16
34
|
private extraInstructions;
|
|
17
35
|
private assistantConfig;
|
|
@@ -36,10 +54,20 @@ declare class AlquimiaSDK {
|
|
|
36
54
|
withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK;
|
|
37
55
|
withAssistantConfig(assistantConfig: any): AlquimiaSDK;
|
|
38
56
|
withUserId(userId: string): AlquimiaSDK;
|
|
57
|
+
/**
|
|
58
|
+
* Pin inference to a cached registry version. Sent as the `version_tag`
|
|
59
|
+
* query parameter, which `POST /event/infer/{assistant_id}` accepts from
|
|
60
|
+
* **runtime v0.5.2** onward; older runtimes ignore it.
|
|
61
|
+
*
|
|
62
|
+
* Works on every version: pass a versioned assistant ref
|
|
63
|
+
* (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the
|
|
64
|
+
* runtime parses the tag out of the path itself.
|
|
65
|
+
*/
|
|
66
|
+
withVersionTag(versionTag: string): AlquimiaSDK;
|
|
39
67
|
getEnforceCharacterization(): boolean;
|
|
40
68
|
textToSpeech(text: string): Promise<TTSResult>;
|
|
41
69
|
speechToText(audio: string): Promise<string>;
|
|
42
|
-
sendMessage(query
|
|
70
|
+
sendMessage(query?: Content, options?: string | SendMessageOptions): Promise<AlquimiaSDK>;
|
|
43
71
|
/**
|
|
44
72
|
* Complete a pending client-tool execution (the missing "submit half" of the
|
|
45
73
|
* client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's
|
|
@@ -60,7 +88,11 @@ declare class AlquimiaSDK {
|
|
|
60
88
|
* session via headers. Always returns `[]`; kept for source compatibility.
|
|
61
89
|
*/
|
|
62
90
|
getAttachmentResponses(): string[];
|
|
63
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Upload a file into the session context. Returns the runtime {@link RuntimeBlob},
|
|
93
|
+
* which is what `sendMessage`'s `inputAudio` expects for audio inference.
|
|
94
|
+
*/
|
|
95
|
+
uploadAttachment(file: File, _attachmentId?: string): Promise<RuntimeBlob>;
|
|
64
96
|
/**
|
|
65
97
|
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
66
98
|
* the rest of the runtime's internal endpoints introduced in v0.2.0→next.
|
|
@@ -70,6 +102,8 @@ declare class AlquimiaSDK {
|
|
|
70
102
|
getStreamId(): string | null;
|
|
71
103
|
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
72
104
|
getTaskId(): string | null;
|
|
105
|
+
/** Registry version tag resolved by the runtime for the current task, if any. */
|
|
106
|
+
getVersionTag(): string | null;
|
|
73
107
|
}
|
|
74
108
|
|
|
75
109
|
export { AlquimiaSDK };
|