@mitralab.io/sdk-core 0.1.0 → 0.2.0-beta.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.
- package/CHANGELOG.md +51 -0
- package/README.md +203 -11
- package/contracts/README.md +40 -11
- package/contracts/manifest.json +10 -1
- package/contracts/v0.2.0-beta.0/mcp-alpha-tools.json +1409 -0
- package/contracts/v0.2.0-beta.0/mcp-tool-parity.json +818 -0
- package/contracts/v0.2.0-beta.0/sdk-parity.json +2563 -0
- package/dist/index.cjs +3467 -192
- package/dist/index.d.cts +1660 -12
- package/dist/index.d.ts +1660 -12
- package/dist/index.js +3439 -191
- package/package.json +7 -4
package/dist/index.cjs
CHANGED
|
@@ -20,19 +20,46 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
AgentTaskTurnError: () => AgentTaskTurnError,
|
|
23
24
|
SdkCoreConfigurationError: () => SdkCoreConfigurationError,
|
|
24
25
|
SdkCoreResponseError: () => SdkCoreResponseError,
|
|
26
|
+
createAgentConnectionsModule: () => createAgentConnectionsModule,
|
|
27
|
+
createAgentCredentialsModule: () => createAgentCredentialsModule,
|
|
28
|
+
createAgentTaskSessionManager: () => createAgentTaskSessionManager,
|
|
29
|
+
createAgentTasksModule: () => createAgentTasksModule,
|
|
30
|
+
createAgentsModule: () => createAgentsModule,
|
|
31
|
+
createAppsModule: () => createAppsModule,
|
|
25
32
|
createAuthModule: () => createAuthModule,
|
|
33
|
+
createContextModule: () => createContextModule,
|
|
34
|
+
createCustomQueriesModule: () => createCustomQueriesModule,
|
|
35
|
+
createDataSourcesModule: () => createDataSourcesModule,
|
|
26
36
|
createEntitiesModule: () => createEntitiesModule,
|
|
37
|
+
createFunctionsAdminModule: () => createFunctionsAdminModule,
|
|
27
38
|
createFunctionsModule: () => createFunctionsModule,
|
|
39
|
+
createImportsModule: () => createImportsModule,
|
|
40
|
+
createIntegrationAdminModule: () => createIntegrationAdminModule,
|
|
28
41
|
createIntegrationModule: () => createIntegrationModule,
|
|
42
|
+
createIntegrationResourcesModule: () => createIntegrationResourcesModule,
|
|
43
|
+
createIntegrationTemplatesModule: () => createIntegrationTemplatesModule,
|
|
44
|
+
createMembersModule: () => createMembersModule,
|
|
45
|
+
createMessengerModule: () => createMessengerModule,
|
|
46
|
+
createPublicFunctionsModule: () => createPublicFunctionsModule,
|
|
29
47
|
createQueriesModule: () => createQueriesModule,
|
|
48
|
+
createSchemaModule: () => createSchemaModule,
|
|
30
49
|
createSdkCore: () => createSdkCore,
|
|
50
|
+
createSqlModule: () => createSqlModule,
|
|
51
|
+
createWorkflowsModule: () => createWorkflowsModule,
|
|
31
52
|
defaultSdkCoreErrorFactory: () => defaultSdkCoreErrorFactory,
|
|
32
53
|
encodePathSegment: () => encodePathSegment,
|
|
33
54
|
expectEmpty: () => expectEmpty,
|
|
55
|
+
expectLegacyPage: () => expectLegacyPage,
|
|
56
|
+
expectNullableObject: () => expectNullableObject,
|
|
34
57
|
expectObject: () => expectObject,
|
|
35
|
-
expectObjectArray: () => expectObjectArray
|
|
58
|
+
expectObjectArray: () => expectObjectArray,
|
|
59
|
+
expectPage: () => expectPage,
|
|
60
|
+
expectStringArray: () => expectStringArray,
|
|
61
|
+
toAgentTimelineItem: () => toAgentTimelineItem,
|
|
62
|
+
withAgentTaskSessions: () => withAgentTaskSessions
|
|
36
63
|
});
|
|
37
64
|
module.exports = __toCommonJS(index_exports);
|
|
38
65
|
|
|
@@ -62,6 +89,23 @@ function invalidResponse(message, errors = defaultSdkCoreErrorFactory) {
|
|
|
62
89
|
throw errors.invalidResponse(message);
|
|
63
90
|
}
|
|
64
91
|
|
|
92
|
+
// src/batch.ts
|
|
93
|
+
function requireBatchSize(items, name, maxSize, errors = defaultSdkCoreErrorFactory) {
|
|
94
|
+
if (items.length < 1 || items.length > maxSize) {
|
|
95
|
+
configurationError(`${name} must contain between 1 and ${maxSize} items`, errors);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/path.ts
|
|
100
|
+
function encodePathSegment(value, name, errors = defaultSdkCoreErrorFactory) {
|
|
101
|
+
const segment = String(value);
|
|
102
|
+
if (!segment.trim()) configurationError(`${name} must not be empty`, errors);
|
|
103
|
+
if (segment === "." || segment === "..") {
|
|
104
|
+
configurationError(`${name} must not be a dot segment`, errors);
|
|
105
|
+
}
|
|
106
|
+
return encodeURIComponent(segment);
|
|
107
|
+
}
|
|
108
|
+
|
|
65
109
|
// src/response.ts
|
|
66
110
|
function isObject(value) {
|
|
67
111
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -69,6 +113,9 @@ function isObject(value) {
|
|
|
69
113
|
function isNullableString(value) {
|
|
70
114
|
return value === null || typeof value === "string";
|
|
71
115
|
}
|
|
116
|
+
function isNullableBoolean(value) {
|
|
117
|
+
return value === null || typeof value === "boolean";
|
|
118
|
+
}
|
|
72
119
|
function isInteger(value) {
|
|
73
120
|
return typeof value === "number" && Number.isInteger(value);
|
|
74
121
|
}
|
|
@@ -78,8 +125,23 @@ function isNullableInteger(value) {
|
|
|
78
125
|
function isStringRecord(value) {
|
|
79
126
|
return isObject(value) && Object.values(value).every((item) => typeof item === "string");
|
|
80
127
|
}
|
|
128
|
+
function isStringArray(value) {
|
|
129
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
130
|
+
}
|
|
131
|
+
function isJsonValue(value) {
|
|
132
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
133
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
134
|
+
if (Array.isArray(value)) return value.every(isJsonValue);
|
|
135
|
+
return isObject(value) && Object.values(value).every(isJsonValue);
|
|
136
|
+
}
|
|
137
|
+
function isJsonRecord(value) {
|
|
138
|
+
return isObject(value) && Object.values(value).every(isJsonValue);
|
|
139
|
+
}
|
|
140
|
+
function isOneOf(value, allowed) {
|
|
141
|
+
return typeof value === "string" && allowed.includes(value);
|
|
142
|
+
}
|
|
81
143
|
function hasOwn(value, property) {
|
|
82
|
-
return Object.
|
|
144
|
+
return Object.hasOwn(value, property);
|
|
83
145
|
}
|
|
84
146
|
function invalidField(context, field, errors) {
|
|
85
147
|
return invalidResponse(`${context} has an invalid ${field} field`, errors);
|
|
@@ -90,21 +152,67 @@ function expectObject(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
|
90
152
|
}
|
|
91
153
|
return value;
|
|
92
154
|
}
|
|
93
|
-
function expectObjectArray(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
155
|
+
function expectObjectArray(value, context, errors = defaultSdkCoreErrorFactory, validateItem) {
|
|
94
156
|
if (!Array.isArray(value) || value.some((item) => !isObject(item))) {
|
|
95
157
|
return invalidResponse(`${context} must be a JSON array of objects`, errors);
|
|
96
158
|
}
|
|
159
|
+
if (validateItem) {
|
|
160
|
+
value.forEach((item, position) => validateItem(item, `${context} item ${position}`, errors));
|
|
161
|
+
}
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
function expectNullableObject(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
165
|
+
return value === null ? null : expectObject(value, context, errors);
|
|
166
|
+
}
|
|
167
|
+
function expectStringArray(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
168
|
+
if (!isStringArray(value)) {
|
|
169
|
+
return invalidResponse(`${context} must be a JSON array of strings`, errors);
|
|
170
|
+
}
|
|
97
171
|
return value;
|
|
98
172
|
}
|
|
173
|
+
function expectPage(value, context, errors = defaultSdkCoreErrorFactory, validateItem) {
|
|
174
|
+
const page = expectObject(value, context, errors);
|
|
175
|
+
if (!Array.isArray(page.content) || page.content.some((item) => !isObject(item))) {
|
|
176
|
+
invalidField(context, "content", errors);
|
|
177
|
+
}
|
|
178
|
+
const metadata = expectObject(page.page, `${context} page`, errors);
|
|
179
|
+
for (const field of ["size", "totalElements", "totalPages", "number"]) {
|
|
180
|
+
if (!isInteger(metadata[field])) invalidField(`${context} page`, field, errors);
|
|
181
|
+
}
|
|
182
|
+
if (metadata.totalElements < page.content.length) {
|
|
183
|
+
invalidField(`${context} page`, "totalElements", errors);
|
|
184
|
+
}
|
|
185
|
+
if (validateItem) {
|
|
186
|
+
page.content.forEach(
|
|
187
|
+
(item, position) => validateItem(item, `${context} item ${position}`, errors)
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
return page;
|
|
191
|
+
}
|
|
192
|
+
function expectLegacyPage(value, context, errors = defaultSdkCoreErrorFactory, validateItem) {
|
|
193
|
+
const page = expectObject(value, context, errors);
|
|
194
|
+
if (!Array.isArray(page.content) || page.content.some((item) => !isObject(item))) {
|
|
195
|
+
invalidField(context, "content", errors);
|
|
196
|
+
}
|
|
197
|
+
if (!isInteger(page.totalElements) || page.totalElements < page.content.length) {
|
|
198
|
+
invalidField(context, "totalElements", errors);
|
|
199
|
+
}
|
|
200
|
+
if (validateItem) {
|
|
201
|
+
page.content.forEach(
|
|
202
|
+
(item, position) => validateItem(item, `${context} item ${position}`, errors)
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
return page;
|
|
206
|
+
}
|
|
99
207
|
function expectTenant(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
100
208
|
const tenant = expectObject(value, context, errors);
|
|
101
209
|
if (typeof tenant.id !== "string") invalidField(context, "id", errors);
|
|
102
210
|
if (typeof tenant.shortId !== "string") invalidField(context, "shortId", errors);
|
|
103
211
|
if (!isNullableInteger(tenant.legacyId)) invalidField(context, "legacyId", errors);
|
|
104
212
|
if (typeof tenant.slug !== "string") invalidField(context, "slug", errors);
|
|
105
|
-
if (!
|
|
106
|
-
|
|
107
|
-
|
|
213
|
+
if (!isOneOf(tenant.clusterType, ["SHARED", "DEDICATED"])) {
|
|
214
|
+
invalidField(context, "clusterType", errors);
|
|
215
|
+
}
|
|
108
216
|
if (typeof tenant.name !== "string") invalidField(context, "name", errors);
|
|
109
217
|
if (!isNullableString(tenant.description)) invalidField(context, "description", errors);
|
|
110
218
|
if (!isNullableString(tenant.hexColor)) invalidField(context, "hexColor", errors);
|
|
@@ -120,11 +228,29 @@ function expectUser(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
|
120
228
|
if (typeof user.name !== "string") invalidField(context, "name", errors);
|
|
121
229
|
if (typeof user.email !== "string") invalidField(context, "email", errors);
|
|
122
230
|
if (!isNullableString(user.imageUrl)) invalidField(context, "imageUrl", errors);
|
|
231
|
+
if (typeof user.planId !== "string") invalidField(context, "planId", errors);
|
|
123
232
|
if (typeof user.onboardingCompleted !== "boolean") {
|
|
124
233
|
invalidField(context, "onboardingCompleted", errors);
|
|
125
234
|
}
|
|
235
|
+
if (typeof user.language !== "string") invalidField(context, "language", errors);
|
|
126
236
|
return user;
|
|
127
237
|
}
|
|
238
|
+
function expectUserPlan(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
239
|
+
const plan = expectObject(value, context, errors);
|
|
240
|
+
if (typeof plan.id !== "string") invalidField(context, "id", errors);
|
|
241
|
+
if (typeof plan.code !== "string") invalidField(context, "code", errors);
|
|
242
|
+
if (typeof plan.name !== "string") invalidField(context, "name", errors);
|
|
243
|
+
if (!isInteger(plan.maxUsers)) invalidField(context, "maxUsers", errors);
|
|
244
|
+
expectObjectArray(plan.prices, `${context} prices`, errors).forEach(
|
|
245
|
+
(price, position) => {
|
|
246
|
+
const priceContext = `${context} price ${position}`;
|
|
247
|
+
if (typeof price.currency !== "string") invalidField(priceContext, "currency", errors);
|
|
248
|
+
if (!isInteger(price.amountMinorUnits)) invalidField(priceContext, "amountMinorUnits", errors);
|
|
249
|
+
if (typeof price.interval !== "string") invalidField(priceContext, "interval", errors);
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
return plan;
|
|
253
|
+
}
|
|
128
254
|
function expectQueryResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
129
255
|
const result = expectObject(value, context, errors);
|
|
130
256
|
if (!Array.isArray(result.rows) || result.rows.some((row) => !isObject(row))) {
|
|
@@ -159,7 +285,7 @@ function expectFunctionExecution(value, context, errors = defaultSdkCoreErrorFac
|
|
|
159
285
|
if (!isNullableInteger(execution.durationMs)) invalidField(context, "durationMs", errors);
|
|
160
286
|
if (!isNullableString(execution.startedAt)) invalidField(context, "startedAt", errors);
|
|
161
287
|
if (!isNullableString(execution.finishedAt)) invalidField(context, "finishedAt", errors);
|
|
162
|
-
if (
|
|
288
|
+
if (!isNullableString(execution.createdAt)) invalidField(context, "createdAt", errors);
|
|
163
289
|
return execution;
|
|
164
290
|
}
|
|
165
291
|
function expectProxyResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
@@ -175,194 +301,2062 @@ function expectProxyResult(value, context, errors = defaultSdkCoreErrorFactory)
|
|
|
175
301
|
if (typeof result.executionId !== "string") invalidField(context, "executionId", errors);
|
|
176
302
|
return result;
|
|
177
303
|
}
|
|
178
|
-
function
|
|
179
|
-
|
|
304
|
+
function expectBatchExecution(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
305
|
+
const execution = expectObject(value, context, errors);
|
|
306
|
+
expectObjectArray(execution.results, `${context} results`, errors).forEach(
|
|
307
|
+
(item, position) => {
|
|
308
|
+
const itemContext = `${context} result ${position}`;
|
|
309
|
+
if (!isInteger(item.index)) invalidField(itemContext, "index", errors);
|
|
310
|
+
if (hasOwn(item, "affectedRows") && !isInteger(item.affectedRows)) {
|
|
311
|
+
invalidField(itemContext, "affectedRows", errors);
|
|
312
|
+
}
|
|
313
|
+
if (!isInteger(item.durationMs)) invalidField(itemContext, "durationMs", errors);
|
|
314
|
+
}
|
|
315
|
+
);
|
|
316
|
+
if (!isInteger(execution.executedCount)) invalidField(context, "executedCount", errors);
|
|
317
|
+
if (!isInteger(execution.totalDurationMs)) invalidField(context, "totalDurationMs", errors);
|
|
318
|
+
return execution;
|
|
180
319
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
errors
|
|
190
|
-
|
|
320
|
+
function expectSchemaTables(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
321
|
+
const groups = expectObjectArray(value, context, errors);
|
|
322
|
+
groups.forEach((group, position) => {
|
|
323
|
+
const groupContext = `${context} group ${position}`;
|
|
324
|
+
if (typeof group.schema !== "string") invalidField(groupContext, "schema", errors);
|
|
325
|
+
expectObjectArray(group.tables, `${groupContext} tables`, errors).forEach(
|
|
326
|
+
(table, tablePosition) => {
|
|
327
|
+
const tableContext = `${groupContext} table ${tablePosition}`;
|
|
328
|
+
if (typeof table.tableName !== "string") invalidField(tableContext, "tableName", errors);
|
|
329
|
+
expectObjectArray(table.columns, `${tableContext} columns`, errors).forEach(
|
|
330
|
+
(column, columnPosition) => {
|
|
331
|
+
const columnContext = `${tableContext} column ${columnPosition}`;
|
|
332
|
+
if (typeof column.name !== "string") invalidField(columnContext, "name", errors);
|
|
333
|
+
if (typeof column.type !== "string") invalidField(columnContext, "type", errors);
|
|
334
|
+
if (typeof column.primaryKey !== "boolean") {
|
|
335
|
+
invalidField(columnContext, "primaryKey", errors);
|
|
336
|
+
}
|
|
337
|
+
if (typeof column.nullable !== "boolean") {
|
|
338
|
+
invalidField(columnContext, "nullable", errors);
|
|
339
|
+
}
|
|
340
|
+
if (!isNullableString(column.defaultValue)) {
|
|
341
|
+
invalidField(columnContext, "defaultValue", errors);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
expectObjectArray(
|
|
346
|
+
table.foreignKeys,
|
|
347
|
+
`${tableContext} foreignKeys`,
|
|
348
|
+
errors
|
|
349
|
+
).forEach((foreignKey, foreignKeyPosition) => {
|
|
350
|
+
const foreignKeyContext = `${tableContext} foreign key ${foreignKeyPosition}`;
|
|
351
|
+
if (!isStringArray(foreignKey.columns)) {
|
|
352
|
+
invalidField(foreignKeyContext, "columns", errors);
|
|
353
|
+
}
|
|
354
|
+
if (typeof foreignKey.referencedTable !== "string") {
|
|
355
|
+
invalidField(foreignKeyContext, "referencedTable", errors);
|
|
356
|
+
}
|
|
357
|
+
if (!isStringArray(foreignKey.referencedColumns)) {
|
|
358
|
+
invalidField(foreignKeyContext, "referencedColumns", errors);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
);
|
|
363
|
+
});
|
|
364
|
+
return groups;
|
|
365
|
+
}
|
|
366
|
+
function expectBulkResult(value, context, idField, errors) {
|
|
367
|
+
const result = expectObject(value, context, errors);
|
|
368
|
+
expectObjectArray(result.results, `${context} results`, errors).forEach(
|
|
369
|
+
(item, position) => {
|
|
370
|
+
const itemContext = `${context} result ${position}`;
|
|
371
|
+
if (!isInteger(item.index)) invalidField(itemContext, "index", errors);
|
|
372
|
+
if (typeof item.success !== "boolean") invalidField(itemContext, "success", errors);
|
|
373
|
+
if (hasOwn(item, idField) && !isNullableString(item[idField])) {
|
|
374
|
+
invalidField(itemContext, idField, errors);
|
|
375
|
+
}
|
|
376
|
+
if (hasOwn(item, "errorCode") && !isNullableString(item.errorCode)) {
|
|
377
|
+
invalidField(itemContext, "errorCode", errors);
|
|
378
|
+
}
|
|
379
|
+
if (hasOwn(item, "message") && !isNullableString(item.message)) {
|
|
380
|
+
invalidField(itemContext, "message", errors);
|
|
381
|
+
}
|
|
191
382
|
}
|
|
192
|
-
|
|
383
|
+
);
|
|
384
|
+
if (!isInteger(result.processedCount)) invalidField(context, "processedCount", errors);
|
|
385
|
+
if (!isInteger(result.succeededCount)) invalidField(context, "succeededCount", errors);
|
|
386
|
+
if (!isInteger(result.failedCount)) invalidField(context, "failedCount", errors);
|
|
387
|
+
return result;
|
|
193
388
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
|
|
389
|
+
function expectTemplateConfigBulkResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
390
|
+
return expectBulkResult(value, context, "configId", errors);
|
|
391
|
+
}
|
|
392
|
+
function expectFunctionVersion(value, context, errors) {
|
|
393
|
+
const version = expectObject(value, context, errors);
|
|
394
|
+
if (typeof version.id !== "string") invalidField(context, "id", errors);
|
|
395
|
+
if (typeof version.functionId !== "string") invalidField(context, "functionId", errors);
|
|
396
|
+
if (typeof version.status !== "string") invalidField(context, "status", errors);
|
|
397
|
+
if (typeof version.code !== "string") invalidField(context, "code", errors);
|
|
398
|
+
if (version.inputSchema !== null && !isObject(version.inputSchema)) {
|
|
399
|
+
invalidField(context, "inputSchema", errors);
|
|
201
400
|
}
|
|
202
|
-
|
|
401
|
+
if (version.outputSchema !== null && !isObject(version.outputSchema)) {
|
|
402
|
+
invalidField(context, "outputSchema", errors);
|
|
403
|
+
}
|
|
404
|
+
if (version.secrets !== null && !isStringArray(version.secrets)) {
|
|
405
|
+
invalidField(context, "secrets", errors);
|
|
406
|
+
}
|
|
407
|
+
if (typeof version.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
203
408
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
409
|
+
function expectFunctionDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
410
|
+
const definition = expectObject(value, context, errors);
|
|
411
|
+
if (typeof definition.id !== "string") invalidField(context, "id", errors);
|
|
412
|
+
if (typeof definition.tenantId !== "string") invalidField(context, "tenantId", errors);
|
|
413
|
+
if (!isNullableString(definition.appId)) invalidField(context, "appId", errors);
|
|
414
|
+
if (!isNullableInteger(definition.legacyId)) invalidField(context, "legacyId", errors);
|
|
415
|
+
if (typeof definition.name !== "string") invalidField(context, "name", errors);
|
|
416
|
+
if (!isNullableString(definition.description)) invalidField(context, "description", errors);
|
|
417
|
+
if (typeof definition.runtime !== "string") invalidField(context, "runtime", errors);
|
|
418
|
+
if (!isNullableString(definition.dataSourceId)) invalidField(context, "dataSourceId", errors);
|
|
419
|
+
if (typeof definition.visibility !== "string") invalidField(context, "visibility", errors);
|
|
420
|
+
if (definition.currentVersion !== null) {
|
|
421
|
+
expectFunctionVersion(definition.currentVersion, `${context} current version`, errors);
|
|
210
422
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
423
|
+
if (!isNullableString(definition.cronExpression)) {
|
|
424
|
+
invalidField(context, "cronExpression", errors);
|
|
425
|
+
}
|
|
426
|
+
if (definition.cronInputJson !== null && !isJsonRecord(definition.cronInputJson)) {
|
|
427
|
+
invalidField(context, "cronInputJson", errors);
|
|
428
|
+
}
|
|
429
|
+
if (!isNullableBoolean(definition.cronEnabled)) invalidField(context, "cronEnabled", errors);
|
|
430
|
+
if (!isNullableString(definition.createdAt)) invalidField(context, "createdAt", errors);
|
|
431
|
+
if (typeof definition.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
432
|
+
return definition;
|
|
433
|
+
}
|
|
434
|
+
function expectFunctionDefinitions(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
435
|
+
return expectObjectArray(value, context, errors).map(
|
|
436
|
+
(item, position) => expectFunctionDefinition(item, `${context} item ${position}`, errors)
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
function expectFunctionBulkDeleteResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
440
|
+
const result = expectObject(value, context, errors);
|
|
441
|
+
if (!isStringArray(result.deleted)) invalidField(context, "deleted", errors);
|
|
442
|
+
if (!isStringArray(result.notFound)) invalidField(context, "notFound", errors);
|
|
443
|
+
if (!isInteger(result.deletedCount)) invalidField(context, "deletedCount", errors);
|
|
444
|
+
return result;
|
|
445
|
+
}
|
|
446
|
+
function expectTemplateConfigPage(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
447
|
+
return expectLegacyPage(value, context, errors, expectTemplateConfigSummary);
|
|
448
|
+
}
|
|
449
|
+
function expectConnectionTestResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
450
|
+
const result = expectObject(value, context, errors);
|
|
451
|
+
if (!isOneOf(result.status, ["unchecked", "connected", "error"])) {
|
|
452
|
+
invalidField(context, "status", errors);
|
|
453
|
+
}
|
|
454
|
+
if (!isInteger(result.durationMs)) invalidField(context, "durationMs", errors);
|
|
455
|
+
if (typeof result.checkedAt !== "string") invalidField(context, "checkedAt", errors);
|
|
456
|
+
if (!isNullableString(result.message)) invalidField(context, "message", errors);
|
|
457
|
+
return result;
|
|
458
|
+
}
|
|
459
|
+
function expectAppMembers(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
460
|
+
const members = expectObjectArray(value, context, errors);
|
|
461
|
+
members.forEach((member, position) => {
|
|
462
|
+
const memberContext = `${context} member ${position}`;
|
|
463
|
+
if (typeof member.userId !== "string") invalidField(memberContext, "userId", errors);
|
|
464
|
+
if (typeof member.name !== "string") invalidField(memberContext, "name", errors);
|
|
465
|
+
if (typeof member.email !== "string") invalidField(memberContext, "email", errors);
|
|
466
|
+
if (typeof member.accessLevel !== "string") invalidField(memberContext, "accessLevel", errors);
|
|
467
|
+
if (typeof member.accessSource !== "string") {
|
|
468
|
+
invalidField(memberContext, "accessSource", errors);
|
|
215
469
|
}
|
|
216
|
-
|
|
470
|
+
});
|
|
471
|
+
return members;
|
|
472
|
+
}
|
|
473
|
+
function expectBulkUnsubscribeResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
474
|
+
const result = expectObject(value, context, errors);
|
|
475
|
+
if (!isStringArray(result.revoked)) invalidField(context, "revoked", errors);
|
|
476
|
+
if (!isStringArray(result.notFound)) invalidField(context, "notFound", errors);
|
|
477
|
+
if (!isInteger(result.revokedCount)) invalidField(context, "revokedCount", errors);
|
|
478
|
+
return result;
|
|
479
|
+
}
|
|
480
|
+
function expectAppDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
481
|
+
const app = expectObject(value, context, errors);
|
|
482
|
+
expectAppFields(app, context, errors);
|
|
483
|
+
if (!isNullableString(app.dataSourceId)) invalidField(context, "dataSourceId", errors);
|
|
484
|
+
return app;
|
|
485
|
+
}
|
|
486
|
+
function expectAppSummary(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
487
|
+
const app = expectObject(value, context, errors);
|
|
488
|
+
expectAppFields(app, context, errors);
|
|
489
|
+
if (typeof app.tenantId !== "string") invalidField(context, "tenantId", errors);
|
|
490
|
+
return app;
|
|
491
|
+
}
|
|
492
|
+
function expectAppFields(app, context, errors) {
|
|
493
|
+
for (const field of ["id", "shortId", "subdomain", "brand", "name", "planId"]) {
|
|
494
|
+
if (typeof app[field] !== "string") invalidField(context, field, errors);
|
|
217
495
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
limit: options?.limit ?? limit,
|
|
226
|
-
skip: options?.skip ?? skip,
|
|
227
|
-
fields: (options?.fields ?? fields)?.join(",")
|
|
228
|
-
};
|
|
229
|
-
const response = expectObject(
|
|
230
|
-
await this.transport.request(basePath, { method: "GET", params }),
|
|
231
|
-
"Entity list response",
|
|
232
|
-
this.errors
|
|
233
|
-
);
|
|
234
|
-
return expectObjectArray(response.data, "Entity list data", this.errors);
|
|
235
|
-
},
|
|
236
|
-
filter: async (query, sort, limit, skip, fields) => {
|
|
237
|
-
const response = expectObject(
|
|
238
|
-
await this.transport.request(basePath, {
|
|
239
|
-
method: "GET",
|
|
240
|
-
params: {
|
|
241
|
-
q: JSON.stringify(query),
|
|
242
|
-
sort,
|
|
243
|
-
limit,
|
|
244
|
-
skip,
|
|
245
|
-
fields: fields?.join(",")
|
|
246
|
-
}
|
|
247
|
-
}),
|
|
248
|
-
"Entity list response",
|
|
249
|
-
this.errors
|
|
250
|
-
);
|
|
251
|
-
return expectObjectArray(response.data, "Entity list data", this.errors);
|
|
252
|
-
},
|
|
253
|
-
get: async (id) => expectObject(
|
|
254
|
-
await this.transport.request(
|
|
255
|
-
`${basePath}/${encodePathSegment(id, "id", this.errors)}`,
|
|
256
|
-
{ method: "GET" }
|
|
257
|
-
),
|
|
258
|
-
"Entity response",
|
|
259
|
-
this.errors
|
|
260
|
-
),
|
|
261
|
-
create: async (data) => expectObject(
|
|
262
|
-
await this.transport.request(basePath, { method: "POST", body: data }),
|
|
263
|
-
"Created entity response",
|
|
264
|
-
this.errors
|
|
265
|
-
),
|
|
266
|
-
bulkCreate: async (data) => expectObjectArray(
|
|
267
|
-
await this.transport.request(`${basePath}/bulk`, {
|
|
268
|
-
method: "POST",
|
|
269
|
-
body: data
|
|
270
|
-
}),
|
|
271
|
-
"Bulk create response",
|
|
272
|
-
this.errors
|
|
273
|
-
),
|
|
274
|
-
update: async (id, data) => expectObject(
|
|
275
|
-
await this.transport.request(
|
|
276
|
-
`${basePath}/${encodePathSegment(id, "id", this.errors)}`,
|
|
277
|
-
{ method: "PUT", body: data }
|
|
278
|
-
),
|
|
279
|
-
"Updated entity response",
|
|
280
|
-
this.errors
|
|
281
|
-
),
|
|
282
|
-
delete: (id) => this.transport.request(`${basePath}/${encodePathSegment(id, "id", this.errors)}`, {
|
|
283
|
-
method: "DELETE"
|
|
284
|
-
}).then((response) => expectEmpty(response, "Delete entity response", this.errors)),
|
|
285
|
-
deleteMany: async (query) => {
|
|
286
|
-
if (Object.keys(query).length === 0) {
|
|
287
|
-
configurationError("query must not be empty for deleteMany", this.errors);
|
|
288
|
-
}
|
|
289
|
-
const response = expectObject(
|
|
290
|
-
await this.transport.request(basePath, {
|
|
291
|
-
method: "DELETE",
|
|
292
|
-
params: { q: JSON.stringify(query) }
|
|
293
|
-
}),
|
|
294
|
-
"Delete many response",
|
|
295
|
-
this.errors
|
|
296
|
-
);
|
|
297
|
-
if (!Number.isInteger(response.deleted)) {
|
|
298
|
-
return invalidResponse(
|
|
299
|
-
"Delete many response must include an integer deleted count",
|
|
300
|
-
this.errors
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
return { deleted: response.deleted };
|
|
304
|
-
}
|
|
305
|
-
};
|
|
496
|
+
if (!isNullableInteger(app.legacyId)) invalidField(context, "legacyId", errors);
|
|
497
|
+
if (!isNullableString(app.description)) invalidField(context, "description", errors);
|
|
498
|
+
if (!isNullableString(app.icon)) invalidField(context, "icon", errors);
|
|
499
|
+
if (!isNullableString(app.template)) invalidField(context, "template", errors);
|
|
500
|
+
if (typeof app.allowSignup !== "boolean") invalidField(context, "allowSignup", errors);
|
|
501
|
+
if (typeof app.externalAccessEnabled !== "boolean") {
|
|
502
|
+
invalidField(context, "externalAccessEnabled", errors);
|
|
306
503
|
}
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (
|
|
313
|
-
|
|
504
|
+
expectAppColor(app.color, `${context} color`, errors);
|
|
505
|
+
expectObjectArray(app.domains, `${context} domains`, errors).forEach(
|
|
506
|
+
(domain, position) => {
|
|
507
|
+
const domainContext = `${context} domain ${position}`;
|
|
508
|
+
if (typeof domain.hostname !== "string") invalidField(domainContext, "hostname", errors);
|
|
509
|
+
if (!isOneOf(domain.kind, ["PLATFORM", "CUSTOM"])) {
|
|
510
|
+
invalidField(domainContext, "kind", errors);
|
|
511
|
+
}
|
|
512
|
+
if (!isOneOf(domain.status, ["ACTIVE", "PENDING", "INACTIVE"])) {
|
|
513
|
+
invalidField(domainContext, "status", errors);
|
|
314
514
|
}
|
|
315
|
-
return target.getTable(property);
|
|
316
515
|
}
|
|
317
|
-
|
|
516
|
+
);
|
|
517
|
+
if (app.currentVersion !== null) {
|
|
518
|
+
expectAppVersion(app.currentVersion, `${context} currentVersion`, errors);
|
|
519
|
+
}
|
|
520
|
+
if (typeof app.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
521
|
+
if (typeof app.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
318
522
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
this.errors = errors;
|
|
325
|
-
this.options = options;
|
|
523
|
+
function expectAppColor(value, context, errors) {
|
|
524
|
+
const color = expectObject(value, context, errors);
|
|
525
|
+
if (color.type === "SOLID") {
|
|
526
|
+
if (typeof color.hex !== "string") invalidField(context, "hex", errors);
|
|
527
|
+
return;
|
|
326
528
|
}
|
|
327
|
-
|
|
328
|
-
|
|
529
|
+
if (color.type === "GRADIENT") {
|
|
530
|
+
if (typeof color.startHex !== "string") invalidField(context, "startHex", errors);
|
|
531
|
+
if (typeof color.endHex !== "string") invalidField(context, "endHex", errors);
|
|
532
|
+
return;
|
|
329
533
|
}
|
|
330
|
-
|
|
331
|
-
|
|
534
|
+
invalidField(context, "type", errors);
|
|
535
|
+
}
|
|
536
|
+
function expectAppDeploy(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
537
|
+
const deploy = expectObject(value, context, errors);
|
|
538
|
+
if (typeof deploy.id !== "string") invalidField(context, "id", errors);
|
|
539
|
+
if (typeof deploy.appId !== "string") invalidField(context, "appId", errors);
|
|
540
|
+
if (typeof deploy.appVersionId !== "string") invalidField(context, "appVersionId", errors);
|
|
541
|
+
if (!isOneOf(deploy.status, ["PENDING", "BUILDING", "DEPLOYED", "FAILED", "CANCELLED"])) {
|
|
542
|
+
invalidField(context, "status", errors);
|
|
332
543
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
`/api/v1/executions/${encodePathSegment(id, "execution id", this.errors)}`,
|
|
336
|
-
{ method: "GET" }
|
|
337
|
-
).then(
|
|
338
|
-
(response) => expectFunctionExecution(response, "Function execution response", this.errors)
|
|
339
|
-
);
|
|
544
|
+
for (const field of ["deployUrl", "errorMessage", "logs", "startedAt", "finishedAt"]) {
|
|
545
|
+
if (!isNullableString(deploy[field])) invalidField(context, field, errors);
|
|
340
546
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
547
|
+
if (!isNullableInteger(deploy.durationMs)) invalidField(context, "durationMs", errors);
|
|
548
|
+
if (typeof deploy.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
549
|
+
return deploy;
|
|
550
|
+
}
|
|
551
|
+
function expectAppVersion(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
552
|
+
const version = expectObject(value, context, errors);
|
|
553
|
+
if (typeof version.id !== "string") invalidField(context, "id", errors);
|
|
554
|
+
if (typeof version.appId !== "string") invalidField(context, "appId", errors);
|
|
555
|
+
if (!isOneOf(version.status, ["DRAFT", "PUBLISHED"])) {
|
|
556
|
+
invalidField(context, "status", errors);
|
|
346
557
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
method: "POST",
|
|
350
|
-
...input !== void 0 || this.options.emptyInput !== "omit-body" ? { body: { input: input ?? {} } } : {},
|
|
351
|
-
...invocationType === void 0 ? {} : { headers: { "X-Invocation-Type": invocationType } }
|
|
352
|
-
};
|
|
353
|
-
return this.transport.request(
|
|
354
|
-
`/api/v1/functions/${encodePathSegment(id, "function id", this.errors)}/execute`,
|
|
355
|
-
request
|
|
356
|
-
).then(
|
|
357
|
-
(response) => expectFunctionExecution(response, "Function execution response", this.errors)
|
|
358
|
-
);
|
|
558
|
+
if (version.currentDeploy !== null) {
|
|
559
|
+
expectAppDeploy(version.currentDeploy, `${context} currentDeploy`, errors);
|
|
359
560
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return new DefaultFunctionsModule(transport, errors, options);
|
|
561
|
+
if (typeof version.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
562
|
+
return version;
|
|
363
563
|
}
|
|
364
|
-
|
|
365
|
-
|
|
564
|
+
function expectCustomQueryDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
565
|
+
const query = expectCustomQuerySummary(value, context, errors);
|
|
566
|
+
if (typeof query.sql !== "string") invalidField(context, "sql", errors);
|
|
567
|
+
return query;
|
|
568
|
+
}
|
|
569
|
+
function expectCustomQuerySummary(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
570
|
+
const query = expectObject(value, context, errors);
|
|
571
|
+
if (typeof query.id !== "string") invalidField(context, "id", errors);
|
|
572
|
+
if (typeof query.name !== "string") invalidField(context, "name", errors);
|
|
573
|
+
if (typeof query.isVirtualTable !== "boolean") invalidField(context, "isVirtualTable", errors);
|
|
574
|
+
if (!isNullableString(query.connectionId)) invalidField(context, "connectionId", errors);
|
|
575
|
+
if (!isNullableString(query.createdAt)) invalidField(context, "createdAt", errors);
|
|
576
|
+
if (typeof query.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
577
|
+
return query;
|
|
578
|
+
}
|
|
579
|
+
function expectConnectionConfig(value, context, errors) {
|
|
580
|
+
const config = expectObject(value, context, errors);
|
|
581
|
+
for (const field of ["host", "schema", "databaseName", "username"]) {
|
|
582
|
+
if (!isNullableString(config[field])) invalidField(context, field, errors);
|
|
583
|
+
}
|
|
584
|
+
if (!isNullableInteger(config.port)) invalidField(context, "port", errors);
|
|
585
|
+
for (const field of [
|
|
586
|
+
"maxPoolSize",
|
|
587
|
+
"connectionTimeoutMs",
|
|
588
|
+
"idleTimeoutMs",
|
|
589
|
+
"minimumIdle",
|
|
590
|
+
"maxLifetimeMs"
|
|
591
|
+
]) {
|
|
592
|
+
if (!isNullableInteger(config[field])) invalidField(context, field, errors);
|
|
593
|
+
}
|
|
594
|
+
if (config.additionalParams !== null && !isStringRecord(config.additionalParams)) {
|
|
595
|
+
invalidField(context, "additionalParams", errors);
|
|
596
|
+
}
|
|
597
|
+
if (config.credential !== null) invalidField(context, "credential", errors);
|
|
598
|
+
}
|
|
599
|
+
function expectDataSourceDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
600
|
+
const dataSource = expectObject(value, context, errors);
|
|
601
|
+
if (typeof dataSource.id !== "string") invalidField(context, "id", errors);
|
|
602
|
+
if (!isNullableInteger(dataSource.legacyId)) invalidField(context, "legacyId", errors);
|
|
603
|
+
if (!isNullableString(dataSource.appId)) invalidField(context, "appId", errors);
|
|
604
|
+
if (typeof dataSource.name !== "string") invalidField(context, "name", errors);
|
|
605
|
+
if (!isOneOf(dataSource.instanceType, ["MITRA_SHARED", "MITRA_DEDICATED", "EXTERNAL"])) {
|
|
606
|
+
invalidField(context, "instanceType", errors);
|
|
607
|
+
}
|
|
608
|
+
if (!isOneOf(dataSource.dbType, ["POSTGRES", "MYSQL", "SQLSERVER", "ORACLE"])) {
|
|
609
|
+
invalidField(context, "dbType", errors);
|
|
610
|
+
}
|
|
611
|
+
expectConnectionConfig(
|
|
612
|
+
dataSource.writeConnectionConfig,
|
|
613
|
+
`${context} writeConnectionConfig`,
|
|
614
|
+
errors
|
|
615
|
+
);
|
|
616
|
+
if (dataSource.readConnectionConfig !== null) {
|
|
617
|
+
expectConnectionConfig(
|
|
618
|
+
dataSource.readConnectionConfig,
|
|
619
|
+
`${context} readConnectionConfig`,
|
|
620
|
+
errors
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
if (dataSource.connectionStatus !== null && !isOneOf(dataSource.connectionStatus, ["CONNECTED", "ERROR"])) {
|
|
624
|
+
invalidField(context, "connectionStatus", errors);
|
|
625
|
+
}
|
|
626
|
+
if (!isNullableString(dataSource.lastCheckedAt)) invalidField(context, "lastCheckedAt", errors);
|
|
627
|
+
if (dataSource.storageQuota !== null) {
|
|
628
|
+
const quota = expectObject(
|
|
629
|
+
dataSource.storageQuota,
|
|
630
|
+
`${context} storageQuota`,
|
|
631
|
+
errors
|
|
632
|
+
);
|
|
633
|
+
if (quota.status !== null && !isOneOf(quota.status, ["NORMAL", "WATCH", "BLOCKED"])) {
|
|
634
|
+
invalidField(`${context} storageQuota`, "status", errors);
|
|
635
|
+
}
|
|
636
|
+
for (const field of ["usedBytes", "limitBytes", "measurementVersion"]) {
|
|
637
|
+
if (!isNullableInteger(quota[field])) invalidField(`${context} storageQuota`, field, errors);
|
|
638
|
+
}
|
|
639
|
+
if (!isNullableString(quota.measuredAt)) {
|
|
640
|
+
invalidField(`${context} storageQuota`, "measuredAt", errors);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return dataSource;
|
|
644
|
+
}
|
|
645
|
+
function expectImportSource(value, context, errors) {
|
|
646
|
+
const source = expectObject(value, context, errors);
|
|
647
|
+
if (source.type === "SQL") {
|
|
648
|
+
if (typeof source.query !== "string") invalidField(context, "query", errors);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (source.type === "CSV") {
|
|
652
|
+
if (typeof source.fileKey !== "string") invalidField(context, "fileKey", errors);
|
|
653
|
+
if (typeof source.separator !== "string") invalidField(context, "separator", errors);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
invalidField(context, "type", errors);
|
|
657
|
+
}
|
|
658
|
+
function expectImportDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
659
|
+
const definition = expectObject(value, context, errors);
|
|
660
|
+
if (typeof definition.id !== "string") invalidField(context, "id", errors);
|
|
661
|
+
if (!isNullableInteger(definition.legacyId)) invalidField(context, "legacyId", errors);
|
|
662
|
+
if (typeof definition.name !== "string") invalidField(context, "name", errors);
|
|
663
|
+
expectImportSource(definition.source, `${context} source`, errors);
|
|
664
|
+
const target = expectObject(definition.target, `${context} target`, errors);
|
|
665
|
+
if (typeof target.tableName !== "string") invalidField(`${context} target`, "tableName", errors);
|
|
666
|
+
if (!isOneOf(target.mode, ["REPLACE", "APPEND", "UPSERT"])) {
|
|
667
|
+
invalidField(`${context} target`, "mode", errors);
|
|
668
|
+
}
|
|
669
|
+
if (target.upsertKeyColumns !== null && !isStringArray(target.upsertKeyColumns)) {
|
|
670
|
+
invalidField(`${context} target`, "upsertKeyColumns", errors);
|
|
671
|
+
}
|
|
672
|
+
const processing = expectObject(
|
|
673
|
+
definition.processing,
|
|
674
|
+
`${context} processing`,
|
|
675
|
+
errors
|
|
676
|
+
);
|
|
677
|
+
if (!isOneOf(processing.mode, ["CHUNKED", "STREAMING"])) {
|
|
678
|
+
invalidField(`${context} processing`, "mode", errors);
|
|
679
|
+
}
|
|
680
|
+
if (!isNullableString(processing.orderColumn)) {
|
|
681
|
+
invalidField(`${context} processing`, "orderColumn", errors);
|
|
682
|
+
}
|
|
683
|
+
if (!isInteger(processing.chunkSize)) invalidField(`${context} processing`, "chunkSize", errors);
|
|
684
|
+
const schedule = expectObject(definition.schedule, `${context} schedule`, errors);
|
|
685
|
+
if (!isNullableString(schedule.cron)) invalidField(`${context} schedule`, "cron", errors);
|
|
686
|
+
if (typeof schedule.enabled !== "boolean") invalidField(`${context} schedule`, "enabled", errors);
|
|
687
|
+
if (definition.columnMappings !== null) {
|
|
688
|
+
expectObjectArray(
|
|
689
|
+
definition.columnMappings,
|
|
690
|
+
`${context} columnMappings`,
|
|
691
|
+
errors
|
|
692
|
+
).forEach((mapping, position) => {
|
|
693
|
+
const mappingContext = `${context} columnMapping ${position}`;
|
|
694
|
+
if (typeof mapping.source !== "string") invalidField(mappingContext, "source", errors);
|
|
695
|
+
if (typeof mapping.target !== "string") invalidField(mappingContext, "target", errors);
|
|
696
|
+
if (hasOwn(mapping, "type") && !isNullableString(mapping.type)) {
|
|
697
|
+
invalidField(mappingContext, "type", errors);
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
if (typeof definition.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
702
|
+
if (typeof definition.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
703
|
+
return definition;
|
|
704
|
+
}
|
|
705
|
+
function expectImportExecution(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
706
|
+
const execution = expectObject(value, context, errors);
|
|
707
|
+
if (typeof execution.id !== "string") invalidField(context, "id", errors);
|
|
708
|
+
if (typeof execution.importDefinitionId !== "string") {
|
|
709
|
+
invalidField(context, "importDefinitionId", errors);
|
|
710
|
+
}
|
|
711
|
+
if (!isNullableString(execution.importName)) invalidField(context, "importName", errors);
|
|
712
|
+
if (!isOneOf(execution.status, [
|
|
713
|
+
"PENDING",
|
|
714
|
+
"PREPARING",
|
|
715
|
+
"RUNNING",
|
|
716
|
+
"COMPLETED",
|
|
717
|
+
"PARTIALLY_COMPLETED",
|
|
718
|
+
"FAILED",
|
|
719
|
+
"CANCELLED"
|
|
720
|
+
])) {
|
|
721
|
+
invalidField(context, "status", errors);
|
|
722
|
+
}
|
|
723
|
+
if (!isOneOf(execution.triggerType, ["MANUAL", "SCHEDULED", "API"])) {
|
|
724
|
+
invalidField(context, "triggerType", errors);
|
|
725
|
+
}
|
|
726
|
+
for (const field of ["totalChunks", "progressPercent", "rowsTotal", "durationSeconds"]) {
|
|
727
|
+
if (!isNullableInteger(execution[field])) invalidField(context, field, errors);
|
|
728
|
+
}
|
|
729
|
+
for (const field of ["completedChunks", "failedChunks", "rowsProcessed"]) {
|
|
730
|
+
if (!isInteger(execution[field])) invalidField(context, field, errors);
|
|
731
|
+
}
|
|
732
|
+
if (typeof execution.queuedAt !== "string") invalidField(context, "queuedAt", errors);
|
|
733
|
+
if (!isNullableString(execution.startedAt)) invalidField(context, "startedAt", errors);
|
|
734
|
+
if (!isNullableString(execution.completedAt)) invalidField(context, "completedAt", errors);
|
|
735
|
+
if (!isNullableString(execution.errorMessage)) invalidField(context, "errorMessage", errors);
|
|
736
|
+
return execution;
|
|
737
|
+
}
|
|
738
|
+
function expectMessageAccepted(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
739
|
+
const response = expectObject(value, context, errors);
|
|
740
|
+
if (typeof response.messageId !== "string") invalidField(context, "messageId", errors);
|
|
741
|
+
return response;
|
|
742
|
+
}
|
|
743
|
+
function expectAgentDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
744
|
+
const agent = expectObject(value, context, errors);
|
|
745
|
+
if (typeof agent.id !== "string") invalidField(context, "id", errors);
|
|
746
|
+
if (typeof agent.name !== "string") invalidField(context, "name", errors);
|
|
747
|
+
if (!isStringArray(agent.functionIds)) invalidField(context, "functionIds", errors);
|
|
748
|
+
if (typeof agent.autonomous !== "boolean") invalidField(context, "autonomous", errors);
|
|
749
|
+
if (typeof agent.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
750
|
+
if (typeof agent.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
751
|
+
return agent;
|
|
752
|
+
}
|
|
753
|
+
function expectAgentBulkDeleteResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
754
|
+
const result = expectObject(value, context, errors);
|
|
755
|
+
if (!isStringArray(result.deleted)) invalidField(context, "deleted", errors);
|
|
756
|
+
if (!isStringArray(result.notFound)) invalidField(context, "notFound", errors);
|
|
757
|
+
if (!isInteger(result.deletedCount)) invalidField(context, "deletedCount", errors);
|
|
758
|
+
return result;
|
|
759
|
+
}
|
|
760
|
+
function expectWorkflowDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
761
|
+
const workflow = expectWorkflowSummary(value, context, errors);
|
|
762
|
+
if (!isObject(workflow.definition)) invalidField(context, "definition", errors);
|
|
763
|
+
return workflow;
|
|
764
|
+
}
|
|
765
|
+
function expectWorkflowSummary(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
766
|
+
const workflow = expectObject(value, context, errors);
|
|
767
|
+
if (typeof workflow.id !== "string") invalidField(context, "id", errors);
|
|
768
|
+
if (typeof workflow.tenantId !== "string") invalidField(context, "tenantId", errors);
|
|
769
|
+
if (!isNullableString(workflow.appId)) invalidField(context, "appId", errors);
|
|
770
|
+
if (typeof workflow.name !== "string") invalidField(context, "name", errors);
|
|
771
|
+
if (typeof workflow.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
772
|
+
if (typeof workflow.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
773
|
+
return workflow;
|
|
774
|
+
}
|
|
775
|
+
function expectWorkflowExecution(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
776
|
+
const execution = expectObject(value, context, errors);
|
|
777
|
+
if (typeof execution.id !== "string") invalidField(context, "id", errors);
|
|
778
|
+
if (typeof execution.tenantId !== "string") invalidField(context, "tenantId", errors);
|
|
779
|
+
if (!isNullableString(execution.appId)) invalidField(context, "appId", errors);
|
|
780
|
+
if (typeof execution.workflowId !== "string") invalidField(context, "workflowId", errors);
|
|
781
|
+
if (!isOneOf(execution.triggerType, ["MANUAL", "SCHEDULED"])) {
|
|
782
|
+
invalidField(context, "triggerType", errors);
|
|
783
|
+
}
|
|
784
|
+
if (!isNullableString(execution.triggeredBy)) invalidField(context, "triggeredBy", errors);
|
|
785
|
+
if (!isOneOf(execution.status, ["PENDING", "RUNNING", "SUCCESS", "FAILED", "CANCELLED"])) {
|
|
786
|
+
invalidField(context, "status", errors);
|
|
787
|
+
}
|
|
788
|
+
if (!isNullableString(execution.currentStepId)) invalidField(context, "currentStepId", errors);
|
|
789
|
+
if (execution.context !== null && !isJsonRecord(execution.context)) {
|
|
790
|
+
invalidField(context, "context", errors);
|
|
791
|
+
}
|
|
792
|
+
if (!isNullableString(execution.errorMessage)) invalidField(context, "errorMessage", errors);
|
|
793
|
+
if (!isNullableString(execution.startedAt)) invalidField(context, "startedAt", errors);
|
|
794
|
+
if (!isNullableString(execution.finishedAt)) invalidField(context, "finishedAt", errors);
|
|
795
|
+
if (typeof execution.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
796
|
+
return execution;
|
|
797
|
+
}
|
|
798
|
+
function expectIntegrationResource(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
799
|
+
const resource = expectObject(value, context, errors);
|
|
800
|
+
if (typeof resource.id !== "string") invalidField(context, "id", errors);
|
|
801
|
+
if (typeof resource.tenantId !== "string") invalidField(context, "tenantId", errors);
|
|
802
|
+
if (typeof resource.templateConfigId !== "string")
|
|
803
|
+
invalidField(context, "templateConfigId", errors);
|
|
804
|
+
if (typeof resource.name !== "string") invalidField(context, "name", errors);
|
|
805
|
+
if (typeof resource.method !== "string") invalidField(context, "method", errors);
|
|
806
|
+
if (typeof resource.endpoint !== "string") invalidField(context, "endpoint", errors);
|
|
807
|
+
if (resource.body !== null && !isJsonRecord(resource.body)) {
|
|
808
|
+
invalidField(context, "body", errors);
|
|
809
|
+
}
|
|
810
|
+
const params = expectObject(resource.params, `${context} params`, errors);
|
|
811
|
+
Object.entries(params).forEach(([name, value2]) => {
|
|
812
|
+
const paramContext = `${context} param ${name}`;
|
|
813
|
+
const param = expectObject(value2, paramContext, errors);
|
|
814
|
+
if (typeof param.type !== "string") invalidField(paramContext, "type", errors);
|
|
815
|
+
if (typeof param.required !== "boolean") invalidField(paramContext, "required", errors);
|
|
816
|
+
if (!isJsonValue(param.defaultValue)) invalidField(paramContext, "defaultValue", errors);
|
|
817
|
+
if (!isNullableString(param.description)) invalidField(paramContext, "description", errors);
|
|
818
|
+
});
|
|
819
|
+
if (typeof resource.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
820
|
+
if (typeof resource.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
821
|
+
return resource;
|
|
822
|
+
}
|
|
823
|
+
function expectIntegrationResourceSummary(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
824
|
+
const resource = expectObject(value, context, errors);
|
|
825
|
+
if (typeof resource.id !== "string") invalidField(context, "id", errors);
|
|
826
|
+
if (typeof resource.name !== "string") invalidField(context, "name", errors);
|
|
827
|
+
if (typeof resource.method !== "string") invalidField(context, "method", errors);
|
|
828
|
+
if (typeof resource.endpoint !== "string") invalidField(context, "endpoint", errors);
|
|
829
|
+
return resource;
|
|
830
|
+
}
|
|
831
|
+
function expectIntegrationTemplateSummary(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
832
|
+
const template = expectObject(value, context, errors);
|
|
833
|
+
if (typeof template.id !== "string") invalidField(context, "id", errors);
|
|
834
|
+
if (typeof template.name !== "string") invalidField(context, "name", errors);
|
|
835
|
+
if (!isNullableString(template.baseUrl)) invalidField(context, "baseUrl", errors);
|
|
836
|
+
if (!isOneOf(template.proxyMode, ["OPEN", "RESOURCE_ONLY"])) {
|
|
837
|
+
invalidField(context, "proxyMode", errors);
|
|
838
|
+
}
|
|
839
|
+
if (!isNullableString(template.logoUrl)) invalidField(context, "logoUrl", errors);
|
|
840
|
+
if (!isOneOf(template.templateType, ["GENERIC_AUTH", "PROVIDER"])) {
|
|
841
|
+
invalidField(context, "templateType", errors);
|
|
842
|
+
}
|
|
843
|
+
return template;
|
|
844
|
+
}
|
|
845
|
+
function expectIntegrationTemplate(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
846
|
+
const template = expectIntegrationTemplateSummary(value, context, errors);
|
|
847
|
+
if (template.loginConfig !== null) {
|
|
848
|
+
expectIntegrationLoginConfig(template.loginConfig, `${context} loginConfig`, errors);
|
|
849
|
+
}
|
|
850
|
+
expectIntegrationRequestConfig(template.requestConfig, `${context} requestConfig`, errors);
|
|
851
|
+
expectObjectArray(template.fieldsSchema, `${context} fieldsSchema`, errors).forEach(
|
|
852
|
+
(field, position) => {
|
|
853
|
+
const fieldContext = `${context} field ${position}`;
|
|
854
|
+
if (typeof field.key !== "string") invalidField(fieldContext, "key", errors);
|
|
855
|
+
if (typeof field.label !== "string") invalidField(fieldContext, "label", errors);
|
|
856
|
+
if (!isOneOf(field.type, ["url", "text", "secret"])) {
|
|
857
|
+
invalidField(fieldContext, "type", errors);
|
|
858
|
+
}
|
|
859
|
+
if (typeof field.required !== "boolean") invalidField(fieldContext, "required", errors);
|
|
860
|
+
if (!isNullableString(field.placeholder)) invalidField(fieldContext, "placeholder", errors);
|
|
861
|
+
if (!isNullableString(field.default)) invalidField(fieldContext, "default", errors);
|
|
862
|
+
}
|
|
863
|
+
);
|
|
864
|
+
if (!isNullableString(template.documentationUrl)) {
|
|
865
|
+
invalidField(context, "documentationUrl", errors);
|
|
866
|
+
}
|
|
867
|
+
return template;
|
|
868
|
+
}
|
|
869
|
+
function expectIntegrationLoginConfig(value, context, errors) {
|
|
870
|
+
const config = expectObject(value, context, errors);
|
|
871
|
+
if (!isNullableString(config.url)) invalidField(context, "url", errors);
|
|
872
|
+
if (!isNullableString(config.method)) invalidField(context, "method", errors);
|
|
873
|
+
for (const field of ["headers", "query_params", "body_form", "body"]) {
|
|
874
|
+
if (config[field] !== null && !isJsonRecord(config[field])) {
|
|
875
|
+
invalidField(context, field, errors);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (config.token_extraction !== null) {
|
|
879
|
+
const extraction = expectObject(
|
|
880
|
+
config.token_extraction,
|
|
881
|
+
`${context} token_extraction`,
|
|
882
|
+
errors
|
|
883
|
+
);
|
|
884
|
+
for (const field of ["source", "path", "name"]) {
|
|
885
|
+
if (!isNullableString(extraction[field])) {
|
|
886
|
+
invalidField(`${context} token_extraction`, field, errors);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
if (!isNullableInteger(config.token_ttl_seconds)) {
|
|
891
|
+
invalidField(context, "token_ttl_seconds", errors);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function expectIntegrationRequestConfig(value, context, errors) {
|
|
895
|
+
const config = expectObject(value, context, errors);
|
|
896
|
+
if (config.headers !== null && !isJsonRecord(config.headers)) {
|
|
897
|
+
invalidField(context, "headers", errors);
|
|
898
|
+
}
|
|
899
|
+
if (config.credential_rules !== null) {
|
|
900
|
+
expectObjectArray(
|
|
901
|
+
config.credential_rules,
|
|
902
|
+
`${context} credential_rules`,
|
|
903
|
+
errors
|
|
904
|
+
).forEach((rule, position) => {
|
|
905
|
+
const ruleContext = `${context} credential rule ${position}`;
|
|
906
|
+
if (rule.placement !== null && !isOneOf(rule.placement, ["HEADER", "QUERY", "COOKIE", "BODY", "BASIC"])) {
|
|
907
|
+
invalidField(ruleContext, "placement", errors);
|
|
908
|
+
}
|
|
909
|
+
for (const field of ["name", "path", "value"]) {
|
|
910
|
+
if (!isNullableString(rule[field])) invalidField(ruleContext, field, errors);
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
function expectTemplateConfigSummary(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
916
|
+
const config = expectObject(value, context, errors);
|
|
917
|
+
if (typeof config.id !== "string") invalidField(context, "id", errors);
|
|
918
|
+
if (!isNullableString(config.appId)) invalidField(context, "appId", errors);
|
|
919
|
+
if (!isNullableInteger(config.legacyId)) invalidField(context, "legacyId", errors);
|
|
920
|
+
if (typeof config.templateId !== "string") invalidField(context, "templateId", errors);
|
|
921
|
+
if (typeof config.alias !== "string") invalidField(context, "alias", errors);
|
|
922
|
+
if (config.status !== null && !isOneOf(config.status, ["unchecked", "connected", "error"])) {
|
|
923
|
+
invalidField(context, "status", errors);
|
|
924
|
+
}
|
|
925
|
+
if (!isNullableString(config.lastCheckedAt)) invalidField(context, "lastCheckedAt", errors);
|
|
926
|
+
return config;
|
|
927
|
+
}
|
|
928
|
+
function expectTemplateConfig(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
929
|
+
const config = expectTemplateConfigSummary(value, context, errors);
|
|
930
|
+
if (typeof config.tenantId !== "string") invalidField(context, "tenantId", errors);
|
|
931
|
+
if (!isJsonRecord(config.config)) invalidField(context, "config", errors);
|
|
932
|
+
if (!isNullableString(config.lastCheckMessage)) {
|
|
933
|
+
invalidField(context, "lastCheckMessage", errors);
|
|
934
|
+
}
|
|
935
|
+
if (typeof config.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
936
|
+
if (typeof config.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
937
|
+
return config;
|
|
938
|
+
}
|
|
939
|
+
function expectIntegrationExecution(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
940
|
+
const execution = expectObject(value, context, errors);
|
|
941
|
+
if (typeof execution.id !== "string") invalidField(context, "id", errors);
|
|
942
|
+
if (typeof execution.templateConfigId !== "string") {
|
|
943
|
+
invalidField(context, "templateConfigId", errors);
|
|
944
|
+
}
|
|
945
|
+
if (!isNullableString(execution.appId)) invalidField(context, "appId", errors);
|
|
946
|
+
if (typeof execution.method !== "string") invalidField(context, "method", errors);
|
|
947
|
+
if (typeof execution.endpoint !== "string") invalidField(context, "endpoint", errors);
|
|
948
|
+
if (!hasOwn(execution, "requestBody") || !isJsonValue(execution.requestBody)) {
|
|
949
|
+
invalidField(context, "requestBody", errors);
|
|
950
|
+
}
|
|
951
|
+
if (!isNullableInteger(execution.responseStatus)) {
|
|
952
|
+
invalidField(context, "responseStatus", errors);
|
|
953
|
+
}
|
|
954
|
+
if (!hasOwn(execution, "responseBody") || !isJsonValue(execution.responseBody)) {
|
|
955
|
+
invalidField(context, "responseBody", errors);
|
|
956
|
+
}
|
|
957
|
+
if (!isNullableInteger(execution.durationMs)) invalidField(context, "durationMs", errors);
|
|
958
|
+
if (typeof execution.success !== "boolean") invalidField(context, "success", errors);
|
|
959
|
+
if (!isNullableString(execution.errorMessage)) invalidField(context, "errorMessage", errors);
|
|
960
|
+
if (!isNullableString(execution.source)) invalidField(context, "source", errors);
|
|
961
|
+
if (typeof execution.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
962
|
+
return execution;
|
|
963
|
+
}
|
|
964
|
+
function expectAgentTask(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
965
|
+
const task = expectObject(value, context, errors);
|
|
966
|
+
if (typeof task.id !== "string") invalidField(context, "id", errors);
|
|
967
|
+
for (const field of ["appId", "agentId", "userId", "title", "reasoningEffort"]) {
|
|
968
|
+
if (!isNullableString(task[field])) invalidField(context, field, errors);
|
|
969
|
+
}
|
|
970
|
+
if (typeof task.agentType !== "string") invalidField(context, "agentType", errors);
|
|
971
|
+
if (typeof task.archived !== "boolean") invalidField(context, "archived", errors);
|
|
972
|
+
if (!isNullableString(task.createdAt)) invalidField(context, "createdAt", errors);
|
|
973
|
+
if (typeof task.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
974
|
+
return task;
|
|
975
|
+
}
|
|
976
|
+
function expectAgentMessage(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
977
|
+
const message = expectObject(value, context, errors);
|
|
978
|
+
for (const field of ["id", "sender", "type", "content", "createdAt"]) {
|
|
979
|
+
if (typeof message[field] !== "string") invalidField(context, field, errors);
|
|
980
|
+
}
|
|
981
|
+
return message;
|
|
982
|
+
}
|
|
983
|
+
function expectAgentModel(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
984
|
+
const model = expectObject(value, context, errors);
|
|
985
|
+
for (const field of ["model", "name", "provider", "agentType"]) {
|
|
986
|
+
if (typeof model[field] !== "string") invalidField(context, field, errors);
|
|
987
|
+
}
|
|
988
|
+
if (!isStringArray(model.reasoningOptions)) invalidField(context, "reasoningOptions", errors);
|
|
989
|
+
return model;
|
|
990
|
+
}
|
|
991
|
+
function expectCredentialStatus(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
992
|
+
const status = expectObject(value, context, errors);
|
|
993
|
+
if (typeof status.provider !== "string") invalidField(context, "provider", errors);
|
|
994
|
+
if (typeof status.connected !== "boolean") invalidField(context, "connected", errors);
|
|
995
|
+
for (const field of ["credentialType", "accountEmail", "maskedApiKey"]) {
|
|
996
|
+
if (!isNullableString(status[field])) invalidField(context, field, errors);
|
|
997
|
+
}
|
|
998
|
+
return status;
|
|
999
|
+
}
|
|
1000
|
+
function expectOAuthStartResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1001
|
+
const result = expectObject(value, context, errors);
|
|
1002
|
+
if (typeof result.authUrl !== "string") invalidField(context, "authUrl", errors);
|
|
1003
|
+
if (typeof result.state !== "string") invalidField(context, "state", errors);
|
|
1004
|
+
return result;
|
|
1005
|
+
}
|
|
1006
|
+
function expectAuthenticationResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1007
|
+
const result = expectObject(value, context, errors);
|
|
1008
|
+
if (typeof result.connected !== "boolean") invalidField(context, "connected", errors);
|
|
1009
|
+
if (!isNullableString(result.email)) invalidField(context, "email", errors);
|
|
1010
|
+
return result;
|
|
1011
|
+
}
|
|
1012
|
+
function expectDeviceAuthorization(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1013
|
+
const result = expectObject(value, context, errors);
|
|
1014
|
+
for (const field of ["deviceAuthId", "userCode", "verificationUri"]) {
|
|
1015
|
+
if (typeof result[field] !== "string") invalidField(context, field, errors);
|
|
1016
|
+
}
|
|
1017
|
+
if (!isInteger(result.intervalSeconds)) invalidField(context, "intervalSeconds", errors);
|
|
1018
|
+
return result;
|
|
1019
|
+
}
|
|
1020
|
+
function expectProviderCredentialStatus(value, context, errors) {
|
|
1021
|
+
const status = expectObject(value, context, errors);
|
|
1022
|
+
if (typeof status.provider !== "string") invalidField(context, "provider", errors);
|
|
1023
|
+
if (typeof status.connected !== "boolean") invalidField(context, "connected", errors);
|
|
1024
|
+
if (!isNullableString(status.credentialType)) invalidField(context, "credentialType", errors);
|
|
1025
|
+
if (!isNullableString(status.accountEmail)) invalidField(context, "accountEmail", errors);
|
|
1026
|
+
return status;
|
|
1027
|
+
}
|
|
1028
|
+
function expectAgentConnection(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1029
|
+
const connection = expectObject(value, context, errors);
|
|
1030
|
+
if (typeof connection.id !== "string") invalidField(context, "id", errors);
|
|
1031
|
+
if (typeof connection.name !== "string") invalidField(context, "name", errors);
|
|
1032
|
+
if (typeof connection.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
1033
|
+
if (typeof connection.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
1034
|
+
expectObjectArray(
|
|
1035
|
+
connection.credentials,
|
|
1036
|
+
`${context} credentials`,
|
|
1037
|
+
errors,
|
|
1038
|
+
expectProviderCredentialStatus
|
|
1039
|
+
);
|
|
1040
|
+
return connection;
|
|
1041
|
+
}
|
|
1042
|
+
function expectTableDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1043
|
+
const wrapped = expectSchemaTables([{ schema: "validation", tables: [value] }], context, errors);
|
|
1044
|
+
return wrapped[0].tables[0];
|
|
1045
|
+
}
|
|
1046
|
+
function expectFunctionSummary(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1047
|
+
const summary = expectObject(value, context, errors);
|
|
1048
|
+
if (typeof summary.id !== "string") invalidField(context, "id", errors);
|
|
1049
|
+
if (typeof summary.tenantId !== "string") invalidField(context, "tenantId", errors);
|
|
1050
|
+
if (!isNullableString(summary.appId)) invalidField(context, "appId", errors);
|
|
1051
|
+
if (!isNullableInteger(summary.legacyId)) invalidField(context, "legacyId", errors);
|
|
1052
|
+
if (typeof summary.name !== "string") invalidField(context, "name", errors);
|
|
1053
|
+
if (!isNullableString(summary.description)) invalidField(context, "description", errors);
|
|
1054
|
+
if (typeof summary.runtime !== "string") invalidField(context, "runtime", errors);
|
|
1055
|
+
if (!isNullableString(summary.dataSourceId)) invalidField(context, "dataSourceId", errors);
|
|
1056
|
+
if (typeof summary.visibility !== "string") invalidField(context, "visibility", errors);
|
|
1057
|
+
if (!isNullableString(summary.cronExpression)) invalidField(context, "cronExpression", errors);
|
|
1058
|
+
if (summary.cronInputJson !== null && !isJsonRecord(summary.cronInputJson)) {
|
|
1059
|
+
invalidField(context, "cronInputJson", errors);
|
|
1060
|
+
}
|
|
1061
|
+
if (!isNullableBoolean(summary.cronEnabled)) invalidField(context, "cronEnabled", errors);
|
|
1062
|
+
if (typeof summary.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
1063
|
+
if (typeof summary.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
1064
|
+
return summary;
|
|
1065
|
+
}
|
|
1066
|
+
function expectFunctionVersionResponse(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1067
|
+
expectFunctionVersion(value, context, errors);
|
|
1068
|
+
return value;
|
|
1069
|
+
}
|
|
1070
|
+
function expectFunctionSecrets(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1071
|
+
const result = expectObject(value, context, errors);
|
|
1072
|
+
if (!isStringArray(result.secrets)) invalidField(context, "secrets", errors);
|
|
1073
|
+
return result;
|
|
1074
|
+
}
|
|
1075
|
+
function expectPublicFunctionResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1076
|
+
const result = expectObject(value, context, errors);
|
|
1077
|
+
if (typeof result.success !== "boolean") invalidField(context, "success", errors);
|
|
1078
|
+
if (result.output !== null && !isObject(result.output)) invalidField(context, "output", errors);
|
|
1079
|
+
if (!isNullableString(result.error)) invalidField(context, "error", errors);
|
|
1080
|
+
return result;
|
|
1081
|
+
}
|
|
1082
|
+
function expectPublicFunctionAsyncResult(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1083
|
+
const result = expectObject(value, context, errors);
|
|
1084
|
+
if (typeof result.id !== "string") invalidField(context, "id", errors);
|
|
1085
|
+
if (typeof result.status !== "string") invalidField(context, "status", errors);
|
|
1086
|
+
return result;
|
|
1087
|
+
}
|
|
1088
|
+
function expectEmpty(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
1089
|
+
if (value !== void 0) invalidResponse(`${context} must be empty`, errors);
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// src/modules/agentConnections.ts
|
|
1093
|
+
var MAX_CONNECTIONS = 100;
|
|
1094
|
+
function createAgentConnectionsModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
1095
|
+
const path = (id) => `/api/v1/connections/${encodePathSegment(id, "connection id", errors)}`;
|
|
1096
|
+
const providerPath = (id, provider) => `${path(id)}/providers/${encodePathSegment(provider, "provider", errors)}`;
|
|
1097
|
+
return {
|
|
1098
|
+
async list() {
|
|
1099
|
+
return expectObjectArray(
|
|
1100
|
+
await transport.request("/api/v1/connections", { method: "GET" }),
|
|
1101
|
+
"Connection response",
|
|
1102
|
+
errors,
|
|
1103
|
+
expectAgentConnection
|
|
1104
|
+
);
|
|
1105
|
+
},
|
|
1106
|
+
async get(id) {
|
|
1107
|
+
return expectAgentConnection(
|
|
1108
|
+
await transport.request(path(id), { method: "GET" }),
|
|
1109
|
+
"Connection response",
|
|
1110
|
+
errors
|
|
1111
|
+
);
|
|
1112
|
+
},
|
|
1113
|
+
async create(name) {
|
|
1114
|
+
return expectAgentConnection(
|
|
1115
|
+
await transport.request("/api/v1/connections", {
|
|
1116
|
+
method: "POST",
|
|
1117
|
+
body: { name }
|
|
1118
|
+
}),
|
|
1119
|
+
"Create connection response",
|
|
1120
|
+
errors
|
|
1121
|
+
);
|
|
1122
|
+
},
|
|
1123
|
+
async bulkCreate(inputs) {
|
|
1124
|
+
requireBatchSize(inputs, "connections", MAX_CONNECTIONS, errors);
|
|
1125
|
+
return expectObjectArray(
|
|
1126
|
+
await transport.request("/api/v1/connections/bulk", {
|
|
1127
|
+
method: "POST",
|
|
1128
|
+
body: { connections: inputs }
|
|
1129
|
+
}),
|
|
1130
|
+
"Bulk create connections response",
|
|
1131
|
+
errors,
|
|
1132
|
+
expectAgentConnection
|
|
1133
|
+
);
|
|
1134
|
+
},
|
|
1135
|
+
async delete(id) {
|
|
1136
|
+
expectEmpty(
|
|
1137
|
+
await transport.request(path(id), { method: "DELETE" }),
|
|
1138
|
+
"Delete connection response",
|
|
1139
|
+
errors
|
|
1140
|
+
);
|
|
1141
|
+
},
|
|
1142
|
+
async saveApiKey(id, provider, apiKey) {
|
|
1143
|
+
expectEmpty(
|
|
1144
|
+
await transport.request(`${providerPath(id, provider)}/api-key`, {
|
|
1145
|
+
method: "PUT",
|
|
1146
|
+
body: { apiKey }
|
|
1147
|
+
}),
|
|
1148
|
+
"Save connection API key response",
|
|
1149
|
+
errors
|
|
1150
|
+
);
|
|
1151
|
+
},
|
|
1152
|
+
async disconnectProvider(id, provider) {
|
|
1153
|
+
expectEmpty(
|
|
1154
|
+
await transport.request(providerPath(id, provider), { method: "DELETE" }),
|
|
1155
|
+
"Disconnect connection provider response",
|
|
1156
|
+
errors
|
|
1157
|
+
);
|
|
1158
|
+
},
|
|
1159
|
+
async startOAuth(id, provider) {
|
|
1160
|
+
return expectOAuthStartResult(
|
|
1161
|
+
await transport.request(`${providerPath(id, provider)}/oauth/start`, {
|
|
1162
|
+
method: "POST"
|
|
1163
|
+
}),
|
|
1164
|
+
"Connection OAuth start response",
|
|
1165
|
+
errors
|
|
1166
|
+
);
|
|
1167
|
+
},
|
|
1168
|
+
async exchangeOAuth(id, provider, input) {
|
|
1169
|
+
return expectAuthenticationResult(
|
|
1170
|
+
await transport.request(`${providerPath(id, provider)}/oauth/exchange`, {
|
|
1171
|
+
method: "POST",
|
|
1172
|
+
body: input
|
|
1173
|
+
}),
|
|
1174
|
+
"Connection OAuth exchange response",
|
|
1175
|
+
errors
|
|
1176
|
+
);
|
|
1177
|
+
},
|
|
1178
|
+
async startDeviceAuthorization(id, provider) {
|
|
1179
|
+
return expectDeviceAuthorization(
|
|
1180
|
+
await transport.request(`${providerPath(id, provider)}/device-authorizations`, {
|
|
1181
|
+
method: "POST"
|
|
1182
|
+
}),
|
|
1183
|
+
"Connection device authorization response",
|
|
1184
|
+
errors
|
|
1185
|
+
);
|
|
1186
|
+
},
|
|
1187
|
+
async pollDeviceAuthorization(id, provider, deviceAuthId) {
|
|
1188
|
+
return expectAuthenticationResult(
|
|
1189
|
+
await transport.request(
|
|
1190
|
+
`${providerPath(id, provider)}/device-authorizations/${encodePathSegment(
|
|
1191
|
+
deviceAuthId,
|
|
1192
|
+
"device authorization id",
|
|
1193
|
+
errors
|
|
1194
|
+
)}/poll`,
|
|
1195
|
+
{ method: "POST" }
|
|
1196
|
+
),
|
|
1197
|
+
"Connection device authorization poll response",
|
|
1198
|
+
errors
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
// src/modules/agentCredentials.ts
|
|
1205
|
+
function createAgentCredentialsModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
1206
|
+
const providerSegment = (provider) => encodePathSegment(provider, "provider", errors);
|
|
1207
|
+
return {
|
|
1208
|
+
async list() {
|
|
1209
|
+
return expectObjectArray(
|
|
1210
|
+
await transport.request("/api/v1/credentials", { method: "GET" }),
|
|
1211
|
+
"Credential status response",
|
|
1212
|
+
errors,
|
|
1213
|
+
expectCredentialStatus
|
|
1214
|
+
);
|
|
1215
|
+
},
|
|
1216
|
+
async listModels(agentId) {
|
|
1217
|
+
return expectObjectArray(
|
|
1218
|
+
await transport.request("/api/v1/models", {
|
|
1219
|
+
method: "GET",
|
|
1220
|
+
params: { agentId }
|
|
1221
|
+
}),
|
|
1222
|
+
"Agent model response",
|
|
1223
|
+
errors,
|
|
1224
|
+
expectAgentModel
|
|
1225
|
+
);
|
|
1226
|
+
},
|
|
1227
|
+
async saveApiKey(provider, apiKey) {
|
|
1228
|
+
expectEmpty(
|
|
1229
|
+
await transport.request(
|
|
1230
|
+
`/api/v1/credentials/${providerSegment(provider)}/api-key`,
|
|
1231
|
+
{ method: "PUT", body: { apiKey } }
|
|
1232
|
+
),
|
|
1233
|
+
"Save API key response",
|
|
1234
|
+
errors
|
|
1235
|
+
);
|
|
1236
|
+
},
|
|
1237
|
+
async remove(provider) {
|
|
1238
|
+
expectEmpty(
|
|
1239
|
+
await transport.request(`/api/v1/credentials/${providerSegment(provider)}`, {
|
|
1240
|
+
method: "DELETE"
|
|
1241
|
+
}),
|
|
1242
|
+
"Remove credential response",
|
|
1243
|
+
errors
|
|
1244
|
+
);
|
|
1245
|
+
},
|
|
1246
|
+
async startOAuth(provider) {
|
|
1247
|
+
return expectOAuthStartResult(
|
|
1248
|
+
await transport.request("/api/v1/oauth/start", {
|
|
1249
|
+
method: "POST",
|
|
1250
|
+
body: { provider }
|
|
1251
|
+
}),
|
|
1252
|
+
"OAuth start response",
|
|
1253
|
+
errors
|
|
1254
|
+
);
|
|
1255
|
+
},
|
|
1256
|
+
async exchangeOAuth(provider, input) {
|
|
1257
|
+
return expectAuthenticationResult(
|
|
1258
|
+
await transport.request("/api/v1/oauth/exchange", {
|
|
1259
|
+
method: "POST",
|
|
1260
|
+
body: { provider, ...input }
|
|
1261
|
+
}),
|
|
1262
|
+
"OAuth exchange response",
|
|
1263
|
+
errors
|
|
1264
|
+
);
|
|
1265
|
+
},
|
|
1266
|
+
async startDeviceAuthorization(provider) {
|
|
1267
|
+
return expectDeviceAuthorization(
|
|
1268
|
+
await transport.request(
|
|
1269
|
+
`/api/v1/credentials/${providerSegment(provider)}/device-authorizations`,
|
|
1270
|
+
{ method: "POST" }
|
|
1271
|
+
),
|
|
1272
|
+
"Device authorization response",
|
|
1273
|
+
errors
|
|
1274
|
+
);
|
|
1275
|
+
},
|
|
1276
|
+
async pollDeviceAuthorization(provider, deviceAuthId) {
|
|
1277
|
+
return expectAuthenticationResult(
|
|
1278
|
+
await transport.request(
|
|
1279
|
+
`/api/v1/credentials/${providerSegment(provider)}/device-authorizations/${encodePathSegment(
|
|
1280
|
+
deviceAuthId,
|
|
1281
|
+
"device authorization id",
|
|
1282
|
+
errors
|
|
1283
|
+
)}/poll`,
|
|
1284
|
+
{ method: "POST" }
|
|
1285
|
+
),
|
|
1286
|
+
"Device authorization poll response",
|
|
1287
|
+
errors
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
// src/modules/agents.ts
|
|
1294
|
+
var MAX_AGENTS = 100;
|
|
1295
|
+
function createAgentsModule(functionsTransport, copilotTransport, errors = defaultSdkCoreErrorFactory) {
|
|
1296
|
+
const path = (id) => `/api/v1/agents/${encodePathSegment(id, "agent id", errors)}`;
|
|
1297
|
+
return {
|
|
1298
|
+
async list(options = {}) {
|
|
1299
|
+
const params = {
|
|
1300
|
+
page: options.page,
|
|
1301
|
+
size: options.size,
|
|
1302
|
+
sort: options.sort
|
|
1303
|
+
};
|
|
1304
|
+
return expectPage(
|
|
1305
|
+
await functionsTransport.request("/api/v1/agents", { method: "GET", params }),
|
|
1306
|
+
"Agent page response",
|
|
1307
|
+
errors,
|
|
1308
|
+
expectAgentDefinition
|
|
1309
|
+
);
|
|
1310
|
+
},
|
|
1311
|
+
async get(id) {
|
|
1312
|
+
return expectAgentDefinition(
|
|
1313
|
+
await functionsTransport.request(path(id), { method: "GET" }),
|
|
1314
|
+
"Agent response",
|
|
1315
|
+
errors
|
|
1316
|
+
);
|
|
1317
|
+
},
|
|
1318
|
+
async create(input) {
|
|
1319
|
+
return expectAgentDefinition(
|
|
1320
|
+
await functionsTransport.request("/api/v1/agents", {
|
|
1321
|
+
method: "POST",
|
|
1322
|
+
body: input
|
|
1323
|
+
}),
|
|
1324
|
+
"Create agent response",
|
|
1325
|
+
errors
|
|
1326
|
+
);
|
|
1327
|
+
},
|
|
1328
|
+
async update(id, input) {
|
|
1329
|
+
return expectAgentDefinition(
|
|
1330
|
+
await functionsTransport.request(path(id), { method: "PUT", body: input }),
|
|
1331
|
+
"Update agent response",
|
|
1332
|
+
errors
|
|
1333
|
+
);
|
|
1334
|
+
},
|
|
1335
|
+
async delete(id) {
|
|
1336
|
+
expectEmpty(
|
|
1337
|
+
await functionsTransport.request(path(id), { method: "DELETE" }),
|
|
1338
|
+
"Delete agent response",
|
|
1339
|
+
errors
|
|
1340
|
+
);
|
|
1341
|
+
},
|
|
1342
|
+
async bulkCreate(inputs) {
|
|
1343
|
+
requireBatchSize(inputs, "agents", MAX_AGENTS, errors);
|
|
1344
|
+
return expectObjectArray(
|
|
1345
|
+
await functionsTransport.request("/api/v1/agents/bulk", {
|
|
1346
|
+
method: "POST",
|
|
1347
|
+
body: { agents: inputs }
|
|
1348
|
+
}),
|
|
1349
|
+
"Bulk create agents response",
|
|
1350
|
+
errors,
|
|
1351
|
+
expectAgentDefinition
|
|
1352
|
+
);
|
|
1353
|
+
},
|
|
1354
|
+
async bulkUpdate(items) {
|
|
1355
|
+
requireBatchSize(items, "agents", MAX_AGENTS, errors);
|
|
1356
|
+
return expectObjectArray(
|
|
1357
|
+
await functionsTransport.request("/api/v1/agents/bulk", {
|
|
1358
|
+
method: "PUT",
|
|
1359
|
+
body: { agents: items }
|
|
1360
|
+
}),
|
|
1361
|
+
"Bulk update agents response",
|
|
1362
|
+
errors,
|
|
1363
|
+
expectAgentDefinition
|
|
1364
|
+
);
|
|
1365
|
+
},
|
|
1366
|
+
async bulkDelete(ids) {
|
|
1367
|
+
requireBatchSize(ids, "ids", MAX_AGENTS, errors);
|
|
1368
|
+
return expectAgentBulkDeleteResult(
|
|
1369
|
+
await functionsTransport.request("/api/v1/agents/bulk-delete", {
|
|
1370
|
+
method: "POST",
|
|
1371
|
+
body: { ids }
|
|
1372
|
+
}),
|
|
1373
|
+
"Bulk delete agents response",
|
|
1374
|
+
errors
|
|
1375
|
+
);
|
|
1376
|
+
},
|
|
1377
|
+
async listModels(agentId) {
|
|
1378
|
+
return expectObjectArray(
|
|
1379
|
+
await copilotTransport.request("/api/v1/models", {
|
|
1380
|
+
method: "GET",
|
|
1381
|
+
params: { agentId }
|
|
1382
|
+
}),
|
|
1383
|
+
"Agent model response",
|
|
1384
|
+
errors,
|
|
1385
|
+
expectAgentModel
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
// src/modules/agentTasks.ts
|
|
1392
|
+
function createAgentTasksModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
1393
|
+
const path = (id) => `/api/v1/tasks/${encodePathSegment(id, "task id", errors)}`;
|
|
1394
|
+
return {
|
|
1395
|
+
async list(options = {}) {
|
|
1396
|
+
const params = {
|
|
1397
|
+
page: options.page,
|
|
1398
|
+
size: options.size,
|
|
1399
|
+
sort: options.sort,
|
|
1400
|
+
archived: options.archived,
|
|
1401
|
+
agentId: options.agentId,
|
|
1402
|
+
search: options.search,
|
|
1403
|
+
userId: options.userId
|
|
1404
|
+
};
|
|
1405
|
+
return expectPage(
|
|
1406
|
+
await transport.request("/api/v1/tasks", { method: "GET", params }),
|
|
1407
|
+
"Agent task page response",
|
|
1408
|
+
errors,
|
|
1409
|
+
expectAgentTask
|
|
1410
|
+
);
|
|
1411
|
+
},
|
|
1412
|
+
async get(id) {
|
|
1413
|
+
return expectAgentTask(
|
|
1414
|
+
await transport.request(path(id), { method: "GET" }),
|
|
1415
|
+
"Agent task response",
|
|
1416
|
+
errors
|
|
1417
|
+
);
|
|
1418
|
+
},
|
|
1419
|
+
async create(input) {
|
|
1420
|
+
return expectAgentTask(
|
|
1421
|
+
await transport.request("/api/v1/tasks", { method: "POST", body: input }),
|
|
1422
|
+
"Create agent task response",
|
|
1423
|
+
errors
|
|
1424
|
+
);
|
|
1425
|
+
},
|
|
1426
|
+
async rename(id, title) {
|
|
1427
|
+
return expectAgentTask(
|
|
1428
|
+
await transport.request(path(id), { method: "PATCH", body: { title } }),
|
|
1429
|
+
"Rename agent task response",
|
|
1430
|
+
errors
|
|
1431
|
+
);
|
|
1432
|
+
},
|
|
1433
|
+
async archive(id) {
|
|
1434
|
+
expectEmpty(
|
|
1435
|
+
await transport.request(`${path(id)}/archive`, { method: "PATCH" }),
|
|
1436
|
+
"Archive agent task response",
|
|
1437
|
+
errors
|
|
1438
|
+
);
|
|
1439
|
+
},
|
|
1440
|
+
async sendInput(id, input) {
|
|
1441
|
+
expectEmpty(
|
|
1442
|
+
await transport.request(`${path(id)}/inputs`, { method: "POST", body: input }),
|
|
1443
|
+
"Agent task input response",
|
|
1444
|
+
errors
|
|
1445
|
+
);
|
|
1446
|
+
},
|
|
1447
|
+
async listMessages(id, options = {}) {
|
|
1448
|
+
return expectPage(
|
|
1449
|
+
await transport.request(`${path(id)}/messages`, {
|
|
1450
|
+
method: "GET",
|
|
1451
|
+
params: { page: options.page, size: options.size, sort: options.sort }
|
|
1452
|
+
}),
|
|
1453
|
+
"Agent message page response",
|
|
1454
|
+
errors,
|
|
1455
|
+
expectAgentMessage
|
|
1456
|
+
);
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// src/modules/apps.ts
|
|
1462
|
+
function createAppsModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
1463
|
+
const appPath = (appId) => `/api/v1/apps/${encodePathSegment(appId, "app id", errors)}`;
|
|
1464
|
+
const params = (options = {}, defaultSort) => ({
|
|
1465
|
+
page: options.page,
|
|
1466
|
+
size: options.size,
|
|
1467
|
+
sort: options.sort ?? defaultSort
|
|
1468
|
+
});
|
|
1469
|
+
return {
|
|
1470
|
+
async list(options = {}) {
|
|
1471
|
+
return expectPage(
|
|
1472
|
+
await transport.request("/api/v1/apps", {
|
|
1473
|
+
method: "GET",
|
|
1474
|
+
params: {
|
|
1475
|
+
...params(options, "createdAt,desc"),
|
|
1476
|
+
search: options.search,
|
|
1477
|
+
version: options.version,
|
|
1478
|
+
brand: options.brand
|
|
1479
|
+
}
|
|
1480
|
+
}),
|
|
1481
|
+
"App page response",
|
|
1482
|
+
errors,
|
|
1483
|
+
expectAppSummary
|
|
1484
|
+
);
|
|
1485
|
+
},
|
|
1486
|
+
async get(appId, options = {}) {
|
|
1487
|
+
return expectAppDefinition(
|
|
1488
|
+
await transport.request(appPath(appId), {
|
|
1489
|
+
method: "GET",
|
|
1490
|
+
params: { version: options.version }
|
|
1491
|
+
}),
|
|
1492
|
+
"App response",
|
|
1493
|
+
errors
|
|
1494
|
+
);
|
|
1495
|
+
},
|
|
1496
|
+
async create(input) {
|
|
1497
|
+
return expectAppDefinition(
|
|
1498
|
+
await transport.request("/api/v1/apps", { method: "POST", body: input }),
|
|
1499
|
+
"Create app response",
|
|
1500
|
+
errors
|
|
1501
|
+
);
|
|
1502
|
+
},
|
|
1503
|
+
async delete(appId) {
|
|
1504
|
+
expectEmpty(
|
|
1505
|
+
await transport.request(appPath(appId), { method: "DELETE" }),
|
|
1506
|
+
"Delete app response",
|
|
1507
|
+
errors
|
|
1508
|
+
);
|
|
1509
|
+
},
|
|
1510
|
+
async update(appId, input) {
|
|
1511
|
+
return expectAppDefinition(
|
|
1512
|
+
await transport.request(appPath(appId), { method: "PATCH", body: input }),
|
|
1513
|
+
"Update app response",
|
|
1514
|
+
errors
|
|
1515
|
+
);
|
|
1516
|
+
},
|
|
1517
|
+
async getFiles(appId) {
|
|
1518
|
+
return expectFiles(
|
|
1519
|
+
await transport.request(`${appPath(appId)}/files`, { method: "GET" }),
|
|
1520
|
+
errors
|
|
1521
|
+
);
|
|
1522
|
+
},
|
|
1523
|
+
async replaceFiles(appId, files) {
|
|
1524
|
+
return expectFiles(
|
|
1525
|
+
await transport.request(`${appPath(appId)}/files`, {
|
|
1526
|
+
method: "PUT",
|
|
1527
|
+
body: { files }
|
|
1528
|
+
}),
|
|
1529
|
+
errors
|
|
1530
|
+
);
|
|
1531
|
+
},
|
|
1532
|
+
async mergeFiles(appId, files) {
|
|
1533
|
+
return expectFiles(
|
|
1534
|
+
await transport.request(`${appPath(appId)}/files`, {
|
|
1535
|
+
method: "PATCH",
|
|
1536
|
+
body: { files }
|
|
1537
|
+
}),
|
|
1538
|
+
errors
|
|
1539
|
+
);
|
|
1540
|
+
},
|
|
1541
|
+
async build(appId) {
|
|
1542
|
+
return expectAppDeploy(
|
|
1543
|
+
await transport.request(`${appPath(appId)}/build`, { method: "POST" }),
|
|
1544
|
+
"Build app deploy response",
|
|
1545
|
+
errors
|
|
1546
|
+
);
|
|
1547
|
+
},
|
|
1548
|
+
async publish(appId, options = {}) {
|
|
1549
|
+
return expectAppDefinition(
|
|
1550
|
+
await transport.request(`${appPath(appId)}/publish`, {
|
|
1551
|
+
method: "POST",
|
|
1552
|
+
body: options.externalAccess === void 0 ? void 0 : options
|
|
1553
|
+
}),
|
|
1554
|
+
"Publish app response",
|
|
1555
|
+
errors
|
|
1556
|
+
);
|
|
1557
|
+
},
|
|
1558
|
+
async getDeploy(appId, deployId) {
|
|
1559
|
+
return expectAppDeploy(
|
|
1560
|
+
await transport.request(
|
|
1561
|
+
`${appPath(appId)}/deploys/${encodePathSegment(deployId, "deploy id", errors)}`,
|
|
1562
|
+
{ method: "GET" }
|
|
1563
|
+
),
|
|
1564
|
+
"App deploy response",
|
|
1565
|
+
errors
|
|
1566
|
+
);
|
|
1567
|
+
},
|
|
1568
|
+
async getCurrentDeploy(appId) {
|
|
1569
|
+
const response = await transport.request(`${appPath(appId)}/deploys/current`, {
|
|
1570
|
+
method: "GET"
|
|
1571
|
+
});
|
|
1572
|
+
return response === null || response === void 0 ? null : expectAppDeploy(response, "Current app deploy response", errors);
|
|
1573
|
+
},
|
|
1574
|
+
async cancelBuild(appId, deployId) {
|
|
1575
|
+
return expectAppDeploy(
|
|
1576
|
+
await transport.request(
|
|
1577
|
+
`${appPath(appId)}/deploys/${encodePathSegment(deployId, "deploy id", errors)}/cancel`,
|
|
1578
|
+
{ method: "POST" }
|
|
1579
|
+
),
|
|
1580
|
+
"Cancel app build response",
|
|
1581
|
+
errors
|
|
1582
|
+
);
|
|
1583
|
+
},
|
|
1584
|
+
async rollback(appId, targetVersionId) {
|
|
1585
|
+
return expectAppDefinition(
|
|
1586
|
+
await transport.request(`${appPath(appId)}/rollback`, {
|
|
1587
|
+
method: "POST",
|
|
1588
|
+
body: { targetVersionId }
|
|
1589
|
+
}),
|
|
1590
|
+
"Rollback app response",
|
|
1591
|
+
errors
|
|
1592
|
+
);
|
|
1593
|
+
},
|
|
1594
|
+
async listDeploys(appId, options = {}) {
|
|
1595
|
+
return expectPage(
|
|
1596
|
+
await transport.request(`${appPath(appId)}/deploys`, {
|
|
1597
|
+
method: "GET",
|
|
1598
|
+
params: params(options, "createdAt,desc")
|
|
1599
|
+
}),
|
|
1600
|
+
"App deploy page response",
|
|
1601
|
+
errors,
|
|
1602
|
+
expectAppDeploy
|
|
1603
|
+
);
|
|
1604
|
+
},
|
|
1605
|
+
async listVersions(appId, options = {}) {
|
|
1606
|
+
return expectPage(
|
|
1607
|
+
await transport.request(`${appPath(appId)}/versions`, {
|
|
1608
|
+
method: "GET",
|
|
1609
|
+
params: params(options, "createdAt,desc")
|
|
1610
|
+
}),
|
|
1611
|
+
"App version page response",
|
|
1612
|
+
errors,
|
|
1613
|
+
expectAppVersion
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
function expectFiles(value, errors) {
|
|
1619
|
+
const response = expectObject(value, "App files response", errors);
|
|
1620
|
+
if (response.files === null || typeof response.files !== "object" || Array.isArray(response.files) || Object.values(response.files).some((content) => typeof content !== "string")) {
|
|
1621
|
+
throw errors.invalidResponse("App files response has an invalid files field");
|
|
1622
|
+
}
|
|
1623
|
+
return response;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// src/modules/auth.ts
|
|
1627
|
+
function createAuthModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
1628
|
+
return {
|
|
1629
|
+
async me() {
|
|
1630
|
+
return expectUser(
|
|
1631
|
+
await transport.request("/api/v1/auth/me", { method: "GET" }),
|
|
1632
|
+
"Current user response",
|
|
1633
|
+
errors
|
|
1634
|
+
);
|
|
1635
|
+
},
|
|
1636
|
+
async listUserPlans() {
|
|
1637
|
+
return expectObjectArray(
|
|
1638
|
+
await transport.request("/api/v1/user-plans", { method: "GET" }),
|
|
1639
|
+
"User plan response",
|
|
1640
|
+
errors,
|
|
1641
|
+
expectUserPlan
|
|
1642
|
+
);
|
|
1643
|
+
}
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
// src/modules/context.ts
|
|
1648
|
+
var SUMMARY_PAGE_SIZE = 2e3;
|
|
1649
|
+
function createContextModule(dependencies, errors = defaultSdkCoreErrorFactory) {
|
|
1650
|
+
return {
|
|
1651
|
+
async getAppContext() {
|
|
1652
|
+
const appId = dependencies.getAppId?.();
|
|
1653
|
+
if (!appId) {
|
|
1654
|
+
configurationError("An appId is required for app context", errors);
|
|
1655
|
+
}
|
|
1656
|
+
const app = await dependencies.apps.get(appId);
|
|
1657
|
+
const tables = await dependencies.schema.listTables({ scope: "APP", includeColumns: true });
|
|
1658
|
+
const functionsPage = await dependencies.functionsAdmin.list({
|
|
1659
|
+
page: 0,
|
|
1660
|
+
size: SUMMARY_PAGE_SIZE,
|
|
1661
|
+
sort: "name"
|
|
1662
|
+
});
|
|
1663
|
+
const agentsPage = await dependencies.agents.list({
|
|
1664
|
+
page: 0,
|
|
1665
|
+
size: SUMMARY_PAGE_SIZE,
|
|
1666
|
+
sort: "name"
|
|
1667
|
+
});
|
|
1668
|
+
const fileResponse = await dependencies.apps.getFiles(appId);
|
|
1669
|
+
const integrationsPage = await dependencies.integrationAdmin.list({
|
|
1670
|
+
page: 0,
|
|
1671
|
+
size: SUMMARY_PAGE_SIZE,
|
|
1672
|
+
sort: "alias"
|
|
1673
|
+
});
|
|
1674
|
+
const connections = await dependencies.agentConnections.list();
|
|
1675
|
+
return {
|
|
1676
|
+
appId,
|
|
1677
|
+
app,
|
|
1678
|
+
tables,
|
|
1679
|
+
functions: functionsPage.content,
|
|
1680
|
+
functionsTotal: functionsPage.page.totalElements,
|
|
1681
|
+
functionsTruncated: functionsPage.content.length < functionsPage.page.totalElements,
|
|
1682
|
+
agents: agentsPage.content,
|
|
1683
|
+
agentsTotal: agentsPage.page.totalElements,
|
|
1684
|
+
agentsTruncated: agentsPage.content.length < agentsPage.page.totalElements,
|
|
1685
|
+
files: Object.keys(fileResponse.files).sort(),
|
|
1686
|
+
integrations: integrationsPage.content,
|
|
1687
|
+
integrationsTotal: integrationsPage.totalElements,
|
|
1688
|
+
integrationsTruncated: integrationsPage.content.length < integrationsPage.totalElements,
|
|
1689
|
+
connections
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
// src/modules/customQueries.ts
|
|
1696
|
+
function createCustomQueriesModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
1697
|
+
const path = (id) => `/api/v1/custom-queries/${encodePathSegment(id, "query id", errors)}`;
|
|
1698
|
+
return {
|
|
1699
|
+
async list(options = {}) {
|
|
1700
|
+
const params = {
|
|
1701
|
+
page: options.page,
|
|
1702
|
+
size: options.size ?? 20,
|
|
1703
|
+
sort: options.sort ?? "name"
|
|
1704
|
+
};
|
|
1705
|
+
return expectPage(
|
|
1706
|
+
await transport.request("/api/v1/custom-queries", { method: "GET", params }),
|
|
1707
|
+
"Custom query page response",
|
|
1708
|
+
errors,
|
|
1709
|
+
expectCustomQuerySummary
|
|
1710
|
+
);
|
|
1711
|
+
},
|
|
1712
|
+
async get(id) {
|
|
1713
|
+
return expectCustomQueryDefinition(
|
|
1714
|
+
await transport.request(path(id), { method: "GET" }),
|
|
1715
|
+
"Custom query response",
|
|
1716
|
+
errors
|
|
1717
|
+
);
|
|
1718
|
+
},
|
|
1719
|
+
async create(input) {
|
|
1720
|
+
return expectCustomQueryDefinition(
|
|
1721
|
+
await transport.request("/api/v1/custom-queries", { method: "POST", body: input }),
|
|
1722
|
+
"Create custom query response",
|
|
1723
|
+
errors
|
|
1724
|
+
);
|
|
1725
|
+
},
|
|
1726
|
+
async update(id, input) {
|
|
1727
|
+
return expectCustomQueryDefinition(
|
|
1728
|
+
await transport.request(path(id), { method: "PUT", body: input }),
|
|
1729
|
+
"Update custom query response",
|
|
1730
|
+
errors
|
|
1731
|
+
);
|
|
1732
|
+
},
|
|
1733
|
+
async delete(id) {
|
|
1734
|
+
expectEmpty(
|
|
1735
|
+
await transport.request(path(id), { method: "DELETE" }),
|
|
1736
|
+
"Delete custom query response",
|
|
1737
|
+
errors
|
|
1738
|
+
);
|
|
1739
|
+
},
|
|
1740
|
+
async execute(id, parameters = {}) {
|
|
1741
|
+
return expectQueryResult(
|
|
1742
|
+
await transport.request(`${path(id)}/execute`, {
|
|
1743
|
+
method: "POST",
|
|
1744
|
+
body: { parameters }
|
|
1745
|
+
}),
|
|
1746
|
+
"Custom query execution response",
|
|
1747
|
+
errors
|
|
1748
|
+
);
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
// src/modules/dataSources.ts
|
|
1754
|
+
var MAX_DATA_SOURCES = 100;
|
|
1755
|
+
function bulkFailure(index, dataSourceId, error) {
|
|
1756
|
+
const errorCode2 = typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : null;
|
|
1757
|
+
return {
|
|
1758
|
+
index,
|
|
1759
|
+
success: false,
|
|
1760
|
+
dataSourceId,
|
|
1761
|
+
errorCode: errorCode2,
|
|
1762
|
+
message: error instanceof Error ? error.message : "Data Source operation failed"
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
function bulkResult(results) {
|
|
1766
|
+
const succeededCount = results.filter(({ success }) => success).length;
|
|
1767
|
+
return {
|
|
1768
|
+
results,
|
|
1769
|
+
processedCount: results.length,
|
|
1770
|
+
succeededCount,
|
|
1771
|
+
failedCount: results.length - succeededCount
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
function createDataSourcesModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
1775
|
+
const path = (id) => `/api/v1/data-sources/${encodePathSegment(id, "data source id", errors)}`;
|
|
1776
|
+
const createOne = async (input) => expectDataSourceDefinition(
|
|
1777
|
+
await transport.request("/api/v1/data-sources", { method: "POST", body: input }),
|
|
1778
|
+
"Create Data Source response",
|
|
1779
|
+
errors
|
|
1780
|
+
);
|
|
1781
|
+
const updateOne = async (id, input) => expectDataSourceDefinition(
|
|
1782
|
+
await transport.request(path(id), { method: "PUT", body: input }),
|
|
1783
|
+
"Update Data Source response",
|
|
1784
|
+
errors
|
|
1785
|
+
);
|
|
1786
|
+
const deleteOne = async (id) => {
|
|
1787
|
+
expectEmpty(
|
|
1788
|
+
await transport.request(path(id), { method: "DELETE" }),
|
|
1789
|
+
"Delete Data Source response",
|
|
1790
|
+
errors
|
|
1791
|
+
);
|
|
1792
|
+
};
|
|
1793
|
+
return {
|
|
1794
|
+
async list(options = {}) {
|
|
1795
|
+
const params = {
|
|
1796
|
+
page: options.page,
|
|
1797
|
+
size: options.size,
|
|
1798
|
+
sort: options.sort
|
|
1799
|
+
};
|
|
1800
|
+
return expectPage(
|
|
1801
|
+
await transport.request("/api/v1/data-sources", { method: "GET", params }),
|
|
1802
|
+
"Data Source page response",
|
|
1803
|
+
errors,
|
|
1804
|
+
expectDataSourceDefinition
|
|
1805
|
+
);
|
|
1806
|
+
},
|
|
1807
|
+
async get(id) {
|
|
1808
|
+
return expectDataSourceDefinition(
|
|
1809
|
+
await transport.request(path(id), { method: "GET" }),
|
|
1810
|
+
"Data Source response",
|
|
1811
|
+
errors
|
|
1812
|
+
);
|
|
1813
|
+
},
|
|
1814
|
+
async create(input) {
|
|
1815
|
+
return createOne(input);
|
|
1816
|
+
},
|
|
1817
|
+
async update(id, input) {
|
|
1818
|
+
return updateOne(id, input);
|
|
1819
|
+
},
|
|
1820
|
+
async delete(id) {
|
|
1821
|
+
return deleteOne(id);
|
|
1822
|
+
},
|
|
1823
|
+
async bulkCreate(dataSources) {
|
|
1824
|
+
requireBatchSize(dataSources, "dataSources", MAX_DATA_SOURCES, errors);
|
|
1825
|
+
const results = [];
|
|
1826
|
+
for (const [index, input] of dataSources.entries()) {
|
|
1827
|
+
try {
|
|
1828
|
+
const created = await createOne(input);
|
|
1829
|
+
results.push({
|
|
1830
|
+
index,
|
|
1831
|
+
success: true,
|
|
1832
|
+
dataSourceId: created.id,
|
|
1833
|
+
errorCode: null,
|
|
1834
|
+
message: null
|
|
1835
|
+
});
|
|
1836
|
+
} catch (error) {
|
|
1837
|
+
results.push(bulkFailure(index, null, error));
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
return bulkResult(results);
|
|
1841
|
+
},
|
|
1842
|
+
async bulkUpdate(dataSources) {
|
|
1843
|
+
requireBatchSize(dataSources, "dataSources", MAX_DATA_SOURCES, errors);
|
|
1844
|
+
const paths = dataSources.map(({ dataSourceId }) => path(dataSourceId));
|
|
1845
|
+
const results = [];
|
|
1846
|
+
for (const [index, { dataSourceId, ...input }] of dataSources.entries()) {
|
|
1847
|
+
try {
|
|
1848
|
+
const updated = expectDataSourceDefinition(
|
|
1849
|
+
await transport.request(paths[index], { method: "PUT", body: input }),
|
|
1850
|
+
"Update Data Source response",
|
|
1851
|
+
errors
|
|
1852
|
+
);
|
|
1853
|
+
results.push({
|
|
1854
|
+
index,
|
|
1855
|
+
success: true,
|
|
1856
|
+
dataSourceId: updated.id,
|
|
1857
|
+
errorCode: null,
|
|
1858
|
+
message: null
|
|
1859
|
+
});
|
|
1860
|
+
} catch (error) {
|
|
1861
|
+
results.push(bulkFailure(index, dataSourceId, error));
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
return bulkResult(results);
|
|
1865
|
+
},
|
|
1866
|
+
async bulkDelete(dataSourceIds) {
|
|
1867
|
+
requireBatchSize(dataSourceIds, "dataSourceIds", MAX_DATA_SOURCES, errors);
|
|
1868
|
+
const paths = dataSourceIds.map((id) => path(id));
|
|
1869
|
+
const results = [];
|
|
1870
|
+
for (const [index, dataSourceId] of dataSourceIds.entries()) {
|
|
1871
|
+
try {
|
|
1872
|
+
expectEmpty(
|
|
1873
|
+
await transport.request(paths[index], { method: "DELETE" }),
|
|
1874
|
+
"Delete Data Source response",
|
|
1875
|
+
errors
|
|
1876
|
+
);
|
|
1877
|
+
results.push({ index, success: true, dataSourceId, errorCode: null, message: null });
|
|
1878
|
+
} catch (error) {
|
|
1879
|
+
results.push(bulkFailure(index, dataSourceId, error));
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
return bulkResult(results);
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
// src/modules/entities.ts
|
|
1888
|
+
var DefaultEntitiesModule = class {
|
|
1889
|
+
constructor(transport, errors) {
|
|
1890
|
+
this.transport = transport;
|
|
1891
|
+
this.errors = errors;
|
|
1892
|
+
}
|
|
1893
|
+
tables = /* @__PURE__ */ new Map();
|
|
1894
|
+
getTable(tableName) {
|
|
1895
|
+
if (!this.tables.has(tableName)) {
|
|
1896
|
+
this.tables.set(tableName, this.createTable(tableName));
|
|
1897
|
+
}
|
|
1898
|
+
return this.tables.get(tableName);
|
|
1899
|
+
}
|
|
1900
|
+
createTable(tableName) {
|
|
1901
|
+
const basePath = `/api/v1/tables/${encodePathSegment(tableName, "tableName", this.errors)}/records`;
|
|
1902
|
+
return {
|
|
1903
|
+
list: async (sortOrOptions, limit, skip, fields) => {
|
|
1904
|
+
const options = typeof sortOrOptions === "object" ? sortOrOptions : void 0;
|
|
1905
|
+
const params = {
|
|
1906
|
+
sort: options?.sort ?? (typeof sortOrOptions === "string" ? sortOrOptions : void 0),
|
|
1907
|
+
limit: options?.limit ?? limit,
|
|
1908
|
+
skip: options?.skip ?? skip,
|
|
1909
|
+
fields: (options?.fields ?? fields)?.join(",")
|
|
1910
|
+
};
|
|
1911
|
+
return expectEntityListResponse(
|
|
1912
|
+
await this.transport.request(basePath, { method: "GET", params }),
|
|
1913
|
+
"Entity list response",
|
|
1914
|
+
this.errors
|
|
1915
|
+
);
|
|
1916
|
+
},
|
|
1917
|
+
filter: async (query, sort, limit, skip, fields) => {
|
|
1918
|
+
return expectEntityListResponse(
|
|
1919
|
+
await this.transport.request(basePath, {
|
|
1920
|
+
method: "GET",
|
|
1921
|
+
params: {
|
|
1922
|
+
q: JSON.stringify(query),
|
|
1923
|
+
sort,
|
|
1924
|
+
limit,
|
|
1925
|
+
skip,
|
|
1926
|
+
fields: fields?.join(",")
|
|
1927
|
+
}
|
|
1928
|
+
}),
|
|
1929
|
+
"Entity list response",
|
|
1930
|
+
this.errors
|
|
1931
|
+
);
|
|
1932
|
+
},
|
|
1933
|
+
get: async (id) => expectObject(
|
|
1934
|
+
await this.transport.request(
|
|
1935
|
+
`${basePath}/${encodePathSegment(id, "id", this.errors)}`,
|
|
1936
|
+
{ method: "GET" }
|
|
1937
|
+
),
|
|
1938
|
+
"Entity response",
|
|
1939
|
+
this.errors
|
|
1940
|
+
),
|
|
1941
|
+
create: async (data) => expectObject(
|
|
1942
|
+
await this.transport.request(basePath, { method: "POST", body: data }),
|
|
1943
|
+
"Created entity response",
|
|
1944
|
+
this.errors
|
|
1945
|
+
),
|
|
1946
|
+
bulkCreate: async (data) => expectObjectArray(
|
|
1947
|
+
await this.transport.request(`${basePath}/bulk`, {
|
|
1948
|
+
method: "POST",
|
|
1949
|
+
body: data
|
|
1950
|
+
}),
|
|
1951
|
+
"Bulk create response",
|
|
1952
|
+
this.errors
|
|
1953
|
+
),
|
|
1954
|
+
update: async (id, data) => expectObject(
|
|
1955
|
+
await this.transport.request(
|
|
1956
|
+
`${basePath}/${encodePathSegment(id, "id", this.errors)}`,
|
|
1957
|
+
{ method: "PUT", body: data }
|
|
1958
|
+
),
|
|
1959
|
+
"Updated entity response",
|
|
1960
|
+
this.errors
|
|
1961
|
+
),
|
|
1962
|
+
delete: (id) => this.transport.request(`${basePath}/${encodePathSegment(id, "id", this.errors)}`, {
|
|
1963
|
+
method: "DELETE"
|
|
1964
|
+
}).then((response) => expectEmpty(response, "Delete entity response", this.errors)),
|
|
1965
|
+
deleteMany: async (query) => {
|
|
1966
|
+
if (Object.keys(query).length === 0) {
|
|
1967
|
+
configurationError("query must not be empty for deleteMany", this.errors);
|
|
1968
|
+
}
|
|
1969
|
+
const response = expectObject(
|
|
1970
|
+
await this.transport.request(basePath, {
|
|
1971
|
+
method: "DELETE",
|
|
1972
|
+
params: { q: JSON.stringify(query) }
|
|
1973
|
+
}),
|
|
1974
|
+
"Delete many response",
|
|
1975
|
+
this.errors
|
|
1976
|
+
);
|
|
1977
|
+
if (!Number.isInteger(response.deleted)) {
|
|
1978
|
+
return invalidResponse(
|
|
1979
|
+
"Delete many response must include an integer deleted count",
|
|
1980
|
+
this.errors
|
|
1981
|
+
);
|
|
1982
|
+
}
|
|
1983
|
+
return { deleted: response.deleted };
|
|
1984
|
+
}
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
function expectEntityListResponse(value, context, errors) {
|
|
1989
|
+
const response = expectObject(value, context, errors);
|
|
1990
|
+
expectObjectArray(response.data, `${context} data`, errors);
|
|
1991
|
+
if (!Number.isInteger(response.limit))
|
|
1992
|
+
invalidResponse(`${context} has an invalid limit field`, errors);
|
|
1993
|
+
if (!Number.isInteger(response.skip))
|
|
1994
|
+
invalidResponse(`${context} has an invalid skip field`, errors);
|
|
1995
|
+
if (!Number.isInteger(response.total))
|
|
1996
|
+
invalidResponse(`${context} has an invalid total field`, errors);
|
|
1997
|
+
if (typeof response.hasMore !== "boolean") {
|
|
1998
|
+
invalidResponse(`${context} has an invalid hasMore field`, errors);
|
|
1999
|
+
}
|
|
2000
|
+
return response;
|
|
2001
|
+
}
|
|
2002
|
+
function createEntitiesModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2003
|
+
const instance = new DefaultEntitiesModule(transport, errors);
|
|
2004
|
+
return new Proxy(instance, {
|
|
2005
|
+
get(target, property, receiver) {
|
|
2006
|
+
if (typeof property !== "string" || property in target) {
|
|
2007
|
+
return Reflect.get(target, property, receiver);
|
|
2008
|
+
}
|
|
2009
|
+
return target.getTable(property);
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
// src/modules/functions.ts
|
|
2015
|
+
var DefaultFunctionsModule = class {
|
|
2016
|
+
constructor(transport, errors, options) {
|
|
2017
|
+
this.transport = transport;
|
|
2018
|
+
this.errors = errors;
|
|
2019
|
+
this.options = options;
|
|
2020
|
+
}
|
|
2021
|
+
execute(id, input) {
|
|
2022
|
+
return this.executeWithType(id, this.options.executeInvocationType, input);
|
|
2023
|
+
}
|
|
2024
|
+
executeAsync(id, input) {
|
|
2025
|
+
return this.executeWithType(id, "async", input);
|
|
2026
|
+
}
|
|
2027
|
+
getExecution(id) {
|
|
2028
|
+
return this.transport.request(
|
|
2029
|
+
`/api/v1/executions/${encodePathSegment(id, "execution id", this.errors)}`,
|
|
2030
|
+
{ method: "GET" }
|
|
2031
|
+
).then(
|
|
2032
|
+
(response) => expectFunctionExecution(response, "Function execution response", this.errors)
|
|
2033
|
+
);
|
|
2034
|
+
}
|
|
2035
|
+
cancelExecution(id) {
|
|
2036
|
+
return this.transport.request(
|
|
2037
|
+
`/api/v1/executions/${encodePathSegment(id, "execution id", this.errors)}/cancel`,
|
|
2038
|
+
{ method: "POST" }
|
|
2039
|
+
).then((response) => expectEmpty(response, "Cancel execution response", this.errors));
|
|
2040
|
+
}
|
|
2041
|
+
executeWithType(id, invocationType, input) {
|
|
2042
|
+
const request = {
|
|
2043
|
+
method: "POST",
|
|
2044
|
+
...input !== void 0 || this.options.emptyInput !== "omit-body" ? { body: { input: input ?? {} } } : {},
|
|
2045
|
+
...invocationType === void 0 ? {} : { headers: { "X-Invocation-Type": invocationType } }
|
|
2046
|
+
};
|
|
2047
|
+
return this.transport.request(
|
|
2048
|
+
`/api/v1/functions/${encodePathSegment(id, "function id", this.errors)}/execute`,
|
|
2049
|
+
request
|
|
2050
|
+
).then(
|
|
2051
|
+
(response) => expectFunctionExecution(response, "Function execution response", this.errors)
|
|
2052
|
+
);
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2055
|
+
function createFunctionsModule(transport, options = {}, errors = defaultSdkCoreErrorFactory) {
|
|
2056
|
+
return new DefaultFunctionsModule(transport, errors, options);
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
// src/modules/functionsAdmin.ts
|
|
2060
|
+
var MAX_FUNCTIONS = 100;
|
|
2061
|
+
var COMPOSED_SCHEDULE_FIELDS = ["cronExpression", "cronInputJson", "cronEnabled"];
|
|
2062
|
+
function rejectBulkScheduleFields(value, operation, errors) {
|
|
2063
|
+
if (typeof value !== "object" || value === null) return;
|
|
2064
|
+
const field = COMPOSED_SCHEDULE_FIELDS.find((candidate) => Object.hasOwn(value, candidate));
|
|
2065
|
+
if (field) {
|
|
2066
|
+
configurationError(
|
|
2067
|
+
`functionsAdmin.${operation} does not support ${field}; composed scheduling is supported only by single-Function create and patch`,
|
|
2068
|
+
errors
|
|
2069
|
+
);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
function bulkPatchUpdate(value) {
|
|
2073
|
+
return typeof value === "object" && value !== null && Object.hasOwn(value, "update") ? value.update : void 0;
|
|
2074
|
+
}
|
|
2075
|
+
function createFunctionsAdminModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2076
|
+
const functionPath = (id) => `/api/v1/functions/${encodePathSegment(id, "function id", errors)}`;
|
|
2077
|
+
const pageParams = (options = {}) => ({
|
|
2078
|
+
page: options.page,
|
|
2079
|
+
size: options.size,
|
|
2080
|
+
sort: options.sort
|
|
2081
|
+
});
|
|
2082
|
+
return {
|
|
2083
|
+
async list(options = {}) {
|
|
2084
|
+
return expectPage(
|
|
2085
|
+
await transport.request("/api/v1/functions", {
|
|
2086
|
+
method: "GET",
|
|
2087
|
+
params: { ...pageParams(options), search: options.search }
|
|
2088
|
+
}),
|
|
2089
|
+
"Function page response",
|
|
2090
|
+
errors,
|
|
2091
|
+
expectFunctionSummary
|
|
2092
|
+
);
|
|
2093
|
+
},
|
|
2094
|
+
async get(id) {
|
|
2095
|
+
return expectFunctionDefinition(
|
|
2096
|
+
await transport.request(functionPath(id), { method: "GET" }),
|
|
2097
|
+
"Function response",
|
|
2098
|
+
errors
|
|
2099
|
+
);
|
|
2100
|
+
},
|
|
2101
|
+
async create(input) {
|
|
2102
|
+
return expectFunctionDefinition(
|
|
2103
|
+
await transport.request("/api/v1/functions", { method: "POST", body: input }),
|
|
2104
|
+
"Create Function response",
|
|
2105
|
+
errors
|
|
2106
|
+
);
|
|
2107
|
+
},
|
|
2108
|
+
async patch(id, input) {
|
|
2109
|
+
return expectFunctionDefinition(
|
|
2110
|
+
await transport.request(functionPath(id), { method: "PATCH", body: input }),
|
|
2111
|
+
"Patch Function response",
|
|
2112
|
+
errors
|
|
2113
|
+
);
|
|
2114
|
+
},
|
|
2115
|
+
async delete(id) {
|
|
2116
|
+
expectEmpty(
|
|
2117
|
+
await transport.request(functionPath(id), { method: "DELETE" }),
|
|
2118
|
+
"Delete Function response",
|
|
2119
|
+
errors
|
|
2120
|
+
);
|
|
2121
|
+
},
|
|
2122
|
+
async bulkCreate(functions) {
|
|
2123
|
+
requireBatchSize(functions, "functions", MAX_FUNCTIONS, errors);
|
|
2124
|
+
functions.forEach((input) => rejectBulkScheduleFields(input, "bulkCreate", errors));
|
|
2125
|
+
return expectFunctionDefinitions(
|
|
2126
|
+
await transport.request("/api/v1/functions/bulk", {
|
|
2127
|
+
method: "POST",
|
|
2128
|
+
body: { functions }
|
|
2129
|
+
}),
|
|
2130
|
+
"Function bulk create response",
|
|
2131
|
+
errors
|
|
2132
|
+
);
|
|
2133
|
+
},
|
|
2134
|
+
async bulkUpdate(functions) {
|
|
2135
|
+
requireBatchSize(functions, "functions", MAX_FUNCTIONS, errors);
|
|
2136
|
+
return expectFunctionDefinitions(
|
|
2137
|
+
await transport.request("/api/v1/functions/bulk", {
|
|
2138
|
+
method: "PUT",
|
|
2139
|
+
body: { functions }
|
|
2140
|
+
}),
|
|
2141
|
+
"Function bulk update response",
|
|
2142
|
+
errors
|
|
2143
|
+
);
|
|
2144
|
+
},
|
|
2145
|
+
async bulkPatch(functions) {
|
|
2146
|
+
requireBatchSize(functions, "functions", MAX_FUNCTIONS, errors);
|
|
2147
|
+
functions.forEach(
|
|
2148
|
+
(item) => rejectBulkScheduleFields(bulkPatchUpdate(item), "bulkPatch", errors)
|
|
2149
|
+
);
|
|
2150
|
+
return expectFunctionDefinitions(
|
|
2151
|
+
await transport.request("/api/v1/functions/bulk", {
|
|
2152
|
+
method: "PATCH",
|
|
2153
|
+
body: { functions }
|
|
2154
|
+
}),
|
|
2155
|
+
"Function bulk patch response",
|
|
2156
|
+
errors
|
|
2157
|
+
);
|
|
2158
|
+
},
|
|
2159
|
+
// POST, not DELETE: the selector travels in a body, and some proxies drop a DELETE body.
|
|
2160
|
+
async bulkDelete(selector) {
|
|
2161
|
+
const body = selectorBody(selector, errors);
|
|
2162
|
+
return expectFunctionBulkDeleteResult(
|
|
2163
|
+
await transport.request("/api/v1/functions/bulk-delete", {
|
|
2164
|
+
method: "POST",
|
|
2165
|
+
body
|
|
2166
|
+
}),
|
|
2167
|
+
"Function bulk delete response",
|
|
2168
|
+
errors
|
|
2169
|
+
);
|
|
2170
|
+
},
|
|
2171
|
+
async publish(id) {
|
|
2172
|
+
return expectFunctionDefinition(
|
|
2173
|
+
await transport.request(`${functionPath(id)}/publish`, { method: "POST" }),
|
|
2174
|
+
"Publish Function response",
|
|
2175
|
+
errors
|
|
2176
|
+
);
|
|
2177
|
+
},
|
|
2178
|
+
async rollback(id, versionId) {
|
|
2179
|
+
return expectFunctionDefinition(
|
|
2180
|
+
await transport.request(`${functionPath(id)}/rollback`, {
|
|
2181
|
+
method: "POST",
|
|
2182
|
+
body: { targetVersionId: versionId }
|
|
2183
|
+
}),
|
|
2184
|
+
"Rollback Function response",
|
|
2185
|
+
errors
|
|
2186
|
+
);
|
|
2187
|
+
},
|
|
2188
|
+
async listVersions(id, options = {}) {
|
|
2189
|
+
return expectPage(
|
|
2190
|
+
await transport.request(`${functionPath(id)}/versions`, {
|
|
2191
|
+
method: "GET",
|
|
2192
|
+
params: pageParams(options)
|
|
2193
|
+
}),
|
|
2194
|
+
"Function version page response",
|
|
2195
|
+
errors,
|
|
2196
|
+
expectFunctionVersionResponse
|
|
2197
|
+
);
|
|
2198
|
+
},
|
|
2199
|
+
async setVisibility(id, visibility) {
|
|
2200
|
+
return expectFunctionDefinition(
|
|
2201
|
+
await transport.request(`${functionPath(id)}/visibility`, {
|
|
2202
|
+
method: "PATCH",
|
|
2203
|
+
body: { visibility }
|
|
2204
|
+
}),
|
|
2205
|
+
"Function visibility response",
|
|
2206
|
+
errors
|
|
2207
|
+
);
|
|
2208
|
+
},
|
|
2209
|
+
async listExecutions(id, options = {}) {
|
|
2210
|
+
return expectPage(
|
|
2211
|
+
await transport.request(`${functionPath(id)}/executions`, {
|
|
2212
|
+
method: "GET",
|
|
2213
|
+
params: pageParams(options)
|
|
2214
|
+
}),
|
|
2215
|
+
"Function execution page response",
|
|
2216
|
+
errors,
|
|
2217
|
+
expectFunctionExecution
|
|
2218
|
+
);
|
|
2219
|
+
},
|
|
2220
|
+
async getExecution(functionId, executionId) {
|
|
2221
|
+
return expectFunctionExecution(
|
|
2222
|
+
await transport.request(
|
|
2223
|
+
`${functionPath(functionId)}/executions/${encodePathSegment(
|
|
2224
|
+
executionId,
|
|
2225
|
+
"execution id",
|
|
2226
|
+
errors
|
|
2227
|
+
)}`,
|
|
2228
|
+
{ method: "GET" }
|
|
2229
|
+
),
|
|
2230
|
+
"Function execution response",
|
|
2231
|
+
errors
|
|
2232
|
+
);
|
|
2233
|
+
},
|
|
2234
|
+
async listSecrets(id) {
|
|
2235
|
+
return expectFunctionSecrets(
|
|
2236
|
+
await transport.request(`${functionPath(id)}/secrets`, { method: "GET" }),
|
|
2237
|
+
"Function secrets response",
|
|
2238
|
+
errors
|
|
2239
|
+
);
|
|
2240
|
+
},
|
|
2241
|
+
async createSecret(id, name, value) {
|
|
2242
|
+
expectEmpty(
|
|
2243
|
+
await transport.request(`${functionPath(id)}/secrets`, {
|
|
2244
|
+
method: "POST",
|
|
2245
|
+
body: { name, value }
|
|
2246
|
+
}),
|
|
2247
|
+
"Create Function secret response",
|
|
2248
|
+
errors
|
|
2249
|
+
);
|
|
2250
|
+
},
|
|
2251
|
+
async deleteSecret(id, name) {
|
|
2252
|
+
expectEmpty(
|
|
2253
|
+
await transport.request(
|
|
2254
|
+
`${functionPath(id)}/secrets/${encodePathSegment(name, "secret name", errors)}`,
|
|
2255
|
+
{ method: "DELETE" }
|
|
2256
|
+
),
|
|
2257
|
+
"Delete Function secret response",
|
|
2258
|
+
errors
|
|
2259
|
+
);
|
|
2260
|
+
}
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
function selectorBody(selector, errors) {
|
|
2264
|
+
const hasIds = selector.ids !== void 0;
|
|
2265
|
+
if (hasIds === (selector.allInApp === true)) {
|
|
2266
|
+
configurationError("Provide either ids or allInApp, not both", errors);
|
|
2267
|
+
}
|
|
2268
|
+
if (selector.ids !== void 0) {
|
|
2269
|
+
requireBatchSize(selector.ids, "ids", MAX_FUNCTIONS, errors);
|
|
2270
|
+
return { ids: selector.ids };
|
|
2271
|
+
}
|
|
2272
|
+
return { allInApp: true };
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
// src/modules/imports.ts
|
|
2276
|
+
function createImportsModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2277
|
+
const path = (id) => `/api/v1/data-imports/${encodePathSegment(id, "import id", errors)}`;
|
|
2278
|
+
const pageParams = (options = {}) => ({
|
|
2279
|
+
page: options.page,
|
|
2280
|
+
size: options.size,
|
|
2281
|
+
sort: options.sort
|
|
2282
|
+
});
|
|
2283
|
+
return {
|
|
2284
|
+
async list(options = {}) {
|
|
2285
|
+
return expectPage(
|
|
2286
|
+
await transport.request("/api/v1/data-imports", {
|
|
2287
|
+
method: "GET",
|
|
2288
|
+
params: pageParams(options)
|
|
2289
|
+
}),
|
|
2290
|
+
"Import page response",
|
|
2291
|
+
errors,
|
|
2292
|
+
expectImportDefinition
|
|
2293
|
+
);
|
|
2294
|
+
},
|
|
2295
|
+
async get(id) {
|
|
2296
|
+
return expectImportDefinition(
|
|
2297
|
+
await transport.request(path(id), { method: "GET" }),
|
|
2298
|
+
"Import response",
|
|
2299
|
+
errors
|
|
2300
|
+
);
|
|
2301
|
+
},
|
|
2302
|
+
async create(input) {
|
|
2303
|
+
return expectImportDefinition(
|
|
2304
|
+
await transport.request("/api/v1/data-imports", { method: "POST", body: input }),
|
|
2305
|
+
"Create import response",
|
|
2306
|
+
errors
|
|
2307
|
+
);
|
|
2308
|
+
},
|
|
2309
|
+
async update(id, input) {
|
|
2310
|
+
return expectImportDefinition(
|
|
2311
|
+
await transport.request(path(id), { method: "PUT", body: input }),
|
|
2312
|
+
"Update import response",
|
|
2313
|
+
errors
|
|
2314
|
+
);
|
|
2315
|
+
},
|
|
2316
|
+
async delete(id) {
|
|
2317
|
+
expectEmpty(
|
|
2318
|
+
await transport.request(path(id), { method: "DELETE" }),
|
|
2319
|
+
"Delete import response",
|
|
2320
|
+
errors
|
|
2321
|
+
);
|
|
2322
|
+
},
|
|
2323
|
+
async execute(id) {
|
|
2324
|
+
return expectImportExecution(
|
|
2325
|
+
await transport.request(`${path(id)}/execute`, { method: "POST" }),
|
|
2326
|
+
"Import execution response",
|
|
2327
|
+
errors
|
|
2328
|
+
);
|
|
2329
|
+
},
|
|
2330
|
+
async listExecutions(options) {
|
|
2331
|
+
return expectPage(
|
|
2332
|
+
await transport.request("/api/v1/data-imports/executions", {
|
|
2333
|
+
method: "GET",
|
|
2334
|
+
params: {
|
|
2335
|
+
definitionId: options.definitionId,
|
|
2336
|
+
page: options.page,
|
|
2337
|
+
size: options.size,
|
|
2338
|
+
sort: options.sort ?? "queuedAt,desc"
|
|
2339
|
+
}
|
|
2340
|
+
}),
|
|
2341
|
+
"Import execution page response",
|
|
2342
|
+
errors,
|
|
2343
|
+
expectImportExecution
|
|
2344
|
+
);
|
|
2345
|
+
},
|
|
2346
|
+
async cancelExecution(executionId) {
|
|
2347
|
+
return expectImportExecution(
|
|
2348
|
+
await transport.request(
|
|
2349
|
+
`/api/v1/data-imports/executions/${encodePathSegment(executionId, "execution id", errors)}/cancel`,
|
|
2350
|
+
{ method: "POST" }
|
|
2351
|
+
),
|
|
2352
|
+
"Cancel import execution response",
|
|
2353
|
+
errors
|
|
2354
|
+
);
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
// src/modules/integration.ts
|
|
366
2360
|
function createIntegrationModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
367
2361
|
return {
|
|
368
2362
|
async executeResource(resourceId, params = {}) {
|
|
@@ -375,13 +2369,356 @@ function createIntegrationModule(transport, errors = defaultSdkCoreErrorFactory)
|
|
|
375
2369
|
errors
|
|
376
2370
|
);
|
|
377
2371
|
},
|
|
378
|
-
async execute(configId, request) {
|
|
379
|
-
return expectProxyResult(
|
|
2372
|
+
async execute(configId, request) {
|
|
2373
|
+
return expectProxyResult(
|
|
2374
|
+
await transport.request(
|
|
2375
|
+
`/api/v1/proxy/template-configs/${encodePathSegment(configId, "config id", errors)}/execute`,
|
|
2376
|
+
{ method: "POST", body: { ...request, source: "SDK" } }
|
|
2377
|
+
),
|
|
2378
|
+
"Integration proxy response",
|
|
2379
|
+
errors
|
|
2380
|
+
);
|
|
2381
|
+
},
|
|
2382
|
+
async executeByAlias(alias, request) {
|
|
2383
|
+
return expectProxyResult(
|
|
2384
|
+
await transport.request(
|
|
2385
|
+
`/api/v1/proxy/template-configs/by-alias/${encodePathSegment(alias, "alias", errors)}/execute`,
|
|
2386
|
+
{ method: "POST", body: { ...request, source: "SDK" } }
|
|
2387
|
+
),
|
|
2388
|
+
"Integration proxy response",
|
|
2389
|
+
errors
|
|
2390
|
+
);
|
|
2391
|
+
}
|
|
2392
|
+
};
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
// src/modules/integrationAdmin.ts
|
|
2396
|
+
var MAX_CONFIGS = 100;
|
|
2397
|
+
function createIntegrationAdminModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2398
|
+
const path = (id) => `/api/v1/template-configs/${encodePathSegment(id, "config id", errors)}`;
|
|
2399
|
+
return {
|
|
2400
|
+
async create(input) {
|
|
2401
|
+
return expectTemplateConfig(
|
|
2402
|
+
await transport.request("/api/v1/template-configs", {
|
|
2403
|
+
method: "POST",
|
|
2404
|
+
body: input
|
|
2405
|
+
}),
|
|
2406
|
+
"Create integration config response",
|
|
2407
|
+
errors
|
|
2408
|
+
);
|
|
2409
|
+
},
|
|
2410
|
+
async update(id, input) {
|
|
2411
|
+
return expectTemplateConfig(
|
|
2412
|
+
await transport.request(path(id), { method: "PUT", body: input }),
|
|
2413
|
+
"Update integration config response",
|
|
2414
|
+
errors
|
|
2415
|
+
);
|
|
2416
|
+
},
|
|
2417
|
+
async delete(id) {
|
|
2418
|
+
expectEmpty(
|
|
2419
|
+
await transport.request(path(id), { method: "DELETE" }),
|
|
2420
|
+
"Delete integration config response",
|
|
2421
|
+
errors
|
|
2422
|
+
);
|
|
2423
|
+
},
|
|
2424
|
+
async bulkCreate(configs) {
|
|
2425
|
+
requireBatchSize(configs, "configs", MAX_CONFIGS, errors);
|
|
2426
|
+
return expectTemplateConfigBulkResult(
|
|
2427
|
+
await transport.request("/api/v1/template-configs/bulk", {
|
|
2428
|
+
method: "POST",
|
|
2429
|
+
body: { configs }
|
|
2430
|
+
}),
|
|
2431
|
+
"Template config bulk create response",
|
|
2432
|
+
errors
|
|
2433
|
+
);
|
|
2434
|
+
},
|
|
2435
|
+
async bulkUpdate(configs) {
|
|
2436
|
+
requireBatchSize(configs, "configs", MAX_CONFIGS, errors);
|
|
2437
|
+
return expectTemplateConfigBulkResult(
|
|
2438
|
+
await transport.request("/api/v1/template-configs/bulk", {
|
|
2439
|
+
method: "PUT",
|
|
2440
|
+
body: { configs }
|
|
2441
|
+
}),
|
|
2442
|
+
"Template config bulk update response",
|
|
2443
|
+
errors
|
|
2444
|
+
);
|
|
2445
|
+
},
|
|
2446
|
+
// POST, not DELETE: the id list travels in a body, and some proxies drop a DELETE body.
|
|
2447
|
+
async bulkDelete(configIds) {
|
|
2448
|
+
requireBatchSize(configIds, "configIds", MAX_CONFIGS, errors);
|
|
2449
|
+
return expectTemplateConfigBulkResult(
|
|
2450
|
+
await transport.request("/api/v1/template-configs/bulk-delete", {
|
|
2451
|
+
method: "POST",
|
|
2452
|
+
body: { configIds }
|
|
2453
|
+
}),
|
|
2454
|
+
"Template config bulk delete response",
|
|
2455
|
+
errors
|
|
2456
|
+
);
|
|
2457
|
+
},
|
|
2458
|
+
async testCredentials(request) {
|
|
2459
|
+
return expectConnectionTestResult(
|
|
2460
|
+
await transport.request("/api/v1/template-configs/test", {
|
|
2461
|
+
method: "POST",
|
|
2462
|
+
body: request
|
|
2463
|
+
}),
|
|
2464
|
+
"Integration credentials test response",
|
|
2465
|
+
errors
|
|
2466
|
+
);
|
|
2467
|
+
},
|
|
2468
|
+
async testConfig(configId) {
|
|
2469
|
+
return expectConnectionTestResult(
|
|
2470
|
+
await transport.request(`${path(configId)}/test`, { method: "POST" }),
|
|
2471
|
+
"Integration config test response",
|
|
2472
|
+
errors
|
|
2473
|
+
);
|
|
2474
|
+
},
|
|
2475
|
+
async list(options = {}) {
|
|
2476
|
+
const params = {
|
|
2477
|
+
page: options.page,
|
|
2478
|
+
size: options.size,
|
|
2479
|
+
sort: options.sort
|
|
2480
|
+
};
|
|
2481
|
+
return expectTemplateConfigPage(
|
|
2482
|
+
await transport.request("/api/v1/template-configs", { method: "GET", params }),
|
|
2483
|
+
"Template config page response",
|
|
2484
|
+
errors
|
|
2485
|
+
);
|
|
2486
|
+
},
|
|
2487
|
+
async listExecutions(configId, options = {}) {
|
|
2488
|
+
return expectLegacyPage(
|
|
2489
|
+
await transport.request(`${path(configId)}/executions`, {
|
|
2490
|
+
method: "GET",
|
|
2491
|
+
params: {
|
|
2492
|
+
page: options.page,
|
|
2493
|
+
size: options.size,
|
|
2494
|
+
sort: options.sort ?? "createdAt,desc"
|
|
2495
|
+
}
|
|
2496
|
+
}),
|
|
2497
|
+
"Integration execution page response",
|
|
2498
|
+
errors,
|
|
2499
|
+
expectIntegrationExecution
|
|
2500
|
+
);
|
|
2501
|
+
},
|
|
2502
|
+
async getExecution(configId, executionId) {
|
|
2503
|
+
return expectIntegrationExecution(
|
|
2504
|
+
await transport.request(
|
|
2505
|
+
`${path(configId)}/executions/${encodePathSegment(executionId, "execution id", errors)}`,
|
|
2506
|
+
{ method: "GET" }
|
|
2507
|
+
),
|
|
2508
|
+
"Integration execution response",
|
|
2509
|
+
errors
|
|
2510
|
+
);
|
|
2511
|
+
}
|
|
2512
|
+
};
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
// src/modules/integrationResources.ts
|
|
2516
|
+
function createIntegrationResourcesModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2517
|
+
const path = (id) => `/api/v1/integration-resources/${encodePathSegment(id, "resource id", errors)}`;
|
|
2518
|
+
return {
|
|
2519
|
+
async list(options = {}) {
|
|
2520
|
+
const params = {
|
|
2521
|
+
page: options.page,
|
|
2522
|
+
size: options.size,
|
|
2523
|
+
sort: options.sort
|
|
2524
|
+
};
|
|
2525
|
+
return expectLegacyPage(
|
|
2526
|
+
await transport.request("/api/v1/integration-resources", {
|
|
2527
|
+
method: "GET",
|
|
2528
|
+
params
|
|
2529
|
+
}),
|
|
2530
|
+
"Integration resource page response",
|
|
2531
|
+
errors,
|
|
2532
|
+
expectIntegrationResourceSummary
|
|
2533
|
+
);
|
|
2534
|
+
},
|
|
2535
|
+
async get(id) {
|
|
2536
|
+
return expectIntegrationResource(
|
|
2537
|
+
await transport.request(path(id), { method: "GET" }),
|
|
2538
|
+
"Integration resource response",
|
|
2539
|
+
errors
|
|
2540
|
+
);
|
|
2541
|
+
},
|
|
2542
|
+
async create(input) {
|
|
2543
|
+
return expectIntegrationResource(
|
|
2544
|
+
await transport.request("/api/v1/integration-resources", {
|
|
2545
|
+
method: "POST",
|
|
2546
|
+
body: input
|
|
2547
|
+
}),
|
|
2548
|
+
"Create integration resource response",
|
|
2549
|
+
errors
|
|
2550
|
+
);
|
|
2551
|
+
},
|
|
2552
|
+
async update(id, input) {
|
|
2553
|
+
return expectIntegrationResource(
|
|
2554
|
+
await transport.request(path(id), { method: "PUT", body: input }),
|
|
2555
|
+
"Update integration resource response",
|
|
2556
|
+
errors
|
|
2557
|
+
);
|
|
2558
|
+
},
|
|
2559
|
+
async delete(id) {
|
|
2560
|
+
expectEmpty(
|
|
2561
|
+
await transport.request(path(id), { method: "DELETE" }),
|
|
2562
|
+
"Delete integration resource response",
|
|
2563
|
+
errors
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
// src/modules/integrationTemplates.ts
|
|
2570
|
+
function createIntegrationTemplatesModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2571
|
+
const params = (options = {}, sort) => ({
|
|
2572
|
+
page: options.page,
|
|
2573
|
+
size: options.size ?? 20,
|
|
2574
|
+
sort: options.sort ?? sort
|
|
2575
|
+
});
|
|
2576
|
+
return {
|
|
2577
|
+
async list(options = {}) {
|
|
2578
|
+
return expectLegacyPage(
|
|
2579
|
+
await transport.request("/api/v1/templates", {
|
|
2580
|
+
method: "GET",
|
|
2581
|
+
params: params(options, "name")
|
|
2582
|
+
}),
|
|
2583
|
+
"Integration template page response",
|
|
2584
|
+
errors,
|
|
2585
|
+
expectIntegrationTemplateSummary
|
|
2586
|
+
);
|
|
2587
|
+
},
|
|
2588
|
+
async get(id) {
|
|
2589
|
+
return expectIntegrationTemplate(
|
|
2590
|
+
await transport.request(
|
|
2591
|
+
`/api/v1/templates/${encodePathSegment(id, "template id", errors)}`,
|
|
2592
|
+
{ method: "GET" }
|
|
2593
|
+
),
|
|
2594
|
+
"Integration template response",
|
|
2595
|
+
errors
|
|
2596
|
+
);
|
|
2597
|
+
},
|
|
2598
|
+
async listConfigs(options = {}) {
|
|
2599
|
+
return expectLegacyPage(
|
|
2600
|
+
await transport.request("/api/v1/template-configs", {
|
|
2601
|
+
method: "GET",
|
|
2602
|
+
params: params(options, "alias")
|
|
2603
|
+
}),
|
|
2604
|
+
"Integration config page response",
|
|
2605
|
+
errors,
|
|
2606
|
+
expectTemplateConfigSummary
|
|
2607
|
+
);
|
|
2608
|
+
},
|
|
2609
|
+
async getConfig(id) {
|
|
2610
|
+
return expectTemplateConfig(
|
|
2611
|
+
await transport.request(
|
|
2612
|
+
`/api/v1/template-configs/${encodePathSegment(id, "config id", errors)}`,
|
|
2613
|
+
{ method: "GET" }
|
|
2614
|
+
),
|
|
2615
|
+
"Integration config response",
|
|
2616
|
+
errors
|
|
2617
|
+
);
|
|
2618
|
+
}
|
|
2619
|
+
};
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
// src/modules/members.ts
|
|
2623
|
+
var MAX_APP_USERS = 100;
|
|
2624
|
+
function createMembersModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2625
|
+
const path = (appId) => `/api/v1/apps/${encodePathSegment(appId, "app id", errors)}/users`;
|
|
2626
|
+
return {
|
|
2627
|
+
async list() {
|
|
2628
|
+
return expectAppMembers(
|
|
2629
|
+
await transport.request("/api/v1/members/current-app", { method: "GET" }),
|
|
2630
|
+
"App members response",
|
|
2631
|
+
errors
|
|
2632
|
+
);
|
|
2633
|
+
},
|
|
2634
|
+
async invite(appId, input) {
|
|
2635
|
+
expectEmpty(
|
|
2636
|
+
await transport.request(path(appId), { method: "POST", body: input }),
|
|
2637
|
+
"Invite app user response",
|
|
2638
|
+
errors
|
|
2639
|
+
);
|
|
2640
|
+
},
|
|
2641
|
+
async unsubscribe(appId, userId) {
|
|
2642
|
+
expectEmpty(
|
|
380
2643
|
await transport.request(
|
|
381
|
-
|
|
382
|
-
{ method: "
|
|
2644
|
+
`${path(appId)}/${encodePathSegment(userId, "user id", errors)}`,
|
|
2645
|
+
{ method: "DELETE" }
|
|
383
2646
|
),
|
|
384
|
-
"
|
|
2647
|
+
"Unsubscribe app user response",
|
|
2648
|
+
errors
|
|
2649
|
+
);
|
|
2650
|
+
},
|
|
2651
|
+
async bulkInvite(appId, users) {
|
|
2652
|
+
requireBatchSize(users, "users", MAX_APP_USERS, errors);
|
|
2653
|
+
expectEmpty(
|
|
2654
|
+
await transport.request(`${path(appId)}/bulk`, {
|
|
2655
|
+
method: "POST",
|
|
2656
|
+
body: { users }
|
|
2657
|
+
}),
|
|
2658
|
+
"Bulk invite app users response",
|
|
2659
|
+
errors
|
|
2660
|
+
);
|
|
2661
|
+
},
|
|
2662
|
+
async bulkUnsubscribe(appId, userIds) {
|
|
2663
|
+
requireBatchSize(userIds, "userIds", MAX_APP_USERS, errors);
|
|
2664
|
+
return expectBulkUnsubscribeResult(
|
|
2665
|
+
await transport.request(`${path(appId)}/bulk-unsubscribe`, {
|
|
2666
|
+
method: "POST",
|
|
2667
|
+
body: { userIds }
|
|
2668
|
+
}),
|
|
2669
|
+
"Bulk unsubscribe app users response",
|
|
2670
|
+
errors
|
|
2671
|
+
);
|
|
2672
|
+
}
|
|
2673
|
+
};
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
// src/modules/messenger.ts
|
|
2677
|
+
function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2678
|
+
return {
|
|
2679
|
+
async notify(content) {
|
|
2680
|
+
return expectMessageAccepted(
|
|
2681
|
+
await transport.request("/api/v1/messages/notify", {
|
|
2682
|
+
method: "POST",
|
|
2683
|
+
body: { content }
|
|
2684
|
+
}),
|
|
2685
|
+
"Notify user response",
|
|
2686
|
+
errors
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
// src/modules/publicFunctions.ts
|
|
2693
|
+
function createPublicFunctionsModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2694
|
+
const execute = async (id, input, mode) => {
|
|
2695
|
+
if (!transport) {
|
|
2696
|
+
configurationError(
|
|
2697
|
+
"A separate publicFunctions transport is required so anonymous requests do not inherit authorization headers",
|
|
2698
|
+
errors
|
|
2699
|
+
);
|
|
2700
|
+
}
|
|
2701
|
+
return transport.request(
|
|
2702
|
+
`/public/v1/functions/${encodePathSegment(id, "function id", errors)}/execute`,
|
|
2703
|
+
{
|
|
2704
|
+
method: "POST",
|
|
2705
|
+
headers: { "X-Invocation-Type": mode },
|
|
2706
|
+
body: { input: input ?? {} }
|
|
2707
|
+
}
|
|
2708
|
+
);
|
|
2709
|
+
};
|
|
2710
|
+
return {
|
|
2711
|
+
async execute(id, input) {
|
|
2712
|
+
return expectPublicFunctionResult(
|
|
2713
|
+
await execute(id, input, "sync"),
|
|
2714
|
+
"Public Function execution response",
|
|
2715
|
+
errors
|
|
2716
|
+
);
|
|
2717
|
+
},
|
|
2718
|
+
async executeAsync(id, input) {
|
|
2719
|
+
return expectPublicFunctionAsyncResult(
|
|
2720
|
+
await execute(id, input, "async"),
|
|
2721
|
+
"Public async Function execution response",
|
|
385
2722
|
errors
|
|
386
2723
|
);
|
|
387
2724
|
}
|
|
@@ -389,22 +2726,15 @@ function createIntegrationModule(transport, errors = defaultSdkCoreErrorFactory)
|
|
|
389
2726
|
}
|
|
390
2727
|
|
|
391
2728
|
// src/modules/queries.ts
|
|
392
|
-
function createQueriesModule(transport,
|
|
2729
|
+
function createQueriesModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
393
2730
|
return {
|
|
394
2731
|
async execute(id, parameters = {}) {
|
|
395
|
-
const dataSourceId = getDataSourceId();
|
|
396
|
-
if (!dataSourceId) {
|
|
397
|
-
configurationError(
|
|
398
|
-
"A dataSourceId is required for queries. Call client.init() first or configure dataSourceId.",
|
|
399
|
-
errors
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
2732
|
return expectQueryResult(
|
|
403
2733
|
await transport.request(
|
|
404
2734
|
`/api/v1/custom-queries/${encodePathSegment(id, "query id", errors)}/execute`,
|
|
405
2735
|
{
|
|
406
2736
|
method: "POST",
|
|
407
|
-
body: {
|
|
2737
|
+
body: { parameters }
|
|
408
2738
|
}
|
|
409
2739
|
),
|
|
410
2740
|
"Query execution response",
|
|
@@ -414,30 +2744,975 @@ function createQueriesModule(transport, getDataSourceId, errors = defaultSdkCore
|
|
|
414
2744
|
};
|
|
415
2745
|
}
|
|
416
2746
|
|
|
2747
|
+
// src/modules/schema.ts
|
|
2748
|
+
function createSchemaModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2749
|
+
const tablePath = (name) => `/api/v1/tables/${encodePathSegment(name, "table name", errors)}`;
|
|
2750
|
+
const list = async (options = {}) => {
|
|
2751
|
+
const params = {
|
|
2752
|
+
scope: options.scope,
|
|
2753
|
+
includeColumns: options.includeColumns
|
|
2754
|
+
};
|
|
2755
|
+
return expectSchemaTables(
|
|
2756
|
+
await transport.request("/api/v1/tables", { method: "GET", params }),
|
|
2757
|
+
"Schema tables response",
|
|
2758
|
+
errors
|
|
2759
|
+
);
|
|
2760
|
+
};
|
|
2761
|
+
return {
|
|
2762
|
+
async createTable(tableName, columns) {
|
|
2763
|
+
expectEmpty(
|
|
2764
|
+
await transport.request("/api/v1/tables", {
|
|
2765
|
+
method: "POST",
|
|
2766
|
+
body: { tableName, columns }
|
|
2767
|
+
}),
|
|
2768
|
+
"Create table response",
|
|
2769
|
+
errors
|
|
2770
|
+
);
|
|
2771
|
+
},
|
|
2772
|
+
listTables: list,
|
|
2773
|
+
listAppTables(options = {}) {
|
|
2774
|
+
return list({
|
|
2775
|
+
scope: "APP",
|
|
2776
|
+
...options.includeColumns === void 0 ? {} : { includeColumns: options.includeColumns }
|
|
2777
|
+
});
|
|
2778
|
+
},
|
|
2779
|
+
async getTable(tableName) {
|
|
2780
|
+
return expectTableDefinition(
|
|
2781
|
+
await transport.request(tablePath(tableName), { method: "GET" }),
|
|
2782
|
+
"Table details response",
|
|
2783
|
+
errors
|
|
2784
|
+
);
|
|
2785
|
+
},
|
|
2786
|
+
async dropTable(tableName) {
|
|
2787
|
+
expectEmpty(
|
|
2788
|
+
await transport.request(tablePath(tableName), { method: "DELETE" }),
|
|
2789
|
+
"Drop table response",
|
|
2790
|
+
errors
|
|
2791
|
+
);
|
|
2792
|
+
},
|
|
2793
|
+
async truncateTable(tableName) {
|
|
2794
|
+
expectEmpty(
|
|
2795
|
+
await transport.request(`${tablePath(tableName)}/truncate`, { method: "POST" }),
|
|
2796
|
+
"Truncate table response",
|
|
2797
|
+
errors
|
|
2798
|
+
);
|
|
2799
|
+
},
|
|
2800
|
+
async addColumn(tableName, column) {
|
|
2801
|
+
expectEmpty(
|
|
2802
|
+
await transport.request(`${tablePath(tableName)}/columns`, {
|
|
2803
|
+
method: "POST",
|
|
2804
|
+
body: column
|
|
2805
|
+
}),
|
|
2806
|
+
"Add column response",
|
|
2807
|
+
errors
|
|
2808
|
+
);
|
|
2809
|
+
},
|
|
2810
|
+
async dropColumn(tableName, columnName) {
|
|
2811
|
+
expectEmpty(
|
|
2812
|
+
await transport.request(
|
|
2813
|
+
`${tablePath(tableName)}/columns/${encodePathSegment(columnName, "column name", errors)}`,
|
|
2814
|
+
{ method: "DELETE" }
|
|
2815
|
+
),
|
|
2816
|
+
"Drop column response",
|
|
2817
|
+
errors
|
|
2818
|
+
);
|
|
2819
|
+
}
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
// src/modules/sql.ts
|
|
2824
|
+
var MAX_STATEMENTS = 20;
|
|
2825
|
+
function createSqlModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2826
|
+
return {
|
|
2827
|
+
async executeQuery(sql, parameters = {}) {
|
|
2828
|
+
return expectQueryResult(
|
|
2829
|
+
await transport.request("/api/v1/sql/execute", {
|
|
2830
|
+
method: "POST",
|
|
2831
|
+
body: { sql, parameters }
|
|
2832
|
+
}),
|
|
2833
|
+
"SQL execution response",
|
|
2834
|
+
errors
|
|
2835
|
+
);
|
|
2836
|
+
},
|
|
2837
|
+
async executeDdl(statements) {
|
|
2838
|
+
requireBatchSize(statements, "statements", MAX_STATEMENTS, errors);
|
|
2839
|
+
return expectBatchExecution(
|
|
2840
|
+
await transport.request("/api/v1/sql/ddl/execute", {
|
|
2841
|
+
method: "POST",
|
|
2842
|
+
body: { statements }
|
|
2843
|
+
}),
|
|
2844
|
+
"DDL batch response",
|
|
2845
|
+
errors
|
|
2846
|
+
);
|
|
2847
|
+
},
|
|
2848
|
+
async executeDml(statements) {
|
|
2849
|
+
requireBatchSize(statements, "statements", MAX_STATEMENTS, errors);
|
|
2850
|
+
return expectBatchExecution(
|
|
2851
|
+
await transport.request("/api/v1/sql/dml/execute", {
|
|
2852
|
+
method: "POST",
|
|
2853
|
+
body: { statements }
|
|
2854
|
+
}),
|
|
2855
|
+
"DML batch response",
|
|
2856
|
+
errors
|
|
2857
|
+
);
|
|
2858
|
+
},
|
|
2859
|
+
async listTables(options = {}) {
|
|
2860
|
+
const params = {
|
|
2861
|
+
scope: options.scope,
|
|
2862
|
+
includeColumns: options.includeColumns
|
|
2863
|
+
};
|
|
2864
|
+
return expectSchemaTables(
|
|
2865
|
+
await transport.request("/api/v1/tables", { method: "GET", params }),
|
|
2866
|
+
"Schema tables response",
|
|
2867
|
+
errors
|
|
2868
|
+
);
|
|
2869
|
+
}
|
|
2870
|
+
};
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2873
|
+
// src/modules/workflows.ts
|
|
2874
|
+
function createWorkflowsModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2875
|
+
const path = (id) => `/api/v1/workflows/${encodePathSegment(id, "workflow id", errors)}`;
|
|
2876
|
+
const params = (options = {}) => ({
|
|
2877
|
+
page: options.page,
|
|
2878
|
+
size: options.size,
|
|
2879
|
+
sort: options.sort
|
|
2880
|
+
});
|
|
2881
|
+
const executionPath = (workflowId, executionId) => `${path(workflowId)}/executions${executionId === void 0 ? "" : `/${encodePathSegment(executionId, "workflow execution id", errors)}`}`;
|
|
2882
|
+
return {
|
|
2883
|
+
async list(options = {}) {
|
|
2884
|
+
return expectPage(
|
|
2885
|
+
await transport.request("/api/v1/workflows", {
|
|
2886
|
+
method: "GET",
|
|
2887
|
+
params: params(options)
|
|
2888
|
+
}),
|
|
2889
|
+
"Workflow page response",
|
|
2890
|
+
errors,
|
|
2891
|
+
expectWorkflowSummary
|
|
2892
|
+
);
|
|
2893
|
+
},
|
|
2894
|
+
async get(id) {
|
|
2895
|
+
return expectWorkflowDefinition(
|
|
2896
|
+
await transport.request(path(id), { method: "GET" }),
|
|
2897
|
+
"Workflow response",
|
|
2898
|
+
errors
|
|
2899
|
+
);
|
|
2900
|
+
},
|
|
2901
|
+
async create(input) {
|
|
2902
|
+
return expectWorkflowDefinition(
|
|
2903
|
+
await transport.request("/api/v1/workflows", {
|
|
2904
|
+
method: "POST",
|
|
2905
|
+
body: input
|
|
2906
|
+
}),
|
|
2907
|
+
"Create workflow response",
|
|
2908
|
+
errors
|
|
2909
|
+
);
|
|
2910
|
+
},
|
|
2911
|
+
async update(id, input) {
|
|
2912
|
+
return expectWorkflowDefinition(
|
|
2913
|
+
await transport.request(path(id), { method: "PUT", body: input }),
|
|
2914
|
+
"Update workflow response",
|
|
2915
|
+
errors
|
|
2916
|
+
);
|
|
2917
|
+
},
|
|
2918
|
+
async delete(id) {
|
|
2919
|
+
expectEmpty(
|
|
2920
|
+
await transport.request(path(id), { method: "DELETE" }),
|
|
2921
|
+
"Delete workflow response",
|
|
2922
|
+
errors
|
|
2923
|
+
);
|
|
2924
|
+
},
|
|
2925
|
+
async execute(id, input = {}) {
|
|
2926
|
+
return expectWorkflowExecution(
|
|
2927
|
+
await transport.request(`${path(id)}/execute`, {
|
|
2928
|
+
method: "POST",
|
|
2929
|
+
body: { input }
|
|
2930
|
+
}),
|
|
2931
|
+
"Workflow execution response",
|
|
2932
|
+
errors
|
|
2933
|
+
);
|
|
2934
|
+
},
|
|
2935
|
+
async listExecutions(workflowId, options = {}) {
|
|
2936
|
+
return expectPage(
|
|
2937
|
+
await transport.request(executionPath(workflowId), {
|
|
2938
|
+
method: "GET",
|
|
2939
|
+
params: params(options)
|
|
2940
|
+
}),
|
|
2941
|
+
"Workflow execution page response",
|
|
2942
|
+
errors,
|
|
2943
|
+
expectWorkflowExecution
|
|
2944
|
+
);
|
|
2945
|
+
},
|
|
2946
|
+
async getExecution(workflowId, executionId) {
|
|
2947
|
+
return expectWorkflowExecution(
|
|
2948
|
+
await transport.request(executionPath(workflowId, executionId), { method: "GET" }),
|
|
2949
|
+
"Workflow execution response",
|
|
2950
|
+
errors
|
|
2951
|
+
);
|
|
2952
|
+
},
|
|
2953
|
+
async cancelExecution(workflowId, executionId) {
|
|
2954
|
+
expectEmpty(
|
|
2955
|
+
await transport.request(`${executionPath(workflowId, executionId)}/cancel`, {
|
|
2956
|
+
method: "POST"
|
|
2957
|
+
}),
|
|
2958
|
+
"Cancel workflow execution response",
|
|
2959
|
+
errors
|
|
2960
|
+
);
|
|
2961
|
+
}
|
|
2962
|
+
};
|
|
2963
|
+
}
|
|
2964
|
+
|
|
417
2965
|
// src/core.ts
|
|
418
2966
|
function createSdkCore(options) {
|
|
419
2967
|
const errors = options.errors ?? defaultSdkCoreErrorFactory;
|
|
2968
|
+
const codeStudio = options.transports.codeStudio ?? unavailableTransport("codeStudio", errors);
|
|
2969
|
+
const copilot = options.transports.copilot ?? unavailableTransport("copilot", errors);
|
|
2970
|
+
const messengerTransport = options.transports.messenger ?? unavailableTransport("messenger", errors);
|
|
2971
|
+
const apps = createAppsModule(codeStudio, errors);
|
|
2972
|
+
const schema = createSchemaModule(options.transports.dataManager, errors);
|
|
2973
|
+
const functionsAdmin = createFunctionsAdminModule(options.transports.functions, errors);
|
|
2974
|
+
const agents = createAgentsModule(options.transports.functions, copilot, errors);
|
|
2975
|
+
const integrationAdmin = createIntegrationAdminModule(options.transports.integration, errors);
|
|
2976
|
+
const agentConnections = createAgentConnectionsModule(copilot, errors);
|
|
2977
|
+
const members = createMembersModule(options.transports.auth, errors);
|
|
420
2978
|
return {
|
|
2979
|
+
agentConnections,
|
|
2980
|
+
agentCredentials: createAgentCredentialsModule(copilot, errors),
|
|
2981
|
+
agents,
|
|
2982
|
+
agentTasks: createAgentTasksModule(copilot, errors),
|
|
2983
|
+
apps,
|
|
421
2984
|
auth: createAuthModule(options.transports.auth, errors),
|
|
2985
|
+
context: createContextModule(
|
|
2986
|
+
{
|
|
2987
|
+
apps,
|
|
2988
|
+
schema,
|
|
2989
|
+
functionsAdmin,
|
|
2990
|
+
agents,
|
|
2991
|
+
integrationAdmin,
|
|
2992
|
+
agentConnections,
|
|
2993
|
+
getAppId: options.getAppId
|
|
2994
|
+
},
|
|
2995
|
+
errors
|
|
2996
|
+
),
|
|
2997
|
+
customQueries: createCustomQueriesModule(options.transports.dataManager, errors),
|
|
2998
|
+
dataSources: createDataSourcesModule(options.transports.dataManager, errors),
|
|
422
2999
|
entities: createEntitiesModule(options.transports.dataManager, errors),
|
|
423
3000
|
functions: createFunctionsModule(options.transports.functions, options.functions, errors),
|
|
3001
|
+
functionsAdmin,
|
|
3002
|
+
imports: createImportsModule(options.transports.dataManager, errors),
|
|
424
3003
|
integration: createIntegrationModule(options.transports.integration, errors),
|
|
425
|
-
|
|
3004
|
+
integrationAdmin,
|
|
3005
|
+
integrationResources: createIntegrationResourcesModule(options.transports.integration, errors),
|
|
3006
|
+
integrationTemplates: createIntegrationTemplatesModule(options.transports.integration, errors),
|
|
3007
|
+
members,
|
|
3008
|
+
messenger: createMessengerModule(messengerTransport, errors),
|
|
3009
|
+
publicFunctions: createPublicFunctionsModule(options.transports.publicFunctions, errors),
|
|
3010
|
+
queries: createQueriesModule(options.transports.dataManager, errors),
|
|
3011
|
+
sql: createSqlModule(options.transports.dataManager, errors),
|
|
3012
|
+
schema,
|
|
3013
|
+
workflows: createWorkflowsModule(options.transports.functions, errors)
|
|
3014
|
+
};
|
|
3015
|
+
}
|
|
3016
|
+
function unavailableTransport(name, errors) {
|
|
3017
|
+
return {
|
|
3018
|
+
request() {
|
|
3019
|
+
return Promise.reject(errors.configuration(`The ${name} transport is not configured`));
|
|
3020
|
+
}
|
|
3021
|
+
};
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
// src/agentSession.ts
|
|
3025
|
+
var AGENT_QUEUE_LIMIT = 10;
|
|
3026
|
+
var CANCEL_SAFETY_MS = 1e4;
|
|
3027
|
+
var RECONCILE_DELAY_MS = 1e3;
|
|
3028
|
+
var AgentTaskTurnError = class extends Error {
|
|
3029
|
+
code;
|
|
3030
|
+
constructor(message, code) {
|
|
3031
|
+
super(message);
|
|
3032
|
+
this.name = "AgentTaskTurnError";
|
|
3033
|
+
this.code = code;
|
|
3034
|
+
}
|
|
3035
|
+
};
|
|
3036
|
+
function asObject(value) {
|
|
3037
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3038
|
+
}
|
|
3039
|
+
function errorMessage(error) {
|
|
3040
|
+
if (error instanceof Error) return error.message;
|
|
3041
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
3042
|
+
return String(error.message);
|
|
3043
|
+
}
|
|
3044
|
+
return String(error);
|
|
3045
|
+
}
|
|
3046
|
+
function errorCode(error) {
|
|
3047
|
+
if (!error || typeof error !== "object") return void 0;
|
|
3048
|
+
const candidate = error;
|
|
3049
|
+
const code = candidate.code ?? candidate.details?.code ?? candidate.details?.error_code;
|
|
3050
|
+
return typeof code === "string" ? code : void 0;
|
|
3051
|
+
}
|
|
3052
|
+
function delay(milliseconds) {
|
|
3053
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
3054
|
+
}
|
|
3055
|
+
function toAgentTimelineItem(message) {
|
|
3056
|
+
if (message.type === "TOOL_USE") {
|
|
3057
|
+
try {
|
|
3058
|
+
const payload = JSON.parse(message.content);
|
|
3059
|
+
if (payload && typeof payload === "object") {
|
|
3060
|
+
return {
|
|
3061
|
+
id: message.id,
|
|
3062
|
+
kind: "tool",
|
|
3063
|
+
tool: {
|
|
3064
|
+
tool: typeof payload.name === "string" ? payload.name : "",
|
|
3065
|
+
...typeof payload.toolId === "string" ? { toolId: payload.toolId } : {},
|
|
3066
|
+
...payload.input !== void 0 ? { input: payload.input } : {},
|
|
3067
|
+
...payload.content !== void 0 ? { content: payload.content } : payload.output !== void 0 ? { content: payload.output } : {},
|
|
3068
|
+
phase: payload.output !== void 0 || payload.content !== void 0 ? "result" : "call"
|
|
3069
|
+
},
|
|
3070
|
+
at: message.createdAt
|
|
3071
|
+
};
|
|
3072
|
+
}
|
|
3073
|
+
} catch {
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
return {
|
|
3077
|
+
id: message.id,
|
|
3078
|
+
kind: message.sender === "USER" ? "user" : "agent",
|
|
3079
|
+
text: message.content,
|
|
3080
|
+
at: message.createdAt
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3083
|
+
function createAgentTaskSessionManager(options) {
|
|
3084
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
3085
|
+
return {
|
|
3086
|
+
session(sessionOptions) {
|
|
3087
|
+
if ("taskId" in sessionOptions) {
|
|
3088
|
+
const current = sessions.get(sessionOptions.taskId);
|
|
3089
|
+
if (current && current.status !== "closed") return current;
|
|
3090
|
+
}
|
|
3091
|
+
const session = new CoreAgentTaskSession(sessionOptions, {
|
|
3092
|
+
...options,
|
|
3093
|
+
onTaskId: (taskId, value) => sessions.set(taskId, value),
|
|
3094
|
+
onClose: (taskId, value) => {
|
|
3095
|
+
if (sessions.get(taskId) === value) sessions.delete(taskId);
|
|
3096
|
+
}
|
|
3097
|
+
});
|
|
3098
|
+
if ("taskId" in sessionOptions) sessions.set(sessionOptions.taskId, session);
|
|
3099
|
+
return session;
|
|
3100
|
+
}
|
|
426
3101
|
};
|
|
427
3102
|
}
|
|
3103
|
+
function withAgentTaskSessions(tasks, manager) {
|
|
3104
|
+
return { ...tasks, session: (options) => manager.session(options) };
|
|
3105
|
+
}
|
|
3106
|
+
var CoreAgentTaskSession = class {
|
|
3107
|
+
constructor(options, dependencies) {
|
|
3108
|
+
this.options = options;
|
|
3109
|
+
this.dependencies = dependencies;
|
|
3110
|
+
this.isNewSession = "create" in options;
|
|
3111
|
+
if ("taskId" in options) {
|
|
3112
|
+
this._taskId = options.taskId;
|
|
3113
|
+
this.openingPromise = this.openExisting();
|
|
3114
|
+
} else {
|
|
3115
|
+
this._status = "idle";
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
_taskId = null;
|
|
3119
|
+
_task = null;
|
|
3120
|
+
_status = "opening";
|
|
3121
|
+
_history = [];
|
|
3122
|
+
_content = "";
|
|
3123
|
+
_queue = [];
|
|
3124
|
+
isNewSession;
|
|
3125
|
+
listeners = /* @__PURE__ */ new Map();
|
|
3126
|
+
connection = null;
|
|
3127
|
+
connectionAbort = null;
|
|
3128
|
+
connectionPromise = null;
|
|
3129
|
+
openingPromise = null;
|
|
3130
|
+
createPromise = null;
|
|
3131
|
+
dispatching = false;
|
|
3132
|
+
recoveryUsed = false;
|
|
3133
|
+
recoveryPromise = null;
|
|
3134
|
+
recoveryGeneration = 0;
|
|
3135
|
+
recoveredTerminalReason;
|
|
3136
|
+
cancelTimer = null;
|
|
3137
|
+
queueSequence = 0;
|
|
3138
|
+
activeWaiter;
|
|
3139
|
+
turnBaselineIds = /* @__PURE__ */ new Set();
|
|
3140
|
+
get taskId() {
|
|
3141
|
+
return this._taskId;
|
|
3142
|
+
}
|
|
3143
|
+
get task() {
|
|
3144
|
+
return this._task;
|
|
3145
|
+
}
|
|
3146
|
+
get isNew() {
|
|
3147
|
+
return this.isNewSession;
|
|
3148
|
+
}
|
|
3149
|
+
get status() {
|
|
3150
|
+
return this._status;
|
|
3151
|
+
}
|
|
3152
|
+
get history() {
|
|
3153
|
+
return [...this._history];
|
|
3154
|
+
}
|
|
3155
|
+
get content() {
|
|
3156
|
+
return this._content;
|
|
3157
|
+
}
|
|
3158
|
+
get queue() {
|
|
3159
|
+
return this._queue.map((item) => ({
|
|
3160
|
+
id: item.id,
|
|
3161
|
+
text: item.text,
|
|
3162
|
+
createdAt: item.createdAt,
|
|
3163
|
+
...item.agentType ? { agentType: item.agentType } : {},
|
|
3164
|
+
...item.reasoningEffort ? { reasoningEffort: item.reasoningEffort } : {}
|
|
3165
|
+
}));
|
|
3166
|
+
}
|
|
3167
|
+
send(prompt, options = {}) {
|
|
3168
|
+
this.requireOpen();
|
|
3169
|
+
if (!prompt.trim()) return;
|
|
3170
|
+
if (this.isBusy()) {
|
|
3171
|
+
this.enqueue(prompt, options);
|
|
3172
|
+
return;
|
|
3173
|
+
}
|
|
3174
|
+
this.startDispatch(prompt, options);
|
|
3175
|
+
}
|
|
3176
|
+
sendAndWait(prompt, options = {}) {
|
|
3177
|
+
this.requireOpen();
|
|
3178
|
+
if (!prompt.trim()) return Promise.reject(new Error("Agent prompt must not be blank."));
|
|
3179
|
+
const waiter = this.createWaiter(options);
|
|
3180
|
+
if (waiter.settled) return waiter.promise;
|
|
3181
|
+
const sendOptions = {
|
|
3182
|
+
...options.agentType ? { agentType: options.agentType } : {},
|
|
3183
|
+
...options.reasoningEffort ? { reasoningEffort: options.reasoningEffort } : {}
|
|
3184
|
+
};
|
|
3185
|
+
if (this.isBusy()) {
|
|
3186
|
+
const queueId = this.enqueue(prompt, sendOptions, waiter);
|
|
3187
|
+
if (queueId) waiter.queueId = queueId;
|
|
3188
|
+
return waiter.promise;
|
|
3189
|
+
}
|
|
3190
|
+
this.startDispatch(prompt, sendOptions, waiter);
|
|
3191
|
+
return waiter.promise;
|
|
3192
|
+
}
|
|
3193
|
+
async cancel() {
|
|
3194
|
+
if (this._status !== "streaming" && this._status !== "cancelled") return;
|
|
3195
|
+
try {
|
|
3196
|
+
await this.sendInput({ type: "interrupt" });
|
|
3197
|
+
this.setStatus("cancelled");
|
|
3198
|
+
this.emit("cancelled", {});
|
|
3199
|
+
if (this.cancelTimer) clearTimeout(this.cancelTimer);
|
|
3200
|
+
this.cancelTimer = setTimeout(() => {
|
|
3201
|
+
this.cancelTimer = null;
|
|
3202
|
+
if (this._status === "cancelled") {
|
|
3203
|
+
const error = new AgentTaskTurnError(
|
|
3204
|
+
"Agent turn cancellation was not acknowledged before the safety timeout."
|
|
3205
|
+
);
|
|
3206
|
+
this.emit("error", { error: error.message });
|
|
3207
|
+
this.failTurn(error);
|
|
3208
|
+
}
|
|
3209
|
+
}, CANCEL_SAFETY_MS);
|
|
3210
|
+
} catch (error) {
|
|
3211
|
+
this.emitError("Failed to cancel Agent task", error);
|
|
3212
|
+
throw error;
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
respondApproval(approved) {
|
|
3216
|
+
void this.sendInput({ type: "approval_response", approved }).catch((error) => {
|
|
3217
|
+
this.emitError("Failed to answer Agent approval", error);
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
async loadHistory(options = {}) {
|
|
3221
|
+
if (!this._taskId) return [];
|
|
3222
|
+
const page = await this.dependencies.tasks.listMessages(this._taskId, {
|
|
3223
|
+
...options.limit !== void 0 ? { size: options.limit } : {},
|
|
3224
|
+
sort: "createdAt,desc"
|
|
3225
|
+
});
|
|
3226
|
+
this._history = [...page.content].reverse().map(toAgentTimelineItem);
|
|
3227
|
+
const history = this.history;
|
|
3228
|
+
this.emit("historyLoaded", { history });
|
|
3229
|
+
return history;
|
|
3230
|
+
}
|
|
3231
|
+
editQueueItem(id, text) {
|
|
3232
|
+
if (!text.trim()) {
|
|
3233
|
+
this.removeQueueItem(id);
|
|
3234
|
+
return;
|
|
3235
|
+
}
|
|
3236
|
+
this._queue = this._queue.map((item) => item.id === id ? { ...item, text } : item);
|
|
3237
|
+
this.emitQueue();
|
|
3238
|
+
}
|
|
3239
|
+
removeQueueItem(id) {
|
|
3240
|
+
const removed = this._queue.find((item) => item.id === id);
|
|
3241
|
+
this._queue = this._queue.filter((item) => item.id !== id);
|
|
3242
|
+
removed?.waiter?.reject(new Error("Queued Agent prompt was removed."));
|
|
3243
|
+
this.emitQueue();
|
|
3244
|
+
}
|
|
3245
|
+
clearQueue() {
|
|
3246
|
+
if (!this._queue.length) return;
|
|
3247
|
+
const removed = this._queue;
|
|
3248
|
+
this._queue = [];
|
|
3249
|
+
for (const item of removed) item.waiter?.reject(new Error("Agent prompt queue was cleared."));
|
|
3250
|
+
this.emitQueue();
|
|
3251
|
+
}
|
|
3252
|
+
on(event, handler) {
|
|
3253
|
+
let listeners = this.listeners.get(event);
|
|
3254
|
+
if (!listeners) {
|
|
3255
|
+
listeners = /* @__PURE__ */ new Set();
|
|
3256
|
+
this.listeners.set(event, listeners);
|
|
3257
|
+
}
|
|
3258
|
+
const callback = handler;
|
|
3259
|
+
listeners.add(callback);
|
|
3260
|
+
return () => listeners?.delete(callback);
|
|
3261
|
+
}
|
|
3262
|
+
close() {
|
|
3263
|
+
if (this._status === "closed") return;
|
|
3264
|
+
this.setStatus("closed");
|
|
3265
|
+
if (this.cancelTimer) clearTimeout(this.cancelTimer);
|
|
3266
|
+
this.cancelTimer = null;
|
|
3267
|
+
this.connectionAbort?.abort();
|
|
3268
|
+
this.connectionAbort = null;
|
|
3269
|
+
this.connection?.close();
|
|
3270
|
+
this.connection = null;
|
|
3271
|
+
this.recoveryGeneration += 1;
|
|
3272
|
+
const closedError = new Error("Agent task session is closed.");
|
|
3273
|
+
this.activeWaiter?.reject(closedError);
|
|
3274
|
+
this.activeWaiter = void 0;
|
|
3275
|
+
for (const item of this._queue) item.waiter?.reject(closedError);
|
|
3276
|
+
this._queue = [];
|
|
3277
|
+
if (this._taskId) this.dependencies.onClose(this._taskId, this);
|
|
3278
|
+
for (const listeners of this.listeners.values()) listeners.clear();
|
|
3279
|
+
}
|
|
3280
|
+
async openExisting() {
|
|
3281
|
+
try {
|
|
3282
|
+
this._task = await this.dependencies.tasks.get(this._taskId);
|
|
3283
|
+
if (this.isClosed()) return false;
|
|
3284
|
+
await this.loadHistory();
|
|
3285
|
+
if (this.isClosed()) return false;
|
|
3286
|
+
await this.ensureChannel();
|
|
3287
|
+
if (this.isClosed()) return false;
|
|
3288
|
+
this.setStatus("idle");
|
|
3289
|
+
return true;
|
|
3290
|
+
} catch (error) {
|
|
3291
|
+
if (this.isClosed()) return false;
|
|
3292
|
+
this.emitError("Failed to open Agent task", error);
|
|
3293
|
+
this.setStatus("error");
|
|
3294
|
+
return false;
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
startDispatch(prompt, options, waiter) {
|
|
3298
|
+
this.dispatching = true;
|
|
3299
|
+
void this.dispatchSend(prompt, options, waiter).catch((error) => {
|
|
3300
|
+
waiter?.reject(error);
|
|
3301
|
+
this.emitError("Failed to send Agent prompt", error);
|
|
3302
|
+
if (this._status === "streaming") this.setStatus("idle");
|
|
3303
|
+
this.flushQueue();
|
|
3304
|
+
}).finally(() => {
|
|
3305
|
+
this.dispatching = false;
|
|
3306
|
+
if (this._status === "idle") this.flushQueue();
|
|
3307
|
+
});
|
|
3308
|
+
}
|
|
3309
|
+
async dispatchSend(prompt, options, waiter) {
|
|
3310
|
+
if (this.openingPromise && !await this.openingPromise) {
|
|
3311
|
+
throw new Error("Agent task session could not be opened.");
|
|
3312
|
+
}
|
|
3313
|
+
if (this.isClosed() || waiter?.settled) return;
|
|
3314
|
+
await this.ensureTask();
|
|
3315
|
+
if (this.isClosed() || waiter?.settled) return;
|
|
3316
|
+
await this.ensureChannel();
|
|
3317
|
+
if (this.isClosed() || waiter?.settled) return;
|
|
3318
|
+
await this.captureTurnBaseline();
|
|
3319
|
+
this._content = "";
|
|
3320
|
+
this.recoveryUsed = false;
|
|
3321
|
+
this.recoveredTerminalReason = void 0;
|
|
3322
|
+
this.recoveryGeneration += 1;
|
|
3323
|
+
this.activeWaiter = waiter;
|
|
3324
|
+
this.setStatus("streaming");
|
|
3325
|
+
this.emit("turnStart", {});
|
|
3326
|
+
await this.sendInput({
|
|
3327
|
+
type: "message",
|
|
3328
|
+
content: prompt,
|
|
3329
|
+
...options.agentType ? { agentType: options.agentType } : {},
|
|
3330
|
+
...options.reasoningEffort ? { reasoningEffort: options.reasoningEffort } : {}
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
async ensureTask() {
|
|
3334
|
+
if (this._taskId) return;
|
|
3335
|
+
if (!("create" in this.options)) throw new Error("Agent task session has no task.");
|
|
3336
|
+
const createOptions = this.options;
|
|
3337
|
+
if (this.createPromise) return this.createPromise;
|
|
3338
|
+
this.createPromise = (async () => {
|
|
3339
|
+
const task = await this.dependencies.tasks.create({
|
|
3340
|
+
agentType: createOptions.agentType,
|
|
3341
|
+
...createOptions.title ? { title: createOptions.title } : {},
|
|
3342
|
+
...createOptions.agentId ? { agentId: createOptions.agentId } : {},
|
|
3343
|
+
...createOptions.reasoningEffort ? { reasoningEffort: createOptions.reasoningEffort } : {},
|
|
3344
|
+
...createOptions.userId ? { userId: createOptions.userId } : {}
|
|
3345
|
+
});
|
|
3346
|
+
this._task = task;
|
|
3347
|
+
this._taskId = task.id;
|
|
3348
|
+
this.dependencies.onTaskId(task.id, this);
|
|
3349
|
+
this.emit("taskCreated", { task });
|
|
3350
|
+
})().finally(() => {
|
|
3351
|
+
this.createPromise = null;
|
|
3352
|
+
});
|
|
3353
|
+
return this.createPromise;
|
|
3354
|
+
}
|
|
3355
|
+
ensureChannel() {
|
|
3356
|
+
if (this.connection) return Promise.resolve();
|
|
3357
|
+
if (this.connectionPromise) return this.connectionPromise;
|
|
3358
|
+
if (!this._taskId) return Promise.reject(new Error("Agent task has not been created."));
|
|
3359
|
+
const abort = new AbortController();
|
|
3360
|
+
this.connectionAbort = abort;
|
|
3361
|
+
this.connectionPromise = this.dependencies.eventSource.open(
|
|
3362
|
+
this._taskId,
|
|
3363
|
+
{
|
|
3364
|
+
onEvent: (event) => this.handleEvent(event),
|
|
3365
|
+
onDisconnect: (error) => this.handleDisconnect(error)
|
|
3366
|
+
},
|
|
3367
|
+
abort.signal,
|
|
3368
|
+
this.options.transport
|
|
3369
|
+
).then((connection) => {
|
|
3370
|
+
if (this.isClosed() || this._status === "error") {
|
|
3371
|
+
connection.close();
|
|
3372
|
+
return;
|
|
3373
|
+
}
|
|
3374
|
+
this.connection = connection;
|
|
3375
|
+
}).finally(() => {
|
|
3376
|
+
this.connectionPromise = null;
|
|
3377
|
+
});
|
|
3378
|
+
return this.connectionPromise;
|
|
3379
|
+
}
|
|
3380
|
+
handleDisconnect(error) {
|
|
3381
|
+
this.connection = null;
|
|
3382
|
+
this.connectionAbort = null;
|
|
3383
|
+
if (this.isClosed()) return;
|
|
3384
|
+
if (this._status !== "streaming" && this._status !== "cancelled") return;
|
|
3385
|
+
if (this.recoveryUsed) {
|
|
3386
|
+
const disconnectError = new Error("Agent live channel disconnected after one recovery.");
|
|
3387
|
+
this.failLiveChannel(error ?? disconnectError, disconnectError);
|
|
3388
|
+
return;
|
|
3389
|
+
}
|
|
3390
|
+
this.recoveryUsed = true;
|
|
3391
|
+
const generation = ++this.recoveryGeneration;
|
|
3392
|
+
this.recoveryPromise = this.recoverTurn(generation).finally(() => {
|
|
3393
|
+
this.recoveryPromise = null;
|
|
3394
|
+
});
|
|
3395
|
+
}
|
|
3396
|
+
async recoverTurn(generation) {
|
|
3397
|
+
try {
|
|
3398
|
+
await this.ensureChannel();
|
|
3399
|
+
while (generation === this.recoveryGeneration && !this.isClosed() && (this._status === "streaming" || this._status === "cancelled")) {
|
|
3400
|
+
if (await this.reconcilePersistedTurn(this.recoveredTerminalReason ?? "reconciled")) {
|
|
3401
|
+
return;
|
|
3402
|
+
}
|
|
3403
|
+
if (this.activeWaiter?.settled) return;
|
|
3404
|
+
await delay(RECONCILE_DELAY_MS);
|
|
3405
|
+
}
|
|
3406
|
+
} catch (error) {
|
|
3407
|
+
if (this.isClosed()) return;
|
|
3408
|
+
const recoveryError = error instanceof Error ? error : new Error(errorMessage(error));
|
|
3409
|
+
this.failLiveChannel(error, recoveryError);
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
async captureTurnBaseline() {
|
|
3413
|
+
if (!this._taskId) return;
|
|
3414
|
+
const page = await this.dependencies.tasks.listMessages(this._taskId, {
|
|
3415
|
+
size: 100,
|
|
3416
|
+
sort: "createdAt,desc"
|
|
3417
|
+
});
|
|
3418
|
+
this.turnBaselineIds = new Set(page.content.map((message) => message.id));
|
|
3419
|
+
}
|
|
3420
|
+
async reconcilePersistedTurn(reason) {
|
|
3421
|
+
if (!this._taskId) return false;
|
|
3422
|
+
const page = await this.dependencies.tasks.listMessages(this._taskId, {
|
|
3423
|
+
size: 100,
|
|
3424
|
+
sort: "createdAt,desc"
|
|
3425
|
+
});
|
|
3426
|
+
this._history = [...page.content].reverse().map(toAgentTimelineItem);
|
|
3427
|
+
this.emit("historyLoaded", { history: this.history });
|
|
3428
|
+
const recovered = page.content.find(
|
|
3429
|
+
(message) => !this.turnBaselineIds.has(message.id) && message.sender !== "USER" && message.type !== "TOOL_USE"
|
|
3430
|
+
);
|
|
3431
|
+
if (!recovered) return false;
|
|
3432
|
+
if (recovered.type === "ERROR") {
|
|
3433
|
+
const error = new AgentTaskTurnError(recovered.content);
|
|
3434
|
+
this.emit("error", { error: error.message });
|
|
3435
|
+
this.failTurn(error);
|
|
3436
|
+
return true;
|
|
3437
|
+
}
|
|
3438
|
+
this._content = recovered.content;
|
|
3439
|
+
this.finishTurn(reason);
|
|
3440
|
+
return true;
|
|
3441
|
+
}
|
|
3442
|
+
sendInput(input) {
|
|
3443
|
+
if (!this._taskId) return Promise.reject(new Error("Agent task has not been created."));
|
|
3444
|
+
return this.dependencies.tasks.sendInput(this._taskId, input);
|
|
3445
|
+
}
|
|
3446
|
+
handleEvent(event) {
|
|
3447
|
+
this.emit("raw", event);
|
|
3448
|
+
const payload = asObject(event.payload);
|
|
3449
|
+
switch (event.type) {
|
|
3450
|
+
case "textDelta":
|
|
3451
|
+
this.consumeDelta(payload, "text");
|
|
3452
|
+
break;
|
|
3453
|
+
case "thinking":
|
|
3454
|
+
this.consumeDelta(payload, "thinking");
|
|
3455
|
+
break;
|
|
3456
|
+
case "toolCall":
|
|
3457
|
+
this.emitTool(payload, "call", event.timestamp);
|
|
3458
|
+
break;
|
|
3459
|
+
case "toolResult":
|
|
3460
|
+
this.emitTool(payload, "result", event.timestamp);
|
|
3461
|
+
break;
|
|
3462
|
+
case "workspace":
|
|
3463
|
+
this.emit("workspace", { payload: event.payload, timestamp: event.timestamp });
|
|
3464
|
+
break;
|
|
3465
|
+
case "stepFinish": {
|
|
3466
|
+
const reason = typeof payload?.reason === "string" ? payload.reason : "unknown";
|
|
3467
|
+
if (reason === "stop" || reason === "endTurn") {
|
|
3468
|
+
if (this.recoveryUsed) {
|
|
3469
|
+
this.recoveredTerminalReason = reason;
|
|
3470
|
+
if (!this.recoveryPromise) {
|
|
3471
|
+
const generation = this.recoveryGeneration;
|
|
3472
|
+
this.recoveryPromise = this.recoverTurn(generation).finally(() => {
|
|
3473
|
+
this.recoveryPromise = null;
|
|
3474
|
+
});
|
|
3475
|
+
}
|
|
3476
|
+
} else {
|
|
3477
|
+
this.finishTurn(reason);
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
break;
|
|
3481
|
+
}
|
|
3482
|
+
case "error": {
|
|
3483
|
+
const code = typeof payload?.code === "string" ? payload.code : void 0;
|
|
3484
|
+
const message = typeof payload?.message === "string" ? payload.message : "Agent returned an error.";
|
|
3485
|
+
this.emit("error", { ...code ? { code } : {}, error: message });
|
|
3486
|
+
if (this._status === "streaming" || this._status === "cancelled") {
|
|
3487
|
+
this.failTurn(new AgentTaskTurnError(message, code));
|
|
3488
|
+
}
|
|
3489
|
+
break;
|
|
3490
|
+
}
|
|
3491
|
+
default:
|
|
3492
|
+
break;
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
consumeDelta(payload, kind) {
|
|
3496
|
+
const text = typeof payload?.text === "string" ? payload.text : "";
|
|
3497
|
+
if (this._status !== "streaming" && this._status !== "cancelled") {
|
|
3498
|
+
this.setStatus("streaming");
|
|
3499
|
+
this.emit("turnStart", {});
|
|
3500
|
+
}
|
|
3501
|
+
if (kind === "text") this._content += text;
|
|
3502
|
+
this.emit("delta", { delta: text, kind });
|
|
3503
|
+
}
|
|
3504
|
+
emitTool(payload, phase, timestamp) {
|
|
3505
|
+
this.emit("tool", {
|
|
3506
|
+
tool: typeof payload?.name === "string" ? payload.name : "",
|
|
3507
|
+
phase,
|
|
3508
|
+
timestamp,
|
|
3509
|
+
...typeof payload?.toolId === "string" ? { toolId: payload.toolId } : {},
|
|
3510
|
+
...phase === "call" && payload?.input !== void 0 ? { input: payload.input } : {},
|
|
3511
|
+
...phase === "result" ? { content: payload?.content ?? payload?.output } : {}
|
|
3512
|
+
});
|
|
3513
|
+
}
|
|
3514
|
+
finishTurn(reason) {
|
|
3515
|
+
if (this._status !== "streaming" && this._status !== "cancelled") return;
|
|
3516
|
+
if (this.cancelTimer) clearTimeout(this.cancelTimer);
|
|
3517
|
+
this.cancelTimer = null;
|
|
3518
|
+
this.recoveryGeneration += 1;
|
|
3519
|
+
const task = this._task;
|
|
3520
|
+
if (!task) {
|
|
3521
|
+
const error = new Error("Agent turn ended before task metadata was available.");
|
|
3522
|
+
this.activeWaiter?.reject(error);
|
|
3523
|
+
this.activeWaiter = void 0;
|
|
3524
|
+
this.emitError("Failed to finish Agent turn", error);
|
|
3525
|
+
this.setStatus("error");
|
|
3526
|
+
return;
|
|
3527
|
+
}
|
|
3528
|
+
const result = { task, content: this._content, reason };
|
|
3529
|
+
this.emit("turnEnd", result);
|
|
3530
|
+
this.activeWaiter?.resolve(result);
|
|
3531
|
+
this.activeWaiter = void 0;
|
|
3532
|
+
this.setStatus("idle");
|
|
3533
|
+
this.flushQueue();
|
|
3534
|
+
}
|
|
3535
|
+
failTurn(error) {
|
|
3536
|
+
if (this.cancelTimer) clearTimeout(this.cancelTimer);
|
|
3537
|
+
this.cancelTimer = null;
|
|
3538
|
+
this.recoveryGeneration += 1;
|
|
3539
|
+
this.activeWaiter?.reject(error);
|
|
3540
|
+
this.activeWaiter = void 0;
|
|
3541
|
+
this.setStatus("idle");
|
|
3542
|
+
this.flushQueue();
|
|
3543
|
+
}
|
|
3544
|
+
failLiveChannel(observed, waiterError) {
|
|
3545
|
+
this.recoveryGeneration += 1;
|
|
3546
|
+
this.emitError("Agent live channel failed", observed);
|
|
3547
|
+
this.activeWaiter?.reject(waiterError);
|
|
3548
|
+
this.activeWaiter = void 0;
|
|
3549
|
+
for (const item of this._queue) item.waiter?.reject(waiterError);
|
|
3550
|
+
this._queue = [];
|
|
3551
|
+
this.emitQueue();
|
|
3552
|
+
this.setStatus("error");
|
|
3553
|
+
}
|
|
3554
|
+
enqueue(text, options, waiter) {
|
|
3555
|
+
if (this._queue.length >= AGENT_QUEUE_LIMIT) {
|
|
3556
|
+
const error = new Error(`Agent message queue is full (maximum ${AGENT_QUEUE_LIMIT}).`);
|
|
3557
|
+
waiter?.reject(error);
|
|
3558
|
+
this.emit("error", { error: error.message });
|
|
3559
|
+
return void 0;
|
|
3560
|
+
}
|
|
3561
|
+
const id = `q-${++this.queueSequence}`;
|
|
3562
|
+
this._queue = [
|
|
3563
|
+
...this._queue,
|
|
3564
|
+
{ id, text, createdAt: Date.now(), ...options, ...waiter ? { waiter } : {} }
|
|
3565
|
+
];
|
|
3566
|
+
this.emitQueue();
|
|
3567
|
+
return id;
|
|
3568
|
+
}
|
|
3569
|
+
flushQueue() {
|
|
3570
|
+
if (this.isBusy()) return;
|
|
3571
|
+
let next = this._queue[0];
|
|
3572
|
+
while (next?.waiter?.settled) {
|
|
3573
|
+
this._queue = this._queue.slice(1);
|
|
3574
|
+
next = this._queue[0];
|
|
3575
|
+
}
|
|
3576
|
+
if (!next) {
|
|
3577
|
+
this.emitQueue();
|
|
3578
|
+
return;
|
|
3579
|
+
}
|
|
3580
|
+
this._queue = this._queue.slice(1);
|
|
3581
|
+
this.emitQueue();
|
|
3582
|
+
this.startDispatch(
|
|
3583
|
+
next.text,
|
|
3584
|
+
{
|
|
3585
|
+
...next.agentType ? { agentType: next.agentType } : {},
|
|
3586
|
+
...next.reasoningEffort ? { reasoningEffort: next.reasoningEffort } : {}
|
|
3587
|
+
},
|
|
3588
|
+
next.waiter
|
|
3589
|
+
);
|
|
3590
|
+
}
|
|
3591
|
+
createWaiter(options) {
|
|
3592
|
+
let resolvePromise;
|
|
3593
|
+
let rejectPromise;
|
|
3594
|
+
let timer;
|
|
3595
|
+
let abortListener;
|
|
3596
|
+
const waiter = {
|
|
3597
|
+
promise: new Promise((resolve, reject) => {
|
|
3598
|
+
resolvePromise = resolve;
|
|
3599
|
+
rejectPromise = reject;
|
|
3600
|
+
}),
|
|
3601
|
+
settled: false,
|
|
3602
|
+
resolve: (result) => {
|
|
3603
|
+
if (waiter.settled) return;
|
|
3604
|
+
waiter.settled = true;
|
|
3605
|
+
waiter.cleanup();
|
|
3606
|
+
resolvePromise(result);
|
|
3607
|
+
},
|
|
3608
|
+
reject: (error) => {
|
|
3609
|
+
if (waiter.settled) return;
|
|
3610
|
+
waiter.settled = true;
|
|
3611
|
+
waiter.cleanup();
|
|
3612
|
+
if (waiter.queueId) this.removeQueuedWaiter(waiter.queueId);
|
|
3613
|
+
rejectPromise(error);
|
|
3614
|
+
},
|
|
3615
|
+
cleanup: () => {
|
|
3616
|
+
if (timer) clearTimeout(timer);
|
|
3617
|
+
if (abortListener) options.signal?.removeEventListener("abort", abortListener);
|
|
3618
|
+
}
|
|
3619
|
+
};
|
|
3620
|
+
if (options.timeoutMs !== void 0) {
|
|
3621
|
+
if (!Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0) {
|
|
3622
|
+
waiter.reject(new Error("Agent turn timeoutMs must be a positive number."));
|
|
3623
|
+
return waiter;
|
|
3624
|
+
}
|
|
3625
|
+
timer = setTimeout(
|
|
3626
|
+
() => waiter.reject(new Error(`Agent turn timed out after ${options.timeoutMs} ms.`)),
|
|
3627
|
+
options.timeoutMs
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
if (options.signal) {
|
|
3631
|
+
abortListener = () => waiter.reject(options.signal?.reason ?? new Error("Agent turn aborted."));
|
|
3632
|
+
if (options.signal.aborted) abortListener();
|
|
3633
|
+
else options.signal.addEventListener("abort", abortListener, { once: true });
|
|
3634
|
+
}
|
|
3635
|
+
return waiter;
|
|
3636
|
+
}
|
|
3637
|
+
removeQueuedWaiter(id) {
|
|
3638
|
+
const size = this._queue.length;
|
|
3639
|
+
this._queue = this._queue.filter((item) => item.id !== id);
|
|
3640
|
+
if (this._queue.length !== size) this.emitQueue();
|
|
3641
|
+
}
|
|
3642
|
+
emitQueue() {
|
|
3643
|
+
this.emit("queueChange", { queue: this.queue });
|
|
3644
|
+
}
|
|
3645
|
+
emitError(prefix, error) {
|
|
3646
|
+
const code = errorCode(error);
|
|
3647
|
+
this.emit("error", {
|
|
3648
|
+
...code ? { code } : {},
|
|
3649
|
+
error: `${prefix}: ${errorMessage(error)}`
|
|
3650
|
+
});
|
|
3651
|
+
}
|
|
3652
|
+
setStatus(status) {
|
|
3653
|
+
if (this._status === status) return;
|
|
3654
|
+
this._status = status;
|
|
3655
|
+
this.emit("statusChange", { status });
|
|
3656
|
+
}
|
|
3657
|
+
requireOpen() {
|
|
3658
|
+
if (this.isClosed()) throw new Error("Agent task session is closed.");
|
|
3659
|
+
}
|
|
3660
|
+
isClosed() {
|
|
3661
|
+
return this._status === "closed";
|
|
3662
|
+
}
|
|
3663
|
+
isBusy() {
|
|
3664
|
+
return this.dispatching || this._status === "streaming" || this._status === "cancelled";
|
|
3665
|
+
}
|
|
3666
|
+
emit(event, payload) {
|
|
3667
|
+
const listeners = this.listeners.get(event);
|
|
3668
|
+
for (const listener of listeners ?? []) {
|
|
3669
|
+
try {
|
|
3670
|
+
listener(payload);
|
|
3671
|
+
} catch {
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
};
|
|
428
3676
|
// Annotate the CommonJS export names for ESM import in node:
|
|
429
3677
|
0 && (module.exports = {
|
|
3678
|
+
AgentTaskTurnError,
|
|
430
3679
|
SdkCoreConfigurationError,
|
|
431
3680
|
SdkCoreResponseError,
|
|
3681
|
+
createAgentConnectionsModule,
|
|
3682
|
+
createAgentCredentialsModule,
|
|
3683
|
+
createAgentTaskSessionManager,
|
|
3684
|
+
createAgentTasksModule,
|
|
3685
|
+
createAgentsModule,
|
|
3686
|
+
createAppsModule,
|
|
432
3687
|
createAuthModule,
|
|
3688
|
+
createContextModule,
|
|
3689
|
+
createCustomQueriesModule,
|
|
3690
|
+
createDataSourcesModule,
|
|
433
3691
|
createEntitiesModule,
|
|
3692
|
+
createFunctionsAdminModule,
|
|
434
3693
|
createFunctionsModule,
|
|
3694
|
+
createImportsModule,
|
|
3695
|
+
createIntegrationAdminModule,
|
|
435
3696
|
createIntegrationModule,
|
|
3697
|
+
createIntegrationResourcesModule,
|
|
3698
|
+
createIntegrationTemplatesModule,
|
|
3699
|
+
createMembersModule,
|
|
3700
|
+
createMessengerModule,
|
|
3701
|
+
createPublicFunctionsModule,
|
|
436
3702
|
createQueriesModule,
|
|
3703
|
+
createSchemaModule,
|
|
437
3704
|
createSdkCore,
|
|
3705
|
+
createSqlModule,
|
|
3706
|
+
createWorkflowsModule,
|
|
438
3707
|
defaultSdkCoreErrorFactory,
|
|
439
3708
|
encodePathSegment,
|
|
440
3709
|
expectEmpty,
|
|
3710
|
+
expectLegacyPage,
|
|
3711
|
+
expectNullableObject,
|
|
441
3712
|
expectObject,
|
|
442
|
-
expectObjectArray
|
|
3713
|
+
expectObjectArray,
|
|
3714
|
+
expectPage,
|
|
3715
|
+
expectStringArray,
|
|
3716
|
+
toAgentTimelineItem,
|
|
3717
|
+
withAgentTaskSessions
|
|
443
3718
|
});
|