summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/summarizer.ts
diff options
context:
space:
mode:
authorHyeongHo Jun <[email protected]>2025-07-23 08:57:06 +0900
committerGitHub <[email protected]>2025-07-22 23:57:06 +0000
commita00f1bb916b551fc17fa5bab80fb51dcdc88f00d (patch)
tree301797288462e03f8e954f03d526cc6ddaf0a7ab /packages/core/src/utils/summarizer.ts
parent487debe525fa20c7bbfb3393ce455fbbae1aab3f (diff)
feat(core): add partUtils module with unit tests (#4575)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/core/src/utils/summarizer.ts')
-rw-r--r--packages/core/src/utils/summarizer.ts36
1 files changed, 1 insertions, 35 deletions
diff --git a/packages/core/src/utils/summarizer.ts b/packages/core/src/utils/summarizer.ts
index 3f0fd52b..a038b8e3 100644
--- a/packages/core/src/utils/summarizer.ts
+++ b/packages/core/src/utils/summarizer.ts
@@ -12,7 +12,7 @@ import {
} from '@google/genai';
import { GeminiClient } from '../core/client.js';
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
-import { PartListUnion } from '@google/genai';
+import { getResponseText, partToString } from './partUtils.js';
/**
* A function that summarizes the result of a tool execution.
@@ -40,40 +40,6 @@ export const defaultSummarizer: Summarizer = (
_abortSignal: AbortSignal,
) => Promise.resolve(JSON.stringify(result.llmContent));
-// TODO: Move both these functions to utils
-function partToString(part: PartListUnion): string {
- if (!part) {
- return '';
- }
- if (typeof part === 'string') {
- return part;
- }
- if (Array.isArray(part)) {
- return part.map(partToString).join('');
- }
- if ('text' in part) {
- return part.text ?? '';
- }
- return '';
-}
-
-function getResponseText(response: GenerateContentResponse): string | null {
- if (response.candidates && response.candidates.length > 0) {
- const candidate = response.candidates[0];
- if (
- candidate.content &&
- candidate.content.parts &&
- candidate.content.parts.length > 0
- ) {
- return candidate.content.parts
- .filter((part) => part.text)
- .map((part) => part.text)
- .join('');
- }
- }
- return null;
-}
-
const SUMMARIZE_TOOL_OUTPUT_PROMPT = `Summarize the following tool output to be a maximum of {maxOutputTokens} tokens. The summary should be concise and capture the main points of the tool output.
The summarization should be done based on the content that is provided. Here are the basic rules to follow: