@gravity-rail/sdk 0.18.0 → 0.21.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.
Files changed (39) hide show
  1. package/dist/{chunk-MP5ENP4Q.js → chunk-24L4RD4Z.js} +560 -136
  2. package/dist/chunk-24L4RD4Z.js.map +1 -0
  3. package/dist/{chunk-2YLKG4TT.js → chunk-3HAV5XUJ.js} +1 -1
  4. package/dist/chunk-3HAV5XUJ.js.map +1 -0
  5. package/dist/{chunk-PJFEGUHM.js → chunk-7OLBLLV7.js} +6 -2
  6. package/dist/{chunk-PJFEGUHM.js.map → chunk-7OLBLLV7.js.map} +1 -1
  7. package/dist/{client-B51HZ6zY.d.cts → client-B0eh2BEY.d.cts} +1592 -364
  8. package/dist/{client-G5i59XtT.d.ts → client-CFz-BGmY.d.ts} +1592 -364
  9. package/dist/helpers.cjs +141 -0
  10. package/dist/helpers.cjs.map +1 -1
  11. package/dist/helpers.d.cts +17 -3
  12. package/dist/helpers.d.ts +17 -3
  13. package/dist/helpers.js +127 -1
  14. package/dist/helpers.js.map +1 -1
  15. package/dist/index.cjs +658 -129
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +28 -5
  18. package/dist/index.d.ts +28 -5
  19. package/dist/index.js +123 -11
  20. package/dist/index.js.map +1 -1
  21. package/dist/internal.cjs +581 -140
  22. package/dist/internal.cjs.map +1 -1
  23. package/dist/internal.d.cts +724 -553
  24. package/dist/internal.d.ts +724 -553
  25. package/dist/internal.js +23 -13
  26. package/dist/internal.js.map +1 -1
  27. package/dist/{revision-state-Cc7RAf8A.d.ts → revision-state-KfOztBkY.d.ts} +147 -232
  28. package/dist/{revision-state-DudSCwea.d.cts → revision-state-fJ9PM15N.d.cts} +147 -232
  29. package/dist/schemas.cjs +32 -18
  30. package/dist/schemas.cjs.map +1 -1
  31. package/dist/schemas.d.cts +37 -35
  32. package/dist/schemas.d.ts +37 -35
  33. package/dist/schemas.js +32 -18
  34. package/dist/schemas.js.map +1 -1
  35. package/dist/{tasks-1JXJJuG8.d.cts → tasks-WH_VfzMv.d.cts} +351 -20
  36. package/dist/{tasks-1JXJJuG8.d.ts → tasks-WH_VfzMv.d.ts} +351 -20
  37. package/package.json +6 -6
  38. package/dist/chunk-2YLKG4TT.js.map +0 -1
  39. package/dist/chunk-MP5ENP4Q.js.map +0 -1
