flare-chat-core 0.2.3 → 0.2.5
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 +6372 -0
- package/package.json +19 -22
- package/docs/CAPABILITY-INVENTORY.md +0 -42
- package/docs/CHAT-CORE-BOUNDARY.md +0 -47
- package/docs/CORE-APP-REALIGNMENT-WORKLOAD-2026-04-18.md +0 -86
- package/docs/SSOT-CHAT-CORE-BOUNDARY.md +0 -73
- package/docs/SSOT-CHAT-CORE-DATAFLOW.md +0 -97
- package/index.html +0 -12
- package/scripts/check.sh +0 -15
- package/src/adapters/index.js +0 -6
- package/src/adapters/message-api.adapter.js +0 -59
- package/src/adapters/session-api.adapter.js +0 -133
- package/src/adapters/session-message-api.http.js +0 -161
- package/src/adapters/session-message-api.js +0 -34
- package/src/adapters/session-message-api.normalize-source-record.test.mjs +0 -180
- package/src/adapters/session-message-api.normalizers.js +0 -153
- package/src/adapters/source-api.adapter.js +0 -135
- package/src/adapters/sse-client.js +0 -244
- package/src/adapters/sse-event-dispatcher.js +0 -121
- package/src/app/App.jsx +0 -11
- package/src/app/AppProviders.jsx +0 -12
- package/src/app/ChatWorkspaceScreen.jsx +0 -33
- package/src/app/WorkspaceLayout.jsx +0 -190
- package/src/app/components/AppCanvasPanel.jsx +0 -64
- package/src/app/components/TriggerThresholdPopoverContent.jsx +0 -122
- package/src/app/components/WorkspaceBodySection.jsx +0 -156
- package/src/app/components/WorkspaceMainPane.jsx +0 -121
- package/src/app/components/WorkspaceSessionPane.jsx +0 -70
- package/src/app/components/WorkspaceTopBarSection.jsx +0 -71
- package/src/app/core-chat-entry/ComposerSectionNode.jsx +0 -241
- package/src/app/core-chat-entry/attachmentSendRefs.js +0 -154
- package/src/app/core-chat-entry/attachmentSendRefs.test.mjs +0 -101
- package/src/app/core-chat-entry/composerActionRouter.js +0 -26
- package/src/app/core-chat-entry/constants.js +0 -108
- package/src/app/core-chat-entry/selectors.js +0 -28
- package/src/app/core-chat-entry/useAppActionErrorGuards.js +0 -68
- package/src/app/core-chat-entry/useChatCorePipelines.js +0 -110
- package/src/app/core-chat-entry/useComposerModeSuggestion.js +0 -89
- package/src/app/core-chat-entry/useDevCapabilityStatusNote.js +0 -22
- package/src/app/core-chat-entry/useProjectNameEditing.js +0 -41
- package/src/app/core-chat-entry/useProjectSourceUpload.js +0 -341
- package/src/app/core-chat-entry/useRealApiReadinessGate.js +0 -103
- package/src/app/core-chat-entry/useUnavailableActionError.js +0 -29
- package/src/app/core-chat-entry/useWorkspaceCanvasController.jsx +0 -177
- package/src/app/core-chat-entry/useWorkspaceCanvasProjection.jsx +0 -171
- package/src/app/core-chat-entry/useWorkspaceComposerController.jsx +0 -199
- package/src/app/core-chat-entry/useWorkspaceController.jsx +0 -226
- package/src/app/core-chat-entry/useWorkspacePanels.js +0 -55
- package/src/app/hooks/useComposerAttachmentSync.js +0 -223
- package/src/app/hooks/useComposerChooserHandlers.js +0 -52
- package/src/app/hooks/useSendWithContextRefs.js +0 -140
- package/src/app/hooks/useSendWithContextRefs.test.mjs +0 -29
- package/src/app/hooks/useUserThresholdProfile.js +0 -121
- package/src/app/index.js +0 -1
- package/src/app/selectors/assistantTextSelector.js +0 -73
- package/src/app/selectors/canvasEvidenceSummarySelector.js +0 -28
- package/src/app/selectors/canvasReportTemplateSelector.js +0 -28
- package/src/app/selectors/canvasTabsSelector.js +0 -58
- package/src/app/selectors/evidenceProjectionSelector.js +0 -175
- package/src/app/selectors/evidenceProjectionSelector.test.mjs +0 -107
- package/src/app/selectors/modeSuggestionSelector.js +0 -50
- package/src/chat-core/app/mockRuntime.js +0 -291
- package/src/chat-core/app/useAppStream.js +0 -187
- package/src/chat-core/app/useAppStream.refs.test.mjs +0 -44
- package/src/chat-core/app/useAppStream.request-body.test.mjs +0 -116
- package/src/chat-core/app/useCoreChatApp.js +0 -115
- package/src/chat-core/facade/useBasicConversationFacade.js +0 -280
- package/src/chat-core/index.js +0 -14
- package/src/chat-core/input/useChatInput.js +0 -103
- package/src/chat-core/messages/buildTimelineItems.analysis-route.test.mjs +0 -36
- package/src/chat-core/messages/buildTimelineItems.js +0 -201
- package/src/chat-core/messages/buildTimelineItems.knowledge-citation.test.mjs +0 -182
- package/src/chat-core/messages/contextUsageDefaults.js +0 -3
- package/src/chat-core/messages/contextUsageViewModel.js +0 -147
- package/src/chat-core/messages/contextUsageViewModel.test.mjs +0 -74
- package/src/chat-core/messages/useContextUsageViewModel.js +0 -41
- package/src/chat-core/orchestration/useBasicSendHandler.js +0 -55
- package/src/chat-core/pipelines/build-action-request.js +0 -46
- package/src/chat-core/pipelines/build-stream-request.js +0 -74
- package/src/chat-core/pipelines/entity-extraction.js +0 -159
- package/src/chat-core/pipelines/preprocess-message.js +0 -16
- package/src/chat-core/pipelines/stream-persist-utils.js +0 -32
- package/src/chat-core/pipelines/transport/send-mock-stream.js +0 -86
- package/src/chat-core/pipelines/transport/send-real-stream.js +0 -330
- package/src/chat-core/pipelines/transport/send-real-stream.test.mjs +0 -27
- package/src/chat-core/pipelines/transport/send-sourcing-search.js +0 -86
- package/src/chat-core/pipelines/transport/send-sourcing-search.test.mjs +0 -14
- package/src/chat-core/pipelines/transport/sourcing-response-templates.js +0 -55
- package/src/chat-core/pipelines/transport/sourcing-search-api.js +0 -155
- package/src/chat-core/runtime/runtimeMode.js +0 -69
- package/src/chat-core/session/chatSessionActionTypes.js +0 -24
- package/src/chat-core/session/chatSessionReducer.js +0 -352
- package/src/chat-core/session/chatSessionReducer.streaming-done.test.mjs +0 -39
- package/src/chat-core/session/index.js +0 -2
- package/src/chat-core/session/sessionActionsMessages.js +0 -44
- package/src/chat-core/session/sessionActionsSessionCrud.js +0 -131
- package/src/chat-core/session/sessionActionsStreaming.js +0 -80
- package/src/chat-core/session/sessionActionsUiState.js +0 -51
- package/src/chat-core/session/useChatSessionReducer.js +0 -131
- package/src/chat-core/session/useSessionListController.js +0 -67
- package/src/chat-core/stream/sse-client.js +0 -1
- package/src/chat-core/stream/sse-event-dispatcher.js +0 -1
- package/src/chat-core/stream/sse-events.js +0 -1
- package/src/chat-core/stream/useSSEStream.js +0 -1
- package/src/chat-core/stream/useStreamSendController.js +0 -46
- package/src/contracts/context-ssot.js +0 -47
- package/src/contracts/index.js +0 -1
- package/src/contracts/sse-events/base-parsers.js +0 -79
- package/src/contracts/sse-events/domain-parsers.js +0 -3
- package/src/contracts/sse-events/internal-normalizers.js +0 -143
- package/src/contracts/sse-events/parsers-intake.js +0 -235
- package/src/contracts/sse-events/parsers-runtime.js +0 -37
- package/src/contracts/sse-events/parsers-sourcing.js +0 -179
- package/src/contracts/sse-events/patch-event-parser.js +0 -121
- package/src/contracts/sse-events/runtime-parsers.js +0 -79
- package/src/contracts/sse-events.js +0 -4
- package/src/index.js +0 -6
- package/src/main.jsx +0 -28
- package/src/orchestration/index.js +0 -6
- package/src/orchestration/useSSEStream.js +0 -221
- package/src/state/index.js +0 -4
- package/vite.config.js +0 -36
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
STREAMING_RESET,
|
|
4
|
-
STREAMING_CHUNK,
|
|
5
|
-
STREAMING_REPLACE,
|
|
6
|
-
AGENT_STATUS_SET,
|
|
7
|
-
THINKING_TRACE_SET,
|
|
8
|
-
EXECUTION_TRACE_SET,
|
|
9
|
-
STREAM_KNOWLEDGE_SEARCH_SET,
|
|
10
|
-
STREAM_SOURCING_CANDIDATES_SET,
|
|
11
|
-
STREAM_KNOWLEDGE_CITATION_SET,
|
|
12
|
-
EXECUTION_CARD_UPSERTED,
|
|
13
|
-
STREAMING_DONE,
|
|
14
|
-
} from './chatSessionActionTypes.js';
|
|
15
|
-
|
|
16
|
-
export function useStreamingActions({ dispatch }) {
|
|
17
|
-
const resetStreaming = useCallback(() => {
|
|
18
|
-
dispatch({ type: STREAMING_RESET });
|
|
19
|
-
}, [dispatch]);
|
|
20
|
-
|
|
21
|
-
const appendStreamChunk = useCallback((chunk) => {
|
|
22
|
-
dispatch({ type: STREAMING_CHUNK, payload: chunk });
|
|
23
|
-
}, [dispatch]);
|
|
24
|
-
|
|
25
|
-
const replaceStreamContent = useCallback((content) => {
|
|
26
|
-
dispatch({ type: STREAMING_REPLACE, payload: content });
|
|
27
|
-
}, [dispatch]);
|
|
28
|
-
|
|
29
|
-
const setAgentStatus = useCallback((agentStatus) => {
|
|
30
|
-
dispatch({ type: AGENT_STATUS_SET, payload: agentStatus });
|
|
31
|
-
}, [dispatch]);
|
|
32
|
-
|
|
33
|
-
const setThinkingTrace = useCallback((trace) => {
|
|
34
|
-
dispatch({ type: THINKING_TRACE_SET, payload: trace });
|
|
35
|
-
}, [dispatch]);
|
|
36
|
-
|
|
37
|
-
const setExecutionTrace = useCallback((executionTrace) => {
|
|
38
|
-
dispatch({ type: EXECUTION_TRACE_SET, payload: executionTrace });
|
|
39
|
-
dispatch({ type: EXECUTION_CARD_UPSERTED, payload: executionTrace });
|
|
40
|
-
}, [dispatch]);
|
|
41
|
-
|
|
42
|
-
const setKnowledgeSearch = useCallback((knowledgeSearch) => {
|
|
43
|
-
dispatch({ type: STREAM_KNOWLEDGE_SEARCH_SET, payload: knowledgeSearch });
|
|
44
|
-
}, [dispatch]);
|
|
45
|
-
|
|
46
|
-
const setSourcingCandidates = useCallback((sourcingCandidates) => {
|
|
47
|
-
dispatch({ type: STREAM_SOURCING_CANDIDATES_SET, payload: sourcingCandidates });
|
|
48
|
-
}, [dispatch]);
|
|
49
|
-
|
|
50
|
-
const setKnowledgeCitation = useCallback((knowledgeCitation) => {
|
|
51
|
-
dispatch({ type: STREAM_KNOWLEDGE_CITATION_SET, payload: knowledgeCitation });
|
|
52
|
-
}, [dispatch]);
|
|
53
|
-
|
|
54
|
-
const completeStreaming = useCallback((finalContent, finalMeta = null) => {
|
|
55
|
-
dispatch({
|
|
56
|
-
type: STREAMING_DONE,
|
|
57
|
-
payload: {
|
|
58
|
-
content: finalContent,
|
|
59
|
-
meta: (
|
|
60
|
-
finalMeta
|
|
61
|
-
&& typeof finalMeta === 'object'
|
|
62
|
-
&& !Array.isArray(finalMeta)
|
|
63
|
-
) ? finalMeta : null,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}, [dispatch]);
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
resetStreaming,
|
|
70
|
-
appendStreamChunk,
|
|
71
|
-
replaceStreamContent,
|
|
72
|
-
setAgentStatus,
|
|
73
|
-
setThinkingTrace,
|
|
74
|
-
setExecutionTrace,
|
|
75
|
-
setKnowledgeSearch,
|
|
76
|
-
setSourcingCandidates,
|
|
77
|
-
setKnowledgeCitation,
|
|
78
|
-
completeStreaming,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
UI_CARDS_SET,
|
|
4
|
-
UI_CARD_UPDATED,
|
|
5
|
-
LAST_USER_MESSAGE_SET,
|
|
6
|
-
DOC_GENERATED,
|
|
7
|
-
LEGEND_HINT_SHOWN,
|
|
8
|
-
SESSION_ERROR,
|
|
9
|
-
INSTANCE_PROFILE_SET,
|
|
10
|
-
} from './chatSessionActionTypes.js';
|
|
11
|
-
|
|
12
|
-
export function useUiStateActions({ dispatch }) {
|
|
13
|
-
const setUICards = useCallback((cards) => {
|
|
14
|
-
dispatch({ type: UI_CARDS_SET, payload: Array.isArray(cards) ? cards : [] });
|
|
15
|
-
}, [dispatch]);
|
|
16
|
-
|
|
17
|
-
const updateUICard = useCallback((card) => {
|
|
18
|
-
dispatch({ type: UI_CARD_UPDATED, payload: card });
|
|
19
|
-
}, [dispatch]);
|
|
20
|
-
|
|
21
|
-
const setLastUserMessage = useCallback((content) => {
|
|
22
|
-
dispatch({ type: LAST_USER_MESSAGE_SET, payload: content || '' });
|
|
23
|
-
}, [dispatch]);
|
|
24
|
-
|
|
25
|
-
const setGeneratedDoc = useCallback((doc) => {
|
|
26
|
-
dispatch({ type: DOC_GENERATED, payload: doc });
|
|
27
|
-
}, [dispatch]);
|
|
28
|
-
|
|
29
|
-
const markLegendHintShown = useCallback((sourceType) => {
|
|
30
|
-
dispatch({ type: LEGEND_HINT_SHOWN, payload: sourceType });
|
|
31
|
-
}, [dispatch]);
|
|
32
|
-
|
|
33
|
-
const setSessionError = useCallback((error) => {
|
|
34
|
-
dispatch({ type: SESSION_ERROR, payload: error });
|
|
35
|
-
}, [dispatch]);
|
|
36
|
-
|
|
37
|
-
const setInstanceProfile = useCallback((profile) => {
|
|
38
|
-
dispatch({ type: INSTANCE_PROFILE_SET, payload: profile || null });
|
|
39
|
-
}, [dispatch]);
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
setUICards,
|
|
43
|
-
updateUICard,
|
|
44
|
-
setLastUserMessage,
|
|
45
|
-
setGeneratedDoc,
|
|
46
|
-
markLegendHintShown,
|
|
47
|
-
setSessionError,
|
|
48
|
-
setInstanceProfile,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { useReducer, useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
initialState,
|
|
4
|
-
reducer,
|
|
5
|
-
} from './chatSessionReducer.js';
|
|
6
|
-
import { useSessionCrudActions } from './sessionActionsSessionCrud.js';
|
|
7
|
-
import { useMessageActions } from './sessionActionsMessages.js';
|
|
8
|
-
import { useStreamingActions } from './sessionActionsStreaming.js';
|
|
9
|
-
import { useUiStateActions } from './sessionActionsUiState.js';
|
|
10
|
-
|
|
11
|
-
export { initialState } from './chatSessionReducer.js';
|
|
12
|
-
|
|
13
|
-
export default function useChatSessionReducer(deps = {}) {
|
|
14
|
-
const { sessionAPI, messageAPI } = deps;
|
|
15
|
-
const [state, dispatch] = useReducer(reducer, initialState);
|
|
16
|
-
|
|
17
|
-
const sessionCrudActions = useSessionCrudActions({
|
|
18
|
-
dispatch,
|
|
19
|
-
sessionAPI,
|
|
20
|
-
messageAPI,
|
|
21
|
-
});
|
|
22
|
-
const messageActions = useMessageActions({
|
|
23
|
-
dispatch,
|
|
24
|
-
messageAPI,
|
|
25
|
-
});
|
|
26
|
-
const streamingActions = useStreamingActions({ dispatch });
|
|
27
|
-
const uiStateActions = useUiStateActions({ dispatch });
|
|
28
|
-
|
|
29
|
-
const {
|
|
30
|
-
loadSession,
|
|
31
|
-
createSession,
|
|
32
|
-
createOrLoadSession,
|
|
33
|
-
resetSession,
|
|
34
|
-
updateTitle,
|
|
35
|
-
promoteSession,
|
|
36
|
-
} = sessionCrudActions;
|
|
37
|
-
const {
|
|
38
|
-
refreshMessages,
|
|
39
|
-
appendUserMessage,
|
|
40
|
-
} = messageActions;
|
|
41
|
-
const {
|
|
42
|
-
resetStreaming,
|
|
43
|
-
appendStreamChunk,
|
|
44
|
-
replaceStreamContent,
|
|
45
|
-
setAgentStatus,
|
|
46
|
-
setThinkingTrace,
|
|
47
|
-
setExecutionTrace,
|
|
48
|
-
setKnowledgeSearch,
|
|
49
|
-
setSourcingCandidates,
|
|
50
|
-
setKnowledgeCitation,
|
|
51
|
-
completeStreaming,
|
|
52
|
-
} = streamingActions;
|
|
53
|
-
const {
|
|
54
|
-
setUICards,
|
|
55
|
-
updateUICard,
|
|
56
|
-
setLastUserMessage,
|
|
57
|
-
setGeneratedDoc,
|
|
58
|
-
markLegendHintShown,
|
|
59
|
-
setSessionError,
|
|
60
|
-
setInstanceProfile,
|
|
61
|
-
} = uiStateActions;
|
|
62
|
-
|
|
63
|
-
return useMemo(() => ({
|
|
64
|
-
sessionId: state.sessionId,
|
|
65
|
-
sessionTitle: state.sessionTitle,
|
|
66
|
-
sessionDetail: state.sessionDetail,
|
|
67
|
-
instanceProfile: state.instanceProfile,
|
|
68
|
-
messages: state.messages,
|
|
69
|
-
executionCards: state.executionCards,
|
|
70
|
-
uiCards: state.uiCards,
|
|
71
|
-
lastUserMessage: state.lastUserMessage,
|
|
72
|
-
generatedDoc: state.generatedDoc,
|
|
73
|
-
streaming: state.streaming,
|
|
74
|
-
sessionError: state.sessionError,
|
|
75
|
-
legendHintsShown: state.legendHintsShown,
|
|
76
|
-
loadSession,
|
|
77
|
-
createSession,
|
|
78
|
-
createOrLoadSession,
|
|
79
|
-
resetSession,
|
|
80
|
-
updateTitle,
|
|
81
|
-
promoteSession,
|
|
82
|
-
refreshMessages,
|
|
83
|
-
setSessionError,
|
|
84
|
-
appendUserMessage,
|
|
85
|
-
setUICards,
|
|
86
|
-
updateUICard,
|
|
87
|
-
setLastUserMessage,
|
|
88
|
-
resetStreaming,
|
|
89
|
-
appendStreamChunk,
|
|
90
|
-
replaceStreamContent,
|
|
91
|
-
setAgentStatus,
|
|
92
|
-
setThinkingTrace,
|
|
93
|
-
setExecutionTrace,
|
|
94
|
-
setKnowledgeSearch,
|
|
95
|
-
setSourcingCandidates,
|
|
96
|
-
setKnowledgeCitation,
|
|
97
|
-
completeStreaming,
|
|
98
|
-
setGeneratedDoc,
|
|
99
|
-
setInstanceProfile,
|
|
100
|
-
markLegendHintShown,
|
|
101
|
-
}), [
|
|
102
|
-
state,
|
|
103
|
-
loadSession,
|
|
104
|
-
createSession,
|
|
105
|
-
createOrLoadSession,
|
|
106
|
-
resetSession,
|
|
107
|
-
updateTitle,
|
|
108
|
-
promoteSession,
|
|
109
|
-
refreshMessages,
|
|
110
|
-
setSessionError,
|
|
111
|
-
appendUserMessage,
|
|
112
|
-
setUICards,
|
|
113
|
-
updateUICard,
|
|
114
|
-
setLastUserMessage,
|
|
115
|
-
resetStreaming,
|
|
116
|
-
appendStreamChunk,
|
|
117
|
-
replaceStreamContent,
|
|
118
|
-
setAgentStatus,
|
|
119
|
-
setThinkingTrace,
|
|
120
|
-
setExecutionTrace,
|
|
121
|
-
setKnowledgeSearch,
|
|
122
|
-
setSourcingCandidates,
|
|
123
|
-
setKnowledgeCitation,
|
|
124
|
-
completeStreaming,
|
|
125
|
-
setGeneratedDoc,
|
|
126
|
-
setInstanceProfile,
|
|
127
|
-
markLegendHintShown,
|
|
128
|
-
]);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export { useChatSessionReducer };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Session list lifecycle controller.
|
|
5
|
-
*
|
|
6
|
-
* @param {object} params - Hook params.
|
|
7
|
-
* @param {object} params.sessionAPI - Session API provider.
|
|
8
|
-
* @param {object} params.listParams - Session list query params.
|
|
9
|
-
* @param {Function} params.onStarted - Optional started callback.
|
|
10
|
-
* @param {Function} params.onSucceeded - Optional succeeded callback.
|
|
11
|
-
* @param {Function} params.onFailed - Optional failed callback.
|
|
12
|
-
* @returns {{sessions: Array<object>, loading: boolean, error: any, loadSessionList: Function}}
|
|
13
|
-
*/
|
|
14
|
-
export default function useSessionListController({
|
|
15
|
-
sessionAPI,
|
|
16
|
-
listParams = {},
|
|
17
|
-
onStarted,
|
|
18
|
-
onSucceeded,
|
|
19
|
-
onFailed,
|
|
20
|
-
} = {}) {
|
|
21
|
-
const [sessions, setSessions] = useState([]);
|
|
22
|
-
const [loading, setLoading] = useState(false);
|
|
23
|
-
const [error, setError] = useState(null);
|
|
24
|
-
const [hasLoaded, setHasLoaded] = useState(false);
|
|
25
|
-
|
|
26
|
-
const loadSessionList = useCallback(async (options = {}) => {
|
|
27
|
-
if (!sessionAPI?.list) {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
const background = options?.background === true;
|
|
31
|
-
const shouldShowLoading = !background && !hasLoaded;
|
|
32
|
-
|
|
33
|
-
onStarted?.();
|
|
34
|
-
if (shouldShowLoading) {
|
|
35
|
-
setLoading(true);
|
|
36
|
-
}
|
|
37
|
-
if (!background) {
|
|
38
|
-
setError(null);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const response = await sessionAPI.list(listParams);
|
|
43
|
-
const resolvedSessions = Array.isArray(response?.sessions) ? response.sessions : [];
|
|
44
|
-
setSessions(resolvedSessions);
|
|
45
|
-
setHasLoaded(true);
|
|
46
|
-
onSucceeded?.(resolvedSessions);
|
|
47
|
-
return resolvedSessions;
|
|
48
|
-
} catch (nextError) {
|
|
49
|
-
setError(nextError);
|
|
50
|
-
onFailed?.(nextError);
|
|
51
|
-
throw nextError;
|
|
52
|
-
} finally {
|
|
53
|
-
if (shouldShowLoading) {
|
|
54
|
-
setLoading(false);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}, [hasLoaded, listParams, onFailed, onStarted, onSucceeded, sessionAPI]);
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
sessions,
|
|
61
|
-
loading,
|
|
62
|
-
error,
|
|
63
|
-
loadSessionList,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export { useSessionListController };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { SSEClient } from '../../adapters/sse-client.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../adapters/sse-event-dispatcher.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../contracts/sse-events.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useSSEStream, default } from '../../orchestration/useSSEStream.js';
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Stream send lifecycle controller.
|
|
5
|
-
*
|
|
6
|
-
* @param {object} params - Hook params.
|
|
7
|
-
* @param {object} params.stream - Stream adapter with `send`.
|
|
8
|
-
* @param {Function} params.onStarted - Optional started callback.
|
|
9
|
-
* @param {Function} params.onChunk - Optional chunk callback.
|
|
10
|
-
* @param {Function} params.onCompleted - Optional completed callback.
|
|
11
|
-
* @param {Function} params.onFailed - Optional failed callback.
|
|
12
|
-
* @returns {{executeStreamSend: Function}}
|
|
13
|
-
*/
|
|
14
|
-
export default function useStreamSendController({
|
|
15
|
-
stream,
|
|
16
|
-
onStarted,
|
|
17
|
-
onChunk,
|
|
18
|
-
onCompleted,
|
|
19
|
-
onFailed,
|
|
20
|
-
} = {}) {
|
|
21
|
-
const executeStreamSend = useCallback(async (content, handlers = {}, options = {}) => {
|
|
22
|
-
if (!stream?.send) {
|
|
23
|
-
throw new Error('stream.send is required');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
onStarted?.();
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
await stream.send(content, {
|
|
30
|
-
...handlers,
|
|
31
|
-
onContent: (chunk, ...args) => {
|
|
32
|
-
onChunk?.(chunk, ...args);
|
|
33
|
-
handlers?.onContent?.(chunk, ...args);
|
|
34
|
-
},
|
|
35
|
-
}, options);
|
|
36
|
-
onCompleted?.();
|
|
37
|
-
} catch (error) {
|
|
38
|
-
onFailed?.(error);
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
}, [onChunk, onCompleted, onFailed, onStarted, stream]);
|
|
42
|
-
|
|
43
|
-
return { executeStreamSend };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { useStreamSendController };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export function createEmptyContext() {
|
|
2
|
-
return {
|
|
3
|
-
confirmed_fields: {},
|
|
4
|
-
missing_fields: [],
|
|
5
|
-
notes: [],
|
|
6
|
-
evidence: [],
|
|
7
|
-
sourcing_results: [],
|
|
8
|
-
analysis_results: [],
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function toArray(value) {
|
|
13
|
-
return Array.isArray(value) ? value : [];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function normalizeContext(input = {}) {
|
|
17
|
-
const base = input && typeof input === 'object' ? input : {};
|
|
18
|
-
return {
|
|
19
|
-
confirmed_fields:
|
|
20
|
-
base.confirmed_fields && typeof base.confirmed_fields === 'object' && !Array.isArray(base.confirmed_fields)
|
|
21
|
-
? { ...base.confirmed_fields }
|
|
22
|
-
: {},
|
|
23
|
-
missing_fields: toArray(base.missing_fields).map((item) => String(item || '').trim()).filter(Boolean),
|
|
24
|
-
notes: toArray(base.notes).map((item) => String(item || '')).filter(Boolean),
|
|
25
|
-
evidence: toArray(base.evidence),
|
|
26
|
-
sourcing_results: toArray(base.sourcing_results),
|
|
27
|
-
analysis_results: toArray(base.analysis_results),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function mergeContextPatch(context = createEmptyContext(), patch = {}) {
|
|
32
|
-
const normalizedContext = normalizeContext(context);
|
|
33
|
-
const normalizedPatch = normalizeContext(patch);
|
|
34
|
-
return {
|
|
35
|
-
confirmed_fields: {
|
|
36
|
-
...normalizedContext.confirmed_fields,
|
|
37
|
-
...normalizedPatch.confirmed_fields,
|
|
38
|
-
},
|
|
39
|
-
missing_fields: normalizedPatch.missing_fields.length > 0
|
|
40
|
-
? normalizedPatch.missing_fields
|
|
41
|
-
: normalizedContext.missing_fields,
|
|
42
|
-
notes: [...normalizedContext.notes, ...normalizedPatch.notes],
|
|
43
|
-
evidence: [...normalizedContext.evidence, ...normalizedPatch.evidence],
|
|
44
|
-
sourcing_results: [...normalizedContext.sourcing_results, ...normalizedPatch.sourcing_results],
|
|
45
|
-
analysis_results: [...normalizedContext.analysis_results, ...normalizedPatch.analysis_results],
|
|
46
|
-
};
|
|
47
|
-
}
|
package/src/contracts/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './sse-events.js';
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
export const parseAgentStatus = (raw) => ({
|
|
2
|
-
agent: raw?.agent ?? '',
|
|
3
|
-
status: raw?.status ?? '',
|
|
4
|
-
timestamp: raw?.timestamp ?? null,
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
export const parseThinkingTrace = (raw) => ({
|
|
8
|
-
trace: raw?.trace ?? '',
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
export const parseExecutionTrace = (raw) => ({
|
|
12
|
-
session_id: raw?.session_id ?? '',
|
|
13
|
-
step_id: raw?.step_id ?? '',
|
|
14
|
-
agent: raw?.agent ?? '',
|
|
15
|
-
stage: raw?.stage ?? '',
|
|
16
|
-
label: raw?.label ?? '',
|
|
17
|
-
detail: raw?.detail ?? raw?.trace ?? '',
|
|
18
|
-
reason: raw?.reason ?? '',
|
|
19
|
-
status: raw?.status ?? raw?.step_status ?? '',
|
|
20
|
-
sources: Array.isArray(raw?.sources) ? raw.sources : [],
|
|
21
|
-
timestamp: raw?.timestamp ?? null,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export const parseContent = (raw) => ({
|
|
25
|
-
chunk: raw?.content ?? '',
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export const parseAck = (raw) => ({
|
|
29
|
-
trace_id: String(raw?.trace_id || '').trim(),
|
|
30
|
-
session_id: String(raw?.session_id || '').trim(),
|
|
31
|
-
request_id: String(raw?.request_id || '').trim(),
|
|
32
|
-
mode: String(raw?.mode || '').trim(),
|
|
33
|
-
ts: Number.isFinite(Number(raw?.ts)) ? Number(raw.ts) : null,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
export const parsePhaseEvent = (raw) => ({
|
|
37
|
-
phase: String(raw?.phase || '').trim(),
|
|
38
|
-
label: String(raw?.label || '').trim(),
|
|
39
|
-
status: String(raw?.status || '').trim(),
|
|
40
|
-
progress: Number.isFinite(Number(raw?.progress)) ? Number(raw.progress) : null,
|
|
41
|
-
meta: raw?.meta && typeof raw.meta === 'object' && !Array.isArray(raw.meta) ? raw.meta : {},
|
|
42
|
-
ts: Number.isFinite(Number(raw?.ts)) ? Number(raw.ts) : null,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
export const parsePatch = (raw) => ({
|
|
46
|
-
scope: String(raw?.scope || '').trim(),
|
|
47
|
-
payload: raw?.payload && typeof raw.payload === 'object' && !Array.isArray(raw.payload) ? raw.payload : {},
|
|
48
|
-
ts: Number.isFinite(Number(raw?.ts)) ? Number(raw.ts) : null,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export const parseTextDelta = (raw) => ({
|
|
52
|
-
channel: String(raw?.channel || 'assistant').trim() || 'assistant',
|
|
53
|
-
delta: String(raw?.delta || ''),
|
|
54
|
-
ts: Number.isFinite(Number(raw?.ts)) ? Number(raw.ts) : null,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
export const parseTextReplace = (raw) => ({
|
|
58
|
-
channel: String(raw?.channel || 'assistant').trim() || 'assistant',
|
|
59
|
-
content: String(raw?.content || ''),
|
|
60
|
-
ts: Number.isFinite(Number(raw?.ts)) ? Number(raw.ts) : null,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
export const parseDone = (raw) => ({
|
|
64
|
-
trace_id: String(raw?.trace_id || '').trim(),
|
|
65
|
-
session_id: String(raw?.session_id || '').trim(),
|
|
66
|
-
request_id: String(raw?.request_id || '').trim(),
|
|
67
|
-
status: String(raw?.status || 'done').trim() || 'done',
|
|
68
|
-
ts: Number.isFinite(Number(raw?.ts)) ? Number(raw.ts) : null,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
export const parseTrace = (raw) => ({
|
|
72
|
-
trace: raw?.trace ?? raw?.detail ?? '',
|
|
73
|
-
summary: raw?.summary ?? raw?.label ?? '',
|
|
74
|
-
agent: raw?.agent ?? '',
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
export const parseSSEError = (raw) => ({
|
|
78
|
-
message: raw?.message ?? '发生错误',
|
|
79
|
-
});
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
export function resolveModeEventPayload(raw) {
|
|
2
|
-
if (raw?.payload && typeof raw.payload === 'object' && !Array.isArray(raw.payload)) {
|
|
3
|
-
return raw.payload;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return raw && typeof raw === 'object' ? raw : {};
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function pickFirstArray(payload, keys) {
|
|
10
|
-
for (const key of keys) {
|
|
11
|
-
const value = payload?.[key];
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isPlainObject(value) {
|
|
20
|
-
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function ensureActionObject(value) {
|
|
24
|
-
return isPlainObject(value) ? value : {};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function pickFirstString(candidates = []) {
|
|
28
|
-
for (const candidate of candidates) {
|
|
29
|
-
const text = String(candidate ?? '').trim();
|
|
30
|
-
if (text) {
|
|
31
|
-
return text;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return '';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function normalizeActionPayload(rawPayload) {
|
|
38
|
-
if (isPlainObject(rawPayload)) {
|
|
39
|
-
return rawPayload;
|
|
40
|
-
}
|
|
41
|
-
return {};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function normalizeAction(rawAction, index = 0) {
|
|
45
|
-
const action = ensureActionObject(rawAction);
|
|
46
|
-
const actionKey = pickFirstString([
|
|
47
|
-
action?.action_key,
|
|
48
|
-
action?.actionKey,
|
|
49
|
-
action?.key,
|
|
50
|
-
action?.id,
|
|
51
|
-
]);
|
|
52
|
-
const label = pickFirstString([
|
|
53
|
-
action?.label,
|
|
54
|
-
action?.title,
|
|
55
|
-
action?.name,
|
|
56
|
-
actionKey,
|
|
57
|
-
'action',
|
|
58
|
-
]);
|
|
59
|
-
const reason = pickFirstString([
|
|
60
|
-
action?.reason,
|
|
61
|
-
action?.description,
|
|
62
|
-
]);
|
|
63
|
-
const ownerModule = pickFirstString([
|
|
64
|
-
action?.owner_module,
|
|
65
|
-
action?.ownerModule,
|
|
66
|
-
]);
|
|
67
|
-
const policyId = pickFirstString([
|
|
68
|
-
action?.policy_id,
|
|
69
|
-
action?.policyId,
|
|
70
|
-
]);
|
|
71
|
-
const payload = normalizeActionPayload(action?.payload);
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
...action,
|
|
75
|
-
action_key: actionKey,
|
|
76
|
-
label,
|
|
77
|
-
reason,
|
|
78
|
-
payload,
|
|
79
|
-
owner_module: ownerModule,
|
|
80
|
-
policy_id: policyId,
|
|
81
|
-
action_index: Number.isFinite(Number(action?.action_index))
|
|
82
|
-
? Number(action.action_index)
|
|
83
|
-
: index,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function normalizeActionList(rawActions) {
|
|
88
|
-
if (!Array.isArray(rawActions)) {
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
|
-
const normalized = [];
|
|
92
|
-
const seenActionKeys = new Set();
|
|
93
|
-
|
|
94
|
-
rawActions.forEach((rawAction, index) => {
|
|
95
|
-
const action = normalizeAction(rawAction, index);
|
|
96
|
-
const actionKey = String(action?.action_key || '').trim();
|
|
97
|
-
if (actionKey) {
|
|
98
|
-
if (seenActionKeys.has(actionKey)) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
seenActionKeys.add(actionKey);
|
|
102
|
-
}
|
|
103
|
-
normalized.push(action);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
return normalized;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function parseGuidedSession(rawGuidedSession) {
|
|
110
|
-
const payload = (rawGuidedSession && typeof rawGuidedSession === 'object' && !Array.isArray(rawGuidedSession))
|
|
111
|
-
? rawGuidedSession
|
|
112
|
-
: {};
|
|
113
|
-
const questionQueue = (payload.question_queue && typeof payload.question_queue === 'object' && !Array.isArray(payload.question_queue))
|
|
114
|
-
? payload.question_queue
|
|
115
|
-
: {};
|
|
116
|
-
const summary = (payload.summary && typeof payload.summary === 'object' && !Array.isArray(payload.summary))
|
|
117
|
-
? payload.summary
|
|
118
|
-
: {};
|
|
119
|
-
const decisionPoint = (payload.decision_point && typeof payload.decision_point === 'object' && !Array.isArray(payload.decision_point))
|
|
120
|
-
? payload.decision_point
|
|
121
|
-
: {};
|
|
122
|
-
return {
|
|
123
|
-
state: payload?.state ?? '',
|
|
124
|
-
active: payload?.active === true,
|
|
125
|
-
current_question: payload?.current_question && typeof payload.current_question === 'object' && !Array.isArray(payload.current_question)
|
|
126
|
-
? payload.current_question
|
|
127
|
-
: null,
|
|
128
|
-
question_queue: {
|
|
129
|
-
total: Number.isFinite(Number(questionQueue?.total)) ? Number(questionQueue.total) : 0,
|
|
130
|
-
answered: Number.isFinite(Number(questionQueue?.answered)) ? Number(questionQueue.answered) : 0,
|
|
131
|
-
remaining: Number.isFinite(Number(questionQueue?.remaining)) ? Number(questionQueue.remaining) : 0,
|
|
132
|
-
pending_fields: Array.isArray(questionQueue?.pending_fields) ? questionQueue.pending_fields : [],
|
|
133
|
-
},
|
|
134
|
-
summary: {
|
|
135
|
-
text: summary?.text ?? '',
|
|
136
|
-
ready: summary?.ready === true,
|
|
137
|
-
},
|
|
138
|
-
decision_point: {
|
|
139
|
-
active: decisionPoint?.active === true,
|
|
140
|
-
actions: Array.isArray(decisionPoint?.actions) ? decisionPoint.actions : [],
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
}
|