@alquimia-ai/tools 2.1.0 → 2.3.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.
Files changed (80) hide show
  1. package/dist/actions/index.d.mts +1 -0
  2. package/dist/actions/index.d.ts +1 -0
  3. package/dist/actions/index.js.map +1 -1
  4. package/dist/actions/index.mjs.map +1 -1
  5. package/dist/actions-BebMyGqF.d.ts +16 -0
  6. package/dist/actions-Ca3ro-hX.d.mts +16 -0
  7. package/dist/adapters/fetch.d.mts +2 -0
  8. package/dist/adapters/fetch.d.ts +2 -0
  9. package/dist/adapters/fetch.js +7 -1
  10. package/dist/adapters/fetch.js.map +1 -1
  11. package/dist/adapters/fetch.mjs +7 -1
  12. package/dist/adapters/fetch.mjs.map +1 -1
  13. package/dist/adapters/index.d.mts +1 -0
  14. package/dist/adapters/index.d.ts +1 -0
  15. package/dist/adapters/index.js.map +1 -1
  16. package/dist/adapters/next.d.mts +2 -0
  17. package/dist/adapters/next.d.ts +2 -0
  18. package/dist/adapters/next.js +7 -1
  19. package/dist/adapters/next.js.map +1 -1
  20. package/dist/adapters/next.mjs +7 -1
  21. package/dist/adapters/next.mjs.map +1 -1
  22. package/dist/genui/index.d.mts +3027 -0
  23. package/dist/genui/index.d.ts +3027 -0
  24. package/dist/genui/index.js +3344 -0
  25. package/dist/genui/index.js.map +1 -0
  26. package/dist/genui/index.mjs +3321 -0
  27. package/dist/genui/index.mjs.map +1 -0
  28. package/dist/hooks/index.d.mts +26 -1
  29. package/dist/hooks/index.d.ts +26 -1
  30. package/dist/hooks/index.js +650 -21
  31. package/dist/hooks/index.js.map +1 -1
  32. package/dist/hooks/index.mjs +632 -3
  33. package/dist/hooks/index.mjs.map +1 -1
  34. package/dist/next/index.d.mts +7 -0
  35. package/dist/next/index.d.ts +7 -0
  36. package/dist/next/index.js +50 -0
  37. package/dist/next/index.js.map +1 -1
  38. package/dist/next/index.mjs +50 -0
  39. package/dist/next/index.mjs.map +1 -1
  40. package/dist/providers/index.d.mts +3 -2
  41. package/dist/providers/index.d.ts +3 -2
  42. package/dist/providers/index.js.map +1 -1
  43. package/dist/providers/index.mjs.map +1 -1
  44. package/dist/proxy.d.mts +2 -0
  45. package/dist/proxy.d.ts +2 -0
  46. package/dist/proxy.js +41 -0
  47. package/dist/proxy.js.map +1 -1
  48. package/dist/proxy.mjs +41 -0
  49. package/dist/proxy.mjs.map +1 -1
  50. package/dist/registry-Bcu_ZYL1.d.mts +19 -0
  51. package/dist/registry-Bcu_ZYL1.d.ts +19 -0
  52. package/dist/sdk/index.d.mts +10 -0
  53. package/dist/sdk/index.d.ts +10 -0
  54. package/dist/sdk/index.js +26 -0
  55. package/dist/sdk/index.js.map +1 -1
  56. package/dist/sdk/index.mjs +26 -0
  57. package/dist/sdk/index.mjs.map +1 -1
  58. package/dist/services/index.d.mts +1 -0
  59. package/dist/services/index.d.ts +1 -0
  60. package/dist/types/index.d.mts +10 -1
  61. package/dist/types/index.d.ts +10 -1
  62. package/dist/types/index.js.map +1 -1
  63. package/dist/types/index.mjs.map +1 -1
  64. package/dist/types-DnfWUE9V.d.mts +56 -0
  65. package/dist/types-DnfWUE9V.d.ts +56 -0
  66. package/dist/types-Dvu9y4WM.d.mts +53 -0
  67. package/dist/types-Dvu9y4WM.d.ts +53 -0
  68. package/dist/utils/index.d.mts +6 -2
  69. package/dist/utils/index.d.ts +6 -2
  70. package/dist/utils/index.js +4 -0
  71. package/dist/utils/index.js.map +1 -1
  72. package/dist/utils/index.mjs +4 -0
  73. package/dist/utils/index.mjs.map +1 -1
  74. package/dist/worklog/index.d.mts +29 -0
  75. package/dist/worklog/index.d.ts +29 -0
  76. package/dist/worklog/index.js +218 -0
  77. package/dist/worklog/index.js.map +1 -0
  78. package/dist/worklog/index.mjs +195 -0
  79. package/dist/worklog/index.mjs.map +1 -0
  80. package/package.json +24 -7
package/dist/proxy.d.mts CHANGED
@@ -4,11 +4,13 @@ interface ProxyConfig {
4
4
  inferRoute?: string;
5
5
  streamRoute?: string;
6
6
  blobUploadRoute?: string;
7
+ toolCompletionRoute?: string;
7
8
  }
