swiftbase-admin-sdk 1.0.2 → 1.0.4

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.cts CHANGED
@@ -378,21 +378,56 @@ declare class Storage {
378
378
  deleteObject(key: string): Promise<void>;
379
379
  }
380
380
 
381
+ interface AIToolCall {
382
+ id: string;
383
+ type: "function";
384
+ function: {
385
+ name: string;
386
+ arguments: string;
387
+ };
388
+ }
389
+ interface AITool {
390
+ type: "function";
391
+ function: {
392
+ name: string;
393
+ description?: string;
394
+ parameters?: Record<string, any>;
395
+ };
396
+ }
381
397
  interface AIChatMessage {
382
- role: "system" | "user" | "assistant";
383
- content: string;
398
+ role: "system" | "user" | "assistant" | "tool";
399
+ content?: string | null;
400
+ name?: string;
401
+ tool_call_id?: string;
402
+ tool_calls?: AIToolCall[];
384
403
  }
385
404
  interface AIChatCompletionOptions {
386
405
  model?: string;
387
406
  messages: AIChatMessage[];
407
+ tools?: AITool[];
408
+ tool_choice?: any;
409
+ temperature?: number;
410
+ max_tokens?: number;
388
411
  }
389
412
  interface AIChatCompletionResponse {
413
+ id?: string;
414
+ object?: string;
415
+ created?: number;
416
+ model?: string;
390
417
  choices: Array<{
418
+ index?: number;
391
419
  message: {
392
420
  role: string;
393
- content: string;
421
+ content: string | null;
422
+ tool_calls?: AIToolCall[];
394
423
  };
424
+ finish_reason?: string;
395
425
  }>;
426
+ usage?: {
427
+ prompt_tokens: number;
428
+ completion_tokens: number;
429
+ total_tokens: number;
430
+ };
396
431
  }
