@adminforth/agent 2.0.9 → 2.1.0
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/README.md +333 -10
- package/dist/application/ports.d.ts +66 -0
- package/dist/application/runTurnUseCase.d.ts +68 -0
- package/dist/application/runTurnUseCase.js +358 -0
- package/dist/{agentEvents.d.ts → domain/agentEvents.d.ts} +1 -1
- package/dist/{agent → domain}/systemPrompt.js +1 -1
- package/dist/{agent/turn → domain}/turnTypes.d.ts +41 -37
- package/dist/{agent/turn/VegaLiteStreamBuffer.d.ts → domain/vegaLiteStreamBuffer.d.ts} +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +40 -35
- package/dist/{agent/runtime/AgentContext.d.ts → llm/agentContext.d.ts} +3 -3
- package/dist/{agent/simpleAgent.d.ts → llm/agentModels.d.ts} +18 -16
- package/dist/llm/agentModels.js +65 -0
- package/dist/{agent/runtime/AgentRuntime.d.ts → llm/agentRuntime.d.ts} +11 -2
- package/dist/{agent/runtime/AgentRuntime.js → llm/agentRuntime.js} +38 -6
- package/dist/llm/langGraphLlm.d.ts +25 -0
- package/dist/llm/langGraphLlm.js +54 -0
- package/dist/{agent/middleware/apiBasedTools.d.ts → llm/middleware/apiToolsMiddleware.d.ts} +1 -1
- package/dist/{agent/middleware/apiBasedTools.js → llm/middleware/apiToolsMiddleware.js} +8 -14
- package/dist/{agent → llm}/middleware/sequenceDebug.d.ts +1 -1
- package/dist/{agent/models/AgentModelFactory.d.ts → llm/modelFactory.d.ts} +1 -1
- package/dist/{agent/models/AgentModelFactory.js → llm/modelFactory.js} +1 -1
- package/dist/llm/streamAdapter.d.ts +18 -0
- package/dist/llm/streamAdapter.js +117 -0
- package/dist/{sessionStore.d.ts → persistence/sessionStore.d.ts} +12 -2
- package/dist/{sessionStore.js → persistence/sessionStore.js} +33 -0
- package/dist/{agent/tools/AgentToolProvider.d.ts → tools/agentToolProvider.d.ts} +1 -1
- package/dist/{agent/tools/AgentToolProvider.js → tools/agentToolProvider.js} +1 -1
- package/dist/{apiBasedTools.js → tools/apiBasedTools.js} +10 -6
- package/dist/{agent/tools → tools}/apiTool.d.ts +1 -1
- package/dist/{agent/tools → tools}/fetchSkill.js +1 -1
- package/dist/{agent/tools → tools}/fetchToolSchema.d.ts +1 -1
- package/dist/{agent/tools → tools}/index.d.ts +1 -1
- package/dist/{agent/tools → tools}/navigateUser.d.ts +3 -3
- package/dist/{endpoints → transport/http}/context.d.ts +2 -2
- package/dist/transport/http/context.js +1 -0
- package/dist/{endpoints/core.js → transport/http/coreEndpoints.js} +3 -3
- package/dist/{endpoints/sessions.js → transport/http/sessionEndpoints.js} +7 -1
- package/dist/transport/sse/sseWriter.d.ts +29 -0
- package/dist/{surfaces/web-sse/createSseEventEmitter.js → transport/sse/sseWriter.js} +15 -0
- package/dist/{chatSurfaceService.d.ts → transport/surfaces/chatSurfaceService.d.ts} +3 -3
- package/dist/{chatSurfaceService.js → transport/surfaces/chatSurfaceService.js} +7 -5
- package/dist/{agent/speech/SpeechTurnService.d.ts → transport/surfaces/speechTurnService.d.ts} +1 -1
- package/dist/{agent/speech/SpeechTurnService.js → transport/surfaces/speechTurnService.js} +2 -2
- package/dist/types.d.ts +10 -4
- package/package.json +11 -2
- package/.woodpecker/buildRelease.sh +0 -13
- package/.woodpecker/buildSlackNotify.sh +0 -46
- package/.woodpecker/release.yml +0 -57
- package/agent/checkpointer.ts +0 -329
- package/agent/languageDetect.ts +0 -92
- package/agent/middleware/apiBasedTools.ts +0 -174
- package/agent/middleware/openAiResponsesContinuation.ts +0 -92
- package/agent/middleware/sequenceDebug.ts +0 -429
- package/agent/models/AgentModeResolver.ts +0 -9
- package/agent/models/AgentModelFactory.ts +0 -28
- package/agent/runtime/AgentContext.ts +0 -30
- package/agent/runtime/AgentRuntime.ts +0 -89
- package/agent/simpleAgent.ts +0 -199
- package/agent/skills/registry.ts +0 -162
- package/agent/speech/SpeechTurnService.ts +0 -179
- package/agent/systemPrompt.ts +0 -133
- package/agent/toolCallEvents.ts +0 -135
- package/agent/tools/AgentToolProvider.ts +0 -28
- package/agent/tools/apiTool.ts +0 -66
- package/agent/tools/fetchSkill.ts +0 -68
- package/agent/tools/fetchToolSchema.ts +0 -47
- package/agent/tools/getUserLocation.ts +0 -45
- package/agent/tools/index.ts +0 -31
- package/agent/tools/navigateUser.ts +0 -210
- package/agent/turn/TurnContextBuilder.ts +0 -36
- package/agent/turn/TurnLifecycleService.ts +0 -47
- package/agent/turn/TurnPersistenceService.ts +0 -33
- package/agent/turn/TurnPromptBuilder.ts +0 -51
- package/agent/turn/TurnStreamConsumer.ts +0 -69
- package/agent/turn/VegaLiteStreamBuffer.ts +0 -90
- package/agent/turn/turnTypes.ts +0 -100
- package/agentEvents.ts +0 -75
- package/agentTurnService.ts +0 -314
- package/apiBasedTools.ts +0 -702
- package/build.log +0 -67
- package/chatSurfaceService.ts +0 -319
- package/custom/ChatFooter.vue +0 -173
- package/custom/ChatHeader.vue +0 -78
- package/custom/ChatSurface.vue +0 -160
- package/custom/CustomAutoScrollContainer.vue +0 -164
- package/custom/SessionsHistory.vue +0 -88
- package/custom/chat.ts +0 -82
- package/custom/composables/agentAudio/utils.ts +0 -220
- package/custom/composables/agentStore/constants.ts +0 -19
- package/custom/composables/agentStore/pageContext.ts +0 -8
- package/custom/composables/agentStore/useAgentChat.ts +0 -241
- package/custom/composables/agentStore/useAgentPlaceholder.ts +0 -142
- package/custom/composables/agentStore/useAgentSessions.ts +0 -350
- package/custom/composables/useAgentAudio.ts +0 -272
- package/custom/composables/useAgentStore.ts +0 -510
- package/custom/composables/useAgentTransitions.ts +0 -58
- package/custom/conversation_area/ConversationArea.vue +0 -301
- package/custom/conversation_area/MessageRenderer.vue +0 -49
- package/custom/conversation_area/ProcessingTimeline.vue +0 -286
- package/custom/conversation_area/ReasoningRenderer.vue +0 -79
- package/custom/conversation_area/SystemMessageRenderer.vue +0 -28
- package/custom/conversation_area/TextRenderer.vue +0 -182
- package/custom/conversation_area/ThreeDotsAnimation.vue +0 -35
- package/custom/conversation_area/ToolApprovalRenderer.vue +0 -98
- package/custom/conversation_area/ToolRenderer.vue +0 -178
- package/custom/conversation_area/ToolsGroup.vue +0 -59
- package/custom/env.d.ts +0 -7
- package/custom/incremark_code_renderers/IncremarkShikiCodeBlock.vue +0 -393
- package/custom/incremark_code_renderers/incremarkCodeHighlight.ts +0 -285
- package/custom/incremark_code_renderers/incremarkRenderer.ts +0 -653
- package/custom/incremark_code_renderers/renderIncremarkMarkdown.ts +0 -118
- package/custom/package.json +0 -30
- package/custom/pnpm-lock.yaml +0 -2394
- package/custom/public/agentAudio/agent-processing.mp3 +0 -0
- package/custom/skills/analyze_data/SKILL.md +0 -25
- package/custom/skills/charts/SKILL.md +0 -193
- package/custom/skills/fetch_data/SKILL.md +0 -31
- package/custom/skills/mutate_data/SKILL.md +0 -121
- package/custom/speech_recognition_frontend/AudioLines.vue +0 -43
- package/custom/speech_recognition_frontend/MicrophoneButon.vue +0 -185
- package/custom/speech_recognition_frontend/types/voice-activity-detection.d.ts +0 -22
- package/custom/speech_recognition_frontend/voiceActivityDetection.ts +0 -62
- package/custom/tsconfig.json +0 -15
- package/custom/types.ts +0 -108
- package/custom/utils.ts +0 -38
- package/dist/agent/middleware/openAiResponsesContinuation.d.ts +0 -1
- package/dist/agent/middleware/openAiResponsesContinuation.js +0 -66
- package/dist/agent/models/AgentModeResolver.d.ts +0 -9
- package/dist/agent/models/AgentModeResolver.js +0 -9
- package/dist/agent/simpleAgent.js +0 -118
- package/dist/agent/turn/TurnContextBuilder.d.ts +0 -14
- package/dist/agent/turn/TurnContextBuilder.js +0 -31
- package/dist/agent/turn/TurnLifecycleService.d.ts +0 -24
- package/dist/agent/turn/TurnLifecycleService.js +0 -47
- package/dist/agent/turn/TurnPersistenceService.d.ts +0 -13
- package/dist/agent/turn/TurnPersistenceService.js +0 -35
- package/dist/agent/turn/TurnPromptBuilder.d.ts +0 -19
- package/dist/agent/turn/TurnPromptBuilder.js +0 -43
- package/dist/agent/turn/TurnStreamConsumer.d.ts +0 -11
- package/dist/agent/turn/TurnStreamConsumer.js +0 -84
- package/dist/agentTurnService.d.ts +0 -24
- package/dist/agentTurnService.js +0 -269
- package/dist/surfaces/web-sse/createSseEventEmitter.d.ts +0 -14
- package/endpoints/chatSurfaces.ts +0 -66
- package/endpoints/context.ts +0 -52
- package/endpoints/core.ts +0 -181
- package/endpoints/sessions.ts +0 -183
- package/errors.ts +0 -10
- package/index.ts +0 -192
- package/pnpm-workspace.yaml +0 -4
- package/sanitizeSpeechText.ts +0 -32
- package/sessionStore.ts +0 -105
- package/surfaces/web-sse/createSseEventEmitter.ts +0 -311
- package/tsconfig.json +0 -14
- package/types.ts +0 -127
- /package/dist/{agent/turn/turnTypes.js → application/ports.js} +0 -0
- /package/dist/{agentEvents.js → domain/agentEvents.js} +0 -0
- /package/dist/{agent → domain}/languageDetect.d.ts +0 -0
- /package/dist/{agent → domain}/languageDetect.js +0 -0
- /package/dist/{agent → domain}/systemPrompt.d.ts +0 -0
- /package/dist/{agent → domain}/toolCallEvents.d.ts +0 -0
- /package/dist/{agent → domain}/toolCallEvents.js +0 -0
- /package/dist/{endpoints/context.js → domain/turnTypes.js} +0 -0
- /package/dist/{agent/turn/VegaLiteStreamBuffer.js → domain/vegaLiteStreamBuffer.js} +0 -0
- /package/dist/{agent/runtime/AgentContext.js → llm/agentContext.js} +0 -0
- /package/dist/{agent → llm}/middleware/sequenceDebug.js +0 -0
- /package/dist/{agent/checkpointer.d.ts → persistence/checkpointStore.d.ts} +0 -0
- /package/dist/{agent/checkpointer.js → persistence/checkpointStore.js} +0 -0
- /package/dist/{errors.d.ts → shared/errors.d.ts} +0 -0
- /package/dist/{errors.js → shared/errors.js} +0 -0
- /package/dist/{sanitizeSpeechText.d.ts → shared/sanitizeSpeechText.d.ts} +0 -0
- /package/dist/{sanitizeSpeechText.js → shared/sanitizeSpeechText.js} +0 -0
- /package/dist/{apiBasedTools.d.ts → tools/apiBasedTools.d.ts} +0 -0
- /package/dist/{agent/tools → tools}/apiTool.js +0 -0
- /package/dist/{agent/tools → tools}/fetchSkill.d.ts +0 -0
- /package/dist/{agent/tools → tools}/fetchToolSchema.js +0 -0
- /package/dist/{agent/tools → tools}/getUserLocation.d.ts +0 -0
- /package/dist/{agent/tools → tools}/getUserLocation.js +0 -0
- /package/dist/{agent/tools → tools}/index.js +0 -0
- /package/dist/{agent/tools → tools}/navigateUser.js +0 -0
- /package/dist/{agent → tools}/skills/registry.d.ts +0 -0
- /package/dist/{agent → tools}/skills/registry.js +0 -0
- /package/dist/{endpoints/chatSurfaces.d.ts → transport/http/chatSurfaceEndpoints.d.ts} +0 -0
- /package/dist/{endpoints/chatSurfaces.js → transport/http/chatSurfaceEndpoints.js} +0 -0
- /package/dist/{endpoints/core.d.ts → transport/http/coreEndpoints.d.ts} +0 -0
- /package/dist/{endpoints/sessions.d.ts → transport/http/sessionEndpoints.d.ts} +0 -0
|
@@ -1,510 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia';
|
|
2
|
-
import { IAgentSession, ISessionsListItem } from '../types';
|
|
3
|
-
import { ref, nextTick, computed, watch, onMounted } from 'vue';
|
|
4
|
-
import { useRouter } from 'vue-router';
|
|
5
|
-
import { useAdminforth } from '@/adminforth';
|
|
6
|
-
import { useCoreStore } from '@/stores/core';
|
|
7
|
-
import { useAgentTransitions } from './useAgentTransitions';
|
|
8
|
-
import { useWindowSize } from '@vueuse/core';
|
|
9
|
-
import { remToPx, pxToRem } from '../utils';
|
|
10
|
-
import {
|
|
11
|
-
type AgentMode,
|
|
12
|
-
DEFAULT_CHAT_WIDTH,
|
|
13
|
-
MAX_WIDTH,
|
|
14
|
-
MIN_WIDTH,
|
|
15
|
-
RESERVED_SYSTEM_MESSAGE_CONTENT,
|
|
16
|
-
PRE_SESSION_ID
|
|
17
|
-
} from './agentStore/constants';
|
|
18
|
-
import { createAgentChatManager } from './agentStore/useAgentChat';
|
|
19
|
-
import { createAgentPlaceholderController } from './agentStore/useAgentPlaceholder';
|
|
20
|
-
import { createAgentSessionManager } from './agentStore/useAgentSessions';
|
|
21
|
-
|
|
22
|
-
export const useAgentStore = defineStore('agent', () => {
|
|
23
|
-
const agentTransitions = useAgentTransitions();
|
|
24
|
-
|
|
25
|
-
const activeSessionId = ref<string | null>(null);
|
|
26
|
-
const currentSession = ref<IAgentSession | null>(null);
|
|
27
|
-
const sessionList = ref<ISessionsListItem[]>([]);
|
|
28
|
-
const sessions = ref<Record<string, IAgentSession>>({});
|
|
29
|
-
const adminforth = useAdminforth();
|
|
30
|
-
const isChatOpen = ref(false);
|
|
31
|
-
const isSessionHistoryOpen = ref(false);
|
|
32
|
-
const router = useRouter();
|
|
33
|
-
const textInput = ref<HTMLTextAreaElement | null>(null);
|
|
34
|
-
const userMessageInput = ref();
|
|
35
|
-
const trimmedUserMessage = computed(() => userMessageInput.value ? userMessageInput.value.trim() : '');
|
|
36
|
-
const lastMessage = ref('');
|
|
37
|
-
const isTeleportedToBody = ref(false);
|
|
38
|
-
const setIsTeleportedToBody = (isTeleported: boolean) => {
|
|
39
|
-
isTeleportedToBody.value = isTeleported;
|
|
40
|
-
}
|
|
41
|
-
const coreStore = useCoreStore();
|
|
42
|
-
const appRoot = ref<HTMLElement | null>(null);
|
|
43
|
-
const header = ref<HTMLElement | null>(null);
|
|
44
|
-
const lastSessionId = ref<string | null>(null);
|
|
45
|
-
const chatWidth = ref(DEFAULT_CHAT_WIDTH);
|
|
46
|
-
const availableModes = ref<AgentMode[]>([]);
|
|
47
|
-
const activeModeName = ref<string | null>(null);
|
|
48
|
-
const { width: viewportWidth } = useWindowSize({
|
|
49
|
-
type: 'visual',
|
|
50
|
-
includeScrollbar: false,
|
|
51
|
-
});
|
|
52
|
-
const {
|
|
53
|
-
currentChat,
|
|
54
|
-
setCurrentChat,
|
|
55
|
-
abortCurrentChatRequest,
|
|
56
|
-
submitToolApproval: submitToolApprovalResponse,
|
|
57
|
-
} = createAgentChatManager({
|
|
58
|
-
lastMessage,
|
|
59
|
-
activeModeName,
|
|
60
|
-
onOpenPage: openAgentPage,
|
|
61
|
-
onToolApprovalRequest: addToolApprovalMessage,
|
|
62
|
-
});
|
|
63
|
-
const {
|
|
64
|
-
userMessagePlaceholder,
|
|
65
|
-
hasTypedMessageInPageSession,
|
|
66
|
-
fetchPlaceholderMessages,
|
|
67
|
-
stopPlaceholderAnimation,
|
|
68
|
-
} = createAgentPlaceholderController({
|
|
69
|
-
userMessageInput,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
function setLocalStorageItem(key: string, value: string) {
|
|
73
|
-
window.localStorage.setItem(`${coreStore.config.brandName || 'adminforth'}-${key}`, value);
|
|
74
|
-
}
|
|
75
|
-
function getLocalStorageItem(key: string) {
|
|
76
|
-
return window.localStorage.getItem(`${coreStore.config.brandName || 'adminforth'}-${key}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const isAudioChatMode = ref(false);
|
|
80
|
-
|
|
81
|
-
const onBeforeChatCloseCallbacks: Array<() => Promise<void>> = [];
|
|
82
|
-
function registerOnBeforeChatCloseCallback(hook: () => Promise<void>) {
|
|
83
|
-
onBeforeChatCloseCallbacks.push(hook);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function executeOnBeforeChatCloseCallbacks() {
|
|
87
|
-
for(const hook of onBeforeChatCloseCallbacks) {
|
|
88
|
-
try {
|
|
89
|
-
await hook();
|
|
90
|
-
} catch (error) {
|
|
91
|
-
console.error('Error executing onBeforeChatClose callback:', error);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function setIsAudioChatMode(isAudioChat: boolean) {
|
|
97
|
-
isAudioChatMode.value = isAudioChat;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getToolApprovalMessages(interrupt: unknown): string[] {
|
|
101
|
-
const interrupts = Array.isArray(interrupt) ? interrupt : [interrupt];
|
|
102
|
-
|
|
103
|
-
return interrupts.flatMap((item: any) => {
|
|
104
|
-
const value = item?.value ?? item;
|
|
105
|
-
const actionRequests = Array.isArray(value?.actionRequests) ? value.actionRequests : [];
|
|
106
|
-
|
|
107
|
-
return actionRequests.map((actionRequest: any) => (
|
|
108
|
-
typeof actionRequest?.description === 'string'
|
|
109
|
-
? actionRequest.description
|
|
110
|
-
: String(actionRequest?.name ?? 'Tool execution pending approval')
|
|
111
|
-
));
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function addToolApprovalMessage(sessionId: string, interrupt: unknown) {
|
|
116
|
-
const approvalPart = {
|
|
117
|
-
type: 'data-tool-approval' as const,
|
|
118
|
-
data: {
|
|
119
|
-
sessionId,
|
|
120
|
-
status: 'pending' as const,
|
|
121
|
-
messages: getToolApprovalMessages(interrupt),
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
const lastChatMessage = currentChat.value?.lastMessage;
|
|
125
|
-
|
|
126
|
-
if (lastChatMessage?.role === 'assistant') {
|
|
127
|
-
lastChatMessage.parts.push(approvalPart);
|
|
128
|
-
currentChat.value?.messages.splice(currentChat.value.messages.length - 1, 1, lastChatMessage);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
currentChat.value?.messages.push({
|
|
133
|
-
role: 'assistant',
|
|
134
|
-
parts: [approvalPart],
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async function submitToolApproval(sessionId: string, decision: 'approve' | 'reject') {
|
|
139
|
-
const message = currentChat.value?.messages
|
|
140
|
-
.findLast(candidate => candidate.role === 'assistant' && candidate.parts.some(part => {
|
|
141
|
-
return part.type === 'data-tool-approval'
|
|
142
|
-
&& part.data?.sessionId === sessionId
|
|
143
|
-
&& part.data?.status === 'pending';
|
|
144
|
-
}));
|
|
145
|
-
const approvalPart = message?.parts.find(part => {
|
|
146
|
-
return part.type === 'data-tool-approval'
|
|
147
|
-
&& part.data?.sessionId === sessionId
|
|
148
|
-
&& part.data?.status === 'pending';
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
if (approvalPart?.data) {
|
|
152
|
-
approvalPart.data.status = 'processing';
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
await submitToolApprovalResponse(sessionId, decision);
|
|
157
|
-
|
|
158
|
-
if (approvalPart?.data) {
|
|
159
|
-
approvalPart.data.status = decision === 'approve' ? 'approved' : 'rejected';
|
|
160
|
-
}
|
|
161
|
-
} catch (error) {
|
|
162
|
-
if (approvalPart?.data) {
|
|
163
|
-
approvalPart.data.status = 'pending';
|
|
164
|
-
}
|
|
165
|
-
console.error('Error submitting tool approval', error);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
watch(isAudioChatMode, (newVal: boolean) => {
|
|
170
|
-
if (newVal) {
|
|
171
|
-
addSystemMessage(RESERVED_SYSTEM_MESSAGE_CONTENT.START_AUDIO_CHAT);
|
|
172
|
-
} else {
|
|
173
|
-
addSystemMessage(RESERVED_SYSTEM_MESSAGE_CONTENT.END_AUDIO_CHAT);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const isResponseInProgress = computed( () => {
|
|
179
|
-
return currentChat.value?.status === 'streaming';
|
|
180
|
-
});
|
|
181
|
-
const hasPendingToolApproval = computed(() => (
|
|
182
|
-
currentChat.value?.messages.some((message: any) => (
|
|
183
|
-
message.role === 'assistant'
|
|
184
|
-
&& message.parts.some((part: any) => (
|
|
185
|
-
part.type === 'data-tool-approval'
|
|
186
|
-
&& (part.data?.status === 'pending' || part.data?.status === 'processing')
|
|
187
|
-
))
|
|
188
|
-
)) ?? false
|
|
189
|
-
));
|
|
190
|
-
const isMessageInputBlocked = computed(() => (
|
|
191
|
-
isResponseInProgress.value || hasPendingToolApproval.value
|
|
192
|
-
));
|
|
193
|
-
const blockCloseOfChat = ref(false);
|
|
194
|
-
const {
|
|
195
|
-
sendMessage,
|
|
196
|
-
createPreSession,
|
|
197
|
-
setActiveSession,
|
|
198
|
-
fetchSessionsList,
|
|
199
|
-
deleteSession,
|
|
200
|
-
addDebugMessage,
|
|
201
|
-
addSystemMessage,
|
|
202
|
-
addAgentMessage,
|
|
203
|
-
addUserMessage,
|
|
204
|
-
addDataToolCallMessage,
|
|
205
|
-
setCurrentChatStatus,
|
|
206
|
-
updateLastAgentMessage
|
|
207
|
-
} = createAgentSessionManager({
|
|
208
|
-
activeSessionId,
|
|
209
|
-
currentSession,
|
|
210
|
-
sessionList,
|
|
211
|
-
sessions,
|
|
212
|
-
currentChat,
|
|
213
|
-
trimmedUserMessage,
|
|
214
|
-
isResponseInProgress,
|
|
215
|
-
isMessageInputBlocked,
|
|
216
|
-
userMessageInput,
|
|
217
|
-
lastMessage,
|
|
218
|
-
blockCloseOfChat,
|
|
219
|
-
adminforth,
|
|
220
|
-
setCurrentChat,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
watch(() => viewportWidth.value, (newWidth) => {
|
|
224
|
-
if (isFullScreen.value) {
|
|
225
|
-
setChatWidth(newWidth, false);
|
|
226
|
-
}
|
|
227
|
-
})
|
|
228
|
-
watch(isTeleportedToBody, (newVal: boolean) => {
|
|
229
|
-
setLocalStorageItem('isTeleportedToBody', newVal ? 'true' : 'false');
|
|
230
|
-
})
|
|
231
|
-
watch(isChatOpen, (newVal: boolean) => {
|
|
232
|
-
setLocalStorageItem('isChatOpen', newVal ? 'true' : 'false');
|
|
233
|
-
})
|
|
234
|
-
watch(chatWidth, (newVal: number) => {
|
|
235
|
-
setLocalStorageItem('chatWidth', newVal.toString());
|
|
236
|
-
if (!isFullScreen.value) {
|
|
237
|
-
setLocalStorageItem('chatWidthBeforeFullScreen', newVal.toString());
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
watch(activeSessionId, (newVal: string | null) => {
|
|
241
|
-
if (newVal) {
|
|
242
|
-
setLocalStorageItem('lastSessionId', newVal);
|
|
243
|
-
}
|
|
244
|
-
})
|
|
245
|
-
onMounted(() => {
|
|
246
|
-
const chatWidthBeforeFullScreen = parseInt(getLocalStorageItem('chatWidthBeforeFullScreen') || '0', 10);
|
|
247
|
-
if (chatWidthBeforeFullScreen && (chatWidthBeforeFullScreen > MAX_WIDTH || chatWidthBeforeFullScreen < MIN_WIDTH)) {
|
|
248
|
-
setChatWidth(remToPx(DEFAULT_CHAT_WIDTH));
|
|
249
|
-
} else if (chatWidthBeforeFullScreen) {
|
|
250
|
-
setChatWidth(remToPx(chatWidthBeforeFullScreen));
|
|
251
|
-
} else {
|
|
252
|
-
const savedChatWidth = parseInt(getLocalStorageItem('chatWidth') || '0', 10);
|
|
253
|
-
if (savedChatWidth) {
|
|
254
|
-
if (savedChatWidth > MAX_WIDTH || savedChatWidth < MIN_WIDTH) {
|
|
255
|
-
setChatWidth(remToPx(DEFAULT_CHAT_WIDTH));
|
|
256
|
-
} else {
|
|
257
|
-
setChatWidth(remToPx(savedChatWidth));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (!coreStore.isMobile) {
|
|
262
|
-
const savedIsTeleportedToBody = getLocalStorageItem('isTeleportedToBody');
|
|
263
|
-
const savedIsTeleportedToBodyBeforeFullScreen = getLocalStorageItem('isTeleportedToBodyBeforeFullScreen');
|
|
264
|
-
let isTeleportedToBodyFromLocalStorage = true;
|
|
265
|
-
if (savedIsTeleportedToBody !== null || savedIsTeleportedToBodyBeforeFullScreen !== null) {
|
|
266
|
-
isTeleportedToBodyFromLocalStorage = savedIsTeleportedToBody === 'true' || savedIsTeleportedToBodyBeforeFullScreen === 'true';
|
|
267
|
-
}
|
|
268
|
-
const savedIsChatOpen = getLocalStorageItem('isChatOpen');
|
|
269
|
-
|
|
270
|
-
setIsTeleportedToBody(isTeleportedToBodyFromLocalStorage);
|
|
271
|
-
if (isTeleportedToBody.value) {
|
|
272
|
-
isChatOpen.value = savedIsChatOpen === null ? true : savedIsChatOpen === 'true';
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
lastSessionId.value = getLocalStorageItem('lastSessionId');
|
|
276
|
-
if (lastSessionId.value && lastSessionId.value !== PRE_SESSION_ID) {
|
|
277
|
-
setActiveSession(lastSessionId.value);
|
|
278
|
-
}
|
|
279
|
-
if (coreStore.isMobile) {
|
|
280
|
-
setChatWidth(window.innerWidth);
|
|
281
|
-
}
|
|
282
|
-
appRoot.value = document.getElementById('app');
|
|
283
|
-
header.value = document.getElementById('af-header-nav');
|
|
284
|
-
if (appRoot.value && header.value) {
|
|
285
|
-
nextTick(() => {
|
|
286
|
-
agentTransitions.setAppRootTransition(false);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
const isFullScreen = ref(false);
|
|
292
|
-
function setFullScreen(fullScreen: boolean) {
|
|
293
|
-
isFullScreen.value = fullScreen;
|
|
294
|
-
const appElement = document.getElementById('app');
|
|
295
|
-
|
|
296
|
-
if (fullScreen) {
|
|
297
|
-
document.body.style.overflow = 'hidden';
|
|
298
|
-
document.body.classList.add('bg-lightHtml', 'dark:bg-darkHtml');
|
|
299
|
-
setTimeout(() => {
|
|
300
|
-
appElement?.setAttribute('style', `opacity: 0; pointer-events: none;`);
|
|
301
|
-
}, agentTransitions.TRANSITION_DURATION);
|
|
302
|
-
setLocalStorageItem('chatWidthBeforeFullScreen', chatWidth.value.toString());
|
|
303
|
-
setLocalStorageItem('isTeleportedToBodyBeforeFullScreen', isTeleportedToBody.value ? 'true' : 'false');
|
|
304
|
-
setIsTeleportedToBody(false);
|
|
305
|
-
useAgentTransitions().setChatSurfaceTransition(false);
|
|
306
|
-
setChatWidth(window.innerWidth, false);
|
|
307
|
-
} else {
|
|
308
|
-
appElement?.setAttribute('style', `opacity: 100; pointer-events: all;`);
|
|
309
|
-
document.body.style.overflow = '';
|
|
310
|
-
const lastChatWidth = parseInt(getLocalStorageItem('chatWidthBeforeFullScreen') || DEFAULT_CHAT_WIDTH.toString(), 10);
|
|
311
|
-
const isTeleportedBeforeFullScreen = getLocalStorageItem('isTeleportedToBodyBeforeFullScreen') === 'true';
|
|
312
|
-
agentTransitions.setAppRootTransition(true);
|
|
313
|
-
setIsTeleportedToBody(isTeleportedBeforeFullScreen);
|
|
314
|
-
setChatWidth(remToPx(lastChatWidth), false);
|
|
315
|
-
setTimeout(() => agentTransitions.setAppRootTransition(false), agentTransitions.TRANSITION_DURATION);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
//takes on input width in pixels, converts to rem and sets chat width
|
|
320
|
-
function setChatWidth(width: number, blockTransition = true) {
|
|
321
|
-
if (blockTransition) {
|
|
322
|
-
agentTransitions.setAppRootTransition(true);
|
|
323
|
-
}
|
|
324
|
-
chatWidth.value = pxToRem(width);
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
watch([isTeleportedToBody, isChatOpen, chatWidth], ([newIsTeleportedToBody, newIsChatOpen, newChatWidth]: [boolean, boolean, number]) => {
|
|
328
|
-
if (appRoot.value && header.value) {
|
|
329
|
-
if (newIsTeleportedToBody && newIsChatOpen) {
|
|
330
|
-
appRoot.value.style.paddingRight = `${remToPx(chatWidth.value)}px`;
|
|
331
|
-
header.value.style.paddingRight = `${remToPx(chatWidth.value)}px`;
|
|
332
|
-
} else {
|
|
333
|
-
appRoot.value.style.paddingRight = '';
|
|
334
|
-
header.value.style.paddingRight = '';
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
function setAvailableModes(modes: AgentMode[], defaultModeName?: string | null) {
|
|
340
|
-
availableModes.value = modes;
|
|
341
|
-
activeModeName.value =
|
|
342
|
-
modes.find((mode: AgentMode) => mode.name === activeModeName.value)?.name
|
|
343
|
-
?? defaultModeName
|
|
344
|
-
?? modes[0]?.name
|
|
345
|
-
?? null;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
function setCurrentGenerationModeFromLocalStorage() {
|
|
349
|
-
const activeModeNameFromLocalStorage = getLocalStorageItem('activeModeName');
|
|
350
|
-
if (activeModeNameFromLocalStorage) {
|
|
351
|
-
setActiveMode(activeModeNameFromLocalStorage);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function setActiveMode(modeName: string) {
|
|
356
|
-
if (!availableModes.value.some((mode: AgentMode) => mode.name === modeName)) {
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
setLocalStorageItem('activeModeName', modeName);
|
|
360
|
-
activeModeName.value = modeName;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
async function closeChat() {
|
|
364
|
-
if (!isChatOpen.value) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
await executeOnBeforeChatCloseCallbacks();
|
|
368
|
-
if(isFullScreen.value) {
|
|
369
|
-
document.body.style.overflow = '';
|
|
370
|
-
}
|
|
371
|
-
if (blockCloseOfChat.value) {
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
isChatOpen.value = false;
|
|
375
|
-
if (isFullScreen.value) {
|
|
376
|
-
setFullScreen(false);
|
|
377
|
-
}
|
|
378
|
-
isSessionHistoryOpen.value = false;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function openChat() {
|
|
382
|
-
if (isFullScreen.value) {
|
|
383
|
-
document.body.style.overflow = 'hidden';
|
|
384
|
-
}
|
|
385
|
-
if (coreStore.isMobile) {
|
|
386
|
-
setFullScreen(true);
|
|
387
|
-
}
|
|
388
|
-
isChatOpen.value = true;
|
|
389
|
-
nextTick(() => {
|
|
390
|
-
focusTextInput();
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function focusTextInput() {
|
|
395
|
-
textInput.value?.focus();
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function setIsChatOpen(isOpen: boolean) {
|
|
399
|
-
isOpen ? openChat() : closeChat();
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
function setSessionHistoryOpen(isOpen: boolean) {
|
|
403
|
-
isSessionHistoryOpen.value = isOpen;
|
|
404
|
-
}
|
|
405
|
-
function regisrerTextInput(el: HTMLTextAreaElement | null) {
|
|
406
|
-
textInput.value = el;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
function abortCurrentChatRequestAndAddSystemMessage() {
|
|
410
|
-
abortCurrentChatRequest();
|
|
411
|
-
addSystemMessage(RESERVED_SYSTEM_MESSAGE_CONTENT.AGENT_RESPONSE_ABORTED);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function resolveInternalRoute(href: string): string | null {
|
|
415
|
-
if (href.startsWith('#')) {
|
|
416
|
-
return `${window.location.pathname}${window.location.search}${href}`;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (href.startsWith('//')) {
|
|
420
|
-
return null;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
const isAbsoluteWithScheme = /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(href);
|
|
424
|
-
const baseUrl = isAbsoluteWithScheme
|
|
425
|
-
? undefined
|
|
426
|
-
: `${window.location.origin}/`;
|
|
427
|
-
const resolvedUrl = new URL(href, baseUrl ?? window.location.href);
|
|
428
|
-
|
|
429
|
-
if (resolvedUrl.origin !== window.location.origin) {
|
|
430
|
-
return null;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
return `${resolvedUrl.pathname}${resolvedUrl.search}${resolvedUrl.hash}`;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function openAgentPage(targetPath: string) {
|
|
437
|
-
const internalRoute = resolveInternalRoute(targetPath);
|
|
438
|
-
|
|
439
|
-
if (internalRoute === null) {
|
|
440
|
-
console.warn('Ignoring external agent navigation target:', targetPath);
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
if (isFullScreen.value && !coreStore.isMobile) {
|
|
445
|
-
setFullScreen(false);
|
|
446
|
-
} else if (coreStore.isMobile) {
|
|
447
|
-
setIsChatOpen(false);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
void router.push(internalRoute);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
return {
|
|
454
|
-
//_________-Sessions management-_____________
|
|
455
|
-
activeSessionId,
|
|
456
|
-
currentSession,
|
|
457
|
-
sessions,
|
|
458
|
-
sessionList,
|
|
459
|
-
setActiveSession,
|
|
460
|
-
fetchSessionsList,
|
|
461
|
-
deleteSession,
|
|
462
|
-
createPreSession,
|
|
463
|
-
//____________________________________________
|
|
464
|
-
regisrerTextInput,
|
|
465
|
-
fetchPlaceholderMessages,
|
|
466
|
-
stopPlaceholderAnimation,
|
|
467
|
-
isChatOpen,
|
|
468
|
-
setIsChatOpen,
|
|
469
|
-
isSessionHistoryOpen,
|
|
470
|
-
setSessionHistoryOpen,
|
|
471
|
-
sendMessage,
|
|
472
|
-
submitToolApproval,
|
|
473
|
-
userMessageInput,
|
|
474
|
-
userMessagePlaceholder,
|
|
475
|
-
chatMessages: computed(() => currentChat.value?.messages || []),
|
|
476
|
-
trimmedUserMessage,
|
|
477
|
-
isResponseInProgress,
|
|
478
|
-
hasPendingToolApproval,
|
|
479
|
-
isMessageInputBlocked,
|
|
480
|
-
isTeleportedToBody,
|
|
481
|
-
setIsTeleportedToBody,
|
|
482
|
-
chatWidth,
|
|
483
|
-
setChatWidth,
|
|
484
|
-
focusTextInput,
|
|
485
|
-
setFullScreen,
|
|
486
|
-
isFullScreen,
|
|
487
|
-
availableModes,
|
|
488
|
-
activeModeName,
|
|
489
|
-
setAvailableModes,
|
|
490
|
-
setCurrentGenerationModeFromLocalStorage,
|
|
491
|
-
setActiveMode,
|
|
492
|
-
DEFAULT_CHAT_WIDTH,
|
|
493
|
-
MAX_WIDTH,
|
|
494
|
-
MIN_WIDTH,
|
|
495
|
-
RESERVED_SYSTEM_MESSAGE_CONTENT,
|
|
496
|
-
getLocalStorageItem,
|
|
497
|
-
addDebugMessage,
|
|
498
|
-
abortCurrentChatRequestAndAddSystemMessage,
|
|
499
|
-
addSystemMessage,
|
|
500
|
-
isAudioChatMode,
|
|
501
|
-
setIsAudioChatMode,
|
|
502
|
-
registerOnBeforeChatCloseCallback,
|
|
503
|
-
addAgentMessage,
|
|
504
|
-
addUserMessage,
|
|
505
|
-
addDataToolCallMessage,
|
|
506
|
-
openAgentPage,
|
|
507
|
-
setCurrentChatStatus,
|
|
508
|
-
updateLastAgentMessage
|
|
509
|
-
}
|
|
510
|
-
})
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia';
|
|
2
|
-
import { ref, nextTick,onMounted } from 'vue';
|
|
3
|
-
import { useAgentStore } from './useAgentStore';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const useAgentTransitions = defineStore('agentTransitions', () => {
|
|
7
|
-
const TRANSITION_DURATION = 300;
|
|
8
|
-
|
|
9
|
-
const agentStore = useAgentStore();
|
|
10
|
-
const appRoot = ref<HTMLElement | null>(null);
|
|
11
|
-
const header = ref<HTMLElement | null>(null);
|
|
12
|
-
|
|
13
|
-
const chatRoot = ref<HTMLElement | null>(null);
|
|
14
|
-
|
|
15
|
-
onMounted(() => {
|
|
16
|
-
appRoot.value = document.getElementById('app');
|
|
17
|
-
header.value = document.getElementById('af-header-nav');
|
|
18
|
-
chatRoot.value = document.getElementById('adminforth-agent-chat-surface');
|
|
19
|
-
if (appRoot.value && header.value) {
|
|
20
|
-
nextTick(() => {
|
|
21
|
-
setAppRootTransition(false);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
if (chatRoot.value) {
|
|
25
|
-
nextTick(() => {
|
|
26
|
-
setChatSurfaceTransition(false);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
function setAppRootTransition(blockTransition = true) {
|
|
31
|
-
if (appRoot.value && header.value) {
|
|
32
|
-
if (blockTransition) {
|
|
33
|
-
appRoot.value.style.transition = '';
|
|
34
|
-
header.value.style.transition = '';
|
|
35
|
-
} else {
|
|
36
|
-
appRoot.value.style.transition = `padding-right ${TRANSITION_DURATION}ms ease-in-out`;
|
|
37
|
-
header.value.style.transition = `padding-right ${TRANSITION_DURATION}ms ease-in-out`;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function setChatSurfaceTransition(blockTransition = true) {
|
|
42
|
-
if (chatRoot.value) {
|
|
43
|
-
if (blockTransition) {
|
|
44
|
-
chatRoot.value.style.transition = '';
|
|
45
|
-
} else {
|
|
46
|
-
chatRoot.value.style.transition = `
|
|
47
|
-
transform ${TRANSITION_DURATION}ms ease-in-out,
|
|
48
|
-
width ${TRANSITION_DURATION}ms ease-in-out
|
|
49
|
-
`;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
TRANSITION_DURATION,
|
|
55
|
-
setAppRootTransition,
|
|
56
|
-
setChatSurfaceTransition
|
|
57
|
-
}
|
|
58
|
-
});
|