swiftbase-admin-sdk 1.0.3 → 1.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.cts CHANGED
@@ -314,6 +314,15 @@ declare class QueryBuilder implements PromiseLike<any> {
314
314
  columns: string[];
315
315
  count: number;
316
316
  }>;
317
+ /**
318
+ * Seamlessly stream query batches for large volume data operations
319
+ */
320
+ stream(options?: {
321
+ batchSize?: number;
322
+ }): AsyncGenerator<{
323
+ data: any[];
324
+ count: number;
325
+ }>;
317
326
  then<TResult1 = any, TResult2 = never>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
318
327
  }
319
328
  interface TableDefinition {
@@ -378,21 +387,56 @@ declare class Storage {
378
387
  deleteObject(key: string): Promise<void>;
379
388
  }
380
389
 
390
+ interface AIToolCall {
391
+ id: string;
392
+ type: "function";
393
+ function: {
394
+ name: string;
395
+ arguments: string;
396
+ };
397
+ }
398
+ interface AITool {
399
+ type: "function";
400
+ function: {
401
+ name: string;
402
+ description?: string;
403
+ parameters?: Record<string, any>;
404
+ };
405
+ }
381
406
  interface AIChatMessage {
382
- role: "system" | "user" | "assistant";
383
- content: string;
407
+ role: "system" | "user" | "assistant" | "tool";
408
+ content?: string | null;
409
+ name?: string;
410
+ tool_call_id?: string;
411
+ tool_calls?: AIToolCall[];
384
412
  }
385
413
  interface AIChatCompletionOptions {
386
414
  model?: string;
387
415
  messages: AIChatMessage[];
416
+ tools?: AITool[];
417
+ tool_choice?: any;
418
+ temperature?: number;
419
+ max_tokens?: number;
388
420
  }
389
421
  interface AIChatCompletionResponse {
422
+ id?: string;
423
+ object?: string;
424
+ created?: number;
425
+ model?: string;
390
426
  choices: Array<{
427
+ index?: number;
391
428
  message: {
392
429
  role: string;
393
- content: string;
430
+ content: string | null;
431
+ tool_calls?: AIToolCall[];
394
432
  };
433
+ finish_reason?: string;
395
434
  }>;
435
+ usage?: {
436
+ prompt_tokens: number;
437
+ completion_tokens: number;
438
+ total_tokens: number;
439
+ };
396
440
  }
397
441
  /**
398
442
  * Generate completion using the AI service.
package/dist/index.d.ts CHANGED
@@ -314,6 +314,15 @@ declare class QueryBuilder implements PromiseLike<any> {
314
314
  columns: string[];
315
315
  count: number;
316
316
  }>;
317
+ /**
318
+ * Seamlessly stream query batches for large volume data operations
319
+ */
320
+ stream(options?: {
321
+ batchSize?: number;
322
+ }): AsyncGenerator<{
323
+ data: any[];
324
+ count: number;
325
+ }>;
317
326
  then<TResult1 = any, TResult2 = never>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
318
327
  }
