@gravity-rail/sdk 0.10.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +7 -8
  2. package/dist/{chunk-2BJG4GYM.js → chunk-LODUVCW6.js} +884 -210
  3. package/dist/chunk-LODUVCW6.js.map +1 -0
  4. package/dist/{chunk-TJT7A4CO.js → chunk-V7ZKEH4V.js} +1 -1
  5. package/dist/chunk-V7ZKEH4V.js.map +1 -0
  6. package/dist/{client-BffM3KcA.d.cts → client-CYQ_N681.d.ts} +2794 -1123
  7. package/dist/{client-DfjAYbt8.d.ts → client-DSFqUxvN.d.cts} +2794 -1123
  8. package/dist/helpers.cjs +6 -18
  9. package/dist/helpers.cjs.map +1 -1
  10. package/dist/helpers.d.cts +2 -2
  11. package/dist/helpers.d.ts +2 -2
  12. package/dist/helpers.js +6 -18
  13. package/dist/helpers.js.map +1 -1
  14. package/dist/index.cjs +914 -298
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +23 -21
  17. package/dist/index.d.ts +23 -21
  18. package/dist/index.js +51 -95
  19. package/dist/index.js.map +1 -1
  20. package/dist/internal.cjs +1040 -297
  21. package/dist/internal.cjs.map +1 -1
  22. package/dist/internal.d.cts +446 -74
  23. package/dist/internal.d.ts +446 -74
  24. package/dist/internal.js +75 -3
  25. package/dist/internal.js.map +1 -1
  26. package/dist/realtime.cjs +42 -0
  27. package/dist/realtime.cjs.map +1 -1
  28. package/dist/realtime.d.cts +26 -0
  29. package/dist/realtime.d.ts +26 -0
  30. package/dist/realtime.js +42 -0
  31. package/dist/realtime.js.map +1 -1
  32. package/dist/{scopes-CmNKWrzb.d.ts → revision-state-C0VW3vDJ.d.cts} +221 -19
  33. package/dist/{scopes-CjSvITpL.d.cts → revision-state-CIRkBy-k.d.ts} +221 -19
  34. package/dist/schemas.cjs +55 -111
  35. package/dist/schemas.cjs.map +1 -1
  36. package/dist/schemas.d.cts +48 -466
  37. package/dist/schemas.d.ts +48 -466
  38. package/dist/schemas.js +55 -108
  39. package/dist/schemas.js.map +1 -1
  40. package/dist/{inquiries-UcWNYo-Q.d.cts → tasks-DcxMysiR.d.cts} +483 -143
  41. package/dist/{inquiries-UcWNYo-Q.d.ts → tasks-DcxMysiR.d.ts} +483 -143
  42. package/package.json +1 -1
  43. package/dist/chunk-2BJG4GYM.js.map +0 -1
  44. package/dist/chunk-TJT7A4CO.js.map +0 -1
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  BusinessType,
15
15
  CELApi,
16
16
  CHAT_TYPES,
17
+ CapabilityClass,
17
18
  ConsentMethod,
18
19
  CriterionType,
19
20
  DEFAULT_CHAT_MODEL,
