@paymanai/payman-typescript-ask-sdk 1.2.2 → 1.2.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/index.js +41 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -21
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +41 -21
- package/dist/index.native.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -207,11 +207,25 @@ function processStreamEvent(event, state) {
|
|
|
207
207
|
}
|
|
208
208
|
state.activeThinkingText = void 0;
|
|
209
209
|
}
|
|
210
|
-
if (
|
|
211
|
-
|
|
210
|
+
if (eventType === "COMPLETED" || eventType === "WORKFLOW_COMPLETED") {
|
|
211
|
+
let content = extractResponseContent(event.response);
|
|
212
|
+
const trace = event.trace && typeof event.trace === "object" ? event.trace : null;
|
|
213
|
+
if (!content && trace?.workflowMsg && typeof trace.workflowMsg === "string") {
|
|
214
|
+
content = trace.workflowMsg;
|
|
215
|
+
}
|
|
216
|
+
if (!content && trace?.aggregator && typeof trace.aggregator === "object") {
|
|
217
|
+
const agg = trace.aggregator;
|
|
218
|
+
if (typeof agg.response === "string") content = agg.response;
|
|
219
|
+
else content = extractResponseContent(agg.response);
|
|
220
|
+
}
|
|
212
221
|
if (content) {
|
|
213
222
|
state.accumulatedContent = content;
|
|
214
|
-
state.finalData = event.response;
|
|
223
|
+
state.finalData = event.response ?? event.trace;
|
|
224
|
+
state.hasError = false;
|
|
225
|
+
state.errorMessage = "";
|
|
226
|
+
} else {
|
|
227
|
+
state.hasError = true;
|
|
228
|
+
state.errorMessage = "WORKFLOW_FAILED";
|
|
215
229
|
}
|
|
216
230
|
}
|
|
217
231
|
if (eventType === "STARTED" || eventType === "WORKFLOW_STARTED") ; else if (eventType === "COMPLETED" || eventType === "WORKFLOW_COMPLETED") {
|
|
@@ -221,7 +235,6 @@ function processStreamEvent(event, state) {
|
|
|
221
235
|
}
|
|
222
236
|
});
|
|
223
237
|
} else if (eventType === "INTENT_ERROR") {
|
|
224
|
-
state.hasError = true;
|
|
225
238
|
state.errorMessage = message || event.errorMessage || "An error occurred";
|
|
226
239
|
const intentStep = state.steps.find(
|
|
227
240
|
(s) => s.eventType === "INTENT_STARTED" && s.status === "in_progress"
|
|
@@ -233,6 +246,7 @@ function processStreamEvent(event, state) {
|
|
|
233
246
|
state.hasError = true;
|
|
234
247
|
state.errorMessage = message || event.errorMessage || "An error occurred";
|
|
235
248
|
} else if (eventType === "ORCHESTRATOR_COMPLETED") {
|
|
249
|
+
state.inOrchestratorPhase = false;
|
|
236
250
|
const orchestratorStep = state.steps.find(
|
|
237
251
|
(s) => s.eventType === "ORCHESTRATOR_THINKING" && s.status === "in_progress"
|
|
238
252
|
);
|
|
@@ -259,6 +273,7 @@ function processStreamEvent(event, state) {
|
|
|
259
273
|
}
|
|
260
274
|
}
|
|
261
275
|
} else if (eventType === "AGGREGATOR_COMPLETED") {
|
|
276
|
+
state.inAggregatorPhase = false;
|
|
262
277
|
const aggregatorStep = state.steps.find(
|
|
263
278
|
(s) => s.eventType === "AGGREGATOR_THINKING" && s.status === "in_progress"
|
|
264
279
|
);
|
|
@@ -272,6 +287,12 @@ function processStreamEvent(event, state) {
|
|
|
272
287
|
}
|
|
273
288
|
}
|
|
274
289
|
} else if (eventType === "ORCHESTRATOR_THINKING" || eventType === "INTENT_STARTED" || eventType === "INTENT_PROGRESS" || eventType === "AGGREGATOR_THINKING") {
|
|
290
|
+
if (eventType === "ORCHESTRATOR_THINKING") {
|
|
291
|
+
state.inOrchestratorPhase = true;
|
|
292
|
+
}
|
|
293
|
+
if (eventType === "AGGREGATOR_THINKING") {
|
|
294
|
+
state.inAggregatorPhase = true;
|
|
295
|
+
}
|
|
275
296
|
if (eventType === "INTENT_PROGRESS") {
|
|
276
297
|
const intentStep = state.steps.find(
|
|
277
298
|
(s) => s.eventType === "INTENT_STARTED" && s.status === "in_progress"
|
|
@@ -420,8 +441,10 @@ function processStreamEvent(event, state) {
|
|
|
420
441
|
} else {
|
|
421
442
|
state.currentThinkingStepId = void 0;
|
|
422
443
|
}
|
|
423
|
-
state.activeThinkingText = "";
|
|
424
444
|
if (state.allThinkingText) state.allThinkingText += "\n\n";
|
|
445
|
+
if (!state.inOrchestratorPhase && !state.inAggregatorPhase) {
|
|
446
|
+
state.activeThinkingText = "";
|
|
447
|
+
}
|
|
425
448
|
} else if (eventType === "INTENT_THINKING_CONT") {
|
|
426
449
|
const delta = event.message || "";
|
|
427
450
|
if (!delta) return state;
|
|
@@ -431,23 +454,22 @@ function processStreamEvent(event, state) {
|
|
|
431
454
|
step.thinkingText = (step.thinkingText || "") + delta;
|
|
432
455
|
}
|
|
433
456
|
}
|
|
434
|
-
if (state.activeThinkingText == null) state.activeThinkingText = "";
|
|
435
|
-
state.activeThinkingText += delta;
|
|
436
457
|
state.allThinkingText += delta;
|
|
458
|
+
if (!state.inOrchestratorPhase && !state.inAggregatorPhase) {
|
|
459
|
+
if (state.activeThinkingText == null) state.activeThinkingText = "";
|
|
460
|
+
state.activeThinkingText += delta;
|
|
461
|
+
}
|
|
437
462
|
}
|
|
438
463
|
return state;
|
|
439
464
|
}
|
|
440
465
|
|
|
441
466
|
// src/utils/messageStateManager.ts
|
|
467
|
+
var FRIENDLY_ERROR_MESSAGE = "Oops, something went wrong. Please try again.";
|
|
442
468
|
function createStreamingMessageUpdate(state) {
|
|
443
469
|
const hasCompletedContent = state.accumulatedContent && state.finalData !== void 0;
|
|
444
470
|
return {
|
|
445
|
-
streamingContent: state.hasError ?
|
|
446
|
-
|
|
447
|
-
${state.errorMessage}` : hasCompletedContent ? state.accumulatedContent : "",
|
|
448
|
-
content: state.hasError ? `Oops, something went wrong. Please try again.
|
|
449
|
-
|
|
450
|
-
${state.errorMessage}` : "",
|
|
471
|
+
streamingContent: state.hasError ? FRIENDLY_ERROR_MESSAGE : hasCompletedContent ? state.accumulatedContent : "",
|
|
472
|
+
content: state.hasError ? FRIENDLY_ERROR_MESSAGE : "",
|
|
451
473
|
currentMessage: state.hasError ? void 0 : state.currentMessage,
|
|
452
474
|
streamProgress: state.hasError ? "error" : "processing",
|
|
453
475
|
isError: state.hasError,
|
|
@@ -470,9 +492,7 @@ function createErrorMessageUpdate(error, state) {
|
|
|
470
492
|
isError: !isAborted,
|
|
471
493
|
isCancelled: isAborted,
|
|
472
494
|
errorDetails: isAborted ? void 0 : error.message,
|
|
473
|
-
content: isAborted ? state.accumulatedContent || "" : state.accumulatedContent ||
|
|
474
|
-
|
|
475
|
-
${error.message}`,
|
|
495
|
+
content: isAborted ? state.accumulatedContent || "" : state.accumulatedContent || FRIENDLY_ERROR_MESSAGE,
|
|
476
496
|
// Preserve currentMessage when cancelled so UI can show it
|
|
477
497
|
currentMessage: isAborted ? state.currentMessage || "Thinking..." : void 0,
|
|
478
498
|
steps: [...state.steps].map((step) => {
|
|
@@ -489,9 +509,7 @@ function createFinalMessage(streamingId, state) {
|
|
|
489
509
|
id: streamingId,
|
|
490
510
|
sessionId: state.sessionId,
|
|
491
511
|
role: "assistant",
|
|
492
|
-
content: state.hasError ?
|
|
493
|
-
|
|
494
|
-
${state.errorMessage}` : state.accumulatedContent || "",
|
|
512
|
+
content: state.hasError ? FRIENDLY_ERROR_MESSAGE : state.accumulatedContent || "",
|
|
495
513
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
496
514
|
isStreaming: false,
|
|
497
515
|
streamProgress: state.hasError ? "error" : "completed",
|
|
@@ -619,7 +637,9 @@ function useStreamManager(config, callbacks, setMessages, setIsWaitingForRespons
|
|
|
619
637
|
userActionRequest: void 0,
|
|
620
638
|
userActionPending: false,
|
|
621
639
|
userActionResult: void 0,
|
|
622
|
-
allThinkingText: ""
|
|
640
|
+
allThinkingText: "",
|
|
641
|
+
inOrchestratorPhase: false,
|
|
642
|
+
inAggregatorPhase: false
|
|
623
643
|
};
|
|
624
644
|
const THROTTLE_MS = 120;
|
|
625
645
|
const CHARS_PER_TICK = 10;
|
|
@@ -700,7 +720,7 @@ function useStreamManager(config, callbacks, setMessages, setIsWaitingForRespons
|
|
|
700
720
|
}
|
|
701
721
|
const isIntentThinkingEvent = eventType === "INTENT_THINKING" || eventType === "INTENT_THINKING_CONT";
|
|
702
722
|
const rawMessage = event.message?.trim() || event.errorMessage?.trim();
|
|
703
|
-
const currentMessage = isIntentThinkingEvent ? getActiveStepMessage() || "Thinking..." : rawMessage || (event.eventType?.startsWith("USER_ACTION_") ? getEventMessage(event) :
|
|
723
|
+
const currentMessage = isIntentThinkingEvent ? getActiveStepMessage() || "Thinking..." : rawMessage || (event.eventType?.startsWith("USER_ACTION_") ? getEventMessage(event) : getActiveStepMessage() || getEventMessage(event));
|
|
704
724
|
const displayThinking = state.activeThinkingText != null ? state.activeThinkingText.slice(0, displayedLengthRef.current) : state.activeThinkingText;
|
|
705
725
|
setMessages(
|
|
706
726
|
(prev) => prev.map(
|