8
9
  interface AlquimiaProxyHandler {
9
10
  handleInfer(request: Request, pathSuffix: string): Promise<Response>;
10
11
  handleStream(request: Request, pathSuffix: string): Promise<Response>;
11
12
  handleBlobUpload(request: Request): Promise<Response>;
13
+ handleToolCompletion(request: Request): Promise<Response>;
12
14
  }
13
15
  declare function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler;
14
16
 
package/dist/proxy.d.ts CHANGED
@@ -4,11 +4,13 @@ interface ProxyConfig {
4
4
  inferRoute?: string;
5
5
  streamRoute?: string;
6
6
  blobUploadRoute?: string;
7
+ toolCompletionRoute?: string;
7
8
  }
8
9
  interface AlquimiaProxyHandler {
9
10
  handleInfer(request: Request, pathSuffix: string): Promise<Response>;
10
11
  handleStream(request: Request, pathSuffix: string): Promise<Response>;
11
12
  handleBlobUpload(request: Request): Promise<Response>;
13
+ handleToolCompletion(request: Request): Promise<Response>;
12
14
  }
13
15
  declare function createAlquimiaProxyHandler(config: ProxyConfig): AlquimiaProxyHandler;
14
16
 
package/dist/proxy.js CHANGED
@@ -46,6 +46,7 @@ function createAlquimiaProxyHandler(config) {
46
46
  const inferRoute = config.inferRoute ?? "event/infer";
47
47
  const streamRoute = config.streamRoute ?? "event/stream";
48
48
  const blobUploadRoute = config.blobUploadRoute ?? "context/blob/upload";
49
+ const toolCompletionRoute = config.toolCompletionRoute ?? "event/tool-completion";
49
50
  const authHeader = { Authorization: `Bearer ${config.apiKey}` };
50
51
  return {
51
52
  async handleInfer(request, pathSuffix) {
@@ -164,6 +165,46 @@ function createAlquimiaProxyHandler(config) {
164
165
  { status: 500, headers: { "Content-Type": "application/json" } }
165
166
  );
166
167
  }
168
+ },
169
+ async handleToolCompletion(request) {
170
+ try {
171
+ const body = await request.text();
172
+ const headers = {
173
+ "Content-Type": "application/json",
174
+ ...authHeader
175
+ };
176
+ const CORRELATION_HEADERS = [
177
+ "taskid",
178
+ "parenttaskid",
179
+ "sessionid",
180
+ "userid",
181
+ "assistantid",
182
+ "agentspaceid",
183
+ "channelid",
184
+ "depth"
185
+ ];
186
+ for (const name of CORRELATION_HEADERS) {
187
+ const value = request.headers.get(name);
188
+ if (value) headers[name] = value;
189
+ }
190
+ const trace = request.headers.get("x-trace-parent");
191
+ if (trace) headers["x-trace-parent"] = trace;
192
+ const response = await fetch(`${baseUrl}/${toolCompletionRoute}`, {
193
+ method: "POST",
194
+ headers,
195
+ body
196
+ });
197
+ return new Response(await response.text(), {
198
+ status: response.status,
199
+ headers: { "Content-Type": "application/json" }
200
+ });
201
+ } catch (error) {
202
+ console.error("AlquimiaProxy handleToolCompletion exception:", error);
203
+ return new Response(
204
+ JSON.stringify({ error: "Failed to forward tool-completion request" }),
205
+ { status: 500, headers: { "Content-Type": "application/json" } }
206
+ );
207
+ }
167
208
  }
168
209
  };
