mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
chore(deadcode): collapse session helper barrels
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
resolveStorePath,
|
||||
} from "./subagent-announce.runtime.js";
|
||||
import { assistantCallsSessionsYield, isSessionsYieldToolResult } from "./subagent-yield-output.js";
|
||||
import { extractAssistantText, sanitizeTextContent } from "./tools/session-message-text.js";
|
||||
import { extractAssistantText, sanitizeTextContent } from "./tools/chat-history-text.js";
|
||||
import { isAnnounceSkip } from "./tools/sessions-send-tokens.js";
|
||||
|
||||
const FAST_TEST_RETRY_INTERVAL_MS = 8;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// assistant message phases.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { extractAssistantText as extractChatHistoryAssistantText } from "./chat-history-text.js";
|
||||
import { extractAssistantText as extractSessionAssistantText } from "./session-message-text.js";
|
||||
|
||||
function assistantTextPart(id: string, phase: string, text: string) {
|
||||
return {
|
||||
@@ -19,39 +18,31 @@ function assistantMessage(...content: ReturnType<typeof assistantTextPart>[]) {
|
||||
};
|
||||
}
|
||||
|
||||
const assistantTextExtractors = [
|
||||
["chat history", extractChatHistoryAssistantText],
|
||||
["session message", extractSessionAssistantText],
|
||||
] as const;
|
||||
|
||||
describe("phase-aware assistant text helpers", () => {
|
||||
it("fails soft for malformed inputs", () => {
|
||||
for (const message of [null, 42, "broken history entry"]) {
|
||||
expect(extractChatHistoryAssistantText(message)).toBeUndefined();
|
||||
expect(extractSessionAssistantText(message)).toBeUndefined();
|
||||
}
|
||||
});
|
||||
|
||||
for (const [label, extractAssistantText] of assistantTextExtractors) {
|
||||
it(`prefers final_answer text over commentary in ${label} helpers`, () => {
|
||||
const message = assistantMessage(
|
||||
assistantTextPart("commentary", "commentary", "Need verify healthy."),
|
||||
assistantTextPart("final", "final_answer", "Health check completed successfully."),
|
||||
);
|
||||
it("prefers final_answer text over commentary", () => {
|
||||
const message = assistantMessage(
|
||||
assistantTextPart("commentary", "commentary", "Need verify healthy."),
|
||||
assistantTextPart("final", "final_answer", "Health check completed successfully."),
|
||||
);
|
||||
|
||||
expect(extractAssistantText(message)).toBe("Health check completed successfully.");
|
||||
});
|
||||
expect(extractChatHistoryAssistantText(message)).toBe("Health check completed successfully.");
|
||||
});
|
||||
|
||||
it(`preserves spaces across split final_answer blocks in ${label} helpers`, () => {
|
||||
const message = assistantMessage(
|
||||
assistantTextPart("commentary", "commentary", "Need verify healthy."),
|
||||
assistantTextPart("final_1", "final_answer", "Hi "),
|
||||
assistantTextPart("final_2", "final_answer", "<think>secret</think>there"),
|
||||
);
|
||||
it("preserves spaces across split final_answer blocks", () => {
|
||||
const message = assistantMessage(
|
||||
assistantTextPart("commentary", "commentary", "Need verify healthy."),
|
||||
assistantTextPart("final_1", "final_answer", "Hi "),
|
||||
assistantTextPart("final_2", "final_answer", "<think>secret</think>there"),
|
||||
);
|
||||
|
||||
expect(extractAssistantText(message)).toBe("Hi there");
|
||||
});
|
||||
}
|
||||
expect(extractChatHistoryAssistantText(message)).toBe("Hi there");
|
||||
});
|
||||
|
||||
it("does not fall back to commentary when an explicit final_answer is empty", () => {
|
||||
// An explicit empty final answer means there is no publishable response;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
/**
|
||||
* Session message text extraction barrel.
|
||||
*
|
||||
* Session tools import this narrow surface for assistant/user text extraction
|
||||
* without reaching into chat-history helper internals.
|
||||
*/
|
||||
export { extractAssistantText, sanitizeTextContent } from "./chat-history-text.js";
|
||||
@@ -20,11 +20,6 @@ export {
|
||||
resolveVisibleSessionReference,
|
||||
shouldResolveSessionIdInput,
|
||||
} from "./sessions-resolution.js";
|
||||
export {
|
||||
extractAssistantText,
|
||||
sanitizeTextContent,
|
||||
stripToolMessages,
|
||||
} from "./chat-history-text.js";
|
||||
import { normalizeOptionalString, type FastMode } from "@openclaw/normalization-core/string-coerce";
|
||||
import { getRuntimeConfig } from "../../config/config.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
describeSessionsHistoryTool,
|
||||
SESSIONS_HISTORY_TOOL_DISPLAY_SUMMARY,
|
||||
} from "../tool-description-presets.js";
|
||||
import { stripToolMessages } from "./chat-history-text.js";
|
||||
import type { AnyAgentTool } from "./common.js";
|
||||
import { jsonResult, readPositiveIntegerParam, readStringParam } from "./common.js";
|
||||
import {
|
||||
@@ -26,7 +27,6 @@ import {
|
||||
resolveSessionReference,
|
||||
resolveSandboxedSessionToolContext,
|
||||
resolveVisibleSessionReference,
|
||||
stripToolMessages,
|
||||
} from "./sessions-helpers.js";
|
||||
|
||||
const SessionsHistoryToolSchema = Type.Object({
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
describeSessionsListTool,
|
||||
SESSIONS_LIST_TOOL_DISPLAY_SUMMARY,
|
||||
} from "../tool-description-presets.js";
|
||||
import { stripToolMessages } from "./chat-history-text.js";
|
||||
import type { AnyAgentTool } from "./common.js";
|
||||
import {
|
||||
jsonResult,
|
||||
@@ -51,7 +52,6 @@ import {
|
||||
resolveSandboxedSessionToolContext,
|
||||
type SessionListRow,
|
||||
type SessionRunStatus,
|
||||
stripToolMessages,
|
||||
} from "./sessions-helpers.js";
|
||||
|
||||
const SessionsListToolSchema = Type.Object({
|
||||
|
||||
@@ -7,7 +7,7 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ChannelMessagingAdapter } from "../../channels/plugins/types.js";
|
||||
import { createTestRegistry } from "../../test-utils/channel-plugins.js";
|
||||
import { withEnvAsync } from "../../test-utils/env.js";
|
||||
import { extractAssistantText, sanitizeTextContent } from "./sessions-helpers.js";
|
||||
import { extractAssistantText, sanitizeTextContent } from "./chat-history-text.js";
|
||||
|
||||
const callGatewayMock = vi.fn();
|
||||
vi.mock("../../gateway/call.js", () => ({
|
||||
|
||||
@@ -5,15 +5,10 @@ import { countPendingDescendantRunsFromRuns } from "../../../agents/subagent-reg
|
||||
import { getSubagentRunsSnapshotForRead } from "../../../agents/subagent-registry-state.js";
|
||||
import { getChannelPlugin, normalizeChannelId } from "../../../channels/plugins/index.js";
|
||||
import { getSessionBindingService } from "../../../infra/outbound/session-binding-service.js";
|
||||
import { resolveChannelAccountId, resolveCommandSurfaceChannel } from "../channel-context.js";
|
||||
import type { CommandHandlerResult } from "../commands-types.js";
|
||||
import { formatRunLabel, sortSubagentRuns } from "../subagents-utils.js";
|
||||
import {
|
||||
RECENT_WINDOW_MINUTES,
|
||||
type SubagentsCommandContext,
|
||||
resolveChannelAccountId,
|
||||
resolveCommandSurfaceChannel,
|
||||
stopWithText,
|
||||
} from "./shared.js";
|
||||
import { RECENT_WINDOW_MINUTES, type SubagentsCommandContext, stopWithText } from "./shared.js";
|
||||
|
||||
function formatConversationBindingText(params: { conversationId: string }): string {
|
||||
return `binding:${params.conversationId}`;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Implements subagent log retrieval and pagination.
|
||||
import { parseStrictNonNegativeInteger } from "@openclaw/normalization-core/number-coercion";
|
||||
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
|
||||
import { stripToolMessages } from "../../../agents/tools/chat-history-text.js";
|
||||
import { callGateway } from "../../../gateway/call.js";
|
||||
import type { CommandHandlerResult } from "../commands-types.js";
|
||||
import { formatRunLabel } from "../subagents-utils.js";
|
||||
@@ -10,7 +11,6 @@ import {
|
||||
formatLogLines,
|
||||
resolveSubagentEntryForToken,
|
||||
stopWithText,
|
||||
stripToolMessages,
|
||||
} from "./shared.js";
|
||||
|
||||
export async function handleSubagentsLogAction(
|
||||
|
||||
@@ -12,14 +12,12 @@ import type { SubagentRunRecord } from "../../../agents/subagent-registry.types.
|
||||
import {
|
||||
resolveInternalSessionKey,
|
||||
resolveMainSessionAlias,
|
||||
stripToolMessages,
|
||||
} from "../../../agents/tools/sessions-helpers.js";
|
||||
import { callGateway } from "../../../gateway/call.js";
|
||||
import { parseAgentSessionKey } from "../../../routing/session-key.js";
|
||||
import { isSubagentSessionKey } from "../../../routing/session-key.js";
|
||||
import { looksLikeSessionId } from "../../../sessions/session-id.js";
|
||||
import { isNativeCommandTurn, resolveCommandTurnContext } from "../../command-turn-context.js";
|
||||
import { resolveCommandSurfaceChannel, resolveChannelAccountId } from "../channel-context.js";
|
||||
import { extractMessageText, type ChatMessage } from "../commands-subagents-text.js";
|
||||
import type { CommandHandler, CommandHandlerResult } from "../commands-types.js";
|
||||
import {
|
||||
@@ -28,8 +26,6 @@ import {
|
||||
type SubagentTargetResolution,
|
||||
} from "../subagents-utils.js";
|
||||
|
||||
export { stripToolMessages };
|
||||
export { resolveCommandSurfaceChannel, resolveChannelAccountId };
|
||||
export type { ChatMessage } from "../commands-subagents-text.js";
|
||||
|
||||
export const COMMAND = "/subagents";
|
||||
|
||||
Reference in New Issue
Block a user