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