@alquimia-ai/tools 2.5.0 → 2.8.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 +603 -23
- package/dist/actions/index.d.mts +1 -1
- package/dist/actions/index.d.ts +1 -1
- package/dist/adapters/fetch.d.mts +1 -0
- package/dist/adapters/fetch.d.ts +1 -0
- package/dist/adapters/fetch.js +4 -0
- package/dist/adapters/fetch.js.map +1 -1
- package/dist/adapters/fetch.mjs +4 -0
- package/dist/adapters/fetch.mjs.map +1 -1
- package/dist/adapters/index.d.mts +1 -0
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/next.d.mts +1 -0
- package/dist/adapters/next.d.ts +1 -0
- package/dist/adapters/next.js +4 -0
- package/dist/adapters/next.js.map +1 -1
- package/dist/adapters/next.mjs +4 -0
- package/dist/adapters/next.mjs.map +1 -1
- package/dist/approvals-CcnmqUkQ.d.ts +59 -0
- package/dist/approvals-dn4sd_Ot.d.mts +59 -0
- package/dist/hooks/index.d.mts +36 -5
- package/dist/hooks/index.d.ts +36 -5
- package/dist/hooks/index.js +269 -17
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +269 -17
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.d.mts +7 -0
- package/dist/next/index.d.ts +7 -0
- package/dist/next/index.js +56 -37
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +56 -37
- package/dist/next/index.mjs.map +1 -1
- package/dist/providers/index.d.mts +3 -3
- package/dist/providers/index.d.ts +3 -3
- package/dist/{providers-b5_yMyMo.d.ts → providers-J_Z9rQ3Q.d.ts} +1 -1
- package/dist/{providers-DiR9cgyo.d.mts → providers-YKiEag2L.d.mts} +1 -1
- package/dist/proxy.d.mts +2 -0
- package/dist/proxy.d.ts +2 -0
- package/dist/proxy.js +47 -37
- package/dist/proxy.js.map +1 -1
- package/dist/proxy.mjs +47 -37
- package/dist/proxy.mjs.map +1 -1
- package/dist/sdk/index.d.mts +60 -5
- package/dist/sdk/index.d.ts +60 -5
- package/dist/sdk/index.js +115 -15
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +115 -15
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/services/index.d.mts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/{type-xksRnBUW.d.ts → type-BFtGEEb4.d.ts} +45 -1
- package/dist/{type-DqX3-9QS.d.mts → type-C_sKpIM1.d.mts} +45 -1
- package/dist/types/index.d.mts +28 -5
- package/dist/types/index.d.ts +28 -5
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/{types-C-6fgK1_.d.mts → types-lOliroPw.d.mts} +1 -1
- package/dist/{types-C-6fgK1_.d.ts → types-lOliroPw.d.ts} +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/worklog/index.d.mts +3 -2
- package/dist/worklog/index.d.ts +3 -2
- package/dist/worklog/index.js +94 -2
- package/dist/worklog/index.js.map +1 -1
- package/dist/worklog/index.mjs +94 -2
- package/dist/worklog/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/sdk/index.js
CHANGED
|
@@ -44,6 +44,12 @@ var AlquimiaSDK = class {
|
|
|
44
44
|
this.streamId = null;
|
|
45
45
|
// W3C traceparent for the current turn, so infer and stream share one trace.
|
|
46
46
|
this.traceParent = null;
|
|
47
|
+
// Registry version tag resolved by the runtime for this task (v0.5.1), so
|
|
48
|
+
// the tool-completion half of the turn lands on the same agentspace version.
|
|
49
|
+
this.versionTag = null;
|
|
50
|
+
// Agentspace the runtime resolved for this task. Tool completion and
|
|
51
|
+
// approval authorize a non-admin caller against it, so it is echoed back.
|
|
52
|
+
this.agentspaceId = null;
|
|
47
53
|
this.tools = [];
|
|
48
54
|
this.extraInstructions = null;
|
|
49
55
|
this.assistantConfig = null;
|
|
@@ -124,6 +130,19 @@ var AlquimiaSDK = class {
|
|
|
124
130
|
this.userId = userId;
|
|
125
131
|
return this;
|
|
126
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Pin inference to a cached registry version. Sent as the `version_tag`
|
|
135
|
+
* query parameter, which `POST /event/infer/{assistant_id}` accepts from
|
|
136
|
+
* **runtime v0.5.2** onward; older runtimes ignore it.
|
|
137
|
+
*
|
|
138
|
+
* Works on every version: pass a versioned assistant ref
|
|
139
|
+
* (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the
|
|
140
|
+
* runtime parses the tag out of the path itself.
|
|
141
|
+
*/
|
|
142
|
+
withVersionTag(versionTag) {
|
|
143
|
+
this.versionTag = versionTag;
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
127
146
|
getEnforceCharacterization() {
|
|
128
147
|
return this.enforceCharacterization ?? true;
|
|
129
148
|
}
|
|
@@ -139,19 +158,29 @@ var AlquimiaSDK = class {
|
|
|
139
158
|
}
|
|
140
159
|
return this.whisperProvider.speechToText(audio);
|
|
141
160
|
}
|
|
142
|
-
async sendMessage(query,
|
|
161
|
+
async sendMessage(query, options = {}) {
|
|
143
162
|
if (!this.conversationId) {
|
|
144
163
|
throw new Error(
|
|
145
164
|
"Conversation not initialized. Call withConversationId() before sendMessage()"
|
|
146
165
|
);
|
|
147
166
|
}
|
|
148
|
-
const
|
|
167
|
+
const opts = typeof options === "string" ? { traceParent: options } : options;
|
|
168
|
+
if (query === void 0 && !opts.inputAudio) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
"AlquimiaSDK: sendMessage needs a query, an inputAudio blob, or both"
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const baseInferUrl = this.adapter.resolveInferUrl(this.assistantId);
|
|
174
|
+
const inferUrl = this.versionTag ? `${baseInferUrl}${baseInferUrl.includes("?") ? "&" : "?"}version_tag=${encodeURIComponent(this.versionTag)}` : baseInferUrl;
|
|
149
175
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
150
176
|
const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;
|
|
151
177
|
const initMessage = {
|
|
152
|
-
query,
|
|
178
|
+
...query !== void 0 && { query },
|
|
153
179
|
session_id: this.conversationId,
|
|
154
180
|
user_id: this.userId,
|
|
181
|
+
...opts.inputAudio && { input_audio: opts.inputAudio },
|
|
182
|
+
// Only sent when set: the runtime defaults `output_audio` to true.
|
|
183
|
+
...opts.outputAudio !== void 0 && { output_audio: opts.outputAudio },
|
|
155
184
|
...this.extraInstructions && { extra_instructions: this.extraInstructions },
|
|
156
185
|
...this.assistantConfig && { config: this.assistantConfig },
|
|
157
186
|
...hasClientTools && {
|
|
@@ -164,13 +193,15 @@ var AlquimiaSDK = class {
|
|
|
164
193
|
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
165
194
|
headers: {
|
|
166
195
|
"Content-Type": "application/json",
|
|
167
|
-
...traceParent && { "x-trace-parent": traceParent },
|
|
196
|
+
...opts.traceParent && { "x-trace-parent": opts.traceParent },
|
|
168
197
|
...adapterHeaders,
|
|
169
198
|
...this.buildIdentityHeaders()
|
|
170
199
|
}
|
|
171
200
|
})).data;
|
|
172
|
-
this.traceParent = traceParent ?? null;
|
|
201
|
+
this.traceParent = opts.traceParent ?? null;
|
|
173
202
|
this.streamId = result.taskid ?? null;
|
|
203
|
+
this.versionTag = result.versiontag ?? this.versionTag;
|
|
204
|
+
this.agentspaceId = result.agentspaceid ?? null;
|
|
174
205
|
this.attachmentResponses = result.attachments ?? [];
|
|
175
206
|
this.attachments = [];
|
|
176
207
|
return this;
|
|
@@ -190,16 +221,37 @@ var AlquimiaSDK = class {
|
|
|
190
221
|
"AlquimiaSDK: adapter does not support tool completion (resolveToolCompletionUrl missing)"
|
|
191
222
|
);
|
|
192
223
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
224
|
+
await this.axiosInstance.post(url, response, { headers: this.buildDecisionHeaders() });
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Answer a `HumanApprovalRequired` gate: POSTs a {@link ToolApprovalEvent} to
|
|
228
|
+
* the runtime's `/event/tool-approval`. `controlId` is the gate's own control
|
|
229
|
+
* id (the `HumanApprovalRequired` record's), not the parked tool call's.
|
|
230
|
+
*
|
|
231
|
+
* Never throws for a runtime refusal — each 409 means something different to
|
|
232
|
+
* the UI, so the answer comes back classified as a {@link ToolApprovalResult}.
|
|
233
|
+
* It does throw when the adapter has no approval route, which is a wiring bug
|
|
234
|
+
* rather than a runtime answer.
|
|
235
|
+
*/
|
|
236
|
+
async submitToolApproval(controlId, approved, message) {
|
|
237
|
+
const url = this.adapter.resolveToolApprovalUrl?.();
|
|
238
|
+
if (!url) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
"AlquimiaSDK: adapter does not support tool approval (resolveToolApprovalUrl missing)"
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
const event = {
|
|
244
|
+
event_class: "ToolApprovalEvent",
|
|
245
|
+
control_id: controlId,
|
|
246
|
+
result: approved,
|
|
247
|
+
...message && { message }
|
|
201
248
|
};
|
|
202
|
-
|
|
249
|
+
try {
|
|
250
|
+
await this.axiosInstance.post(url, event, { headers: this.buildDecisionHeaders() });
|
|
251
|
+
return { outcome: "accepted" };
|
|
252
|
+
} catch (error) {
|
|
253
|
+
return classifyApprovalError(error);
|
|
254
|
+
}
|
|
203
255
|
}
|
|
204
256
|
async generateImage(query) {
|
|
205
257
|
if (!this.stableDiffusionProvider) {
|
|
@@ -239,18 +291,23 @@ var AlquimiaSDK = class {
|
|
|
239
291
|
getAttachmentResponses() {
|
|
240
292
|
return this.attachmentResponses;
|
|
241
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Upload a file into the session context. Returns the runtime {@link RuntimeBlob},
|
|
296
|
+
* which is what `sendMessage`'s `inputAudio` expects for audio inference.
|
|
297
|
+
*/
|
|
242
298
|
async uploadAttachment(file, _attachmentId) {
|
|
243
299
|
const url = this.adapter.resolveBlobUploadUrl();
|
|
244
300
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
245
301
|
const formData = new FormData();
|
|
246
302
|
formData.append("file", file);
|
|
247
|
-
await this.axiosInstance.post(url, formData, {
|
|
303
|
+
const response = await this.axiosInstance.post(url, formData, {
|
|
248
304
|
headers: {
|
|
249
305
|
"Content-Type": "multipart/form-data",
|
|
250
306
|
...adapterHeaders,
|
|
251
307
|
...this.buildIdentityHeaders()
|
|
252
308
|
}
|
|
253
309
|
});
|
|
310
|
+
return response.data;
|
|
254
311
|
}
|
|
255
312
|
/**
|
|
256
313
|
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
@@ -265,6 +322,23 @@ var AlquimiaSDK = class {
|
|
|
265
322
|
if (this.streamId) headers["task-id"] = this.streamId;
|
|
266
323
|
return headers;
|
|
267
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Correlation headers for tool-completion and tool-approval: the runtime's
|
|
327
|
+
* `CommonAttributes` header aliases, with no separator. Not interchangeable
|
|
328
|
+
* with the kebab-case set in {@link buildIdentityHeaders}.
|
|
329
|
+
*/
|
|
330
|
+
buildDecisionHeaders() {
|
|
331
|
+
return {
|
|
332
|
+
"Content-Type": "application/json",
|
|
333
|
+
assistantid: this.assistantId,
|
|
334
|
+
...this.streamId && { taskid: this.streamId },
|
|
335
|
+
...this.conversationId && { sessionid: this.conversationId },
|
|
336
|
+
...this.userId && { userid: this.userId },
|
|
337
|
+
...this.agentspaceId && { agentspaceid: this.agentspaceId },
|
|
338
|
+
...this.versionTag && { versiontag: this.versionTag },
|
|
339
|
+
...this.adapter.getHeaders?.() ?? {}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
268
342
|
getUrlStream() {
|
|
269
343
|
if (!this.streamId) {
|
|
270
344
|
throw new Error("Stream ID not initialized. Call sendMessage() first");
|
|
@@ -281,6 +355,32 @@ var AlquimiaSDK = class {
|
|
|
281
355
|
getTaskId() {
|
|
282
356
|
return this.streamId;
|
|
283
357
|
}
|
|
358
|
+
/** Registry version tag resolved by the runtime for the current task, if any. */
|
|
359
|
+
getVersionTag() {
|
|
360
|
+
return this.versionTag;
|
|
361
|
+
}
|
|
362
|
+
/** Agentspace the runtime resolved for the current task, if any. */
|
|
363
|
+
getAgentspaceId() {
|
|
364
|
+
return this.agentspaceId;
|
|
365
|
+
}
|
|
284
366
|
};
|
|
367
|
+
function classifyApprovalError(error) {
|
|
368
|
+
const response = error?.response;
|
|
369
|
+
const status = response?.status;
|
|
370
|
+
const data = response?.data;
|
|
371
|
+
const rawDetail = typeof data === "string" ? data : data?.detail ?? data?.error ?? error?.message;
|
|
372
|
+
const detail = typeof rawDetail === "string" ? rawDetail : JSON.stringify(rawDetail ?? "");
|
|
373
|
+
let outcome = "error";
|
|
374
|
+
if (status === 409) {
|
|
375
|
+
if (/original channel/i.test(detail)) outcome = "wrong-channel";
|
|
376
|
+
else if (/already been recorded/i.test(detail)) outcome = "already-decided";
|
|
377
|
+
else if (/no pending approval/i.test(detail)) outcome = "not-pending";
|
|
378
|
+
} else if (status === 401 || status === 403) {
|
|
379
|
+
outcome = "forbidden";
|
|
380
|
+
} else if (status === 404) {
|
|
381
|
+
outcome = "not-found";
|
|
382
|
+
}
|
|
383
|
+
return { outcome, ...status !== void 0 && { status }, detail };
|
|
384
|
+
}
|
|
285
385
|
var alquimia_sdk_default = AlquimiaSDK;
|
|
286
386
|
//# sourceMappingURL=index.js.map
|
package/dist/sdk/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sdk/index.ts","../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["export { default as AlquimiaSDK } from './alquimia-sdk';","import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult, 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 // W3C traceparent for the current turn, so infer and stream share one trace.\n private traceParent: 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 ...(traceParent && { 'x-trace-parent': traceParent }),\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.traceParent = traceParent ?? null;\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\n const url = this.adapter.resolveStreamUrl(this.streamId);\n if (!this.traceParent) return url;\n\n // `EventSource` cannot set request headers, so the turn's traceparent rides\n // the URL. The proxy turns it back into `x-trace-parent` and does not pass\n // the param upstream; without this the stream leg — where the whole\n // inference actually happens — lands in a different trace than the infer.\n const separator = url.includes('?') ? '&' : '?';\n return `${url}${separator}trace_parent=${encodeURIComponent(this.traceParent)}`;\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n\n /** Alias for {@link getStreamId} — same value as infer `task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qB;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;AAEA,UAAM,MAAM,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AACvD,QAAI,CAAC,KAAK,YAAa,QAAO;AAM9B,UAAM,YAAY,IAAI,SAAS,GAAG,IAAI,MAAM;AAC5C,WAAO,GAAG,GAAG,GAAG,SAAS,gBAAgB,mBAAmB,KAAK,WAAW,CAAC;AAAA,EAC/E;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 {\n AttachmentPayload,\n TTSResult,\n type CommonAttributes,\n type Content,\n type RuntimeBlob,\n type ToolApprovalEvent,\n type ToolApprovalOutcome,\n type ToolApprovalResult,\n} from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\nimport type { ToolExecutionResponse } from '../genui/types';\n\n/** Per-turn options for {@link AlquimiaSDK.sendMessage}. */\nexport interface SendMessageOptions {\n /** W3C traceparent, so infer and stream share one trace. */\n traceParent?: string;\n /**\n * Audio input for this turn (runtime v0.5.1). Upload it with\n * {@link AlquimiaSDK.uploadAttachment} first and pass the blob it returns.\n * May be sent with or instead of `query`.\n */\n inputAudio?: RuntimeBlob;\n /**\n * Set to `false` to force a text-only reply from an audio-enabled agent.\n * The runtime defaults to `true`, so leaving this unset keeps its behaviour.\n */\n outputAudio?: boolean;\n}\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 // W3C traceparent for the current turn, so infer and stream share one trace.\n private traceParent: string | null = null;\n // Registry version tag resolved by the runtime for this task (v0.5.1), so\n // the tool-completion half of the turn lands on the same agentspace version.\n private versionTag: string | null = null;\n // Agentspace the runtime resolved for this task. Tool completion and\n // approval authorize a non-admin caller against it, so it is echoed back.\n private agentspaceId: 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 /**\n * Pin inference to a cached registry version. Sent as the `version_tag`\n * query parameter, which `POST /event/infer/{assistant_id}` accepts from\n * **runtime v0.5.2** onward; older runtimes ignore it.\n *\n * Works on every version: pass a versioned assistant ref\n * (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the\n * runtime parses the tag out of the path itself.\n */\n withVersionTag(versionTag: string): AlquimiaSDK {\n this.versionTag = versionTag;\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(\n query?: Content,\n options: string | SendMessageOptions = {}\n ): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n // Backwards-compat: the previous signature was sendMessage(query, traceParent?).\n const opts: SendMessageOptions =\n typeof options === 'string' ? { traceParent: options } : options;\n\n if (query === undefined && !opts.inputAudio) {\n throw new Error(\n 'AlquimiaSDK: sendMessage needs a query, an inputAudio blob, or both'\n );\n }\n\n const baseInferUrl = this.adapter.resolveInferUrl(this.assistantId);\n // `version_tag` is a query parameter on infer (runtime v0.5.2+), never a\n // header — the runtime reads it with `Query(...)`.\n const inferUrl = this.versionTag\n ? `${baseInferUrl}${baseInferUrl.includes('?') ? '&' : '?'}version_tag=${encodeURIComponent(this.versionTag)}`\n : baseInferUrl;\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 !== undefined && { query }),\n session_id: this.conversationId,\n user_id: this.userId,\n ...(opts.inputAudio && { input_audio: opts.inputAudio }),\n // Only sent when set: the runtime defaults `output_audio` to true.\n ...(opts.outputAudio !== undefined && { output_audio: opts.outputAudio }),\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 ...(opts.traceParent && { 'x-trace-parent': opts.traceParent }),\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.traceParent = opts.traceParent ?? null;\n this.streamId = result.taskid ?? null;\n this.versionTag = result.versiontag ?? this.versionTag;\n this.agentspaceId = result.agentspaceid ?? 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 await this.axiosInstance.post(url, response, { headers: this.buildDecisionHeaders() });\n }\n\n /**\n * Answer a `HumanApprovalRequired` gate: POSTs a {@link ToolApprovalEvent} to\n * the runtime's `/event/tool-approval`. `controlId` is the gate's own control\n * id (the `HumanApprovalRequired` record's), not the parked tool call's.\n *\n * Never throws for a runtime refusal — each 409 means something different to\n * the UI, so the answer comes back classified as a {@link ToolApprovalResult}.\n * It does throw when the adapter has no approval route, which is a wiring bug\n * rather than a runtime answer.\n */\n async submitToolApproval(\n controlId: string,\n approved: boolean,\n message?: string\n ): Promise<ToolApprovalResult> {\n const url = this.adapter.resolveToolApprovalUrl?.();\n if (!url) {\n throw new Error(\n 'AlquimiaSDK: adapter does not support tool approval (resolveToolApprovalUrl missing)'\n );\n }\n\n const event: ToolApprovalEvent = {\n event_class: 'ToolApprovalEvent',\n control_id: controlId,\n result: approved,\n ...(message && { message }),\n };\n\n try {\n await this.axiosInstance.post(url, event, { headers: this.buildDecisionHeaders() });\n return { outcome: 'accepted' };\n } catch (error) {\n return classifyApprovalError(error);\n }\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 /**\n * Upload a file into the session context. Returns the runtime {@link RuntimeBlob},\n * which is what `sendMessage`'s `inputAudio` expects for audio inference.\n */\n async uploadAttachment(file: File, _attachmentId?: string): Promise<RuntimeBlob> {\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 const response = await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n return response.data as RuntimeBlob;\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 /**\n * Correlation headers for tool-completion and tool-approval: the runtime's\n * `CommonAttributes` header aliases, with no separator. Not interchangeable\n * with the kebab-case set in {@link buildIdentityHeaders}.\n */\n private buildDecisionHeaders(): Record<string, string> {\n return {\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 ...(this.agentspaceId && { agentspaceid: this.agentspaceId }),\n ...(this.versionTag && { versiontag: this.versionTag }),\n ...(this.adapter.getHeaders?.() ?? {}),\n };\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n\n const url = this.adapter.resolveStreamUrl(this.streamId);\n if (!this.traceParent) return url;\n\n // `EventSource` cannot set request headers, so the turn's traceparent rides\n // the URL. The proxy turns it back into `x-trace-parent` and does not pass\n // the param upstream; without this the stream leg — where the whole\n // inference actually happens — lands in a different trace than the infer.\n const separator = url.includes('?') ? '&' : '?';\n return `${url}${separator}trace_parent=${encodeURIComponent(this.traceParent)}`;\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 /** Registry version tag resolved by the runtime for the current task, if any. */\n getVersionTag(): string | null {\n return this.versionTag;\n }\n\n /** Agentspace the runtime resolved for the current task, if any. */\n getAgentspaceId(): string | null {\n return this.agentspaceId;\n }\n}\n\n/**\n * Map a failed `/event/tool-approval` call onto an outcome. The runtime's 409s\n * share a status and differ only in `detail` (`routers/event.py`), so matching\n * the text is the contract, not a shortcut.\n */\nfunction classifyApprovalError(error: unknown): ToolApprovalResult {\n const response = (error as { response?: { status?: number; data?: unknown } })?.response;\n const status = response?.status;\n const data = response?.data as { detail?: unknown; error?: unknown } | string | undefined;\n const rawDetail =\n typeof data === 'string' ? data : data?.detail ?? data?.error ?? (error as Error)?.message;\n const detail = typeof rawDetail === 'string' ? rawDetail : JSON.stringify(rawDetail ?? '');\n\n let outcome: ToolApprovalOutcome = 'error';\n if (status === 409) {\n if (/original channel/i.test(detail)) outcome = 'wrong-channel';\n else if (/already been recorded/i.test(detail)) outcome = 'already-decided';\n else if (/no pending approval/i.test(detail)) outcome = 'not-pending';\n } else if (status === 401 || status === 403) {\n outcome = 'forbidden';\n } else if (status === 404) {\n outcome = 'not-found';\n }\n\n return { outcome, ...(status !== undefined && { status }), detail };\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;AAsCrC,IAAM,cAAN,MAAkB;AAAA,EA6BhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AA7BF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AAEnC;AAAA,SAAQ,WAA0B;AAElC;AAAA,SAAQ,cAA6B;AAGrC;AAAA;AAAA,SAAQ,aAA4B;AAGpC;AAAA;AAAA,SAAQ,eAA8B;AACtC,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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K;AAC3C,cAAU;AAAA,EACZ,WAAW,WAAW,KAAK;AACzB,cAAU;AAAA,EACZ;AAEA,SAAO,EAAE,SAAS,GAAI,WAAW,UAAa,EAAE,OAAO,GAAI,OAAO;AACpE;AAEA,IAAO,uBAAQ;","names":["axios"]}
|
package/dist/sdk/index.mjs
CHANGED
|
@@ -8,6 +8,12 @@ var AlquimiaSDK = class {
|
|
|
8
8
|
this.streamId = null;
|
|
9
9
|
// W3C traceparent for the current turn, so infer and stream share one trace.
|
|
10
10
|
this.traceParent = null;
|
|
11
|
+
// Registry version tag resolved by the runtime for this task (v0.5.1), so
|
|
12
|
+
// the tool-completion half of the turn lands on the same agentspace version.
|
|
13
|
+
this.versionTag = null;
|
|
14
|
+
// Agentspace the runtime resolved for this task. Tool completion and
|
|
15
|
+
// approval authorize a non-admin caller against it, so it is echoed back.
|
|
16
|
+
this.agentspaceId = null;
|
|
11
17
|
this.tools = [];
|
|
12
18
|
this.extraInstructions = null;
|
|
13
19
|
this.assistantConfig = null;
|
|
@@ -88,6 +94,19 @@ var AlquimiaSDK = class {
|
|
|
88
94
|
this.userId = userId;
|
|
89
95
|
return this;
|
|
90
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Pin inference to a cached registry version. Sent as the `version_tag`
|
|
99
|
+
* query parameter, which `POST /event/infer/{assistant_id}` accepts from
|
|
100
|
+
* **runtime v0.5.2** onward; older runtimes ignore it.
|
|
101
|
+
*
|
|
102
|
+
* Works on every version: pass a versioned assistant ref
|
|
103
|
+
* (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the
|
|
104
|
+
* runtime parses the tag out of the path itself.
|
|
105
|
+
*/
|
|
106
|
+
withVersionTag(versionTag) {
|
|
107
|
+
this.versionTag = versionTag;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
91
110
|
getEnforceCharacterization() {
|
|
92
111
|
return this.enforceCharacterization ?? true;
|
|
93
112
|
}
|
|
@@ -103,19 +122,29 @@ var AlquimiaSDK = class {
|
|
|
103
122
|
}
|
|
104
123
|
return this.whisperProvider.speechToText(audio);
|
|
105
124
|
}
|
|
106
|
-
async sendMessage(query,
|
|
125
|
+
async sendMessage(query, options = {}) {
|
|
107
126
|
if (!this.conversationId) {
|
|
108
127
|
throw new Error(
|
|
109
128
|
"Conversation not initialized. Call withConversationId() before sendMessage()"
|
|
110
129
|
);
|
|
111
130
|
}
|
|
112
|
-
const
|
|
131
|
+
const opts = typeof options === "string" ? { traceParent: options } : options;
|
|
132
|
+
if (query === void 0 && !opts.inputAudio) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
"AlquimiaSDK: sendMessage needs a query, an inputAudio blob, or both"
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const baseInferUrl = this.adapter.resolveInferUrl(this.assistantId);
|
|
138
|
+
const inferUrl = this.versionTag ? `${baseInferUrl}${baseInferUrl.includes("?") ? "&" : "?"}version_tag=${encodeURIComponent(this.versionTag)}` : baseInferUrl;
|
|
113
139
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
114
140
|
const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;
|
|
115
141
|
const initMessage = {
|
|
116
|
-
query,
|
|
142
|
+
...query !== void 0 && { query },
|
|
117
143
|
session_id: this.conversationId,
|
|
118
144
|
user_id: this.userId,
|
|
145
|
+
...opts.inputAudio && { input_audio: opts.inputAudio },
|
|
146
|
+
// Only sent when set: the runtime defaults `output_audio` to true.
|
|
147
|
+
...opts.outputAudio !== void 0 && { output_audio: opts.outputAudio },
|
|
119
148
|
...this.extraInstructions && { extra_instructions: this.extraInstructions },
|
|
120
149
|
...this.assistantConfig && { config: this.assistantConfig },
|
|
121
150
|
...hasClientTools && {
|
|
@@ -128,13 +157,15 @@ var AlquimiaSDK = class {
|
|
|
128
157
|
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
129
158
|
headers: {
|
|
130
159
|
"Content-Type": "application/json",
|
|
131
|
-
...traceParent && { "x-trace-parent": traceParent },
|
|
160
|
+
...opts.traceParent && { "x-trace-parent": opts.traceParent },
|
|
132
161
|
...adapterHeaders,
|
|
133
162
|
...this.buildIdentityHeaders()
|
|
134
163
|
}
|
|
135
164
|
})).data;
|
|
136
|
-
this.traceParent = traceParent ?? null;
|
|
165
|
+
this.traceParent = opts.traceParent ?? null;
|
|
137
166
|
this.streamId = result.taskid ?? null;
|
|
167
|
+
this.versionTag = result.versiontag ?? this.versionTag;
|
|
168
|
+
this.agentspaceId = result.agentspaceid ?? null;
|
|
138
169
|
this.attachmentResponses = result.attachments ?? [];
|
|
139
170
|
this.attachments = [];
|
|
140
171
|
return this;
|
|
@@ -154,16 +185,37 @@ var AlquimiaSDK = class {
|
|
|
154
185
|
"AlquimiaSDK: adapter does not support tool completion (resolveToolCompletionUrl missing)"
|
|
155
186
|
);
|
|
156
187
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
188
|
+
await this.axiosInstance.post(url, response, { headers: this.buildDecisionHeaders() });
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Answer a `HumanApprovalRequired` gate: POSTs a {@link ToolApprovalEvent} to
|
|
192
|
+
* the runtime's `/event/tool-approval`. `controlId` is the gate's own control
|
|
193
|
+
* id (the `HumanApprovalRequired` record's), not the parked tool call's.
|
|
194
|
+
*
|
|
195
|
+
* Never throws for a runtime refusal — each 409 means something different to
|
|
196
|
+
* the UI, so the answer comes back classified as a {@link ToolApprovalResult}.
|
|
197
|
+
* It does throw when the adapter has no approval route, which is a wiring bug
|
|
198
|
+
* rather than a runtime answer.
|
|
199
|
+
*/
|
|
200
|
+
async submitToolApproval(controlId, approved, message) {
|
|
201
|
+
const url = this.adapter.resolveToolApprovalUrl?.();
|
|
202
|
+
if (!url) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
"AlquimiaSDK: adapter does not support tool approval (resolveToolApprovalUrl missing)"
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
const event = {
|
|
208
|
+
event_class: "ToolApprovalEvent",
|
|
209
|
+
control_id: controlId,
|
|
210
|
+
result: approved,
|
|
211
|
+
...message && { message }
|
|
165
212
|
};
|
|
166
|
-
|
|
213
|
+
try {
|
|
214
|
+
await this.axiosInstance.post(url, event, { headers: this.buildDecisionHeaders() });
|
|
215
|
+
return { outcome: "accepted" };
|
|
216
|
+
} catch (error) {
|
|
217
|
+
return classifyApprovalError(error);
|
|
218
|
+
}
|
|
167
219
|
}
|
|
168
220
|
async generateImage(query) {
|
|
169
221
|
if (!this.stableDiffusionProvider) {
|
|
@@ -203,18 +255,23 @@ var AlquimiaSDK = class {
|
|
|
203
255
|
getAttachmentResponses() {
|
|
204
256
|
return this.attachmentResponses;
|
|
205
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Upload a file into the session context. Returns the runtime {@link RuntimeBlob},
|
|
260
|
+
* which is what `sendMessage`'s `inputAudio` expects for audio inference.
|
|
261
|
+
*/
|
|
206
262
|
async uploadAttachment(file, _attachmentId) {
|
|
207
263
|
const url = this.adapter.resolveBlobUploadUrl();
|
|
208
264
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
209
265
|
const formData = new FormData();
|
|
210
266
|
formData.append("file", file);
|
|
211
|
-
await this.axiosInstance.post(url, formData, {
|
|
267
|
+
const response = await this.axiosInstance.post(url, formData, {
|
|
212
268
|
headers: {
|
|
213
269
|
"Content-Type": "multipart/form-data",
|
|
214
270
|
...adapterHeaders,
|
|
215
271
|
...this.buildIdentityHeaders()
|
|
216
272
|
}
|
|
217
273
|
});
|
|
274
|
+
return response.data;
|
|
218
275
|
}
|
|
219
276
|
/**
|
|
220
277
|
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
@@ -229,6 +286,23 @@ var AlquimiaSDK = class {
|
|
|
229
286
|
if (this.streamId) headers["task-id"] = this.streamId;
|
|
230
287
|
return headers;
|
|
231
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Correlation headers for tool-completion and tool-approval: the runtime's
|
|
291
|
+
* `CommonAttributes` header aliases, with no separator. Not interchangeable
|
|
292
|
+
* with the kebab-case set in {@link buildIdentityHeaders}.
|
|
293
|
+
*/
|
|
294
|
+
buildDecisionHeaders() {
|
|
295
|
+
return {
|
|
296
|
+
"Content-Type": "application/json",
|
|
297
|
+
assistantid: this.assistantId,
|
|
298
|
+
...this.streamId && { taskid: this.streamId },
|
|
299
|
+
...this.conversationId && { sessionid: this.conversationId },
|
|
300
|
+
...this.userId && { userid: this.userId },
|
|
301
|
+
...this.agentspaceId && { agentspaceid: this.agentspaceId },
|
|
302
|
+
...this.versionTag && { versiontag: this.versionTag },
|
|
303
|
+
...this.adapter.getHeaders?.() ?? {}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
232
306
|
getUrlStream() {
|
|
233
307
|
if (!this.streamId) {
|
|
234
308
|
throw new Error("Stream ID not initialized. Call sendMessage() first");
|
|
@@ -245,7 +319,33 @@ var AlquimiaSDK = class {
|
|
|
245
319
|
getTaskId() {
|
|
246
320
|
return this.streamId;
|
|
247
321
|
}
|
|
322
|
+
/** Registry version tag resolved by the runtime for the current task, if any. */
|
|
323
|
+
getVersionTag() {
|
|
324
|
+
return this.versionTag;
|
|
325
|
+
}
|
|
326
|
+
/** Agentspace the runtime resolved for the current task, if any. */
|
|
327
|
+
getAgentspaceId() {
|
|
328
|
+
return this.agentspaceId;
|
|
329
|
+
}
|
|
248
330
|
};
|
|
331
|
+
function classifyApprovalError(error) {
|
|
332
|
+
const response = error?.response;
|
|
333
|
+
const status = response?.status;
|
|
334
|
+
const data = response?.data;
|
|
335
|
+
const rawDetail = typeof data === "string" ? data : data?.detail ?? data?.error ?? error?.message;
|
|
336
|
+
const detail = typeof rawDetail === "string" ? rawDetail : JSON.stringify(rawDetail ?? "");
|
|
337
|
+
let outcome = "error";
|
|
338
|
+
if (status === 409) {
|
|
339
|
+
if (/original channel/i.test(detail)) outcome = "wrong-channel";
|
|
340
|
+
else if (/already been recorded/i.test(detail)) outcome = "already-decided";
|
|
341
|
+
else if (/no pending approval/i.test(detail)) outcome = "not-pending";
|
|
342
|
+
} else if (status === 401 || status === 403) {
|
|
343
|
+
outcome = "forbidden";
|
|
344
|
+
} else if (status === 404) {
|
|
345
|
+
outcome = "not-found";
|
|
346
|
+
}
|
|
347
|
+
return { outcome, ...status !== void 0 && { status }, detail };
|
|
348
|
+
}
|
|
249
349
|
var alquimia_sdk_default = AlquimiaSDK;
|
|
250
350
|
export {
|
|
251
351
|
alquimia_sdk_default as AlquimiaSDK
|
package/dist/sdk/index.mjs.map
CHANGED
|
@@ -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';\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 // W3C traceparent for the current turn, so infer and stream share one trace.\n private traceParent: 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 ...(traceParent && { 'x-trace-parent': traceParent }),\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.traceParent = traceParent ?? null;\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\n const url = this.adapter.resolveStreamUrl(this.streamId);\n if (!this.traceParent) return url;\n\n // `EventSource` cannot set request headers, so the turn's traceparent rides\n // the URL. The proxy turns it back into `x-trace-parent` and does not pass\n // the param upstream; without this the stream leg — where the whole\n // inference actually happens — lands in a different trace than the infer.\n const separator = url.includes('?') ? '&' : '?';\n return `${url}${separator}trace_parent=${encodeURIComponent(this.traceParent)}`;\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;AAYrC,IAAM,cAAN,MAAkB;AAAA,EAuBhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AAvBF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AAEnC;AAAA,SAAQ,WAA0B;AAElC;AAAA,SAAQ,cAA6B;AACrC,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;A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;AAEA,UAAM,MAAM,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AACvD,QAAI,CAAC,KAAK,YAAa,QAAO;AAM9B,UAAM,YAAY,IAAI,SAAS,GAAG,IAAI,MAAM;AAC5C,WAAO,GAAG,GAAG,GAAG,SAAS,gBAAgB,mBAAmB,KAAK,WAAW,CAAC;AAAA,EAC/E;AAAA,EAEA,cAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,YAA2B;AACzB,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","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 {\n AttachmentPayload,\n TTSResult,\n type CommonAttributes,\n type Content,\n type RuntimeBlob,\n type ToolApprovalEvent,\n type ToolApprovalOutcome,\n type ToolApprovalResult,\n} from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\nimport type { ToolExecutionResponse } from '../genui/types';\n\n/** Per-turn options for {@link AlquimiaSDK.sendMessage}. */\nexport interface SendMessageOptions {\n /** W3C traceparent, so infer and stream share one trace. */\n traceParent?: string;\n /**\n * Audio input for this turn (runtime v0.5.1). Upload it with\n * {@link AlquimiaSDK.uploadAttachment} first and pass the blob it returns.\n * May be sent with or instead of `query`.\n */\n inputAudio?: RuntimeBlob;\n /**\n * Set to `false` to force a text-only reply from an audio-enabled agent.\n * The runtime defaults to `true`, so leaving this unset keeps its behaviour.\n */\n outputAudio?: boolean;\n}\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 // W3C traceparent for the current turn, so infer and stream share one trace.\n private traceParent: string | null = null;\n // Registry version tag resolved by the runtime for this task (v0.5.1), so\n // the tool-completion half of the turn lands on the same agentspace version.\n private versionTag: string | null = null;\n // Agentspace the runtime resolved for this task. Tool completion and\n // approval authorize a non-admin caller against it, so it is echoed back.\n private agentspaceId: 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 /**\n * Pin inference to a cached registry version. Sent as the `version_tag`\n * query parameter, which `POST /event/infer/{assistant_id}` accepts from\n * **runtime v0.5.2** onward; older runtimes ignore it.\n *\n * Works on every version: pass a versioned assistant ref\n * (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the\n * runtime parses the tag out of the path itself.\n */\n withVersionTag(versionTag: string): AlquimiaSDK {\n this.versionTag = versionTag;\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(\n query?: Content,\n options: string | SendMessageOptions = {}\n ): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n // Backwards-compat: the previous signature was sendMessage(query, traceParent?).\n const opts: SendMessageOptions =\n typeof options === 'string' ? { traceParent: options } : options;\n\n if (query === undefined && !opts.inputAudio) {\n throw new Error(\n 'AlquimiaSDK: sendMessage needs a query, an inputAudio blob, or both'\n );\n }\n\n const baseInferUrl = this.adapter.resolveInferUrl(this.assistantId);\n // `version_tag` is a query parameter on infer (runtime v0.5.2+), never a\n // header — the runtime reads it with `Query(...)`.\n const inferUrl = this.versionTag\n ? `${baseInferUrl}${baseInferUrl.includes('?') ? '&' : '?'}version_tag=${encodeURIComponent(this.versionTag)}`\n : baseInferUrl;\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 !== undefined && { query }),\n session_id: this.conversationId,\n user_id: this.userId,\n ...(opts.inputAudio && { input_audio: opts.inputAudio }),\n // Only sent when set: the runtime defaults `output_audio` to true.\n ...(opts.outputAudio !== undefined && { output_audio: opts.outputAudio }),\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 ...(opts.traceParent && { 'x-trace-parent': opts.traceParent }),\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.traceParent = opts.traceParent ?? null;\n this.streamId = result.taskid ?? null;\n this.versionTag = result.versiontag ?? this.versionTag;\n this.agentspaceId = result.agentspaceid ?? 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 await this.axiosInstance.post(url, response, { headers: this.buildDecisionHeaders() });\n }\n\n /**\n * Answer a `HumanApprovalRequired` gate: POSTs a {@link ToolApprovalEvent} to\n * the runtime's `/event/tool-approval`. `controlId` is the gate's own control\n * id (the `HumanApprovalRequired` record's), not the parked tool call's.\n *\n * Never throws for a runtime refusal — each 409 means something different to\n * the UI, so the answer comes back classified as a {@link ToolApprovalResult}.\n * It does throw when the adapter has no approval route, which is a wiring bug\n * rather than a runtime answer.\n */\n async submitToolApproval(\n controlId: string,\n approved: boolean,\n message?: string\n ): Promise<ToolApprovalResult> {\n const url = this.adapter.resolveToolApprovalUrl?.();\n if (!url) {\n throw new Error(\n 'AlquimiaSDK: adapter does not support tool approval (resolveToolApprovalUrl missing)'\n );\n }\n\n const event: ToolApprovalEvent = {\n event_class: 'ToolApprovalEvent',\n control_id: controlId,\n result: approved,\n ...(message && { message }),\n };\n\n try {\n await this.axiosInstance.post(url, event, { headers: this.buildDecisionHeaders() });\n return { outcome: 'accepted' };\n } catch (error) {\n return classifyApprovalError(error);\n }\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 /**\n * Upload a file into the session context. Returns the runtime {@link RuntimeBlob},\n * which is what `sendMessage`'s `inputAudio` expects for audio inference.\n */\n async uploadAttachment(file: File, _attachmentId?: string): Promise<RuntimeBlob> {\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 const response = await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n return response.data as RuntimeBlob;\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 /**\n * Correlation headers for tool-completion and tool-approval: the runtime's\n * `CommonAttributes` header aliases, with no separator. Not interchangeable\n * with the kebab-case set in {@link buildIdentityHeaders}.\n */\n private buildDecisionHeaders(): Record<string, string> {\n return {\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 ...(this.agentspaceId && { agentspaceid: this.agentspaceId }),\n ...(this.versionTag && { versiontag: this.versionTag }),\n ...(this.adapter.getHeaders?.() ?? {}),\n };\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n\n const url = this.adapter.resolveStreamUrl(this.streamId);\n if (!this.traceParent) return url;\n\n // `EventSource` cannot set request headers, so the turn's traceparent rides\n // the URL. The proxy turns it back into `x-trace-parent` and does not pass\n // the param upstream; without this the stream leg — where the whole\n // inference actually happens — lands in a different trace than the infer.\n const separator = url.includes('?') ? '&' : '?';\n return `${url}${separator}trace_parent=${encodeURIComponent(this.traceParent)}`;\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 /** Registry version tag resolved by the runtime for the current task, if any. */\n getVersionTag(): string | null {\n return this.versionTag;\n }\n\n /** Agentspace the runtime resolved for the current task, if any. */\n getAgentspaceId(): string | null {\n return this.agentspaceId;\n }\n}\n\n/**\n * Map a failed `/event/tool-approval` call onto an outcome. The runtime's 409s\n * share a status and differ only in `detail` (`routers/event.py`), so matching\n * the text is the contract, not a shortcut.\n */\nfunction classifyApprovalError(error: unknown): ToolApprovalResult {\n const response = (error as { response?: { status?: number; data?: unknown } })?.response;\n const status = response?.status;\n const data = response?.data as { detail?: unknown; error?: unknown } | string | undefined;\n const rawDetail =\n typeof data === 'string' ? data : data?.detail ?? data?.error ?? (error as Error)?.message;\n const detail = typeof rawDetail === 'string' ? rawDetail : JSON.stringify(rawDetail ?? '');\n\n let outcome: ToolApprovalOutcome = 'error';\n if (status === 409) {\n if (/original channel/i.test(detail)) outcome = 'wrong-channel';\n else if (/already been recorded/i.test(detail)) outcome = 'already-decided';\n else if (/no pending approval/i.test(detail)) outcome = 'not-pending';\n } else if (status === 401 || status === 403) {\n outcome = 'forbidden';\n } else if (status === 404) {\n outcome = 'not-found';\n }\n\n return { outcome, ...(status !== undefined && { status }), detail };\n}\n\nexport default AlquimiaSDK;\n"],"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