Compare commits

..

14 Commits

Author SHA1 Message Date
Gao Jinzhe 9ab11f3f7f Revert "feat: add batch operation functionality for session management" 2026-01-15 19:39:28 +08:00
Gao Jinzhe e0f3fb3c3d Merge pull request #4194 from Luna-channel/feat/session-management
feat: add batch operation functionality for session management
2026-01-15 19:38:24 +08:00
Soulter fef789e4d3 feat: add Docker Compose configuration for AstrBot and Shipyard services 2026-01-15 18:53:24 +08:00
Soulter 680b900c76 feat: implement iPython tool and reasoning blocks with enhanced UI components 2026-01-15 18:15:42 +08:00
Soulter f797f132cf perf: refine tool call related prompts 2026-01-15 17:22:50 +08:00
Soulter 941ab6db84 chore: add requirement 2026-01-15 16:19:26 +08:00
Soulter 5eea508296 feat: astrbot agent sandbox env(improved code interpreter) (#4449)
* stage

* fix: update tool call logging to include tool call IDs and enhance sandbox ship creation parameters

* feat: file upload

* fix

* update

* fix: remove 'boxlite' option from booter and handle error in PythonTool execution

* feat: implement singleton pattern for ShipyardSandboxClient and add FileUploadTool for file uploads

* feat: sandbox

* fix

* beta

* uv lock

* remove

* chore: makes world better

* feat: implement localStorage persistence for showReservedPlugins state

* docs: refine EULA

* fix

* feat: add availability check for sandbox in Shipyard and base booters

* feat: add shipyard session configuration options and update related tools

* feat: add file download functionality and update shipyard SDK version

* fix: sending OpenAI-style image_url causes Anthropic 400 invalid tag error (#4444)

* feat: chatui project (#4477)

* feat: chatui-project

* fix: remove console log from getProjects function

* fix: title saving logic and update project sessions on changes

* docs: standardize Context class documentation formatting (#4436)

* docs: standardize Context class documentation formatting

- Unified all method docstrings to standard format
- Fixed mixed language and formatting issues
- Added complete parameter and return descriptions
- Enhanced developer experience for plugin creators
- Fixes #4429

* docs: fix Context class documentation issues per review

- Restored Sphinx directives for versionadded notes
- Fixed MessageSesion typo to MessageSession throughout file
- Added clarification for kwargs propagation in tool_loop_agent
- Unified deprecation marker format
- Fixes #4429

* Convert developer API comments to English

* chore: revise comments

---------

Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>

* fix: handle empty output case in PythonTool execution

* fix: update description for command parameter in ExecuteShellTool

* refactor: remove unused file tools and update PythonTool output handling

* project list

* fix: ensure message stream order (#4487)

* feat: enhance iPython tool rendering with Shiki syntax highlighting

* bugfixes

* feat: add sandbox mode prompt for enhanced user guidance in executing commands

* chore: remove skills prompt

---------

Co-authored-by: 時壹 <137363396+KBVsent@users.noreply.github.com>
Co-authored-by: Li-shi-ling <114913764+Li-shi-ling@users.noreply.github.com>
2026-01-15 16:17:56 +08:00
時壹 9782d1bff8 fix:exclude disabled commands from platform command registration (#4485) 2026-01-15 14:04:15 +08:00
Soulter 0e3d224c12 fix: ensure message stream order (#4487) 2026-01-15 13:11:27 +08:00
Luna-channel 61dfb0f207 chore: remove unnecessary files and revert auto_release.yml 2025-12-25 15:04:47 +08:00
Luna-channel 6f9cb770be 修复格式问题 2025-12-25 14:40:33 +08:00
Luna-channel f4e05e1352 2.0 2025-12-25 02:25:38 +08:00
Luna-channel 8af46ab804 稳定版 2025-12-25 01:44:24 +08:00
Luna-channel 9d32c4e720 自定义规则界面修改 2025-12-25 00:37:10 +08:00
13 changed files with 722 additions and 404 deletions
@@ -227,7 +227,8 @@ class ToolLoopAgentRunner(BaseAgentRunner[TContext]):
encrypted=llm_resp.reasoning_signature,
)
)
parts.append(TextPart(text=llm_resp.completion_text or "*No response*"))
if llm_resp.completion_text:
parts.append(TextPart(text=llm_resp.completion_text))
self.run_context.messages.append(Message(role="assistant", content=parts))
# call the on_agent_done hook
@@ -277,7 +278,8 @@ class ToolLoopAgentRunner(BaseAgentRunner[TContext]):
encrypted=llm_resp.reasoning_signature,
)
)
parts.append(TextPart(text=llm_resp.completion_text or "*No response*"))
if llm_resp.completion_text:
parts.append(TextPart(text=llm_resp.completion_text))
tool_calls_result = ToolCallsResult(
tool_calls_info=AssistantMessageSegment(
tool_calls=llm_resp.to_openai_to_calls_model(),
@@ -361,7 +363,7 @@ class ToolLoopAgentRunner(BaseAgentRunner[TContext]):
ToolCallMessageSegment(
role="tool",
tool_call_id=func_tool_id,
content=f"error: 未找到工具 {func_tool_name}",
content=f"error: Tool {func_tool_name} not found.",
),
)
continue
@@ -427,7 +429,7 @@ class ToolLoopAgentRunner(BaseAgentRunner[TContext]):
ToolCallMessageSegment(
role="tool",
tool_call_id=func_tool_id,
content="返回了图片(已直接发送给用户)",
content="The tool has successfully returned an image and sent directly to the user. You can describe it in your next response.",
),
)
yield MessageChain(type="tool_direct_result").base64_image(
@@ -452,7 +454,7 @@ class ToolLoopAgentRunner(BaseAgentRunner[TContext]):
ToolCallMessageSegment(
role="tool",
tool_call_id=func_tool_id,
content="返回了图片(已直接发送给用户)",
content="The tool has successfully returned an image and sent directly to the user. You can describe it in your next response.",
),
)
yield MessageChain(
@@ -463,7 +465,7 @@ class ToolLoopAgentRunner(BaseAgentRunner[TContext]):
ToolCallMessageSegment(
role="tool",
tool_call_id=func_tool_id,
content="返回的数据类型不受支持",
content="The tool has returned a data type that is not supported.",
),
)
@@ -480,7 +482,7 @@ class ToolLoopAgentRunner(BaseAgentRunner[TContext]):
ToolCallMessageSegment(
role="tool",
tool_call_id=func_tool_id,
content="*工具没有返回值或者将结果直接发送给了用户*",
content="The tool has no return value, or has sent the result directly to the user.",
),
)
else:
@@ -492,7 +494,7 @@ class ToolLoopAgentRunner(BaseAgentRunner[TContext]):
ToolCallMessageSegment(
role="tool",
tool_call_id=func_tool_id,
content="*工具返回了不支持的类型,请告诉用户检查这个工具的定义和实现。*",
content="*The tool has returned an unsupported type. Please tell the user to check the definition and implementation of this tool.*",
),
)
@@ -36,6 +36,7 @@ from .....astr_agent_tool_exec import FunctionToolExecutor
from ....context import PipelineContext, call_event_hook
from ...stage import Stage
from ...utils import (
CHATUI_EXTRA_PROMPT,
EXECUTE_SHELL_TOOL,
FILE_DOWNLOAD_TOOL,
FILE_UPLOAD_TOOL,
@@ -43,6 +44,7 @@ from ...utils import (
LLM_SAFETY_MODE_SYSTEM_PROMPT,
PYTHON_TOOL,
SANDBOX_MODE_PROMPT,
TOOL_CALL_PROMPT,
decoded_blocked,
retrieve_knowledge_base,
)
@@ -657,6 +659,14 @@ class InternalAgentSubStage(Stage):
if event.get_platform_name() == "webchat":
asyncio.create_task(self._handle_webchat(event, req, provider))
# 注入 ChatUI 额外 prompt
# 比如 follow-up questions 提示等
req.system_prompt += f"\n{CHATUI_EXTRA_PROMPT}\n"
# 注入基本 prompt
if req.func_tool and req.func_tool.tools:
req.system_prompt += f"\n{TOOL_CALL_PROMPT}\n"
await agent_runner.reset(
provider=provider,
request=req,
+11 -3
View File
@@ -36,9 +36,17 @@ SANDBOX_MODE_PROMPT = (
# "Use `cat /app/skills/{skill_name}/SKILL.md` to read the documentation of a specific skill."
# "SKILL.md might be large, you can read the description first, which is located in the YAML frontmatter of the file."
# "Use shell commands such as grep, sed, awk to extract relevant information from the documentation as needed.\n"
"Note:\n"
"1. If you use shell, your command will always runs in the /home/<username>/workspace directory.\n"
"2. If you use IPython, you would better use absolute paths when dealing with files to avoid confusion.\n"
)
TOOL_CALL_PROMPT = (
"You MUST NOT return an empty response, especially after invoking a tool."
"Before calling any tool, provide a brief explanatory message to the user stating the purpose of the tool call."
"After the tool call is completed, you must briefly summarize the results returned by the tool for the user."
)
CHATUI_EXTRA_PROMPT = (
'When you answered, you need to add a follow up question / summarization but do not add "Follow up" words. '
"Such as, user asked you to generate codes, you can add: Do you need me to run these codes for you?"
)
@@ -370,6 +370,8 @@ class DiscordPlatformAdapter(Platform):
for handler_md in star_handlers_registry:
if not star_map[handler_md.handler_module_path].activated:
continue
if not handler_md.enabled:
continue
for event_filter in handler_md.event_filters:
cmd_info = self._extract_command_info(event_filter, handler_md)
if not cmd_info:
@@ -161,6 +161,8 @@ class TelegramPlatformAdapter(Platform):
handler_metadata = handler_md
if not star_map[handler_metadata.handler_module_path].activated:
continue
if not handler_metadata.enabled:
continue
for event_filter in handler_metadata.event_filters:
cmd_info = self._extract_command_info(
event_filter,
+47
View File
@@ -0,0 +1,47 @@
version: '3.8'
# 当接入 QQ NapCat 时,请使用这个 compose 文件一键部署: https://github.com/NapNeko/NapCat-Docker/blob/main/compose/astrbot.yml
services:
astrbot:
image: soulter/astrbot:latest
container_name: astrbot
restart: always
ports: # mappings description: https://github.com/AstrBotDevs/AstrBot/issues/497
- "6185:6185" # 必选,AstrBot WebUI 端口
- "6199:6199" # 可选, QQ 个人号 WebSocket 端口
environment:
- TZ=Asia/Shanghai
volumes:
- ${PWD}/data:/AstrBot/data
# - /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
networks:
- astrbot_network
shipyard:
image: soulter/shipyard-bay:latest
container_name: astrbot_shipyard
# ports:
# - "8156:8156"
environment:
- PORT=8156
- DATABASE_URL=sqlite+aiosqlite:///./data/bay.db
- ACCESS_TOKEN=secret-token
- MAX_SHIP_NUM=10
- BEHAVIOR_AFTER_MAX_SHIP=reject
- DOCKER_IMAGE=soulter/shipyard-ship:latest
- DOCKER_NETWORK=astrbot_network
- SHIP_DATA_DIR=${PWD}/data/shipyard/ship_mnt_data
- DEFAULT_SHIP_CPUS=1.0
- DEFAULT_SHIP_MEMORY=512m
volumes:
- ${PWD}/data/shipyard/bay_data:/app/data
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- astrbot_network
networks:
astrbot_network:
name: astrbot_network
driver: bridge
+45 -390
View File
@@ -90,103 +90,28 @@
<template v-else>
<!-- Reasoning Block (Collapsible) - 放在最前面 -->
<div v-if="msg.content.reasoning && msg.content.reasoning.trim()"
class="reasoning-container" :class="{ 'is-dark': isDark }"
:style="isDark ? { backgroundColor: 'rgba(103, 58, 183, 0.08)' } : {}">
<div class="reasoning-header" :class="{ 'is-dark': isDark }"
@click="toggleReasoning(index)">
<v-icon size="small" class="reasoning-icon">
{{ isReasoningExpanded(index) ? 'mdi-chevron-down' : 'mdi-chevron-right' }}
</v-icon>
<span class="reasoning-label">{{ tm('reasoning.thinking') }}</span>
</div>
<div v-if="isReasoningExpanded(index)" class="reasoning-content">
<MarkdownRender :content="msg.content.reasoning"
class="reasoning-text markdown-content" :typewriter="false"
:style="isDark ? { opacity: '0.85' } : {}" :is-dark="isDark" />
</div>
</div>
<ReasoningBlock v-if="msg.content.reasoning && msg.content.reasoning.trim()"
:reasoning="msg.content.reasoning" :is-dark="isDark"
:initial-expanded="isReasoningExpanded(index)" />
<!-- 遍历 message parts (保持顺序) -->
<template v-for="(part, partIndex) in msg.content.message" :key="partIndex">
<!-- Tool Calls Block -->
<div v-if="part.type === 'tool_call' && part.tool_calls && part.tool_calls.length > 0"
class="tool-calls-container">
<div class="tool-calls-label">{{ tm('actions.toolsUsed') }}</div>
<div v-for="(toolCall, tcIndex) in part.tool_calls" :key="toolCall.id"
class="tool-call-card" :class="{ 'is-dark': isDark, 'expanded': isToolCallExpanded(index, partIndex, tcIndex) }" :style="isDark ? {
backgroundColor: 'rgba(40, 60, 100, 0.4)',
borderColor: 'rgba(100, 140, 200, 0.4)'
} : {}">
<div class="tool-call-header" :class="{ 'is-dark': isDark }"
@click="toggleToolCall(index, partIndex, tcIndex)">
<v-icon size="small" class="tool-call-expand-icon">
{{ isToolCallExpanded(index, partIndex, tcIndex) ?
'mdi-chevron-down' : 'mdi-chevron-right' }}
</v-icon>
<v-icon size="small" class="tool-call-icon">mdi-wrench-outline</v-icon>
<div class="tool-call-info">
<span class="tool-call-name">{{ toolCall.name }}</span>
</div>
<span class="tool-call-status"
:class="{ 'status-running': !toolCall.finished_ts, 'status-finished': toolCall.finished_ts }">
<template v-if="toolCall.finished_ts">
<v-icon size="x-small"
class="status-icon">mdi-check-circle</v-icon>
{{ formatDuration(toolCall.finished_ts - toolCall.ts) }}
</template>
<template v-else>
<v-icon size="x-small"
class="status-icon spinning">mdi-loading</v-icon>
{{ getElapsedTime(toolCall.ts) }}
</template>
</span>
</div>
<div v-if="isToolCallExpanded(index, partIndex, tcIndex)"
class="tool-call-details" :style="isDark ? {
borderTopColor: 'rgba(100, 140, 200, 0.3)',
backgroundColor: 'rgba(30, 45, 70, 0.5)'
} : {}">
<!-- Special rendering for iPython tool -->
<template v-if="isIPythonTool(toolCall)">
<div class="ipython-code-container">
<!-- <div class="detail-label ipython-label">Code:</div> -->
<div v-if="shikiReady && getIPythonCode(toolCall)"
class="ipython-code-highlighted"
v-html="highlightIPythonCode(getIPythonCode(toolCall))"></div>
<pre v-else class="detail-value detail-json"
:style="isDark ? { backgroundColor: 'transparent' } : {}">{{ getIPythonCode(toolCall) || 'No code available' }}</pre>
</div>
<div v-if="toolCall.result" class="tool-call-detail-row">
<span class="detail-label">Result:</span>
<pre class="detail-value detail-json detail-result"
:style="isDark ? { backgroundColor: 'transparent' } : {}">{{ formatToolResult(toolCall.result) }}</pre>
</div>
</template>
<!-- Default rendering for other tools -->
<template v-else>
<div class="tool-call-detail-row">
<span class="detail-label">ID:</span>
<code class="detail-value"
:style="isDark ? { backgroundColor: 'transparent' } : {}">{{ toolCall.id
}}</code>
</div>
<div class="tool-call-detail-row">
<span class="detail-label">Args:</span>
<pre class="detail-value detail-json"
:style="isDark ? { backgroundColor: 'transparent' } : {}">{{
JSON.stringify(toolCall.args, null, 2) }}</pre>
</div>
<div v-if="toolCall.result" class="tool-call-detail-row">
<span class="detail-label">Result:</span>
<pre class="detail-value detail-json detail-result"
:style="isDark ? { backgroundColor: 'transparent' } : {}">{{ formatToolResult(toolCall.result) }}
</pre>
</div>
</template>
</div>
</div>
<!-- iPython Tool Special Block -->
<template v-if="part.type === 'tool_call' && part.tool_calls && part.tool_calls.length > 0">
<template v-for="(toolCall, tcIndex) in part.tool_calls" :key="toolCall.id">
<IPythonToolBlock v-if="isIPythonTool(toolCall)" :tool-call="toolCall" style="margin: 8px 0;"
:is-dark="isDark"
:initial-expanded="isIPythonToolExpanded(index, partIndex, tcIndex)" />
</template>
</template>
<!-- Regular Tool Calls Block (for non-iPython tools) -->
<div v-if="part.type === 'tool_call' && part.tool_calls && part.tool_calls.some(tc => !isIPythonTool(tc))"
class="flex flex-col gap-2">
<div class="font-medium opacity-70" style="font-size: 13px; margin-bottom: 16px;">{{ tm('actions.toolsUsed') }}</div>
<ToolCallCard v-for="(toolCall, tcIndex) in part.tool_calls.filter(tc => !isIPythonTool(tc))"
:key="toolCall.id" :tool-call="toolCall" :is-dark="isDark"
:initial-expanded="isToolCallExpanded(index, partIndex, tcIndex)" />
</div>
<!-- Text (Markdown) -->
@@ -325,7 +250,9 @@ import 'markstream-vue/index.css'
import 'katex/dist/katex.min.css'
import 'highlight.js/styles/github.css';
import axios from 'axios';
import { createHighlighter } from 'shiki';
import ReasoningBlock from './message_list_comps/ReasoningBlock.vue';
import IPythonToolBlock from './message_list_comps/IPythonToolBlock.vue';
import ToolCallCard from './message_list_comps/ToolCallCard.vue';
enableKatex();
enableMermaid();
@@ -333,7 +260,10 @@ enableMermaid();
export default {
name: 'MessageList',
components: {
MarkdownRender
MarkdownRender,
ReasoningBlock,
IPythonToolBlock,
ToolCallCard
},
props: {
messages: {
@@ -372,6 +302,7 @@ export default {
expandedReasoning: new Set(), // Track which reasoning blocks are expanded
downloadingFiles: new Set(), // Track which files are being downloaded
expandedToolCalls: new Set(), // Track which tool call cards are expanded
expandedIPythonTools: new Set(), // Track which iPython tools are expanded
elapsedTimeTimer: null, // Timer for updating elapsed time
currentTime: Date.now() / 1000, // Current time for elapsed time calculation
// 选中文本相关状态
@@ -384,10 +315,7 @@ export default {
imagePreview: {
show: false,
url: ''
},
// Shiki highlighter
shikiHighlighter: null,
shikiReady: false
}
};
},
async mounted() {
@@ -396,7 +324,6 @@ export default {
this.addScrollListener();
this.scrollToBottom();
this.startElapsedTimeTimer();
await this.initShiki();
},
updated() {
this.initCodeCopyButtons();
@@ -545,6 +472,23 @@ export default {
return this.expandedReasoning.has(messageIndex);
},
// Toggle iPython tool expansion state
toggleIPythonTool(messageIndex, partIndex, toolCallIndex) {
const key = `${messageIndex}-${partIndex}-${toolCallIndex}`;
if (this.expandedIPythonTools.has(key)) {
this.expandedIPythonTools.delete(key);
} else {
this.expandedIPythonTools.add(key);
}
// Force reactivity
this.expandedIPythonTools = new Set(this.expandedIPythonTools);
},
// Check if iPython tool is expanded
isIPythonToolExpanded(messageIndex, partIndex, toolCallIndex) {
return this.expandedIPythonTools.has(`${messageIndex}-${partIndex}-${toolCallIndex}`);
},
// 下载文件
async downloadFile(file) {
if (!file.attachment_id) return;
@@ -930,50 +874,9 @@ export default {
}, 300);
},
// Initialize Shiki highlighter
async initShiki() {
try {
this.shikiHighlighter = await createHighlighter({
themes: ['nord', 'github-light'],
langs: ['python']
});
this.shikiReady = true;
} catch (err) {
console.error('Failed to initialize Shiki:', err);
}
},
// Check if tool is iPython executor
isIPythonTool(toolCall) {
return toolCall.name === 'astrbot_execute_ipython';
},
// Get iPython code from tool args
getIPythonCode(toolCall) {
try {
if (toolCall.args && toolCall.args.code) {
return toolCall.args.code;
}
} catch (err) {
console.error('Failed to get iPython code:', err);
}
return null;
},
// Highlight iPython code with Shiki
highlightIPythonCode(code) {
if (!this.shikiReady || !this.shikiHighlighter || !code) {
return '';
}
try {
return this.shikiHighlighter.codeToHtml(code, {
lang: 'python',
theme: this.isDark ? 'nord' : 'github-light'
});
} catch (err) {
console.error('Failed to highlight code:', err);
return `<pre><code>${code}</code></pre>`;
}
}
}
}
@@ -1443,167 +1346,6 @@ export default {
animation: fadeIn 0.3s ease-in-out;
}
/* Reasoning 区块样式 */
.reasoning-container {
margin-bottom: 12px;
margin-top: 6px;
border: 1px solid var(--v-theme-border);
border-radius: 20px;
overflow: hidden;
width: fit-content;
}
.reasoning-header {
display: inline-flex;
align-items: center;
padding: 8px 8px;
cursor: pointer;
user-select: none;
transition: background-color 0.2s ease;
border-radius: 20px;
}
.reasoning-header:hover {
background-color: rgba(103, 58, 183, 0.08);
}
.reasoning-header.is-dark:hover {
background-color: rgba(103, 58, 183, 0.15);
}
.reasoning-icon {
margin-right: 6px;
color: var(--v-theme-secondary);
transition: transform 0.2s ease;
}
.reasoning-label {
font-size: 13px;
font-weight: 500;
color: var(--v-theme-secondary);
letter-spacing: 0.3px;
}
.reasoning-content {
padding: 0px 12px;
border-top: 1px solid var(--v-theme-border);
color: gray;
animation: fadeIn 0.2s ease-in-out;
font-style: italic;
}
.reasoning-text {
font-size: 14px;
line-height: 1.6;
color: var(--v-theme-secondaryText);
}
/* Tool Call Card Styles */
.tool-calls-container {
display: flex;
flex-direction: column;
gap: 8px;
margin-bottom: 12px;
margin-top: 6px;
}
.tool-calls-label {
font-size: 13px;
font-weight: 500;
color: var(--v-theme-secondaryText);
opacity: 0.7;
margin-bottom: 4px;
}
.tool-call-card {
border-radius: 8px;
overflow: hidden;
background-color: #eff3f6;
margin: 8px 0px;
width: fit-content;
min-width: 320px;
max-width: 100%;
transition: all 0.1s ease;
}
.tool-call-card.expanded {
width: 100%;
}
.tool-call-header {
display: flex;
align-items: center;
padding: 10px 12px;
cursor: pointer;
user-select: none;
transition: background-color 0.2s ease;
gap: 8px;
}
.tool-call-header:hover {
background-color: rgba(169, 194, 219, 0.15);
}
.tool-call-header.is-dark:hover {
background-color: rgba(100, 150, 200, 0.2);
}
.tool-call-expand-icon {
color: var(--v-theme-secondary);
transition: transform 0.2s ease;
flex-shrink: 0;
}
.tool-call-icon {
color: var(--v-theme-secondary);
flex-shrink: 0;
}
.tool-call-info {
display: flex;
flex-direction: column;
gap: 2px;
flex: 1;
min-width: 0;
}
.tool-call-name {
font-size: 13px;
font-weight: 600;
color: var(--v-theme-secondary);
}
.tool-call-id {
font-size: 11px;
color: var(--v-theme-secondaryText);
opacity: 0.7;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.tool-call-status {
margin-left: 8px;
display: flex;
align-items: center;
gap: 4px;
font-size: 12px;
font-weight: 500;
flex-shrink: 0;
}
.tool-call-status.status-running {
color: #ff9800;
}
.tool-call-status.status-finished {
color: #4caf50;
}
.tool-call-status .status-icon {
font-size: 14px;
}
/* 浮动引用按钮样式 */
.selection-quote-button {
position: fixed;
@@ -1614,7 +1356,6 @@ export default {
pointer-events: all;
}
.quote-btn {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
font-size: 14px;
@@ -1634,94 +1375,8 @@ export default {
color: #ffffff !important;
}
.tool-call-status .status-icon.spinning {
animation: spin 1s linear infinite;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.tool-call-details {
padding: 12px;
background-color: rgba(255, 255, 255, 0.5);
animation: fadeIn 0.2s ease-in-out;
}
.tool-call-detail-row {
display: flex;
flex-direction: column;
margin-bottom: 8px;
}
.tool-call-detail-row:last-child {
margin-bottom: 0;
}
.detail-label {
font-size: 11px;
font-weight: 600;
color: var(--v-theme-secondaryText);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 4px;
}
.detail-value {
font-size: 12px;
color: var(--v-theme-primaryText);
background-color: transparent;
padding: 4px 8px;
border-radius: 4px;
word-break: break-all;
}
.detail-json {
font-family: 'Fira Code', 'Consolas', monospace;
white-space: pre-wrap;
max-height: 200px;
overflow-y: auto;
margin: 0;
}
.detail-result {
max-height: 300px;
background-color: transparent;
}
/* iPython Tool Special Styles */
.ipython-code-container {
margin-bottom: 12px;
}
.ipython-label {
margin-bottom: 8px;
}
.ipython-code-highlighted {
border-radius: 6px;
overflow-x: auto;
font-size: 13px;
line-height: 1.5;
}
.ipython-code-highlighted :deep(pre) {
margin: 0;
padding: 12px;
border-radius: 6px;
overflow-x: auto;
}
.ipython-code-highlighted :deep(code) {
font-family: 'Fira Code', 'Consolas', monospace;
font-size: 13px;
}
</style>
<style>
@@ -0,0 +1,220 @@
<template>
<div class="mb-3 mt-1.5">
<div class="ipython-header" :class="{ 'expanded': isExpanded }" @click="toggleExpanded">
<span class="ipython-label">
{{ tm('actions.pythonCodeAnalysis') }}
</span>
<v-icon size="small" class="ipython-icon" :class="{ 'rotated': isExpanded }">
mdi-chevron-right
</v-icon>
</div>
<div v-if="isExpanded" class="py-3 animate-fade-in">
<!-- Code Section -->
<div class="code-section">
<div v-if="shikiReady && code" class="code-highlighted"
v-html="highlightedCode"></div>
<pre v-else class="code-fallback"
:class="{ 'dark-theme': isDark }">{{ code || 'No code available' }}</pre>
</div>
<!-- Result Section -->
<div v-if="result" class="result-section">
<div class="result-label">
{{ tm('ipython.output') }}:
</div>
<pre class="result-content"
:class="{ 'dark-theme': isDark }">{{ formattedResult }}</pre>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue';
import { useModuleI18n } from '@/i18n/composables';
import { createHighlighter } from 'shiki';
const props = defineProps({
toolCall: {
type: Object,
required: true
},
isDark: {
type: Boolean,
default: false
},
initialExpanded: {
type: Boolean,
default: false
}
});
const { tm } = useModuleI18n('features/chat');
const isExpanded = ref(props.initialExpanded);
const shikiHighlighter = ref(null);
const shikiReady = ref(false);
const code = computed(() => {
try {
if (props.toolCall.args && props.toolCall.args.code) {
return props.toolCall.args.code;
}
} catch (err) {
console.error('Failed to get iPython code:', err);
}
return null;
});
const result = computed(() => props.toolCall.result);
const formattedResult = computed(() => {
if (!result.value) return '';
try {
const parsed = JSON.parse(result.value);
return JSON.stringify(parsed, null, 2);
} catch {
return result.value;
}
});
const highlightedCode = computed(() => {
if (!shikiReady.value || !shikiHighlighter.value || !code.value) {
return '';
}
try {
return shikiHighlighter.value.codeToHtml(code.value, {
lang: 'python',
theme: props.isDark ? 'min-dark' : 'github-light'
});
} catch (err) {
console.error('Failed to highlight code:', err);
return `<pre><code>${code.value}</code></pre>`;
}
});
const toggleExpanded = () => {
isExpanded.value = !isExpanded.value;
};
onMounted(async () => {
try {
shikiHighlighter.value = await createHighlighter({
themes: ['min-dark', 'github-light'],
langs: ['python']
});
shikiReady.value = true;
} catch (err) {
console.error('Failed to initialize Shiki:', err);
}
});
</script>
<style scoped>
.mb-3 {
margin-bottom: 12px;
}
.mt-1\.5 {
margin-top: 6px;
}
.ipython-header {
display: inline-flex;
align-items: center;
cursor: pointer;
user-select: none;
border-radius: 20px;
opacity: 0.7;
transition: opacity;
}
.ipython-header:hover,
.ipython-header.expanded {
opacity: 1;
}
.ipython-label {
font-size: 16px;
}
.ipython-icon {
margin-left: 6px;
transition: transform 0.2s ease;
}
.ipython-icon.rotated {
transform: rotate(90deg);
}
.py-3 {
padding-top: 12px;
padding-bottom: 12px;
}
.code-section {
margin-bottom: 12px;
}
.code-highlighted {
border-radius: 6px;
overflow: hidden;
font-size: 14px;
line-height: 1.5;
}
.code-fallback {
margin: 0;
padding: 12px;
border-radius: 6px;
overflow-x: auto;
font-size: 13px;
line-height: 1.5;
background-color: #f5f5f5;
}
.code-fallback.dark-theme {
background-color: transparent;
}
.result-section {
margin-top: 12px;
}
.result-label {
font-size: 12px;
font-weight: 600;
color: var(--v-theme-secondaryText);
margin-bottom: 6px;
opacity: 0.8;
}
.result-content {
margin: 0;
padding: 12px;
border-radius: 6px;
overflow-x: auto;
font-size: 13px;
line-height: 1.5;
background-color: #f5f5f5;
max-height: 300px;
overflow-y: auto;
}
.result-content.dark-theme {
background-color: transparent;
}
.animate-fade-in {
animation: fadeIn 0.2s ease-in-out;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>
@@ -0,0 +1,73 @@
<template>
<div class="mb-3 mt-1.5 border border-gray-200 dark:border-gray-700 rounded-2xl overflow-hidden w-fit"
:class="{ 'dark:bg-purple-900/8': isDark, 'bg-purple-50/50': !isDark }">
<div class="inline-flex items-center px-2 py-2 cursor-pointer select-none rounded-2xl transition-colors hover:bg-purple-50/80 dark:hover:bg-purple-900/15"
@click="toggleExpanded">
<v-icon size="small" class="mr-1.5 text-purple-600 dark:text-purple-400 transition-transform"
:class="{ 'rotate-90': isExpanded }">
mdi-chevron-right
</v-icon>
<span class="text-sm font-medium text-purple-600 dark:text-purple-400 tracking-wide">
{{ tm('reasoning.thinking') }}
</span>
</div>
<div v-if="isExpanded" class="px-3 border-t border-gray-200 dark:border-gray-700 text-gray-600 dark:text-gray-400 animate-fade-in italic">
<MarkdownRender :content="reasoning" class="reasoning-text markdown-content text-sm leading-relaxed"
:typewriter="false" :is-dark="isDark" :style="isDark ? { opacity: '0.85' } : {}" />
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { useModuleI18n } from '@/i18n/composables';
import { MarkdownRender } from 'markstream-vue';
const props = defineProps({
reasoning: {
type: String,
required: true
},
isDark: {
type: Boolean,
default: false
},
initialExpanded: {
type: Boolean,
default: false
}
});
const { tm } = useModuleI18n('features/chat');
const isExpanded = ref(props.initialExpanded);
const toggleExpanded = () => {
isExpanded.value = !isExpanded.value;
};
</script>
<style scoped>
.animate-fade-in {
animation: fadeIn 0.2s ease-in-out;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.rotate-90 {
transform: rotate(90deg);
}
.reasoning-text {
font-size: 14px;
line-height: 1.6;
color: var(--v-theme-secondaryText);
}
</style>
@@ -0,0 +1,290 @@
<template>
<div class="tool-call-card" :class="{ 'is-dark': isDark, 'expanded': isExpanded }" :style="isDark ? {
backgroundColor: 'rgba(40, 60, 100, 0.4)',
borderColor: 'rgba(100, 140, 200, 0.4)'
} : {}">
<!-- Header -->
<div class="tool-call-header" :class="{ 'is-dark': isDark }" @click="toggleExpanded">
<v-icon size="small" class="tool-call-expand-icon" :class="{ 'expanded': isExpanded }">
mdi-chevron-right
</v-icon>
<v-icon size="small" class="tool-call-icon">mdi-wrench-outline</v-icon>
<div class="tool-call-info">
<span class="tool-call-name">{{ toolCall.name }}</span>
</div>
<span class="tool-call-status"
:class="{ 'status-running': !toolCall.finished_ts, 'status-finished': toolCall.finished_ts }">
<template v-if="toolCall.finished_ts">
<v-icon size="x-small" class="status-icon">mdi-check-circle</v-icon>
{{ formatDuration(toolCall.finished_ts - toolCall.ts) }}
</template>
<template v-else>
<v-icon size="x-small" class="status-icon spinning">mdi-loading</v-icon>
{{ elapsedTime }}
</template>
</span>
</div>
<!-- Details -->
<div v-if="isExpanded" class="tool-call-details" :style="isDark ? {
borderTopColor: 'rgba(100, 140, 200, 0.3)',
backgroundColor: 'rgba(30, 45, 70, 0.5)'
} : {}">
<!-- ID -->
<div class="tool-call-detail-row">
<span class="detail-label">ID:</span>
<code class="detail-value" :style="isDark ? { backgroundColor: 'transparent' } : {}">
{{ toolCall.id }}
</code>
</div>
<!-- Args -->
<div class="tool-call-detail-row">
<span class="detail-label">Args:</span>
<pre class="detail-value detail-json" :style="isDark ? { backgroundColor: 'transparent' } : {}">{{
JSON.stringify(toolCall.args, null, 2) }}</pre>
</div>
<!-- Result -->
<div v-if="toolCall.result" class="tool-call-detail-row">
<span class="detail-label">Result:</span>
<pre class="detail-value detail-json detail-result"
:style="isDark ? { backgroundColor: 'transparent' } : {}">{{
formattedResult }}</pre>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue';
const props = defineProps({
toolCall: {
type: Object,
required: true
},
isDark: {
type: Boolean,
default: false
},
initialExpanded: {
type: Boolean,
default: false
}
});
const isExpanded = ref(props.initialExpanded);
const currentTime = ref(Date.now() / 1000);
let timer = null;
const elapsedTime = computed(() => {
if (props.toolCall.finished_ts) return '';
const elapsed = currentTime.value - props.toolCall.ts;
return formatDuration(elapsed);
});
const formattedResult = computed(() => {
if (!props.toolCall.result) return '';
try {
const parsed = JSON.parse(props.toolCall.result);
return JSON.stringify(parsed, null, 2);
} catch {
return props.toolCall.result;
}
});
const formatDuration = (seconds) => {
if (seconds < 1) {
return `${Math.round(seconds * 1000)}ms`;
} else if (seconds < 60) {
return `${seconds.toFixed(1)}s`;
} else {
const minutes = Math.floor(seconds / 60);
const secs = Math.round(seconds % 60);
return `${minutes}m ${secs}s`;
}
};
const toggleExpanded = () => {
isExpanded.value = !isExpanded.value;
};
const updateTime = () => {
currentTime.value = Date.now() / 1000;
};
onMounted(() => {
// Update time periodically if tool call is running
if (!props.toolCall.finished_ts) {
timer = setInterval(updateTime, 100);
}
});
onUnmounted(() => {
if (timer) {
clearInterval(timer);
}
});
</script>
<style scoped>
.tool-call-card {
border-radius: 8px;
overflow: hidden;
background-color: #eff3f6;
margin: 8px 0px;
width: fit-content;
min-width: 320px;
max-width: 100%;
transition: all 0.1s ease;
}
.tool-call-card.expanded {
width: 100%;
}
.tool-call-header {
display: flex;
align-items: center;
padding: 10px 12px;
cursor: pointer;
user-select: none;
transition: background-color 0.2s ease;
gap: 8px;
}
.tool-call-header:hover {
background-color: rgba(169, 194, 219, 0.15);
}
.tool-call-header.is-dark:hover {
background-color: rgba(100, 150, 200, 0.2);
}
.tool-call-expand-icon {
color: var(--v-theme-secondary);
transition: transform 0.2s ease;
flex-shrink: 0;
}
.tool-call-expand-icon.expanded {
transform: rotate(90deg);
}
.tool-call-icon {
color: var(--v-theme-secondary);
flex-shrink: 0;
}
.tool-call-info {
display: flex;
flex-direction: column;
gap: 2px;
flex: 1;
min-width: 0;
}
.tool-call-name {
font-size: 13px;
font-weight: 600;
color: var(--v-theme-secondary);
}
.tool-call-status {
margin-left: 8px;
display: flex;
align-items: center;
gap: 4px;
font-size: 12px;
font-weight: 500;
flex-shrink: 0;
}
.tool-call-status.status-running {
color: #ff9800;
}
.tool-call-status.status-finished {
color: #4caf50;
}
.tool-call-status .status-icon {
font-size: 14px;
}
.tool-call-status .status-icon.spinning {
animation: spin 1s linear infinite;
}
.tool-call-details {
padding: 12px;
background-color: rgba(255, 255, 255, 0.5);
animation: fadeIn 0.2s ease-in-out;
}
.tool-call-detail-row {
display: flex;
flex-direction: column;
margin-bottom: 8px;
}
.tool-call-detail-row:last-child {
margin-bottom: 0;
}
.detail-label {
font-size: 11px;
font-weight: 600;
color: var(--v-theme-secondaryText);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 4px;
}
.detail-value {
font-size: 12px;
color: var(--v-theme-primaryText);
background-color: transparent;
padding: 4px 8px;
border-radius: 4px;
word-break: break-all;
}
.detail-json {
font-family: 'Fira Code', 'Consolas', monospace;
white-space: pre-wrap;
max-height: 200px;
overflow-y: auto;
margin: 0;
}
.detail-result {
max-height: 300px;
background-color: transparent;
}
.animate-fade-in {
animation: fadeIn 0.2s ease-in-out;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
@@ -43,7 +43,11 @@
"exitFullscreen": "Exit Fullscreen",
"reply": "Reply",
"providerConfig": "AI Configuration",
"toolsUsed": "Tool Used"
"toolsUsed": "Tool Used",
"pythonCodeAnalysis": "Python Code Analysis Used"
},
"ipython": {
"output": "Output"
},
"conversation": {
"newConversation": "New Conversation",
@@ -43,7 +43,11 @@
"exitFullscreen": "退出全屏",
"reply": "引用回复",
"providerConfig": "AI 配置",
"toolsUsed": "已使用工具"
"toolsUsed": "已使用工具",
"pythonCodeAnalysis": "已使用 Python 代码分析"
},
"ipython": {
"output": "输出"
},
"conversation": {
"newConversation": "新的聊天",
+2 -1
View File
@@ -52,4 +52,5 @@ rank-bm25>=0.2.2
jieba>=0.42.1
markitdown-no-magika[docx,xls,xlsx]>=0.1.2
xinference-client
tenacity>=9.1.2
tenacity>=9.1.2
shipyard-python-sdk>=0.2.4