@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.
- package/dist/shared/assistant/abortSignal.d.ts +2 -0
- package/dist/shared/assistant/abortSignal.js +9 -0
- package/dist/shared/assistant/history/historyEngine.js +424 -423
- package/dist/shared/assistant/index.d.ts +1 -0
- package/dist/shared/assistant/speech/hostedTtsSpeechEngine.js +137 -136
- package/dist/shared/assistant/workflowApi.js +71 -70
- package/dist/shared-assistant.js +345 -344
- package/package.json +1 -1
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
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
|
|
4
|
-
function
|
|
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
|
|
8
|
-
if (!
|
|
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
|
|
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 &&
|
|
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
|
|
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 (!
|
|
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 && !
|
|
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
|
|
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
|
|
43
|
+
var l = class {
|
|
43
44
|
request;
|
|
44
|
-
constructor(
|
|
45
|
-
this.request =
|
|
45
|
+
constructor(e = t) {
|
|
46
|
+
this.request = e;
|
|
46
47
|
}
|
|
47
48
|
async courseTargetForEnrollment(e, t) {
|
|
48
|
-
if (!
|
|
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 (!
|
|
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,
|
|
62
|
-
if (
|
|
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
|
-
...
|
|
65
|
+
...n,
|
|
65
66
|
operationName: "StartWorkflowAssistantTurn",
|
|
66
|
-
query: `mutation StartWorkflowAssistantTurn($input: ${c}!) { ${s}(input: $input) { ${
|
|
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(
|
|
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,
|
|
86
|
-
|
|
87
|
-
let
|
|
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: `${
|
|
91
|
-
${c}(clientTurnId: $clientTurnId${
|
|
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:
|
|
95
|
-
...
|
|
95
|
+
clientTurnId: t,
|
|
96
|
+
...o ? { courseId: e.courseId } : {}
|
|
96
97
|
}
|
|
97
98
|
}))[c];
|
|
98
|
-
return
|
|
99
|
+
return s(e, t, u);
|
|
99
100
|
}
|
|
100
101
|
async conversations(e, t, n = null) {
|
|
101
|
-
|
|
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
|
|
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}(${
|
|
108
|
+
query: `query ListWorkflowAssistantConversations($targetId: ID!, $after: ID) { ${o}(${i ? "courseId" : "agentId"}: $targetId, after: $after) { nodes { clientConversationId createdAt } nextCursor } }`,
|
|
108
109
|
variables: {
|
|
109
|
-
targetId:
|
|
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,
|
|
117
|
-
if (
|
|
118
|
-
let
|
|
119
|
-
...
|
|
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) { ${
|
|
122
|
-
clientConversationId turns { message receipt { ${
|
|
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:
|
|
126
|
+
targetId: i ? e.courseId : e.agentId,
|
|
126
127
|
clientConversationId: r
|
|
127
128
|
}
|
|
128
|
-
}))[
|
|
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
|
-
|
|
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,
|
|
141
|
-
if (
|
|
142
|
-
let
|
|
143
|
-
...
|
|
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}(${
|
|
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:
|
|
148
|
+
targetId: o ? e.courseId : e.agentId,
|
|
148
149
|
clientConversationId: r,
|
|
149
|
-
before:
|
|
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 ===
|
|
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
|
-
|
|
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 (!
|
|
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(
|
|
171
|
-
let
|
|
172
|
-
if (!Number.isInteger(
|
|
173
|
-
let
|
|
174
|
-
for (; Date.now() <
|
|
175
|
-
if (
|
|
176
|
-
if (
|
|
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:
|
|
179
|
+
receipt: c
|
|
179
180
|
};
|
|
180
181
|
if ([
|
|
181
182
|
"FAILED",
|
|
182
183
|
"UNKNOWN",
|
|
183
184
|
"CANCELLED"
|
|
184
|
-
].includes(
|
|
185
|
+
].includes(c.status)) return {
|
|
185
186
|
kind: "terminal",
|
|
186
|
-
receipt:
|
|
187
|
+
receipt: c
|
|
187
188
|
};
|
|
188
189
|
}
|
|
189
|
-
if (
|
|
190
|
+
if (e(r.signal), Date.now() >= s) break;
|
|
190
191
|
await new Promise((e, t) => {
|
|
191
|
-
let
|
|
192
|
-
|
|
193
|
-
}, Math.min(
|
|
194
|
-
clearTimeout(i),
|
|
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
|
-
|
|
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:
|
|
202
|
+
receipt: c
|
|
202
203
|
};
|
|
203
204
|
}
|
|
204
205
|
};
|
|
205
206
|
//#endregion
|
|
206
|
-
export {
|
|
207
|
+
export { l as AssistantWorkflowClient, c as isWorkflowAssistantAdmissionRefusal };
|