@@ -60,6 +61,7 @@ import {
60
61
  PERMISSION_VERIFY,
61
62
  PIDS_DISPOSITIONS,
62
63
  PIDS_SOURCES,
64
+ POSITIVE_RATING_THRESHOLD,
63
65
  ProductType,
64
66
  QUERY_VALUELESS_OPS,
65
67
  QueriesApi,
@@ -93,6 +95,7 @@ import {
93
95
  TTS_PREVIEW_PROVIDERS,
94
96
  TemplatesApi,
95
97
  ToolkitState,
98
+ WIDGET_SLUGS,
96
99
  WorkflowAccessWarningResourceType,
97
100
  WorkspaceFeature,
98
101
  WorkspaceProvisionStatus,
@@ -114,18 +117,20 @@ import {
114
117
  getFeaturesByVisibility,
115
118
  getMissingDependencies,
116
119
  getResourceMetadata,
120
+ getRevisionState,
117
121
  getScopeFromProductType,
118
122
  getTTSProvider,
119
123
  getVoiceModelId,
120
124
  initializeFeatures,
121
125
  isChatType,
122
126
  isFeatureAvailable,
127
+ isPositiveRating,
123
128
  isRegistryInitialized,
124
129
  isSMSDeliveryFailureStatus,
125
130
  requiresAssistantParticipant,
126
131
  usesBuiltinAssistant,
127
132
  validateFeatureDependencies
128
- } from "./chunk-2BJG4GYM.js";
133
+ } from "./chunk-LODUVCW6.js";
129
134
  import {
130
135
  AttendeeResponseStatus,
131
136
  AttendeeStatus,
@@ -140,7 +145,7 @@ import {
140
145
  DataSensitivity,
141
146
  DataTypeRecordScope,
142
147
  IndexStatus
143
- } from "./chunk-TJT7A4CO.js";
148
+ } from "./chunk-V7ZKEH4V.js";
144
149
  import {
145
150
  ApiError,
146
151
  BaseApiClient,
@@ -211,27 +216,25 @@ var MemberFilterBuilder = class extends WorkspaceBuilderResource {
211
216
  super();
212
217
  this.name = name;
213
218
  this.description = options.description ?? "";
219
+ this.query = options.query ?? null;
214
220
  }
215
221
  name;
216
222
  description;
217
- rules = [];
218
- addRule(objectType, filterType, options = {}) {
219
- this.rules.push({
220
- objectType,
221
- filterType,
222
- ...options.objectIds ? { objectIds: options.objectIds } : {},
223
- ...options.query ? { query: options.query } : {}
224
- });
223
+ /** Query-engine predicate (JSON IR) authored on MemberFilter.query. */
224
+ query = null;
225
+ /** Set the filter's query-engine predicate (JSON IR). */
226
+ setQuery(query) {
227
+ this.query = query;
225
228
  return this;
226
229
  }
227
230
  planLine() {
228
- return `MemberFilter: ${this.name}${this.rules.length ? ` (${this.rules.length} rules)` : ""}`;
231
+ return `MemberFilter: ${this.name}${this.query ? " (query)" : ""}`;
229
232
  }
230
233
  async apply(client) {
231
234
  const payload = {
232
235
  name: this.name,
233
236
  description: this.description,
234
- rules: this.rules
237
+ query: this.query
235
238
  };
236
239
  const result = await client.createMemberFilter(payload);
237
240
  this._id = result.id;
@@ -755,8 +758,13 @@ var TaskBuilder = class extends WorkspaceBuilderResource {
755
758
  }
756
759
  async apply(client) {
757
760
  if (this._existed || this.workflow._id === void 0) return;
761
+ if (this.workflow._draftRevisionId === void 0) {
762
+ throw new Error(
763
+ `Workflow '${this.workflow.name}' has no draft revision id; cannot create tasks. Tasks attach to a WorkflowRevision, not the stable workflow root.`
764
+ );
765
+ }
758
766
  const result = await client.createTask({
759
- workflowId: this.workflow._id,
767
+ workflowRevisionId: this.workflow._draftRevisionId,
760
768
  name: this.name,
761
769
  prompt: this.prompt,
762
770
  description: this.description
@@ -772,14 +780,18 @@ var WorkflowBuilder = class extends WorkspaceBuilderResource {
772
780
  this.name = name;
773
781
  this.description = options.description ?? "";
774
782
  this.prompt = options.prompt;
775
- this.agentId = options.agentId ?? options.agent_id;
783
+ this.copyFromAgentId = options.copyFromAgentId;
776
784
  }
777
785
  name;
778
786
  description;
779
787
  prompt;
780
- agentId;
788
+ copyFromAgentId;
781
789
  tasks = [];
782
790
  abilities = [];
791
+ /** The DRAFT revision's id — where tasks and graph edits attach.
792
+ * `_id` is the STABLE workflow root id; the two are different entities
793
+ * and (after any publish) different numbers. */
794
+ _draftRevisionId;
783
795
  task(name, options = {}) {
784
796
  const task = new TaskBuilder(
785
797
  name,
@@ -802,10 +814,14 @@ var WorkflowBuilder = class extends WorkspaceBuilderResource {
802
814
  return this.name;
803
815
  }
804
816
  adopt(existing) {
805
- super.adopt(existing);
817
+ const root = existing.workflow ?? existing;
818
+ super.adopt(root);
819
+ const draft = existing.draftRevision;
820
+ this._draftRevisionId = draft?.id ?? root.draftRevisionId;
806
821
  const start = this.startTask;
807
- if (start && existing.startTaskId) {
808
- start._id = existing.startTaskId;
822
+ const startTaskId = draft?.startTaskId;
823
+ if (start && startTaskId) {
824
+ start._id = startTaskId;
809
825
  start._existed = true;
810
826
  }
811
827
  }
@@ -815,12 +831,6 @@ var WorkflowBuilder = class extends WorkspaceBuilderResource {
815
831
  if (this.abilities.length) details.push(`${this.abilities.length} abilities`);
816
832
  return `Workflow: ${this.name}${details.length ? ` (${details.join(", ")})` : ""}`;
817
833
  }
818
- needsDefaultAgent() {
819
- return !this._existed && this.agentId === void 0;
820
- }
821
- setAgentId(agentId) {
822
- this.agentId = agentId;
823
- }
824
834
  async apply(client) {
825
835
  if (this._existed) return;
826
836
  const payload = {
@@ -828,63 +838,16 @@ var WorkflowBuilder = class extends WorkspaceBuilderResource {
828
838
  description: this.description,
829
839
  createMode: "taskless",
830
840
  ...this.prompt ? { prompt: this.prompt } : {},
831
- ...this.agentId ? { agentId: this.agentId } : {},
841
+ ...this.copyFromAgentId ? { copyFromAgentId: this.copyFromAgentId } : {},
832
842
  ...this.abilities.length ? { abilities: this.abilities.map((ability) => ability.toAbility()) } : {}
833
843
  };
834
844
  const result = await client.createWorkflow(payload);
835
- this._id = result.id;
836
- this._uuid = result.uuid;
845
+ this._id = result.workflow.id;
846
+ this._uuid = result.workflow.uuid;
847
+ this._draftRevisionId = result.draftRevision.id;
837
848
  this._created = true;
838
849
  }
839
850
  };
840
- var WORKSPACE_BUILDER_DEFAULT_AGENT_NAME = "Workspace Setup Agent";
841
- var WORKSPACE_BUILDER_DEFAULT_AGENT_PROMPT = "You help workspace members complete the workflow you are assigned to. Follow the task prompts, collect requested information accurately, and escalate when the workflow asks you to.";
842
- async function getOrCreateDefaultWorkflowAgent(client) {
843
- const existingAgents = recordsFromResponse(
844
- await client.getAgents({ pageSize: 100, includeArchived: false })
845
- );
846
- const existing = existingAgents.find((agent) => !agent.isArchived) ?? existingAgents[0];
847
- if (existing) {
848
- return {
849
- id: numberField(existing, "id"),
850
- name: stringField(existing, "name"),
851
- created: false
852
- };
853
- }
854
- const roles = recordsFromResponse(await client.getMemberRoles());
855
- const role = roles.find((candidate) => stringField(candidate, "name").toLowerCase() === "agent") ?? roles[0];
856
- if (!role) {
857
- throw new Error("Cannot create default workflow agent: workspace has no member roles");
858
- }
859
- const payload = {
860
- name: WORKSPACE_BUILDER_DEFAULT_AGENT_NAME,
861
- memberRoleId: numberField(role, "id"),
862
- chatModelId: DEFAULT_CHAT_MODEL,
863
- systemPrompt: WORKSPACE_BUILDER_DEFAULT_AGENT_PROMPT
864
- };
865
- const created = await client.createAgent(payload);
866
- return {
867
- id: created.id,
868
- name: created.name ?? WORKSPACE_BUILDER_DEFAULT_AGENT_NAME,
869
- created: true
870
- };
871
- }
872
- function recordsFromResponse(value) {
873
- if (Array.isArray(value)) return value;
874
- if (value && typeof value === "object" && Array.isArray(value.items)) {
875
- return value.items;
876
- }
877
- return [];
878
- }
879
- function numberField(record, key) {
880
- const value = record[key];
881
- if (typeof value !== "number") throw new Error(`Expected numeric ${key}`);
882
- return value;
883
- }
884
- function stringField(record, key) {
885
- const value = record[key];
886
- return typeof value === "string" ? value : "";
887
- }
888
851
  var AgentBuilder = class extends WorkspaceBuilderResource {
889
852
  constructor(name, options = {}) {
890
853
  super();
@@ -1051,7 +1014,6 @@ ${"=".repeat(50)}`);
1051
1014
  await this.resolveExisting(resources);
1052
1015
  const summary = {};
1053
1016
  writeLine("Applying...");
1054
- await this.ensureWorkflowAgents(resources, summary);
1055
1017
  for (const resource of resources) {
1056
1018
  try {
1057
1019
  if (resource._existed) {
@@ -1112,9 +1074,11 @@ Done! Created ${count} resources.`);
1112
1074
  }
1113
1075
  }
1114
1076
  if (!workflowNames.size) return;
1115
- for (const existing of await this.client.getWorkflows()) {
1077
+ const existingWorkflows = await this.client.getWorkflows();
1078
+ for (const { workflow: existing } of existingWorkflows.items) {
1116
1079
  if (existing.name && workflowNames.has(existing.name)) {
1117
- workflowNames.get(existing.name).adopt(existing);
1080
+ const detail = await this.client.getWorkflow(existing.id);
1081
+ workflowNames.get(existing.name).adopt(detail);
1118
1082
  }
1119
1083
  }
1120
1084
  const adoptedWorkflows = resources.filter(
@@ -1123,7 +1087,9 @@ Done! Created ${count} resources.`);
1123
1087
  if (!adoptedWorkflows.length) return;
1124
1088
  const existingTasks = await this.client.getTasks();
1125
1089
  for (const workflow of adoptedWorkflows) {
1126
- const workflowTasks = existingTasks.filter((task) => task.workflowId === workflow._id);
1090
+ const workflowTasks = existingTasks.filter(
1091
+ (task) => (task.workflowRevisionId ?? task.workflowId) === workflow._draftRevisionId
1092
+ );
1127
1093
  const taskByName = new Map(workflowTasks.map((task) => [task.name, task]));
1128
1094
  for (const taskBuilder of workflow.tasks) {
1129
1095
  const match = taskByName.get(taskBuilder.name);
@@ -1145,21 +1111,6 @@ Done! Created ${count} resources.`);
1145
1111
  }
1146
1112
  }
1147
1113
  }
1148
- async ensureWorkflowAgents(resources, summary) {
1149
- const workflows = resources.filter(
1150
- (resource) => resource instanceof WorkflowBuilder && resource.needsDefaultAgent()
1151
- );
1152
- if (!workflows.length) return;
1153
- const agent = await getOrCreateDefaultWorkflowAgent(this.client);
1154
- for (const workflow of workflows) workflow.setAgentId(agent.id);
1155
- if (agent.created) {
1156
- summary.agents ??= [];
1157
- summary.agents.push(agent.id);
1158
- writeLine(` Created Agent: ${agent.name} -> id=${agent.id}`);
1159
- } else {
1160
- writeLine(` Using Agent: ${agent.name || agent.id} -> id=${agent.id}`);
1161
- }
1162
- }
1163
1114
  sortedResources() {
1164
1115
  const all = [];
1165
1116
  for (const resource of this.resources) {
@@ -1364,7 +1315,7 @@ var SEARCHABLE_EVENT_RULE_SOURCE_FIELDS = [
1364
1315
  "taskId",
1365
1316
  "dataTypeId",
1366
1317
  "routineId",
1367
- "workflowId",
1318
+ "workflowRevisionId",
1368
1319
  "journeyStepId"
1369
1320
  ];
1370
1321
  var EVENT_RULE_SOURCE_FIELDS = [
@@ -1557,6 +1508,7 @@ export {
1557
1508
  CalendarScheduleAvailabilityType,
1558
1509
  CalendarScheduleRecurrence,
1559
1510
  CalendarSource,
1511
+ CapabilityClass,
1560
1512
  ConsentMethod,
1561
1513
  CriterionType,
1562
1514
  DEFAULT_CHAT_MODEL,
@@ -1616,6 +1568,7 @@ export {
1616
1568
  PERMISSION_VERIFY,
1617
1569
  PIDS_DISPOSITIONS,
1618
1570
  PIDS_SOURCES,
1571
+ POSITIVE_RATING_THRESHOLD,
1619
1572
  ProductType,
1620
1573
  QUERY_VALUELESS_OPS,
1621
1574
  QueriesApi,
@@ -1652,6 +1605,7 @@ export {
1652
1605
  TaskBuilder,
1653
1606
  TemplatesApi,
1654
1607
  ToolkitState,
1608
+ WIDGET_SLUGS,
1655
1609
  WorkflowAccessWarningResourceType,
1656
1610
  WorkflowBuilder,
1657
1611
  WorkflowAccessWarningResourceType as WorkflowResourceType,
@@ -1677,12 +1631,14 @@ export {
1677
1631
  getFeaturesByVisibility,
1678
1632
  getMissingDependencies,
1679
1633
  getResourceMetadata,
1634
+ getRevisionState,
1680
1635
  getScopeFromProductType,
1681
1636
  getTTSProvider,
1682
1637
  getVoiceModelId,
1683
1638
  initializeFeatures,
1684
1639
  isChatType,
1685
1640
  isFeatureAvailable,
1641
+ isPositiveRating,
1686
1642
  isRegistryInitialized,
1687
1643
  isSMSDeliveryFailureStatus,
1688
1644
  requiresAssistantParticipant,