169
210
  }
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}\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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AO,mCAAmC,CAAC;AAAA,UAC5D,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,iBAAiB,SAAqC;AAC1D,UAAI;AACF,cAAM,YAAY,GAAG,OAAO,IAAI,eAAe;AAC/C,cAAM,cAAc,QAAQ,QAAQ,IAAI,cAAc,KAAK;AAE3D,cAAM,WAAW,MAAM,MAAM,WAAW;AAAA,UACtC,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,GAAG;AAAA,YACH,GAAI,eAAe,EAAE,gBAAgB,YAAY;AAAA,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":[]}
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,Q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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,QACF;AACA,mBAAW,QAAQ,qBAAqB;AACtC,gBAAM,QAAQ,QAAQ,QAAQ,IAAI,IAAI;AACtC,cAAI,MAAO,SAAQ,IAAI,IAAI;AAAA,QAC7B;AACA,cAAM,QAAQ,QAAQ,QAAQ,IAAI,gBAAgB;AAClD,YAAI,MAAO,SAAQ,gBAAgB,IAAI;AAEvC,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
@@ -22,6 +22,7 @@ function createAlquimiaProxyHandler(config) {
22
22
  const inferRoute = config.inferRoute ?? "event/infer";
23
23
  const streamRoute = config.streamRoute ?? "event/stream";
24
24
  const blobUploadRoute = config.blobUploadRoute ?? "context/blob/upload";
25
+ const toolCompletionRoute = config.toolCompletionRoute ?? "event/tool-completion";
25
26
  const authHeader = { Authorization: `Bearer ${config.apiKey}` };
26
27
  return {
27
28
  async handleInfer(request, pathSuffix) {
@@ -140,6 +141,46 @@ function createAlquimiaProxyHandler(config) {
140
141
  { status: 500, headers: { "Content-Type": "application/json" } }
141
142
  );
142
143
  }
144
+ },
145
+ async handleToolCompletion(request) {
146
+ try {
147
+ const body = await request.text();
148
+ const headers = {
149
+ "Content-Type": "application/json",
150
+ ...authHeader
151
+ };
152
+ const CORRELATION_HEADERS = [
153
+ "taskid",
154
+ "parenttaskid",
155
+ "sessionid",
156
+ "userid",
157
+ "assistantid",
158
+ "agentspaceid",
159
+ "channelid",
160
+ "depth"
161
+ ];
162
+ for (const name of CORRELATION_HEADERS) {
163
+ const value = request.headers.get(name);
164
+ if (value) headers[name] = value;
165
+ }
166
+ const trace = request.headers.get("x-trace-parent");
167
+ if (trace) headers["x-trace-parent"] = trace;
168
+ const response = await fetch(`${baseUrl}/${toolCompletionRoute}`, {
169
+ method: "POST",
170
+ headers,
171
+ body
172
+ });
173
+ return new Response(await response.text(), {
174
+ status: response.status,
175
+ headers: { "Content-Type": "application/json" }
176
+ });
177
+ } catch (error) {
178
+ console.error("AlquimiaProxy handleToolCompletion exception:", error);
179
+ return new Response(
180
+ JSON.stringify({ error: "Failed to forward tool-completion request" }),
181
+ { status: 500, headers: { "Content-Type": "application/json" } }
182
+ );
183
+ }
143
184
  }
144
185
  };
145
186
  }