319
328
  interface TableDefinition {
@@ -378,21 +387,56 @@ declare class Storage {
378
387
  deleteObject(key: string): Promise<void>;
379
388
  }
380
389
 
390
+ interface AIToolCall {
391
+ id: string;
392
+ type: "function";
393
+ function: {
394
+ name: string;
395
+ arguments: string;
396
+ };
397
+ }
398
+ interface AITool {
399
+ type: "function";
400
+ function: {
401
+ name: string;
402
+ description?: string;
403
+ parameters?: Record<string, any>;
404
+ };
405
+ }
381
406
  interface AIChatMessage {
382
- role: "system" | "user" | "assistant";
383
- content: string;
407
+ role: "system" | "user" | "assistant" | "tool";
408
+ content?: string | null;
409
+ name?: string;
410
+ tool_call_id?: string;
411
+ tool_calls?: AIToolCall[];
384
412
  }
385
413
  interface AIChatCompletionOptions {
386
414
  model?: string;
387
415
  messages: AIChatMessage[];
416
+ tools?: AITool[];
417
+ tool_choice?: any;
418
+ temperature?: number;
419
+ max_tokens?: number;
388
420
  }
389
421
  interface AIChatCompletionResponse {
422
+ id?: string;
423
+ object?: string;
424
+ created?: number;
425
+ model?: string;
390
426
  choices: Array<{
427
+ index?: number;
391
428
  message: {
392
429
  role: string;
393
- content: string;
430
+ content: string | null;
431
+ tool_calls?: AIToolCall[];
394
432
  };
433
+ finish_reason?: string;
395
434
  }>;
435
+ usage?: {
436
+ prompt_tokens: number;
437
+ completion_tokens: number;
438
+ total_tokens: number;
439
+ };
396
440
  }
397
441
  /**
398
442
  * Generate completion using the AI service.
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __getProtoOf = Object.getPrototypeOf;
9
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
10
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
11
12
  var __typeError = (msg) => {
12
13
  throw TypeError(msg);
13
14
  };
@@ -92,6 +93,21 @@ var __async = (__this, __arguments, generator) => {
92
93
  step((generator = generator.apply(__this, __arguments)).next());
93
94
  });
94
95
  };
96
+ var __await = function(promise, isYieldStar) {
97
+ this[0] = promise;
98
+ this[1] = isYieldStar;
99
+ };
100
+ var __asyncGenerator = (__this, __arguments, generator) => {
101
+ var resume = (k, v, yes, no) => {
102
+ try {
103
+ var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
104
+ Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
105
+ } catch (e) {
106
+ no(e);
107
+ }
108
+ }, method = (k, call, wait, clear) => it[k] = (x) => (call = new Promise((yes, no, run) => (run = () => resume(k, x, yes, no), q ? q.then(run) : run())), clear = () => q === wait && (q = 0), q = wait = call.then(clear, clear), call), q, it = {};
109
+ return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
110
+ };
95
111
 
96
112
  // src/common/token.ts
97
113
  var _token, _type, _expiration, Token;
@@ -4331,6 +4347,31 @@ var QueryBuilder = class {
4331
4347
  return yield makeRequest("post" /* POST */, "/api/db/query", void 0, this.payload);
4332
4348
  });
4333
4349
  }
4350
+ /**
4351
+ * Seamlessly stream query batches for large volume data operations
4352
+ */
4353
+ stream() {
4354
+ return __asyncGenerator(this, arguments, function* (options = {}) {
4355
+ const batchSize = options.batchSize || 1e3;
4356
+ let offset = this.payload.offset || 0;
4357
+ const maxLimit = this.payload.limit;
4358
+ while (true) {
4359
+ const currentBatchLimit = maxLimit ? Math.min(batchSize, maxLimit - offset) : batchSize;
4360
+ if (currentBatchLimit <= 0) break;
4361
+ const pagePayload = __spreadProps(__spreadValues({}, this.payload), {
4362
+ limit: currentBatchLimit,
4363
+ offset
4364
+ });
4365
+ const result = yield new __await(makeRequest("post" /* POST */, "/api/db/query", void 0, pagePayload));
4366
+ const rows = result.data || [];
4367
+ if (rows.length === 0) break;
4368
+ yield { data: rows, count: rows.length };
4369
+ offset += rows.length;
4370
+ if (rows.length < currentBatchLimit) break;
4371
+ if (maxLimit && offset >= maxLimit) break;
4372
+ }
4373
+ });
4374
+ }
4334
4375
  then(onfulfilled, onrejected) {
4335
4376
  return this.execute().then(onfulfilled, onrejected);
4336
4377
  }
@@ -4581,13 +4622,39 @@ function parseListBuckets(xml) {
4581
4622
  }
4582
4623
  return buckets;
4583
4624
  }