package/dist/index.js CHANGED
@@ -72,7 +72,6 @@ import {
72
72
  REALTIME_MODEL_CUSTOM,
73
73
  REALTIME_MODEL_GEMINI,
74
74
  REALTIME_MODEL_GEMINI_VERTEX,
75
- REALTIME_MODEL_NOVA_SONIC,
76
75
  REALTIME_MODEL_OPENAI,
77
76
  REALTIME_MODEL_OPENAI_2,
78
77
  REALTIME_MODEL_OPENAI_MINI,
@@ -118,8 +117,6 @@ import {
118
117
  formatAppContextAsMarkdown,
119
118
  getAllFeatures,
120
119
  getAllResourceSlugs,
121
- getApplicableResourceSlugs,
122
- getApplicableResources,
123
120
  getAvailableFeaturesForUpgrade,
124
121
  getFeature,
125
122
  getFeaturesByCategory,
@@ -127,7 +124,6 @@ import {
127
124
  getMissingDependencies,
128
125
  getResourceMetadata,
129
126
  getRevisionState,
130
- getScopeFromProductType,
131
127
  getTTSProvider,
132
128
  getVoiceModelId,
133
129
  initializeFeatures,
@@ -146,7 +142,7 @@ import {
146
142
  roleWorkflowAccess,
147
143
  usesBuiltinAssistant,
148
144
  validateFeatureDependencies
149
- } from "./chunk-MP5ENP4Q.js";
145
+ } from "./chunk-24L4RD4Z.js";
150
146
  import {
151
147
  AttendeeResponseStatus,
152
148
  AttendeeStatus,
@@ -161,13 +157,13 @@ import {
161
157
  DataSensitivity,
162
158
  DataTypeRecordScope,
163
159
  IndexStatus
164
- } from "./chunk-2YLKG4TT.js";
160
+ } from "./chunk-3HAV5XUJ.js";
165
161
  import {
166
162
  ApiError,
167
163
  BaseApiClient,
168
164
  getCookieValue,
169
165
  parseOrgAuthChallenge
170
- } from "./chunk-PJFEGUHM.js";
166
+ } from "./chunk-7OLBLLV7.js";
171
167
 
172
168
  // src/workspace-builder/resource.ts
173
169
  function isRecord(value) {
@@ -318,6 +314,7 @@ var RoutineBuilder = class extends WorkspaceBuilderResource {
318
314
  return `Routine: ${this.name} (${parts.join(", ")})`;
319
315
  }
320
316
  async apply(client) {
317
+ if (this._existed) return;
321
318
  const eventRules = this.rules.map((rule) => {
322
319
  const actionParams = { ...rule.actionParams };
323
320
  if (rule.workflow?._id !== void 0) actionParams.workflowId = rule.workflow._id;
@@ -373,6 +370,7 @@ var NotificationRuleBuilder = class extends WorkspaceBuilderResource {
373
370
  return `NotificationRule: ${this.name}${parts.length ? ` (${parts.join(", ")})` : ""}`;
374
371
  }
375
372
  async apply(client) {
373
+ if (this._existed) return;
376
374
  if (this.memberId === void 0) {
377
375
  throw new Error(`Notification rule '${this.name}' requires memberId`);
378
376
  }
@@ -907,6 +905,7 @@ var RoleUpdate = class extends WorkspaceBuilderResource {
907
905
  return `RoleUpdate: roleId=${this.roleId}${parts.length ? ` (${parts.join(", ")})` : ""}`;
908
906
  }
909
907
  async apply(client) {
908
+ if (this._existed) return;
910
909
  const payload = {};
911
910
  if (this.workflowIds) payload.workflowIds = this.workflowIds;
912
911
  if (this.dataTypeIds) payload.dataTypeIds = this.dataTypeIds;
@@ -1136,6 +1135,7 @@ var AgentBuilder = class extends WorkspaceBuilderResource {
1136
1135
  return `Agent: ${this.name}${parts.length ? ` (${parts.join(", ")})` : ""}`;
1137
1136
  }
1138
1137
  async apply(client) {
1138
+ if (this._existed) return;
1139
1139
  if (this.memberRoleId === void 0) {
1140
1140
  throw new Error(`Agent '${this.name}' requires memberRoleId`);
1141
1141
  }
@@ -1171,6 +1171,25 @@ var PHASES = /* @__PURE__ */ new Map([
1171
1171
  [JourneyBuilder, 7],
1172
1172
  [JourneyStepBuilder, 8]
1173
1173
  ]);
1174
+ var LIST_PAGE_SIZE = 100;
1175
+ async function collectPages(fetchPage) {
1176
+ const first = await fetchPage(1);
1177
+ const all = [...first.items];
1178
+ const totalPages = first.totalPages ?? 1;
1179
+ for (let page = 2; page <= totalPages; page++) {
1180
+ const next = await fetchPage(page);
1181
+ if (!next.items.length) break;
1182
+ all.push(...next.items);
1183
+ }
1184
+ return all;
1185
+ }
1186
+ function sameIdSet(left, right) {
1187
+ const target = new Set(right);
1188
+ return target.size === new Set(left).size && left.every((id) => target.has(id));
1189
+ }
1190
+ function notificationRuleKey(noticeType, memberId, workflowId) {
1191
+ return JSON.stringify([noticeType, memberId, workflowId]);
1192
+ }
1174
1193
  function phaseFor(resource) {
1175
1194
  let ctor = resource.constructor;
1176
1195
  while (ctor) {
@@ -1433,6 +1452,103 @@ Done! Created ${count} resources.`);
1433
1452
  journeyNames.get(existing.name).adopt(detail);
1434
1453
  }
1435
1454
  }
1455
+ const agentNames = new Map(
1456
+ resources.filter((resource) => resource instanceof AgentBuilder).map((resource) => [resource.name, resource])
1457
+ );
1458
+ if (agentNames.size) {
1459
+ for (const existing of await collectPages(
1460
+ (page) => this.client.getAgents({ page, pageSize: LIST_PAGE_SIZE })
1461
+ )) {
1462
+ if (existing.name && agentNames.has(existing.name)) {
1463
+ agentNames.get(existing.name).adopt(existing);
1464
+ }
1465
+ }
1466
+ }
1467
+ const routineNames = new Map(
1468
+ resources.filter((resource) => resource instanceof RoutineBuilder).map((resource) => [resource.name, resource])
1469
+ );
1470
+ if (routineNames.size) {
1471
+ for (const existing of await collectPages(
1472
+ (page) => this.client.getRoutines({ page, pageSize: LIST_PAGE_SIZE })
1473
+ )) {
1474
+ if (existing.name && routineNames.has(existing.name)) {
1475
+ routineNames.get(existing.name).adopt(existing);
1476
+ }
1477
+ }
1478
+ }
1479
+ await this.resolveExistingRoleUpdates(resources);
1480
+ await this.resolveExistingWorkflows(resources, workflowNames);
1481
+ await this.resolveExistingNotificationRules(resources);
1482
+ }
1483
+ /**
1484
+ * Adopt a role update whose grants the server already has.
1485
+ *
1486
+ * A role update is a replace-semantics PUT, not a create, so its identity is
1487
+ * the role id and "already applied" means the id sets match exactly. Subset
1488
+ * would be wrong: `roleUpdate(7, [])` asks to *clear* the role's workflow
1489
+ * access, and treating that as satisfied by a role that still has grants
1490
+ * would silently skip a real change.
1491
+ *
1492
+ * Only the fields this update declares are compared — an update that passes
1493
+ * `workflowIds` and omits `dataTypeIds` never touches data-type access, so
1494
+ * that access cannot make it stale.
1495
+ */
1496
+ async resolveExistingRoleUpdates(resources) {
1497
+ const updates = resources.filter(
1498
+ (resource) => resource instanceof RoleUpdate
1499
+ );
1500
+ if (!updates.length) return;
1501
+ const rolesById = new Map(
1502
+ (await this.client.getMemberRoles()).map((role) => [role.id, role])
1503
+ );
1504
+ for (const update of updates) {
1505
+ const role = rolesById.get(update.roleId);
1506
+ if (!role) continue;
1507
+ const workflowsSettled = update.workflowIds === void 0 || sameIdSet(
1508
+ update.workflowIds,
1509
+ (role.workflowAccess ?? []).map((access) => access.workflowId)
1510
+ );
1511
+ const dataTypesSettled = update.dataTypeIds === void 0 || sameIdSet(
1512
+ update.dataTypeIds,
1513
+ (role.dataTypeAccess ?? []).map((access) => access.dataTypeId)
1514
+ );
1515
+ if (workflowsSettled && dataTypesSettled) update.adopt(role);
1516
+ }
1517
+ }
1518
+ /**
1519
+ * Adopt notification rules the server already has.
1520
+ *
1521
+ * There is no name on the server row — `NotificationRule` is keyed by what
1522
+ * it does — so identity is the composite the API enforces uniqueness on in
1523
+ * practice: notice type, recipient, and subject workflow.
1524
+ */
1525
+ async resolveExistingNotificationRules(resources) {
1526
+ const rules = resources.filter(
1527
+ (resource) => resource instanceof NotificationRuleBuilder
1528
+ );
1529
+ if (!rules.length) return;
1530
+ const identified = rules.flatMap((rule) => {
1531
+ if (rule.memberId === void 0) return [];
1532
+ if (rule.workflow && rule.workflow._id === void 0) return [];
1533
+ return [
1534
+ [
1535
+ notificationRuleKey(rule.noticeType, rule.memberId, rule.workflow?._id ?? null),
1536
+ rule
1537
+ ]
1538
+ ];
1539
+ });
1540
+ if (!identified.length) return;
1541
+ const byKey = new Map(identified);
1542
+ for (const existing of await this.client.getNotificationRules()) {
1543
+ const key = notificationRuleKey(
1544
+ existing.noticeType,
1545
+ existing.memberId,
1546
+ existing.workflowId ?? null
1547
+ );
1548
+ byKey.get(key)?.adopt(existing);
1549
+ }
1550
+ }
1551
+ async resolveExistingWorkflows(resources, workflowNames) {
1436
1552
  if (!workflowNames.size) return;
1437
1553
  const existingWorkflows = await this.client.getWorkflows();
1438
1554
  for (const { workflow: existing } of existingWorkflows.items) {
@@ -1952,7 +2068,6 @@ export {
1952
2068
  REALTIME_MODEL_CUSTOM,
1953
2069
  REALTIME_MODEL_GEMINI,
1954
2070
  REALTIME_MODEL_GEMINI_VERTEX,
1955
- REALTIME_MODEL_NOVA_SONIC,
1956
2071
  REALTIME_MODEL_OPENAI,
1957
2072
  REALTIME_MODEL_OPENAI_2,
1958
2073
  REALTIME_MODEL_OPENAI_MINI,
@@ -2005,8 +2120,6 @@ export {
2005
2120
  formatAppContextAsMarkdown,
2006
2121
  getAllFeatures,
2007
2122
  getAllResourceSlugs,
2008
- getApplicableResourceSlugs,
2009
- getApplicableResources,
2010
2123
  getAvailableFeaturesForUpgrade,
2011
2124
  getCookieValue,
2012
2125
  getFeature,
@@ -2015,7 +2128,6 @@ export {
2015
2128
  getMissingDependencies,
2016
2129
  getResourceMetadata,
2017
2130
  getRevisionState,
2018
- getScopeFromProductType,
2019
2131
  getTTSProvider,
2020
2132
  getVoiceModelId,
2021
2133
  initializeFeatures,