mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
fix(cli): forward session context and apply preprocessing in tool adapter
agent-stream-runner: pass timeFilter and maxMessagesLimit from request params into the tool context so evidence and retrieval tools respect the active session time range in CLI Web sessions, matching the desktop runner. tool-adapter: pass preprocessConfig, anonymizeNames and ownerPlatformId to applyPreprocessingPipeline in the rawMessages branch so desensitization and name anonymization apply to search_messages / recent_messages results, matching the desktop adapter behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
69ac64791e
commit
88dea48ec6
2 files changed
+19
-1
No files matched your search
@@ -139,6 +139,8 @@ export function createCliRunAgentStream(
|
||||
semanticIndexService,
|
||||
preprocessConfig: params.preprocessConfig,
|
||||
ownerPlatformId: ownerInfo?.platformId,
|
||||
timeFilter: params.timeFilter,
|
||||
maxMessagesLimit: params.maxMessagesLimit,
|
||||
}),
|
||||
{ maxToolResultTokens }
|
||||
)
|
||||
|
||||
@@ -5,7 +5,13 @@
|
||||
* 消息类工具返回 rawMessages 时自动执行预处理管道(清洗、去噪、脱敏、截断、格式化)。
|
||||
*/
|
||||
|
||||
import type { ToolDefinition, ToolExecutionContext, SemanticSearchToolService, RawMessage } from '@openchatlab/tools'
|
||||
import type {
|
||||
ToolDefinition,
|
||||
ToolExecutionContext,
|
||||
SemanticSearchToolService,
|
||||
RawMessage,
|
||||
TimeFilter,
|
||||
} from '@openchatlab/tools'
|
||||
import { CoreDataProvider } from '@openchatlab/tools'
|
||||
import type { DatabaseAdapter } from '@openchatlab/core'
|
||||
import {
|
||||
@@ -43,6 +49,10 @@ export interface ServerToolContext {
|
||||
preprocessConfig?: Record<string, unknown>
|
||||
/** 当前用户平台 id(昵称匿名化 owner 识别) */
|
||||
ownerPlatformId?: string
|
||||
/** 会话时间范围筛选(来自请求参数,供证据类工具继承) */
|
||||
timeFilter?: TimeFilter
|
||||
/** 关键词搜索消息条数上限 */
|
||||
maxMessagesLimit?: number
|
||||
}
|
||||
|
||||
function convertJsonSchemaToParameters(schema: ToolDefinition['inputSchema']) {
|
||||
@@ -87,6 +97,8 @@ export function adaptToolsForAgent(
|
||||
semanticIndexService: ctx.semanticIndexService,
|
||||
preprocessConfig: ctx.preprocessConfig,
|
||||
ownerPlatformId: ctx.ownerPlatformId,
|
||||
timeFilter: ctx.timeFilter,
|
||||
maxMessagesLimit: ctx.maxMessagesLimit,
|
||||
maxToolResultTokens: tokenBudget,
|
||||
segmentText: (texts, locale, options) => batchSegmentWithFrequency(texts, locale as any, options as any),
|
||||
desensitizeMessages: (messages: RawMessage[]): RawMessage[] =>
|
||||
@@ -109,8 +121,12 @@ export function adaptToolsForAgent(
|
||||
// tools may mirror rawMessages inside data; keep it out of extraDetails
|
||||
// so the pipeline only renders scalar metadata (same as the desktop adapter)
|
||||
const { rawMessages: _rawInData, ...extraDetails } = (result.data ?? {}) as Record<string, unknown>
|
||||
const preprocessCfg = ctx.preprocessConfig as PreprocessConfig | undefined
|
||||
const pipelineResult = applyPreprocessingPipeline({
|
||||
rawMessages: result.rawMessages as PreprocessableMessage[],
|
||||
preprocessConfig: preprocessCfg,
|
||||
anonymizeNames: preprocessCfg?.anonymizeNames ?? false,
|
||||
ownerPlatformId: ctx.ownerPlatformId,
|
||||
locale: ctx.locale,
|
||||
maxToolResultTokens: tokenBudget,
|
||||
truncationStrategy: TOOL_TRUNCATION_STRATEGY[tool.name] ?? 'keep_last',
|
||||
|
||||
Reference in new issue
Block a user