@alquimia-ai/tools 1.13.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.d.mts +2 -17
- package/dist/actions/index.d.ts +2 -17
- package/dist/actions/index.js +47 -152
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/index.mjs +47 -152
- package/dist/actions/index.mjs.map +1 -1
- package/dist/adapters/fetch.d.mts +12 -0
- package/dist/adapters/fetch.d.ts +12 -0
- package/dist/adapters/fetch.js +44 -0
- package/dist/adapters/fetch.js.map +1 -0
- package/dist/adapters/fetch.mjs +23 -0
- package/dist/adapters/fetch.mjs.map +1 -0
- package/dist/adapters/index.d.mts +11 -0
- package/dist/adapters/index.d.ts +11 -0
- package/dist/adapters/index.js +19 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +1 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/adapters/next.d.mts +10 -0
- package/dist/adapters/next.d.ts +10 -0
- package/dist/adapters/next.js +42 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/next.mjs +21 -0
- package/dist/adapters/next.mjs.map +1 -0
- package/dist/hooks/index.d.mts +23 -4
- package/dist/hooks/index.d.ts +23 -4
- package/dist/hooks/index.js +292 -57
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +283 -58
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.d.mts +46 -0
- package/dist/next/index.d.ts +46 -0
- package/dist/next/index.js +337 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/index.mjs +314 -0
- package/dist/next/index.mjs.map +1 -0
- package/dist/providers/index.d.mts +7 -3
- package/dist/providers/index.d.ts +7 -3
- package/dist/providers/index.js +15 -14
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +15 -14
- package/dist/providers/index.mjs.map +1 -1
- package/dist/proxy.d.mts +15 -0
- package/dist/proxy.d.ts +15 -0
- package/dist/proxy.js +170 -0
- package/dist/proxy.js.map +1 -0
- package/dist/proxy.mjs +149 -0
- package/dist/proxy.mjs.map +1 -0
- package/dist/sdk/index.d.mts +22 -20
- package/dist/sdk/index.d.ts +22 -20
- package/dist/sdk/index.js +85 -66
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +85 -66
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/services/index.d.mts +25 -3
- package/dist/services/index.d.ts +25 -3
- package/dist/session.action-DirvOWt0.d.mts +3 -0
- package/dist/session.action-DirvOWt0.d.ts +3 -0
- package/dist/types/index.d.mts +79 -18
- package/dist/types/index.d.ts +79 -18
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/package.json +35 -5
- package/dist/providers/elastic/index.d.mts +0 -23
- package/dist/providers/elastic/index.d.ts +0 -23
- package/dist/providers/elastic/index.js +0 -102
- package/dist/providers/elastic/index.js.map +0 -1
- package/dist/providers/elastic/index.mjs +0 -69
- package/dist/providers/elastic/index.mjs.map +0 -1
- package/dist/services/apm/index.d.mts +0 -26
- package/dist/services/apm/index.d.ts +0 -26
- package/dist/services/apm/index.js +0 -86
- package/dist/services/apm/index.js.map +0 -1
- package/dist/services/apm/index.mjs +0 -63
- package/dist/services/apm/index.mjs.map +0 -1
package/dist/sdk/index.js
CHANGED
|
@@ -37,38 +37,40 @@ module.exports = __toCommonJS(sdk_exports);
|
|
|
37
37
|
// src/sdk/alquimia-sdk.ts
|
|
38
38
|
var import_axios = __toESM(require("axios"));
|
|
39
39
|
var AlquimiaSDK = class {
|
|
40
|
-
constructor(
|
|
40
|
+
constructor(assistantId, adapter, options = {}) {
|
|
41
41
|
this.conversationId = null;
|
|
42
42
|
this.sessionId = null;
|
|
43
|
+
// Internal subscription id from infer (`taskid` on the wire).
|
|
43
44
|
this.streamId = null;
|
|
44
|
-
this.evaluationStrategy = null;
|
|
45
45
|
this.tools = [];
|
|
46
|
-
this.
|
|
46
|
+
this.extraInstructions = null;
|
|
47
47
|
this.assistantConfig = null;
|
|
48
|
-
this.forceProfile = {};
|
|
49
48
|
this.userId = null;
|
|
50
49
|
this.attachments = [];
|
|
51
50
|
this.attachmentResponses = [];
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
if (!assistantId) {
|
|
52
|
+
throw new Error("AlquimiaSDK: assistantId is required");
|
|
53
|
+
}
|
|
54
|
+
if (!adapter) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()"
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
this.assistantId = assistantId;
|
|
60
|
+
this.adapter = adapter;
|
|
61
|
+
this.enforceCharacterization = options.enforceCharacterization ?? true;
|
|
54
62
|
this.axiosInstance = import_axios.default.create();
|
|
55
63
|
this.axiosInstance.interceptors.response.use(
|
|
56
64
|
(response) => response,
|
|
57
65
|
async (error) => {
|
|
58
|
-
if (error.response?.status) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
data: error.config.data,
|
|
67
|
-
status: error.response.status,
|
|
68
|
-
responseData: error.response.data
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
}
|
|
66
|
+
if (error.response?.status && this.loggerProvider) {
|
|
67
|
+
await this.loggerProvider.logError("Server Error", error, {
|
|
68
|
+
url: error.config.url,
|
|
69
|
+
method: error.config.method,
|
|
70
|
+
data: error.config.data,
|
|
71
|
+
status: error.response.status,
|
|
72
|
+
responseData: error.response.data
|
|
73
|
+
});
|
|
72
74
|
}
|
|
73
75
|
return Promise.reject(error);
|
|
74
76
|
}
|
|
@@ -76,16 +78,7 @@ var AlquimiaSDK = class {
|
|
|
76
78
|
this.textToSpeech = this.textToSpeech.bind(this);
|
|
77
79
|
this.speechToText = this.speechToText.bind(this);
|
|
78
80
|
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
apiKey,
|
|
82
|
-
chatUrl: `${inferUrl}/chat/${assistantId}`,
|
|
83
|
-
streamUrl: `${streamUrl}`,
|
|
84
|
-
attachmentUrl,
|
|
85
|
-
assistantId
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
widthConversationId(conversationId) {
|
|
81
|
+
withConversationId(conversationId) {
|
|
89
82
|
this.conversationId = conversationId;
|
|
90
83
|
return this;
|
|
91
84
|
}
|
|
@@ -113,22 +106,12 @@ var AlquimiaSDK = class {
|
|
|
113
106
|
this.loggerProvider = provider;
|
|
114
107
|
return this;
|
|
115
108
|
}
|
|
116
|
-
getEnforceCharacterization() {
|
|
117
|
-
return this.enforceCharacterization ?? true;
|
|
118
|
-
}
|
|
119
|
-
getEvaluationStrategy() {
|
|
120
|
-
return this.evaluationStrategy;
|
|
121
|
-
}
|
|
122
109
|
withTools(tools) {
|
|
123
110
|
this.tools = tools;
|
|
124
111
|
return this;
|
|
125
112
|
}
|
|
126
|
-
|
|
127
|
-
this.
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
withForceProfile(forceProfile) {
|
|
131
|
-
this.forceProfile = forceProfile;
|
|
113
|
+
withExtraInstructions(extraInstructions) {
|
|
114
|
+
this.extraInstructions = extraInstructions;
|
|
132
115
|
return this;
|
|
133
116
|
}
|
|
134
117
|
withAssistantConfig(assistantConfig) {
|
|
@@ -139,6 +122,9 @@ var AlquimiaSDK = class {
|
|
|
139
122
|
this.userId = userId;
|
|
140
123
|
return this;
|
|
141
124
|
}
|
|
125
|
+
getEnforceCharacterization() {
|
|
126
|
+
return this.enforceCharacterization ?? true;
|
|
127
|
+
}
|
|
142
128
|
textToSpeech(text) {
|
|
143
129
|
if (!this.whisperProvider) {
|
|
144
130
|
throw new Error("Whisper provider not initialized");
|
|
@@ -153,26 +139,35 @@ var AlquimiaSDK = class {
|
|
|
153
139
|
}
|
|
154
140
|
async sendMessage(query, traceParent) {
|
|
155
141
|
if (!this.conversationId) {
|
|
156
|
-
throw new Error(
|
|
142
|
+
throw new Error(
|
|
143
|
+
"Conversation not initialized. Call withConversationId() before sendMessage()"
|
|
144
|
+
);
|
|
157
145
|
}
|
|
146
|
+
const inferUrl = this.adapter.resolveInferUrl(this.assistantId);
|
|
147
|
+
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
148
|
+
const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;
|
|
158
149
|
const initMessage = {
|
|
159
150
|
query,
|
|
160
151
|
session_id: this.conversationId,
|
|
161
|
-
...this.extraData && { extra_data: this.extraData },
|
|
162
|
-
force_profile: this.forceProfile,
|
|
163
|
-
...this.assistantConfig && { config: this.assistantConfig },
|
|
164
|
-
tools: this.tools,
|
|
165
152
|
user_id: this.userId,
|
|
166
|
-
|
|
153
|
+
...this.extraInstructions && { extra_instructions: this.extraInstructions },
|
|
154
|
+
...this.assistantConfig && { config: this.assistantConfig },
|
|
155
|
+
...hasClientTools && {
|
|
156
|
+
evaluation_strategy: {
|
|
157
|
+
evaluation_strategy_id: "native",
|
|
158
|
+
tool_schemas: this.tools
|
|
159
|
+
}
|
|
160
|
+
}
|
|
167
161
|
};
|
|
168
|
-
const result = (await this.axiosInstance.post(
|
|
162
|
+
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
169
163
|
headers: {
|
|
170
164
|
"Content-Type": "application/json",
|
|
171
|
-
"x-trace-parent": traceParent || ""
|
|
165
|
+
"x-trace-parent": traceParent || "",
|
|
166
|
+
...adapterHeaders,
|
|
167
|
+
...this.buildIdentityHeaders()
|
|
172
168
|
}
|
|
173
169
|
})).data;
|
|
174
|
-
this.
|
|
175
|
-
this.streamId = result.stream_id;
|
|
170
|
+
this.streamId = result.taskid ?? null;
|
|
176
171
|
this.attachmentResponses = result.attachments ?? [];
|
|
177
172
|
this.attachments = [];
|
|
178
173
|
return this;
|
|
@@ -185,51 +180,75 @@ var AlquimiaSDK = class {
|
|
|
185
180
|
}
|
|
186
181
|
async analyzeCharacterization(text) {
|
|
187
182
|
if (!this.analyzeCharacterizationProvider) {
|
|
188
|
-
throw new Error("
|
|
183
|
+
throw new Error("Analyze characterization provider not initialized");
|
|
189
184
|
}
|
|
190
185
|
return this.analyzeCharacterizationProvider.analyzeCharacterization(text);
|
|
191
186
|
}
|
|
192
187
|
async rate(data) {
|
|
193
188
|
if (!this.ratingsProvider) {
|
|
194
|
-
throw new Error("
|
|
189
|
+
throw new Error("Ratings provider not initialized");
|
|
195
190
|
}
|
|
196
191
|
return this.ratingsProvider.rate(data);
|
|
197
192
|
}
|
|
198
193
|
async logInfo(message, data) {
|
|
199
194
|
if (!this.loggerProvider) {
|
|
200
|
-
throw new Error("
|
|
195
|
+
throw new Error("Logger provider not initialized");
|
|
201
196
|
}
|
|
202
197
|
return this.loggerProvider.logInfo(message, data);
|
|
203
198
|
}
|
|
204
199
|
async logError(message, error, data) {
|
|
205
200
|
if (!this.loggerProvider) {
|
|
206
|
-
throw new Error("
|
|
201
|
+
throw new Error("Logger provider not initialized");
|
|
207
202
|
}
|
|
208
203
|
return this.loggerProvider.logError(message, error, data);
|
|
209
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated The runtime no longer returns attachment IDs from the infer
|
|
207
|
+
* response — attachments are uploaded as standalone blobs and linked to the
|
|
208
|
+
* session via headers. Always returns `[]`; kept for source compatibility.
|
|
209
|
+
*/
|
|
210
210
|
getAttachmentResponses() {
|
|
211
211
|
return this.attachmentResponses;
|
|
212
212
|
}
|
|
213
|
-
async uploadAttachment(file,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
if (!this.streamId || !attachmentId) {
|
|
218
|
-
throw new Error("Stream or attachment ID not initialized");
|
|
219
|
-
}
|
|
220
|
-
const url = `${this.config.attachmentUrl}/${this.streamId}/${attachmentId}`;
|
|
213
|
+
async uploadAttachment(file, _attachmentId) {
|
|
214
|
+
const url = this.adapter.resolveBlobUploadUrl();
|
|
215
|
+
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
221
216
|
const formData = new FormData();
|
|
222
217
|
formData.append("file", file);
|
|
223
218
|
await this.axiosInstance.post(url, formData, {
|
|
224
|
-
headers: {
|
|
219
|
+
headers: {
|
|
220
|
+
"Content-Type": "multipart/form-data",
|
|
221
|
+
...adapterHeaders,
|
|
222
|
+
...this.buildIdentityHeaders()
|
|
223
|
+
}
|
|
225
224
|
});
|
|
226
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
228
|
+
* the rest of the runtime's internal endpoints introduced in v0.2.0→next.
|
|
229
|
+
*/
|
|
230
|
+
buildIdentityHeaders() {
|
|
231
|
+
const headers = {
|
|
232
|
+
"assistant-id": this.assistantId
|
|
233
|
+
};
|
|
234
|
+
if (this.conversationId) headers["session-id"] = this.conversationId;
|
|
235
|
+
if (this.userId) headers["user-id"] = this.userId;
|
|
236
|
+
if (this.streamId) headers["task-id"] = this.streamId;
|
|
237
|
+
return headers;
|
|
238
|
+
}
|
|
227
239
|
getUrlStream() {
|
|
228
|
-
|
|
240
|
+
if (!this.streamId) {
|
|
241
|
+
throw new Error("Stream ID not initialized. Call sendMessage() first");
|
|
242
|
+
}
|
|
243
|
+
return this.adapter.resolveStreamUrl(this.streamId);
|
|
229
244
|
}
|
|
230
245
|
getStreamId() {
|
|
231
246
|
return this.streamId;
|
|
232
247
|
}
|
|
248
|
+
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
249
|
+
getTaskId() {
|
|
250
|
+
return this.streamId;
|
|
251
|
+
}
|
|
233
252
|
};
|
|
234
253
|
var alquimia_sdk_default = AlquimiaSDK;
|
|
235
254
|
//# 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 } from \"../types\";\ninterface AlquimiaSDKConfig {\n apiKey: string;\n chatUrl: string;\n streamUrl: string;\n attachmentUrl: string;\n assistantId: string;\n}\n\n\nclass AlquimiaSDK {\n private config: AlquimiaSDKConfig;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n private streamId: string | null = null;\n private evaluationStrategy: string | null = null;\n private tools: any = [];\n private extraData: any = null;\n private assistantConfig: any = null;\n private forceProfile: any = {};\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(config: AlquimiaSDKConfig, enforceCharacterization: boolean = true) {\n this.config = config;\n this.enforceCharacterization = enforceCharacterization;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status) {\n if (this.loggerProvider) {\n await this.loggerProvider.logError(\n 'Server Error',\n error,\n {\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 }\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 static configure(\n apiKey: string,\n inferUrl: string,\n streamUrl: string,\n attachmentUrl: string,\n assistantId: string,\n ): AlquimiaSDKConfig {\n return {\n apiKey,\n chatUrl: `${inferUrl}/chat/${assistantId}`,\n streamUrl: `${streamUrl}`,\n attachmentUrl: attachmentUrl,\n assistantId: assistantId,\n };\n }\n\n widthConversationId(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 getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n getEvaluationStrategy(): string | null {\n return this.evaluationStrategy;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraData(extraData: any): AlquimiaSDK {\n this.extraData = extraData;\n return this;\n }\n\n withForceProfile(forceProfile: any): AlquimiaSDK {\n this.forceProfile = forceProfile;\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 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) {\n if (!this.conversationId) {\n throw new Error(\"Conversation not initialized\");\n }\n\n const initMessage = {\n query,\n session_id: this.conversationId,\n ...(this.extraData && { extra_data: this.extraData }),\n force_profile: this.forceProfile,\n ...(this.assistantConfig && { config: this.assistantConfig }),\n tools: this.tools,\n user_id: this.userId,\n attachments: this.attachments,\n };\n\n const result = (await this.axiosInstance.post(this.config.chatUrl, initMessage, {\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-trace-parent\": traceParent || \"\",\n },\n })).data\n\n this.evaluationStrategy = result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id || null;\n this.streamId = result.stream_id;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this\n }\n\n async generateImage(query: 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) {\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) {\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) {\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) {\n if (!this.loggerProvider) {\n throw new Error(\"logger provider not initialized\");\n }\n return this.loggerProvider.logError(message, error, data)\n }\n\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, attachmentId: string): Promise<void> {\n if (!this.config.attachmentUrl) {\n throw new Error(\"Attachment URL not configured\");\n }\n if (!this.streamId || !attachmentId) {\n throw new Error(\"Stream or attachment ID not initialized\");\n }\n const url = `${this.config.attachmentUrl}/${this.streamId}/${attachmentId}`;\n const formData = new FormData();\n formData.append(\"file\", file);\n await this.axiosInstance.post(url, formData, {\n headers: { \"Content-Type\": \"multipart/form-data\" },\n });\n }\n\n getUrlStream() {\n return `${this.config.streamUrl}/${this.streamId}`;\n }\n\n getStreamId() {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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MAAW;AACxC,QAAI,CAAC,KAAK,gBAAgB;AACxB,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,WAAO,KAAK,eAAe,QAAQ,SAAS,IAAI;AAAA,EAClD;AAAA,EAEA,MAAM,SAAS,SAAiB,OAAc,MAAW;AACvD,QAAI,CAAC,KAAK,gBAAgB;AACxB,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,WAAO,KAAK,eAAe,SAAS,SAAS,OAAO,IAAI;AAAA,EAC1D;AAAA,EAEA,yBAAmC;AACjC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,iBAAiB,MAAY,cAAqC;AACtE,QAAI,CAAC,KAAK,OAAO,eAAe;AAC9B,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AACA,QAAI,CAAC,KAAK,YAAY,CAAC,cAAc;AACnC,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AACA,UAAM,MAAM,GAAG,KAAK,OAAO,aAAa,IAAI,KAAK,QAAQ,IAAI,YAAY;AACzE,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,QAAQ,IAAI;AAC5B,UAAM,KAAK,cAAc,KAAK,KAAK,UAAU;AAAA,MAC3C,SAAS,EAAE,gBAAgB,sBAAsB;AAAA,IACnD,CAAC;AAAA,EACH;AAAA,EAEA,eAAe;AACb,WAAO,GAAG,KAAK,OAAO,SAAS,IAAI,KAAK,QAAQ;AAAA,EAClD;AAAA,EAEA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":["axios"]}
|
|
1
|
+
{"version":3,"sources":["../../src/sdk/index.ts","../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["export { default as AlquimiaSDK } from './alquimia-sdk';","import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult, type CommonAttributes } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n // Internal subscription id from infer (`taskid` on the wire).\n private streamId: string | null = null;\n private tools: any = [];\n private extraInstructions: Record<string, string> | null = null;\n private assistantConfig: any = null;\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK {\n this.extraInstructions = extraInstructions;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;\n\n const initMessage: Record<string, unknown> = {\n query,\n session_id: this.conversationId,\n user_id: this.userId,\n ...(this.extraInstructions && { extra_instructions: this.extraInstructions }),\n ...(this.assistantConfig && { config: this.assistantConfig }),\n ...(hasClientTools && {\n evaluation_strategy: {\n evaluation_strategy_id: 'native',\n tool_schemas: this.tools,\n },\n }),\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.streamId = result.taskid ?? null;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n /**\n * @deprecated The runtime no longer returns attachment IDs from the infer\n * response — attachments are uploaded as standalone blobs and linked to the\n * session via headers. Always returns `[]`; kept for source compatibility.\n */\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, _attachmentId?: string): Promise<void> {\n void _attachmentId;\n const url = this.adapter.resolveBlobUploadUrl();\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n }\n\n /**\n * Identity headers (kebab-case) required by `/context/blob/upload` and\n * the rest of the runtime's internal endpoints introduced in v0.2.0→next.\n */\n private buildIdentityHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n 'assistant-id': this.assistantId,\n };\n if (this.conversationId) headers['session-id'] = this.conversationId;\n if (this.userId) headers['user-id'] = this.userId;\n if (this.streamId) headers['task-id'] = this.streamId;\n return headers;\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n\n /** Alias for {@link getStreamId} — same value as infer `taskid`. */\n getTaskId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;AAWrC,IAAM,cAAN,MAAkB;AAAA,EAqBhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AArBF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AAEnC;AAAA,SAAQ,WAA0B;AAClC,SAAQ,QAAa,CAAC;AACtB,SAAQ,oBAAmD;AAC3D,SAAQ,kBAAuB;AAC/B,SAAQ,SAAwB;AAOhC,SAAQ,cAAmC,CAAC;AAC5C,SAAQ,sBAAgC,CAAC;AAOvC,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,sCAAsC;AAAA,IACxD;AACA,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,cAAc;AACnB,SAAK,UAAU;AACf,SAAK,0BAA0B,QAAQ,2BAA2B;AAElE,SAAK,gBAAgB,aAAAA,QAAM,OAAO;AAClC,SAAK,cAAc,aAAa,SAAS;AAAA,MACvC,CAAC,aAAa;AAAA,MACd,OAAO,UAAU;AACf,YAAI,MAAM,UAAU,UAAU,KAAK,gBAAgB;AACjD,gBAAM,KAAK,eAAe,SAAS,gBAAgB,OAAO;AAAA,YACxD,KAAK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AAAA;AAAA;AAAA,EAMQ,uBAA+C;AACrD,UAAM,UAAkC;AAAA,MACtC,gBAAgB,KAAK;AAAA,IACvB;AACA,QAAI,KAAK,eAAgB,SAAQ,YAAY,IAAI,KAAK;AACtD,QAAI,KAAK,OAAQ,SAAQ,SAAS,IAAI,KAAK;AAC3C,QAAI,KAAK,SAAU,SAAQ,SAAS,IAAI,KAAK;AAC7C,WAAO;AAAA,EACT;AAAA,EAEA,eAAuB;AACrB,QAAI,CAAC,KAAK,UAAU;AAClB,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AACA,WAAO,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AAAA,EACpD;AAAA,EAEA,cAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,YAA2B;AACzB,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":["axios"]}
|
package/dist/sdk/index.mjs
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
// src/sdk/alquimia-sdk.ts
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
var AlquimiaSDK = class {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(assistantId, adapter, options = {}) {
|
|
5
5
|
this.conversationId = null;
|
|
6
6
|
this.sessionId = null;
|
|
7
|
+
// Internal subscription id from infer (`taskid` on the wire).
|
|
7
8
|
this.streamId = null;
|
|
8
|
-
this.evaluationStrategy = null;
|
|
9
9
|
this.tools = [];
|
|
10
|
-
this.
|
|
10
|
+
this.extraInstructions = null;
|
|
11
11
|
this.assistantConfig = null;
|
|
12
|
-
this.forceProfile = {};
|
|
13
12
|
this.userId = null;
|
|
14
13
|
this.attachments = [];
|
|
15
14
|
this.attachmentResponses = [];
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (!assistantId) {
|
|
16
|
+
throw new Error("AlquimiaSDK: assistantId is required");
|
|
17
|
+
}
|
|
18
|
+
if (!adapter) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
this.assistantId = assistantId;
|
|
24
|
+
this.adapter = adapter;
|
|
25
|
+
this.enforceCharacterization = options.enforceCharacterization ?? true;
|
|
18
26
|
this.axiosInstance = axios.create();
|
|
19
27
|
this.axiosInstance.interceptors.response.use(
|
|
20
28
|
(response) => response,
|
|
21
29
|
async (error) => {
|
|
22
|
-
if (error.response?.status) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
data: error.config.data,
|
|
31
|
-
status: error.response.status,
|
|
32
|
-
responseData: error.response.data
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
}
|
|
30
|
+
if (error.response?.status && this.loggerProvider) {
|
|
31
|
+
await this.loggerProvider.logError("Server Error", error, {
|
|
32
|
+
url: error.config.url,
|
|
33
|
+
method: error.config.method,
|
|
34
|
+
data: error.config.data,
|
|
35
|
+
status: error.response.status,
|
|
36
|
+
responseData: error.response.data
|
|
37
|
+
});
|
|
36
38
|
}
|
|
37
39
|
return Promise.reject(error);
|
|
38
40
|
}
|
|
@@ -40,16 +42,7 @@ var AlquimiaSDK = class {
|
|
|
40
42
|
this.textToSpeech = this.textToSpeech.bind(this);
|
|
41
43
|
this.speechToText = this.speechToText.bind(this);
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
apiKey,
|
|
46
|
-
chatUrl: `${inferUrl}/chat/${assistantId}`,
|
|
47
|
-
streamUrl: `${streamUrl}`,
|
|
48
|
-
attachmentUrl,
|
|
49
|
-
assistantId
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
widthConversationId(conversationId) {
|
|
45
|
+
withConversationId(conversationId) {
|
|
53
46
|
this.conversationId = conversationId;
|
|
54
47
|
return this;
|
|
55
48
|
}
|
|
@@ -77,22 +70,12 @@ var AlquimiaSDK = class {
|
|
|
77
70
|
this.loggerProvider = provider;
|
|
78
71
|
return this;
|
|
79
72
|
}
|
|
80
|
-
getEnforceCharacterization() {
|
|
81
|
-
return this.enforceCharacterization ?? true;
|
|
82
|
-
}
|
|
83
|
-
getEvaluationStrategy() {
|
|
84
|
-
return this.evaluationStrategy;
|
|
85
|
-
}
|
|
86
73
|
withTools(tools) {
|
|
87
74
|
this.tools = tools;
|
|
88
75
|
return this;
|
|
89
76
|
}
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
withForceProfile(forceProfile) {
|
|
95
|
-
this.forceProfile = forceProfile;
|
|
77
|
+
withExtraInstructions(extraInstructions) {
|
|
78
|
+
this.extraInstructions = extraInstructions;
|
|
96
79
|
return this;
|
|
97
80
|
}
|
|
98
81
|
withAssistantConfig(assistantConfig) {
|
|
@@ -103,6 +86,9 @@ var AlquimiaSDK = class {
|
|
|
103
86
|
this.userId = userId;
|
|
104
87
|
return this;
|
|
105
88
|
}
|
|
89
|
+
getEnforceCharacterization() {
|
|
90
|
+
return this.enforceCharacterization ?? true;
|
|
91
|
+
}
|
|
106
92
|
textToSpeech(text) {
|
|
107
93
|
if (!this.whisperProvider) {
|
|
108
94
|
throw new Error("Whisper provider not initialized");
|
|
@@ -117,26 +103,35 @@ var AlquimiaSDK = class {
|
|
|
117
103
|
}
|
|
118
104
|
async sendMessage(query, traceParent) {
|
|
119
105
|
if (!this.conversationId) {
|
|
120
|
-
throw new Error(
|
|
106
|
+
throw new Error(
|
|
107
|
+
"Conversation not initialized. Call withConversationId() before sendMessage()"
|
|
108
|
+
);
|
|
121
109
|
}
|
|
110
|
+
const inferUrl = this.adapter.resolveInferUrl(this.assistantId);
|
|
111
|
+
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
112
|
+
const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;
|
|
122
113
|
const initMessage = {
|
|
123
114
|
query,
|
|
124
115
|
session_id: this.conversationId,
|
|
125
|
-
...this.extraData && { extra_data: this.extraData },
|
|
126
|
-
force_profile: this.forceProfile,
|
|
127
|
-
...this.assistantConfig && { config: this.assistantConfig },
|
|
128
|
-
tools: this.tools,
|
|
129
116
|
user_id: this.userId,
|
|
130
|
-
|
|
117
|
+
...this.extraInstructions && { extra_instructions: this.extraInstructions },
|
|
118
|
+
...this.assistantConfig && { config: this.assistantConfig },
|
|
119
|
+
...hasClientTools && {
|
|
120
|
+
evaluation_strategy: {
|
|
121
|
+
evaluation_strategy_id: "native",
|
|
122
|
+
tool_schemas: this.tools
|
|
123
|
+
}
|
|
124
|
+
}
|
|
131
125
|
};
|
|
132
|
-
const result = (await this.axiosInstance.post(
|
|
126
|
+
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
133
127
|
headers: {
|
|
134
128
|
"Content-Type": "application/json",
|
|
135
|
-
"x-trace-parent": traceParent || ""
|
|
129
|
+
"x-trace-parent": traceParent || "",
|
|
130
|
+
...adapterHeaders,
|
|
131
|
+
...this.buildIdentityHeaders()
|
|
136
132
|
}
|
|
137
133
|
})).data;
|
|
138
|
-
this.
|
|
139
|
-
this.streamId = result.stream_id;
|
|
134
|
+
this.streamId = result.taskid ?? null;
|
|
140
135
|
this.attachmentResponses = result.attachments ?? [];
|
|
141
136
|
this.attachments = [];
|
|
142
137
|
return this;
|
|
@@ -149,51 +144,75 @@ var AlquimiaSDK = class {
|
|
|
149
144
|
}
|
|
150
145
|
async analyzeCharacterization(text) {
|
|
151
146
|
if (!this.analyzeCharacterizationProvider) {
|
|
152
|
-
throw new Error("
|
|
147
|
+
throw new Error("Analyze characterization provider not initialized");
|
|
153
148
|
}
|
|
154
149
|
return this.analyzeCharacterizationProvider.analyzeCharacterization(text);
|
|
155
150
|
}
|
|
156
151
|
async rate(data) {
|
|
157
152
|
if (!this.ratingsProvider) {
|
|
158
|
-
throw new Error("
|
|
153
|
+
throw new Error("Ratings provider not initialized");
|
|
159
154
|
}
|
|
160
155
|
return this.ratingsProvider.rate(data);
|
|
161
156
|
}
|
|
162
157
|
async logInfo(message, data) {
|
|
163
158
|
if (!this.loggerProvider) {
|
|
164
|
-
throw new Error("
|
|
159
|
+
throw new Error("Logger provider not initialized");
|
|
165
160
|
}
|
|
166
161
|
return this.loggerProvider.logInfo(message, data);
|
|
167
162
|
}
|
|
168
163
|
async logError(message, error, data) {
|
|
169
164
|
if (!this.loggerProvider) {
|
|
170
|
-
throw new Error("
|
|
165
|
+
throw new Error("Logger provider not initialized");
|
|
171
166
|
}
|
|
172
167
|
return this.loggerProvider.logError(message, error, data);
|
|
173
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* @deprecated The runtime no longer returns attachment IDs from the infer
|
|
171
|
+
* response — attachments are uploaded as standalone blobs and linked to the
|
|
172
|
+
* session via headers. Always returns `[]`; kept for source compatibility.
|
|
173
|
+
*/
|
|
174
174
|
getAttachmentResponses() {
|
|
175
175
|
return this.attachmentResponses;
|
|
176
176
|
}
|
|
177
|
-
async uploadAttachment(file,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
if (!this.streamId || !attachmentId) {
|
|
182
|
-
throw new Error("Stream or attachment ID not initialized");
|
|
183
|
-
}
|
|
184
|
-
const url = `${this.config.attachmentUrl}/${this.streamId}/${attachmentId}`;
|
|
177
|
+
async uploadAttachment(file, _attachmentId) {
|
|
178
|
+
const url = this.adapter.resolveBlobUploadUrl();
|
|
179
|
+
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
185
180
|
const formData = new FormData();
|
|
186
181
|
formData.append("file", file);
|
|
187
182
|
await this.axiosInstance.post(url, formData, {
|
|
188
|
-
headers: {
|
|
183
|
+
headers: {
|
|
184
|
+
"Content-Type": "multipart/form-data",
|
|
185
|
+
...adapterHeaders,
|
|
186
|
+
...this.buildIdentityHeaders()
|
|
187
|
+
}
|
|
189
188
|
});
|
|
190
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Identity headers (kebab-case) required by `/context/blob/upload` and
|
|
192
|
+
* the rest of the runtime's internal endpoints introduced in v0.2.0→next.
|
|
193
|
+
*/
|
|
194
|
+
buildIdentityHeaders() {
|
|
195
|
+
const headers = {
|
|
196
|
+
"assistant-id": this.assistantId
|
|
197
|
+
};
|
|
198
|
+
if (this.conversationId) headers["session-id"] = this.conversationId;
|
|
199
|
+
if (this.userId) headers["user-id"] = this.userId;
|
|
200
|
+
if (this.streamId) headers["task-id"] = this.streamId;
|
|
201
|
+
return headers;
|
|
202
|
+
}
|
|
191
203
|
getUrlStream() {
|
|
192
|
-
|
|
204
|
+
if (!this.streamId) {
|
|
205
|
+
throw new Error("Stream ID not initialized. Call sendMessage() first");
|
|
206
|
+
}
|
|
207
|
+
return this.adapter.resolveStreamUrl(this.streamId);
|
|
193
208
|
}
|
|
194
209
|
getStreamId() {
|
|
195
210
|
return this.streamId;
|
|
196
211
|
}
|
|
212
|
+
/** Alias for {@link getStreamId} — same value as infer `taskid`. */
|
|
213
|
+
getTaskId() {
|
|
214
|
+
return this.streamId;
|
|
215
|
+
}
|
|
197
216
|
};
|
|
198
217
|
var alquimia_sdk_default = AlquimiaSDK;
|
|
199
218
|
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 } from \"../types\";\ninterface AlquimiaSDKConfig {\n apiKey: string;\n chatUrl: string;\n streamUrl: string;\n attachmentUrl: string;\n assistantId: string;\n}\n\n\nclass AlquimiaSDK {\n private config: AlquimiaSDKConfig;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n private streamId: string | null = null;\n private evaluationStrategy: string | null = null;\n private tools: any = [];\n private extraData: any = null;\n private assistantConfig: any = null;\n private forceProfile: any = {};\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(config: AlquimiaSDKConfig, enforceCharacterization: boolean = true) {\n this.config = config;\n this.enforceCharacterization = enforceCharacterization;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status) {\n if (this.loggerProvider) {\n await this.loggerProvider.logError(\n 'Server Error',\n error,\n {\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 }\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 static configure(\n apiKey: string,\n inferUrl: string,\n streamUrl: string,\n attachmentUrl: string,\n assistantId: string,\n ): AlquimiaSDKConfig {\n return {\n apiKey,\n chatUrl: `${inferUrl}/chat/${assistantId}`,\n streamUrl: `${streamUrl}`,\n attachmentUrl: attachmentUrl,\n assistantId: assistantId,\n };\n }\n\n widthConversationId(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 getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n getEvaluationStrategy(): string | null {\n return this.evaluationStrategy;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraData(extraData: any): AlquimiaSDK {\n this.extraData = extraData;\n return this;\n }\n\n withForceProfile(forceProfile: any): AlquimiaSDK {\n this.forceProfile = forceProfile;\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 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) {\n if (!this.conversationId) {\n throw new Error(\"Conversation not initialized\");\n }\n\n const initMessage = {\n query,\n session_id: this.conversationId,\n ...(this.extraData && { extra_data: this.extraData }),\n force_profile: this.forceProfile,\n ...(this.assistantConfig && { config: this.assistantConfig }),\n tools: this.tools,\n user_id: this.userId,\n attachments: this.attachments,\n };\n\n const result = (await this.axiosInstance.post(this.config.chatUrl, initMessage, {\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-trace-parent\": traceParent || \"\",\n },\n })).data\n\n this.evaluationStrategy = result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id || null;\n this.streamId = result.stream_id;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this\n }\n\n async generateImage(query: 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) {\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) {\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) {\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) {\n if (!this.loggerProvider) {\n throw new Error(\"logger provider not initialized\");\n }\n return this.loggerProvider.logError(message, error, data)\n }\n\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, attachmentId: string): Promise<void> {\n if (!this.config.attachmentUrl) {\n throw new Error(\"Attachment URL not configured\");\n }\n if (!this.streamId || !attachmentId) {\n throw new Error(\"Stream or attachment ID not initialized\");\n }\n const url = `${this.config.attachmentUrl}/${this.streamId}/${attachmentId}`;\n const formData = new FormData();\n formData.append(\"file\", file);\n await this.axiosInstance.post(url, formData, {\n headers: { \"Content-Type\": \"multipart/form-data\" },\n });\n }\n\n getUrlStream() {\n return `${this.config.streamUrl}/${this.streamId}`;\n }\n\n getStreamId() {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";AAAA,OAAO,WAA8B;AAkBrC,IAAM,cAAN,MAAkB;AAAA,EAqBhB,YAAY,QAA2B,0BAAmC,MAAM;AAlBhF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AACnC,SAAQ,WAA0B;AAClC,SAAQ,qBAAoC;AAC5C,SAAQ,QAAa,CAAC;AACtB,SAAQ,YAAiB;AACzB,SAAQ,kBAAuB;AAC/B,SAAQ,eAAoB,CAAC;AAC7B,SAAQ,SAAwB;AAOhC,SAAQ,cAAmC,CAAC;AAC5C,SAAQ,sBAAgC,CAAC;AAGvC,SAAK,SAAS;AAC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,QAAI,CAAC,KAAK,OAAO,eAAe;AAC9B,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AACA,QAAI,CAAC,KAAK,YAAY,CAAC,cAAc;AACnC,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AACA,UAAM,MAAM,GAAG,KAAK,OAAO,aAAa,IAAI,KAAK,QAAQ,IAAI,YAAY;AACzE,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,QAAQ,IAAI;AAC5B,UAAM,KAAK,cAAc,KAAK,KAAK,UAAU;AAAA,MAC3C,SAAS,EAAE,gBAAgB,sBAAsB;AAAA,IACnD,CAAC;AAAA,EACH;AAAA,EAEA,eAAe;AACb,WAAO,GAAG,KAAK,OAAO,SAAS,IAAI,KAAK,QAAQ;AAAA,EAClD;AAAA,EAEA,cAAc;AACZ,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 { AttachmentPayload, TTSResult, type CommonAttributes } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n // Internal subscription id from infer (`taskid` on the wire).\n private streamId: string | null = null;\n private tools: any = [];\n private extraInstructions: Record<string, string> | null = null;\n private assistantConfig: any = null;\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraInstructions(extraInstructions: Record<string, string>): AlquimiaSDK {\n this.extraInstructions = extraInstructions;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const hasClientTools = Array.isArray(this.tools) && this.tools.length > 0;\n\n const initMessage: Record<string, unknown> = {\n query,\n session_id: this.conversationId,\n user_id: this.userId,\n ...(this.extraInstructions && { extra_instructions: this.extraInstructions }),\n ...(this.assistantConfig && { config: this.assistantConfig }),\n ...(hasClientTools && {\n evaluation_strategy: {\n evaluation_strategy_id: 'native',\n tool_schemas: this.tools,\n },\n }),\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n })\n ).data as CommonAttributes;\n\n this.streamId = result.taskid ?? null;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n /**\n * @deprecated The runtime no longer returns attachment IDs from the infer\n * response — attachments are uploaded as standalone blobs and linked to the\n * session via headers. Always returns `[]`; kept for source compatibility.\n */\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, _attachmentId?: string): Promise<void> {\n void _attachmentId;\n const url = this.adapter.resolveBlobUploadUrl();\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n ...adapterHeaders,\n ...this.buildIdentityHeaders(),\n },\n });\n }\n\n /**\n * Identity headers (kebab-case) required by `/context/blob/upload` and\n * the rest of the runtime's internal endpoints introduced in v0.2.0→next.\n */\n private buildIdentityHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n 'assistant-id': this.assistantId,\n };\n if (this.conversationId) headers['session-id'] = this.conversationId;\n if (this.userId) headers['user-id'] = this.userId;\n if (this.streamId) headers['task-id'] = this.streamId;\n return headers;\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n\n /** Alias for {@link getStreamId} — same value as infer `taskid`. */\n getTaskId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";AAAA,OAAO,WAA8B;AAWrC,IAAM,cAAN,MAA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IAAO,uBAAQ;","names":[]}
|
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import '../types/index.mjs';
|
|
1
|
+
import { Transaction } from '@elastic/apm-rum';
|
|
2
|
+
import { ApmSpan } from '../types/index.mjs';
|
|
4
3
|
import 'ai';
|
|
4
|
+
|
|
5
|
+
interface APMInitializerProps {
|
|
6
|
+
serviceName: string;
|
|
7
|
+
serverUrl?: string;
|
|
8
|
+
serverUrlPrefix?: string | undefined;
|
|
9
|
+
logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
10
|
+
environment: string;
|
|
11
|
+
ignoreUrls?: Array<string | RegExp>;
|
|
12
|
+
}
|
|
13
|
+
type LabelValue = string | number | boolean | null;
|
|
14
|
+
interface TransactionLabels {
|
|
15
|
+
[key: string]: LabelValue;
|
|
16
|
+
}
|
|
17
|
+
declare function APMInitializer({ serviceName, serverUrl, serverUrlPrefix, logLevel, environment, ignoreUrls }: APMInitializerProps): null;
|
|
18
|
+
declare function handleApmTransaction(name: string, type: string, labels: TransactionLabels, callback: () => Promise<void> | void): Promise<void>;
|
|
19
|
+
declare function traceError(error: string | Error, labels?: TransactionLabels, customMessage?: string): void;
|
|
20
|
+
declare const startManagedTransaction: (name: string, type: string | undefined, spanName: string, spanType?: string) => {
|
|
21
|
+
transaction: Transaction | undefined;
|
|
22
|
+
span: ApmSpan | undefined;
|
|
23
|
+
traceParentId: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { APMInitializer, handleApmTransaction, startManagedTransaction, traceError };
|