@@ -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}\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,QAA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A,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\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,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A,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,QACF;AACA,mBAAW,QAAQ,qBAAqB;AACtC,gBAAM,QAAQ,QAAQ,QAAQ,IAAI,IAAI;AACtC,cAAI,MAAO,SAAQ,IAAI,IAAI;AAAA,QAC7B;AACA,cAAM,QAAQ,QAAQ,QAAQ,IAAI,gBAAgB;AAClD,YAAI,MAAO,SAAQ,gBAAgB,IAAI;AAEvC,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":[]}
@@ -0,0 +1,19 @@
1
+ import { ZodType } from 'zod';
2
+
3
+ interface UIComponentDefinition {
4
+ name: string;
5
+ /** zod schema for the component's presentational props. */
6
+ schema: ZodType;
7
+ /** semantic action names this component may emit. */
8
+ allowedActions?: string[];
9
+ }
10
+ interface CatalogManifest {
11
+ id: string;
12
+ components: Record<string, UIComponentDefinition>;
13
+ }
14
+ /** Marker used by the renderer when a component name is not in the catalog. */
15
+ declare const UNKNOWN_COMPONENT = "__unknown__";
16
+ /** Resolve a component name against the active catalog. Returns null on miss — never throws. */
17
+ declare function resolveComponent(manifest: CatalogManifest, name: string): UIComponentDefinition | null;
18
+
19
+ export { type CatalogManifest as C, type UIComponentDefinition as U, UNKNOWN_COMPONENT as a, resolveComponent as r };
@@ -0,0 +1,19 @@
1
+ import { ZodType } from 'zod';
2
+
3
+ interface UIComponentDefinition {
4
+ name: string;
5
+ /** zod schema for the component's presentational props. */
6
+ schema: ZodType;
7
+ /** semantic action names this component may emit. */
8
+ allowedActions?: string[];
9
+ }
10
+ interface CatalogManifest {
11
+ id: string;
12
+ components: Record<string, UIComponentDefinition>;
13
+ }
14
+ /** Marker used by the renderer when a component name is not in the catalog. */
15
+ declare const UNKNOWN_COMPONENT = "__unknown__";
16
+ /** Resolve a component name against the active catalog. Returns null on miss — never throws. */
17
+ declare function resolveComponent(manifest: CatalogManifest, name: string): UIComponentDefinition | null;
18
+
19
+ export { type CatalogManifest as C, type UIComponentDefinition as U, UNKNOWN_COMPONENT as a, resolveComponent as r };
@@ -1,6 +1,7 @@
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
3
  import { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters/index.mjs';
4
+ import { T as ToolExecutionResponse } from '../types-DnfWUE9V.mjs';
4
5
  import '@elastic/apm-rum';
5
6
  import 'ai';
6
7
 
@@ -39,6 +40,15 @@ declare class AlquimiaSDK {
39
40
  textToSpeech(text: string): Promise<TTSResult>;
40
41
  speechToText(audio: string): Promise<string>;
41
42
  sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK>;
43
+ /**
44
+ * Complete a pending client-tool execution (the missing "submit half" of the
45
+ * client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's
46
+ * `/event/tool-completion`. For interactive `render_ui` surfaces `result` is
47
+ * the user's data; for display-only surfaces the SDK sends `{ shown: true }`.
48
+ * The pending call is correlated by `control_id` in the body + the
49
+ * `context-metadata` header (taskid + sessionid).
50
+ */
51
+ submitToolResult(response: ToolExecutionResponse): Promise<void>;
42
52
  generateImage(query: string): Promise<string>;
43
53
  analyzeCharacterization(text: string): Promise<Record<string, any>>;
44
54
  rate(data: any): Promise<Record<string, any>>;
@@ -1,6 +1,7 @@
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
3
  import { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters/index.js';
4
+ import { T as ToolExecutionResponse } from '../types-DnfWUE9V.js';
4
5
  import '@elastic/apm-rum';
5
6
  import 'ai';
6
7
 
@@ -39,6 +40,15 @@ declare class AlquimiaSDK {
39
40
  textToSpeech(text: string): Promise<TTSResult>;
40
41
  speechToText(audio: string): Promise<string>;
41
42
  sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK>;
43
+ /**
44
+ * Complete a pending client-tool execution (the missing "submit half" of the
45
+ * client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's
46
+ * `/event/tool-completion`. For interactive `render_ui` surfaces `result` is
47
+ * the user's data; for display-only surfaces the SDK sends `{ shown: true }`.
48
+ * The pending call is correlated by `control_id` in the body + the
49
+ * `context-metadata` header (taskid + sessionid).
50
+ */
51
+ submitToolResult(response: ToolExecutionResponse): Promise<void>;
42
52
  generateImage(query: string): Promise<string>;
43
53
  analyzeCharacterization(text: string): Promise<Record<string, any>>;
44
54
  rate(data: any): Promise<Record<string, any>>;
package/dist/sdk/index.js CHANGED
@@ -172,6 +172,32 @@ var AlquimiaSDK = class {
172
172
  this.attachments = [];
173
173
  return this;
174
174
  }
175
+ /**
176
+ * Complete a pending client-tool execution (the missing "submit half" of the
177
+ * client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's
178
+ * `/event/tool-completion`. For interactive `render_ui` surfaces `result` is
179
+ * the user's data; for display-only surfaces the SDK sends `{ shown: true }`.
180
+ * The pending call is correlated by `control_id` in the body + the
181
+ * `context-metadata` header (taskid + sessionid).
182
+ */
183
+ async submitToolResult(response) {
184
+ const url = this.adapter.resolveToolCompletionUrl?.();
185
+ if (!url) {
186
+ throw new Error(
187
+ "AlquimiaSDK: adapter does not support tool completion (resolveToolCompletionUrl missing)"
188
+ );
189
+ }
190
+ const adapterHeaders = this.adapter.getHeaders?.() ?? {};
191
+ const headers = {
192
+ "Content-Type": "application/json",
193
+ assistantid: this.assistantId,
194
+ ...this.streamId && { taskid: this.streamId },
195
+ ...this.conversationId && { sessionid: this.conversationId },
196
+ ...this.userId && { userid: this.userId },
197
+ ...adapterHeaders
198
+ };
199
+ await this.axiosInstance.post(url, response, { headers });
200
+ }
175
201
  async generateImage(query) {
176
202
  if (!this.stableDiffusionProvider) {
177
203
  throw new Error("Stable Diffusion provider not initialized");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/sdk/index.ts","../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["export { default as AlquimiaSDK } from './alquimia-sdk';","import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult, type CommonAttributes } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n // Internal subscription id from infer (`taskid` on the wire).\n private streamId: string | null = null;\n private tools: any = [];\n private extraInstructions: Record<string, string> | null = null;\n private assistantConfig: any = null;\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK {\n this.extraInstructions = extraInstructions;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;\n\n const initMessage: Record<string, unknown> = {\n query,\n session_id: this.conversationId,\n user_id: this.userId,\n ...(this.extraInstructions && { extra_instructions: this.extraInstructions }),\n ...(this.assistantConfig && { config: this.assistantConfig }),\n ...(hasClientTools && {\n evaluation_strategy: {\n evaluation_strategy_id: 'native',\n tool_schemas: this.tools,\n },\n }),\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.streamId = result.taskid ?? null;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n /**\n * @deprecated The runtime no longer returns attachment IDs from the infer\n * response — attachments are uploaded as standalone blobs and linked to the\n * session via headers. Always returns `[]`; kept for source compatibility.\n */\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, _attachmentId?: string): Promise<void> {\n void _attachmentId;\n const url = this.adapter.resolveBlobUploadUrl();\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n }\n\n /**\n * Identity headers (kebab-case) required by `/context/blob/upload` and\n * the rest of the runtime's internal endpoints introduced in v0.2.0→next.\n */\n private buildIdentityHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n 'assistant-id': this.assistantId,\n };\n if (this.conversationId) headers['session-id'] = this.conversationId;\n if (this.userId) headers['user-id'] = this.userId;\n if (this.streamId) headers['task-id'] = this.streamId;\n return headers;\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n\n /** Alias for {@link getStreamId} — same value as infer `taskid`. */\n getTaskId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;AAWrC,IAAM,cAAN,MAAkB;AAAA,EAqBhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AArBF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AAEnC;AAAA,SAAQ,WAA0B;AAClC,SAAQ,QAAa,CAAC;AACtB,SAAQ,oBAAmD;AAC3D,SAAQ,kBAAuB;AAC/B,SAAQ,SAAwB;AAOhC,SAAQ,cAAmC,CAAC;AAC5C,SAAQ,sBAAgC,CAAC;AAOvC,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,sCAAsC;AAAA,IACxD;AACA,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,cAAc;AACnB,SAAK,UAAU;AACf,SAAK,0BAA0B,QAAQ,2BAA2B;AAElE,SAAK,gBAAgB,aAAAA,QAAM,OAAO;AAClC,SAAK,cAAc,aAAa,SAAS;AAAA,MACvC,CAAC,aAAa;AAAA,MACd,OAAO,UAAU;AACf,YAAI,MAAM,UAAU,UAAU,KAAK,gBAAgB;AACjD,gBAAM,KAAK,eAAe,SAAS,gBAAgB,OAAO;AAAA,YACxD,KAAK,MAAM,OAAO;AAAA,YAClB,QAAQ,MAAM,OAAO;AAAA,YACrB,MAAM,MAAM,OAAO;AAAA,YACnB,QAAQ,MAAM,SAAS;AAAA,YACvB,cAAc,MAAM,SAAS;AAAA,UAC/B,CAAC;AAAA,QACH;AACA,eAAO,QAAQ,OAAO,KAAK;AAAA,MAC7B;AAAA,IACF;AAEA,SAAK,eAAe,KAAK,aAAa,KAAK,IAAI;AAC/C,SAAK,eAAe,KAAK,aAAa,KAAK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AAC,KAAK,UAAU;AAClB,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AACA,WAAO,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AAAA,EACpD;AAAA,EAEA,cAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,YAA2B;AACzB,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":["axios"]}
1
+ {"version":3,"sources":["../../src/sdk/index.ts","../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["export { default as AlquimiaSDK } from './alquimia-sdk';","import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult, type CommonAttributes } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\nimport type { ToolExecutionResponse } from '../genui/types';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n // Internal subscription id from infer (`taskid` on the wire).\n private streamId: string | null = null;\n private tools: any = [];\n private extraInstructions: Record<string, string> | null = null;\n private assistantConfig: any = null;\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK {\n this.extraInstructions = extraInstructions;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;\n\n const initMessage: Record<string, unknown> = {\n query,\n session_id: this.conversationId,\n user_id: this.userId,\n ...(this.extraInstructions && { extra_instructions: this.extraInstructions }),\n ...(this.assistantConfig && { config: this.assistantConfig }),\n ...(hasClientTools && {\n evaluation_strategy: {\n evaluation_strategy_id: 'native',\n tool_schemas: this.tools,\n },\n }),\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.streamId = result.taskid ?? null;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n /**\n * Complete a pending client-tool execution (the missing \"submit half\" of the\n * client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's\n * `/event/tool-completion`. For interactive `render_ui` surfaces `result` is\n * the user's data; for display-only surfaces the SDK sends `{ shown: true }`.\n * The pending call is correlated by `control_id` in the body + the\n * `context-metadata` header (taskid + sessionid).\n */\n async submitToolResult(response: ToolExecutionResponse): Promise<void> {\n const url = this.adapter.resolveToolCompletionUrl?.();\n if (!url) {\n throw new Error(\n 'AlquimiaSDK: adapter does not support tool completion (resolveToolCompletionUrl missing)'\n );\n }\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n assistantid: this.assistantId,\n ...(this.streamId && { taskid: this.streamId }),\n ...(this.conversationId && { sessionid: this.conversationId }),\n ...(this.userId && { userid: this.userId }),\n ...adapterHeaders,\n };\n await this.axiosInstance.post(url, response, { headers });\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n /**\n * @deprecated The runtime no longer returns attachment IDs from the infer\n * response — attachments are uploaded as standalone blobs and linked to the\n * session via headers. Always returns `[]`; kept for source compatibility.\n */\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, _attachmentId?: string): Promise<void> {\n void _attachmentId;\n const url = this.adapter.resolveBlobUploadUrl();\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n }\n\n /**\n * Identity headers (kebab-case) required by `/context/blob/upload` and\n * the rest of the runtime's internal endpoints introduced in v0.2.0→next.\n */\n private buildIdentityHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n 'assistant-id': this.assistantId,\n };\n if (this.conversationId) headers['session-id'] = this.conversationId;\n if (this.userId) headers['user-id'] = this.userId;\n if (this.streamId) headers['task-id'] = this.streamId;\n return headers;\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n\n /** Alias for {@link getStreamId} — same value as infer `taskid`. */\n getTaskId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;AAYrC,IAAM,cAAN,MAAkB;AAAA,EAqBhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AArBF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AAEnC;AAAA,SAAQ,WAA0B;AAClC,SAAQ,QAAa,CAAC;AACtB,SAAQ,oBAAmD;AAC3D,SAAQ,kBAAuB;AAC/B,SAAQ,SAAwB;AAOhC,SAAQ,cAAmC,CAAC;AAC5C,SAAQ,sBAAgC,CAAC;AAOvC,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,sCAAsC;AAAA,IACxD;AACA,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,cAAc;AACnB,SAAK,UAAU;AACf,SAAK,0BAA0B,QAAQ,2BAA2B;AAElE,SAAK,gBAAgB,aAAAA,QAAM,OAAO;AAClC,SAAK,cAAc,aAAa,SAAS;AAAA,MACvC,CAAC,aAAa;AAAA,MACd,OAAO,UAAU;AACf,YAAI,MAAM,UAAU,UAAU,KAAK,gBAAgB;AACjD,gBAAM,KAAK,eAAe,SAAS,gBAAgB,OAAO;AAAA,YACxD,KAAK,MAAM,OAAO;AAAA,YAClB,QAAQ,MAAM,OAAO;AAAA,YACrB,MAAM,MAAM,OAAO;AAAA,YACnB,QAAQ,MAAM,SAAS;AAAA,YACvB,cAAc,MAA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A;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,yBAAmC;AACjC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,iBAAiB,MAAY,eAAuC;AAExE,UAAM,MAAM,KAAK,QAAQ,qBAAqB;AAC9C,UAAM,iBAAiB,KAAK,QAAQ,aAAa,KAAK,CAAC;AACvD,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,QAAQ,IAAI;AAC5B,UAAM,KAAK,cAAc,KAAK,KAAK,UAAU;AAAA,MAC3C,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,GAAG;AAAA,QACH,GAAG,KAAK,qBAAqB;AAAA,MAC/B;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,uBAA+C;AACrD,UAAM,UAAkC;AAAA,MACtC,gBAAgB,KAAK;AAAA,IACvB;AACA,QAAI,KAAK,eAAgB,SAAQ,YAAY,IAAI,KAAK;AACtD,QAAI,KAAK,OAAQ,SAAQ,SAAS,IAAI,KAAK;AAC3C,QAAI,KAAK,SAAU,SAAQ,SAAS,IAAI,KAAK;AAC7C,WAAO;AAAA,EACT;AAAA,EAEA,eAAuB;AACrB,QAAI,CAAC,KAAK,UAAU;AAClB,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AACA,WAAO,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AAAA,EACpD;AAAA,EAEA,cAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,YAA2B;AACzB,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":["axios"]}
@@ -136,6 +136,32 @@ var AlquimiaSDK = class {
136
136
  this.attachments = [];
137
137
  return this;
138
138
  }
139
+ /**
140
+ * Complete a pending client-tool execution (the missing "submit half" of the
141
+ * client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's
142
+ * `/event/tool-completion`. For interactive `render_ui` surfaces `result` is
143
+ * the user's data; for display-only surfaces the SDK sends `{ shown: true }`.
144
+ * The pending call is correlated by `control_id` in the body + the
145
+ * `context-metadata` header (taskid + sessionid).
146
+ */
147
+ async submitToolResult(response) {
148
+ const url = this.adapter.resolveToolCompletionUrl?.();
149
+ if (!url) {
150
+ throw new Error(
151
+ "AlquimiaSDK: adapter does not support tool completion (resolveToolCompletionUrl missing)"
152
+ );
153
+ }
154
+ const adapterHeaders = this.adapter.getHeaders?.() ?? {};
155
+ const headers = {
156
+ "Content-Type": "application/json",
157
+ assistantid: this.assistantId,
158
+ ...this.streamId && { taskid: this.streamId },
159
+ ...this.conversationId && { sessionid: this.conversationId },
160
+ ...this.userId && { userid: this.userId },
161
+ ...adapterHeaders
162
+ };
163
+ await this.axiosInstance.post(url, response, { headers });
164
+ }
139
165
  async generateImage(query) {
140
166
  if (!this.stableDiffusionProvider) {
141
167
  throw new Error("Stable Diffusion provider not initialized");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult, type CommonAttributes } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n // Internal subscription id from infer (`taskid` on the wire).\n private streamId: string | null = null;\n private tools: any = [];\n private extraInstructions: Record<string, string> | null = null;\n private assistantConfig: any = null;\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK {\n this.extraInstructions = extraInstructions;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;\n\n const initMessage: Record<string, unknown> = {\n query,\n session_id: this.conversationId,\n user_id: this.userId,\n ...(this.extraInstructions && { extra_instructions: this.extraInstructions }),\n ...(this.assistantConfig && { config: this.assistantConfig }),\n ...(hasClientTools && {\n evaluation_strategy: {\n evaluation_strategy_id: 'native',\n tool_schemas: this.tools,\n },\n }),\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.streamId = result.taskid ?? null;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n /**\n * @deprecated The runtime no longer returns attachment IDs from the infer\n * response — attachments are uploaded as standalone blobs and linked to the\n * session via headers. Always returns `[]`; kept for source compatibility.\n */\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, _attachmentId?: string): Promise<void> {\n void _attachmentId;\n const url = this.adapter.resolveBlobUploadUrl();\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n }\n\n /**\n * Identity headers (kebab-case) required by `/context/blob/upload` and\n * the rest of the runtime's internal endpoints introduced in v0.2.0→next.\n */\n private buildIdentityHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n 'assistant-id': this.assistantId,\n };\n if (this.conversationId) headers['session-id'] = this.conversationId;\n if (this.userId) headers['user-id'] = this.userId;\n if (this.streamId) headers['task-id'] = this.streamId;\n return headers;\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n\n /** Alias for {@link getStreamId} — same value as infer `taskid`. */\n getTaskId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";AAAA,OAAO,WAA8B;AAWrC,IAAM,cAAN,MAAkB;AAAA,EAq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;","names":[]}
1
+ {"version":3,"sources":["../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult, type CommonAttributes } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\nimport type { ToolExecutionResponse } from '../genui/types';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n // Internal subscription id from infer (`taskid` on the wire).\n private streamId: string | null = null;\n private tools: any = [];\n private extraInstructions: Record<string, string> | null = null;\n private assistantConfig: any = null;\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK {\n this.extraInstructions = extraInstructions;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;\n\n const initMessage: Record<string, unknown> = {\n query,\n session_id: this.conversationId,\n user_id: this.userId,\n ...(this.extraInstructions && { extra_instructions: this.extraInstructions }),\n ...(this.assistantConfig && { config: this.assistantConfig }),\n ...(hasClientTools && {\n evaluation_strategy: {\n evaluation_strategy_id: 'native',\n tool_schemas: this.tools,\n },\n }),\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.streamId = result.taskid ?? null;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n /**\n * Complete a pending client-tool execution (the missing \"submit half\" of the\n * client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's\n * `/event/tool-completion`. For interactive `render_ui` surfaces `result` is\n * the user's data; for display-only surfaces the SDK sends `{ shown: true }`.\n * The pending call is correlated by `control_id` in the body + the\n * `context-metadata` header (taskid + sessionid).\n */\n async submitToolResult(response: ToolExecutionResponse): Promise<void> {\n const url = this.adapter.resolveToolCompletionUrl?.();\n if (!url) {\n throw new Error(\n 'AlquimiaSDK: adapter does not support tool completion (resolveToolCompletionUrl missing)'\n );\n }\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n assistantid: this.assistantId,\n ...(this.streamId && { taskid: this.streamId }),\n ...(this.conversationId && { sessionid: this.conversationId }),\n ...(this.userId && { userid: this.userId }),\n ...adapterHeaders,\n };\n await this.axiosInstance.post(url, response, { headers });\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n /**\n * @deprecated The runtime no longer returns attachment IDs from the infer\n * response — attachments are uploaded as standalone blobs and linked to the\n * session via headers. Always returns `[]`; kept for source compatibility.\n */\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, _attachmentId?: string): Promise<void> {\n void _attachmentId;\n const url = this.adapter.resolveBlobUploadUrl();\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n }\n\n /**\n * Identity headers (kebab-case) required by `/context/blob/upload` and\n * the rest of the runtime's internal endpoints introduced in v0.2.0→next.\n */\n private buildIdentityHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n 'assistant-id': this.assistantId,\n };\n if (this.conversationId) headers['session-id'] = this.conversationId;\n if (this.userId) headers['user-id'] = this.userId;\n if (this.streamId) headers['task-id'] = this.streamId;\n return headers;\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n\n /** Alias for {@link getStreamId} — same value as infer `taskid`. */\n getTaskId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";AAAA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AG;AAAA,QACH,GAAG,KAAK,qBAAqB;AAAA,MAC/B;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,uBAA+C;AACrD,UAAM,UAAkC;AAAA,MACtC,gBAAgB,KAAK;AAAA,IACvB;AACA,QAAI,KAAK,eAAgB,SAAQ,YAAY,IAAI,KAAK;AACtD,QAAI,KAAK,OAAQ,SAAQ,SAAS,IAAI,KAAK;AAC3C,QAAI,KAAK,SAAU,SAAQ,SAAS,IAAI,KAAK;AAC7C,WAAO;AAAA,EACT;AAAA,EAEA,eAAuB;AACrB,QAAI,CAAC,KAAK,UAAU;AAClB,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AACA,WAAO,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AAAA,EACpD;AAAA,EAEA,cAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,YAA2B;AACzB,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import { Transaction } from '@elastic/apm-rum';
2
2
  import { ApmSpan } from '../types/index.mjs';
3
3
  import 'ai';
4
+ import '../types-DnfWUE9V.mjs';
4
5
 
5
6
  interface APMInitializerProps {
6
7
  serviceName: string;
@@ -1,6 +1,7 @@
1
1
  import { Transaction } from '@elastic/apm-rum';
2
2
  import { ApmSpan } from '../types/index.js';
3
3
  import 'ai';
4
+ import '../types-DnfWUE9V.js';
4
5
 
5
6
  interface APMInitializerProps {
6
7
  serviceName: string;
@@ -1,5 +1,6 @@
1
1
  import { Span } from '@elastic/apm-rum';
2
2
  import { Message } from 'ai';
3
+ import { a as A2uiSurface } from '../types-DnfWUE9V.mjs';
3
4
 
4
5
  interface ITooler {
5
6
  tooler: Array<{
@@ -297,5 +298,13 @@ interface ThinkingsInferenceResponse {
297
298
  is_partial: boolean;
298
299
  };
299
300
  }
301
+ interface GenuiSurfaceItem {
302
+ controlId: string;
303
+ surface: A2uiSurface;
304
+ /** Message-count anchor: the surface renders after this many messages (chronological ordering). */
305
+ afterCount: number;
306
+ /** True once the user has submitted an interactive surface (disables it + shows a submitted state). */
307
+ submitted?: boolean;
308
+ }
300
309
 
301
- export { type AIMessageChunk, type AIMessageChunkData, type ActionResponse, type AlquimiaEventData, type AlquimiaMessage, type ApiError, type ApmSpan, type AssistantInferenceResponse, type AssistantResponseData, type AttachmentPayload, type BaseAPIConfig, type CommonAttributes, type ConversationsMap, type DocumentSearchResult, type ElevenLabsRequestSpecs, type ElevenLabsVoiceSettings, type EvaluationStrategy, type ExpertInferenceResponse, type ExtraDataContext, type IToolSpec, type ITooler, type InferInitResponse, type NativeToolsEvaluationStrategy, type OneShootEvaluationStrategy, type RatingData, type RawToolsEvaluationStrategy, type ResponseMetadata, type TTSResult, type ThinkingsInferenceResponse, type TokenUsage, type ToolEvent, ToolFactory, type ToolOutput, type ToolSummary, type Tooler, type UsageMetadata };
310
+ export { type AIMessageChunk, type AIMessageChunkData, type ActionResponse, type AlquimiaEventData, type AlquimiaMessage, type ApiError, type ApmSpan, type AssistantInferenceResponse, type AssistantResponseData, type AttachmentPayload, type BaseAPIConfig, type CommonAttributes, type ConversationsMap, type DocumentSearchResult, type ElevenLabsRequestSpecs, type ElevenLabsVoiceSettings, type EvaluationStrategy, type ExpertInferenceResponse, type ExtraDataContext, type GenuiSurfaceItem, type IToolSpec, type ITooler, type InferInitResponse, type NativeToolsEvaluationStrategy, type OneShootEvaluationStrategy, type RatingData, type RawToolsEvaluationStrategy, type ResponseMetadata, type TTSResult, type ThinkingsInferenceResponse, type TokenUsage, type ToolEvent, ToolFactory, type ToolOutput, type ToolSummary, type Tooler, type UsageMetadata };
@@ -1,5 +1,6 @@
1
1
  import { Span } from '@elastic/apm-rum';
2
2
  import { Message } from 'ai';
3
+ import { a as A2uiSurface } from '../types-DnfWUE9V.js';
3
4
 
4
5
  interface ITooler {
5
6
  tooler: Array<{
@@ -297,5 +298,13 @@ interface ThinkingsInferenceResponse {
297
298
  is_partial: boolean;
298
299
  };
299
300
  }
301
+ interface GenuiSurfaceItem {
302
+ controlId: string;
303
+ surface: A2uiSurface;
304
+ /** Message-count anchor: the surface renders after this many messages (chronological ordering). */
305
+ afterCount: number;
306
+ /** True once the user has submitted an interactive surface (disables it + shows a submitted state). */
307
+ submitted?: boolean;
308
+ }
300
309
 
301
- export { type AIMessageChunk, type AIMessageChunkData, type ActionResponse, type AlquimiaEventData, type AlquimiaMessage, type ApiError, type ApmSpan, type AssistantInferenceResponse, type AssistantResponseData, type AttachmentPayload, type BaseAPIConfig, type CommonAttributes, type ConversationsMap, type DocumentSearchResult, type ElevenLabsRequestSpecs, type ElevenLabsVoiceSettings, type EvaluationStrategy, type ExpertInferenceResponse, type ExtraDataContext, type IToolSpec, type ITooler, type InferInitResponse, type NativeToolsEvaluationStrategy, type OneShootEvaluationStrategy, type RatingData, type RawToolsEvaluationStrategy, type ResponseMetadata, type TTSResult, type ThinkingsInferenceResponse, type TokenUsage, type ToolEvent, ToolFactory, type ToolOutput, type ToolSummary, type Tooler, type UsageMetadata };
310
+ export { type AIMessageChunk, type AIMessageChunkData, type ActionResponse, type AlquimiaEventData, type AlquimiaMessage, type ApiError, type ApmSpan, type AssistantInferenceResponse, type AssistantResponseData, type AttachmentPayload, type BaseAPIConfig, type CommonAttributes, type ConversationsMap, type DocumentSearchResult, type ElevenLabsRequestSpecs, type ElevenLabsVoiceSettings, type EvaluationStrategy, type ExpertInferenceResponse, type ExtraDataContext, type GenuiSurfaceItem, type IToolSpec, type ITooler, type InferInitResponse, type NativeToolsEvaluationStrategy, type OneShootEvaluationStrategy, type RatingData, type RawToolsEvaluationStrategy, type ResponseMetadata, type TTSResult, type ThinkingsInferenceResponse, type TokenUsage, type ToolEvent, ToolFactory, type ToolOutput, type ToolSummary, type Tooler, type UsageMetadata };