@ptkl/sdk 1.10.0 → 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,73 +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
- if (Object.keys(ctx.$adv || []).length > 0) {
173
- params.$adv = [(_a = ctx.$adv) !== null && _a !== void 0 ? _a : {}];
174
- }
175
- if (ctx.$aggregate && ctx.$aggregate.length > 0) {
176
- 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;
177
166
  }
178
- return await this.client.post(`/v4/system/component/${this.ref}/models`, {
179
- ...params,
180
- options: opts
181
- }, {
167
+ const body = this._buildFindBody(filters, opts);
168
+ return this.client.post(`/v4/system/component/${this.ref}/models`, body, {
182
169
  headers: {
183
170
  "Accept-Language": (opts === null || opts === void 0 ? void 0 : opts.locale) || "en_US",
184
171
  }
@@ -207,6 +194,34 @@ class Component extends PlatformBaseClient {
207
194
  }
208
195
  return null;
209
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
+ }
210
225
  /**
211
226
  * Get model by uuid
212
227
  *
@@ -1292,6 +1307,145 @@ class Forge extends PlatformBaseClient {
1292
1307
  }
1293
1308
  }
1294
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
+
1295
1449
  class Project extends PlatformBaseClient {
1296
1450
  /**
1297
1451
  * Get list of all projects for the current user
@@ -1516,6 +1670,9 @@ class Platform extends PlatformBaseClient {
1516
1670
  forge() {
1517
1671
  return (new Forge()).setClient(this.client);
1518
1672
  }
1673
+ kortex() {
1674
+ return (new Kortex()).setClient(this.client);
1675
+ }
1519
1676
  component(ref) {
1520
1677
  return (new Component(ref)).setClient(this.client);
1521
1678
  }
@@ -1882,6 +2039,12 @@ class DMS extends IntegrationsBaseClient {
1882
2039
  async generateDocument(payload) {
1883
2040
  return this.requestv2('POST', 'documents/document/generate', { data: payload });
1884
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
+ }
1885
2048
  async fillPdf(data) {
1886
2049
  const { input_path, output_path, output_pdf = false, output_type, output_file_name, replace, form_data, forms } = data;
1887
2050
  const responseType = output_pdf ? 'arraybuffer' : 'json';
@@ -3428,6 +3591,45 @@ class Ecommerce extends IntegrationsBaseClient {
3428
3591
  }
3429
3592
  }
3430
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
+
3431
3633
  class Integrations extends IntegrationsBaseClient {
3432
3634
  constructor(options) {
3433
3635
  super(options);
@@ -3439,6 +3641,7 @@ class Integrations extends IntegrationsBaseClient {
3439
3641
  'protokol-payments': new Payments().setClient(this.client),
3440
3642
  'protokol-minimax': new Minimax().setClient(this.client),
3441
3643
  'protokol-ecommerce': new Ecommerce().setClient(this.client),
3644
+ 'protokol-timber': new Timber().setClient(this.client),
3442
3645
  };
3443
3646
  }
3444
3647
  getDMS() {
@@ -3465,6 +3668,9 @@ class Integrations extends IntegrationsBaseClient {
3465
3668
  getEcommerce() {
3466
3669
  return this.getInterfaceOf('protokol-ecommerce');
3467
3670
  }
3671
+ getTimber() {
3672
+ return this.getInterfaceOf('protokol-timber');
3673
+ }
3468
3674
  async list() {
3469
3675
  const { data } = await this.client.get("/v1/integrations");
3470
3676
  return data;
@@ -3639,4 +3845,4 @@ class Invoicing extends PlatformBaseClient {
3639
3845
  }
3640
3846
  }
3641
3847
 
3642
- 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 };
@@ -18,6 +18,7 @@ type FindOptions = {
18
18
  buildTTL?: number;
19
19
  locale?: string;
20
20
  unmaskPasswords?: boolean;
21
+ stream?: boolean;
21
22
  };
22
23
  type FindResponse = {
23
24
  items: Model[];
@@ -48,6 +49,29 @@ type AggregateChainable = {
48
49
  then: <T>(resolve?: (value: any) => T, reject?: (error: any) => any) => Promise<T>;
49
50
  catch: (reject: (error: any) => any) => Promise<any>;
50
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
+ };
51
75
  type FindAdvancedParams = {
52
76
  [key: string]: any;
53
77
  };
@@ -410,4 +434,4 @@ type SetupData = {
410
434
  settings?: Settings;
411
435
  };
412
436
  type ComponentCreateResponse = ComponentListItem;
413
- 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[];