@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.
@@ -112,77 +112,60 @@ class Component extends PlatformBaseClient {
112
112
  super();
113
113
  this.ref = ref;
114
114
  }
115
- /**
116
- * Find method to search for models
117
- *
118
- * @param {FindParams} filters - The filters to apply to the search
119
- * @param {FindOptions} opts - The options to apply to the search
120
- *
121
- * @returns {Promise<FindResponse>} - The result of the search
122
- *
123
- * @example
124
- * platform.component(name).find({
125
- * currentPage: 1,
126
- * perPage: 10,
127
- * })
128
- *
129
- * // advanced search
130
- * platform.component(name).find({
131
- * $adv: {
132
- * name: "John Doe",
133
- * }
134
- * )
135
- **/
136
- async find(filters, opts) {
137
- var _a;
138
- let payload = {
139
- context: filters,
140
- ref: this.ref,
141
- };
142
- let ctx = payload.context;
143
- let offset = ctx.currentPage;
144
- if (offset == undefined) {
145
- offset = 0;
146
- }
147
- let limit = ctx.perPage;
148
- if (limit == undefined || limit == -1) {
149
- limit = 10;
150
- }
151
- let sortDesc = 1;
152
- if (ctx.sortDesc) {
153
- sortDesc = -1;
154
- }
155
- if (ctx.filterOn === undefined) {
156
- ctx.filterOn = [];
157
- }
158
- let params = {
159
- offset: offset,
160
- sortBy: ctx.sortBy,
161
- sortDesc: sortDesc,
162
- filter: ctx.filter,
163
- filterOn: ctx.filterOn,
164
- limit: limit,
165
- dateFrom: ctx.dateFrom,
166
- dateTo: ctx.dateTo,
167
- dateField: ctx.dateField,
168
- };
169
- if (ctx.only && ctx.only.length > 0) {
170
- params.only = ctx.only;
171
- }
172
- else if (ctx.includeFields && ctx.includeFields.length > 0) {
173
- // Backward-compatible alias. The API now prefers `only`.
174
- params.includeFields = ctx.includeFields;
175
- }
176
- if (Object.keys(ctx.$adv || []).length > 0) {
177
- params.$adv = [(_a = ctx.$adv) !== null && _a !== void 0 ? _a : {}];
178
- }
179
- if (ctx.$aggregate && ctx.$aggregate.length > 0) {
180
- params.$aggregate = ctx.$aggregate;
115
+ find(filters, opts) {
116
+ if (opts && opts.stream === true) {
117
+ let onMetaCallback = () => { };
118
+ let onDataCallback = () => { };
119
+ let onErrorCallback;
120
+ let onEndCallback;
121
+ let isFirstLine = true;
122
+ const chainable = {
123
+ onMeta: (callback) => {
124
+ onMetaCallback = callback;
125
+ return chainable;
126
+ },
127
+ onData: (callback) => {
128
+ onDataCallback = callback;
129
+ return chainable;
130
+ },
131
+ onError: (callback) => {
132
+ onErrorCallback = callback;
133
+ return chainable;
134
+ },
135
+ onEnd: (callback) => {
136
+ onEndCallback = callback;
137
+ return chainable;
138
+ },
139
+ stream: () => {
140
+ const body = this._buildFindBody(filters, opts);
141
+ const handler = {
142
+ onData: async (doc) => {
143
+ if (isFirstLine) {
144
+ isFirstLine = false;
145
+ const result = onMetaCallback(doc);
146
+ if (result instanceof Promise)
147
+ await result;
148
+ }
149
+ else {
150
+ const result = onDataCallback(doc);
151
+ if (result instanceof Promise)
152
+ await result;
153
+ }
154
+ },
155
+ onError: onErrorCallback,
156
+ onEnd: onEndCallback,
157
+ };
158
+ return this._streamNDJSON(`/v4/system/component/${this.ref}/models/stream`, {
159
+ 'Accept': 'application/x-ndjson',
160
+ 'Content-Type': 'application/json',
161
+ 'Accept-Language': (opts === null || opts === void 0 ? void 0 : opts.locale) || 'en_US',
162
+ }, handler, body);
163
+ }
164
+ };
165
+ return chainable;
181
166
  }
182
- return await this.client.post(`/v4/system/component/${this.ref}/models`, {
183
- ...params,
184
- options: opts
185
- }, {
167
+ const body = this._buildFindBody(filters, opts);
168
+ return this.client.post(`/v4/system/component/${this.ref}/models`, body, {
186
169
  headers: {
187
170
  "Accept-Language": (opts === null || opts === void 0 ? void 0 : opts.locale) || "en_US",
188
171
  }
@@ -211,6 +194,34 @@ class Component extends PlatformBaseClient {
211
194
  }
212
195
  return null;
213
196
  }
197
+ /** @private Build the POST body shared by `find` (streaming and non-streaming) */
198
+ _buildFindBody(filters, opts) {
199
+ var _a, _b;
200
+ let ctx = { ...filters };
201
+ let offset = (_a = ctx.currentPage) !== null && _a !== void 0 ? _a : 0;
202
+ let limit = (ctx.perPage == null || ctx.perPage === -1) ? 10 : ctx.perPage;
203
+ let sortDesc = ctx.sortDesc ? -1 : 1;
204
+ if (ctx.filterOn === undefined)
205
+ ctx.filterOn = [];
206
+ const params = {
207
+ offset,
208
+ sortBy: ctx.sortBy,
209
+ sortDesc,
210
+ filter: ctx.filter,
211
+ filterOn: ctx.filterOn,
212
+ limit,
213
+ dateFrom: ctx.dateFrom,
214
+ dateTo: ctx.dateTo,
215
+ dateField: ctx.dateField,
216
+ };
217
+ if (ctx.only && ctx.only.length > 0)
218
+ params.only = ctx.only;
219
+ if (Object.keys(ctx.$adv || {}).length > 0)
220
+ params.$adv = [(_b = ctx.$adv) !== null && _b !== void 0 ? _b : {}];
221
+ if (ctx.$aggregate && ctx.$aggregate.length > 0)
222
+ params.$aggregate = ctx.$aggregate;
223
+ return { ...params, options: opts };
224
+ }
214
225
  /**
215
226
  * Get model by uuid
216
227
  *
@@ -960,12 +971,13 @@ class ComponentUtils extends PlatformBaseClient {
960
971
  }
961
972
 
962
973
  class Thunder extends PlatformBaseClient {
963
- async read(type, filters, flag, options, only) {
974
+ async read(type, filters, flag, opts) {
975
+ const { only, ...options } = opts !== null && opts !== void 0 ? opts : {};
964
976
  return await this.client.post("/v3/system/thunder", {
965
977
  type,
966
978
  filters,
967
979
  flag,
968
- options,
980
+ options: Object.keys(options).length ? options : undefined,
969
981
  only,
970
982
  });
971
983
  }
@@ -980,14 +992,14 @@ class Thunder extends PlatformBaseClient {
980
992
  async operation(name, filters, data) {
981
993
  return await this.write(name, filters, data, "Operation");
982
994
  }
983
- async find(name, filters, only) {
984
- return await this.read(name, filters, "Find", undefined, only);
995
+ async find(name, filters, options) {
996
+ return await this.read(name, filters, "Find", options);
985
997
  }
986
- async findOne(name, filters, only) {
987
- return await this.read(name, filters, "FindOne", undefined, only);
998
+ async findOne(name, filters, options) {
999
+ return await this.read(name, filters, "FindOne", options);
988
1000
  }
989
- async paginate(name, filters, options, only) {
990
- return await this.read(name, filters, "Paginate", options, only);
1001
+ async paginate(name, filters, options) {
1002
+ return await this.read(name, filters, "Paginate", options);
991
1003
  }
992
1004
  async upsert(name, filters, data) {
993
1005
  return await this.write(name, filters, data, "Upsert");
@@ -1295,6 +1307,145 @@ class Forge extends PlatformBaseClient {
1295
1307
  }
1296
1308
  }
1297
1309
 
1310
+ const BASE = '/luma/kortex/v1';
1311
+ class Kortex extends PlatformBaseClient {
1312
+ // ── Agents ──
1313
+ async createAgent(data) {
1314
+ return await this.client.post(`${BASE}/agents`, data);
1315
+ }
1316
+ async listAgents(params) {
1317
+ return await this.client.get(`${BASE}/agents`, { params });
1318
+ }
1319
+ async getAgent(uuid) {
1320
+ return await this.client.get(`${BASE}/agents/${uuid}`);
1321
+ }
1322
+ async updateAgent(uuid, data) {
1323
+ return await this.client.patch(`${BASE}/agents/${uuid}`, data);
1324
+ }
1325
+ async deleteAgent(uuid) {
1326
+ return await this.client.delete(`${BASE}/agents/${uuid}`);
1327
+ }
1328
+ async listAgentKnowledgeBases(agentUUID) {
1329
+ return await this.client.get(`${BASE}/agents/${agentUUID}/knowledge-bases`);
1330
+ }
1331
+ // ── Knowledge Bases ──
1332
+ async createKnowledgeBase(data) {
1333
+ return await this.client.post(`${BASE}/knowledge-bases`, data);
1334
+ }
1335
+ async listKnowledgeBases(params) {
1336
+ return await this.client.get(`${BASE}/knowledge-bases`, { params });
1337
+ }
1338
+ async getKnowledgeBase(uuid) {
1339
+ return await this.client.get(`${BASE}/knowledge-bases/${uuid}`);
1340
+ }
1341
+ async updateKnowledgeBase(uuid, data) {
1342
+ return await this.client.put(`${BASE}/knowledge-bases/${uuid}`, data);
1343
+ }
1344
+ async deleteKnowledgeBase(uuid) {
1345
+ return await this.client.delete(`${BASE}/knowledge-bases/${uuid}`);
1346
+ }
1347
+ // ── Documents ──
1348
+ async listDocuments(kbUUID, params) {
1349
+ return await this.client.get(`${BASE}/knowledge-bases/${kbUUID}/documents`, { params });
1350
+ }
1351
+ async uploadDocument(kbUUID, formData) {
1352
+ return await this.client.post(`${BASE}/knowledge-bases/${kbUUID}/documents`, formData, {
1353
+ headers: { 'Content-Type': 'multipart/form-data' },
1354
+ timeout: 120000,
1355
+ });
1356
+ }
1357
+ async getDocument(kbUUID, uuid) {
1358
+ return await this.client.get(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}`);
1359
+ }
1360
+ async deleteDocument(kbUUID, uuid) {
1361
+ return await this.client.delete(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}`);
1362
+ }
1363
+ async retryDocument(kbUUID, uuid) {
1364
+ return await this.client.post(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}/retry`);
1365
+ }
1366
+ // ── Conversations ──
1367
+ async createConversation(data) {
1368
+ return await this.client.post(`${BASE}/conversations`, data);
1369
+ }
1370
+ async listConversations(params) {
1371
+ return await this.client.get(`${BASE}/conversations`, { params });
1372
+ }
1373
+ async getConversation(uuid) {
1374
+ return await this.client.get(`${BASE}/conversations/${uuid}`);
1375
+ }
1376
+ async updateConversation(uuid, data) {
1377
+ return await this.client.put(`${BASE}/conversations/${uuid}`, data);
1378
+ }
1379
+ async deleteConversation(uuid) {
1380
+ return await this.client.delete(`${BASE}/conversations/${uuid}`);
1381
+ }
1382
+ async archiveConversation(uuid) {
1383
+ return await this.client.post(`${BASE}/conversations/${uuid}/archive`);
1384
+ }
1385
+ async unarchiveConversation(uuid) {
1386
+ return await this.client.post(`${BASE}/conversations/${uuid}/unarchive`);
1387
+ }
1388
+ async addParticipant(conversationUUID, data) {
1389
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/participants`, data);
1390
+ }
1391
+ async removeParticipant(conversationUUID, agentUUID) {
1392
+ return await this.client.delete(`${BASE}/conversations/${conversationUUID}/participants/${agentUUID}`);
1393
+ }
1394
+ // ── Messages / Completions ──
1395
+ async sendMessage(conversationUUID, data) {
1396
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages`, data);
1397
+ }
1398
+ async streamMessage(conversationUUID, data) {
1399
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages`, { ...data, stream: true }, {
1400
+ responseType: 'stream',
1401
+ timeout: 120000,
1402
+ });
1403
+ }
1404
+ async listMessages(conversationUUID, params) {
1405
+ return await this.client.get(`${BASE}/conversations/${conversationUUID}/messages`, { params });
1406
+ }
1407
+ async injectMessage(conversationUUID, data) {
1408
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages/inject`, data);
1409
+ }
1410
+ // ── OCR ──
1411
+ async ocr(data) {
1412
+ return await this.client.post(`${BASE}/ocr`, data, { timeout: 120000 });
1413
+ }
1414
+ // ── User Access ──
1415
+ async createUserAccess(data) {
1416
+ return await this.client.post(`${BASE}/user-access`, data);
1417
+ }
1418
+ async listUserAccess(params) {
1419
+ return await this.client.get(`${BASE}/user-access`, { params });
1420
+ }
1421
+ async getUserAccess(uuid) {
1422
+ return await this.client.get(`${BASE}/user-access/${uuid}`);
1423
+ }
1424
+ async updateUserAccess(uuid, data) {
1425
+ return await this.client.patch(`${BASE}/user-access/${uuid}`, data);
1426
+ }
1427
+ async deleteUserAccess(uuid) {
1428
+ return await this.client.delete(`${BASE}/user-access/${uuid}`);
1429
+ }
1430
+ async getUserMonthlyUsage(uuid, params) {
1431
+ return await this.client.get(`${BASE}/user-access/${uuid}/usage`, { params });
1432
+ }
1433
+ async getUserUsageBreakdown(uuid) {
1434
+ return await this.client.get(`${BASE}/user-access/${uuid}/usage/breakdown`);
1435
+ }
1436
+ async getMyAccess() {
1437
+ return await this.client.get(`${BASE}/my-access`);
1438
+ }
1439
+ // ── Usage (Admin) ──
1440
+ async listUsage(params) {
1441
+ return await this.client.get(`${BASE}/usage`, { params });
1442
+ }
1443
+ // ── Tier ──
1444
+ async getTier() {
1445
+ return await this.client.get(`${BASE}/tier`);
1446
+ }
1447
+ }
1448
+
1298
1449
  class Project extends PlatformBaseClient {
1299
1450
  /**
1300
1451
  * Get list of all projects for the current user
@@ -1519,6 +1670,9 @@ class Platform extends PlatformBaseClient {
1519
1670
  forge() {
1520
1671
  return (new Forge()).setClient(this.client);
1521
1672
  }
1673
+ kortex() {
1674
+ return (new Kortex()).setClient(this.client);
1675
+ }
1522
1676
  component(ref) {
1523
1677
  return (new Component(ref)).setClient(this.client);
1524
1678
  }
@@ -1885,6 +2039,12 @@ class DMS extends IntegrationsBaseClient {
1885
2039
  async generateDocument(payload) {
1886
2040
  return this.requestv2('POST', 'documents/document/generate', { data: payload });
1887
2041
  }
2042
+ async listDocumentRevisions(path) {
2043
+ return this.requestv2('GET', `documents/revisions/${path}`);
2044
+ }
2045
+ async getDocumentRevision(path, version) {
2046
+ return this.requestv2('GET', `documents/revision/${path}`, { params: { version } });
2047
+ }
1888
2048
  async fillPdf(data) {
1889
2049
  const { input_path, output_path, output_pdf = false, output_type, output_file_name, replace, form_data, forms } = data;
1890
2050
  const responseType = output_pdf ? 'arraybuffer' : 'json';
@@ -3431,6 +3591,45 @@ class Ecommerce extends IntegrationsBaseClient {
3431
3591
  }
3432
3592
  }
3433
3593
 
3594
+ class Timber extends IntegrationsBaseClient {
3595
+ async query(params = {}) {
3596
+ const { data } = await this.client.get("/v1/timber/logs", {
3597
+ params: this.normalizeParams(params),
3598
+ });
3599
+ return data;
3600
+ }
3601
+ async write(payload) {
3602
+ const { data } = await this.client.post("/v1/timber/logs", payload);
3603
+ return data;
3604
+ }
3605
+ async usage() {
3606
+ const { data } = await this.client.get("/v1/timber/usage");
3607
+ return data;
3608
+ }
3609
+ async debug(message, payload) {
3610
+ return this.write({ ...payload, message, level: 'debug' });
3611
+ }
3612
+ async info(message, payload) {
3613
+ return this.write({ ...payload, message, level: 'info' });
3614
+ }
3615
+ async warn(message, payload) {
3616
+ return this.write({ ...payload, message, level: 'warn' });
3617
+ }
3618
+ async error(message, payload) {
3619
+ return this.write({ ...payload, message, level: 'error' });
3620
+ }
3621
+ normalizeParams(params) {
3622
+ const normalized = { ...params };
3623
+ if (params.from instanceof Date) {
3624
+ normalized.from = params.from.toISOString();
3625
+ }
3626
+ if (params.to instanceof Date) {
3627
+ normalized.to = params.to.toISOString();
3628
+ }
3629
+ return normalized;
3630
+ }
3631
+ }
3632
+
3434
3633
  class Integrations extends IntegrationsBaseClient {
3435
3634
  constructor(options) {
3436
3635
  super(options);
@@ -3442,6 +3641,7 @@ class Integrations extends IntegrationsBaseClient {
3442
3641
  'protokol-payments': new Payments().setClient(this.client),
3443
3642
  'protokol-minimax': new Minimax().setClient(this.client),
3444
3643
  'protokol-ecommerce': new Ecommerce().setClient(this.client),
3644
+ 'protokol-timber': new Timber().setClient(this.client),
3445
3645
  };
3446
3646
  }
3447
3647
  getDMS() {
@@ -3468,6 +3668,9 @@ class Integrations extends IntegrationsBaseClient {
3468
3668
  getEcommerce() {
3469
3669
  return this.getInterfaceOf('protokol-ecommerce');
3470
3670
  }
3671
+ getTimber() {
3672
+ return this.getInterfaceOf('protokol-timber');
3673
+ }
3471
3674
  async list() {
3472
3675
  const { data } = await this.client.get("/v1/integrations");
3473
3676
  return data;
@@ -3642,4 +3845,4 @@ class Invoicing extends PlatformBaseClient {
3642
3845
  }
3643
3846
  }
3644
3847
 
3645
- export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Ecommerce, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Mail, NBS, PRN, Payments, Platform, Project, Ratchet, Sandbox, MinFin as SerbiaMinFin, System, Thunder, Users, VPFR, Workflow, parsePRN };
3848
+ export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Ecommerce, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Kortex, Mail, NBS, PRN, Payments, Platform, Project, Ratchet, Sandbox, MinFin as SerbiaMinFin, System, Thunder, Timber, Users, VPFR, Workflow, parsePRN };
@@ -10,7 +10,6 @@ type FindParams = {
10
10
  dateTo?: string;
11
11
  dateField?: string;
12
12
  only?: string[];
13
- includeFields?: string[];
14
13
  $adv?: FindAdvancedParams;
15
14
  $aggregate?: FindAggregateParams[];
16
15
  };
@@ -19,6 +18,7 @@ type FindOptions = {
19
18
  buildTTL?: number;
20
19
  locale?: string;
21
20
  unmaskPasswords?: boolean;
21
+ stream?: boolean;
22
22
  };
23
23
  type FindResponse = {
24
24
  items: Model[];
@@ -49,6 +49,29 @@ type AggregateChainable = {
49
49
  then: <T>(resolve?: (value: any) => T, reject?: (error: any) => any) => Promise<T>;
50
50
  catch: (reject: (error: any) => any) => Promise<any>;
51
51
  };
52
+ /**
53
+ * Pagination metadata emitted as the first NDJSON line from findStream
54
+ */
55
+ type FindStreamMeta = {
56
+ total: number;
57
+ total_filtered: number;
58
+ total_pages: number;
59
+ page: number;
60
+ };
61
+ /**
62
+ * Callback invoked once with pagination metadata before any records
63
+ */
64
+ type FindStreamMetaCallback = (meta: FindStreamMeta) => void | Promise<void>;
65
+ /**
66
+ * Chainable find stream result for cursor-based NDJSON pagination
67
+ */
68
+ type FindChainable = {
69
+ onMeta: (callback: FindStreamMetaCallback) => FindChainable;
70
+ onData: (callback: StreamCallback) => FindChainable;
71
+ onError: (callback: (error: Error) => void) => FindChainable;
72
+ onEnd: (callback: () => void) => FindChainable;
73
+ stream: () => Promise<void>;
74
+ };
52
75
  type FindAdvancedParams = {
53
76
  [key: string]: any;
54
77
  };
@@ -411,4 +434,4 @@ type SetupData = {
411
434
  settings?: Settings;
412
435
  };
413
436
  type ComponentCreateResponse = ComponentListItem;
414
- export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, UpdateOperators, UpdateAggregate, ModelUpdateData, ComponentOptions, ComponentListResponse, ComponentListItem, ComponentLabel, ComponentWorkspace, StreamCallback, StreamHandler, AggregateChainable, UpdateManyOptions, CreateManyOptions, Settings, SettingsField, FieldRoles, FieldConstraints, Context, Preset, PresetContext, Filters, Function, Extension, Policy, FieldAccessConfig, TemplatesDist, SetupData, ComponentCreateResponse, };
437
+ export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, UpdateOperators, UpdateAggregate, ModelUpdateData, ComponentOptions, ComponentListResponse, ComponentListItem, ComponentLabel, ComponentWorkspace, StreamCallback, StreamHandler, AggregateChainable, FindChainable, FindStreamMeta, FindStreamMetaCallback, UpdateManyOptions, CreateManyOptions, Settings, SettingsField, FieldRoles, FieldConstraints, Context, Preset, PresetContext, Filters, Function, Extension, Policy, FieldAccessConfig, TemplatesDist, SetupData, ComponentCreateResponse, };
@@ -339,3 +339,9 @@ export type DocumentGenerateResponse = {
339
339
  /** Rendered document content */
340
340
  content: string;
341
341
  };
342
+ export type DocumentRevisionItem = {
343
+ version: string;
344
+ documentVersion: number;
345
+ updatedBy: DocumentAuditEntry;
346
+ };
347
+ export type DocumentRevisionListResponse = DocumentRevisionItem[];