chore(deadcode): dedupe live assistant text extraction · openclaw/openclaw@7355054
vincentkoc
·
2026-06-22
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,12 +2,12 @@
|
2 | 2 | import type { AssistantMessage, Tool } from "openclaw/plugin-sdk/llm"; |
3 | 3 | import { Type } from "typebox"; |
4 | 4 | import { describe, expect, it } from "vitest"; |
| 5 | +import { extractAssistantText } from "./embedded-agent-utils.js"; |
5 | 6 | import { |
6 | 7 | buildAssistantHistoryTurn, |
7 | 8 | buildStableCachePrefix, |
8 | 9 | completeSimpleWithLiveTimeout, |
9 | 10 | computeCacheHitRate, |
10 | | -extractAssistantText, |
11 | 11 | LIVE_CACHE_TEST_ENABLED, |
12 | 12 | logLiveCache, |
13 | 13 | resolveLiveDirectModel, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,11 +3,8 @@ import type { Message, Model } from "openclaw/plugin-sdk/llm";
|
3 | 3 | import { describe, expect, it, vi } from "vitest"; |
4 | 4 | import { wrapStreamFnSanitizeMalformedToolCalls } from "./embedded-agent-runner/run/attempt.tool-call-normalization.js"; |
5 | 5 | import { OMITTED_ASSISTANT_REASONING_TEXT } from "./embedded-agent-runner/thinking.js"; |
6 | | -import { |
7 | | -completeSimpleWithLiveTimeout, |
8 | | -extractAssistantText, |
9 | | -logLiveCache, |
10 | | -} from "./live-cache-test-support.js"; |
| 6 | +import { extractAssistantText } from "./embedded-agent-utils.js"; |
| 7 | +import { completeSimpleWithLiveTimeout, logLiveCache } from "./live-cache-test-support.js"; |
11 | 8 | import { isLiveTestEnabled } from "./live-test-helpers.js"; |
12 | 9 | import { buildAssistantMessageWithZeroUsage } from "./stream-message-shared.js"; |
13 | 10 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -9,12 +9,12 @@ import type { OpenClawConfig } from "../config/config.js";
|
9 | 9 | import { deleteTestEnvValue, setTestEnvValue } from "../test-utils/env.js"; |
10 | 10 | import { runEmbeddedAgent } from "./embedded-agent-runner.js"; |
11 | 11 | import { compactEmbeddedAgentSessionDirect } from "./embedded-agent-runner/compact.runtime.js"; |
| 12 | +import { extractAssistantText } from "./embedded-agent-utils.js"; |
12 | 13 | import { |
13 | 14 | buildAssistantHistoryTurn as buildTypedAssistantHistoryTurn, |
14 | 15 | buildStableCachePrefix, |
15 | 16 | completeSimpleWithLiveTimeout, |
16 | 17 | computeCacheHitRate, |
17 | | -extractAssistantText, |
18 | 18 | LIVE_CACHE_TEST_ENABLED, |
19 | 19 | logLiveCache, |
20 | 20 | resolveLiveDirectModel, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ import fs from "node:fs/promises";
|
9 | 9 | import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce"; |
10 | 10 | import { Type } from "typebox"; |
11 | 11 | import type { AssistantMessage, Message, Tool } from "../llm/types.js"; |
| 12 | +import { extractAssistantText } from "./embedded-agent-utils.js"; |
12 | 13 | import { |
13 | 14 | LIVE_CACHE_REGRESSION_BASELINE, |
14 | 15 | type LiveCacheFloor, |
@@ -18,7 +19,6 @@ import {
|
18 | 19 | buildStableCachePrefix, |
19 | 20 | completeSimpleWithLiveTimeout, |
20 | 21 | computeCacheHitRate, |
21 | | -extractAssistantText, |
22 | 22 | isLiveCachePrerequisiteSkip, |
23 | 23 | type LiveResolvedModel, |
24 | 24 | type LiveResolvedModelPool, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -163,15 +163,6 @@ export function buildStableCachePrefix(tag: string, sections = 160): string {
|
163 | 163 | return lines.join("\n"); |
164 | 164 | } |
165 | 165 | |
166 | | -/** Extract normalized assistant text from a streamed/completed assistant message. */ |
167 | | -export function extractAssistantText(message: AssistantMessage): string { |
168 | | -return message.content |
169 | | -.filter((block) => block.type === "text") |
170 | | -.map((block) => block.text.trim()) |
171 | | -.filter(Boolean) |
172 | | -.join(" "); |
173 | | -} |
174 | | - |
175 | 166 | /** Build a zero-usage assistant history turn for cache fixture setup. */ |
176 | 167 | export function buildAssistantHistoryTurn( |
177 | 168 | text: string, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,6 @@ import {
|
4 | 4 | buildLiveModelFileProbeContext, |
5 | 5 | buildLiveModelFileProbeRetryContext, |
6 | 6 | buildLiveModelImageProbeContext, |
7 | | -extractAssistantText, |
8 | 7 | fileProbeTextMatches, |
9 | 8 | imageProbeTextMatches, |
10 | 9 | isLiveModelProbeEnabled, |
@@ -61,18 +60,6 @@ describe("live model turn probes", () => {
|
61 | 60 | expect(content[1]).toHaveProperty("mimeType", "image/png"); |
62 | 61 | }); |
63 | 62 | |
64 | | -it("extracts assistant text blocks only", () => { |
65 | | -expect( |
66 | | -extractAssistantText({ |
67 | | -content: [ |
68 | | -{ type: "thinking", thinking: "hidden" }, |
69 | | -{ type: "text", text: " ok " }, |
70 | | -{ type: "toolCall", id: "1", name: "noop", arguments: {} }, |
71 | | -], |
72 | | -}), |
73 | | -).toBe("ok"); |
74 | | -}); |
75 | | - |
76 | 63 | it("detects image input support from model metadata", () => { |
77 | 64 | expect(modelSupportsImageInput({ input: ["text", "image"] })).toBe(true); |
78 | 65 | expect(modelSupportsImageInput({ input: ["text"] })).toBe(false); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,7 @@
|
4 | 4 | * Live profile tests use these fixtures to verify text, file-label, and image |
5 | 5 | * turn behavior without coupling probe construction to the large live suite. |
6 | 6 | */ |
7 | | -import type { AssistantMessage, Context, Model } from "../llm/types.js"; |
| 7 | +import type { Context, Model } from "../llm/types.js"; |
8 | 8 | |
9 | 9 | /** Stable token embedded in file-style live probe prompts. */ |
10 | 10 | export const LIVE_MODEL_FILE_PROBE_TOKEN = "opal"; |
@@ -69,15 +69,6 @@ export function isLiveModelProbeEnabled(
|
69 | 69 | return !["0", "false", "no", "off"].includes(raw); |
70 | 70 | } |
71 | 71 | |
72 | | -/** Extracts assistant text blocks into the probe result string. */ |
73 | | -export function extractAssistantText(message: Pick<AssistantMessage, "content">): string { |
74 | | -return message.content |
75 | | -.filter((block) => block.type === "text") |
76 | | -.map((block) => block.text.trim()) |
77 | | -.filter(Boolean) |
78 | | -.join(" "); |
79 | | -} |
80 | | - |
81 | 72 | /** Returns whether model metadata advertises image input support. */ |
82 | 73 | export function modelSupportsImageInput(model: Pick<Model, "input">): boolean { |
83 | 74 | return model.input.includes("image"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,7 @@ import { resolveDefaultAgentDir } from "./agent-scope.js";
|
20 | 20 | import { externalCliDiscoveryForProviders } from "./auth-profiles/external-cli-discovery.js"; |
21 | 21 | import { ensureCustomApiRegistered } from "./custom-api-registry.js"; |
22 | 22 | import { isRateLimitErrorMessage } from "./embedded-agent-helpers/errors.js"; |
| 23 | +import { extractAssistantText } from "./embedded-agent-utils.js"; |
23 | 24 | import { collectAnthropicApiKeys } from "./live-auth-keys.js"; |
24 | 25 | import { appendPrioritizedDynamicLiveModels } from "./live-model-dynamic-candidates.js"; |
25 | 26 | import { isModelNotFoundErrorMessage } from "./live-model-errors.js"; |
@@ -38,7 +39,6 @@ import {
|
38 | 39 | buildLiveModelFileProbeContext, |
39 | 40 | buildLiveModelFileProbeRetryContext, |
40 | 41 | buildLiveModelImageProbeContext, |
41 | | -extractAssistantText, |
42 | 42 | fileProbeTextMatches, |
43 | 43 | imageProbeTextMatches, |
44 | 44 | isLiveModelProbeEnabled, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。