@paymanai/payman-typescript-ask-sdk 1.2.7 → 1.2.9
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.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +94 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +94 -3
- package/dist/index.native.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -71,10 +71,13 @@ type UseVoiceReturn = {
|
|
|
71
71
|
type MessageRole = "user" | "assistant" | "system";
|
|
72
72
|
type StreamProgress = "started" | "processing" | "completed" | "error";
|
|
73
73
|
type WorkflowStage = "DEV" | "SANDBOX" | "PROD" | "ARCHIVED";
|
|
74
|
+
type UserActionType = "PAYMENT_APPROVAL" | "PAYEE_APPROVAL";
|
|
74
75
|
type UserActionRequest = {
|
|
75
76
|
userActionId: string;
|
|
77
|
+
userActionType?: UserActionType;
|
|
76
78
|
message: string;
|
|
77
79
|
requestedSchema: Record<string, unknown>;
|
|
80
|
+
metadata?: Record<string, string>;
|
|
78
81
|
};
|
|
79
82
|
type UserActionResult = "approved" | "rejected";
|
|
80
83
|
type UserActionState = {
|
|
@@ -123,6 +126,8 @@ type MessageDisplay = {
|
|
|
123
126
|
activeThinkingText?: string;
|
|
124
127
|
/** All thinking accumulated across blocks (for post-stream display) */
|
|
125
128
|
allThinkingText?: string;
|
|
129
|
+
/** True while RAG image URLs are being resolved after the final response is shown */
|
|
130
|
+
isResolvingImages?: boolean;
|
|
126
131
|
};
|
|
127
132
|
type SessionParams = {
|
|
128
133
|
id?: string;
|
|
@@ -138,6 +143,8 @@ type APIConfig = {
|
|
|
138
143
|
headers?: Record<string, string>;
|
|
139
144
|
/** API endpoint for streaming (default: /api/workflows/ask/stream) */
|
|
140
145
|
streamEndpoint?: string;
|
|
146
|
+
/** API endpoint for resolving RAG image URLs (default: /api/playground/ask/resolve-image-urls) */
|
|
147
|
+
resolveImagesEndpoint?: string;
|
|
141
148
|
};
|
|
142
149
|
type ChatConfig = {
|
|
143
150
|
/** API configuration - required for the library to make calls */
|
|
@@ -301,8 +308,10 @@ type StreamEvent = {
|
|
|
301
308
|
elapsedMs?: number;
|
|
302
309
|
userActionRequest?: {
|
|
303
310
|
userActionId: string;
|
|
311
|
+
userActionType?: string;
|
|
304
312
|
message: string;
|
|
305
313
|
requestedSchema: Record<string, unknown>;
|
|
314
|
+
metadata?: Record<string, string>;
|
|
306
315
|
};
|
|
307
316
|
[key: string]: unknown;
|
|
308
317
|
};
|
|
@@ -334,4 +343,4 @@ declare function cancelUserAction(config: ChatConfig, userActionId: string): Pro
|
|
|
334
343
|
*/
|
|
335
344
|
declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
336
345
|
|
|
337
|
-
export { type APIConfig, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageRole, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatReturn, type UseVoiceReturn, type UserActionRequest, type UserActionResult, type UserActionState, type VoiceCallbacks, type VoiceConfig, type VoicePermissions, type VoiceResult, type VoiceState, type WorkflowStage, cancelUserAction, generateId, resendUserAction, streamWorkflowEvents, submitUserAction, useChat, useVoice };
|
|
346
|
+
export { type APIConfig, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageRole, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatReturn, type UseVoiceReturn, type UserActionRequest, type UserActionResult, type UserActionState, type UserActionType, type VoiceCallbacks, type VoiceConfig, type VoicePermissions, type VoiceResult, type VoiceState, type WorkflowStage, cancelUserAction, generateId, resendUserAction, streamWorkflowEvents, submitUserAction, useChat, useVoice };
|
package/dist/index.d.ts
CHANGED
|
@@ -71,10 +71,13 @@ type UseVoiceReturn = {
|
|
|
71
71
|
type MessageRole = "user" | "assistant" | "system";
|
|
72
72
|
type StreamProgress = "started" | "processing" | "completed" | "error";
|
|
73
73
|
type WorkflowStage = "DEV" | "SANDBOX" | "PROD" | "ARCHIVED";
|
|
74
|
+
type UserActionType = "PAYMENT_APPROVAL" | "PAYEE_APPROVAL";
|
|
74
75
|
type UserActionRequest = {
|
|
75
76
|
userActionId: string;
|
|
77
|
+
userActionType?: UserActionType;
|
|
76
78
|
message: string;
|
|
77
79
|
requestedSchema: Record<string, unknown>;
|
|
80
|
+
metadata?: Record<string, string>;
|
|
78
81
|
};
|
|
79
82
|
type UserActionResult = "approved" | "rejected";
|
|
80
83
|
type UserActionState = {
|
|
@@ -123,6 +126,8 @@ type MessageDisplay = {
|
|
|
123
126
|
activeThinkingText?: string;
|
|
124
127
|
/** All thinking accumulated across blocks (for post-stream display) */
|
|
125
128
|
allThinkingText?: string;
|
|
129
|
+
/** True while RAG image URLs are being resolved after the final response is shown */
|
|
130
|
+
isResolvingImages?: boolean;
|
|
126
131
|
};
|
|
127
132
|
type SessionParams = {
|
|
128
133
|
id?: string;
|
|
@@ -138,6 +143,8 @@ type APIConfig = {
|
|
|
138
143
|
headers?: Record<string, string>;
|
|
139
144
|
/** API endpoint for streaming (default: /api/workflows/ask/stream) */
|
|
140
145
|
streamEndpoint?: string;
|
|
146
|
+
/** API endpoint for resolving RAG image URLs (default: /api/playground/ask/resolve-image-urls) */
|
|
147
|
+
resolveImagesEndpoint?: string;
|
|
141
148
|
};
|
|
142
149
|
type ChatConfig = {
|
|
143
150
|
/** API configuration - required for the library to make calls */
|
|
@@ -301,8 +308,10 @@ type StreamEvent = {
|
|
|
301
308
|
elapsedMs?: number;
|
|
302
309
|
userActionRequest?: {
|
|
303
310
|
userActionId: string;
|
|
311
|
+
userActionType?: string;
|
|
304
312
|
message: string;
|
|
305
313
|
requestedSchema: Record<string, unknown>;
|
|
314
|
+
metadata?: Record<string, string>;
|
|
306
315
|
};
|
|
307
316
|
[key: string]: unknown;
|
|
308
317
|
};
|
|
@@ -334,4 +343,4 @@ declare function cancelUserAction(config: ChatConfig, userActionId: string): Pro
|
|
|
334
343
|
*/
|
|
335
344
|
declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
336
345
|
|
|
337
|
-
export { type APIConfig, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageRole, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatReturn, type UseVoiceReturn, type UserActionRequest, type UserActionResult, type UserActionState, type VoiceCallbacks, type VoiceConfig, type VoicePermissions, type VoiceResult, type VoiceState, type WorkflowStage, cancelUserAction, generateId, resendUserAction, streamWorkflowEvents, submitUserAction, useChat, useVoice };
|
|
346
|
+
export { type APIConfig, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageRole, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatReturn, type UseVoiceReturn, type UserActionRequest, type UserActionResult, type UserActionState, type UserActionType, type VoiceCallbacks, type VoiceConfig, type VoicePermissions, type VoiceResult, type VoiceState, type WorkflowStage, cancelUserAction, generateId, resendUserAction, streamWorkflowEvents, submitUserAction, useChat, useVoice };
|
package/dist/index.js
CHANGED
|
@@ -336,8 +336,10 @@ function processStreamEvent(event, state) {
|
|
|
336
336
|
if (event.userActionRequest) {
|
|
337
337
|
state.userActionRequest = {
|
|
338
338
|
userActionId: event.userActionRequest.userActionId,
|
|
339
|
+
userActionType: event.userActionRequest.userActionType,
|
|
339
340
|
message: event.userActionRequest.message,
|
|
340
|
-
requestedSchema: event.userActionRequest.requestedSchema
|
|
341
|
+
requestedSchema: event.userActionRequest.requestedSchema,
|
|
342
|
+
metadata: event.userActionRequest.metadata
|
|
341
343
|
};
|
|
342
344
|
}
|
|
343
345
|
state.userActionPending = true;
|
|
@@ -529,7 +531,8 @@ function createFinalMessage(streamingId, state) {
|
|
|
529
531
|
currentExecutingStepId: void 0,
|
|
530
532
|
userActionResult: state.userActionResult,
|
|
531
533
|
activeThinkingText: void 0,
|
|
532
|
-
allThinkingText: state.hasError ? void 0 : state.allThinkingText
|
|
534
|
+
allThinkingText: state.hasError ? void 0 : state.allThinkingText,
|
|
535
|
+
isResolvingImages: state.hasError ? void 0 : state.isResolvingImages
|
|
533
536
|
};
|
|
534
537
|
}
|
|
535
538
|
function createCancelledMessageUpdate(steps, currentMessage) {
|
|
@@ -583,6 +586,16 @@ function buildUserActionUrl(config, userActionId, action) {
|
|
|
583
586
|
const encodedUserActionId = encodeURIComponent(userActionId);
|
|
584
587
|
return `${config.api.baseUrl}${basePath}/user-action/${encodedUserActionId}/${action}`;
|
|
585
588
|
}
|
|
589
|
+
function buildResolveImagesUrl(config) {
|
|
590
|
+
if (config.api.resolveImagesEndpoint) {
|
|
591
|
+
return `${config.api.baseUrl}${config.api.resolveImagesEndpoint}`;
|
|
592
|
+
}
|
|
593
|
+
const streamEndpoint = config.api.streamEndpoint || "/api/workflows/ask/stream";
|
|
594
|
+
const [endpointPath] = streamEndpoint.split("?");
|
|
595
|
+
const normalizedEndpointPath = endpointPath.replace(/\/+$/, "");
|
|
596
|
+
const basePath = normalizedEndpointPath.endsWith("/stream") ? normalizedEndpointPath.slice(0, -"/stream".length) : normalizedEndpointPath;
|
|
597
|
+
return `${config.api.baseUrl}${basePath}/resolve-image-urls`;
|
|
598
|
+
}
|
|
586
599
|
function buildRequestHeaders(config) {
|
|
587
600
|
const headers = {
|
|
588
601
|
...config.api.headers
|
|
@@ -697,6 +710,58 @@ var activeStreamStore = {
|
|
|
697
710
|
streams.delete(key);
|
|
698
711
|
}
|
|
699
712
|
};
|
|
713
|
+
|
|
714
|
+
// src/utils/ragImageResolver.ts
|
|
715
|
+
var RAG_IMAGE_REGEX = /\/api\/rag\/chunks\/[^"'\s]+\/image/;
|
|
716
|
+
function hasRagImages(content) {
|
|
717
|
+
return RAG_IMAGE_REGEX.test(content);
|
|
718
|
+
}
|
|
719
|
+
async function waitForNextPaint(signal) {
|
|
720
|
+
if (signal?.aborted) return;
|
|
721
|
+
await new Promise((resolve) => {
|
|
722
|
+
let isSettled = false;
|
|
723
|
+
const finish = () => {
|
|
724
|
+
if (isSettled) return;
|
|
725
|
+
isSettled = true;
|
|
726
|
+
signal?.removeEventListener("abort", finish);
|
|
727
|
+
resolve();
|
|
728
|
+
};
|
|
729
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
730
|
+
if (typeof requestAnimationFrame === "function") {
|
|
731
|
+
requestAnimationFrame(() => {
|
|
732
|
+
setTimeout(finish, 0);
|
|
733
|
+
});
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
setTimeout(finish, 0);
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
async function resolveRagImageUrls(config, content, signal) {
|
|
740
|
+
const url = buildResolveImagesUrl(config);
|
|
741
|
+
const baseHeaders = buildRequestHeaders(config);
|
|
742
|
+
const headers = { "Content-Type": "application/json", ...baseHeaders };
|
|
743
|
+
const response = await fetch(url, {
|
|
744
|
+
method: "POST",
|
|
745
|
+
headers,
|
|
746
|
+
body: JSON.stringify({ input: content }),
|
|
747
|
+
signal
|
|
748
|
+
});
|
|
749
|
+
if (!response.ok) {
|
|
750
|
+
const errorText = await response.text();
|
|
751
|
+
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
752
|
+
}
|
|
753
|
+
const text = await response.text();
|
|
754
|
+
try {
|
|
755
|
+
const parsed = JSON.parse(text);
|
|
756
|
+
if (typeof parsed === "string") return parsed;
|
|
757
|
+
if (typeof parsed.output === "string") return parsed.output;
|
|
758
|
+
if (typeof parsed.result === "string") return parsed.result;
|
|
759
|
+
} catch {
|
|
760
|
+
}
|
|
761
|
+
return text;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/hooks/useStreamManager.ts
|
|
700
765
|
function useStreamManager(config, callbacks, setMessages, setIsWaitingForResponse) {
|
|
701
766
|
const abortControllerRef = react.useRef(null);
|
|
702
767
|
const configRef = react.useRef(config);
|
|
@@ -862,9 +927,11 @@ function useStreamManager(config, callbacks, setMessages, setIsWaitingForRespons
|
|
|
862
927
|
if (state.currentSessionId && state.currentSessionId !== sessionId) {
|
|
863
928
|
callbacksRef.current.onSessionIdChange?.(state.currentSessionId);
|
|
864
929
|
}
|
|
930
|
+
const needsImageResolve = !state.hasError && !abortController.signal.aborted && hasRagImages(state.accumulatedContent);
|
|
865
931
|
const finalMessage = createFinalMessage(streamingId, {
|
|
866
932
|
...state,
|
|
867
|
-
sessionId: state.currentSessionId || sessionId
|
|
933
|
+
sessionId: state.currentSessionId || sessionId,
|
|
934
|
+
isResolvingImages: needsImageResolve
|
|
868
935
|
});
|
|
869
936
|
setMessages(
|
|
870
937
|
(prev) => prev.map(
|
|
@@ -875,6 +942,30 @@ function useStreamManager(config, callbacks, setMessages, setIsWaitingForRespons
|
|
|
875
942
|
}
|
|
876
943
|
});
|
|
877
944
|
clearThrottle();
|
|
945
|
+
const shouldResolveImages = !abortController.signal.aborted && !state.hasError && hasRagImages(state.accumulatedContent);
|
|
946
|
+
if (shouldResolveImages) {
|
|
947
|
+
await waitForNextPaint(abortController.signal);
|
|
948
|
+
}
|
|
949
|
+
if (shouldResolveImages && !abortController.signal.aborted) {
|
|
950
|
+
try {
|
|
951
|
+
const resolvedContent = await resolveRagImageUrls(
|
|
952
|
+
currentConfig,
|
|
953
|
+
state.accumulatedContent,
|
|
954
|
+
abortController.signal
|
|
955
|
+
);
|
|
956
|
+
setMessages(
|
|
957
|
+
(prev) => prev.map(
|
|
958
|
+
(msg) => msg.id === streamingId ? { ...msg, content: resolvedContent, isResolvingImages: false } : msg
|
|
959
|
+
)
|
|
960
|
+
);
|
|
961
|
+
} catch {
|
|
962
|
+
setMessages(
|
|
963
|
+
(prev) => prev.map(
|
|
964
|
+
(msg) => msg.id === streamingId ? { ...msg, isResolvingImages: false } : msg
|
|
965
|
+
)
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
878
969
|
return state.currentSessionId;
|
|
879
970
|
} catch (error) {
|
|
880
971
|
clearThrottle();
|