4584
- function parseListObjects(xml) {
4585
- const nameMatch = xml.match(/<Name>(.*?)<\/Name>/);
4586
- const prefixMatch = xml.match(/<Prefix>(.*?)<\/Prefix>/);
4587
- const maxKeysMatch = xml.match(/<MaxKeys>(.*?)<\/MaxKeys>/);
4588
- const isTruncatedMatch = xml.match(/<IsTruncated>(.*?)<\/IsTruncated>/);
4625
+ function parseListObjects(text) {
4626
+ const trimmed = text.trim();
4627
+ if (trimmed.startsWith("[") || trimmed.startsWith("{")) {
4628
+ try {
4629
+ const parsed = JSON.parse(trimmed);
4630
+ const items = Array.isArray(parsed) ? parsed : parsed.contents || [];
4631
+ const contents2 = items.map((item) => {
4632
+ const pathPrefix = item.path && item.path !== "/" ? item.path.replace(/\/$/, "") + "/" : "";
4633
+ const key = item.key || (item.name ? `${pathPrefix}${item.name}` : "");
4634
+ return {
4635
+ key,
4636
+ lastModified: item.modified || item.lastModified,
4637
+ etag: item.etag,
4638
+ size: item.size || 0
4639
+ };
4640
+ });
4641
+ return {
4642
+ name: "",
4643
+ prefix: "",
4644
+ maxKeys: contents2.length,
4645
+ isTruncated: false,
4646
+ contents: contents2,
4647
+ commonPrefixes: []
4648
+ };
4649
+ } catch (e) {
4650
+ }
4651
+ }
4652
+ const nameMatch = text.match(/<Name>(.*?)<\/Name>/);
4653
+ const prefixMatch = text.match(/<Prefix>(.*?)<\/Prefix>/);
4654
+ const maxKeysMatch = text.match(/<MaxKeys>(.*?)<\/MaxKeys>/);
4655
+ const isTruncatedMatch = text.match(/<IsTruncated>(.*?)<\/IsTruncated>/);
4589
4656
  const contents = [];
4590
- const contentMatches = xml.matchAll(/<Contents>([\s\S]*?)<\/Contents>/g);
4657
+ const contentMatches = text.matchAll(/<Contents>([\s\S]*?)<\/Contents>/g);
4591
4658
  for (const match of contentMatches) {
4592
4659
  const content = match[1];
4593
4660
  const keyMatch = content.match(/<Key>(.*?)<\/Key>/);
@@ -4604,11 +4671,11 @@ function parseListObjects(xml) {
4604
4671
  }
4605
4672
  }
4606
4673
  const commonPrefixes = [];
4607
- const cpMatches = xml.matchAll(/<CommonPrefixes>([\s\S]*?)<\/CommonPrefixes>/g);
4674
+ const cpMatches = text.matchAll(/<CommonPrefixes>([\s\S]*?)<\/CommonPrefixes>/g);
4608
4675
  for (const match of cpMatches) {
4609
- const prefixMatch2 = match[1].match(/<Prefix>(.*?)<\/Prefix>/);
4610
- if (prefixMatch2) {
4611
- commonPrefixes.push(prefixMatch2[1]);
4676
+ const pMatch = match[1].match(/<Prefix>(.*?)<\/Prefix>/);
4677
+ if (pMatch) {
4678
+ commonPrefixes.push(pMatch[1]);
4612
4679
  }
4613
4680
  }
4614
4681
  return {
@@ -4777,7 +4844,11 @@ var ai = {
4777
4844
  create: (options) => __async(null, null, function* () {
4778
4845
  return yield makeRequest("post" /* POST */, "/api/ai/chat/completions", void 0, {
4779
4846
  model: options.model || "gemini-3.5-flash",
4780
- messages: options.messages
4847
+ messages: options.messages,
4848
+ tools: options.tools,
4849
+ tool_choice: options.tool_choice,
4850
+ temperature: options.temperature,
4851
+ max_tokens: options.max_tokens
4781
4852
  });
4782
4853
  })
4783
4854
  }