@ptkl/sdk 1.10.0 → 1.12.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
  *
@@ -1273,6 +1288,7 @@ class Workflow extends PlatformBaseClient {
1273
1288
  }
1274
1289
 
1275
1290
  class Forge extends PlatformBaseClient {
1291
+ // --- Management (appservice) ---
1276
1292
  async bundleUpload(buffer) {
1277
1293
  return await this.client.post(`/luma/appservice/v1/forge/upload`, buffer, {
1278
1294
  headers: {
@@ -1290,6 +1306,170 @@ class Forge extends PlatformBaseClient {
1290
1306
  async list() {
1291
1307
  return await this.client.get(`/luma/appservice/v1/forge`);
1292
1308
  }
1309
+ async listServices(ref) {
1310
+ return await this.client.get(`/luma/appservice/v1/forge/${ref}/services`);
1311
+ }
1312
+ // --- Variables ---
1313
+ async getVariables(ref) {
1314
+ return await this.client.get(`/luma/appservice/v1/forge/${ref}/variables`);
1315
+ }
1316
+ async updateVariables(ref, variables) {
1317
+ return await this.client.patch(`/luma/appservice/v1/forge/${ref}/variables`, variables);
1318
+ }
1319
+ async addVariable(ref, key, value) {
1320
+ var _a;
1321
+ const resp = await this.client.get(`/luma/appservice/v1/forge/${ref}/variables`);
1322
+ const current = (_a = resp.data) !== null && _a !== void 0 ? _a : {};
1323
+ current[key] = value;
1324
+ return await this.client.patch(`/luma/appservice/v1/forge/${ref}/variables`, current);
1325
+ }
1326
+ // --- Service execution (forge-runtime) ---
1327
+ async callService(appUuid, serviceName, options) {
1328
+ var _a;
1329
+ const queryString = (options === null || options === void 0 ? void 0 : options.query)
1330
+ ? '?' + new URLSearchParams(options.query).toString()
1331
+ : '';
1332
+ return await this.client.post(`/luma/forge-runtime/api/services/${appUuid}/${serviceName}${queryString}`, (_a = options === null || options === void 0 ? void 0 : options.body) !== null && _a !== void 0 ? _a : {}, (options === null || options === void 0 ? void 0 : options.headers) ? { headers: options.headers } : undefined);
1333
+ }
1334
+ }
1335
+
1336
+ const BASE = '/luma/kortex/v1';
1337
+ class Kortex extends PlatformBaseClient {
1338
+ // ── Agents ──
1339
+ async createAgent(data) {
1340
+ return await this.client.post(`${BASE}/agents`, data);
1341
+ }
1342
+ async listAgents(params) {
1343
+ return await this.client.get(`${BASE}/agents`, { params });
1344
+ }
1345
+ async getAgent(uuid) {
1346
+ return await this.client.get(`${BASE}/agents/${uuid}`);
1347
+ }
1348
+ async updateAgent(uuid, data) {
1349
+ return await this.client.patch(`${BASE}/agents/${uuid}`, data);
1350
+ }
1351
+ async deleteAgent(uuid) {
1352
+ return await this.client.delete(`${BASE}/agents/${uuid}`);
1353
+ }
1354
+ async listAgentKnowledgeBases(agentUUID) {
1355
+ return await this.client.get(`${BASE}/agents/${agentUUID}/knowledge-bases`);
1356
+ }
1357
+ // ── Knowledge Bases ──
1358
+ async createKnowledgeBase(data) {
1359
+ return await this.client.post(`${BASE}/knowledge-bases`, data);
1360
+ }
1361
+ async listKnowledgeBases(params) {
1362
+ return await this.client.get(`${BASE}/knowledge-bases`, { params });
1363
+ }
1364
+ async getKnowledgeBase(uuid) {
1365
+ return await this.client.get(`${BASE}/knowledge-bases/${uuid}`);
1366
+ }
1367
+ async updateKnowledgeBase(uuid, data) {
1368
+ return await this.client.put(`${BASE}/knowledge-bases/${uuid}`, data);
1369
+ }
1370
+ async deleteKnowledgeBase(uuid) {
1371
+ return await this.client.delete(`${BASE}/knowledge-bases/${uuid}`);
1372
+ }
1373
+ // ── Documents ──
1374
+ async listDocuments(kbUUID, params) {
1375
+ return await this.client.get(`${BASE}/knowledge-bases/${kbUUID}/documents`, { params });
1376
+ }
1377
+ async uploadDocument(kbUUID, formData) {
1378
+ return await this.client.post(`${BASE}/knowledge-bases/${kbUUID}/documents`, formData, {
1379
+ headers: { 'Content-Type': 'multipart/form-data' },
1380
+ timeout: 120000,
1381
+ });
1382
+ }
1383
+ async getDocument(kbUUID, uuid) {
1384
+ return await this.client.get(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}`);
1385
+ }
1386
+ async deleteDocument(kbUUID, uuid) {
1387
+ return await this.client.delete(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}`);
1388
+ }
1389
+ async retryDocument(kbUUID, uuid) {
1390
+ return await this.client.post(`${BASE}/knowledge-bases/${kbUUID}/documents/${uuid}/retry`);
1391
+ }
1392
+ // ── Conversations ──
1393
+ async createConversation(data) {
1394
+ return await this.client.post(`${BASE}/conversations`, data);
1395
+ }
1396
+ async listConversations(params) {
1397
+ return await this.client.get(`${BASE}/conversations`, { params });
1398
+ }
1399
+ async getConversation(uuid) {
1400
+ return await this.client.get(`${BASE}/conversations/${uuid}`);
1401
+ }
1402
+ async updateConversation(uuid, data) {
1403
+ return await this.client.put(`${BASE}/conversations/${uuid}`, data);
1404
+ }
1405
+ async deleteConversation(uuid) {
1406
+ return await this.client.delete(`${BASE}/conversations/${uuid}`);
1407
+ }
1408
+ async archiveConversation(uuid) {
1409
+ return await this.client.post(`${BASE}/conversations/${uuid}/archive`);
1410
+ }
1411
+ async unarchiveConversation(uuid) {
1412
+ return await this.client.post(`${BASE}/conversations/${uuid}/unarchive`);
1413
+ }
1414
+ async addParticipant(conversationUUID, data) {
1415
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/participants`, data);
1416
+ }
1417
+ async removeParticipant(conversationUUID, agentUUID) {
1418
+ return await this.client.delete(`${BASE}/conversations/${conversationUUID}/participants/${agentUUID}`);
1419
+ }
1420
+ // ── Messages / Completions ──
1421
+ async sendMessage(conversationUUID, data) {
1422
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages`, data);
1423
+ }
1424
+ async streamMessage(conversationUUID, data) {
1425
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages`, { ...data, stream: true }, {
1426
+ responseType: 'stream',
1427
+ timeout: 120000,
1428
+ });
1429
+ }
1430
+ async listMessages(conversationUUID, params) {
1431
+ return await this.client.get(`${BASE}/conversations/${conversationUUID}/messages`, { params });
1432
+ }
1433
+ async injectMessage(conversationUUID, data) {
1434
+ return await this.client.post(`${BASE}/conversations/${conversationUUID}/messages/inject`, data);
1435
+ }
1436
+ // ── OCR ──
1437
+ async ocr(data) {
1438
+ return await this.client.post(`${BASE}/ocr`, data, { timeout: 120000 });
1439
+ }
1440
+ // ── User Access ──
1441
+ async createUserAccess(data) {
1442
+ return await this.client.post(`${BASE}/user-access`, data);
1443
+ }
1444
+ async listUserAccess(params) {
1445
+ return await this.client.get(`${BASE}/user-access`, { params });
1446
+ }
1447
+ async getUserAccess(uuid) {
1448
+ return await this.client.get(`${BASE}/user-access/${uuid}`);
1449
+ }
1450
+ async updateUserAccess(uuid, data) {
1451
+ return await this.client.patch(`${BASE}/user-access/${uuid}`, data);
1452
+ }
1453
+ async deleteUserAccess(uuid) {
1454
+ return await this.client.delete(`${BASE}/user-access/${uuid}`);
1455
+ }
1456
+ async getUserMonthlyUsage(uuid, params) {
1457
+ return await this.client.get(`${BASE}/user-access/${uuid}/usage`, { params });
1458
+ }
1459
+ async getUserUsageBreakdown(uuid) {
1460
+ return await this.client.get(`${BASE}/user-access/${uuid}/usage/breakdown`);
1461
+ }
1462
+ async getMyAccess() {
1463
+ return await this.client.get(`${BASE}/my-access`);
1464
+ }
1465
+ // ── Usage (Admin) ──
1466
+ async listUsage(params) {
1467
+ return await this.client.get(`${BASE}/usage`, { params });
1468
+ }
1469
+ // ── Tier ──
1470
+ async getTier() {
1471
+ return await this.client.get(`${BASE}/tier`);
1472
+ }
1293
1473
  }
1294
1474
 
1295
1475
  class Project extends PlatformBaseClient {
@@ -1516,6 +1696,9 @@ class Platform extends PlatformBaseClient {
1516
1696
  forge() {
1517
1697
  return (new Forge()).setClient(this.client);
1518
1698
  }
1699
+ kortex() {
1700
+ return (new Kortex()).setClient(this.client);
1701
+ }
1519
1702
  component(ref) {
1520
1703
  return (new Component(ref)).setClient(this.client);
1521
1704
  }
@@ -1882,6 +2065,12 @@ class DMS extends IntegrationsBaseClient {
1882
2065
  async generateDocument(payload) {
1883
2066
  return this.requestv2('POST', 'documents/document/generate', { data: payload });
1884
2067
  }
2068
+ async listDocumentRevisions(path) {
2069
+ return this.requestv2('GET', `documents/revisions/${path}`);
2070
+ }
2071
+ async getDocumentRevision(path, version) {
2072
+ return this.requestv2('GET', `documents/revision/${path}`, { params: { version } });
2073
+ }
1885
2074
  async fillPdf(data) {
1886
2075
  const { input_path, output_path, output_pdf = false, output_type, output_file_name, replace, form_data, forms } = data;
1887
2076
  const responseType = output_pdf ? 'arraybuffer' : 'json';
@@ -3428,6 +3617,45 @@ class Ecommerce extends IntegrationsBaseClient {
3428
3617
  }
3429
3618
  }
3430
3619
 
3620
+ class Timber extends IntegrationsBaseClient {
3621
+ async query(params = {}) {
3622
+ const { data } = await this.client.get("/v1/timber/logs", {
3623
+ params: this.normalizeParams(params),
3624
+ });
3625
+ return data;
3626
+ }
3627
+ async write(payload) {
3628
+ const { data } = await this.client.post("/v1/timber/logs", payload);
3629
+ return data;
3630
+ }
3631
+ async usage() {
3632
+ const { data } = await this.client.get("/v1/timber/usage");
3633
+ return data;
3634
+ }
3635
+ async debug(message, payload) {
3636
+ return this.write({ ...payload, message, level: 'debug' });
3637
+ }
3638
+ async info(message, payload) {
3639
+ return this.write({ ...payload, message, level: 'info' });
3640
+ }
3641
+ async warn(message, payload) {
3642
+ return this.write({ ...payload, message, level: 'warn' });
3643
+ }
3644
+ async error(message, payload) {
3645
+ return this.write({ ...payload, message, level: 'error' });
3646
+ }
3647
+ normalizeParams(params) {
3648
+ const normalized = { ...params };
3649
+ if (params.from instanceof Date) {
3650
+ normalized.from = params.from.toISOString();
3651
+ }
3652
+ if (params.to instanceof Date) {
3653
+ normalized.to = params.to.toISOString();
3654
+ }
3655
+ return normalized;
3656
+ }
3657
+ }
3658
+
3431
3659
  class Integrations extends IntegrationsBaseClient {
3432
3660
  constructor(options) {
3433
3661
  super(options);
@@ -3439,6 +3667,7 @@ class Integrations extends IntegrationsBaseClient {
3439
3667
  'protokol-payments': new Payments().setClient(this.client),
3440
3668
  'protokol-minimax': new Minimax().setClient(this.client),
3441
3669
  'protokol-ecommerce': new Ecommerce().setClient(this.client),
3670
+ 'protokol-timber': new Timber().setClient(this.client),
3442
3671
  };
3443
3672
  }
3444
3673
  getDMS() {
@@ -3465,6 +3694,9 @@ class Integrations extends IntegrationsBaseClient {
3465
3694
  getEcommerce() {
3466
3695
  return this.getInterfaceOf('protokol-ecommerce');
3467
3696
  }
3697
+ getTimber() {
3698
+ return this.getInterfaceOf('protokol-timber');
3699
+ }
3468
3700
  async list() {
3469
3701
  const { data } = await this.client.get("/v1/integrations");
3470
3702
  return data;
@@ -3639,4 +3871,4 @@ class Invoicing extends PlatformBaseClient {
3639
3871
  }
3640
3872
  }
3641
3873
 
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 };
3874
+ 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[];