397
432
  /**
398
433
  * Generate completion using the AI service.
package/dist/index.d.ts CHANGED
@@ -378,21 +378,56 @@ declare class Storage {
378
378
  deleteObject(key: string): Promise<void>;
379
379
  }
380
380
 
381
+ interface AIToolCall {
382
+ id: string;
383
+ type: "function";
384
+ function: {
385
+ name: string;
386
+ arguments: string;
387
+ };
388
+ }
389
+ interface AITool {
390
+ type: "function";
391
+ function: {
392
+ name: string;
393
+ description?: string;
394
+ parameters?: Record<string, any>;
395
+ };
396
+ }
381
397
  interface AIChatMessage {
382
- role: "system" | "user" | "assistant";
383
- content: string;
398
+ role: "system" | "user" | "assistant" | "tool";
399
+ content?: string | null;
400
+ name?: string;
401
+ tool_call_id?: string;
402
+ tool_calls?: AIToolCall[];
384
403
  }
385
404
  interface AIChatCompletionOptions {
386
405
  model?: string;
387
406
  messages: AIChatMessage[];
407
+ tools?: AITool[];
408
+ tool_choice?: any;
409
+ temperature?: number;
410
+ max_tokens?: number;
388
411
  }
389
412
  interface AIChatCompletionResponse {
413
+ id?: string;
414
+ object?: string;
415
+ created?: number;
416
+ model?: string;
390
417
  choices: Array<{
418
+ index?: number;
391
419
  message: {
392
420
  role: string;
393
- content: string;
421
+ content: string | null;
422
+ tool_calls?: AIToolCall[];
394
423
  };
424
+ finish_reason?: string;
395
425
  }>;
426
+ usage?: {
427
+ prompt_tokens: number;
428
+ completion_tokens: number;
429
+ total_tokens: number;
430
+ };
396
431
  }
397
432
  /**
398
433
  * Generate completion using the AI service.
package/dist/index.js CHANGED
@@ -225,9 +225,6 @@ var init_login = __esm({
225
225
  body.append("client_secret", secretKey);
226
226
  body.append("scope", "openid profile email");
227
227
  let base = app.baseUrl || "https://api.swiftbase.io";
228
- if (!base.includes("localhost") && !base.includes("127.0.0.1")) {
229
- base = base.replace("api.swiftbase", "identity.swiftbase");
230
- }
231
228
  const url = `${base}/oauth2/token`;
232
229
  const response = yield fetch(url, {
233
230
  method: "POST",
@@ -3869,15 +3866,6 @@ var makeRequest = (method, path, params, body) => __async(null, null, function*
3869
3866
  headers["Authorization"] = `Bearer ${app.accessToken.value()}`;
3870
3867
  }
3871
3868
  let base = app.baseUrl || "https://api.swiftbase.io";
3872
- if (!base.includes("localhost") && !base.includes("127.0.0.1")) {
3873
- if (path.includes("/db/") || path.includes("/database") || path.includes("/tables") || path.includes("/sql") || path.includes("/queries")) {
3874
- base = base.replace("api.swiftbase", "database.swiftbase");
3875
- } else if (path.includes("/oauth2") || path.includes("/login") || path.includes("/api/roles") || path.includes("/api/services") || path.includes("/api/users") || path.includes("/api/me")) {
3876
- base = base.replace("api.swiftbase", "identity.swiftbase");
3877
- } else {
3878
- base = base.replace("api.swiftbase", "app.swiftbase");
3879
- }
3880
- }
3881
3869
  let url = path.startsWith("http") ? path : `${base}${!path.startsWith("/") ? "/" : ""}${path}`;
3882
3870
  if (params) {
3883
3871
  const query = new URLSearchParams();
@@ -3947,9 +3935,6 @@ var verifyToken = (token) => __async(null, null, function* () {
3947
3935
  "Authorization": `Bearer ${token}`
3948
3936
  };
3949
3937
  let base = app.baseUrl || "https://api.swiftbase.io";
3950
- if (!base.includes("localhost") && !base.includes("127.0.0.1")) {
3951
- base = base.replace("api.swiftbase", "identity.swiftbase");
3952
- }
3953
3938
  const response = yield fetch(`${base}/api/me`, { headers });
3954
3939
  if (!response.ok) {
3955
3940
  throw new Error(`Token verification failed: ${response.status}`);
@@ -3961,9 +3946,6 @@ var verifyToken = (token) => __async(null, null, function* () {
3961
3946
  init_app();
3962
3947
  var verifyServiceToken = (token, scope) => __async(null, null, function* () {
3963
3948
  let base = app.baseUrl || "https://api.swiftbase.io";
3964
- if (!base.includes("localhost") && !base.includes("127.0.0.1")) {
3965
- base = base.replace("api.swiftbase", "identity.swiftbase");
3966
- }
3967
3949
  const url = `${base}/api/verify-service-token`;
3968
3950
  const response = yield fetch(url, {
3969
3951
  method: "POST",
@@ -4581,10 +4563,7 @@ function signS3Request(options) {
4581
4563
  // src/storage/storage.ts
4582
4564
  function getDefaultEndpoint() {
4583
4565
  const base = app.baseUrl || "https://api.swiftbase.io";
4584
- if (base.includes("localhost") || base.includes("127.0.0.1")) {
4585
- return "http://localhost:3006";
4586
- }
4587
- return base.replace("api.swiftbase", "storage.swiftbase");
4566
+ return base + "/storage";
4588
4567
  }
4589
4568
  function parseListBuckets(xml) {
4590
4569
  const buckets = [];
@@ -4602,13 +4581,39 @@ function parseListBuckets(xml) {
4602
4581
  }
4603
4582
  return buckets;
4604
4583
  }
4605
- function parseListObjects(xml) {
4606
- const nameMatch = xml.match(/<Name>(.*?)<\/Name>/);
4607
- const prefixMatch = xml.match(/<Prefix>(.*?)<\/Prefix>/);
4608
- const maxKeysMatch = xml.match(/<MaxKeys>(.*?)<\/MaxKeys>/);
4609
- const isTruncatedMatch = xml.match(/<IsTruncated>(.*?)<\/IsTruncated>/);
4584
+ function parseListObjects(text) {
4585
+ const trimmed = text.trim();
4586
+ if (trimmed.startsWith("[") || trimmed.startsWith("{")) {
4587
+ try {
4588
+ const parsed = JSON.parse(trimmed);
4589
+ const items = Array.isArray(parsed) ? parsed : parsed.contents || [];
4590
+ const contents2 = items.map((item) => {
4591
+ const pathPrefix = item.path && item.path !== "/" ? item.path.replace(/\/$/, "") + "/" : "";
4592
+ const key = item.key || (item.name ? `${pathPrefix}${item.name}` : "");
4593
+ return {
4594
+ key,
4595
+ lastModified: item.modified || item.lastModified,
4596
+ etag: item.etag,
4597
+ size: item.size || 0
4598
+ };
4599
+ });
4600
+ return {
4601
+ name: "",
4602
+ prefix: "",
4603
+ maxKeys: contents2.length,
4604
+ isTruncated: false,
4605
+ contents: contents2,
4606
+ commonPrefixes: []
4607
+ };
4608
+ } catch (e) {
4609
+ }
4610
+ }
4611
+ const nameMatch = text.match(/<Name>(.*?)<\/Name>/);
4612
+ const prefixMatch = text.match(/<Prefix>(.*?)<\/Prefix>/);
4613
+ const maxKeysMatch = text.match(/<MaxKeys>(.*?)<\/MaxKeys>/);
4614
+ const isTruncatedMatch = text.match(/<IsTruncated>(.*?)<\/IsTruncated>/);
4610
4615
  const contents = [];
4611
- const contentMatches = xml.matchAll(/<Contents>([\s\S]*?)<\/Contents>/g);
4616
+ const contentMatches = text.matchAll(/<Contents>([\s\S]*?)<\/Contents>/g);
4612
4617
  for (const match of contentMatches) {
4613
4618
  const content = match[1];
4614
4619
  const keyMatch = content.match(/<Key>(.*?)<\/Key>/);
@@ -4625,11 +4630,11 @@ function parseListObjects(xml) {
4625
4630
  }
4626
4631
  }
4627
4632
  const commonPrefixes = [];
4628
- const cpMatches = xml.matchAll(/<CommonPrefixes>([\s\S]*?)<\/CommonPrefixes>/g);
4633
+ const cpMatches = text.matchAll(/<CommonPrefixes>([\s\S]*?)<\/CommonPrefixes>/g);
4629
4634
  for (const match of cpMatches) {
4630
- const prefixMatch2 = match[1].match(/<Prefix>(.*?)<\/Prefix>/);
4631
- if (prefixMatch2) {
4632
- commonPrefixes.push(prefixMatch2[1]);
4635
+ const pMatch = match[1].match(/<Prefix>(.*?)<\/Prefix>/);
4636
+ if (pMatch) {
4637
+ commonPrefixes.push(pMatch[1]);
4633
4638
  }
4634
4639
  }
4635
4640
  return {
@@ -4798,7 +4803,11 @@ var ai = {
4798
4803
  create: (options) => __async(null, null, function* () {
4799
4804
  return yield makeRequest("post" /* POST */, "/api/ai/chat/completions", void 0, {
4800
4805
  model: options.model || "gemini-3.5-flash",
4801
- messages: options.messages
4806
+ messages: options.messages,
4807
+ tools: options.tools,
4808
+ tool_choice: options.tool_choice,
4809
+ temperature: options.temperature,
4810
+ max_tokens: options.max_tokens
4802
4811
  });
4803
4812
  })
4804
4813
  }