@omnikit-ai/sdk 2.0.4 → 2.0.6
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/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +51 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1146,15 +1146,57 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1146
1146
|
return client.streamLLMResponse(params);
|
|
1147
1147
|
}
|
|
1148
1148
|
}
|
|
1149
|
+
let response;
|
|
1149
1150
|
const method = client._services[serviceName];
|
|
1150
|
-
if (
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
"
|
|
1151
|
+
if (method) {
|
|
1152
|
+
response = await method(params, useServiceToken);
|
|
1153
|
+
} else {
|
|
1154
|
+
const servicePathMap = {
|
|
1155
|
+
"SendEmail": "email/send",
|
|
1156
|
+
"InvokeLLM": "llm/invoke",
|
|
1157
|
+
"GenerateImage": "image/generate",
|
|
1158
|
+
"GenerateSpeech": "speech/generate",
|
|
1159
|
+
"GenerateVideo": "video/generate",
|
|
1160
|
+
"ExtractData": "extract/data",
|
|
1161
|
+
"SendSMS": "sms/send",
|
|
1162
|
+
"UploadFile": "storage/upload",
|
|
1163
|
+
"UploadPrivateFile": "storage/upload-private",
|
|
1164
|
+
"CreateFileSignedUrl": "storage/signed-url"
|
|
1165
|
+
};
|
|
1166
|
+
const servicePath = servicePathMap[serviceName];
|
|
1167
|
+
if (!servicePath) {
|
|
1168
|
+
throw new OmnikitError(
|
|
1169
|
+
`Service '${serviceName}' not found. Known services: ${Object.keys(servicePathMap).join(", ")}`,
|
|
1170
|
+
404,
|
|
1171
|
+
"SERVICE_NOT_FOUND"
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
const headers = {
|
|
1175
|
+
"Content-Type": "application/json"
|
|
1176
|
+
};
|
|
1177
|
+
if (client._apiKey) {
|
|
1178
|
+
headers["X-API-Key"] = client._apiKey;
|
|
1179
|
+
} else if (client.userToken) {
|
|
1180
|
+
headers["Authorization"] = `Bearer ${client.userToken}`;
|
|
1181
|
+
}
|
|
1182
|
+
const fetchResponse = await fetch(
|
|
1183
|
+
`${client.baseUrl}/apps/${client.appId}/integrations/${servicePath}`,
|
|
1184
|
+
{
|
|
1185
|
+
method: "POST",
|
|
1186
|
+
headers,
|
|
1187
|
+
body: JSON.stringify(params || {})
|
|
1188
|
+
}
|
|
1155
1189
|
);
|
|
1190
|
+
if (!fetchResponse.ok) {
|
|
1191
|
+
const error = await fetchResponse.json().catch(() => ({}));
|
|
1192
|
+
throw new OmnikitError(
|
|
1193
|
+
error.detail || `Service call failed: ${fetchResponse.statusText}`,
|
|
1194
|
+
fetchResponse.status,
|
|
1195
|
+
"SERVICE_CALL_FAILED"
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
response = await fetchResponse.json();
|
|
1156
1199
|
}
|
|
1157
|
-
const response = await method(params, useServiceToken);
|
|
1158
1200
|
if (response && response.async && response.job_id) {
|
|
1159
1201
|
if (asyncOptions?.returnJobId) {
|
|
1160
1202
|
return response;
|
|
@@ -1251,16 +1293,14 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1251
1293
|
this.initPromise = null;
|
|
1252
1294
|
}
|
|
1253
1295
|
/**
|
|
1254
|
-
* Initialize SDK by fetching app schema and
|
|
1296
|
+
* Initialize SDK by fetching app schema (for collections and metadata)
|
|
1297
|
+
* Services use static mappings - no schema fetch needed
|
|
1255
1298
|
* This happens automatically on first use - no need to call explicitly
|
|
1256
1299
|
*/
|
|
1257
1300
|
async initialize() {
|
|
1258
1301
|
if (this.initialized) return;
|
|
1259
1302
|
try {
|
|
1260
|
-
const
|
|
1261
|
-
this.fetchAppSchema(),
|
|
1262
|
-
this.fetchIntegrationSchema()
|
|
1263
|
-
]);
|
|
1303
|
+
const appSchema = await this.fetchAppSchema();
|
|
1264
1304
|
if (appSchema.app) {
|
|
1265
1305
|
this.updateMetadataCache({
|
|
1266
1306
|
name: appSchema.app.name,
|
|
@@ -1273,11 +1313,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1273
1313
|
if (appSchema.entities) {
|
|
1274
1314
|
this.createCollections(appSchema.entities);
|
|
1275
1315
|
}
|
|
1276
|
-
if (integrationSchema && "services" in integrationSchema) {
|
|
1277
|
-
this.createServicesFromSchema(integrationSchema);
|
|
1278
|
-
} else if (integrationSchema && "installed_packages" in integrationSchema) {
|
|
1279
|
-
this.createIntegrationsFromSchema(integrationSchema);
|
|
1280
|
-
}
|
|
1281
1316
|
this.initialized = true;
|
|
1282
1317
|
} catch (error) {
|
|
1283
1318
|
console.error("Failed to initialize Omnikit SDK:", error);
|