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