@omnikit-ai/sdk 2.0.9 → 2.0.10
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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +90 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1187,6 +1187,11 @@ declare class APIClient implements OmnikitClient {
|
|
|
1187
1187
|
private _metadataListeners;
|
|
1188
1188
|
private _userListeners;
|
|
1189
1189
|
constructor(config: OmnikitConfig);
|
|
1190
|
+
/**
|
|
1191
|
+
* Initialize built-in services with their definitions
|
|
1192
|
+
* These services don't require backend schema - they're defined in the SDK
|
|
1193
|
+
*/
|
|
1194
|
+
private initializeBuiltInServices;
|
|
1190
1195
|
/**
|
|
1191
1196
|
* Load metadata from localStorage cache, falling back to initial config
|
|
1192
1197
|
* Guards localStorage access for Deno/Node compatibility
|
package/dist/index.d.ts
CHANGED
|
@@ -1187,6 +1187,11 @@ declare class APIClient implements OmnikitClient {
|
|
|
1187
1187
|
private _metadataListeners;
|
|
1188
1188
|
private _userListeners;
|
|
1189
1189
|
constructor(config: OmnikitConfig);
|
|
1190
|
+
/**
|
|
1191
|
+
* Initialize built-in services with their definitions
|
|
1192
|
+
* These services don't require backend schema - they're defined in the SDK
|
|
1193
|
+
*/
|
|
1194
|
+
private initializeBuiltInServices;
|
|
1190
1195
|
/**
|
|
1191
1196
|
* Load metadata from localStorage cache, falling back to initial config
|
|
1192
1197
|
* Guards localStorage access for Deno/Node compatibility
|
package/dist/index.js
CHANGED
|
@@ -529,10 +529,96 @@ var APIClient = class {
|
|
|
529
529
|
this.userToken = detectedToken;
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
|
+
this.initializeBuiltInServices();
|
|
532
533
|
this.ensureInitialized().catch((err) => {
|
|
533
534
|
console.warn("[Omnikit SDK] Background initialization failed:", err);
|
|
534
535
|
});
|
|
535
536
|
}
|
|
537
|
+
/**
|
|
538
|
+
* Initialize built-in services with their definitions
|
|
539
|
+
* These services don't require backend schema - they're defined in the SDK
|
|
540
|
+
*/
|
|
541
|
+
initializeBuiltInServices() {
|
|
542
|
+
const builtInServices = [
|
|
543
|
+
{
|
|
544
|
+
name: "SendEmail",
|
|
545
|
+
path: "/services/email",
|
|
546
|
+
description: "Send an email",
|
|
547
|
+
method: "POST",
|
|
548
|
+
params: { to: "string", subject: "string", body: "string" }
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
name: "InvokeLLM",
|
|
552
|
+
path: "/services/llm",
|
|
553
|
+
description: "Invoke a language model",
|
|
554
|
+
method: "POST",
|
|
555
|
+
params: { messages: "array", model: "string" }
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
name: "GenerateImage",
|
|
559
|
+
path: "/services/images",
|
|
560
|
+
description: "Generate an image from a prompt",
|
|
561
|
+
method: "POST",
|
|
562
|
+
async: true,
|
|
563
|
+
params: { prompt: "string" }
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
name: "GenerateSpeech",
|
|
567
|
+
path: "/services/speech",
|
|
568
|
+
description: "Generate speech from text",
|
|
569
|
+
method: "POST",
|
|
570
|
+
async: true,
|
|
571
|
+
params: { text: "string" }
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
name: "GenerateVideo",
|
|
575
|
+
path: "/services/video",
|
|
576
|
+
description: "Generate a video from a prompt",
|
|
577
|
+
method: "POST",
|
|
578
|
+
async: true,
|
|
579
|
+
params: { prompt: "string" }
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
name: "ExtractData",
|
|
583
|
+
path: "/services/extract-text",
|
|
584
|
+
description: "Extract structured data from text or files",
|
|
585
|
+
method: "POST",
|
|
586
|
+
async: true,
|
|
587
|
+
params: { file_url: "string" }
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
name: "SendSMS",
|
|
591
|
+
path: "/services/sms",
|
|
592
|
+
description: "Send an SMS message",
|
|
593
|
+
method: "POST",
|
|
594
|
+
params: { to: "string", body: "string" }
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
name: "UploadFile",
|
|
598
|
+
path: "/services/files",
|
|
599
|
+
description: "Upload a file (public)",
|
|
600
|
+
method: "POST",
|
|
601
|
+
params: { file: "File" }
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
name: "UploadPrivateFile",
|
|
605
|
+
path: "/services/files/private",
|
|
606
|
+
description: "Upload a private file",
|
|
607
|
+
method: "POST",
|
|
608
|
+
params: { file: "File" }
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
name: "CreateFileSignedUrl",
|
|
612
|
+
path: "/services/files/signed-url",
|
|
613
|
+
description: "Create a signed URL for a private file",
|
|
614
|
+
method: "POST",
|
|
615
|
+
params: { file_uri: "string" }
|
|
616
|
+
}
|
|
617
|
+
];
|
|
618
|
+
builtInServices.forEach((service) => {
|
|
619
|
+
this._services[service.name] = this.createServiceMethod(service);
|
|
620
|
+
});
|
|
621
|
+
}
|
|
536
622
|
/**
|
|
537
623
|
* Load metadata from localStorage cache, falling back to initial config
|
|
538
624
|
* Guards localStorage access for Deno/Node compatibility
|
|
@@ -1191,57 +1277,11 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1191
1277
|
if (method) {
|
|
1192
1278
|
response = await method(params, useServiceToken);
|
|
1193
1279
|
} else {
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
"
|
|
1198
|
-
"GenerateSpeech": "services/speech",
|
|
1199
|
-
"GenerateVideo": "services/video",
|
|
1200
|
-
"ExtractData": "services/extract-text",
|
|
1201
|
-
"SendSMS": "services/sms",
|
|
1202
|
-
"UploadFile": "services/files",
|
|
1203
|
-
"UploadPrivateFile": "services/files/private/init",
|
|
1204
|
-
"CreateFileSignedUrl": "services/files/signed-url"
|
|
1205
|
-
};
|
|
1206
|
-
const servicePath = servicePathMap[normalizedName];
|
|
1207
|
-
if (!servicePath) {
|
|
1208
|
-
throw new OmnikitError(
|
|
1209
|
-
`Service '${serviceName}' not found. Known services: ${Object.keys(servicePathMap).join(", ")} (camelCase also supported)`,
|
|
1210
|
-
404,
|
|
1211
|
-
"SERVICE_NOT_FOUND"
|
|
1212
|
-
);
|
|
1213
|
-
}
|
|
1214
|
-
const headers = {
|
|
1215
|
-
"Content-Type": "application/json"
|
|
1216
|
-
};
|
|
1217
|
-
if (client._apiKey) {
|
|
1218
|
-
headers["X-API-Key"] = client._apiKey;
|
|
1219
|
-
} else if (client.userToken) {
|
|
1220
|
-
headers["Authorization"] = `Bearer ${client.userToken}`;
|
|
1221
|
-
}
|
|
1222
|
-
if ((normalizedName === "UploadFile" || normalizedName === "uploadFile") && params?.file instanceof File) {
|
|
1223
|
-
return client.handleFileUpload(params.file, servicePath, useServiceToken);
|
|
1224
|
-
}
|
|
1225
|
-
if ((normalizedName === "UploadPrivateFile" || normalizedName === "uploadPrivateFile") && params?.file instanceof File) {
|
|
1226
|
-
return client.handleFileUpload(params.file, servicePath, useServiceToken);
|
|
1227
|
-
}
|
|
1228
|
-
const fetchResponse = await fetch(
|
|
1229
|
-
`${client.baseUrl}/apps/${client.appId}/${servicePath}`,
|
|
1230
|
-
{
|
|
1231
|
-
method: "POST",
|
|
1232
|
-
headers,
|
|
1233
|
-
body: JSON.stringify(params || {})
|
|
1234
|
-
}
|
|
1280
|
+
throw new OmnikitError(
|
|
1281
|
+
`Service '${serviceName}' not found. Known services: SendEmail, InvokeLLM, GenerateImage, GenerateSpeech, GenerateVideo, ExtractData, SendSMS, UploadFile, UploadPrivateFile, CreateFileSignedUrl (camelCase also supported)`,
|
|
1282
|
+
404,
|
|
1283
|
+
"SERVICE_NOT_FOUND"
|
|
1235
1284
|
);
|
|
1236
|
-
if (!fetchResponse.ok) {
|
|
1237
|
-
const error = await fetchResponse.json().catch(() => ({}));
|
|
1238
|
-
throw new OmnikitError(
|
|
1239
|
-
error.detail || `Service call failed: ${fetchResponse.statusText}`,
|
|
1240
|
-
fetchResponse.status,
|
|
1241
|
-
"SERVICE_CALL_FAILED"
|
|
1242
|
-
);
|
|
1243
|
-
}
|
|
1244
|
-
response = await fetchResponse.json();
|
|
1245
1285
|
}
|
|
1246
1286
|
if (response && response.async && response.job_id) {
|
|
1247
1287
|
if (asyncOptions?.returnJobId) {
|