@ptkl/sdk 1.9.2 → 1.11.0

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.
@@ -1,11 +1,12 @@
1
1
  import PlatformBaseClient from "./platformBaseClient";
2
+ import type { ThunderReadOptions } from "../types/thunder";
2
3
  export default class Thunder extends PlatformBaseClient {
3
- read(type: string, filters: any, flag: string, options?: any, only?: string[]): Promise<import("axios").AxiosResponse<any, any>>;
4
+ read(type: string, filters: any, flag: string, opts?: ThunderReadOptions): Promise<import("axios").AxiosResponse<any, any>>;
4
5
  write(type: string, filters: any, d: any, flag: any): Promise<import("axios").AxiosResponse<any, any>>;
5
6
  operation(name: string, filters: any, data: any): Promise<import("axios").AxiosResponse<any, any>>;
6
- find(name: string, filters: any, only?: string[]): Promise<import("axios").AxiosResponse<any, any>>;
7
- findOne(name: string, filters: any, only?: string[]): Promise<import("axios").AxiosResponse<any, any>>;
8
- paginate(name: string, filters: any, options?: any, only?: string[]): Promise<import("axios").AxiosResponse<any, any>>;
7
+ find(name: string, filters: any, options?: ThunderReadOptions): Promise<import("axios").AxiosResponse<any, any>>;
8
+ findOne(name: string, filters: any, options?: ThunderReadOptions): Promise<import("axios").AxiosResponse<any, any>>;
9
+ paginate(name: string, filters: any, options?: ThunderReadOptions): Promise<import("axios").AxiosResponse<any, any>>;
9
10
  upsert(name: string, filters: any, data: any): Promise<import("axios").AxiosResponse<any, any>>;
10
11
  insertOne(name: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
11
12
  updateOne(name: string, filters: any, data: any): Promise<import("axios").AxiosResponse<any, any>>;
@@ -19079,77 +19079,60 @@ class Component extends PlatformBaseClient {
19079
19079
  super();
19080
19080
  this.ref = ref;
19081
19081
  }
19082
- /**
19083
- * Find method to search for models
19084
- *
19085
- * @param {FindParams} filters - The filters to apply to the search
19086
- * @param {FindOptions} opts - The options to apply to the search
19087
- *
19088
- * @returns {Promise<FindResponse>} - The result of the search
19089
- *
19090
- * @example
19091
- * platform.component(name).find({
19092
- * currentPage: 1,
19093
- * perPage: 10,
19094
- * })
19095
- *
19096
- * // advanced search
19097
- * platform.component(name).find({
19098
- * $adv: {
19099
- * name: "John Doe",
19100
- * }
19101
- * )
19102
- **/
19103
- async find(filters, opts) {
19104
- var _a;
19105
- let payload = {
19106
- context: filters,
19107
- ref: this.ref,
19108
- };
19109
- let ctx = payload.context;
19110
- let offset = ctx.currentPage;
19111
- if (offset == undefined) {
19112
- offset = 0;
19113
- }
19114
- let limit = ctx.perPage;
19115
- if (limit == undefined || limit == -1) {
19116
- limit = 10;
19117
- }
19118
- let sortDesc = 1;
19119
- if (ctx.sortDesc) {
19120
- sortDesc = -1;
19121
- }
19122
- if (ctx.filterOn === undefined) {
19123
- ctx.filterOn = [];
19124
- }
19125
- let params = {
19126
- offset: offset,
19127
- sortBy: ctx.sortBy,
19128
- sortDesc: sortDesc,
19129
- filter: ctx.filter,
19130
- filterOn: ctx.filterOn,
19131
- limit: limit,
19132
- dateFrom: ctx.dateFrom,
19133
- dateTo: ctx.dateTo,
19134
- dateField: ctx.dateField,
19135
- };
19136
- if (ctx.only && ctx.only.length > 0) {
19137
- params.only = ctx.only;
19138
- }
19139
- else if (ctx.includeFields && ctx.includeFields.length > 0) {
19140
- // Backward-compatible alias. The API now prefers `only`.
19141
- params.includeFields = ctx.includeFields;
19142
- }
19143
- if (Object.keys(ctx.$adv || []).length > 0) {
19144
- params.$adv = [(_a = ctx.$adv) !== null && _a !== void 0 ? _a : {}];
19145
- }
19146
- if (ctx.$aggregate && ctx.$aggregate.length > 0) {
19147
- params.$aggregate = ctx.$aggregate;
19082
+ find(filters, opts) {
19083
+ if (opts && opts.stream === true) {
19084
+ let onMetaCallback = () => { };
19085
+ let onDataCallback = () => { };
19086
+ let onErrorCallback;
19087
+ let onEndCallback;
19088
+ let isFirstLine = true;
19089
+ const chainable = {
19090
+ onMeta: (callback) => {
19091
+ onMetaCallback = callback;
19092
+ return chainable;
19093
+ },
19094
+ onData: (callback) => {
19095
+ onDataCallback = callback;
19096
+ return chainable;
19097
+ },
19098
+ onError: (callback) => {
19099
+ onErrorCallback = callback;
19100
+ return chainable;
19101
+ },
19102
+ onEnd: (callback) => {
19103
+ onEndCallback = callback;
19104
+ return chainable;
19105
+ },
19106
+ stream: () => {
19107
+ const body = this._buildFindBody(filters, opts);
19108
+ const handler = {
19109
+ onData: async (doc) => {
19110
+ if (isFirstLine) {
19111
+ isFirstLine = false;
19112
+ const result = onMetaCallback(doc);
19113
+ if (result instanceof Promise)
19114
+ await result;
19115
+ }
19116
+ else {
19117
+ const result = onDataCallback(doc);
19118
+ if (result instanceof Promise)
19119
+ await result;
19120
+ }
19121
+ },
19122
+ onError: onErrorCallback,
19123
+ onEnd: onEndCallback,
19124
+ };
19125
+ return this._streamNDJSON(`/v4/system/component/${this.ref}/models/stream`, {
19126
+ 'Accept': 'application/x-ndjson',
19127
+ 'Content-Type': 'application/json',
19128
+ 'Accept-Language': (opts === null || opts === void 0 ? void 0 : opts.locale) || 'en_US',
19129
+ }, handler, body);
19130
+ }
19131
+ };
19132
+ return chainable;
19148
19133
  }
19149
- return await this.client.post(`/v4/system/component/${this.ref}/models`, {
19150
- ...params,
19151
- options: opts
19152
- }, {
19134
+ const body = this._buildFindBody(filters, opts);
19135
+ return this.client.post(`/v4/system/component/${this.ref}/models`, body, {
19153
19136
  headers: {
19154
19137
  "Accept-Language": (opts === null || opts === void 0 ? void 0 : opts.locale) || "en_US",
19155
19138
  }
@@ -19178,6 +19161,34 @@ class Component extends PlatformBaseClient {
19178
19161
  }
19179
19162
  return null;
19180
19163
  }
19164
+ /** @private Build the POST body shared by `find` (streaming and non-streaming) */
19165
+ _buildFindBody(filters, opts) {
19166
+ var _a, _b;
19167
+ let ctx = { ...filters };
19168
+ let offset = (_a = ctx.currentPage) !== null && _a !== void 0 ? _a : 0;
19169
+ let limit = (ctx.perPage == null || ctx.perPage === -1) ? 10 : ctx.perPage;
19170
+ let sortDesc = ctx.sortDesc ? -1 : 1;
19171
+ if (ctx.filterOn === undefined)
19172
+ ctx.filterOn = [];
19173
+ const params = {
19174
+ offset,
19175
+ sortBy: ctx.sortBy,
19176
+ sortDesc,
19177
+ filter: ctx.filter,
19178
+ filterOn: ctx.filterOn,
19179
+ limit,
19180
+ dateFrom: ctx.dateFrom,
19181
+ dateTo: ctx.dateTo,
19182
+ dateField: ctx.dateField,
19183
+ };
19184
+ if (ctx.only && ctx.only.length > 0)
19185
+ params.only = ctx.only;
19186
+ if (Object.keys(ctx.$adv || {}).length > 0)
19187
+ params.$adv = [(_b = ctx.$adv) !== null && _b !== void 0 ? _b : {}];
19188
+ if (ctx.$aggregate && ctx.$aggregate.length > 0)
19189
+ params.$aggregate = ctx.$aggregate;
19190
+ return { ...params, options: opts };
19191
+ }
19181
19192
  /**
19182
19193
  * Get model by uuid
19183
19194
  *
@@ -19927,12 +19938,13 @@ class ComponentUtils extends PlatformBaseClient {
19927
19938
  }
19928
19939
 
19929
19940
  class Thunder extends PlatformBaseClient {
19930
- async read(type, filters, flag, options, only) {
19941
+ async read(type, filters, flag, opts) {
19942
+ const { only, ...options } = opts !== null && opts !== void 0 ? opts : {};
19931
19943
  return await this.client.post("/v3/system/thunder", {
19932
19944
  type,
19933
19945
  filters,
19934
19946
  flag,
19935
- options,
19947
+ options: Object.keys(options).length ? options : undefined,
19936
19948
  only,
19937
19949
  });
19938
19950
  }
@@ -19947,14 +19959,14 @@ class Thunder extends PlatformBaseClient {
19947
19959
  async operation(name, filters, data) {
19948
19960
  return await this.write(name, filters, data, "Operation");
19949
19961
  }
19950
- async find(name, filters, only) {
19951
- return await this.read(name, filters, "Find", undefined, only);
19962
+ async find(name, filters, options) {
19963
+ return await this.read(name, filters, "Find", options);
19952
19964
  }
19953
- async findOne(name, filters, only) {
19954
- return await this.read(name, filters, "FindOne", undefined, only);
19965
+ async findOne(name, filters, options) {
19966
+ return await this.read(name, filters, "FindOne", options);
19955
19967
  }
19956
- async paginate(name, filters, options, only) {
19957
- return await this.read(name, filters, "Paginate", options, only);
19968
+ async paginate(name, filters, options) {
19969
+ return await this.read(name, filters, "Paginate", options);
19958
19970
  }
19959
19971
  async upsert(name, filters, data) {
19960
19972
  return await this.write(name, filters, data, "Upsert");
@@ -20262,6 +20274,145 @@ class Forge extends PlatformBaseClient {
20262
20274
  }
20263
20275
  }
20264
20276
 
20277
+ const BASE = '/luma/kortex/v1';
20278
+ class Kortex extends PlatformBaseClient {
20279
+ // ── Agents ──
20280
+ async createAgent(data) {
20281
+ return await this.client.post(`${BASE}/agents`, data);
20282
+ }
20283
+ async listAgents(params) {
20284
+ return await this.client.get(`${BASE}/agents`, { params });
20285
+ }
20286
+ async getAgent(uuid) {
20287
+ return await this.client.get(`${BASE}/agents/${uuid}`);
20288
+ }
20289
+ async updateAgent(uuid, data) {
20290
+ return await this.client.patch(`${BASE}/agents/${uuid}`, data);
20291
+ }
20292
+ async deleteAgent(uuid) {
20293
+ return await this.client.delete(`${BASE}/agents/${uuid}`);
20294
+ }
20295
+ async listAgentKnowledgeBases(agentUUID) {
20296
+ return await this.client.get(`${BASE}/agents/${agentUUID}/knowledge-bases`);
20297
+ }
20298
+ // ── Knowledge Bases ──
20299
+ async createKnowledgeBase(data) {
20300
+ return await this.client.post(`${BASE}/knowledge-bases`, data);
20301
+ }
20302
+ async listKnowledgeBases(params) {
20303
+ return await this.client.get(`${BASE}/knowledge-bases`, { params });
20304
+ }
20305
+ async getKnowledgeBase(uuid) {
20306
+ return await this.client.get(`${BASE}/knowledge-bases/${uuid}`);
20307
+ }
20308
+ async updateKnowledgeBase(uuid, data) {
20309
+ return await this.client.put(`${BASE}/knowledge-bases/${uuid}`, data);
20310
+ }
20311
+ async deleteKnowledgeBase(uuid) {
20312
+ return await this.client.delete(`${BASE}/knowledge-bases/${uuid}`);
20313
+ }
20314
+ // ── Documents ──
20315
+ async listDocuments(kbUUID, params) {
20316
+ return await this.client.get(`${BASE}/knowledge-bases/${kbUUID}/documents`, { params });
20317
+ }
20318
+ async uploadDocument(kbUUID, formData) {
20319
+ return await this.client.post(`${BASE}/knowledge-bases/${kbUUID}/documents`, formData, {
20320
+ headers: { 'Content-Type': 'multipart/form-data' },
20321
+ timeout: 120000,
20322
+ });
20323
+ }
20324
+ async getDocument(kbUUID, uuid) {
20325
+ return await this.client.get(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}`);
20326
+ }
20327
+ async deleteDocument(kbUUID, uuid) {
20328
+ return await this.client.delete(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}`);
20329
+ }
20330
+ async retryDocument(kbUUID, uuid) {
20331
+ return await this.client.post(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}/retry`);
20332
+ }
20333
+ // ── Conversations ──
20334
+ async createConversation(data) {
20335
+ return await this.client.post(`${BASE}/conversations`, data);
20336
+ }
20337
+ async listConversations(params) {
20338
+ return await this.client.get(`${BASE}/conversations`, { params });
20339
+ }
20340
+ async getConversation(uuid) {
20341
+ return await this.client.get(`${BASE}/conversations/${uuid}`);
20342
+ }
20343
+ async updateConversation(uuid, data) {
20344
+ return await this.client.put(`${BASE}/conversations/${uuid}`, data);
20345
+ }
20346
+ async deleteConversation(uuid) {
20347
+ return await this.client.delete(`${BASE}/conversations/${uuid}`);
20348
+ }
20349
+ async archiveConversation(uuid) {
20350
+ return await this.client.post(`${BASE}/conversations/${uuid}/archive`);
20351
+ }
20352
+ async unarchiveConversation(uuid) {
20353
+ return await this.client.post(`${BASE}/conversations/${uuid}/unarchive`);
20354
+ }
20355
+ async addParticipant(conversationUUID, data) {
20356
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/participants`, data);
20357
+ }
20358
+ async removeParticipant(conversationUUID, agentUUID) {
20359
+ return await this.client.delete(`${BASE}/conversations/${conversationUUID}/participants/${agentUUID}`);
20360
+ }
20361
+ // ── Messages / Completions ──
20362
+ async sendMessage(conversationUUID, data) {
20363
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages`, data);
20364
+ }
20365
+ async streamMessage(conversationUUID, data) {
20366
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages`, { ...data, stream: true }, {
20367
+ responseType: 'stream',
20368
+ timeout: 120000,
20369
+ });
20370
+ }
20371
+ async listMessages(conversationUUID, params) {
20372
+ return await this.client.get(`${BASE}/conversations/${conversationUUID}/messages`, { params });
20373
+ }
20374
+ async injectMessage(conversationUUID, data) {
20375
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages/inject`, data);
20376
+ }
20377
+ // ── OCR ──
20378
+ async ocr(data) {
20379
+ return await this.client.post(`${BASE}/ocr`, data, { timeout: 120000 });
20380
+ }
20381
+ // ── User Access ──
20382
+ async createUserAccess(data) {
20383
+ return await this.client.post(`${BASE}/user-access`, data);
20384
+ }
20385
+ async listUserAccess(params) {
20386
+ return await this.client.get(`${BASE}/user-access`, { params });
20387
+ }
20388
+ async getUserAccess(uuid) {
20389
+ return await this.client.get(`${BASE}/user-access/${uuid}`);
20390
+ }
20391
+ async updateUserAccess(uuid, data) {
20392
+ return await this.client.patch(`${BASE}/user-access/${uuid}`, data);
20393
+ }
20394
+ async deleteUserAccess(uuid) {
20395
+ return await this.client.delete(`${BASE}/user-access/${uuid}`);
20396
+ }
20397
+ async getUserMonthlyUsage(uuid, params) {
20398
+ return await this.client.get(`${BASE}/user-access/${uuid}/usage`, { params });
20399
+ }
20400
+ async getUserUsageBreakdown(uuid) {
20401
+ return await this.client.get(`${BASE}/user-access/${uuid}/usage/breakdown`);
20402
+ }
20403
+ async getMyAccess() {
20404
+ return await this.client.get(`${BASE}/my-access`);
20405
+ }
20406
+ // ── Usage (Admin) ──
20407
+ async listUsage(params) {
20408
+ return await this.client.get(`${BASE}/usage`, { params });
20409
+ }
20410
+ // ── Tier ──
20411
+ async getTier() {
20412
+ return await this.client.get(`${BASE}/tier`);
20413
+ }
20414
+ }
20415
+
20265
20416
  class Project extends PlatformBaseClient {
20266
20417
  /**
20267
20418
  * Get list of all projects for the current user
@@ -20486,6 +20637,9 @@ class Platform extends PlatformBaseClient {
20486
20637
  forge() {
20487
20638
  return (new Forge()).setClient(this.client);
20488
20639
  }
20640
+ kortex() {
20641
+ return (new Kortex()).setClient(this.client);
20642
+ }
20489
20643
  component(ref) {
20490
20644
  return (new Component(ref)).setClient(this.client);
20491
20645
  }
@@ -20852,6 +21006,12 @@ class DMS extends IntegrationsBaseClient {
20852
21006
  async generateDocument(payload) {
20853
21007
  return this.requestv2('POST', 'documents/document/generate', { data: payload });
20854
21008
  }
21009
+ async listDocumentRevisions(path) {
21010
+ return this.requestv2('GET', `documents/revisions/${path}`);
21011
+ }
21012
+ async getDocumentRevision(path, version) {
21013
+ return this.requestv2('GET', `documents/revision/${path}`, { params: { version } });
21014
+ }
20855
21015
  async fillPdf(data) {
20856
21016
  const { input_path, output_path, output_pdf = false, output_type, output_file_name, replace, form_data, forms } = data;
20857
21017
  const responseType = output_pdf ? 'arraybuffer' : 'json';
@@ -22398,6 +22558,45 @@ class Ecommerce extends IntegrationsBaseClient {
22398
22558
  }
22399
22559
  }
22400
22560
 
22561
+ class Timber extends IntegrationsBaseClient {
22562
+ async query(params = {}) {
22563
+ const { data } = await this.client.get("/v1/timber/logs", {
22564
+ params: this.normalizeParams(params),
22565
+ });
22566
+ return data;
22567
+ }
22568
+ async write(payload) {
22569
+ const { data } = await this.client.post("/v1/timber/logs", payload);
22570
+ return data;
22571
+ }
22572
+ async usage() {
22573
+ const { data } = await this.client.get("/v1/timber/usage");
22574
+ return data;
22575
+ }
22576
+ async debug(message, payload) {
22577
+ return this.write({ ...payload, message, level: 'debug' });
22578
+ }
22579
+ async info(message, payload) {
22580
+ return this.write({ ...payload, message, level: 'info' });
22581
+ }
22582
+ async warn(message, payload) {
22583
+ return this.write({ ...payload, message, level: 'warn' });
22584
+ }
22585
+ async error(message, payload) {
22586
+ return this.write({ ...payload, message, level: 'error' });
22587
+ }
22588
+ normalizeParams(params) {
22589
+ const normalized = { ...params };
22590
+ if (params.from instanceof Date) {
22591
+ normalized.from = params.from.toISOString();
22592
+ }
22593
+ if (params.to instanceof Date) {
22594
+ normalized.to = params.to.toISOString();
22595
+ }
22596
+ return normalized;
22597
+ }
22598
+ }
22599
+
22401
22600
  class Integrations extends IntegrationsBaseClient {
22402
22601
  constructor(options) {
22403
22602
  super(options);
@@ -22409,6 +22608,7 @@ class Integrations extends IntegrationsBaseClient {
22409
22608
  'protokol-payments': new Payments().setClient(this.client),
22410
22609
  'protokol-minimax': new Minimax().setClient(this.client),
22411
22610
  'protokol-ecommerce': new Ecommerce().setClient(this.client),
22611
+ 'protokol-timber': new Timber().setClient(this.client),
22412
22612
  };
22413
22613
  }
22414
22614
  getDMS() {
@@ -22435,6 +22635,9 @@ class Integrations extends IntegrationsBaseClient {
22435
22635
  getEcommerce() {
22436
22636
  return this.getInterfaceOf('protokol-ecommerce');
22437
22637
  }
22638
+ getTimber() {
22639
+ return this.getInterfaceOf('protokol-timber');
22640
+ }
22438
22641
  async list() {
22439
22642
  const { data } = await this.client.get("/v1/integrations");
22440
22643
  return data;
@@ -22621,6 +22824,7 @@ exports.Functions = Functions;
22621
22824
  exports.Integration = Integrations;
22622
22825
  exports.Integrations = Integrations;
22623
22826
  exports.Invoicing = Invoicing;
22827
+ exports.Kortex = Kortex;
22624
22828
  exports.Mail = Mail;
22625
22829
  exports.NBS = NBS;
22626
22830
  exports.PRN = PRN;
@@ -22632,6 +22836,7 @@ exports.Sandbox = Sandbox;
22632
22836
  exports.SerbiaMinFin = MinFin;
22633
22837
  exports.System = System;
22634
22838
  exports.Thunder = Thunder;
22839
+ exports.Timber = Timber;
22635
22840
  exports.Users = Users;
22636
22841
  exports.VPFR = VPFR;
22637
22842
  exports.Workflow = Workflow;