@burdenoff/fe-libs 2026.1005.4 → 2026.1006.1
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/index.d.ts +3 -0
- package/dist/shared/assistant/index.d.ts.map +1 -1
- package/dist/shared/assistant/speech/createSpeechEngine.d.ts.map +1 -1
- package/dist/shared/assistant/speech/createSpeechEngine.js +38 -37
- package/dist/shared/assistant/speech/notifyCancellationSpeechEngine.d.ts +4 -0
- package/dist/shared/assistant/speech/notifyCancellationSpeechEngine.d.ts.map +1 -0
- package/dist/shared/assistant/speech/notifyCancellationSpeechEngine.js +38 -0
- package/dist/shared/assistant/ui/WorkflowAssistantPanel.d.ts +14 -0
- package/dist/shared/assistant/ui/WorkflowAssistantPanel.d.ts.map +1 -0
- package/dist/shared/assistant/ui/WorkflowAssistantPanel.js +425 -0
- package/dist/shared/assistant/workflowApi.d.ts +100 -0
- package/dist/shared/assistant/workflowApi.d.ts.map +1 -0
- package/dist/shared/assistant/workflowApi.js +206 -0
- package/dist/shared-assistant.js +202 -199
- package/package.json +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { executeAssistantGraphQLOnce } from './gatewayClient';
|
|
2
|
+
import { AssistantSandboxAuthContext } from './types';
|
|
3
|
+
/** Product configuration selects a server-owned assistant, never a model or workflow override. */
|
|
4
|
+
export type AssistantWorkflowTarget = {
|
|
5
|
+
kind: 'botmanor';
|
|
6
|
+
agentId: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'buildmyiq-course';
|
|
9
|
+
courseId: string;
|
|
10
|
+
};
|
|
11
|
+
export interface WorkflowAssistantTurnInput {
|
|
12
|
+
clientTurnId: string;
|
|
13
|
+
clientConversationId: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
export interface WorkflowAssistantReceipt {
|
|
17
|
+
partialMessage?: string | null;
|
|
18
|
+
id: string;
|
|
19
|
+
clientTurnId: string;
|
|
20
|
+
courseId: string | null;
|
|
21
|
+
status: 'READY' | 'RUNNING' | 'GENERATED' | 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'UNKNOWN';
|
|
22
|
+
historyDelivered: boolean;
|
|
23
|
+
usageDelivered: boolean;
|
|
24
|
+
result: {
|
|
25
|
+
message: string;
|
|
26
|
+
model: string;
|
|
27
|
+
tokensUsed: number;
|
|
28
|
+
sources: {
|
|
29
|
+
reference: number;
|
|
30
|
+
chunkId: string;
|
|
31
|
+
documentId: string;
|
|
32
|
+
knowledgeBaseId: string;
|
|
33
|
+
}[];
|
|
34
|
+
} | null;
|
|
35
|
+
}
|
|
36
|
+
export interface WorkflowAssistantConversationPage {
|
|
37
|
+
nodes: Array<{
|
|
38
|
+
clientConversationId: string;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
}>;
|
|
41
|
+
nextCursor: string | null;
|
|
42
|
+
}
|
|
43
|
+
export interface WorkflowAssistantConversation {
|
|
44
|
+
clientConversationId: string;
|
|
45
|
+
turns: Array<{
|
|
46
|
+
message: string;
|
|
47
|
+
receipt: WorkflowAssistantReceipt;
|
|
48
|
+
}>;
|
|
49
|
+
pending: WorkflowAssistantTurnInput | null;
|
|
50
|
+
}
|
|
51
|
+
export interface WorkflowAssistantRequestContext {
|
|
52
|
+
workspaceId: string;
|
|
53
|
+
authContext?: AssistantSandboxAuthContext;
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
export interface WorkflowAssistantRunHandle {
|
|
57
|
+
runId: string;
|
|
58
|
+
status: string;
|
|
59
|
+
workflowId: string;
|
|
60
|
+
workflowKey: string;
|
|
61
|
+
version: string;
|
|
62
|
+
triggerNodeId: string;
|
|
63
|
+
}
|
|
64
|
+
export type WorkflowAssistantWaitOutcome = {
|
|
65
|
+
kind: 'completed';
|
|
66
|
+
receipt: WorkflowAssistantReceipt;
|
|
67
|
+
} | {
|
|
68
|
+
kind: 'terminal';
|
|
69
|
+
receipt: WorkflowAssistantReceipt;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'pending';
|
|
72
|
+
receipt: WorkflowAssistantReceipt | null;
|
|
73
|
+
};
|
|
74
|
+
/** Only an authoritative admission refusal can release a blocked composer. */
|
|
75
|
+
export declare function isWorkflowAssistantAdmissionRefusal(error: unknown): boolean;
|
|
76
|
+
/** Shared authenticated gateway implementation. There is no sandbox or vendor fallback. */
|
|
77
|
+
export declare class AssistantWorkflowClient {
|
|
78
|
+
private readonly request;
|
|
79
|
+
constructor(request?: typeof executeAssistantGraphQLOnce);
|
|
80
|
+
/** Resolve an LMS route through its owner-filtered server endpoint. */
|
|
81
|
+
courseTargetForEnrollment(enrollmentId: string, context: WorkflowAssistantRequestContext): Promise<Extract<AssistantWorkflowTarget, {
|
|
82
|
+
kind: 'buildmyiq-course';
|
|
83
|
+
}>>;
|
|
84
|
+
start(target: AssistantWorkflowTarget, input: WorkflowAssistantTurnInput, context: WorkflowAssistantRequestContext): Promise<WorkflowAssistantRunHandle>;
|
|
85
|
+
read(target: AssistantWorkflowTarget, clientTurnId: string, context: WorkflowAssistantRequestContext, retryDelivery?: boolean): Promise<WorkflowAssistantReceipt | null>;
|
|
86
|
+
conversations(target: AssistantWorkflowTarget, context: WorkflowAssistantRequestContext, after?: string | null): Promise<WorkflowAssistantConversationPage>;
|
|
87
|
+
conversation(target: AssistantWorkflowTarget, context: WorkflowAssistantRequestContext, clientConversationId?: string | null): Promise<WorkflowAssistantConversation | null>;
|
|
88
|
+
messages(target: AssistantWorkflowTarget, context: WorkflowAssistantRequestContext, clientConversationId: string, before?: string | null): Promise<{
|
|
89
|
+
turns: WorkflowAssistantConversation['turns'];
|
|
90
|
+
nextCursor: string | null;
|
|
91
|
+
}>;
|
|
92
|
+
cancel(clientTurnId: string, context: WorkflowAssistantRequestContext): Promise<boolean>;
|
|
93
|
+
/** A client deadline leaves an admitted turn recoverable; it never regenerates it. */
|
|
94
|
+
wait(target: AssistantWorkflowTarget, clientTurnId: string, context: WorkflowAssistantRequestContext, options?: {
|
|
95
|
+
budgetMs?: number;
|
|
96
|
+
intervalMs?: number;
|
|
97
|
+
onProgress?: (receipt: WorkflowAssistantReceipt) => void;
|
|
98
|
+
}): Promise<WorkflowAssistantWaitOutcome>;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=workflowApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflowApi.d.ts","sourceRoot":"","sources":["../../../src/shared/assistant/workflowApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAE3D,kGAAkG;AAClG,MAAM,MAAM,uBAAuB,GAC/B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AACnD,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;AACD,MAAM,WAAW,wBAAwB;IACvC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;IAC7F,gBAAgB,EAAE,OAAO,CAAC;IAC1B,cAAc,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE;YACP,SAAS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AI,CACR,MAAM,EAAE,uBAAuB,EAC/B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,+BAA+B,EACxC,OAAO,GAAE;QACP,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,IAAI,CAAC;KACrD,GACL,OAAO,CAAC,4BAA4B,CAAC;CAmDzC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { executeAssistantGraphQLOnce as e } from "./gatewayClient.js";
|
|
2
|
+
//#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) {
|
|
5
|
+
return typeof e == "string" && e.length > 0 && e.length <= 255;
|
|
6
|
+
}
|
|
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");
|
|
9
|
+
}
|
|
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));
|
|
12
|
+
}
|
|
13
|
+
function o(e, t, n) {
|
|
14
|
+
if (n === null) return null;
|
|
15
|
+
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
|
+
"READY",
|
|
18
|
+
"RUNNING",
|
|
19
|
+
"GENERATED",
|
|
20
|
+
"COMPLETED",
|
|
21
|
+
"FAILED",
|
|
22
|
+
"CANCELLED",
|
|
23
|
+
"UNKNOWN"
|
|
24
|
+
].includes(n.status)) throw Error("Invalid assistant turn receipt");
|
|
25
|
+
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.status === "COMPLETED" && (!n.result || !n.historyDelivered || !n.usageDelivered)) throw Error("Assistant answer delivery is incomplete");
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
function s(e) {
|
|
31
|
+
if (!e || typeof e != "object" || !("extensions" in e)) return !1;
|
|
32
|
+
let t = e.extensions;
|
|
33
|
+
return !!t && typeof t == "object" && "code" in t && typeof t.code == "string" && [
|
|
34
|
+
"BAD_USER_INPUT",
|
|
35
|
+
"FAILED_PRECONDITION",
|
|
36
|
+
"FORBIDDEN",
|
|
37
|
+
"NOT_FOUND",
|
|
38
|
+
"QUOTA_EXHAUSTED",
|
|
39
|
+
"QUOTA_NOT_PROVISIONED"
|
|
40
|
+
].includes(t.code);
|
|
41
|
+
}
|
|
42
|
+
var c = class {
|
|
43
|
+
request;
|
|
44
|
+
constructor(t = e) {
|
|
45
|
+
this.request = t;
|
|
46
|
+
}
|
|
47
|
+
async courseTargetForEnrollment(e, t) {
|
|
48
|
+
if (!r(e) || !r(t.workspaceId)) throw Error("Invalid assistant enrollment scope");
|
|
49
|
+
let n = await this.request({
|
|
50
|
+
...t,
|
|
51
|
+
operationName: "ReadCourseAssistantTarget",
|
|
52
|
+
query: "query ReadCourseAssistantTarget($enrollmentId: ID!) { buiMyCourseAssistantTarget(enrollmentId: $enrollmentId) { courseId } }",
|
|
53
|
+
variables: { enrollmentId: e }
|
|
54
|
+
});
|
|
55
|
+
if (!r(n.buiMyCourseAssistantTarget?.courseId)) throw Error("Invalid assistant course target");
|
|
56
|
+
return {
|
|
57
|
+
kind: "buildmyiq-course",
|
|
58
|
+
courseId: n.buiMyCourseAssistantTarget.courseId
|
|
59
|
+
};
|
|
60
|
+
}
|
|
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");
|
|
63
|
+
let o = e.kind === "buildmyiq-course", s = o ? "buiStartCourseAssistantTurn" : "startAssistantTurn", c = o ? "BuiCourseAssistantTurnInput" : "StartAssistantTurnInput", l = (await this.request({
|
|
64
|
+
...a,
|
|
65
|
+
operationName: "StartWorkflowAssistantTurn",
|
|
66
|
+
query: `mutation StartWorkflowAssistantTurn($input: ${c}!) { ${s}(input: $input) { ${n} } }`,
|
|
67
|
+
variables: { input: {
|
|
68
|
+
...t,
|
|
69
|
+
...o ? { courseId: e.courseId } : {
|
|
70
|
+
agentId: e.agentId,
|
|
71
|
+
expectedCourseId: null
|
|
72
|
+
}
|
|
73
|
+
} }
|
|
74
|
+
}))[s];
|
|
75
|
+
if (!l || ![
|
|
76
|
+
l.runId,
|
|
77
|
+
l.status,
|
|
78
|
+
l.workflowId,
|
|
79
|
+
l.workflowKey,
|
|
80
|
+
l.version,
|
|
81
|
+
l.triggerNodeId
|
|
82
|
+
].every(r)) throw Error("Assistant admission could not be confirmed; recover with the same turn ID");
|
|
83
|
+
return l;
|
|
84
|
+
}
|
|
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({
|
|
88
|
+
...r,
|
|
89
|
+
operationName: l,
|
|
90
|
+
query: `${a ? "mutation" : "query"} ${l}($clientTurnId: ID!${s ? ", $courseId: ID!" : ""}) {
|
|
91
|
+
${c}(clientTurnId: $clientTurnId${s ? ", courseId: $courseId" : ""}) { ${t} }
|
|
92
|
+
}`,
|
|
93
|
+
variables: {
|
|
94
|
+
clientTurnId: n,
|
|
95
|
+
...s ? { courseId: e.courseId } : {}
|
|
96
|
+
}
|
|
97
|
+
}))[c];
|
|
98
|
+
return o(e, n, u);
|
|
99
|
+
}
|
|
100
|
+
async conversations(e, t, n = null) {
|
|
101
|
+
i(e, "history-list", t);
|
|
102
|
+
let r = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
|
|
103
|
+
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
|
+
...t,
|
|
106
|
+
operationName: "ListWorkflowAssistantConversations",
|
|
107
|
+
query: `query ListWorkflowAssistantConversations($targetId: ID!, $after: ID) { ${o}(${a ? "courseId" : "agentId"}: $targetId, after: $after) { nodes { clientConversationId createdAt } nextCursor } }`,
|
|
108
|
+
variables: {
|
|
109
|
+
targetId: a ? e.courseId : e.agentId,
|
|
110
|
+
after: n
|
|
111
|
+
}
|
|
112
|
+
}))[o];
|
|
113
|
+
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
|
+
return s;
|
|
115
|
+
}
|
|
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,
|
|
120
|
+
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 }
|
|
123
|
+
} }`,
|
|
124
|
+
variables: {
|
|
125
|
+
targetId: a ? e.courseId : e.agentId,
|
|
126
|
+
clientConversationId: r
|
|
127
|
+
}
|
|
128
|
+
}))[s];
|
|
129
|
+
if (l === null) return null;
|
|
130
|
+
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
|
+
let u = /* @__PURE__ */ new Set();
|
|
132
|
+
for (let t of l.turns) {
|
|
133
|
+
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
|
+
}
|
|
136
|
+
let d = l.pending;
|
|
137
|
+
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
|
+
return l;
|
|
139
|
+
}
|
|
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,
|
|
144
|
+
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
|
+
variables: {
|
|
147
|
+
targetId: s ? e.courseId : e.agentId,
|
|
148
|
+
clientConversationId: r,
|
|
149
|
+
before: a
|
|
150
|
+
}
|
|
151
|
+
}))[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
|
+
let u = /* @__PURE__ */ new Set(), d = 0;
|
|
154
|
+
for (let t of l.turns) {
|
|
155
|
+
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
|
+
}
|
|
158
|
+
if (d > 262144) throw Error("Invalid assistant transcript size");
|
|
159
|
+
return l;
|
|
160
|
+
}
|
|
161
|
+
async cancel(e, t) {
|
|
162
|
+
if (!r(t.workspaceId) || !/^[a-zA-Z0-9_.:-]{1,128}$/.test(e)) throw Error("Invalid assistant turn scope");
|
|
163
|
+
return (await this.request({
|
|
164
|
+
...t,
|
|
165
|
+
operationName: "CancelWorkflowAssistantTurn",
|
|
166
|
+
query: "mutation CancelWorkflowAssistantTurn($clientTurnId: ID!) { cancelMyAssistantTurn(clientTurnId: $clientTurnId) }",
|
|
167
|
+
variables: { clientTurnId: e }
|
|
168
|
+
})).cancelMyAssistantTurn === !0;
|
|
169
|
+
}
|
|
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 {
|
|
177
|
+
kind: "completed",
|
|
178
|
+
receipt: s
|
|
179
|
+
};
|
|
180
|
+
if ([
|
|
181
|
+
"FAILED",
|
|
182
|
+
"UNKNOWN",
|
|
183
|
+
"CANCELLED"
|
|
184
|
+
].includes(s.status)) return {
|
|
185
|
+
kind: "terminal",
|
|
186
|
+
receipt: s
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (n.signal?.throwIfAborted(), Date.now() >= o) break;
|
|
190
|
+
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"));
|
|
195
|
+
};
|
|
196
|
+
n.signal?.addEventListener("abort", s, { once: !0 }), n.signal?.aborted && s();
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
kind: "pending",
|
|
201
|
+
receipt: s
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
//#endregion
|
|
206
|
+
export { c as AssistantWorkflowClient, s as isWorkflowAssistantAdmissionRefusal };
|