@alquimia-ai/tools 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +527 -23
- package/dist/actions/index.d.mts +1 -1
- package/dist/actions/index.d.ts +1 -1
- package/dist/hooks/index.d.mts +3 -3
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/index.js +62 -6
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +62 -6
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.js +4 -1
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +4 -1
- 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-DiR9cgyo.d.mts → providers-B4IOiGfr.d.mts} +1 -1
- package/dist/{providers-b5_yMyMo.d.ts → providers-mx21gNgZ.d.ts} +1 -1
- package/dist/proxy.js +4 -1
- package/dist/proxy.js.map +1 -1
- package/dist/proxy.mjs +4 -1
- package/dist/proxy.mjs.map +1 -1
- package/dist/sdk/index.d.mts +37 -4
- package/dist/sdk/index.d.ts +37 -4
- package/dist/sdk/index.js +43 -6
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +43 -6
- 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-DqX3-9QS.d.mts → type-61gaZga-.d.mts} +45 -1
- package/dist/{type-xksRnBUW.d.ts → type-D-JaSMkV.d.ts} +45 -1
- package/dist/types/index.d.mts +6 -4
- package/dist/types/index.d.ts +6 -4
- 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 +2 -2
- package/dist/worklog/index.d.ts +2 -2
- package/dist/worklog/index.js +19 -0
- package/dist/worklog/index.js.map +1 -1
- package/dist/worklog/index.mjs +19 -0
- package/dist/worklog/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-
|
|
2
|
-
import { i as AttachmentPayload, T as TTSResult } from '../type-
|
|
1
|
+
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-mx21gNgZ.js';
|
|
2
|
+
import { i as AttachmentPayload, T as TTSResult, j as Content, w as RuntimeBlob } from '../type-D-JaSMkV.js';
|
|
3
3
|
import { T as ToolExecutionResponse } from '../types-CMVbyEv8.js';
|
|
4
4
|
import { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters/index.js';
|
|
5
5
|
import '@elastic/apm-rum';
|
|
6
6
|
import 'ai';
|
|
7
7
|
|
|
8
|
+
/** Per-turn options for {@link AlquimiaSDK.sendMessage}. */
|
|
9
|
+
interface SendMessageOptions {
|
|
10
|
+
/** W3C traceparent, so infer and stream share one trace. */
|
|
11
|
+
traceParent?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Audio input for this turn (runtime v0.5.1). Upload it with
|
|
14
|
+
* {@link AlquimiaSDK.uploadAttachment} first and pass the blob it returns.
|
|
15
|
+
* May be sent with or instead of `query`.
|
|
16
|
+
*/
|
|
17
|
+
inputAudio?: RuntimeBlob;
|
|
18
|
+
/**
|
|
19
|
+
* Set to `false` to force a text-only reply from an audio-enabled agent.
|
|
20
|
+
* The runtime defaults to `true`, so leaving this unset keeps its behaviour.
|
|
21
|
+
*/
|
|
22
|
+
outputAudio?: boolean;
|
|
23
|
+
}
|
|
8
24
|
declare class AlquimiaSDK {
|
|
9
25
|
private adapter;
|
|
10
26
|
private assistantId;
|
|
@@ -13,6 +29,7 @@ declare class AlquimiaSDK {
|
|
|
13
29
|
private sessionId;
|
|
14
30
|
private streamId;
|
|
15
31
|
private traceParent;
|
|
32
|
+
private versionTag;
|
|
16
33
|
private tools;
|
|
17
34
|
private extraInstructions;
|
|
18
35
|
private assistantConfig;
|
|
@@ -37,10 +54,20 @@ declare class AlquimiaSDK {
|
|
|
37
54
|
withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK;
|
|
38
55
|
withAssistantConfig(assistantConfig: any): AlquimiaSDK;
|
|
39
56
|
withUserId(userId: string): AlquimiaSDK;
|
|
57
|
+
/**
|
|
58
|
+
* Pin inference to a cached registry version. Sent as the `version_tag`
|
|
59
|
+
* query parameter, which `POST /event/infer/{assistant_id}` accepts from
|
|
60
|
+
* **runtime v0.5.2** onward; older runtimes ignore it.
|
|
61
|
+
*
|
|
62
|
+
* Works on every version: pass a versioned assistant ref
|
|
63
|
+
* (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the
|
|
64
|
+
* runtime parses the tag out of the path itself.
|
|
65
|
+
*/
|
|
66
|
+
withVersionTag(versionTag: string): AlquimiaSDK;
|
|
40
67
|
getEnforceCharacterization(): boolean;
|
|
41
68
|
textToSpeech(text: string): Promise<TTSResult>;
|
|
42
69
|
speechToText(audio: string): Promise<string>;
|
|
43
|
-
sendMessage(query
|
|
70
|
+
sendMessage(query?: Content, options?: string | SendMessageOptions): Promise<AlquimiaSDK>;
|
|
44
71
|
/**
|
|
45
72
|
* Complete a pending client-tool execution (the missing "submit half" of the
|
|
46
73
|
* client-tool loop). POSTs a {@link ToolExecutionResponse} to the runtime's
|
|
@@ -61,7 +88,11 @@ declare class AlquimiaSDK {
|
|
|
61
88
|
* session via headers. Always returns `[]`; kept for source compatibility.
|
|
62
89
|
*/
|
|
63
90
|
getAttachmentResponses(): string[];
|
|
64
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Upload a file into the session context. Returns the runtime {@link RuntimeBlob},
|
|
93
|
+
* which is what `sendMessage`'s `inputAudio` expects for audio inference.
|
|
94
|
+
*/
|
|
95
|
+
uploadAttachment(file: File, _attachmentId?: string): Promise<RuntimeBlob>;
|
|
65
96
|
/**
|
|
66
97
|
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
67
98
|
* the rest of the runtime's internal endpoints introduced in v0.2.0→next.
|
|
@@ -71,6 +102,8 @@ declare class AlquimiaSDK {
|
|
|
71
102
|
getStreamId(): string | null;
|
|
72
103
|
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
73
104
|
getTaskId(): string | null;
|
|
105
|
+
/** Registry version tag resolved by the runtime for the current task, if any. */
|
|
106
|
+
getVersionTag(): string | null;
|
|
74
107
|
}
|
|
75
108
|
|
|
76
109
|
export { AlquimiaSDK };
|
package/dist/sdk/index.js
CHANGED
|
@@ -44,6 +44,9 @@ 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;
|
|
47
50
|
this.tools = [];
|
|
48
51
|
this.extraInstructions = null;
|
|
49
52
|
this.assistantConfig = null;
|
|
@@ -124,6 +127,19 @@ var AlquimiaSDK = class {
|
|
|
124
127
|
this.userId = userId;
|
|
125
128
|
return this;
|
|
126
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Pin inference to a cached registry version. Sent as the `version_tag`
|
|
132
|
+
* query parameter, which `POST /event/infer/{assistant_id}` accepts from
|
|
133
|
+
* **runtime v0.5.2** onward; older runtimes ignore it.
|
|
134
|
+
*
|
|
135
|
+
* Works on every version: pass a versioned assistant ref
|
|
136
|
+
* (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the
|
|
137
|
+
* runtime parses the tag out of the path itself.
|
|
138
|
+
*/
|
|
139
|
+
withVersionTag(versionTag) {
|
|
140
|
+
this.versionTag = versionTag;
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
127
143
|
getEnforceCharacterization() {
|
|
128
144
|
return this.enforceCharacterization ?? true;
|
|
129
145
|
}
|
|
@@ -139,19 +155,29 @@ var AlquimiaSDK = class {
|
|
|
139
155
|
}
|
|
140
156
|
return this.whisperProvider.speechToText(audio);
|
|
141
157
|
}
|
|
142
|
-
async sendMessage(query,
|
|
158
|
+
async sendMessage(query, options = {}) {
|
|
143
159
|
if (!this.conversationId) {
|
|
144
160
|
throw new Error(
|
|
145
161
|
"Conversation not initialized. Call withConversationId() before sendMessage()"
|
|
146
162
|
);
|
|
147
163
|
}
|
|
148
|
-
const
|
|
164
|
+
const opts = typeof options === "string" ? { traceParent: options } : options;
|
|
165
|
+
if (query === void 0 && !opts.inputAudio) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
"AlquimiaSDK: sendMessage needs a query, an inputAudio blob, or both"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
const baseInferUrl = this.adapter.resolveInferUrl(this.assistantId);
|
|
171
|
+
const inferUrl = this.versionTag ? `${baseInferUrl}${baseInferUrl.includes("?") ? "&" : "?"}version_tag=${encodeURIComponent(this.versionTag)}` : baseInferUrl;
|
|
149
172
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
150
173
|
const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;
|
|
151
174
|
const initMessage = {
|
|
152
|
-
query,
|
|
175
|
+
...query !== void 0 && { query },
|
|
153
176
|
session_id: this.conversationId,
|
|
154
177
|
user_id: this.userId,
|
|
178
|
+
...opts.inputAudio && { input_audio: opts.inputAudio },
|
|
179
|
+
// Only sent when set: the runtime defaults `output_audio` to true.
|
|
180
|
+
...opts.outputAudio !== void 0 && { output_audio: opts.outputAudio },
|
|
155
181
|
...this.extraInstructions && { extra_instructions: this.extraInstructions },
|
|
156
182
|
...this.assistantConfig && { config: this.assistantConfig },
|
|
157
183
|
...hasClientTools && {
|
|
@@ -164,13 +190,14 @@ var AlquimiaSDK = class {
|
|
|
164
190
|
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
165
191
|
headers: {
|
|
166
192
|
"Content-Type": "application/json",
|
|
167
|
-
...traceParent && { "x-trace-parent": traceParent },
|
|
193
|
+
...opts.traceParent && { "x-trace-parent": opts.traceParent },
|
|
168
194
|
...adapterHeaders,
|
|
169
195
|
...this.buildIdentityHeaders()
|
|
170
196
|
}
|
|
171
197
|
})).data;
|
|
172
|
-
this.traceParent = traceParent ?? null;
|
|
198
|
+
this.traceParent = opts.traceParent ?? null;
|
|
173
199
|
this.streamId = result.taskid ?? null;
|
|
200
|
+
this.versionTag = result.versiontag ?? this.versionTag;
|
|
174
201
|
this.attachmentResponses = result.attachments ?? [];
|
|
175
202
|
this.attachments = [];
|
|
176
203
|
return this;
|
|
@@ -197,6 +224,7 @@ var AlquimiaSDK = class {
|
|
|
197
224
|
...this.streamId && { taskid: this.streamId },
|
|
198
225
|
...this.conversationId && { sessionid: this.conversationId },
|
|
199
226
|
...this.userId && { userid: this.userId },
|
|
227
|
+
...this.versionTag && { versiontag: this.versionTag },
|
|
200
228
|
...adapterHeaders
|
|
201
229
|
};
|
|
202
230
|
await this.axiosInstance.post(url, response, { headers });
|
|
@@ -239,18 +267,23 @@ var AlquimiaSDK = class {
|
|
|
239
267
|
getAttachmentResponses() {
|
|
240
268
|
return this.attachmentResponses;
|
|
241
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Upload a file into the session context. Returns the runtime {@link RuntimeBlob},
|
|
272
|
+
* which is what `sendMessage`'s `inputAudio` expects for audio inference.
|
|
273
|
+
*/
|
|
242
274
|
async uploadAttachment(file, _attachmentId) {
|
|
243
275
|
const url = this.adapter.resolveBlobUploadUrl();
|
|
244
276
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
245
277
|
const formData = new FormData();
|
|
246
278
|
formData.append("file", file);
|
|
247
|
-
await this.axiosInstance.post(url, formData, {
|
|
279
|
+
const response = await this.axiosInstance.post(url, formData, {
|
|
248
280
|
headers: {
|
|
249
281
|
"Content-Type": "multipart/form-data",
|
|
250
282
|
...adapterHeaders,
|
|
251
283
|
...this.buildIdentityHeaders()
|
|
252
284
|
}
|
|
253
285
|
});
|
|
286
|
+
return response.data;
|
|
254
287
|
}
|
|
255
288
|
/**
|
|
256
289
|
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
@@ -281,6 +314,10 @@ var AlquimiaSDK = class {
|
|
|
281
314
|
getTaskId() {
|
|
282
315
|
return this.streamId;
|
|
283
316
|
}
|
|
317
|
+
/** Registry version tag resolved by the runtime for the current task, if any. */
|
|
318
|
+
getVersionTag() {
|
|
319
|
+
return this.versionTag;
|
|
320
|
+
}
|
|
284
321
|
};
|
|
285
322
|
var alquimia_sdk_default = AlquimiaSDK;
|
|
286
323
|
//# 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 `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,EAuBhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AAvBF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AAEnC;AAAA,SAAQ,WAA0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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} 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 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.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 ...(this.versionTag && { versiontag: this.versionTag }),\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 /**\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 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 {\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AI,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;AAAA;AAAA,EAGA,gBAA+B;AAC7B,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":["axios"]}
|
package/dist/sdk/index.mjs
CHANGED
|
@@ -8,6 +8,9 @@ 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;
|
|
11
14
|
this.tools = [];
|
|
12
15
|
this.extraInstructions = null;
|
|
13
16
|
this.assistantConfig = null;
|
|
@@ -88,6 +91,19 @@ var AlquimiaSDK = class {
|
|
|
88
91
|
this.userId = userId;
|
|
89
92
|
return this;
|
|
90
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Pin inference to a cached registry version. Sent as the `version_tag`
|
|
96
|
+
* query parameter, which `POST /event/infer/{assistant_id}` accepts from
|
|
97
|
+
* **runtime v0.5.2** onward; older runtimes ignore it.
|
|
98
|
+
*
|
|
99
|
+
* Works on every version: pass a versioned assistant ref
|
|
100
|
+
* (`<agentspace>/<assistant>[:<tag>]`) as the `assistantId` instead — the
|
|
101
|
+
* runtime parses the tag out of the path itself.
|
|
102
|
+
*/
|
|
103
|
+
withVersionTag(versionTag) {
|
|
104
|
+
this.versionTag = versionTag;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
91
107
|
getEnforceCharacterization() {
|
|
92
108
|
return this.enforceCharacterization ?? true;
|
|
93
109
|
}
|
|
@@ -103,19 +119,29 @@ var AlquimiaSDK = class {
|
|
|
103
119
|
}
|
|
104
120
|
return this.whisperProvider.speechToText(audio);
|
|
105
121
|
}
|
|
106
|
-
async sendMessage(query,
|
|
122
|
+
async sendMessage(query, options = {}) {
|
|
107
123
|
if (!this.conversationId) {
|
|
108
124
|
throw new Error(
|
|
109
125
|
"Conversation not initialized. Call withConversationId() before sendMessage()"
|
|
110
126
|
);
|
|
111
127
|
}
|
|
112
|
-
const
|
|
128
|
+
const opts = typeof options === "string" ? { traceParent: options } : options;
|
|
129
|
+
if (query === void 0 && !opts.inputAudio) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
"AlquimiaSDK: sendMessage needs a query, an inputAudio blob, or both"
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const baseInferUrl = this.adapter.resolveInferUrl(this.assistantId);
|
|
135
|
+
const inferUrl = this.versionTag ? `${baseInferUrl}${baseInferUrl.includes("?") ? "&" : "?"}version_tag=${encodeURIComponent(this.versionTag)}` : baseInferUrl;
|
|
113
136
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
114
137
|
const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;
|
|
115
138
|
const initMessage = {
|
|
116
|
-
query,
|
|
139
|
+
...query !== void 0 && { query },
|
|
117
140
|
session_id: this.conversationId,
|
|
118
141
|
user_id: this.userId,
|
|
142
|
+
...opts.inputAudio && { input_audio: opts.inputAudio },
|
|
143
|
+
// Only sent when set: the runtime defaults `output_audio` to true.
|
|
144
|
+
...opts.outputAudio !== void 0 && { output_audio: opts.outputAudio },
|
|
119
145
|
...this.extraInstructions && { extra_instructions: this.extraInstructions },
|
|
120
146
|
...this.assistantConfig && { config: this.assistantConfig },
|
|
121
147
|
...hasClientTools && {
|
|
@@ -128,13 +154,14 @@ var AlquimiaSDK = class {
|
|
|
128
154
|
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
129
155
|
headers: {
|
|
130
156
|
"Content-Type": "application/json",
|
|
131
|
-
...traceParent && { "x-trace-parent": traceParent },
|
|
157
|
+
...opts.traceParent && { "x-trace-parent": opts.traceParent },
|
|
132
158
|
...adapterHeaders,
|
|
133
159
|
...this.buildIdentityHeaders()
|
|
134
160
|
}
|
|
135
161
|
})).data;
|
|
136
|
-
this.traceParent = traceParent ?? null;
|
|
162
|
+
this.traceParent = opts.traceParent ?? null;
|
|
137
163
|
this.streamId = result.taskid ?? null;
|
|
164
|
+
this.versionTag = result.versiontag ?? this.versionTag;
|
|
138
165
|
this.attachmentResponses = result.attachments ?? [];
|
|
139
166
|
this.attachments = [];
|
|
140
167
|
return this;
|
|
@@ -161,6 +188,7 @@ var AlquimiaSDK = class {
|
|
|
161
188
|
...this.streamId && { taskid: this.streamId },
|
|
162
189
|
...this.conversationId && { sessionid: this.conversationId },
|
|
163
190
|
...this.userId && { userid: this.userId },
|
|
191
|
+
...this.versionTag && { versiontag: this.versionTag },
|
|
164
192
|
...adapterHeaders
|
|
165
193
|
};
|
|
166
194
|
await this.axiosInstance.post(url, response, { headers });
|
|
@@ -203,18 +231,23 @@ var AlquimiaSDK = class {
|
|
|
203
231
|
getAttachmentResponses() {
|
|
204
232
|
return this.attachmentResponses;
|
|
205
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Upload a file into the session context. Returns the runtime {@link RuntimeBlob},
|
|
236
|
+
* which is what `sendMessage`'s `inputAudio` expects for audio inference.
|
|
237
|
+
*/
|
|
206
238
|
async uploadAttachment(file, _attachmentId) {
|
|
207
239
|
const url = this.adapter.resolveBlobUploadUrl();
|
|
208
240
|
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
209
241
|
const formData = new FormData();
|
|
210
242
|
formData.append("file", file);
|
|
211
|
-
await this.axiosInstance.post(url, formData, {
|
|
243
|
+
const response = await this.axiosInstance.post(url, formData, {
|
|
212
244
|
headers: {
|
|
213
245
|
"Content-Type": "multipart/form-data",
|
|
214
246
|
...adapterHeaders,
|
|
215
247
|
...this.buildIdentityHeaders()
|
|
216
248
|
}
|
|
217
249
|
});
|
|
250
|
+
return response.data;
|
|
218
251
|
}
|
|
219
252
|
/**
|
|
220
253
|
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
@@ -245,6 +278,10 @@ var AlquimiaSDK = class {
|
|
|
245
278
|
getTaskId() {
|
|
246
279
|
return this.streamId;
|
|
247
280
|
}
|
|
281
|
+
/** Registry version tag resolved by the runtime for the current task, if any. */
|
|
282
|
+
getVersionTag() {
|
|
283
|
+
return this.versionTag;
|
|
284
|
+
}
|
|
248
285
|
};
|
|
249
286
|
var alquimia_sdk_default = AlquimiaSDK;
|
|
250
287
|
export {
|
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,QAA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AAkC;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":[]}
|
|
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} 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 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.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 ...(this.versionTag && { versiontag: this.versionTag }),\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 /**\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 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\nexport default AlquimiaSDK;\n"],"mappings":";AAAA,OAAO,WAA8B;AAmCrC,IAAM,cAAN,MAAkB;AAAA,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ACvE;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;AAAA;AAAA,EAGA,gBAA+B;AAC7B,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":[]}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -221,8 +221,52 @@ interface CommonAttributes {
|
|
|
221
221
|
channelid?: string | null;
|
|
222
222
|
depth?: string;
|
|
223
223
|
attachments?: string[];
|
|
224
|
+
/** Registry version the runtime resolved for this task (runtime v0.5.1). */
|
|
225
|
+
versiontag?: string | null;
|
|
224
226
|
}
|
|
225
227
|
type InferInitResponse = CommonAttributes;
|
|
228
|
+
/** A text block in a multimodal `query` (runtime `TextContentPart`). */
|
|
229
|
+
interface TextContentPart {
|
|
230
|
+
type: 'text';
|
|
231
|
+
text: string;
|
|
232
|
+
}
|
|
233
|
+
/** An image block in a multimodal `query` (runtime `ImageContentPart`). */
|
|
234
|
+
interface ImageContentPart {
|
|
235
|
+
type: 'image_url';
|
|
236
|
+
image_url: {
|
|
237
|
+
url: string;
|
|
238
|
+
detail?: 'auto' | 'low' | 'high';
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Catch-all for content blocks the runtime does not model explicitly. It
|
|
243
|
+
* round-trips unknown provider blocks rather than failing validation.
|
|
244
|
+
*/
|
|
245
|
+
interface NonStandardContentPart {
|
|
246
|
+
type: 'non_standard';
|
|
247
|
+
value?: Record<string, unknown>;
|
|
248
|
+
}
|
|
249
|
+
type ContentPart = TextContentPart | ImageContentPart | NonStandardContentPart;
|
|
250
|
+
/**
|
|
251
|
+
* An inference `query`: either plain text, or an OpenAI-style list of content
|
|
252
|
+
* parts for multimodal input.
|
|
253
|
+
*/
|
|
254
|
+
type Content = string | ContentPart[];
|
|
255
|
+
/**
|
|
256
|
+
* A blob held in the session context. Returned by `POST /context/blob/upload`
|
|
257
|
+
* and accepted as `input_audio` on infer (runtime v0.5.1).
|
|
258
|
+
*/
|
|
259
|
+
interface RuntimeBlob {
|
|
260
|
+
blob_id: string;
|
|
261
|
+
filename: string;
|
|
262
|
+
content_size: number;
|
|
263
|
+
content_type?: string | null;
|
|
264
|
+
checksum?: string | null;
|
|
265
|
+
created_at?: number | null;
|
|
266
|
+
expires_at?: number | null;
|
|
267
|
+
/** Base64-encoded content. Populated by channel ingest, not by blob upload. */
|
|
268
|
+
data_base64?: string | null;
|
|
269
|
+
}
|
|
226
270
|
/**
|
|
227
271
|
* Native-tools evaluation strategy. Wraps the client-side tool schemas
|
|
228
272
|
* the SDK previously sent at the top level of the infer payload.
|
|
@@ -309,4 +353,4 @@ interface GenuiSurfaceItem {
|
|
|
309
353
|
dismissedWith?: string;
|
|
310
354
|
}
|
|
311
355
|
|
|
312
|
-
export { type ApmSpan as A, type BaseAPIConfig as B, type CommonAttributes as C, type DocumentSearchResult as D, type ElevenLabsRequestSpecs as E, type GenuiSurfaceItem as G, type IToolSpec as I, type NativeToolsEvaluationStrategy as N, type OneShootEvaluationStrategy as O, type RatingData as R, type TTSResult as T, type UsageMetadata as U, type AIMessageChunk as a, type AIMessageChunkData as b, type ActionResponse as c, type AlquimiaEventData as d, type AlquimiaMessage as e, type ApiError as f, type AssistantInferenceResponse as g, type AssistantResponseData as h, type AttachmentPayload as i, type
|
|
356
|
+
export { type ApmSpan as A, type BaseAPIConfig as B, type CommonAttributes as C, type DocumentSearchResult as D, type ElevenLabsRequestSpecs as E, type ToolEvent as F, type GenuiSurfaceItem as G, ToolFactory as H, type IToolSpec as I, type ToolOutput as J, type ToolSummary as K, type Tooler as L, type NativeToolsEvaluationStrategy as N, type OneShootEvaluationStrategy as O, type RatingData as R, type TTSResult as T, type UsageMetadata as U, type AIMessageChunk as a, type AIMessageChunkData as b, type ActionResponse as c, type AlquimiaEventData as d, type AlquimiaMessage as e, type ApiError as f, type AssistantInferenceResponse as g, type AssistantResponseData as h, type AttachmentPayload as i, type Content as j, type ContentPart as k, type ConversationsMap as l, type ElevenLabsVoiceSettings as m, type EvaluationStrategy as n, type ExpertInferenceResponse as o, type ExtraDataContext as p, type ITooler as q, type ImageContentPart as r, type InferInitResponse as s, type NonStandardContentPart as t, type RawToolsEvaluationStrategy as u, type ResponseMetadata as v, type RuntimeBlob as w, type TextContentPart as x, type ThinkingsInferenceResponse as y, type TokenUsage as z };
|
|
@@ -221,8 +221,52 @@ interface CommonAttributes {
|
|
|
221
221
|
channelid?: string | null;
|
|
222
222
|
depth?: string;
|
|
223
223
|
attachments?: string[];
|
|
224
|
+
/** Registry version the runtime resolved for this task (runtime v0.5.1). */
|
|
225
|
+
versiontag?: string | null;
|
|
224
226
|
}
|
|
225
227
|
type InferInitResponse = CommonAttributes;
|
|
228
|
+
/** A text block in a multimodal `query` (runtime `TextContentPart`). */
|
|
229
|
+
interface TextContentPart {
|
|
230
|
+
type: 'text';
|
|
231
|
+
text: string;
|
|
232
|
+
}
|
|
233
|
+
/** An image block in a multimodal `query` (runtime `ImageContentPart`). */
|
|
234
|
+
interface ImageContentPart {
|
|
235
|
+
type: 'image_url';
|
|
236
|
+
image_url: {
|
|
237
|
+
url: string;
|
|
238
|
+
detail?: 'auto' | 'low' | 'high';
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Catch-all for content blocks the runtime does not model explicitly. It
|
|
243
|
+
* round-trips unknown provider blocks rather than failing validation.
|
|
244
|
+
*/
|
|
245
|
+
interface NonStandardContentPart {
|
|
246
|
+
type: 'non_standard';
|
|
247
|
+
value?: Record<string, unknown>;
|
|
248
|
+
}
|
|
249
|
+
type ContentPart = TextContentPart | ImageContentPart | NonStandardContentPart;
|
|
250
|
+
/**
|
|
251
|
+
* An inference `query`: either plain text, or an OpenAI-style list of content
|
|
252
|
+
* parts for multimodal input.
|
|
253
|
+
*/
|
|
254
|
+
type Content = string | ContentPart[];
|
|
255
|
+
/**
|
|
256
|
+
* A blob held in the session context. Returned by `POST /context/blob/upload`
|
|
257
|
+
* and accepted as `input_audio` on infer (runtime v0.5.1).
|
|
258
|
+
*/
|
|
259
|
+
interface RuntimeBlob {
|
|
260
|
+
blob_id: string;
|
|
261
|
+
filename: string;
|
|
262
|
+
content_size: number;
|
|
263
|
+
content_type?: string | null;
|
|
264
|
+
checksum?: string | null;
|
|
265
|
+
created_at?: number | null;
|
|
266
|
+
expires_at?: number | null;
|
|
267
|
+
/** Base64-encoded content. Populated by channel ingest, not by blob upload. */
|
|
268
|
+
data_base64?: string | null;
|
|
269
|
+
}
|
|
226
270
|
/**
|
|
227
271
|
* Native-tools evaluation strategy. Wraps the client-side tool schemas
|
|
228
272
|
* the SDK previously sent at the top level of the infer payload.
|
|
@@ -309,4 +353,4 @@ interface GenuiSurfaceItem {
|
|
|
309
353
|
dismissedWith?: string;
|
|
310
354
|
}
|
|
311
355
|
|
|
312
|
-
export { type ApmSpan as A, type BaseAPIConfig as B, type CommonAttributes as C, type DocumentSearchResult as D, type ElevenLabsRequestSpecs as E, type GenuiSurfaceItem as G, type IToolSpec as I, type NativeToolsEvaluationStrategy as N, type OneShootEvaluationStrategy as O, type RatingData as R, type TTSResult as T, type UsageMetadata as U, type AIMessageChunk as a, type AIMessageChunkData as b, type ActionResponse as c, type AlquimiaEventData as d, type AlquimiaMessage as e, type ApiError as f, type AssistantInferenceResponse as g, type AssistantResponseData as h, type AttachmentPayload as i, type
|
|
356
|
+
export { type ApmSpan as A, type BaseAPIConfig as B, type CommonAttributes as C, type DocumentSearchResult as D, type ElevenLabsRequestSpecs as E, type ToolEvent as F, type GenuiSurfaceItem as G, ToolFactory as H, type IToolSpec as I, type ToolOutput as J, type ToolSummary as K, type Tooler as L, type NativeToolsEvaluationStrategy as N, type OneShootEvaluationStrategy as O, type RatingData as R, type TTSResult as T, type UsageMetadata as U, type AIMessageChunk as a, type AIMessageChunkData as b, type ActionResponse as c, type AlquimiaEventData as d, type AlquimiaMessage as e, type ApiError as f, type AssistantInferenceResponse as g, type AssistantResponseData as h, type AttachmentPayload as i, type Content as j, type ContentPart as k, type ConversationsMap as l, type ElevenLabsVoiceSettings as m, type EvaluationStrategy as n, type ExpertInferenceResponse as o, type ExtraDataContext as p, type ITooler as q, type ImageContentPart as r, type InferInitResponse as s, type NonStandardContentPart as t, type RawToolsEvaluationStrategy as u, type ResponseMetadata as v, type RuntimeBlob as w, type TextContentPart as x, type ThinkingsInferenceResponse as y, type TokenUsage as z };
|