@burdenoff/fe-libs 2026.1030.3 → 2026.1030.4

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.
@@ -1,19 +1,20 @@
1
- import { executeAssistantGraphQLOnce as e } from "./gatewayClient.js";
1
+ import { throwIfAborted as e } from "./abortSignal.js";
2
+ import { executeAssistantGraphQLOnce as t } from "./gatewayClient.js";
2
3
  //#region src/shared/assistant/workflowApi.ts
3
- var t = "id clientTurnId courseId status partialMessage historyDelivered usageDelivered\n result { message model tokensUsed sources { reference chunkId documentId knowledgeBaseId } }", n = "runId status workflowId workflowKey version triggerNodeId";
4
- function r(e) {
4
+ var n = "id clientTurnId courseId status partialMessage historyDelivered usageDelivered\n result { message model tokensUsed sources { reference chunkId documentId knowledgeBaseId } }", r = "runId status workflowId workflowKey version triggerNodeId";
5
+ function i(e) {
5
6
  return typeof e == "string" && e.length > 0 && e.length <= 255;
6
7
  }
7
- function i(e, t, n) {
8
- if (!r(n.workspaceId) || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(t) || !r(e.kind === "botmanor" ? e.agentId : e.courseId)) throw Error("Invalid assistant turn scope");
8
+ function a(e, t, n) {
9
+ if (!i(n.workspaceId) || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(t) || !i(e.kind === "botmanor" ? e.agentId : e.courseId)) throw Error("Invalid assistant turn scope");
9
10
  }
10
- function a(e) {
11
- return !e || typeof e.message != "string" || !e.message.trim() || new TextEncoder().encode(e.message).length > 131072 || typeof e.model != "string" || !e.model || new TextEncoder().encode(e.model).length > 1024 || !Number.isInteger(e.tokensUsed) || e.tokensUsed < 0 || e.tokensUsed > 2147483647 || !Array.isArray(e.sources) || e.sources.length > 100 ? !1 : e.sources.every((e) => e && Number.isInteger(e.reference) && e.reference >= 1 && r(e.chunkId) && r(e.documentId) && r(e.knowledgeBaseId));
11
+ function o(e) {
12
+ return !e || typeof e.message != "string" || !e.message.trim() || new TextEncoder().encode(e.message).length > 131072 || typeof e.model != "string" || !e.model || new TextEncoder().encode(e.model).length > 1024 || !Number.isInteger(e.tokensUsed) || e.tokensUsed < 0 || e.tokensUsed > 2147483647 || !Array.isArray(e.sources) || e.sources.length > 100 ? !1 : e.sources.every((e) => e && Number.isInteger(e.reference) && e.reference >= 1 && i(e.chunkId) && i(e.documentId) && i(e.knowledgeBaseId));
12
13
  }
13
- function o(e, t, n) {
14
+ function s(e, t, n) {
14
15
  if (n === null) return null;
15
16
  if (!n) throw Error("Missing assistant turn receipt");
16
- if (!r(n.id) || typeof n.historyDelivered != "boolean" || typeof n.usageDelivered != "boolean" || n.clientTurnId !== t || (e.kind === "buildmyiq-course" ? n.courseId !== e.courseId : n.courseId !== null) || ![
17
+ if (!i(n.id) || typeof n.historyDelivered != "boolean" || typeof n.usageDelivered != "boolean" || n.clientTurnId !== t || (e.kind === "buildmyiq-course" ? n.courseId !== e.courseId : n.courseId !== null) || ![
17
18
  "READY",
18
19
  "RUNNING",
19
20
  "GENERATED",
@@ -23,11 +24,11 @@ function o(e, t, n) {
23
24
  "UNKNOWN"
24
25
  ].includes(n.status)) throw Error("Invalid assistant turn receipt");
25
26
  if (n.partialMessage != null && (n.status !== "RUNNING" || typeof n.partialMessage != "string" || new TextEncoder().encode(n.partialMessage).length > 131072)) throw Error("Invalid provisional assistant answer");
26
- if (n.result !== null && !a(n.result)) throw Error("Invalid assistant answer receipt");
27
+ if (n.result !== null && !o(n.result)) throw Error("Invalid assistant answer receipt");
27
28
  if (n.status === "COMPLETED" && (!n.result || !n.historyDelivered || !n.usageDelivered)) throw Error("Assistant answer delivery is incomplete");
28
29
  return n;
29
30
  }
30
- function s(e) {
31
+ function c(e) {
31
32
  if (!e || typeof e != "object" || !("extensions" in e)) return !1;
32
33
  let t = e.extensions;
33
34
  return !!t && typeof t == "object" && "code" in t && typeof t.code == "string" && [
@@ -39,31 +40,31 @@ function s(e) {
39
40
  "QUOTA_NOT_PROVISIONED"
40
41
  ].includes(t.code);
41
42
  }
42
- var c = class {
43
+ var l = class {
43
44
  request;
44
- constructor(t = e) {
45
- this.request = t;
45
+ constructor(e = t) {
46
+ this.request = e;
46
47
  }
47
48
  async courseTargetForEnrollment(e, t) {
48
- if (!r(e) || !r(t.workspaceId)) throw Error("Invalid assistant enrollment scope");
49
+ if (!i(e) || !i(t.workspaceId)) throw Error("Invalid assistant enrollment scope");
49
50
  let n = await this.request({
50
51
  ...t,
51
52
  operationName: "ReadCourseAssistantTarget",
52
53
  query: "query ReadCourseAssistantTarget($enrollmentId: ID!) { buiMyCourseAssistantTarget(enrollmentId: $enrollmentId) { courseId } }",
53
54
  variables: { enrollmentId: e }
54
55
  });
55
- if (!r(n.buiMyCourseAssistantTarget?.courseId)) throw Error("Invalid assistant course target");
56
+ if (!i(n.buiMyCourseAssistantTarget?.courseId)) throw Error("Invalid assistant course target");
56
57
  return {
57
58
  kind: "buildmyiq-course",
58
59
  courseId: n.buiMyCourseAssistantTarget.courseId
59
60
  };
60
61
  }
61
- async start(e, t, a) {
62
- if (i(e, t.clientTurnId, a), !a.workspaceId || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(t.clientTurnId) || !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{7,127}$/.test(t.clientConversationId) || !t.message.trim() || t.message.length > 8192) throw Error("Invalid assistant turn");
62
+ async start(e, t, n) {
63
+ if (a(e, t.clientTurnId, n), !n.workspaceId || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(t.clientTurnId) || !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{7,127}$/.test(t.clientConversationId) || !t.message.trim() || t.message.length > 8192) throw Error("Invalid assistant turn");
63
64
  let o = e.kind === "buildmyiq-course", s = o ? "buiStartCourseAssistantTurn" : "startAssistantTurn", c = o ? "BuiCourseAssistantTurnInput" : "StartAssistantTurnInput", l = (await this.request({
64
- ...a,
65
+ ...n,
65
66
  operationName: "StartWorkflowAssistantTurn",
66
- query: `mutation StartWorkflowAssistantTurn($input: ${c}!) { ${s}(input: $input) { ${n} } }`,
67
+ query: `mutation StartWorkflowAssistantTurn($input: ${c}!) { ${s}(input: $input) { ${r} } }`,
67
68
  variables: { input: {
68
69
  ...t,
69
70
  ...o ? { courseId: e.courseId } : {
@@ -79,87 +80,87 @@ var c = class {
79
80
  l.workflowKey,
80
81
  l.version,
81
82
  l.triggerNodeId
82
- ].every(r)) throw Error("Assistant admission could not be confirmed; recover with the same turn ID");
83
+ ].every(i)) throw Error("Assistant admission could not be confirmed; recover with the same turn ID");
83
84
  return l;
84
85
  }
85
- async read(e, n, r, a = !1) {
86
- i(e, n, r);
87
- let s = e.kind === "buildmyiq-course", c = s ? a ? "buiRetryCourseAssistantDelivery" : "buiMyCourseAssistantTurn" : a ? "retryMyAssistantTurnDelivery" : "myAssistantTurn", l = a ? "RetryWorkflowAssistantDelivery" : "ReadWorkflowAssistantTurn", u = (await this.request({
86
+ async read(e, t, r, i = !1) {
87
+ a(e, t, r);
88
+ let o = e.kind === "buildmyiq-course", c = o ? i ? "buiRetryCourseAssistantDelivery" : "buiMyCourseAssistantTurn" : i ? "retryMyAssistantTurnDelivery" : "myAssistantTurn", l = i ? "RetryWorkflowAssistantDelivery" : "ReadWorkflowAssistantTurn", u = (await this.request({
88
89
  ...r,
89
90
  operationName: l,
90
- query: `${a ? "mutation" : "query"} ${l}($clientTurnId: ID!${s ? ", $courseId: ID!" : ""}) {
91
- ${c}(clientTurnId: $clientTurnId${s ? ", courseId: $courseId" : ""}) { ${t} }
91
+ query: `${i ? "mutation" : "query"} ${l}($clientTurnId: ID!${o ? ", $courseId: ID!" : ""}) {
92
+ ${c}(clientTurnId: $clientTurnId${o ? ", courseId: $courseId" : ""}) { ${n} }
92
93
  }`,
93
94
  variables: {
94
- clientTurnId: n,
95
- ...s ? { courseId: e.courseId } : {}
95
+ clientTurnId: t,
96
+ ...o ? { courseId: e.courseId } : {}
96
97
  }
97
98
  }))[c];
98
- return o(e, n, u);
99
+ return s(e, t, u);
99
100
  }
100
101
  async conversations(e, t, n = null) {
101
- i(e, "history-list", t);
102
+ a(e, "history-list", t);
102
103
  let r = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
103
104
  if (n !== null && !r.test(n)) throw Error("Invalid assistant conversation cursor");
104
- let a = e.kind === "buildmyiq-course", o = a ? "buiMyCourseAssistantConversations" : "myAssistantWorkflowConversations", s = (await this.request({
105
+ let i = e.kind === "buildmyiq-course", o = i ? "buiMyCourseAssistantConversations" : "myAssistantWorkflowConversations", s = (await this.request({
105
106
  ...t,
106
107
  operationName: "ListWorkflowAssistantConversations",
107
- query: `query ListWorkflowAssistantConversations($targetId: ID!, $after: ID) { ${o}(${a ? "courseId" : "agentId"}: $targetId, after: $after) { nodes { clientConversationId createdAt } nextCursor } }`,
108
+ query: `query ListWorkflowAssistantConversations($targetId: ID!, $after: ID) { ${o}(${i ? "courseId" : "agentId"}: $targetId, after: $after) { nodes { clientConversationId createdAt } nextCursor } }`,
108
109
  variables: {
109
- targetId: a ? e.courseId : e.agentId,
110
+ targetId: i ? e.courseId : e.agentId,
110
111
  after: n
111
112
  }
112
113
  }))[o];
113
114
  if (!s || !Array.isArray(s.nodes) || s.nodes.length > 20 || s.nodes.some((e) => !e || !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{7,127}$/.test(e.clientConversationId) || typeof e.createdAt != "string" || !Number.isFinite(Date.parse(e.createdAt))) || s.nextCursor !== null && (!r.test(s.nextCursor) || s.nextCursor === n)) throw Error("Invalid assistant conversation page");
114
115
  return s;
115
116
  }
116
- async conversation(e, n, r = null) {
117
- if (i(e, "history-read", n), r !== null && !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{7,127}$/.test(r)) throw Error("Invalid assistant conversation");
118
- let a = e.kind === "buildmyiq-course", s = a ? "buiMyCourseAssistantConversation" : "myAssistantWorkflowConversation", c = a ? "courseId" : "agentId", l = (await this.request({
119
- ...n,
117
+ async conversation(e, t, r = null) {
118
+ if (a(e, "history-read", t), r !== null && !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{7,127}$/.test(r)) throw Error("Invalid assistant conversation");
119
+ let i = e.kind === "buildmyiq-course", o = i ? "buiMyCourseAssistantConversation" : "myAssistantWorkflowConversation", c = i ? "courseId" : "agentId", l = (await this.request({
120
+ ...t,
120
121
  operationName: "ReadWorkflowAssistantConversation",
121
- query: `query ReadWorkflowAssistantConversation($targetId: ID!, $clientConversationId: ID) { ${s}(${c}: $targetId, clientConversationId: $clientConversationId) {
122
- clientConversationId turns { message receipt { ${t} } } pending { clientTurnId clientConversationId message }
122
+ query: `query ReadWorkflowAssistantConversation($targetId: ID!, $clientConversationId: ID) { ${o}(${c}: $targetId, clientConversationId: $clientConversationId) {
123
+ clientConversationId turns { message receipt { ${n} } } pending { clientTurnId clientConversationId message }
123
124
  } }`,
124
125
  variables: {
125
- targetId: a ? e.courseId : e.agentId,
126
+ targetId: i ? e.courseId : e.agentId,
126
127
  clientConversationId: r
127
128
  }
128
- }))[s];
129
+ }))[o];
129
130
  if (l === null) return null;
130
131
  if (!l || r !== null && l.clientConversationId !== r || !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{7,127}$/.test(l.clientConversationId) || !Array.isArray(l.turns) || l.turns.length > 6) throw Error("Invalid assistant conversation receipt");
131
132
  let u = /* @__PURE__ */ new Set();
132
133
  for (let t of l.turns) {
133
134
  if (!t || typeof t.message != "string" || t.message.length > 8192 || !t.receipt || t.receipt.status !== "COMPLETED" || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(t.receipt.clientTurnId) || u.has(t.receipt.clientTurnId)) throw Error("Invalid assistant history turn");
134
- o(e, t.receipt.clientTurnId, t.receipt), u.add(t.receipt.clientTurnId);
135
+ s(e, t.receipt.clientTurnId, t.receipt), u.add(t.receipt.clientTurnId);
135
136
  }
136
137
  let d = l.pending;
137
138
  if (d !== null && (!d || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(d.clientTurnId) || d.clientConversationId !== l.clientConversationId || typeof d.message != "string" || !d.message.trim() || d.message.length > 8192 || u.has(d.clientTurnId))) throw Error("Invalid assistant recovery handle");
138
139
  return l;
139
140
  }
140
- async messages(e, n, r, a = null) {
141
- if (i(e, "history-page", n), !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{7,127}$/.test(r) || a !== null && (a.length > 4096 || !/^[A-Za-z0-9_-]+$/.test(a))) throw Error("Invalid assistant transcript cursor");
142
- let s = e.kind === "buildmyiq-course", c = s ? "buiMyCourseAssistantMessages" : "myAssistantWorkflowConversationMessages", l = (await this.request({
143
- ...n,
141
+ async messages(e, t, r, i = null) {
142
+ if (a(e, "history-page", t), !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{7,127}$/.test(r) || i !== null && (i.length > 4096 || !/^[A-Za-z0-9_-]+$/.test(i))) throw Error("Invalid assistant transcript cursor");
143
+ let o = e.kind === "buildmyiq-course", c = o ? "buiMyCourseAssistantMessages" : "myAssistantWorkflowConversationMessages", l = (await this.request({
144
+ ...t,
144
145
  operationName: "ReadWorkflowAssistantMessages",
145
- query: `query ReadWorkflowAssistantMessages($targetId:ID!,$clientConversationId:ID!,$before:String) { ${c}(${s ? "courseId" : "agentId"}:$targetId,clientConversationId:$clientConversationId,before:$before) { turns { message receipt { ${t} } } nextCursor } }`,
146
+ query: `query ReadWorkflowAssistantMessages($targetId:ID!,$clientConversationId:ID!,$before:String) { ${c}(${o ? "courseId" : "agentId"}:$targetId,clientConversationId:$clientConversationId,before:$before) { turns { message receipt { ${n} } } nextCursor } }`,
146
147
  variables: {
147
- targetId: s ? e.courseId : e.agentId,
148
+ targetId: o ? e.courseId : e.agentId,
148
149
  clientConversationId: r,
149
- before: a
150
+ before: i
150
151
  }
151
152
  }))[c];
152
- if (!l || !Array.isArray(l.turns) || l.turns.length > 25 || l.nextCursor !== null && (typeof l.nextCursor != "string" || l.nextCursor.length > 4096 || !/^[A-Za-z0-9_-]+$/.test(l.nextCursor) || l.nextCursor === a)) throw Error("Invalid assistant transcript page");
153
+ if (!l || !Array.isArray(l.turns) || l.turns.length > 25 || l.nextCursor !== null && (typeof l.nextCursor != "string" || l.nextCursor.length > 4096 || !/^[A-Za-z0-9_-]+$/.test(l.nextCursor) || l.nextCursor === i)) throw Error("Invalid assistant transcript page");
153
154
  let u = /* @__PURE__ */ new Set(), d = 0;
154
155
  for (let t of l.turns) {
155
156
  if (!t || typeof t.message != "string" || !t.receipt || t.receipt.status !== "COMPLETED" || !t.receipt.result || u.has(t.receipt.clientTurnId)) throw Error("Invalid assistant transcript turn");
156
- o(e, t.receipt.clientTurnId, t.receipt), u.add(t.receipt.clientTurnId), d += new TextEncoder().encode(t.message).length + new TextEncoder().encode(t.receipt.result.message).length;
157
+ s(e, t.receipt.clientTurnId, t.receipt), u.add(t.receipt.clientTurnId), d += new TextEncoder().encode(t.message).length + new TextEncoder().encode(t.receipt.result.message).length;
157
158
  }
158
159
  if (d > 262144) throw Error("Invalid assistant transcript size");
159
160
  return l;
160
161
  }
161
162
  async cancel(e, t) {
162
- if (!r(t.workspaceId) || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(e)) throw Error("Invalid assistant turn scope");
163
+ if (!i(t.workspaceId) || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(e)) throw Error("Invalid assistant turn scope");
163
164
  return (await this.request({
164
165
  ...t,
165
166
  operationName: "CancelWorkflowAssistantTurn",
@@ -167,40 +168,40 @@ var c = class {
167
168
  variables: { clientTurnId: e }
168
169
  })).cancelMyAssistantTurn === !0;
169
170
  }
170
- async wait(e, t, n, r = {}) {
171
- let i = r.budgetMs ?? 18e4, a = r.intervalMs ?? 1e3;
172
- if (!Number.isInteger(i) || i < 100 || i > 6e5 || !Number.isInteger(a) || a < 10 || a > 5e3) throw Error("Invalid assistant polling budget");
173
- let o = Date.now() + i, s = null, c = 0;
174
- for (; Date.now() < o;) {
175
- if (n.signal?.throwIfAborted(), s = await this.read(e, t, n), s?.status === "GENERATED" && Date.now() >= c && (c = Date.now() + 5e3, s = await this.read(e, t, n, !0)), s) {
176
- if (r.onProgress?.(s), s.status === "COMPLETED") return {
171
+ async wait(t, n, r, i = {}) {
172
+ let a = i.budgetMs ?? 18e4, o = i.intervalMs ?? 1e3;
173
+ if (!Number.isInteger(a) || a < 100 || a > 6e5 || !Number.isInteger(o) || o < 10 || o > 5e3) throw Error("Invalid assistant polling budget");
174
+ let s = Date.now() + a, c = null, l = 0;
175
+ for (; Date.now() < s;) {
176
+ if (e(r.signal), c = await this.read(t, n, r), c?.status === "GENERATED" && Date.now() >= l && (l = Date.now() + 5e3, c = await this.read(t, n, r, !0)), c) {
177
+ if (i.onProgress?.(c), c.status === "COMPLETED") return {
177
178
  kind: "completed",
178
- receipt: s
179
+ receipt: c
179
180
  };
180
181
  if ([
181
182
  "FAILED",
182
183
  "UNKNOWN",
183
184
  "CANCELLED"
184
- ].includes(s.status)) return {
185
+ ].includes(c.status)) return {
185
186
  kind: "terminal",
186
- receipt: s
187
+ receipt: c
187
188
  };
188
189
  }
189
- if (n.signal?.throwIfAborted(), Date.now() >= o) break;
190
+ if (e(r.signal), Date.now() >= s) break;
190
191
  await new Promise((e, t) => {
191
- let r = () => n.signal?.removeEventListener("abort", s), i = setTimeout(() => {
192
- r(), e();
193
- }, Math.min(a, o - Date.now())), s = () => {
194
- clearTimeout(i), r(), t(n.signal?.reason ?? new DOMException("Aborted", "AbortError"));
192
+ let n = () => r.signal?.removeEventListener("abort", a), i = setTimeout(() => {
193
+ n(), e();
194
+ }, Math.min(o, s - Date.now())), a = () => {
195
+ clearTimeout(i), n(), t(r.signal?.reason ?? new DOMException("Aborted", "AbortError"));
195
196
  };
196
- n.signal?.addEventListener("abort", s, { once: !0 }), n.signal?.aborted && s();
197
+ r.signal?.addEventListener("abort", a, { once: !0 }), r.signal?.aborted && a();
197
198
  });
198
199
  }
199
200
  return {
200
201
  kind: "pending",
201
- receipt: s
202
+ receipt: c
202
203
  };
203
204
  }
204
205
  };
205
206
  //#endregion
206
- export { c as AssistantWorkflowClient, s as isWorkflowAssistantAdmissionRefusal };
207
+ export { l as AssistantWorkflowClient, c as isWorkflowAssistantAdmissionRefusal };